shuvcode 2.0.0-alpha-1 → 2.0.0-alpha-2

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.
@@ -9,17 +9,16 @@ import { fileURLToPath } from "node:url"
9
9
 
10
10
  const directory = path.dirname(fileURLToPath(import.meta.url))
11
11
  const require = createRequire(import.meta.url)
12
- const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"))
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "../package.json"), "utf8"))
13
13
  const command = Object.keys(packageJson.bin ?? {})[0]
14
- if (!command) throw new Error("Shuvcode package does not declare a binary")
14
+ if (!command) fail("Shuvcode package does not declare a binary")
15
15
 
16
16
  const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] ?? os.platform()
17
17
  const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] ?? os.arch()
18
18
  const sourceBinary = platform === "windows" ? `${command}.exe` : command
19
- const targetBinary = path.resolve(directory, packageJson.bin[command])
20
19
  const dependencies = packageJson.optionalDependencies ?? {}
21
20
  const base = Object.keys(dependencies).find((name) => name.endsWith(`-${platform}-${arch}`))
22
- if (!base) throw new Error(`Shuvcode does not provide a binary for ${platform}-${arch}`)
21
+ if (!base) fail(`Shuvcode does not provide a binary for ${platform}-${arch}`)
23
22
 
24
23
  function supportsAvx2() {
25
24
  if (arch !== "x64") return false
@@ -31,33 +30,25 @@ function supportsAvx2() {
31
30
  }
32
31
  }
33
32
  if (platform === "darwin") {
34
- try {
35
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
36
- encoding: "utf8",
37
- timeout: 1500,
38
- })
39
- return result.status === 0 && (result.stdout || "").trim() === "1"
40
- } catch {
41
- return false
42
- }
33
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
34
+ encoding: "utf8",
35
+ timeout: 1500,
36
+ })
37
+ return result.status === 0 && (result.stdout || "").trim() === "1"
43
38
  }
44
39
  if (platform === "windows") {
45
40
  const script =
46
41
  '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
47
42
  for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
48
- try {
49
- const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", script], {
50
- encoding: "utf8",
51
- timeout: 3000,
52
- windowsHide: true,
53
- })
54
- if (result.status !== 0) continue
55
- const output = (result.stdout || "").trim().toLowerCase()
56
- if (output === "true" || output === "1") return true
57
- if (output === "false" || output === "0") return false
58
- } catch {
59
- continue
60
- }
43
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", script], {
44
+ encoding: "utf8",
45
+ timeout: 3000,
46
+ windowsHide: true,
47
+ })
48
+ if (result.status !== 0) continue
49
+ const output = (result.stdout || "").trim().toLowerCase()
50
+ if (output === "true" || output === "1") return true
51
+ if (output === "false" || output === "0") return false
61
52
  }
62
53
  }
63
54
  return false
@@ -97,75 +88,34 @@ function packageNames() {
97
88
  return names.filter((name) => dependencies[name])
98
89
  }
99
90
 
100
- function copyBinary(source) {
101
- if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
102
- fs.mkdirSync(path.dirname(targetBinary), { recursive: true })
103
- if (fs.existsSync(targetBinary)) fs.unlinkSync(targetBinary)
104
- try {
105
- fs.linkSync(source, targetBinary)
106
- } catch {
107
- fs.copyFileSync(source, targetBinary)
108
- }
109
- fs.chmodSync(targetBinary, 0o755)
110
- }
111
-
112
91
  function resolveBinary(name) {
113
92
  const packagePath = require.resolve(`${name}/package.json`)
114
- return path.join(path.dirname(packagePath), "bin", sourceBinary)
93
+ const binary = path.join(path.dirname(packagePath), "bin", sourceBinary)
94
+ if (!fs.existsSync(binary)) throw new Error(`Binary not found at ${binary}`)
95
+ return binary
115
96
  }
116
97
 
