@nubjs/nub 0.0.9 → 0.0.11

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 CHANGED
@@ -12,38 +12,17 @@
12
12
  // crates/nub-cli/src/cli.rs Argv0::detect). spawnSync's `argv0` option sets that
13
13
  // basename for the child without changing process.execPath, so the binary still
14
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
- };
15
+ const { spawnSync } = require("child_process");
16
+ const { platformPackage } = require("../platform.js");
27
17
 
28
18
  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];
19
+ const { key, pkg } = platformPackage();
41
20
  if (!pkg) {
42
- console.error(`@nubjs/nub: no prebuilt binary for ${platform}-${arch}`);
21
+ console.error(`@nubjs/nub: no prebuilt binary for ${key}`);
43
22
  process.exit(1);
44
23
  }
45
24
  try {
46
- return require.resolve(`${pkg}/bin/nub${platform === "win32" ? ".exe" : ""}`);
25
+ return require.resolve(`${pkg}/bin/nub${process.platform === "win32" ? ".exe" : ""}`);
47
26
  } catch {
48
27
  console.error(`@nubjs/nub: the ${pkg} package is not installed. Try: npm rebuild @nubjs/nub`);
49
28
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubjs/nub",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
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",
@@ -11,19 +11,20 @@
11
11
  },
12
12
  "files": [
13
13
  "bin",
14
+ "platform.js",
14
15
  "postinstall.js"
15
16
  ],
16
17
  "scripts": {
17
18
  "postinstall": "node postinstall.js"
18
19
  },
19
20
  "optionalDependencies": {
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"
21
+ "@nubjs/nub-darwin-arm64": "0.0.11",
22
+ "@nubjs/nub-darwin-x64": "0.0.11",
23
+ "@nubjs/nub-linux-x64": "0.0.11",
24
+ "@nubjs/nub-linux-x64-musl": "0.0.11",
25
+ "@nubjs/nub-linux-arm64": "0.0.11",
26
+ "@nubjs/nub-linux-arm64-musl": "0.0.11",
27
+ "@nubjs/nub-win32-x64": "0.0.11",
28
+ "@nubjs/nub-win32-arm64": "0.0.11"
28
29
  }
29
30
  }
package/platform.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ // Platform → @nubjs/nub-<platform> package selection, shared by postinstall.js
3
+ // (install-time symlink/copy of the native binary) and bin/launch.js (runtime
4
+ // spawn). Keep the musl detection in ONE place — it shipped wrong in 0.0.10
5
+ // duplicated across both files (see isMusl below).
6
+
7
+ const PLATFORMS = {
8
+ "darwin-arm64": "@nubjs/nub-darwin-arm64",
9
+ "darwin-x64": "@nubjs/nub-darwin-x64",
10
+ "linux-x64": "@nubjs/nub-linux-x64",
11
+ "linux-x64-musl": "@nubjs/nub-linux-x64-musl",
12
+ "linux-arm64": "@nubjs/nub-linux-arm64",
13
+ "linux-arm64-musl": "@nubjs/nub-linux-arm64-musl",
14
+ "win32-x64": "@nubjs/nub-win32-x64",
15
+ "win32-arm64": "@nubjs/nub-win32-arm64",
16
+ };
17
+
18
+ // True on a musl Linux (Alpine, etc.), where the `-musl` platform package is the
19
+ // one npm installs and the one the binary must come from.
20
+ //
21
+ // Primary signal: Node's own diagnostic report. `header.glibcVersionRuntime` is
22
+ // present on glibc and ABSENT on musl — no subprocess, and what detect-libc keys
23
+ // on. Fallback: `ldd --version`, which on musl exits NON-ZERO and prints
24
+ // "musl libc …". 0.0.10 shipped a detection that, in that throw path, checked only
25
+ // `e.stderr` — but with `2>&1` the text lands in `e.stdout`, so musl read as glibc
26
+ // and the launcher resolved the wrong (uninstalled) package. Check the merged output.
27
+ function isMusl() {
28
+ if (process.platform !== "linux") return false;
29
+ try {
30
+ const report = process.report.getReport();
31
+ const header = (typeof report === "string" ? JSON.parse(report) : report).header;
32
+ if (header && "glibcVersionRuntime" in header) {
33
+ return !header.glibcVersionRuntime;
34
+ }
35
+ } catch {
36
+ // process.report unavailable — fall through to ldd.
37
+ }
38
+ try {
39
+ const out = require("child_process").execSync("ldd --version 2>&1", { encoding: "utf8" });
40
+ return out.includes("musl");
41
+ } catch (e) {
42
+ return (((e && e.stdout) || "") + ((e && e.stderr) || "")).includes("musl");
43
+ }
44
+ }
45
+
46
+ // { key, pkg }. `pkg` is undefined for an unsupported platform.
47
+ function platformPackage() {
48
+ const key = `${process.platform}-${process.arch}${isMusl() ? "-musl" : ""}`;
49
+ return { key, pkg: PLATFORMS[key] };
50
+ }
51
+
52
+ module.exports = { PLATFORMS, isMusl, platformPackage };
package/postinstall.js CHANGED
@@ -1,31 +1,12 @@
1
- const { platform, arch } = process;
1
+ const { platform } = process;
2
2
  const { mkdirSync, unlinkSync, symlinkSync, copyFileSync, chmodSync } = require("fs");
3
3
  const { join } = require("path");
4
+ const { platformPackage } = require("./platform.js");
4
5
 
5
- const PLATFORMS = {
6
- "darwin-arm64": "@nubjs/nub-darwin-arm64",
7
- "darwin-x64": "@nubjs/nub-darwin-x64",
8
- "linux-x64": "@nubjs/nub-linux-x64",
9
- "linux-x64-musl": "@nubjs/nub-linux-x64-musl",
10
- "linux-arm64": "@nubjs/nub-linux-arm64",
11
- "linux-arm64-musl": "@nubjs/nub-linux-arm64-musl",
12
- "win32-x64": "@nubjs/nub-win32-x64",
13
- "win32-arm64": "@nubjs/nub-win32-arm64",
14
- };
15
-
16
- const isMusl = platform === "linux" && (() => {
17
- try {
18
- return require("child_process").execSync("ldd --version 2>&1", { encoding: "utf8" }).includes("musl");
19
- } catch (e) {
20
- return (e.stderr || "").includes("musl");
21
- }
22
- })();
23
-
24
- const key = `${platform}-${arch}${isMusl ? "-musl" : ""}`;
25
- const pkg = PLATFORMS[key];
6
+ const { key, pkg } = platformPackage();
26
7
 
27
8
  if (!pkg) {
28
- console.error(`@nubjs/nub: no prebuilt binary for ${platform}-${arch}`);
9
+ console.error(`@nubjs/nub: no prebuilt binary for ${key}`);
29
10
  process.exit(0);
30
11
  }
31
12