(target)
| 135 | } |
| 136 | |
| 137 | async function ensureTargetNodeBinary(target) { |
| 138 | const extractedPath = resolve(nodeCacheDir, target.nodeBinaryInArchive); |
| 139 | if (await exists(extractedPath)) return extractedPath; |
| 140 | |
| 141 | const archivePath = resolve(nodeCacheDir, target.nodeArchive); |
| 142 | if (!(await exists(archivePath))) { |
| 143 | const url = `https://nodejs.org/dist/${nodeVersion}/${target.nodeArchive}`; |
| 144 | console.log(`[computerd-bin] downloading ${url}`); |
| 145 | const res = await fetch(url); |
| 146 | if (!res.ok || !res.body) throw new Error(`failed to download ${url}: ${res.status}`); |
| 147 | const tmpPath = `${archivePath}.${process.pid}.tmp`; |
| 148 | await pipeline(Readable.fromWeb(res.body), createWriteStream(tmpPath)); |
| 149 | await execFileP("mv", [tmpPath, archivePath]); |
| 150 | } |
| 151 | |
| 152 | await execFileP("tar", ["-xJf", archivePath, "-C", nodeCacheDir]); |
| 153 | if (!(await exists(extractedPath))) { |
| 154 | throw new Error(`extraction did not produce ${extractedPath}`); |
| 155 | } |
| 156 | return extractedPath; |
| 157 | } |
| 158 | |
| 159 | async function exists(p) { |
| 160 | try { |
no test coverage detected