()
| 18 | fs.mkdirSync(physicalNodewinDir, {recursive: true}); |
| 19 | |
| 20 | async function main() { |
| 21 | const corepackPath = path.join(distDir, `corepack.js`); |
| 22 | fs.writeFileSync(corepackPath, [ |
| 23 | `#!/usr/bin/env node`, |
| 24 | `process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT??='0';`, |
| 25 | `require('module').enableCompileCache?.();`, |
| 26 | `require('./lib/corepack.cjs').runMain(process.argv.slice(2));`, |
| 27 | ].join(`\n`)); |
| 28 | fs.chmodSync(corepackPath, 0o755); |
| 29 | |
| 30 | for (const packageManager of SupportedPackageManagerSet) { |
| 31 | const binSet = engine.getBinariesFor(packageManager); |
| 32 | |
| 33 | for (const binaryName of binSet) { |
| 34 | const entryPath = path.join(distDir, `${binaryName}.js`); |
| 35 | const entryScript = [ |
| 36 | `#!/usr/bin/env node`, |
| 37 | `process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT??='1'`, |
| 38 | `require('module').enableCompileCache?.();`, |
| 39 | `require('./lib/corepack.cjs').runMain(['${binaryName}', ...process.argv.slice(2)]);`, |
| 40 | ].join(`\n`); |
| 41 | |
| 42 | fs.writeFileSync(entryPath, entryScript); |
| 43 | fs.chmodSync(entryPath, 0o755); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | for (const entry of fs.readdirSync(distDir, {withFileTypes: true})) { |
| 48 | if (entry.isDirectory()) |
| 49 | continue; |
| 50 | |
| 51 | await cmdShim(path.join(distDir, entry.name), path.join(shimsDir, path.basename(entry.name, `.js`)), {createCmdFile: true}); |
| 52 | } |
| 53 | |
| 54 | // The Node distribution doesn't support symlinks, so they copy the shims into |
| 55 | // the target folder. Since our shims have relative paths, it doesn't work |
| 56 | // super well... To make this process easier, we ship with a set of shims |
| 57 | // compatible for this use case. Not great, but better than text replacement |
| 58 | // in batch scripts. |
| 59 | |
| 60 | // Last note: cmdShim generates shims with relative paths, so it doesn't matter |
| 61 | // that the target files don't truly exist, as long as we mock the `stat` function. |
| 62 | const remapPath = (p: string) => path.resolve(__dirname, path.relative(virtualNodewinDir, p)); |
| 63 | |
| 64 | const easyStatFs = Object.assign(Object.create(fs), { |
| 65 | readFile: (p: string, encoding: BufferEncoding, cb: (err: any, str: string) => void) => fs.readFile(remapPath(p), encoding, cb), |
| 66 | stat: (p: string, cb: () => void) => fs.stat(remapPath(p), cb), |
| 67 | }); |
| 68 | |
| 69 | for (const entry of fs.readdirSync(distDir, {withFileTypes: true})) { |
| 70 | if (entry.isDirectory()) |
| 71 | continue; |
| 72 | |
| 73 | await cmdShim(path.join(virtualNodewinDir, `dist/${entry.name}`), path.join(physicalNodewinDir, path.basename(entry.name, `.js`)), {createCmdFile: true, fs: easyStatFs}); |
| 74 | } |
| 75 | |
| 76 | console.log(`All shims have been generated.`); |
| 77 | } |
no test coverage detected
searching dependent graphs…