@@ -338,16 +338,29 @@ function run(target) {
338338if (process.env.EXECUTOR_BIN_PATH) run(process.env.EXECUTOR_BIN_PATH);
339339
340340const scriptDir = path.dirname(fs.realpathSync(__filename));
341- const cached = path.join(scriptDir, process.platform === "win32" ? ".executor.exe" : ".executor");
341+ const binary = process.platform === "win32" ? "executor.exe" : "executor";
342+ const runtimeBinary = path.join(scriptDir, "runtime", binary);
343+ const legacyCached = path.join(scriptDir, process.platform === "win32" ? ".executor.exe" : ".executor");
344+
345+ const resolveInstalledBinary = () => {
346+ if (fs.existsSync(runtimeBinary)) {
347+ return runtimeBinary;
348+ }
349+ if (fs.existsSync(legacyCached)) {
350+ return legacyCached;
351+ }
352+ return null;
353+ };
342354
343355const installIfNeeded = () => {
344- if (fs.existsSync(cached)) {
345- return true;
356+ const existing = resolveInstalledBinary();
357+ if (existing) {
358+ return existing;
346359 }
347360
348361 const installer = path.resolve(scriptDir, "..", "postinstall.cjs");
349362 if (!fs.existsSync(installer)) {
350- return false ;
363+ return null ;
351364 }
352365
353366 console.error("executor binary is missing; downloading release asset...");
@@ -365,15 +378,16 @@ const installIfNeeded = () => {
365378 process.exit(result.status);
366379 }
367380
368- return fs.existsSync(cached );
381+ return resolveInstalledBinary( );
369382};
370383
371- if (!installIfNeeded()) {
384+ const installedBinary = installIfNeeded();
385+ if (!installedBinary) {
372386 console.error("executor binary is missing. Reinstall the package or run 'npm rebuild executor'.");
373387 process.exit(1);
374388}
375389
376- run(cached );
390+ run(installedBinary );
377391` ;
378392
379393// ---------------------------------------------------------------------------
@@ -388,6 +402,7 @@ const os = require("os");
388402
389403const packageDir = path.dirname(fs.realpathSync(__filename));
390404const binDir = path.join(packageDir, "bin");
405+ const runtimeDir = path.join(binDir, "runtime");
391406const packageJson = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8"));
392407
393408const repositoryUrl = typeof packageJson.repository === "string"
@@ -402,7 +417,8 @@ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" };
402417const platform = platformMap[os.platform()] || os.platform();
403418const arch = os.arch() === "arm64" ? "arm64" : "x64";
404419const binary = platform === "windows" ? "executor.exe" : "executor";
405- const cachedBinary = path.join(binDir, platform === "win32" ? ".executor.exe" : ".executor");
420+ const cachedBinary = path.join(runtimeDir, binary);
421+ const legacyCachedBinary = path.join(binDir, platform === "win32" ? ".executor.exe" : ".executor");
406422
407423const isMusl = (() => {
408424 if (platform !== "linux") return false;
@@ -442,20 +458,22 @@ const download = async () => {
442458
443459const extract = () => {
444460 fs.mkdirSync(binDir, { recursive: true });
461+ fs.rmSync(runtimeDir, { recursive: true, force: true });
462+ fs.mkdirSync(runtimeDir, { recursive: true });
445463
446464 if (platform === "linux") {
447- run("tar", ["-xzf", archivePath, "-C", binDir ]);
465+ run("tar", ["-xzf", archivePath, "-C", runtimeDir ]);
448466 return;
449467 }
450468
451469 if (platform === "darwin") {
452- run("unzip", ["-o", archivePath, "-d", binDir ]);
470+ run("unzip", ["-o", archivePath, "-d", runtimeDir ]);
453471 return;
454472 }
455473
456474 const command = [
457475 "$ErrorActionPreference = 'Stop'",
458- "Expand-Archive -LiteralPath '" + archivePath.replace(/'/g, "''") + "' -DestinationPath '" + binDir .replace(/'/g, "''") + "' -Force",
476+ "Expand-Archive -LiteralPath '" + archivePath.replace(/'/g, "''") + "' -DestinationPath '" + runtimeDir .replace(/'/g, "''") + "' -Force",
459477 ].join("; ");
460478 run("powershell.exe", ["-NoLogo", "-NoProfile", "-Command", command]);
461479};
@@ -465,15 +483,13 @@ const extract = () => {
465483 await download();
466484 extract();
467485
468- const extractedBinary = path.join(binDir, binary);
469- if (!fs.existsSync(extractedBinary)) {
470- throw new Error("Expected extracted binary at " + extractedBinary);
486+ if (!fs.existsSync(cachedBinary)) {
487+ throw new Error("Expected extracted binary at " + cachedBinary);
471488 }
472489
473- if (fs.existsSync(cachedBinary )) {
474- fs.unlinkSync(cachedBinary );
490+ if (fs.existsSync(legacyCachedBinary )) {
491+ fs.unlinkSync(legacyCachedBinary );
475492 }
476- fs.renameSync(extractedBinary, cachedBinary);
477493 fs.chmodSync(cachedBinary, 0o755);
478494 fs.rmSync(archivePath, { force: true });
479495 console.log("executor: installed " + assetBase + " from GitHub Releases");
0 commit comments