117
- function installPackage(name) {
118
- const temp = fs.mkdtempSync(path.join(os.tmpdir(), "shuvcode-install-"))
119
- try {
120
- const result = childProcess.spawnSync(
121
- "npm",
122
- [
123
- "install",
124
- "--ignore-scripts",
125
- "--no-save",
126
- "--loglevel=error",
127
- "--prefix",
128
- temp,
129
- `${name}@${dependencies[name]}`,
130
- ],
131
- { stdio: "inherit", windowsHide: true },
132
- )
133
- if (result.status !== 0) return false
134
- copyBinary(path.join(temp, "node_modules", name, "bin", sourceBinary))
135
- return true
136
- } finally {
137
- fs.rmSync(temp, { recursive: true, force: true })
138
- }
139
- }
140
-
141
- function verifyBinary() {
142
- return (
143
- childProcess.spawnSync(targetBinary, ["--version"], {
144
- stdio: "ignore",
145
- windowsHide: true,
146
- }).status === 0
147
- )
98
+ function fail(message) {
99
+ console.error(message)
100
+ process.exit(1)
148
101
  }
149
102
 
150
- function main() {
151
- const names = packageNames()
152
- for (const name of names) {
153
- try {
154
- copyBinary(resolveBinary(name))
155
- if (verifyBinary()) return
156
- } catch {
157
- if (installPackage(name) && verifyBinary()) return
158
- }
103
+ const names = packageNames()
104
+ const binary = names.reduce((result, name) => {
105
+ if (result) return result
106
+ try {
107
+ return resolveBinary(name)
108
+ } catch {
109
+ return undefined
159
110
  }
111
+ }, undefined)
160
112
 
161
- throw new Error(
162
- `Failed to install Shuvcode. Try manually installing ${names.map((name) => JSON.stringify(name)).join(" or ")}.`,
163
- )
164
- }
113
+ if (!binary) fail(`Failed to find Shuvcode binary package. Reinstall ${packageJson.name}.`)
165
114
 
166
- try {
167
- main()
168
- } catch (error) {
169
- console.error(error instanceof Error ? error.message : String(error))
170
- process.exit(1)
171
- }
115
+ const result = childProcess.spawnSync(binary, process.argv.slice(2), {
116
+ stdio: "inherit",
117
+ windowsHide: true,
118
+ })
119
+ if (result.error) fail(result.error.message)
120
+ if (result.signal) process.kill(process.pid, result.signal)
121
+ process.exit(result.status ?? 1)
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "shuvcode",
3
3
  "bin": {
4
- "shuvcode": "./bin/shuvcode.exe"
4
+ "shuvcode": "./bin/launcher.mjs"
5
5
  },
6
- "scripts": {
7
- "postinstall": "node ./postinstall.mjs"
8
- },
9
- "version": "2.0.0-alpha-1",
6
+ "version": "2.0.0-alpha-2",
10
7
  "license": "MIT",
11
8
  "repository": {
12
9
  "type": "git",
@@ -22,17 +19,17 @@
22
19
  "x64"
23
20
  ],
24
21
  "optionalDependencies": {
25
- "shuvcode-darwin-arm64": "2.0.0-alpha-1",
26
- "shuvcode-linux-arm64": "2.0.0-alpha-1",
27
- "shuvcode-linux-x64-baseline": "2.0.0-alpha-1",
28
- "shuvcode-linux-x64": "2.0.0-alpha-1",
29
- "shuvcode-linux-arm64-musl": "2.0.0-alpha-1",
30
- "shuvcode-linux-x64-baseline-musl": "2.0.0-alpha-1",
31
- "shuvcode-darwin-x64": "2.0.0-alpha-1",
32
- "shuvcode-windows-x64": "2.0.0-alpha-1",
33
- "shuvcode-linux-x64-musl": "2.0.0-alpha-1",
34
- "shuvcode-darwin-x64-baseline": "2.0.0-alpha-1",
35
- "shuvcode-windows-x64-baseline": "2.0.0-alpha-1",
36
- "shuvcode-windows-arm64": "2.0.0-alpha-1"
22
+ "shuvcode-linux-arm64": "2.0.0-alpha-2",
23
+ "shuvcode-linux-x64-baseline": "2.0.0-alpha-2",
24
+ "shuvcode-linux-x64-musl": "2.0.0-alpha-2",
25
+ "shuvcode-linux-x64-baseline-musl": "2.0.0-alpha-2",
26
+ "shuvcode-darwin-arm64": "2.0.0-alpha-2",
27
+ "shuvcode-linux-x64": "2.0.0-alpha-2",
28
+ "shuvcode-darwin-x64": "2.0.0-alpha-2",
29
+ "shuvcode-windows-x64": "2.0.0-alpha-2",
30
+ "shuvcode-windows-x64-baseline": "2.0.0-alpha-2",
31
+ "shuvcode-windows-arm64": "2.0.0-alpha-2",
32
+ "shuvcode-linux-arm64-musl": "2.0.0-alpha-2",
33
+ "shuvcode-darwin-x64-baseline": "2.0.0-alpha-2"
37
34
  }
38
35
  }
package/bin/shuvcode.exe DELETED
@@ -1,5 +0,0 @@
1
- echo "Error: shuvcode's postinstall script was not run." >&2
2
- echo "" >&2
3
- echo "This occurs when installation scripts are disabled." >&2
4
- echo "Run the package postinstall script or reinstall with scripts enabled." >&2
5
- exit 1