shuvcode 2.3.1-shuv.1 → 2.3.1-shuv.3

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.
Files changed (2) hide show
  1. package/bin/launcher.mjs +51 -43
  2. package/package.json +13 -13
package/bin/launcher.mjs CHANGED
@@ -56,36 +56,35 @@ function supportsAvx2() {
56
56
 
57
57
  function isMusl() {
58
58
  if (platform !== "linux") return false
59
- try {
60
- if (fs.existsSync("/etc/alpine-release")) return true
61
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
62
- return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
63
- } catch {
64
- return false
65
- }
59
+ if (fs.existsSync("/etc/alpine-release")) return true
60
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8", timeout: 1500 })
61
+ const output = `${result.stdout || ""}${result.stderr || ""}`.toLowerCase()
62
+ if (output.includes("musl")) return true
63
+ if (output.includes("glibc") || output.includes("gnu libc")) return false
64
+ return !process.report?.getReport?.()?.header?.glibcVersionRuntime
66
65
  }
67
66
 
68
67
  function packageNames() {
69
68
  const baseline = arch === "x64" && !supportsAvx2()
70
- const names =
71
- platform === "linux"
72
- ? isMusl()
73
- ? arch === "x64"
74
- ? baseline
75
- ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
76
- : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
77
- : [`${base}-musl`, base]
78
- : arch === "x64"
79
- ? baseline
80
- ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
81
- : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
82
- : [base, `${base}-musl`]
83
- : arch === "x64"
84
- ? baseline
85
- ? [`${base}-baseline`, base]
86
- : [base, `${base}-baseline`]
87
- : [base]
88
- return names.filter((name) => dependencies[name])
69
+ const musl = platform === "linux" && isMusl()
70
+ // A binary built for the other libc fails at exec time with a loader error, so never fall back across libc.
71
+ const names = musl
72
+ ? arch === "x64"
73
+ ? baseline
74
+ ? [`${base}-baseline-musl`, `${base}-musl`]
75
+ : [`${base}-musl`, `${base}-baseline-musl`]
76
+ : [`${base}-musl`]
77
+ : arch === "x64"
78
+ ? baseline
79
+ ? [`${base}-baseline`, base]
80
+ : [base, `${base}-baseline`]
81
+ : [base]
82
+ const candidates = names.filter((name) => dependencies[name])
83
+ if (candidates.length === 0)
84
+ fail(
85
+ `${packageJson.name}@${packageJson.version} does not provide a ${platform === "linux" ? `Linux ${musl ? "musl" : "glibc"}` : platform} binary for ${arch}.`,
86
+ )
87
+ return candidates
89
88
  }
90
89
 
91
90
  function resolveBinary(name) {
@@ -94,7 +93,9 @@ function resolveBinary(name) {
94
93
  // which would silently run the previous release under the new launcher.
95
94
  const version = JSON.parse(fs.readFileSync(packagePath, "utf8")).version
96
95
  if (version !== dependencies[name]) {
97
- const error = new Error(`${name} is ${version}, expected ${dependencies[name]}`)
96
+ const error = new Error(
97
+ `${name} is ${version}, expected ${dependencies[name]}. Reinstall ${packageJson.name}@${packageJson.version}.`,
98
+ )
98
99
  error.code = "STALE_PLATFORM_BINARY"
99
100
  throw error
100
101
  }
@@ -109,23 +110,30 @@ function fail(message) {
109
110
  }
110
111
 
111
112
  const names = packageNames()
112
- const binary = (() => {
113
- try {
114
- return names.reduce((result, name) => {
115
- if (result) return result
116
- try {
117
- return resolveBinary(name)
118
- } catch (error) {
119
- if (error && error.code === "STALE_PLATFORM_BINARY") throw error
120
- return undefined
121
- }
122
- }, undefined)
123
- } catch (error) {
124
- fail(error instanceof Error ? error.message : String(error))
125
- }
126
- })()
113
+ // A stale candidate (for example one hoisted into a parent node_modules) only fails the launch
114
+ // when no other compatible candidate resolves at the expected version.
115
+ const resolved = names.reduce(
116
+ (result, name) => {
117
+ if (result.binary) return result
118
+ try {
119
+ return { ...result, binary: resolveBinary(name) }
120
+ } catch (error) {
121
+ if (error && error.code === "STALE_PLATFORM_BINARY") return { ...result, stale: result.stale ?? error }
122
+ if (error && error.code === "MODULE_NOT_FOUND") return result
123
+ return { ...result, broken: result.broken ?? error }
124
+ }
125
+ },
126
+ { binary: undefined, stale: undefined, broken: undefined },
127
+ )
127
128
 
128
- if (!binary) fail(`Failed to find Shuvcode binary package. Reinstall ${packageJson.name}.`)
129
+ if (!resolved.binary && resolved.stale) fail(resolved.stale.message)
130
+ if (!resolved.binary && resolved.broken)
131
+ fail(`${resolved.broken.message}. Reinstall ${packageJson.name}@${packageJson.version}.`)
132
+ if (!resolved.binary)
133
+ fail(
134
+ `Missing platform binary package ${names[0]}@${dependencies[names[0]]}. Reinstall ${packageJson.name}@${packageJson.version}.`,
135
+ )
136
+ const binary = resolved.binary
129
137
 
130
138
  const result = childProcess.spawnSync(binary, process.argv.slice(2), {
131
139
  stdio: "inherit",
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "import": "./client/index.js"
15
15
  }
16
16
  },
17
- "version": "2.3.1-shuv.1",
17
+ "version": "2.3.1-shuv.3",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -30,17 +30,17 @@
30
30
  "x64"
31
31
  ],
32
32
  "optionalDependencies": {
33
- "shuvcode-windows-x64-baseline": "2.3.1-shuv.1",
34
- "shuvcode-windows-arm64": "2.3.1-shuv.1",
35
- "shuvcode-linux-x64-baseline-musl": "2.3.1-shuv.1",
36
- "shuvcode-darwin-arm64": "2.3.1-shuv.1",
37
- "shuvcode-darwin-x64-baseline": "2.3.1-shuv.1",
38
- "shuvcode-linux-arm64": "2.3.1-shuv.1",
39
- "shuvcode-linux-x64-musl": "2.3.1-shuv.1",
40
- "shuvcode-linux-x64-baseline": "2.3.1-shuv.1",
41
- "shuvcode-windows-x64": "2.3.1-shuv.1",
42
- "shuvcode-linux-arm64-musl": "2.3.1-shuv.1",
43
- "shuvcode-linux-x64": "2.3.1-shuv.1",
44
- "shuvcode-darwin-x64": "2.3.1-shuv.1"
33
+ "shuvcode-windows-x64-baseline": "2.3.1-shuv.3",
34
+ "shuvcode-windows-x64": "2.3.1-shuv.3",
35
+ "shuvcode-linux-arm64": "2.3.1-shuv.3",
36
+ "shuvcode-darwin-x64-baseline": "2.3.1-shuv.3",
37
+ "shuvcode-linux-x64-baseline-musl": "2.3.1-shuv.3",
38
+ "shuvcode-linux-arm64-musl": "2.3.1-shuv.3",
39
+ "shuvcode-windows-arm64": "2.3.1-shuv.3",
40
+ "shuvcode-darwin-x64": "2.3.1-shuv.3",
41
+ "shuvcode-linux-x64-baseline": "2.3.1-shuv.3",
42
+ "shuvcode-darwin-arm64": "2.3.1-shuv.3",
43
+ "shuvcode-linux-x64": "2.3.1-shuv.3",
44
+ "shuvcode-linux-x64-musl": "2.3.1-shuv.3"
45
45
  }
46
46
  }