Skip to content

Commit a09601c

Browse files
committed
fallback when bun blocks postinstall
1 parent efc1e6b commit a09601c

5 files changed

Lines changed: 41 additions & 20 deletions

File tree

‎.changeset/kind-cycles-hang.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"executor": patch
3+
---
4+
5+
Fallback to downloading the platform binary on first run when package-manager postinstall scripts are blocked, including Bun global installs.

‎.changeset/pre.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@executor/ui": "1.4.0-beta.0"
2727
},
2828
"changesets": [
29-
"funny-buses-count",
29+
"kind-cycles-hang",
3030
"ripe-yaks-sniff"
3131
]
3232
}

‎apps/cli/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "executor",
3-
"version": "1.4.0-beta.2",
3+
"version": "1.4.0-beta.3",
44
"private": true,
55
"type": "module",
66
"bin": {

‎apps/cli/src/build.ts‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,29 @@ function run(target) {
338338
if (process.env.EXECUTOR_BIN_PATH) run(process.env.EXECUTOR_BIN_PATH);
339339
340340
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+
};
342354
343355
const 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
389403
const packageDir = path.dirname(fs.realpathSync(__filename));
390404
const binDir = path.join(packageDir, "bin");
405+
const runtimeDir = path.join(binDir, "runtime");
391406
const packageJson = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8"));
392407
393408
const repositoryUrl = typeof packageJson.repository === "string"
@@ -402,7 +417,8 @@ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" };
402417
const platform = platformMap[os.platform()] || os.platform();
403418
const arch = os.arch() === "arm64" ? "arm64" : "x64";
404419
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");
406422
407423
const isMusl = (() => {
408424
if (platform !== "linux") return false;
@@ -442,20 +458,22 @@ const download = async () => {
442458
443459
const 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");

‎bun.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)