shuvcode 1.2.27 → 2.0.0-alpha-1

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.
@@ -0,0 +1,5 @@
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
package/package.json CHANGED
@@ -1,29 +1,38 @@
1
1
  {
2
2
  "name": "shuvcode",
3
3
  "bin": {
4
- "shuvcode": "./bin/shuvcode"
4
+ "shuvcode": "./bin/shuvcode.exe"
5
5
  },
6
6
  "scripts": {
7
- "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
7
+ "postinstall": "node ./postinstall.mjs"
8
8
  },
9
- "version": "1.2.27",
9
+ "version": "2.0.0-alpha-1",
10
10
  "license": "MIT",
11
- "optionalDependencies": {
12
- "shuvcode-linux-arm64": "1.2.27",
13
- "shuvcode-linux-x64": "1.2.27",
14
- "shuvcode-linux-x64-baseline": "1.2.27",
15
- "shuvcode-linux-arm64-musl": "1.2.27",
16
- "shuvcode-linux-x64-musl": "1.2.27",
17
- "shuvcode-linux-x64-baseline-musl": "1.2.27",
18
- "shuvcode-darwin-arm64": "1.2.27",
19
- "shuvcode-darwin-x64": "1.2.27",
20
- "shuvcode-darwin-x64-baseline": "1.2.27",
21
- "shuvcode-windows-arm64": "1.2.27",
22
- "shuvcode-windows-x64": "1.2.27",
23
- "shuvcode-windows-x64-baseline": "1.2.27"
24
- },
25
11
  "repository": {
26
12
  "type": "git",
27
- "url": "https://github.com/Latitudes-Dev/shuvcode"
13
+ "url": "git+https://github.com/Latitudes-Dev/shuvcode.git"
14
+ },
15
+ "os": [
16
+ "darwin",
17
+ "linux",
18
+ "win32"
19
+ ],
20
+ "cpu": [
21
+ "arm64",
22
+ "x64"
23
+ ],
24
+ "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"
28
37
  }
29
38
  }
package/postinstall.mjs CHANGED
@@ -1,131 +1,171 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from "fs"
4
- import path from "path"
5
- import os from "os"
6
- import { fileURLToPath } from "url"
7
- import { createRequire } from "module"
8
-
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
3
+ import childProcess from "node:child_process"
4
+ import fs from "node:fs"
5
+ import os from "node:os"
6
+ import path from "node:path"
7
+ import { createRequire } from "node:module"
8
+ import { fileURLToPath } from "node:url"
9
+
10
+ const directory = path.dirname(fileURLToPath(import.meta.url))
10
11
  const require = createRequire(import.meta.url)
