@nubjs/nub 0.0.7 → 0.0.9
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/launch.js +65 -0
- package/bin/nub +7 -3
- package/bin/nubx +8 -0
- package/package.json +10 -10
- package/postinstall.js +35 -25
package/bin/launch.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared launcher used by bin/nub and bin/nubx.
|
|
3
|
+
//
|
|
4
|
+
// On POSIX, postinstall.js replaces bin/nub and bin/nubx with direct symlinks to
|
|
5
|
+
// the platform binary, so this module never runs on the hot path — `nub`/`nubx`
|
|
6
|
+
// exec the native Rust binary directly (no Node bootstrap, preserving cold-start).
|
|
7
|
+
// It DOES run on Windows (npm's generated nub.cmd / nubx.cmd invoke `node bin/nub`
|
|
8
|
+
// — there is no symlink fast path there) and as a fallback on any platform where
|
|
9
|
+
// postinstall could not create the symlink.
|
|
10
|
+
//
|
|
11
|
+
// The Rust CLI selects its verb from argv[0]'s basename (nub vs nubx vs node — see
|
|
12
|
+
// crates/nub-cli/src/cli.rs Argv0::detect). spawnSync's `argv0` option sets that
|
|
13
|
+
// basename for the child without changing process.execPath, so the binary still
|
|
14
|
+
// resolves its sibling runtime/ directory by walking up from its real location.
|
|
15
|
+
const { spawnSync, execSync } = require("child_process");
|
|
16
|
+
|
|
17
|
+
const PLATFORMS = {
|
|
18
|
+
"darwin-arm64": "@nubjs/nub-darwin-arm64",
|
|
19
|
+
"darwin-x64": "@nubjs/nub-darwin-x64",
|
|
20
|
+
"linux-x64": "@nubjs/nub-linux-x64",
|
|
21
|
+
"linux-x64-musl": "@nubjs/nub-linux-x64-musl",
|
|
22
|
+
"linux-arm64": "@nubjs/nub-linux-arm64",
|
|
23
|
+
"linux-arm64-musl": "@nubjs/nub-linux-arm64-musl",
|
|
24
|
+
"win32-x64": "@nubjs/nub-win32-x64",
|
|
25
|
+
"win32-arm64": "@nubjs/nub-win32-arm64",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function resolveBinary() {
|
|
29
|
+
const { platform, arch } = process;
|
|
30
|
+
const isMusl =
|
|
31
|
+
platform === "linux" &&
|
|
32
|
+
(() => {
|
|
33
|
+
try {
|
|
34
|
+
return execSync("ldd --version 2>&1", { encoding: "utf8" }).includes("musl");
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return ((e && e.stderr) || "").toString().includes("musl");
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
const key = `${platform}-${arch}${isMusl ? "-musl" : ""}`;
|
|
40
|
+
const pkg = PLATFORMS[key];
|
|
41
|
+
if (!pkg) {
|
|
42
|
+
console.error(`@nubjs/nub: no prebuilt binary for ${platform}-${arch}`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return require.resolve(`${pkg}/bin/nub${platform === "win32" ? ".exe" : ""}`);
|
|
47
|
+
} catch {
|
|
48
|
+
console.error(`@nubjs/nub: the ${pkg} package is not installed. Try: npm rebuild @nubjs/nub`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// argv0Name: the basename the child should see as argv[0] ("nub" or "nubx"). When
|
|
54
|
+
// omitted the child sees the binary path, whose basename is "nub" — the default verb.
|
|
55
|
+
module.exports = function launch(argv0Name) {
|
|
56
|
+
const binPath = resolveBinary();
|
|
57
|
+
const opts = { stdio: "inherit", windowsHide: true };
|
|
58
|
+
if (argv0Name) opts.argv0 = argv0Name;
|
|
59
|
+
const result = spawnSync(binPath, process.argv.slice(2), opts);
|
|
60
|
+
if (result.error) {
|
|
61
|
+
console.error(`@nubjs/nub: failed to launch ${binPath}: ${result.error.message}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
process.exit(result.status == null ? 1 : result.status);
|
|
65
|
+
};
|
package/bin/nub
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#!/bin/
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// Entry point for the `nub` command. On POSIX this file is replaced by a symlink
|
|
4
|
+
// to the native binary at install time (see postinstall.js); it only executes via
|
|
5
|
+
// Node on Windows or as a fallback. No argv0 override → the child sees the binary's
|
|
6
|
+
// own basename ("nub") and runs the default verb.
|
|
7
|
+
require("./launch.js")();
|
package/bin/nubx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// Entry point for the `nubx` command (npx-equivalent bin runner). On POSIX this
|
|
4
|
+
// file is replaced by a symlink to the native binary at install time; it only
|
|
5
|
+
// executes via Node on Windows or as a fallback. argv0 "nubx" makes the Rust CLI
|
|
6
|
+
// enter exec mode directly (Argv0::Nubx), identical to the POSIX symlink whose
|
|
7
|
+
// basename is "nubx".
|
|
8
|
+
require("./launch.js")("nubx");
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubjs/nub",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "TypeScript-first developer supertool — a fast script runner and TS runtime powered by Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/colinhacks/nub",
|
|
7
7
|
"homepage": "https://github.com/colinhacks/nub",
|
|
8
8
|
"bin": {
|
|
9
9
|
"nub": "bin/nub",
|
|
10
|
-
"nubx": "bin/
|
|
10
|
+
"nubx": "bin/nubx"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"bin",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"postinstall": "node postinstall.js"
|
|
18
18
|
},
|
|
19
19
|
"optionalDependencies": {
|
|
20
|
-
"@nubjs/nub-darwin-arm64": "0.0.
|
|
21
|
-
"@nubjs/nub-darwin-x64": "0.0.
|
|
22
|
-
"@nubjs/nub-linux-x64": "0.0.
|
|
23
|
-
"@nubjs/nub-linux-x64-musl": "0.0.
|
|
24
|
-
"@nubjs/nub-linux-arm64": "0.0.
|
|
25
|
-
"@nubjs/nub-linux-arm64-musl": "0.0.
|
|
26
|
-
"@nubjs/nub-win32-x64": "0.0.
|
|
27
|
-
"@nubjs/nub-win32-arm64": "0.0.
|
|
20
|
+
"@nubjs/nub-darwin-arm64": "0.0.9",
|
|
21
|
+
"@nubjs/nub-darwin-x64": "0.0.9",
|
|
22
|
+
"@nubjs/nub-linux-x64": "0.0.9",
|
|
23
|
+
"@nubjs/nub-linux-x64-musl": "0.0.9",
|
|
24
|
+
"@nubjs/nub-linux-arm64": "0.0.9",
|
|
25
|
+
"@nubjs/nub-linux-arm64-musl": "0.0.9",
|
|
26
|
+
"@nubjs/nub-win32-x64": "0.0.9",
|
|
27
|
+
"@nubjs/nub-win32-arm64": "0.0.9"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/postinstall.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { platform, arch } = process;
|
|
2
|
-
const {
|
|
3
|
-
const { join
|
|
2
|
+
const { mkdirSync, unlinkSync, symlinkSync, copyFileSync, chmodSync } = require("fs");
|
|
3
|
+
const { join } = require("path");
|
|
4
4
|
|
|
5
5
|
const PLATFORMS = {
|
|
6
6
|
"darwin-arm64": "@nubjs/nub-darwin-arm64",
|
|
@@ -29,36 +29,46 @@ if (!pkg) {
|
|
|
29
29
|
process.exit(0);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// Windows: there is no symlink fast path. npm's generated nub.cmd / nubx.cmd invoke
|
|
33
|
+
// the JS launchers (bin/nub, bin/nubx), which resolve and spawn the platform .exe at
|
|
34
|
+
// runtime. Nothing to do at install time — leave the launchers in place.
|
|
35
|
+
if (platform === "win32") {
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
let binSrc;
|
|
33
40
|
try {
|
|
34
|
-
|
|
35
|
-
binSrc = require.resolve(`${pkg}/bin/nub${ext}`);
|
|
41
|
+
binSrc = require.resolve(`${pkg}/bin/nub`);
|
|
36
42
|
} catch {
|
|
37
|
-
// optionalDependency not installed (wrong platform) —
|
|
43
|
+
// optionalDependency not installed (wrong platform) — leave the JS launchers as a
|
|
44
|
+
// fallback; they print an actionable error if invoked.
|
|
38
45
|
process.exit(0);
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
// POSIX fast path: replace each JS launcher with a direct symlink to the platform
|
|
49
|
+
// binary, so `nub` and `nubx` exec the native Rust binary with no Node bootstrap.
|
|
50
|
+
// Both names point at the SAME binary; the Rust CLI selects its verb from argv[0]'s
|
|
51
|
+
// basename (nub vs nubx — see crates/nub-cli/src/cli.rs Argv0::detect), and
|
|
52
|
+
// process.execPath still resolves to the platform binary so the sibling runtime/
|
|
53
|
+
// directory is found by walking up.
|
|
41
54
|
const binDir = join(__dirname, "bin");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Remove placeholder
|
|
47
|
-
try { require("fs").unlinkSync(binDest); } catch {}
|
|
48
|
-
// Symlink to platform package binary (keeps runtime/ findable via walk-up)
|
|
49
|
-
if (platform === "win32") {
|
|
50
|
-
copyFileSync(binSrc, binDest);
|
|
51
|
-
} else {
|
|
52
|
-
require("fs").symlinkSync(binSrc, binDest);
|
|
53
|
-
}
|
|
54
|
-
chmodSync(binSrc, 0o755);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
// Fallback: copy if symlink fails (e.g., cross-device)
|
|
55
|
+
mkdirSync(binDir, { recursive: true });
|
|
56
|
+
for (const name of ["nub", "nubx"]) {
|
|
57
|
+
const dest = join(binDir, name);
|
|
58
|
+
try { unlinkSync(dest); } catch {}
|
|
57
59
|
try {
|
|
58
|
-
|
|
59
|
-
chmodSync(
|
|
60
|
-
} catch
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
symlinkSync(binSrc, dest);
|
|
61
|
+
chmodSync(dest, 0o755);
|
|
62
|
+
} catch {
|
|
63
|
+
// Fallback: copy if symlink fails (e.g. cross-device). Slower path resolution
|
|
64
|
+
// but correct — argv[0] still resolves to a binary named nub/nubx.
|
|
65
|
+
try {
|
|
66
|
+
copyFileSync(binSrc, dest);
|
|
67
|
+
chmodSync(dest, 0o755);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error(`@nubjs/nub: failed to install ${name} binary: ${err.message}`);
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
}
|
|
74
|
+
chmodSync(binSrc, 0o755);
|