@bsdkrun/cli 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/bsdkrun.js CHANGED
@@ -8,38 +8,54 @@ const fs = require("node:fs");
8
8
  const { spawnSync } = require("node:child_process");
9
9
  const { binaryPath, gvproxyPath } = require("../scripts/platform.js");
10
10
 
11
- const bin = binaryPath();
12
-
13
- // Point bsdkrun at the gvproxy postinstall bundled, unless the user already
14
- // picked one (BSDKRUN_GVPROXY takes precedence in the native binary too, but
15
- // setting it here also wins over a different gvproxy on PATH).
16
- if (!process.env.BSDKRUN_GVPROXY) {
17
- const gv = gvproxyPath();
18
- if (fs.existsSync(gv)) {
19
- process.env.BSDKRUN_GVPROXY = gv;
11
+ async function main() {
12
+ const bin = binaryPath();
13
+
14
+ // Self-heal: `bunx` (and any install with lifecycle scripts disabled) never
15
+ // runs postinstall, so the binary won't be here. Download it on first use
16
+ // rather than erroring out — this is the only run path under bunx.
17
+ if (!fs.existsSync(bin)) {
18
+ try {
19
+ const { install } = require("../scripts/postinstall.js");
20
+ await install();
21
+ } catch (err) {
22
+ console.error(
23
+ "[bsdkrun] native binary not found and on-demand download failed:\n" +
24
+ " " +
25
+ (err && err.message ? err.message : err) +
26
+ "\nRun the install script manually:\n" +
27
+ " node " +
28
+ require("node:path").join(__dirname, "..", "scripts", "postinstall.js")
29
+ );
30
+ process.exit(1);
31
+ }
32
+ if (!fs.existsSync(bin)) {
33
+ console.error("[bsdkrun] native binary still missing after download at " + bin);
34
+ process.exit(1);
35
+ }
20
36
  }
21
- }
22
37
 
23
- if (!fs.existsSync(bin)) {
24
- console.error(
25
- "[bsdkrun] native binary not found at " +
26
- bin +
27
- "\nThe postinstall download may have been skipped (e.g. `npm install --ignore-scripts`).\n" +
28
- "Reinstall @bsdkrun/cli, or run its install script manually:\n" +
29
- " node " +
30
- require("node:path").join(__dirname, "..", "scripts", "postinstall.js")
31
- );
32
- process.exit(1);
33
- }
38
+ // Point bsdkrun at the gvproxy postinstall bundled, unless the user already
39
+ // picked one (BSDKRUN_GVPROXY takes precedence in the native binary too, but
40
+ // setting it here also wins over a different gvproxy on PATH).
41
+ if (!process.env.BSDKRUN_GVPROXY) {
42
+ const gv = gvproxyPath();
43
+ if (fs.existsSync(gv)) {
44
+ process.env.BSDKRUN_GVPROXY = gv;
45
+ }
46
+ }
34
47
 
35
- const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
48
+ const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
36
49
 
37
- if (res.error) {
38
- console.error("[bsdkrun] failed to launch: " + res.error.message);
39
- process.exit(1);
40
- }
41
- // Propagate a terminating signal as the conventional 128+signal exit code.
42
- if (res.signal) {
43
- process.exit(1);
50
+ if (res.error) {
51
+ console.error("[bsdkrun] failed to launch: " + res.error.message);
52
+ process.exit(1);
53
+ }
54
+ // Propagate a terminating signal as the conventional 128+signal exit code.
55
+ if (res.signal) {
56
+ process.exit(1);
57
+ }
58
+ process.exit(res.status === null ? 1 : res.status);
44
59
  }
45
- process.exit(res.status === null ? 1 : res.status);
60
+
61
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsdkrun/cli",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Firecracker-style microVM launcher for BSD and Linux (OCI) guests, built on libkrun. Installs the prebuilt bsdkrun host binary for your platform.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/tsirysndr/bsdkrun#readme",
@@ -174,7 +174,16 @@ async function verifyChecksum(archive, sidecarUrl, asset) {
174
174
  console.log(`[bsdkrun] checksum OK (${actual.slice(0, 12)}…)`);
175
175
  }
176
176
 
177
- main().catch((err) => {
178
- console.error("\n[bsdkrun] install failed:\n" + (err && err.message ? err.message : err));
179
- process.exit(1);
180
- });
177
+ // Exported so the bin shim can self-heal: under `bunx` (and any install run
178
+ // with lifecycle scripts disabled) postinstall never runs, so the launcher
179
+ // calls install() on first use to fetch the binary on demand.
180
+ module.exports = { install: main };
181
+
182
+ // Only auto-run when executed directly (`node scripts/postinstall.js`), not
183
+ // when require()'d by the bin shim.
184
+ if (require.main === module) {
185
+ main().catch((err) => {
186
+ console.error("\n[bsdkrun] install failed:\n" + (err && err.message ? err.message : err));
187
+ process.exit(1);
188
+ });
189
+ }