shuvcode 1.2.27 → 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.
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+
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))
11
+ const require = createRequire(import.meta.url)
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "../package.json"), "utf8"))
13
+ const command = Object.keys(packageJson.bin ?? {})[0]
14
+ if (!command) fail("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 dependencies = packageJson.optionalDependencies ?? {}
20
+ const base = Object.keys(dependencies).find((name) => name.endsWith(`-${platform}-${arch}`))
21
+ if (!base) fail(`Shuvcode does not provide a binary for ${platform}-${arch}`)
22
+
23
+ function supportsAvx2() {
24
+ if (arch !== "x64") return false
25
+ if (platform === "linux") {
26
+ try {
27
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
28
+ } catch {
29
+ return false
30
+ }
31
+ }
32
+ if (platform === "darwin") {
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"
38
+ }
39
+ if (platform === "windows") {
40
+ const script =
41
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
42
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
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
52
+ }
53
+ }
54
+ return false
55
+ }
56
+
57
+ function isMusl() {
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
+ }
66
+ }
67
+
68
+ function packageNames() {
69
+ 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])
89
+ }
90
+
91
+ function resolveBinary(name) {
92
+ const packagePath = require.resolve(`${name}/package.json`)
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
96
+ }
97
+
98
+ function fail(message) {
99
+ console.error(message)
100
+ process.exit(1)
101
+ }
102
+
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
110
+ }
111
+ }, undefined)
112
+
113
+ if (!binary) fail(`Failed to find Shuvcode binary package. Reinstall ${packageJson.name}.`)
114
+
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,29 +1,35 @@
1
1
  {
2
2
  "name": "shuvcode",
3
3
  "bin": {
4
- "shuvcode": "./bin/shuvcode"
4
+ "shuvcode": "./bin/launcher.mjs"
5
5
  },
6
- "scripts": {
7
- "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
- },
9
- "version": "1.2.27",
6
+ "version": "2.0.0-alpha-2",
10
7
  "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
8
  "repository": {
26
9
  "type": "git",
27
- "url": "https://github.com/Latitudes-Dev/shuvcode"
10
+ "url": "git+https://github.com/Latitudes-Dev/shuvcode.git"
11
+ },
12
+ "os": [
13
+ "darwin",
14
+ "linux",
15
+ "win32"
16
+ ],
17
+ "cpu": [
18
+ "arm64",
19
+ "x64"
20
+ ],
21
+ "optionalDependencies": {
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"
28
34
  }
29
35
  }
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)
package/postinstall.mjs DELETED
@@ -1,131 +0,0 @@
1
- #!/usr/bin/env node
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))
10
- 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
28
- }
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
45
- }
46
-
47
- return { platform, arch }
48
- }
49
-
50
- function findBinary() {
51
- const { platform, arch } = detectPlatformAndArch()
52
- const packageName = `shuvcode-${platform}-${arch}`
53
- const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
54
-
55
- 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}`)
68
- }
69
- }
70
-
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
- }
79
-
80
- // Remove existing binary/symlink if it exists
81
- if (fs.existsSync(targetPath)) {
82
- fs.unlinkSync(targetPath)
83
- }
84
-
85
- return { binDir, targetPath }
86
- }
87
-
88
- function symlinkBinary(sourcePath, binaryName) {
89
- const { targetPath } = prepareBinDirectory(binaryName)
90
-
91
- fs.symlinkSync(sourcePath, targetPath)
92
- console.log(`opencode binary symlinked: ${targetPath} -> ${sourcePath}`)
93
-
94
- // Verify the file exists after operation
95
- if (!fs.existsSync(targetPath)) {
96
- throw new Error(`Failed to symlink binary to ${targetPath}`)
97
- }
98
- }
99
-
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
- }
108
-
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)
114
- try {
115
- fs.linkSync(binaryPath, target)
116
- } catch {
117
- fs.copyFileSync(binaryPath, target)
118
- }
119
- fs.chmodSync(target, 0o755)
120
- } catch (error) {
121
- console.error("Failed to setup opencode binary:", error.message)
122
- process.exit(1)
123
- }
124
- }
125
-
126
- try {
127
- main()
128
- } catch (error) {
129
- console.error("Postinstall script error:", error.message)
130
- process.exit(0)
131
- }