| @@ -338,16 +338,29 @@ function run(target) { · 337 unmodified lines |
| 338 | 338 | if (process.env.EXECUTOR_BIN_PATH) run(process.env.EXECUTOR_BIN_PATH); |
| 339 | 339 | |
| 340 | 340 | const 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 | +}; |
| 342 | 354 | |
| 343 | 355 | const installIfNeeded = () => { |
| 344 | | − if (fs.existsSync(cached)) { |
| 345 | | − return true; |
| 356 | + const existing = resolveInstalledBinary(); |
| 357 | + if (existing) { |
| 358 | + return existing; |
| 346 | 359 | } |
| 347 | 360 | |
| 348 | 361 | const installer = path.resolve(scriptDir, "..", "postinstall.cjs"); |
| 349 | 362 | if (!fs.existsSync(installer)) { |
| 350 | | − return false; |
| 363 | + return null; |
| 351 | 364 | } |
| 352 | 365 | |
| 353 | 366 | console.error("executor binary is missing; downloading release asset..."); |
| @@ -365,15 +378,16 @@ const installIfNeeded = () => { · 11 unmodified lines |
| 365 | 378 | process.exit(result.status); |
| 366 | 379 | } |
| 367 | 380 | |
| 368 | | − return fs.existsSync(cached); |
| 381 | + return resolveInstalledBinary(); |
| 369 | 382 | }; |
| 370 | 383 | |
| 371 | | −if (!installIfNeeded()) { |
| 384 | +const installedBinary = installIfNeeded(); |
| 385 | +if (!installedBinary) { |
| 372 | 386 | console.error("executor binary is missing. Reinstall the package or run 'npm rebuild executor'."); |
| 373 | 387 | process.exit(1); |
| 374 | 388 | } |
| 375 | 389 | |
| 376 | | −run(cached); |
| 390 | +run(installedBinary); |
| 377 | 391 | `; |
| 378 | 392 | |
| 379 | 393 | // --------------------------------------------------------------------------- |
| @@ -388,6 +402,7 @@ const os = require("os"); · 8 unmodified lines |
| 388 | 402 | |
| 389 | 403 | const packageDir = path.dirname(fs.realpathSync(__filename)); |
| 390 | 404 | const binDir = path.join(packageDir, "bin"); |
| 405 | +const runtimeDir = path.join(binDir, "runtime"); |
| 391 | 406 | const packageJson = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8")); |
| 392 | 407 | |
| 393 | 408 | const repositoryUrl = typeof packageJson.repository === "string" |
| @@ -402,7 +417,8 @@ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" }; · 8 unmodified lines |
| 402 | 417 | const platform = platformMap[os.platform()] || os.platform(); |
| 403 | 418 | const arch = os.arch() === "arm64" ? "arm64" : "x64"; |
| 404 | 419 | const 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"); |
| 406 | 422 | |
| 407 | 423 | const isMusl = (() => { |
| 408 | 424 | if (platform !== "linux") return false; |
| @@ -442,20 +458,22 @@ const download = async () => { · 33 unmodified lines |
| 442 | 458 | |
| 443 | 459 | const extract = () => { |
| 444 | 460 | fs.mkdirSync(binDir, { recursive: true }); |
| 461 | + fs.rmSync(runtimeDir, { recursive: true, force: true }); |
| 462 | + fs.mkdirSync(runtimeDir, { recursive: true }); |
| 445 | 463 | |
| 446 | 464 | if (platform === "linux") { |
| 447 | | − run("tar", ["-xzf", archivePath, "-C", binDir]); |
| 465 | + run("tar", ["-xzf", archivePath, "-C", runtimeDir]); |
| 448 | 466 | return; |
| 449 | 467 | } |
| 450 | 468 | |
| 451 | 469 | if (platform === "darwin") { |
| 452 | | − run("unzip", ["-o", archivePath, "-d", binDir]); |
| 470 | + run("unzip", ["-o", archivePath, "-d", runtimeDir]); |
| 453 | 471 | return; |
| 454 | 472 | } |
| 455 | 473 | |
| 456 | 474 | const command = [ |
| 457 | 475 | "$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", |
| 459 | 477 | ].join("; "); |
| 460 | 478 | run("powershell.exe", ["-NoLogo", "-NoProfile", "-Command", command]); |
| 461 | 479 | }; |
| @@ -465,15 +483,13 @@ const extract = () => { · 3 unmodified lines |
| 465 | 483 | await download(); |
| 466 | 484 | extract(); |
| 467 | 485 | |
| 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); |
| 471 | 488 | } |
| 472 | 489 | |
| 473 | | − if (fs.existsSync(cachedBinary)) { |
| 474 | | − fs.unlinkSync(cachedBinary); |
| 490 | + if (fs.existsSync(legacyCachedBinary)) { |
| 491 | + fs.unlinkSync(legacyCachedBinary); |
| 475 | 492 | } |
| 476 | | − fs.renameSync(extractedBinary, cachedBinary); |
| 477 | 493 | fs.chmodSync(cachedBinary, 0o755); |
| 478 | 494 | fs.rmSync(archivePath, { force: true }); |
| 479 | 495 | console.log("executor: installed " + assetBase + " from GitHub Releases"); |