shuvcode 1.1.56 → 1.2.6

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/shuvcode +101 -12
  2. package/package.json +12 -12
package/bin/shuvcode CHANGED
@@ -47,20 +47,109 @@ if (!arch) {
47
47
  const base = "shuvcode-" + platform + "-" + arch
48
48
  const binary = platform === "windows" ? "shuvcode.exe" : "shuvcode"
49
49
 
50
+ function supportsAvx2() {
51
+ if (arch !== "x64") return false
52
+
53
+ if (platform === "linux") {
54
+ try {
55
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
56
+ } catch {
57
+ return false
58
+ }
59
+ }
60
+
61
+ if (platform === "darwin") {
62
+ try {
63
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
64
+ encoding: "utf8",
65
+ timeout: 1500,
66
+ })
67
+ if (result.status !== 0) return false
68
+ return (result.stdout || "").trim() === "1"
69
+ } catch {
70
+ return false
71
+ }
72
+ }
73
+
74
+ if (platform === "windows") {
75
+ const cmd =
76
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
77
+
78
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
79
+ try {
80
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
81
+ encoding: "utf8",
82
+ timeout: 3000,
83
+ windowsHide: true,
84
+ })
85
+ if (result.status !== 0) continue
86
+ const out = (result.stdout || "").trim().toLowerCase()
87
+ if (out === "true" || out === "1") return true
88
+ if (out === "false" || out === "0") return false
89
+ } catch {
90
+ continue
91
+ }
92
+ }
93
+
94
+ return false
95
+ }
96
+
97
+ return false
98
+ }
99
+
100
+ const names = (() => {
101
+ const avx2 = supportsAvx2()
102
+ const baseline = arch === "x64" && !avx2
103
+
104
+ if (platform === "linux") {
105
+ const musl = (() => {
106
+ try {
107
+ if (fs.existsSync("/etc/alpine-release")) return true
108
+ } catch {
109
+ // ignore
110
+ }
111
+
112
+ try {
113
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
114
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
115
+ if (text.includes("musl")) return true
116
+ } catch {
117
+ // ignore
118
+ }
119
+
120
+ return false
121
+ })()
122
+
123
+ if (musl) {
124
+ if (arch === "x64") {
125
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
126
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
127
+ }
128
+ return [`${base}-musl`, base]
129
+ }
130
+
131
+ if (arch === "x64") {
132
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
133
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
134
+ }
135
+ return [base, `${base}-musl`]
136
+ }
137
+
138
+ if (arch === "x64") {
139
+ if (baseline) return [`${base}-baseline`, base]
140
+ return [base, `${base}-baseline`]
141
+ }
142
+ return [base]
143
+ })()
144
+
50
145
  function findBinary(startDir) {
51
146
  let current = startDir
52
147
  for (;;) {
53
148
  const modules = path.join(current, "node_modules")
54
149
  if (fs.existsSync(modules)) {
55
- const entries = fs.readdirSync(modules)
56
- for (const entry of entries) {
57
- if (!entry.startsWith(base)) {
58
- continue
59
- }
60
- const candidate = path.join(modules, entry, "bin", binary)
61
- if (fs.existsSync(candidate)) {
62
- return candidate
63
- }
150
+ for (const name of names) {
151
+ const candidate = path.join(modules, name, "bin", binary)
152
+ if (fs.existsSync(candidate)) return candidate
64
153
  }
65
154
  }
66
155
  const parent = path.dirname(current)
@@ -74,9 +163,9 @@ function findBinary(startDir) {
74
163
  const resolved = findBinary(scriptDir)
75
164
  if (!resolved) {
76
165
  console.error(
77
- 'It seems that your package manager failed to install the right version of shuvcode for your platform. You can try manually installing the "' +
78
- base +
79
- '" package',
166
+ "It seems that your package manager failed to install the right version of shuvcode for your platform. You can try manually installing " +
167
+ names.map((n) => `\"${n}\"`).join(" or ") +
168
+ " package",
80
169
  )
81
170
  process.exit(1)
82
171
  }
package/package.json CHANGED
@@ -6,20 +6,20 @@
6
6
  "scripts": {
7
7
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
8
  },
9
- "version": "1.1.56",
9
+ "version": "1.2.6",
10
10
  "license": "MIT",
11
11
  "optionalDependencies": {
12
- "shuvcode-linux-arm64": "1.1.56",
13
- "shuvcode-linux-x64": "1.1.56",
14
- "shuvcode-linux-x64-baseline": "1.1.56",
15
- "shuvcode-linux-arm64-musl": "1.1.56",
16
- "shuvcode-linux-x64-musl": "1.1.56",
17
- "shuvcode-linux-x64-baseline-musl": "1.1.56",
18
- "shuvcode-darwin-arm64": "1.1.56",
19
- "shuvcode-darwin-x64": "1.1.56",
20
- "shuvcode-darwin-x64-baseline": "1.1.56",
21
- "shuvcode-windows-x64": "1.1.56",
22
- "shuvcode-windows-x64-baseline": "1.1.56"
12
+ "shuvcode-linux-arm64": "1.2.6",
13
+ "shuvcode-linux-x64": "1.2.6",
14
+ "shuvcode-linux-x64-baseline": "1.2.6",
15
+ "shuvcode-linux-arm64-musl": "1.2.6",
16
+ "shuvcode-linux-x64-musl": "1.2.6",
17
+ "shuvcode-linux-x64-baseline-musl": "1.2.6",
18
+ "shuvcode-darwin-arm64": "1.2.6",
19
+ "shuvcode-darwin-x64": "1.2.6",
20
+ "shuvcode-darwin-x64-baseline": "1.2.6",
21
+ "shuvcode-windows-x64": "1.2.6",
22
+ "shuvcode-windows-x64-baseline": "1.2.6"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",