(env: IBootloaderInfo)
| 66 | } |
| 67 | |
| 68 | function inspectOrQueue(env: IBootloaderInfo) { |
| 69 | const mode = !isPipeAvailable(env.inspectorIpc) |
| 70 | ? Mode.Inactive |
| 71 | : env.deferredMode |
| 72 | ? Mode.Deferred |
| 73 | : Mode.Immediate; |
| 74 | |
| 75 | bootloaderLogger.info(LogTag.Runtime, 'Set debug mode', { mode }); |
| 76 | if (mode === Mode.Inactive) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | // inspector.url() will be defined if --inspect is passed to the process. |
| 81 | // Don't call it again to avoid https://github.com/nodejs/node/issues/33012 |
| 82 | const openedFromCli = inspector.url() !== undefined; |
| 83 | if (!openedFromCli) { |
| 84 | inspector.open(0, undefined, false); // first call to set the inspector.url() |
| 85 | } |
| 86 | |
| 87 | const info: IAutoAttachInfo = { |
| 88 | ipcAddress: env.inspectorIpc || '', |
| 89 | pid: String(process.pid), |
| 90 | telemetry, |
| 91 | scriptName: process.argv[1], |
| 92 | inspectorURL: inspector.url() as string, |
| 93 | waitForDebugger: true, |
| 94 | ppid: String(env.ppid ?? ''), |
| 95 | }; |
| 96 | |
| 97 | if (mode === Mode.Immediate) { |
| 98 | spawnWatchdog(env.execPath || process.execPath, info); |
| 99 | } else { |
| 100 | // The bootloader must call inspector.open() synchronously, which will block |
| 101 | // the event loop. Spawn the watchdog handoff in a new process to debug this. |
| 102 | spawnSync( |
| 103 | env.execPath || process.execPath, |
| 104 | [ |
| 105 | '-e', |
| 106 | `const c=require("net").createConnection(process.env.NODE_INSPECTOR_IPC)` + |
| 107 | `.on("connect",()=>{c.write(process.env.NODE_INSPECTOR_INFO,'utf-8',()=>c.end())})`, |
| 108 | ], |
| 109 | { |
| 110 | env: { |
| 111 | NODE_INSPECTOR_INFO: JSON.stringify(info), |
| 112 | NODE_INSPECTOR_IPC: env.inspectorIpc, |
| 113 | }, |
| 114 | }, |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | inspector.open(openedFromCli ? undefined : 0, undefined, true); |
| 119 | } |
| 120 | |
| 121 | function isPipeAvailable(pipe?: string): pipe is string { |
| 122 | if (!pipe) { |
no test coverage detected