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