@leohenon/ocv 0.0.0-test
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 +21 -0
- package/README.md +3 -0
- package/bin/ocv +29 -0
- package/package.json +18 -0
- package/postinstall.mjs +119 -0
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/README.md
ADDED
package/bin/ocv
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require("child_process")
|
|
4
|
+
const fs = require("fs")
|
|
5
|
+
const path = require("path")
|
|
6
|
+
|
|
7
|
+
function run(target) {
|
|
8
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
9
|
+
stdio: "inherit",
|
|
10
|
+
})
|
|
11
|
+
if (result.error) {
|
|
12
|
+
console.error(result.error.message)
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
|
15
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
16
|
+
process.exit(code)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const envPath = process.env.OCV_BIN_PATH
|
|
20
|
+
if (envPath) run(envPath)
|
|
21
|
+
|
|
22
|
+
const ext = process.platform === "win32" ? ".exe" : ""
|
|
23
|
+
const bin = path.join(__dirname, ".ocv" + ext)
|
|
24
|
+
if (!fs.existsSync(bin)) {
|
|
25
|
+
console.error("ocv binary is missing. Try reinstalling: npm i -g @leohenon/ocv@latest")
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
run(bin)
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leohenon/ocv",
|
|
3
|
+
"version": "0.0.0-test",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/leohenon/opencode"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/leohenon/opencode/issues"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"ocv": "./bin/ocv"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node ./postinstall.mjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const os = require("os")
|
|
5
|
+
const path = require("path")
|
|
6
|
+
|
|
7
|
+
const version = process.env.npm_package_version
|
|
8
|
+
const baseUrl = process.env.OCV_RELEASE_BASE_URL || "https://github.com/leohenon/opencode/releases/download"
|
|
9
|
+
|
|
10
|
+
function platform() {
|
|
11
|
+
const map = { darwin: "darwin", linux: "linux", win32: "windows" }
|
|
12
|
+
return map[os.platform()] || os.platform()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function arch() {
|
|
16
|
+
const map = { x64: "x64", arm64: "arm64", arm: "arm" }
|
|
17
|
+
return map[os.arch()] || os.arch()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function avx2(p, a) {
|
|
21
|
+
if (a !== "x64") return false
|
|
22
|
+
|
|
23
|
+
if (p === "linux") {
|
|
24
|
+
try {
|
|
25
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
26
|
+
} catch {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (p === "darwin") {
|
|
32
|
+
try {
|
|
33
|
+
const childProcess = require("child_process")
|
|
34
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
35
|
+
encoding: "utf8",
|
|
36
|
+
timeout: 1500,
|
|
37
|
+
})
|
|
38
|
+
if (result.status !== 0) return false
|
|
39
|
+
return (result.stdout || "").trim() === "1"
|
|
40
|
+
} catch {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function musl() {
|
|
49
|
+
try {
|
|
50
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
51
|
+
} catch {}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const childProcess = require("child_process")
|
|
55
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
56
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
57
|
+
if (text.includes("musl")) return true
|
|
58
|
+
} catch {}
|
|
59
|
+
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function names(p, a) {
|
|
64
|
+
const base = "ocv-" + p + "-" + a
|
|
65
|
+
const baseline = a === "x64" && !avx2(p, a)
|
|
66
|
+
|
|
67
|
+
if (p === "linux") {
|
|
68
|
+
if (musl()) {
|
|
69
|
+
if (a === "x64") {
|
|
70
|
+
if (baseline) return [base + "-baseline-musl", base + "-musl", base + "-baseline", base]
|
|
71
|
+
return [base + "-musl", base + "-baseline-musl", base, base + "-baseline"]
|
|
72
|
+
}
|
|
73
|
+
return [base + "-musl", base]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (a === "x64") {
|
|
77
|
+
if (baseline) return [base + "-baseline", base, base + "-baseline-musl", base + "-musl"]
|
|
78
|
+
return [base, base + "-baseline", base + "-musl", base + "-baseline-musl"]
|
|
79
|
+
}
|
|
80
|
+
return [base, base + "-musl"]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (a === "x64") {
|
|
84
|
+
if (baseline) return [base + "-baseline", base]
|
|
85
|
+
return [base, base + "-baseline"]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [base]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function main() {
|
|
92
|
+
const p = platform()
|
|
93
|
+
const a = arch()
|
|
94
|
+
const ext = p === "windows" ? ".exe" : ""
|
|
95
|
+
const out = path.join(__dirname, "bin", ".ocv" + ext)
|
|
96
|
+
const list = names(p, a)
|
|
97
|
+
|
|
98
|
+
fs.mkdirSync(path.dirname(out), { recursive: true })
|
|
99
|
+
|
|
100
|
+
for (const name of list) {
|
|
101
|
+
const url = baseUrl + "/v" + version + "/" + name + ext
|
|
102
|
+
try {
|
|
103
|
+
const result = await fetch(url)
|
|
104
|
+
if (!result.ok) continue
|
|
105
|
+
const data = Buffer.from(await result.arrayBuffer())
|
|
106
|
+
fs.writeFileSync(out, data)
|
|
107
|
+
fs.chmodSync(out, 0o755)
|
|
108
|
+
console.log("installed ocv binary: " + name + ext)
|
|
109
|
+
return
|
|
110
|
+
} catch {}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw new Error("No compatible release asset found for " + p + "/" + a + " (" + list.join(", ") + ")")
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
main().catch((err) => {
|
|
117
|
+
console.error("Failed to install ocv binary:", err.message)
|
|
118
|
+
process.exit(1)
|
|
119
|
+
})
|