Lines 202-242javascript
203 const pkgJson = req.resolve(`${name}/package.json`);
204 const pkgDir = path.dirname(pkgJson);
205 const src = path.join(pkgDir, "bin", `code-${targetTriple}`);
206 if (existsSync(src)) {
207 // Always ensure cache has the binary; on Unix mirror into node_modules
208 copyFileSync(src, cachePath);
209 if (platform !== "win32") {
210 copyFileSync(cachePath, binaryPath);
211 try { chmodSync(binaryPath, 0o755); } catch {}
215 } catch { /* ignore and fall back */ }
217 } catch { /* ignore */ }
219 // 4) Download from GitHub release
220 const isWin = platform === "win32";
221 const archiveName = isWin
222 ? `code-${targetTriple}.zip`
223 : (() => { try { execSync("zstd --version", { stdio: "ignore", shell: true }); return `code-${targetTriple}.zst`; } catch { return `code-${targetTriple}.tar.gz`; } })();
224 const url = `https://github.com/just-every/code/releases/download/v${version}/${archiveName}`;
225 const tmp = path.join(binDir, `.${archiveName}.part`);
226 return httpsDownload(url, tmp)
229 // Extract zip with robust fallbacks and use a safe temp dir, then move to cache
231 const sysRoot = process.env.SystemRoot || process.env.windir || 'C:\\\Windows';
232 const psFull = path.join(sysRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
bin/coder.jsView on unpkg · L222 233 const unzipDest = getCacheDir(version); // extract directly to cache location
234 const psCmd = `Expand-Archive -Path '${tmp}' -DestinationPath '${unzipDest}' -Force`;
236 try { execSync(`"${psFull}" -NoProfile -NonInteractive -Command "${psCmd}"`, { stdio: 'ignore' }); ok = true; } catch {}
237 if (!ok) { try { execSync(`powershell -NoProfile -NonInteractive -Command "${psCmd}"`, { stdio: 'ignore' }); ok = true; } catch {} }
238 if (!ok) { try { execSync(`pwsh -NoProfile -NonInteractive -Command "${psCmd}"`, { stdio: 'ignore' }); ok = true; } catch {} }
239 if (!ok) { execSync(`tar -xf "${tmp}" -C "${unzipDest}"`, { stdio: 'ignore', shell: true }); }
241 throw new Error(`failed to unzip: ${e.message}`);
242 } finally { try { unlinkSync(tmp); } catch {} }