lingeebuild-cli 0.0.0-stage → 0.0.363

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.
@@ -0,0 +1,186 @@
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 env = { ...process.env }
10
+ // 平台包 bin/lib 随带了比老发行版(麒麟等)系统库更新的 libstdc++,
11
+ // 内嵌 .node 在 /tmp 被 dlopen 时只能靠 LD_LIBRARY_PATH 解析依赖。
12
+ const libDir = path.join(path.dirname(target), "lib")
13
+ if (os.platform() === "linux" && fs.existsSync(libDir)) {
14
+ env.LD_LIBRARY_PATH = env.LD_LIBRARY_PATH ? `${libDir}:${env.LD_LIBRARY_PATH}` : libDir
15
+ }
16
+ const result = childProcess.spawnSync(target, process.argv.slice(2), {
17
+ stdio: "inherit",
18
+ env,
19
+ })
20
+ if (result.error) {
21
+ console.error(result.error.message)
22
+ process.exit(1)
23
+ }
24
+ const code = typeof result.status === "number" ? result.status : 0
25
+ process.exit(code)
26
+ }
27
+
28
+ const envPath = process.env.LINGEEBUILD_BIN_PATH ?? process.env.OPENCODE_BIN_PATH
29
+ if (envPath) {
30
+ run(envPath)
31
+ }
32
+
33
+ const scriptPath = fs.realpathSync(__filename)
34
+ const scriptDir = path.dirname(scriptPath)
35
+
36
+ const cached = path.join(scriptDir, ".lingeebuild")
37
+ if (fs.existsSync(cached)) {
38
+ run(cached)
39
+ }
40
+
41
+ const platformMap = {
42
+ darwin: "darwin",
43
+ linux: "linux",
44
+ win32: "windows",
45
+ }
46
+ const archMap = {
47
+ x64: "x64",
48
+ arm64: "arm64",
49
+ arm: "arm",
50
+ }
51
+
52
+ let platform = platformMap[os.platform()]
53
+ if (!platform) {
54
+ platform = os.platform()
55
+ }
56
+ let arch = archMap[os.arch()]
57
+ if (!arch) {
58
+ arch = os.arch()
59
+ }
60
+ const base = "lingeebuild-" + platform + "-" + arch
61
+ const binary = platform === "windows" ? "lingeebuild.exe" : "lingeebuild"
62
+
63
+ function supportsAvx2() {
64
+ if (arch !== "x64") return false
65
+
66
+ if (platform === "linux") {
67
+ try {
68
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
69
+ } catch {
70
+ return false
71
+ }
72
+ }
73
+
74
+ if (platform === "darwin") {
75
+ try {
76
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
77
+ encoding: "utf8",
78
+ timeout: 1500,
79
+ })
80
+ if (result.status !== 0) return false
81
+ return (result.stdout || "").trim() === "1"
82
+ } catch {
83
+ return false
84
+ }
85
+ }
86
+
87
+ if (platform === "windows") {
88
+ const cmd =
89
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
90
+
91
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
92
+ try {
93
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
94
+ encoding: "utf8",
95
+ timeout: 3000,
96
+ windowsHide: true,
97
+ })
98
+ if (result.status !== 0) continue
99
+ const out = (result.stdout || "").trim().toLowerCase()
100
+ if (out === "true" || out === "1") return true
101
+ if (out === "false" || out === "0") return false
102
+ } catch {
103
+ continue
104
+ }
105
+ }
106
+
107
+ return false
108
+ }
109
+
110
+ return false
111
+ }
112
+
113
+ const names = (() => {
114
+ const avx2 = supportsAvx2()
115
+ const baseline = arch === "x64" && !avx2
116
+
117
+ if (platform === "linux") {
118
+ const musl = (() => {
119
+ try {
120
+ if (fs.existsSync("/etc/alpine-release")) return true
121
+ } catch {
122
+ // ignore
123
+ }
124
+
125
+ try {
126
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
127
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
128
+ if (text.includes("musl")) return true
129
+ } catch {
130
+ return false
131
+ }
132
+
133
+ return false
134
+ })()
135
+
136
+ if (musl) {
137
+ if (arch === "x64") {
138
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
139
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
140
+ }
141
+ return [`${base}-musl`, base]
142
+ }
143
+
144
+ if (arch === "x64") {
145
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
146
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
147
+ }
148
+ return [base, `${base}-musl`]
149
+ }
150
+
151
+ if (arch === "x64") {
152
+ if (baseline) return [`${base}-baseline`, base]
153
+ return [base, `${base}-baseline`]
154
+ }
155
+ return [base]
156
+ })()
157
+
158
+ function findBinary(startDir) {
159
+ let current = startDir
160
+ for (;;) {
161
+ const modules = path.join(current, "node_modules")
162
+ if (fs.existsSync(modules)) {
163
+ for (const name of names) {
164
+ const candidate = path.join(modules, name, "bin", binary)
165
+ if (fs.existsSync(candidate)) return candidate
166
+ }
167
+ }
168
+ const parent = path.dirname(current)
169
+ if (parent === current) {
170
+ return
171
+ }
172
+ current = parent
173
+ }
174
+ }
175
+
176
+ const resolved = findBinary(scriptDir)
177
+ if (!resolved) {
178
+ console.error(
179
+ "It seems that your package manager failed to install the right version of the lingeebuild CLI for your platform. You can try manually installing " +
180
+ names.map((n) => `"${n}"`).join(" or ") +
181
+ " package",
182
+ )
183
+ process.exit(1)
184
+ }
185
+
186
+ run(resolved)
package/package.json CHANGED
@@ -1,6 +1,19 @@
1
1
  {
2
2
  "name": "lingeebuild-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "bin": {
4
+ "lingeebuild": "./bin/lingeebuild"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "0.0.363",
10
+ "license": "MIT",
11
+ "optionalDependencies": {
12
+ "lingeebuild-darwin-arm64": "0.0.363",
13
+ "lingeebuild-linux-arm64": "0.0.363",
14
+ "lingeebuild-windows-x64": "0.0.363",
15
+ "lingeebuild-darwin-x64": "0.0.363",
16
+ "lingeebuild-windows-arm64": "0.0.363",
17
+ "lingeebuild-linux-x64": "0.0.363"
18
+ }
6
19
  }
