* Scan arguments and increment port number for inspect calls (to avoid conflicts when spawning new command). * * @param {string[]} args - array of arguments from node.execArgv * @returns {string[]} * @private
(args)
| 2717 | */ |
| 2718 | |
| 2719 | function incrementNodeInspectorPort(args) { |
| 2720 | // Testing for these options: |
| 2721 | // --inspect[=[host:]port] |
| 2722 | // --inspect-brk[=[host:]port] |
| 2723 | // --inspect-port=[host:]port |
| 2724 | return args.map((arg) => { |
| 2725 | if (!arg.startsWith('--inspect')) { |
| 2726 | return arg; |
| 2727 | } |
| 2728 | let debugOption; |
| 2729 | let debugHost = '127.0.0.1'; |
| 2730 | let debugPort = '9229'; |
| 2731 | let match; |
| 2732 | if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) { |
| 2733 | // e.g. --inspect |
| 2734 | debugOption = match[1]; |
| 2735 | } else if ( |
| 2736 | (match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null |
| 2737 | ) { |
| 2738 | debugOption = match[1]; |
| 2739 | if (/^\d+$/.test(match[3])) { |
| 2740 | // e.g. --inspect=1234 |
| 2741 | debugPort = match[3]; |
| 2742 | } else { |
| 2743 | // e.g. --inspect=localhost |
| 2744 | debugHost = match[3]; |
| 2745 | } |
| 2746 | } else if ( |
| 2747 | (match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null |
| 2748 | ) { |
| 2749 | // e.g. --inspect=localhost:1234 |
| 2750 | debugOption = match[1]; |
| 2751 | debugHost = match[3]; |
| 2752 | debugPort = match[4]; |
| 2753 | } |
| 2754 | |
| 2755 | if (debugOption && debugPort !== '0') { |
| 2756 | return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`; |
| 2757 | } |
| 2758 | return arg; |
| 2759 | }); |
| 2760 | } |
| 2761 | |
| 2762 | /** |
| 2763 | * Exported for using from tests, not otherwise used outside this file. |