slopcode 0.2.138 → 0.2.141

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/slopcode CHANGED
@@ -7,7 +7,19 @@ const path = require("path")
7
7
  const os = require("os")
8
8
  const pkg = require("../package.json")
9
9
 
10
+ const startupStart = Date.now()
11
+ function startupTraceEnabled() {
12
+ const value = (process.env.SLOPCODE_ANDROID_STARTUP_LOG || "").toLowerCase()
13
+ return value === "1" || value === "true" || value === "on"
14
+ }
15
+
16
+ function startupLog(phase, extra = {}) {
17
+ if (!startupTraceEnabled()) return
18
+ console.error(JSON.stringify({ event: "android.startup", phase, ms: Date.now() - startupStart, ...extra }))
19
+ }
20
+
10
21
  function run(target, options = {}) {
22
+ startupLog("launcher.exec", { target: path.basename(target) })
11
23
  const result = childProcess.spawnSync(target, options.args || process.argv.slice(2), {
12
24
  stdio: "inherit",
13
25
  env: options.env ? { ...process.env, ...options.env } : process.env,
@@ -51,6 +63,7 @@ const supported = {
51
63
 
52
64
  const rawPlatform = process.env.SLOPCODE_TEST_PLATFORM || os.platform()
53
65
  const rawArch = process.env.SLOPCODE_TEST_ARCH || os.arch()
66
+ startupLog("launcher.start", { platform: rawPlatform, arch: rawArch })
54
67
  let platform = platformMap[rawPlatform]
55
68
  if (!platform) {
56
69
  platform = rawPlatform
@@ -77,7 +90,7 @@ function termuxEnv() {
77
90
  }
78
91
 
79
92
  function libc() {
80
- if (platform === "android") return "bionic"
93
+ if (platform === "android" || termuxEnv()) return "bionic"
81
94
  if (platform !== "linux") return
82
95
  const report = process.report?.getReport?.()
83
96
  if (typeof report?.header?.glibcVersionRuntime === "string" && report.header.glibcVersionRuntime) {
@@ -97,7 +110,7 @@ function libc() {
97
110
  const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
98
111
  if (text.includes("musl")) return "musl"
99
112
  if (text.includes("glibc") || text.includes("gnu libc")) return "glibc"
100
- if (text.includes("bionic") || termuxEnv()) return "bionic"
113
+ if (text.includes("bionic")) return "bionic"
101
114
  const loader = arch === "arm64" ? "/lib/ld-musl-aarch64.so.1" : arch === "x64" ? "/lib/ld-musl-x86_64.so.1" : ""
102
115
  if (loader && fs.existsSync(loader)) return "musl"
103
116
  }
@@ -223,7 +236,18 @@ function androidDoctor(args) {
223
236
  }
224
237
 
225
238
  function androidInteractive(args) {
226
- return !androidDoctor(args) && !args.includes("--self-test")
239
+ return !androidDoctor(args) && args[0] !== "--version" && !args.includes("--self-test")
240
+ }
241
+
242
+ function findNodeModuleFile(startDir, parts) {
243
+ let current = startDir
244
+ for (;;) {
245
+ const candidate = path.join(current, "node_modules", ...parts)
246
+ if (fs.existsSync(candidate)) return candidate
247
+ const parent = path.dirname(current)
248
+ if (parent === current) return
249
+ current = parent
250
+ }
227
251
  }
228
252
 
229
253
  function androidBun(arch) {
@@ -231,7 +255,9 @@ function androidBun(arch) {
231
255
  return [
232
256
  process.env.SLOPCODE_BUN_PATH,
233
257
  path.join(rootDir, "node_modules", "@oven", name, "bin", "bun"),
258
+ findNodeModuleFile(scriptDir, ["@oven", name, "bin", "bun"]),
234
259
  path.join(rootDir, "node_modules", ".bin", process.platform === "win32" ? "bun.cmd" : "bun"),
260
+ findNodeModuleFile(scriptDir, [".bin", process.platform === "win32" ? "bun.cmd" : "bun"]),
235
261
  ].find((item) => item && fs.existsSync(item))
236
262
  }
237
263
 
@@ -296,10 +322,22 @@ if (!resolved) {
296
322
  }
297
323
 
298
324
  const args = process.argv.slice(2)
299
- if (platform === "android" && androidInteractive(args)) {
325
+ if (libc() === "bionic" && androidInteractive(args)) {
300
326
  const bun = androidBun(arch)
327
+ startupLog("launcher.android.interactive", {
328
+ runtime: path.basename(resolved.path),
329
+ bun: bun ? path.basename(bun) : undefined,
330
+ legacy: process.env.SLOPCODE_ANDROID_BOOTSTRAP === "legacy",
331
+ })
332
+ if (!fs.existsSync(androidBundle)) {
333
+ console.error(
334
+ "SlopCode Android CLI bootstrap bundle is missing. Reinstall from Termux with: npm install -g slopcode@latest --include=optional",
335
+ )
336
+ process.exit(1)
337
+ }
301
338
  if (bun && fs.existsSync(androidBundle)) {
302
339
  const runtimeRoot = path.dirname(path.dirname(resolved.path))
340
+ startupLog("launcher.android.legacy_bundle", { bundle: androidBundle })
303
341
  run(bun, {
304
342
  args: [androidBundle, ...args],
305
343
  env: {
@@ -313,13 +351,12 @@ if (platform === "android" && androidInteractive(args)) {
313
351
  },
314
352
  })
315
353
  }
316
- if (fs.existsSync(androidBundle) && !bun) {
354
+ if (!bun) {
317
355
  console.error(
318
- "SlopCode Android CLI bootstrap is missing. Reinstall from Termux with: npm install -g slopcode@latest --include=optional",
356
+ "SlopCode Android CLI bootstrap is missing. Run npm rebuild slopcode or reinstall from Termux with: npm install -g slopcode@latest --include=optional",
319
357
  )
320
358
  process.exit(1)
321
359
  }
322
360
  }
323
361
 
324
362
  run(resolved.path)
325
-