@fabriccode/cli 7.0.115 → 7.0.117

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/fabriccode CHANGED
@@ -5,6 +5,8 @@ const fs = require("fs")
5
5
  const path = require("path")
6
6
  const os = require("os")
7
7
 
8
+ const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"]
9
+
8
10
  // fabriccode_change start
9
11
  function code(signal) {
10
12
  const num = os.constants.signals?.[signal]
@@ -12,38 +14,106 @@ function code(signal) {
12
14
  return 1
13
15
  }
14
16
 
15
- function fail(target, result) {
16
- if (result.signal === "SIGSEGV" && target.includes("cli-linux-x64-baseline")) {
17
+ function reportCrash(target, signal) {
18
+ if (signal === "SIGSEGV" && target.includes("cli-linux-x64-baseline")) {
17
19
  console.error("Fabric's Linux x64 baseline binary crashed inside Bun on a non-AVX CPU.")
18
20
  console.error("This host is not currently supported by the npm-distributed baseline build.")
19
21
  console.error("Use a machine with AVX support for now, or build and run Fabric from source on a supported host.")
20
22
  }
21
- if (result.signal) {
22
- console.error(`Fabric binary crashed with ${result.signal}: ${target}`)
23
- process.exit(code(result.signal))
23
+ console.error(`Fabric binary crashed with ${signal}: ${target}`)
24
+ }
25
+ // fabriccode_change end
26
+
27
+ // fabriccode_change start - point packaged binaries at co-located tree-sitter WASM resources
28
+ function configureTreeSitterResources(target) {
29
+ const wasmDir = path.join(path.dirname(target), "tree-sitter")
30
+ if (!process.env.FABRIC_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) {
31
+ process.env.FABRIC_TREE_SITTER_WASM_DIR = wasmDir
24
32
  }
25
- const status = typeof result.status === "number" ? result.status : 1
26
- process.exit(status)
27
33
  }
34
+ // fabriccode_change end
28
35
 
29
- function run(target) {
30
- const result = childProcess.spawnSync(target, process.argv.slice(2), {
31
- stdio: "inherit",
32
- })
33
- if (result.error) {
34
- console.error(result.error.message)
36
+ function run(target, fallback) {
37
+ // fabriccode_change - preserve cached binary fallback
38
+ configureTreeSitterResources(target) // fabriccode_change
39
+ // fabriccode_change start - fall through if the cached binary cannot be spawned
40
+ const child = (() => {
41
+ try {
42
+ return childProcess.spawn(target, process.argv.slice(2), {
43
+ stdio: "inherit",
44
+ })
45
+ } catch (error) {
46
+ if (fallback) {
47
+ run(fallback)
48
+ return
49
+ }
50
+ console.error(error.message)
51
+ process.exit(1)
52
+ }
53
+ })()
54
+ if (!child) return
55
+ // fabriccode_change end
56
+
57
+ const forwarders = {}
58
+ const clear = () => {
59
+ // fabriccode_change - remove listeners before cached binary fallback
60
+ for (const signal of forwardedSignals) {
61
+ process.removeListener(signal, forwarders[signal])
62
+ }
63
+ }
64
+
65
+ child.on("error", (error) => {
66
+ clear() // fabriccode_change
67
+ // fabriccode_change start - fall through to findBinary() if cached binary fails
68
+ if (fallback) {
69
+ run(fallback)
70
+ return
71
+ }
72
+ // fabriccode_change end
73
+ console.error(error.message)
35
74
  process.exit(1)
75
+ })
76
+
77
+ for (const signal of forwardedSignals) {
78
+ forwarders[signal] = () => {
79
+ try {
80
+ child.kill(signal)
81
+ } catch {
82
+ // The child may have already exited.
83
+ }
84
+ }
85
+ process.on(signal, forwarders[signal])
36
86
  }
37
- if (result.signal) fail(target, result)
38
- const status = typeof result.status === "number" ? result.status : 1
39
- process.exit(status)
40
- }
41
87
 
42
- const envPath = process.env.FABRIC_BIN_PATH
43
- if (envPath) {
44
- run(envPath)
88
+ child.on("exit", (exitCode, signal) => {
89
+ clear() // fabriccode_change
90
+
91
+ if (signal) {
92
+ // fabriccode_change start - SIGILL on a non-baseline x64 binary: retry the baseline build
93
+ if (signal === "SIGILL") {
94
+ const baseline = findFallback(scriptDir, target)
95
+ if (baseline) {
96
+ console.error(`Fabric binary crashed with SIGILL, retrying baseline build: ${baseline}`)
97
+ run(baseline)
98
+ return
99
+ }
100
+ }
101
+ reportCrash(target, signal)
102
+ process.exit(code(signal))
103
+ // fabriccode_change end
104
+ }
105
+
106
+ process.exit(typeof exitCode === "number" ? exitCode : 0)
107
+ })
45
108
  }
46
109
 
110
+ const envPath = process.env.FABRIC_BIN_PATH // fabriccode_change
111
+
112
+ const scriptPath = fs.realpathSync(__filename)
113
+ const scriptDir = path.dirname(scriptPath)
114
+
115
+ const cached = path.join(scriptDir, ".fabriccode") // fabriccode_change
116
+
47
117
  const platformMap = {
48
118
  darwin: "darwin",
49
119
  linux: "linux",
@@ -199,10 +269,7 @@ function findFallback(startDir, target) {
199
269
  }
200
270
  // fabriccode_change end
201
271
 
202
- const scriptPath = fs.realpathSync(__filename)
203
- const scriptDir = path.dirname(scriptPath)
204
-
205
- const resolved = findBinary(scriptDir)
272
+ const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir))
206
273
  if (!resolved) {
207
274
  console.error(
208
275
  "It seems that your package manager failed to install the right version of Fabric Code for your platform. You can try manually installing " +
@@ -212,22 +279,4 @@ if (!resolved) {
212
279
  process.exit(1)
213
280
  }
214
281
 
215
- const result = childProcess.spawnSync(resolved, process.argv.slice(2), {
216
- stdio: "inherit",
217
- })
218
- if (result.error) {
219
- console.error(result.error.message)
220
- process.exit(1)
221
- }
222
- // fabriccode_change start
223
- if (result.signal === "SIGILL") {
224
- const fallback = findFallback(scriptDir, resolved)
225
- if (fallback) {
226
- console.error(`Fabric binary crashed with SIGILL, retrying baseline build: ${fallback}`)
227
- run(fallback)
228
- }
229
- }
230
- // fabriccode_change end
231
- if (result.signal) fail(resolved, result)
232
- const status = typeof result.status === "number" ? result.status : 1
233
- process.exit(status)
282
+ run(resolved, resolved === cached ? findBinary(scriptDir) : undefined) // fabriccode_change - preserve cached binary fallback
package/package.json CHANGED
@@ -6,21 +6,21 @@
6
6
  "scripts": {
7
7
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
8
  },
9
- "version": "7.0.115",
9
+ "version": "7.0.117",
10
10
  "license": "MIT",
11
11
  "optionalDependencies": {
12
- "@fabriccode/cli-linux-x64-baseline-musl": "7.0.115",
13
- "@fabriccode/cli-linux-x64-musl": "7.0.115",
14
- "@fabriccode/cli-darwin-x64-baseline": "7.0.115",
15
- "@fabriccode/cli-darwin-x64": "7.0.115",
16
- "@fabriccode/cli-linux-arm64": "7.0.115",
17
- "@fabriccode/cli-linux-x64": "7.0.115",
18
- "@fabriccode/cli-windows-x64-baseline": "7.0.115",
19
- "@fabriccode/cli-linux-arm64-musl": "7.0.115",
20
- "@fabriccode/cli-windows-arm64": "7.0.115",
21
- "@fabriccode/cli-windows-x64": "7.0.115",
22
- "@fabriccode/cli-linux-x64-baseline": "7.0.115",
23
- "@fabriccode/cli-darwin-arm64": "7.0.115"
12
+ "@fabriccode/cli-linux-arm64-musl": "7.0.117",
13
+ "@fabriccode/cli-darwin-x64-baseline": "7.0.117",
14
+ "@fabriccode/cli-windows-arm64": "7.0.117",
15
+ "@fabriccode/cli-linux-arm64": "7.0.117",
16
+ "@fabriccode/cli-linux-x64": "7.0.117",
17
+ "@fabriccode/cli-darwin-arm64": "7.0.117",
18
+ "@fabriccode/cli-windows-x64": "7.0.117",
19
+ "@fabriccode/cli-linux-x64-musl": "7.0.117",
20
+ "@fabriccode/cli-windows-x64-baseline": "7.0.117",
21
+ "@fabriccode/cli-darwin-x64": "7.0.117",
22
+ "@fabriccode/cli-linux-x64-baseline-musl": "7.0.117",
23
+ "@fabriccode/cli-linux-x64-baseline": "7.0.117"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
package/postinstall.mjs CHANGED
@@ -126,6 +126,19 @@ function findBinary() {
126
126
  }
127
127
  // fabriccode_change end
128
128
 
129
+ // fabriccode_change start - copy tree-sitter WASM resources next to cached binary
130
+ function copyTreeSitterResources(binaryPath) {
131
+ const source = path.join(path.dirname(binaryPath), "tree-sitter")
132
+ const target = path.join(__dirname, "bin", "tree-sitter")
133
+ const runtime = path.join(source, "tree-sitter.wasm")
134
+
135
+ if (!fs.existsSync(runtime)) return
136
+
137
+ fs.rmSync(target, { recursive: true, force: true })
138
+ fs.cpSync(source, target, { recursive: true })
139
+ }
140
+ // fabriccode_change end
141
+
129
142
  function main() {
130
143
  if (os.platform() === "win32") {
131
144
  // On Windows, the .exe is already included in the package and bin field points to it
@@ -141,6 +154,7 @@ function main() {
141
154
  } catch {
142
155
  fs.copyFileSync(binaryPath, target)
143
156
  }
157
+ copyTreeSitterResources(binaryPath) // fabriccode_change
144
158
  fs.chmodSync(target, 0o755)
145
159
  }
146
160
 
package/bin/kilo DELETED
@@ -1,188 +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.FABRIC_BIN_PATH
21
- if (envPath) {
22
- run(envPath)
23
- }
24
-
25
- const scriptPath = fs.realpathSync(__filename)
26
- const scriptDir = path.dirname(scriptPath)
27
-
28
- // fabriccode_change start - fall through to findBinary() if cached binary fails
29
- const cached = path.join(scriptDir, ".kilo")
30
- if (fs.existsSync(cached)) {
31
- const result = childProcess.spawnSync(cached, process.argv.slice(2), {
32
- stdio: "inherit",
33
- })
34
- if (!result.error) {
35
- const code = typeof result.status === "number" ? result.status : 0
36
- process.exit(code)
37
- }
38
- // cached binary failed (e.g. wrong platform/arch, missing dynamic linker),
39
- // fall through to findBinary() which has better variant detection
40
- }
41
- // fabriccode_change end
42
-
43
- const platformMap = {
44
- darwin: "darwin",
45
- linux: "linux",
46
- win32: "windows",
47
- }
48
- const archMap = {
49
- x64: "x64",
50
- arm64: "arm64",
51
- arm: "arm",
52
- }
53
-
54
- let platform = platformMap[os.platform()]
55
- if (!platform) {
56
- platform = os.platform()
57
- }
58
- let arch = archMap[os.arch()]
59
- if (!arch) {
60
- arch = os.arch()
61
- }
62
- const base = "@fabriccode/cli-" + platform + "-" + arch
63
- const binary = platform === "windows" ? "fabric.exe" : "fabric" // fabriccode_change: binary is built as "fabric" not "kilo"
64
-
65
- function supportsAvx2() {
66
- if (arch !== "x64") return false
67
-
68
- if (platform === "linux") {
69
- try {
70
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
71
- } catch {
72
- return false
73
- }
74
- }
75
-
76
- if (platform === "darwin") {
77
- try {
78
- const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
79
- encoding: "utf8",
80
- timeout: 1500,
81
- })
82
- if (result.status !== 0) return false
83
- return (result.stdout || "").trim() === "1"
84
- } catch {
85
- return false
86
- }
87
- }
88
-
89
- if (platform === "windows") {
90
- const cmd =
91
- '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
92
-
93
- for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
94
- try {
95
- const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
96
- encoding: "utf8",
97
- timeout: 3000,
98
- windowsHide: true,
99
- })
100
- if (result.status !== 0) continue
101
- const out = (result.stdout || "").trim().toLowerCase()
102
- if (out === "true" || out === "1") return true
103
- if (out === "false" || out === "0") return false
104
- } catch {
105
- continue
106
- }
107
- }
108
-
109
- return false
110
- }
111
-
112
- return false
113
- }
114
-
115
- const names = (() => {
116
- const avx2 = supportsAvx2()
117
- const baseline = arch === "x64" && !avx2
118
-
119
- if (platform === "linux") {
120
- const musl = (() => {
121
- try {
122
- if (fs.existsSync("/etc/alpine-release")) return true
123
- } catch {
124
- // ignore
125
- }
126
-
127
- try {
128
- const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
129
- const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
130
- if (text.includes("musl")) return true
131
- } catch {
132
- // ignore
133
- }
134
-
135
- return false
136
- })()
137
-
138
- if (musl) {
139
- if (arch === "x64") {
140
- if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
141
- return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
142
- }
143
- return [`${base}-musl`, base]
144
- }
145
-
146
- if (arch === "x64") {
147
- if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
148
- return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
149
- }
150
- return [base, `${base}-musl`]
151
- }
152
-
153
- if (arch === "x64") {
154
- if (baseline) return [`${base}-baseline`, base]
155
- return [base, `${base}-baseline`]
156
- }
157
- return [base]
158
- })()
159
-
160
- function findBinary(startDir) {
161
- let current = startDir
162
- for (;;) {
163
- const modules = path.join(current, "node_modules")
164
- if (fs.existsSync(modules)) {
165
- for (const name of names) {
166
- const candidate = path.join(modules, name, "bin", binary)
167
- if (fs.existsSync(candidate)) return candidate
168
- }
169
- }
170
- const parent = path.dirname(current)
171
- if (parent === current) {
172
- return
173
- }
174
- current = parent
175
- }
176
- }
177
-
178
- const resolved = findBinary(scriptDir)
179
- if (!resolved) {
180
- console.error(
181
- "It seems that your package manager failed to install the right version of the Fabric CLI for your platform. You can try manually installing " +
182
- names.map((n) => `\"${n}\"`).join(" or ") +
183
- " package",
184
- )
185
- process.exit(1)
186
- }
187
-
188
- run(resolved)