slopcode 0.2.149 → 0.2.151

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.
Binary file
Binary file
package/bin/slopcode CHANGED
@@ -19,29 +19,41 @@ function startupLog(phase, extra = {}) {
19
19
  }
20
20
 
21
21
  function run(target, options = {}) {
22
- const maxRetries = 3
23
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
24
- startupLog("launcher.exec", { target: path.basename(target), attempt })
25
- const result = childProcess.spawnSync(target, options.args || process.argv.slice(2), {
26
- stdio: "inherit",
27
- env: options.env ? { ...process.env, ...options.env } : process.env,
28
- })
29
- if (result.error) {
30
- console.error(result.error.message)
31
- process.exit(1)
32
- }
33
- if (result.signal === "SIGABRT" && attempt < maxRetries) {
34
- console.error(`slopcode crashed (SIGABRT), retrying (${attempt + 1}/${maxRetries})...`)
35
- continue
36
- }
37
- if (result.signal) {
38
- try {
39
- process.kill(process.pid, result.signal)
40
- } catch {}
22
+ startupLog("launcher.exec", { target: path.basename(target) })
23
+ const result = childProcess.spawnSync(target, options.args || process.argv.slice(2), {
24
+ stdio: "inherit",
25
+ env: options.env ? { ...process.env, ...options.env } : process.env,
26
+ })
27
+ if (result.error) {
28
+ console.error(result.error.message)
29
+ process.exit(1)
30
+ }
31
+ if (result.signal === "SIGABRT" && options.fallback) {
32
+ console.error("slopcode crashed (SIGABRT), falling back to JS bundle...")
33
+ const bun = childProcess.spawnSync("bun", ["--version"], { encoding: "utf8", timeout: 3000 })
34
+ if (bun.status === 0 && bun.stdout.trim()) {
35
+ const fbEnv = { ...process.env, SLOPCODE_IN_PROCESS: "1", ...(options.fallbackEnv || {}) }
36
+ const fb = childProcess.spawnSync("bun", ["run", options.fallback, ...(options.args || process.argv.slice(2))], {
37
+ stdio: "inherit",
38
+ env: fbEnv,
39
+ cwd: path.dirname(options.fallback),
40
+ })
41
+ if (fb.error) {
42
+ console.error(fb.error.message)
43
+ process.exit(1)
44
+ }
45
+ if (fb.signal) {
46
+ try { process.kill(process.pid, fb.signal) } catch {}
47
+ }
48
+ process.exit(typeof fb.status === "number" ? fb.status : 1)
41
49
  }
42
- const code = typeof result.status === "number" ? result.status : 1
43
- process.exit(code)
44
50
  }
51
+ if (result.signal) {
52
+ try {
53
+ process.kill(process.pid, result.signal)
54
+ } catch {}
55
+ }
56
+ process.exit(typeof result.status === "number" ? result.status : 1)
45
57
  }
46
58
 
47
59
  const envPath = process.env.SLOPCODE_BIN_PATH
@@ -321,9 +333,19 @@ const useCache = libc() !== "bionic"
321
333
 
322
334
  const packageNames = names("slopcode-bin")
323
335
  const resolvedNames = Array.from(new Set([...packageNames, ...names("slopcode")]))
336
+
337
+ function findFallback(binaryPath) {
338
+ const pkgDir = path.dirname(path.dirname(binaryPath))
339
+ const fallback = path.join(pkgDir, "fallback", "index.js")
340
+ if (!fs.existsSync(fallback)) return
341
+ const modules = path.join(pkgDir, "fallback", "modules")
342
+ return { path: fallback, env: { NODE_PATH: [modules, process.env.NODE_PATH].filter(Boolean).join(path.delimiter) } }
343
+ }
344
+
324
345
  const hit = useCache ? cacheReady(resolvedNames) : undefined
325
346
  if (hit) {
326
- run(hit)
347
+ const resolvedPkg = resolveBinary() || findBinary(scriptDir)
348
+ run(hit, { fallback: resolvedPkg ? findFallback(resolvedPkg.path)?.path : undefined, fallbackEnv: resolvedPkg ? findFallback(resolvedPkg.path)?.env : undefined })
327
349
  }
328
350
  clearCache()
329
351
 
@@ -428,4 +450,8 @@ if (libc() === "bionic" && androidInteractive(args)) {
428
450
  }
429
451
  }
430
452
 
431
- run(resolved.path)
453
+ const fallback = findFallback(resolved.path)
454
+ run(resolved.path, {
455
+ fallback: fallback?.path,
456
+ fallbackEnv: fallback?.env,
457
+ })