11
-
12
- function detectPlatformAndArch() {
13
- // Map platform names
14
- let platform
15
- switch (os.platform()) {
16
- case "darwin":
17
- platform = "darwin"
18
- break
19
- case "linux":
20
- platform = "linux"
21
- break
22
- case "win32":
23
- platform = "windows"
24
- break
25
- default:
26
- platform = os.platform()
27
- break
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"))
13
+ const command = Object.keys(packageJson.bin ?? {})[0]
14
+ if (!command) throw new Error("Shuvcode package does not declare a binary")
15
+
16
+ const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] ?? os.platform()
17
+ const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] ?? os.arch()
18
+ const sourceBinary = platform === "windows" ? `${command}.exe` : command
19
+ const targetBinary = path.resolve(directory, packageJson.bin[command])
20
+ const dependencies = packageJson.optionalDependencies ?? {}
21
+ 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}`)
23
+
24
+ function supportsAvx2() {
25
+ if (arch !== "x64") return false
26
+ if (platform === "linux") {
27
+ try {
28
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
29
+ } catch {
30
+ return false
31
+ }
28
32
  }
29
-
30
- // Map architecture names
31
- let arch
32
- switch (os.arch()) {
33
- case "x64":
34
- arch = "x64"
35
- break
36
- case "arm64":
37
- arch = "arm64"
38
- break
39
- case "arm":
40
- arch = "arm"
41
- break
42
- default:
43
- arch = os.arch()
44
- break
33
+ 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
+ }
45
43
  }
46
-
47
- return { platform, arch }
44
+ if (platform === "windows") {
45
+ const script =
46
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
47
+ 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
+ }
61
+ }
62
+ }
63
+ return false
48
64
  }
49
65
 
50
- function findBinary() {
51
- const { platform, arch } = detectPlatformAndArch()
52
- const packageName = `shuvcode-${platform}-${arch}`
53
- const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
54
-
66
+ function isMusl() {
67
+ if (platform !== "linux") return false
55
68
  try {
56
- // Use require.resolve to find the package
57
- const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
- const packageDir = path.dirname(packageJsonPath)
59
- const binaryPath = path.join(packageDir, "bin", binaryName)
60
-
61
- if (!fs.existsSync(binaryPath)) {
62
- throw new Error(`Binary not found at ${binaryPath}`)
63
- }
64
-
65
- return { binaryPath, binaryName }
66
- } catch (error) {
67
- throw new Error(`Could not find package ${packageName}: ${error.message}`)
69
+ if (fs.existsSync("/etc/alpine-release")) return true
70
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
71
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
72
+ } catch {
73
+ return false
68
74
  }
69
75
  }
70
76
 
71
- function prepareBinDirectory(binaryName) {
72
- const binDir = path.join(__dirname, "bin")
73
- const targetPath = path.join(binDir, binaryName)
74
-
75
- // Ensure bin directory exists
76
- if (!fs.existsSync(binDir)) {
77
- fs.mkdirSync(binDir, { recursive: true })
78
- }
77
+ function packageNames() {
78
+ const baseline = arch === "x64" && !supportsAvx2()
79
+ const names =
80
+ platform === "linux"
81
+ ? isMusl()
82
+ ? arch === "x64"
83
+ ? baseline
84
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
85
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
86
+ : [`${base}-musl`, base]
87
+ : arch === "x64"
88
+ ? baseline
89
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
90
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
91
+ : [base, `${base}-musl`]
92
+ : arch === "x64"
93
+ ? baseline
94
+ ? [`${base}-baseline`, base]
95
+ : [base, `${base}-baseline`]
96
+ : [base]
97
+ return names.filter((name) => dependencies[name])
98
+ }
79
99
 
80
- // Remove existing binary/symlink if it exists
81
- if (fs.existsSync(targetPath)) {
82
- fs.unlinkSync(targetPath)
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)
83
108
  }
84
-
85
- return { binDir, targetPath }
109
+ fs.chmodSync(targetBinary, 0o755)
86
110
  }
87
111
 
88
- function symlinkBinary(sourcePath, binaryName) {
89
- const { targetPath } = prepareBinDirectory(binaryName)
90
-
91
- fs.symlinkSync(sourcePath, targetPath)
92
- console.log(`opencode binary symlinked: ${targetPath} -> ${sourcePath}`)
112
+ function resolveBinary(name) {
113
+ const packagePath = require.resolve(`${name}/package.json`)
114
+ return path.join(path.dirname(packagePath), "bin", sourceBinary)
115
+ }
93
116
 
94
- // Verify the file exists after operation
95
- if (!fs.existsSync(targetPath)) {
96
- throw new Error(`Failed to symlink binary to ${targetPath}`)
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 })
97
138
  }
98
139
  }
99
140
 
100
- async function main() {
101
- try {
102
- if (os.platform() === "win32") {
103
- // On Windows, the .exe is already included in the package and bin field points to it
104
- // No postinstall setup needed
105
- console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
- return
107
- }
141
+ function verifyBinary() {
142
+ return (
143
+ childProcess.spawnSync(targetBinary, ["--version"], {
144
+ stdio: "ignore",
145
+ windowsHide: true,
146
+ }).status === 0
147
+ )
148
+ }
108
149
 
109
- // On non-Windows platforms, just verify the binary package exists
110
- // Don't replace the wrapper script - it handles binary execution
111
- const { binaryPath } = findBinary()
112
- const target = path.join(__dirname, "bin", ".opencode")
113
- if (fs.existsSync(target)) fs.unlinkSync(target)
150
+ function main() {
151
+ const names = packageNames()
152
+ for (const name of names) {
114
153
  try {
115
- fs.linkSync(binaryPath, target)
154
+ copyBinary(resolveBinary(name))
155
+ if (verifyBinary()) return
116
156
  } catch {
117
- fs.copyFileSync(binaryPath, target)
157
+ if (installPackage(name) && verifyBinary()) return
118
158
  }
119
- fs.chmodSync(target, 0o755)
120
- } catch (error) {
121
- console.error("Failed to setup opencode binary:", error.message)
122
- process.exit(1)
123
159
  }
160
+
161
+ throw new Error(
162
+ `Failed to install Shuvcode. Try manually installing ${names.map((name) => JSON.stringify(name)).join(" or ")}.`,
163
+ )
124
164
  }
125
165
 
126
166
  try {
127
167
  main()
128
168
  } catch (error) {
129
- console.error("Postinstall script error:", error.message)
130
- process.exit(0)
169
+ console.error(error instanceof Error ? error.message : String(error))
170
+ process.exit(1)
131
171
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 opencode
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/bin/shuvcode DELETED
@@ -1,179 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const childProcess = require("child_process")
4
- const fs = require("fs")
5
- const path = require("path")
6
- const os = require("os")
7
-
8
- function run(target) {
9
- const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
- stdio: "inherit",
11
- })
12
- if (result.error) {
13
- console.error(result.error.message)
14
- process.exit(1)
15
- }
16
- const code = typeof result.status === "number" ? result.status : 0
17
- process.exit(code)
18
- }
19
-
20
- const envPath = process.env.OPENCODE_BIN_PATH
21
- if (envPath) {
22
- run(envPath)
23
- }
24
-
25
- const scriptPath = fs.realpathSync(__filename)
26
- const scriptDir = path.dirname(scriptPath)
27
-
28
- //
29
- const cached = path.join(scriptDir, ".opencode")
30
- if (fs.existsSync(cached)) {
31
- run(cached)
32
- }
33
-
34
- const platformMap = {
35
- darwin: "darwin",
36
- linux: "linux",
37
- win32: "windows",
38
- }
39
- const archMap = {
40
- x64: "x64",
41
- arm64: "arm64",
42
- arm: "arm",
43
- }
44
-
45
- let platform = platformMap[os.platform()]
46
- if (!platform) {
47
- platform = os.platform()
48
- }
49
- let arch = archMap[os.arch()]
50
- if (!arch) {
51
- arch = os.arch()
52
- }
53
- const base = "shuvcode-" + platform + "-" + arch
54
- const binary = platform === "windows" ? "shuvcode.exe" : "shuvcode"
55
-
56
- function supportsAvx2() {
57
- if (arch !== "x64") return false
58
-
59
- if (platform === "linux") {
60
- try {
61
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
62
- } catch {
63
- return false
64
- }
65
- }
66
-
67
- if (platform === "darwin") {
68
- try {
69
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
70
- encoding: "utf8",
71
- timeout: 1500,
72
- })
73
- if (result.status !== 0) return false
74
- return (result.stdout || "").trim() === "1"
75
- } catch {
76
- return false
77
- }
78
- }
79
-
80
- if (platform === "windows") {
81
- const cmd =
82
- '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
83
-
84
- for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
85
- try {
86
- const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
87
- encoding: "utf8",
88
- timeout: 3000,
89
- windowsHide: true,
90
- })
91
- if (result.status !== 0) continue
92
- const out = (result.stdout || "").trim().toLowerCase()
93
- if (out === "true" || out === "1") return true
94
- if (out === "false" || out === "0") return false
95
- } catch {
96
- continue
97
- }
98
- }
99
-
100
- return false
101
- }
102
-
103
- return false
104
- }
105
-
106
- const names = (() => {
107
- const avx2 = supportsAvx2()
108
- const baseline = arch === "x64" && !avx2
109
-
110
- if (platform === "linux") {
111
- const musl = (() => {
112
- try {
113
- if (fs.existsSync("/etc/alpine-release")) return true
114
- } catch {
115
- // ignore
116
- }
117
-
118
- try {
119
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
120
- const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
121
- if (text.includes("musl")) return true
122
- } catch {
123
- // ignore
124
- }
125
-
126
- return false
127
- })()
128
-
129
- if (musl) {
130
- if (arch === "x64") {
131
- if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
132
- return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
133
- }
134
- return [`${base}-musl`, base]
135
- }
136
-
137
- if (arch === "x64") {
138
- if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
139
- return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
140
- }
141
- return [base, `${base}-musl`]
142
- }
143
-
144
- if (arch === "x64") {
145
- if (baseline) return [`${base}-baseline`, base]
146
- return [base, `${base}-baseline`]
147
- }
148
- return [base]
149
- })()
150
-
151
- function findBinary(startDir) {
152
- let current = startDir
153
- for (;;) {
154
- const modules = path.join(current, "node_modules")
155
- if (fs.existsSync(modules)) {
156
- for (const name of names) {
157
- const candidate = path.join(modules, name, "bin", binary)
158
- if (fs.existsSync(candidate)) return candidate
159
- }
160
- }
161
- const parent = path.dirname(current)
162
- if (parent === current) {
163
- return
164
- }
165
- current = parent
166
- }
167
- }
168
-
169
- const resolved = findBinary(scriptDir)
170
- if (!resolved) {
171
- console.error(
172
- "It seems that your package manager failed to install the right version of shuvcode for your platform. You can try manually installing " +
173
- names.map((n) => `\"${n}\"`).join(" or ") +
174
- " package",
175
- )
176
- process.exit(1)
177
- }
178
-
179
- run(resolved)