slopcode 0.2.137 → 0.2.140

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/package.json CHANGED
@@ -36,20 +36,20 @@
36
36
  "scripts": {
37
37
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
38
38
  },
39
- "version": "0.2.137",
39
+ "version": "0.2.140",
40
40
  "license": "MIT",
41
41
  "optionalDependencies": {
42
- "slopcode-bin-darwin-x64-baseline": "0.2.137",
43
- "slopcode-bin-linux-x64-baseline": "0.2.137",
44
- "slopcode-bin-linux-x64-musl": "0.2.137",
45
- "slopcode-bin-windows-x64": "0.2.137",
46
- "slopcode-bin-darwin-x64": "0.2.137",
47
- "slopcode-bin-windows-x64-baseline": "0.2.137",
48
- "slopcode-bin-darwin-arm64": "0.2.137",
49
- "slopcode-bin-linux-x64-baseline-musl": "0.2.137",
50
- "slopcode-bin-linux-x64": "0.2.137",
51
- "slopcode-bin-linux-arm64-musl": "0.2.137",
52
- "slopcode-bin-linux-arm64": "0.2.137",
42
+ "slopcode-bin-darwin-x64-baseline": "0.2.140",
43
+ "slopcode-bin-linux-x64-baseline": "0.2.140",
44
+ "slopcode-bin-linux-x64-musl": "0.2.140",
45
+ "slopcode-bin-windows-x64": "0.2.140",
46
+ "slopcode-bin-darwin-x64": "0.2.140",
47
+ "slopcode-bin-windows-x64-baseline": "0.2.140",
48
+ "slopcode-bin-darwin-arm64": "0.2.140",
49
+ "slopcode-bin-linux-x64-baseline-musl": "0.2.140",
50
+ "slopcode-bin-linux-x64": "0.2.140",
51
+ "slopcode-bin-linux-arm64-musl": "0.2.140",
52
+ "slopcode-bin-linux-arm64": "0.2.140",
53
53
  "@oven/bun-linux-aarch64-android": "1.3.14",
54
54
  "@oven/bun-linux-x64-android": "1.3.14"
55
55
  }
package/postinstall.mjs CHANGED
@@ -39,7 +39,7 @@ function termuxEnv() {
39
39
  }
40
40
 