@@ -0,0 +1,119 @@
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 = `lingeebuild-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "lingeebuild.exe" : "lingeebuild"
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, packageDir }
66
+ } catch (error) {
67
+ throw new Error(`Could not find package ${packageName}: ${error.message}`, { cause: error })
68
+ }
69
+ }
70
+
71
+ async function main() {
72
+ try {
73
+ if (os.platform() === "win32") {
74
+ // On Windows, the .exe is already included in the package and bin field points to it
75
+ // No postinstall setup needed
76
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
77
+ return
78
+ }
79
+
80
+ // On non-Windows platforms, just verify the binary package exists
81
+ // Don't replace the wrapper script - it handles binary execution
82
+ const { binaryPath, packageDir } = findBinary()
83
+ const target = path.join(__dirname, "bin", ".lingeebuild")
84
+ if (fs.existsSync(target)) fs.unlinkSync(target)
85
+ try {
86
+ fs.linkSync(binaryPath, target)
87
+ } catch {
88
+ fs.copyFileSync(binaryPath, target)
89
+ }
90
+ fs.chmodSync(target, 0o755)
91
+
92
+ // 平台包 bin/lib 随带兼容老发行版的 libstdc++;复制到 wrapper 的 bin/lib,
93
+ // wrapper 启动二进制时注入 LD_LIBRARY_PATH(硬链接路径下同样生效)。
94
+ const libSrc = path.join(packageDir, "bin", "lib")
95
+ if (fs.existsSync(libSrc)) {
96
+ const libDest = path.join(__dirname, "bin", "lib")
97
+ fs.mkdirSync(libDest, { recursive: true })
98
+ for (const file of fs.readdirSync(libSrc)) {
99
+ const dest = path.join(libDest, file)
100
+ if (fs.existsSync(dest)) fs.unlinkSync(dest)
101
+ try {
102
+ fs.linkSync(path.join(libSrc, file), dest)
103
+ } catch {
104
+ fs.copyFileSync(path.join(libSrc, file), dest)
105
+ }
106
+ }
107
+ }
108
+ } catch (error) {
109
+ console.error("Failed to setup lingeebuild binary:", error.message)
110
+ process.exit(1)
111
+ }
112
+ }
113
+
114
+ try {
115
+ void main()
116
+ } catch (error) {
117
+ console.error("Postinstall script error:", error.message)
118
+ process.exit(0)
119
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.