@muxcodecli/cli 1.15.12 → 1.15.14
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/bin/muxcode +17 -191
- package/dist/index.js +5965 -0
- package/package.json +18 -2
package/bin/muxcode
CHANGED
|
@@ -1,199 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const childProcess = require("child_process")
|
|
4
|
-
const fs = require("fs")
|
|
2
|
+
const { spawnSync } = require("child_process")
|
|
5
3
|
const path = require("path")
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"]
|
|
9
|
-
|
|
10
|
-
function run(target) {
|
|
11
|
-
const child = childProcess.spawn(target, process.argv.slice(2), {
|
|
12
|
-
stdio: "inherit",
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
child.on("error", (error) => {
|
|
16
|
-
console.error(error.message)
|
|
17
|
-
process.exit(1)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const forwarders = {}
|
|
21
|
-
for (const signal of forwardedSignals) {
|
|
22
|
-
forwarders[signal] = () => {
|
|
23
|
-
try {
|
|
24
|
-
child.kill(signal)
|
|
25
|
-
} catch {
|
|
26
|
-
// The child may have already exited.
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
process.on(signal, forwarders[signal])
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
child.on("exit", (code, signal) => {
|
|
33
|
-
for (const forwardedSignal of forwardedSignals) {
|
|
34
|
-
process.removeListener(forwardedSignal, forwarders[forwardedSignal])
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (signal) {
|
|
38
|
-
process.kill(process.pid, signal)
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
process.exit(typeof code === "number" ? code : 0)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const envPath = process.env.MUXCODE_BIN_PATH
|
|
47
|
-
|
|
48
|
-
const scriptPath = fs.realpathSync(__filename)
|
|
49
|
-
const scriptDir = path.dirname(scriptPath)
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
const cached = path.join(scriptDir, ".muxcode")
|
|
53
|
-
|
|
54
|
-
const platformMap = {
|
|
55
|
-
darwin: "darwin",
|
|
56
|
-
linux: "linux",
|
|
57
|
-
win32: "windows",
|
|
58
|
-
}
|
|
59
|
-
const archMap = {
|
|
60
|
-
x64: "x64",
|
|
61
|
-
arm64: "arm64",
|
|
62
|
-
arm: "arm",
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let platform = platformMap[os.platform()]
|
|
66
|
-
if (!platform) {
|
|
67
|
-
platform = os.platform()
|
|
68
|
-
}
|
|
69
|
-
let arch = archMap[os.arch()]
|
|
70
|
-
if (!arch) {
|
|
71
|
-
arch = os.arch()
|
|
72
|
-
}
|
|
73
|
-
const base = "muxcode-" + platform + "-" + arch
|
|
74
|
-
const binary = platform === "windows" ? "muxcode.exe" : "muxcode"
|
|
75
|
-
|
|
76
|
-
function supportsAvx2() {
|
|
77
|
-
if (arch !== "x64") return false
|
|
78
|
-
|
|
79
|
-
if (platform === "linux") {
|
|
80
|
-
try {
|
|
81
|
-
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
82
|
-
} catch {
|
|
83
|
-
return false
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (platform === "darwin") {
|
|
88
|
-
try {
|
|
89
|
-
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
90
|
-
encoding: "utf8",
|
|
91
|
-
timeout: 1500,
|
|
92
|
-
})
|
|
93
|
-
if (result.status !== 0) return false
|
|
94
|
-
return (result.stdout || "").trim() === "1"
|
|
95
|
-
} catch {
|
|
96
|
-
return false
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (platform === "windows") {
|
|
101
|
-
const cmd =
|
|
102
|
-
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
103
|
-
|
|
104
|
-
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
105
|
-
try {
|
|
106
|
-
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
107
|
-
encoding: "utf8",
|
|
108
|
-
timeout: 3000,
|
|
109
|
-
windowsHide: true,
|
|
110
|
-
})
|
|
111
|
-
if (result.status !== 0) continue
|
|
112
|
-
const out = (result.stdout || "").trim().toLowerCase()
|
|
113
|
-
if (out === "true" || out === "1") return true
|
|
114
|
-
if (out === "false" || out === "0") return false
|
|
115
|
-
} catch {
|
|
116
|
-
continue
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return false
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return false
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const names = (() => {
|
|
127
|
-
const avx2 = supportsAvx2()
|
|
128
|
-
const baseline = arch === "x64" && !avx2
|
|
129
|
-
|
|
130
|
-
if (platform === "linux") {
|
|
131
|
-
const musl = (() => {
|
|
132
|
-
try {
|
|
133
|
-
if (fs.existsSync("/etc/alpine-release")) return true
|
|
134
|
-
} catch {
|
|
135
|
-
// ignore
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
140
|
-
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
141
|
-
if (text.includes("musl")) return true
|
|
142
|
-
} catch {
|
|
143
|
-
// ignore
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return false
|
|
147
|
-
})()
|
|
148
|
-
|
|
149
|
-
if (musl) {
|
|
150
|
-
if (arch === "x64") {
|
|
151
|
-
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
152
|
-
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
153
|
-
}
|
|
154
|
-
return [`${base}-musl`, base]
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (arch === "x64") {
|
|
158
|
-
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
159
|
-
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
160
|
-
}
|
|
161
|
-
return [base, `${base}-musl`]
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (arch === "x64") {
|
|
165
|
-
if (baseline) return [`${base}-baseline`, base]
|
|
166
|
-
return [base, `${base}-baseline`]
|
|
167
|
-
}
|
|
168
|
-
return [base]
|
|
169
|
-
})()
|
|
4
|
+
const fs = require("fs")
|
|
170
5
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
if (fs.existsSync(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
const parent = path.dirname(current)
|
|
182
|
-
if (parent === current) {
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
current = parent
|
|
186
|
-
}
|
|
6
|
+
// Tenta encontrar bun: primeiro @oven-sh/bun, depois PATH
|
|
7
|
+
function findBun() {
|
|
8
|
+
try {
|
|
9
|
+
const bunPkg = require.resolve("@oven-sh/bun/bin/bun")
|
|
10
|
+
if (fs.existsSync(bunPkg)) return bunPkg
|
|
11
|
+
} catch {}
|
|
12
|
+
const { execSync } = require("child_process")
|
|
13
|
+
try { return execSync("which bun || where bun", { encoding: "utf8" }).trim().split("\n")[0] } catch {}
|
|
14
|
+
return null
|
|
187
15
|
}
|
|
188
16
|
|
|
189
|
-
const
|
|
190
|
-
if (!
|
|
191
|
-
console.error(
|
|
192
|
-
"It seems that your package manager failed to install the right version of the muxcode CLI for your platform. You can try manually installing " +
|
|
193
|
-
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
194
|
-
" package",
|
|
195
|
-
)
|
|
17
|
+
const bun = findBun()
|
|
18
|
+
if (!bun) {
|
|
19
|
+
console.error("bun not found. Install via: npm install -g @oven-sh/bun")
|
|
196
20
|
process.exit(1)
|
|
197
21
|
}
|
|
198
22
|
|
|
199
|
-
|
|
23
|
+
const bundle = path.join(__dirname, "..", "dist", "index.js")
|
|
24
|
+
const result = spawnSync(bun, [bundle, ...process.argv.slice(2)], { stdio: "inherit" })
|
|
25
|
+
process.exit(result.status ?? 0)
|