(args: string)
| 112 | * Analyse the given command line arguments and extract debug port and protocol from it. |
| 113 | */ |
| 114 | export function analyseArguments(args: string) { |
| 115 | const DEBUG_PORT_PATTERN = /--inspect-port=(\d+)/; |
| 116 | |
| 117 | let address: string | undefined; |
| 118 | let port: number | undefined; |
| 119 | |
| 120 | // match --inspect, --inspect=1234, --inspect-brk, --inspect-brk=1234 |
| 121 | let matches = DEBUG_FLAGS_PATTERN().exec(args); |
| 122 | if (matches?.groups) { |
| 123 | const portStr = matches.groups.port1 || matches.groups.port2; |
| 124 | port = portStr ? Number(portStr) : 9229; |
| 125 | address = matches.groups.address ?? '127.0.0.1'; |
| 126 | } |
| 127 | |
| 128 | // a --inspect-port=1234 overrides the port |
| 129 | matches = DEBUG_PORT_PATTERN.exec(args); |
| 130 | if (matches && matches.length === 2) { |
| 131 | address ||= '127.0.0.1'; |
| 132 | port = parseInt(matches[1]); |
| 133 | } |
| 134 | |
| 135 | return { address, port }; |
| 136 | } |
no outgoing calls
no test coverage detected