41
41
  function detectLibc(platform, arch) {
42
- if (platform === "android") return "bionic"
42
+ if (platform === "android" || termuxEnv()) return "bionic"
43
43
  if (platform !== "linux") return
44
44
  const report = process.report?.getReport?.()
45
45
  if (typeof report?.header?.glibcVersionRuntime === "string" && report.header.glibcVersionRuntime) {
@@ -59,7 +59,7 @@ function detectLibc(platform, arch) {
59
59
  const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
60
60
  if (text.includes("musl")) return "musl"
61
61
  if (text.includes("glibc") || text.includes("gnu libc")) return "glibc"
62
- if (text.includes("bionic") || termuxEnv()) return "bionic"
62
+ if (text.includes("bionic")) return "bionic"
63
63
  const loader = arch === "arm64" ? "/lib/ld-musl-aarch64.so.1" : arch === "x64" ? "/lib/ld-musl-x86_64.so.1" : ""
64
64
  if (loader && fs.existsSync(loader)) return "musl"
65
65
  }
@@ -142,7 +142,7 @@ function supportedMessage() {
142
142
 
143
143
  function termuxMessage() {
144
144
  return [
145
- "SlopCode native Termux support could not install the Android runtime.",
145
+ "SlopCode native Termux support could not install the Android runtime/bootstrap.",
146
146
  "Install from Termux with:",
147
147
  " pkg update",
148
148
  " pkg install nodejs git ripgrep neovim tar",
@@ -163,6 +163,21 @@ function androidUrl(arch) {
163
163
  return `https://github.com/teamslop/slopcode/releases/download/v${pkg.version}/slopcode-android-${arch}.tar.gz`
164
164
  }
165
165
 
166
+ const androidBunVersion = "1.3.14"
167
+
168
+ function androidBunPackage(arch) {
169
+ return arch === "arm64" ? "bun-linux-aarch64-android" : "bun-linux-x64-android"
170
+ }
171
+
172
+ function androidBunTarget(arch) {
173
+ return path.join(__dirname, "node_modules", "@oven", androidBunPackage(arch))
174
+ }
175
+
176
+ function androidBunUrl(arch) {
177
+ const name = androidBunPackage(arch)
178
+ return `https://registry.npmjs.org/@oven/${name}/-/${name}-${androidBunVersion}.tgz`
179
+ }
180
+
166
181
  async function androidAsset(arch, tmp) {
167
182
  if (process.env.SLOPCODE_ANDROID_ASSET_PATH) return process.env.SLOPCODE_ANDROID_ASSET_PATH
168
183
  const out = path.join(tmp, `slopcode-android-${arch}.tar.gz`)
@@ -206,6 +221,51 @@ async function installAndroid(arch) {
206
221
  }
207
222
  }
208
223
 
224
+ async function androidBunAsset(arch, tmp) {
225
+ if (process.env.SLOPCODE_ANDROID_BUN_ASSET_PATH) return process.env.SLOPCODE_ANDROID_BUN_ASSET_PATH
226
+ const out = path.join(tmp, `${androidBunPackage(arch)}.tgz`)
227
+ const res = await fetch(process.env.SLOPCODE_ANDROID_BUN_ASSET_URL || androidBunUrl(arch))
228
+ if (!res.ok) throw new Error(`Failed to download Android Bun bootstrap: ${res.status} ${res.statusText}`)
229
+ await fs.promises.writeFile(out, Buffer.from(await res.arrayBuffer()))
230
+ return out
231
+ }
232
+
233
+ async function installAndroidBun(arch) {
234
+ const target = androidBunTarget(arch)
235
+ const existing = path.join(target, "bin", "bun")
236
+ if (fs.existsSync(existing)) {
237
+ fs.chmodSync(existing, 0o755)
238
+ return "detected"
239
+ }
240
+
241
+ const tmp = await fs.promises.mkdtemp(path.join(os.tmpdir(), "slopcode-android-bun-"))
242
+ try {
243
+ const archive = await androidBunAsset(arch, tmp)
244
+ const extract = path.join(tmp, "extract")
245
+ await fs.promises.mkdir(extract, { recursive: true })
246
+ const result = require("child_process").spawnSync("tar", ["-xzf", path.basename(archive), "-C", extract], {
247
+ cwd: path.dirname(archive),
248
+ encoding: "utf8",
249
+ timeout: 120000,
250
+ })
251
+ if (result.status !== 0) {
252
+ throw new Error((result.stderr || result.stdout || "tar failed").trim())
253
+ }
254
+ const source = fs.existsSync(path.join(extract, "package", "bin", "bun"))
255
+ ? path.join(extract, "package")
256
+ : extract
257
+ const binary = path.join(source, "bin", "bun")
258
+ if (!fs.existsSync(binary)) throw new Error("Downloaded Android Bun bootstrap is missing bin/bun")
259
+ await fs.promises.rm(target, { recursive: true, force: true })
260
+ await fs.promises.mkdir(path.dirname(target), { recursive: true })
261
+ await fs.promises.rename(source, target)
262
+ fs.chmodSync(path.join(target, "bin", "bun"), 0o755)
263
+ return "installed"
264
+ } finally {
265
+ await fs.promises.rm(tmp, { recursive: true, force: true })
266
+ }
267
+ }
268
+
209
269
  function findBinary() {
210
270
  const { platform, arch } = detectPlatformAndArch()
211
271
  const binaryName = platform === "windows" ? "slopcode.exe" : "slopcode"
@@ -289,7 +349,8 @@ async function main() {
289
349
  if (detectLibc(platform, arch) === "bionic") {
290
350
  try {
291
351
  await installAndroid(arch)
292
- console.log("Android/Termux runtime installed from GitHub release asset")
352
+ await installAndroidBun(arch)
353
+ console.log("Android/Termux runtime and bootstrap installed from release assets")
293
354
  } catch (error) {
294
355
  console.log(termuxMessage())
295
356
  console.error(error.message)
@@ -302,7 +363,13 @@ async function main() {
302
363
 
303
364
  if (found.libc === "bionic") {
304
365
  clearCache()
305
- console.log("Android/Termux runtime package detected; runtime resolver will launch it")
366
+ try {
367
+ await installAndroidBun(arch)
368
+ console.log("Android/Termux runtime package detected; runtime resolver will launch it")
369
+ } catch (error) {
370
+ console.log(termuxMessage())
371
+ console.error(error.message)
372
+ }
306
373
  return
307
374
  }
308
375
  clearCache()