* Returns the file from which to load our bootloader. We need to do this in * since Node does not support paths with spaces in them < 13 (nodejs/node#12971), * so if our installation path has spaces, we need to fall back somewhere.
(cwd: string | undefined, binary: NodeBinary)
| 496 | * so if our installation path has spaces, we need to fall back somewhere. |
| 497 | */ |
| 498 | protected async getBootloaderFile(cwd: string | undefined, binary: NodeBinary) { |
| 499 | const targetPath = forceForwardSlashes(bootloaderDefaultPath); |
| 500 | |
| 501 | // 1. If the path doesn't have a space, we're OK to use it. |
| 502 | if (!targetPath.includes(' ')) { |
| 503 | return { interpolatedPath: targetPath, dispose: () => undefined }; |
| 504 | } |
| 505 | |
| 506 | // 1.5. If we can otherwise use spaces in the path, quote and return it. |
| 507 | if (binary.has(Capability.UseSpacesInRequirePath)) { |
| 508 | return { interpolatedPath: `"${targetPath}"`, dispose: () => undefined }; |
| 509 | } |
| 510 | |
| 511 | // 2. Try the tmpdir, if it's space-free. |
| 512 | const contents = `require(${JSON.stringify(targetPath)})`; |
| 513 | if (!os.tmpdir().includes(' ') || !cwd) { |
| 514 | const tmpPath = path.join(os.tmpdir(), 'vscode-js-debug-bootloader.js'); |
| 515 | await fs.promises.writeFile(tmpPath, contents); |
| 516 | return { interpolatedPath: tmpPath, dispose: () => undefined }; |
| 517 | } |
| 518 | |
| 519 | // 3. Worst case, write into the cwd. This is messy, but we have few options. |
| 520 | const nearFilename = '.vscode-js-debug-bootloader.js'; |
| 521 | const nearPath = path.join(cwd, nearFilename); |
| 522 | await fs.promises.writeFile(nearPath, contents); |
| 523 | return { |
| 524 | interpolatedPath: `./${nearFilename}`, |
| 525 | dispose: () => fs.unlinkSync(nearPath), |
| 526 | }; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Reads telemetry from the process. |
nothing calls this directly
no test coverage detected