aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/bnu.js8
-rw-r--r--bin/npm.js20
2 files changed, 23 insertions, 5 deletions
diff --git a/bin/bnu.js b/bin/bnu.js
index 9d1917e..0ea480b 100755
--- a/bin/bnu.js
+++ b/bin/bnu.js
@@ -1,12 +1,10 @@
#!/usr/bin/env bun
import { realpathSync } from "node:fs";
-import { basename, dirname, join } from "node:path";
-import { pathToFileURL } from "node:url";
+import { basename } from "node:path";
+import { commandNames } from "../src/shared/catalog.js";
+import { main } from "../src/shared/runtime.js";
-const here = dirname(realpathSync(Bun.argv[1]));
globalThis[Symbol.for("bnu.cli")] = true;
-const { commandNames } = await import(pathToFileURL(join(here, "../src/shared/catalog.js")).href);
-const { main } = await import(pathToFileURL(join(here, "../src/shared/runtime.js")).href);
let invokedPath = Bun.argv[1];
try {
if (process.env._ && realpathSync(process.env._) === realpathSync(Bun.argv[1])) invokedPath = process.env._;
diff --git a/bin/npm.js b/bin/npm.js
new file mode 100644
index 0000000..4f45f0e
--- /dev/null
+++ b/bin/npm.js
@@ -0,0 +1,20 @@
+#!/usr/bin/env node
+
+import { spawn } from "node:child_process";
+import { createRequire } from "node:module";
+import { fileURLToPath } from "node:url";
+
+const require = createRequire(import.meta.url);
+const bun = require.resolve("bun/bin/bun.exe");
+const launcher = fileURLToPath(new URL("../runtime/bnu.js", import.meta.url));
+const child = spawn(bun, [launcher, ...process.argv.slice(2)], { stdio: "inherit" });
+
+child.on("error", (error) => {
+ console.error(`bnu: failed to start bundled Bun runtime: ${error.message}`);
+ process.exit(1);
+});
+
+child.on("exit", (code, signal) => {
+ if (signal) process.kill(process.pid, signal);
+ else process.exit(code ?? 1);
+});