MCPcopy Create free account
hub / github.com/cloudflare/computer / ensureTargetNodeBinary

Function ensureTargetNodeBinary

packages/computerd/scripts/build-bin.mjs:137–157  ·  view source on GitHub ↗
(target)

Source from the content-addressed store, hash-verified

135}
136
137async 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
159async function exists(p) {
160 try {

Callers 1

buildTargetFunction · 0.85

Calls 3

existsFunction · 0.70
logMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected