jpcode-cli 1.18.31

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
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/jpcode.exe ADDED
@@ -0,0 +1,10 @@
1
+ echo "Error: jpcode-cli's postinstall script was not run." >&2
2
+ echo "" >&2
3
+ echo "This occurs when using --ignore-scripts during installation, or when using a" >&2
4
+ echo "package manager like pnpm that does not run postinstall scripts by default." >&2
5
+ echo "" >&2
6
+ echo "To fix this, run the postinstall script manually:" >&2
7
+ echo " cd node_modules/jpcode-cli && node postinstall.mjs" >&2
8
+ echo "" >&2
9
+ echo "Or reinstall jpcode-cli without the --ignore-scripts flag." >&2
10
+ exit 1
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "jpcode-cli",
3
+ "bin": {
4
+ "jpcode": "./bin/jpcode.exe"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "node ./postinstall.mjs"
8
+ },
9
+ "version": "1.18.31",
10
+ "license": "MIT",
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "arm64",
18
+ "x64"
19
+ ],
20
+ "optionalDependencies": {
21
+ "jpcode-linux-x64": "1.18.31"
22
+ }
23
+ }
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env node
2
+
3
+ import childProcess from "child_process"
4
+ import fs from "fs"
5
+ import os from "os"
6
+ import path from "path"
7
+ import { createRequire } from "module"
8
+ import { fileURLToPath } from "url"
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
11
+ const require = createRequire(import.meta.url)
12
+ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
13
+
14
+ const platformMap = {
15
+ darwin: "darwin",
16
+ linux: "linux",
17
+ win32: "windows",
18
+ }
19
+ const archMap = {
20
+ x64: "x64",
21
+ arm64: "arm64",
22
+ arm: "arm",
23
+ }
24
+
25
+ const platform = platformMap[os.platform()] ?? os.platform()
26
+ const arch = archMap[os.arch()] ?? os.arch()
27
+ // jpcode's platform packages follow build.ts naming: jpcode-<os>-<arch>[...].
28
+ const base = `jpcode-${platform}-${arch}`
29
+ const sourceBinary = platform === "windows" ? "jpcode.exe" : "jpcode"
30
+ const targetBinary = path.join(__dirname, "bin", "jpcode.exe")
31
+
32
+ function supportsAvx2() {
33
+ if (arch !== "x64") return false
34
+
35
+ if (platform === "linux") {
36
+ try {
37
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
38
+ } catch {
39
+ return false
40
+ }
41
+ }
42
+
43
+ if (platform === "darwin") {
44
+ try {
45
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
46
+ encoding: "utf8",
47
+ timeout: 1500,
48
+ })
49
+ if (result.status !== 0) return false
50
+ return (result.stdout || "").trim() === "1"
51
+ } catch {
52
+ return false
53
+ }
54
+ }
55
+
56
+ if (platform === "windows") {
57
+ const command =
58
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
59
+
60
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
61
+ try {
62
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
63
+ encoding: "utf8",
64
+ timeout: 3000,
65
+ windowsHide: true,
66
+ })
67
+ if (result.status !== 0) continue
68
+ const output = (result.stdout || "").trim().toLowerCase()
69
+ if (output === "true" || output === "1") return true
70
+ if (output === "false" || output === "0") return false
71
+ } catch {
72
+ continue
73
+ }
74
+ }
75
+ }
76
+
77
+ return false
78
+ }
79
+
80
+ function isMusl() {
81
+ if (platform !== "linux") return false
82
+
83
+ try {
84
+ if (fs.existsSync("/etc/alpine-release")) return true
85
+ } catch {
86
+ // Ignore filesystem probes that are blocked by the host.
87
+ }
88
+
89
+ try {
90
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
91
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
92
+ } catch {
93
+ return false
94
+ }
95
+ }
96
+
97
+ function packageNames() {
98
+ const baseline = arch === "x64" && !supportsAvx2()
99
+
100
+ if (platform === "linux") {
101
+ if (isMusl()) {
102
+ if (arch === "x64")
103
+ return baseline
104
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
105
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
106
+ return [`${base}-musl`, base]
107
+ }
108
+
109
+ if (arch === "x64")
110
+ return baseline
111
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
112
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
113
+ return [base, `${base}-musl`]
114
+ }
115
+
116
+ if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
117
+ return [base]
118
+ }
119
+
120
+ function resolveBinary(name) {
121
+ const packageJsonPath = require.resolve(`${name}/package.json`)
122
+ const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
123
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
124
+ return binaryPath
125
+ }
126
+
127
+ function installPackage(name) {
128
+ const version = packageJson.optionalDependencies?.[name]
129
+ if (!version) return
130
+
131
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "jpcode-install-"))
132
+ try {
133
+ const result = childProcess.spawnSync(
134
+ "npm",
135
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
136
+ { stdio: "inherit", windowsHide: true },
137
+ )
138
+ if (result.status !== 0) return
139
+ const packageDir = path.join(temp, "node_modules", name)
140
+ copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
141
+ return true
142
+ } finally {
143
+ fs.rmSync(temp, { recursive: true, force: true })
144
+ }
145
+ }
146
+
147
+ function copyBinary(source, target) {
148
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
149
+ fs.mkdirSync(path.dirname(target), { recursive: true })
150
+ if (fs.existsSync(target)) fs.unlinkSync(target)
151
+ try {
152
+ fs.linkSync(source, target)
153
+ } catch {
154
+ fs.copyFileSync(source, target)
155
+ }
156
+ fs.chmodSync(target, 0o755)
157
+ }
158
+
159
+ function verifyBinary() {
160
+ const result = childProcess.spawnSync(targetBinary, ["--version"], {
161
+ encoding: "utf8",
162
+ stdio: "ignore",
163
+ windowsHide: true,
164
+ })
165
+ return result.status === 0
166
+ }
167
+
168
+ function main() {
169
+ for (const name of packageNames()) {
170
+ try {
171
+ copyBinary(resolveBinary(name), targetBinary)
172
+ if (verifyBinary()) return
173
+ } catch {
174
+ if (installPackage(name) && verifyBinary()) return
175
+ }
176
+ }
177
+
178
+ throw new Error(
179
+ `It seems your package manager failed to install the right jpcode CLI package. Try manually installing ${packageNames()
180
+ .map((name) => JSON.stringify(name))
181
+ .join(" or ")}.`,
182
+ )
183
+ }
184
+
185
+ try {
186
+ main()
187
+ } catch (error) {
188
+ console.error(error.message)
189
+ process.exit(1)
190
+ }