Lines 58-98javascript
58 let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
60 subpath = `package/${subpath}`;
61 while (offset < buffer.length) {
62 let name = str(offset, 100);
63 let size = parseInt(str(offset + 124, 12), 8);
66 if (name === subpath) return buffer.subarray(offset, offset + size);
67 offset += (size + 511) & ~511;
70 throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
73function installUsingNPM(pkg, subpath, binPath) {
74 const env = { ...process.env, npm_config_global: void 0 };
75 const installDir = path.join(__dirname, "npm-install");
76 fs.mkdirSync(installDir, { recursive: true });
78 fs.writeFileSync(path.join(installDir, "package.json"), "{}");
79 child_process.execSync(
80 `npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${packageJSON.version}`,
81 { cwd: installDir, stdio: "pipe", env }
HighRuntime Package Install
Package source invokes a package manager install command at runtime.
install.jsView on unpkg · L78 83 const installedBinPath = path.join(installDir, "node_modules", pkg, subpath);
84 fs.copyFileSync(installedBinPath, binPath);
85 fs.chmodSync(binPath, 0o755);
88 removeRecursive(installDir);
93function removeRecursive(dir) {
94 for (const entry of fs.readdirSync(dir)) {
95 const entryPath = path.join(dir, entry);
98 stats = fs.lstatSync(entryPath);