@vantaloom/cli 0.3.3 → 0.3.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +57 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vantaloom/cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Vantaloom local runtime manager.",
package/src/cli.mjs CHANGED
@@ -44,6 +44,8 @@ if (shouldDisableTLS()) {
44
44
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
45
45
  }
46
46
 
47
+ const cliVersion = readJSONIfExists(path.join(cliRoot, "package.json")).version ?? "unknown"
48
+
47
49
  export async function main(argv) {
48
50
  const command = argv[0] ?? "help"
49
51
  const options = parseOptions(argv.slice(1))
@@ -53,6 +55,10 @@ export async function main(argv) {
53
55
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
54
56
  }
55
57
 
58
+ if (command === "install" || command === "update") {
59
+ console.log(`vantaloom-cli v${cliVersion} (${platformId()})`)
60
+ }
61
+
56
62
  switch (command) {
57
63
  case "install":
58
64
  if (options.package) {
@@ -218,9 +224,16 @@ async function applyPackage(packageRoot, prefix, options) {
218
224
  // don't write tray.pid, so vantaloomctl stop won't find them).
219
225
  killTrayProcess(prefix)
220
226
 
227
+ // Copy package contents to install prefix
221
228
  for (const name of ["bin", "web", "cli"]) {
222
- removeKnownPath(path.join(prefix, name), prefix)
223
- await cp(path.join(packageRoot, name), path.join(prefix, name), {
229
+ const src = path.join(packageRoot, name)
230
+ const dst = path.join(prefix, name)
231
+ if (!existsSync(src)) {
232
+ console.error(` warning: package missing ${name}/ directory`)
233
+ continue
234
+ }
235
+ removeKnownPath(dst, prefix)
236
+ await cp(src, dst, {
224
237
  recursive: true,
225
238
  force: true,
226
239
  dereference: false,
@@ -228,14 +241,28 @@ async function applyPackage(packageRoot, prefix, options) {
228
241
  }
229
242
 
230
243
  // Ensure binaries are executable on Unix (cross-compiled from Windows they lose +x)
231
- if (process.platform !== "win32") {
232
- const binDir = path.join(prefix, "bin")
244
+ const binDir = path.join(prefix, "bin")
245
+ if (process.platform !== "win32" && existsSync(binDir)) {
233
246
  for (const entry of readdirSync(binDir)) {
234
247
  const binPath = path.join(binDir, entry)
235
248
  try { chmodSync(binPath, 0o755) } catch {}
236
249
  }
237
250
  }
238
251
 
252
+ // Verify vantaloomctl binary exists before trying to run it
253
+ const ctlBin = path.join(prefix, "bin", binaryName("vantaloomctl"))
254
+ if (!existsSync(ctlBin)) {
255
+ const binContents = existsSync(binDir) ? readdirSync(binDir) : []
256
+ const srcBinContents = existsSync(path.join(packageRoot, "bin")) ? readdirSync(path.join(packageRoot, "bin")) : []
257
+ throw new Error(
258
+ `vantaloomctl binary not found at ${ctlBin}\n` +
259
+ ` installed bin/: [${binContents.join(", ")}]\n` +
260
+ ` package bin/: [${srcBinContents.join(", ")}]\n` +
261
+ ` platform: ${platformId()}\n` +
262
+ ` This may indicate a corrupt download. Try again or install from source.`
263
+ )
264
+ }
265
+
239
266
  await writeLauncher(prefix)
240
267
  await writeText(path.join(prefix, "cli", "config.json"), `${JSON.stringify(mergedConfig, null, 2)}\n`)
241
268
  await writeText(path.join(prefix, "VERSION"), `${version}\n`)
@@ -243,7 +270,7 @@ async function applyPackage(packageRoot, prefix, options) {
243
270
  force: true,
244
271
  })
245
272
 
246
- run(path.join(prefix, "bin", binaryName("vantaloomctl")), [
273
+ run(ctlBin, [
247
274
  "install",
248
275
  "--prefix",
249
276
  prefix,
@@ -252,7 +279,7 @@ async function applyPackage(packageRoot, prefix, options) {
252
279
  ])
253
280
 
254
281
  if (!options.noStart) {
255
- run(path.join(prefix, "bin", binaryName("vantaloomctl")), [
282
+ run(ctlBin, [
256
283
  "start",
257
284
  "--prefix",
258
285
  prefix,
@@ -265,7 +292,10 @@ async function applyPackage(packageRoot, prefix, options) {
265
292
  async function syncFromNpmRegistry(options, action) {
266
293
  const prefix = safeDirectory(options.prefix ?? defaultPrefix())
267
294
  const installedConfig = readInstalledConfig(prefix)
268
- const runtimePackage = options.runtimePackage || installedConfig.runtimePackage || runtimePackageName(platformId())
295
+ // Always derive runtimePackage from current platform — never trust stale config
296
+ // from a different platform (e.g. win32 config baked into a darwin package).
297
+ // Only explicit --runtime-package flag can override.
298
+ const runtimePackage = options.runtimePackage || runtimePackageName(platformId())
269
299
  const runtimeVersion = options.runtimeVersion || installedConfig.runtimeVersion || "latest"
270
300
  const explicitRegistry = options.npmRegistry || installedConfig.npmRegistry
271
301
  const registry = normalizeRegistry(explicitRegistry || detectNpmRegistry() || defaultNpmRegistry)
@@ -520,11 +550,22 @@ async function resolveNpmPackage({ registry, name, version }) {
520
550
  }
521
551
 
522
552
  async function downloadNpmTarball({ tarballUrl, target, packageName, version }) {
523
- const response = await fetch(tarballUrl, {
524
- headers: {
525
- "User-Agent": "vantaloom-cli",
526
- },
527
- })
553
+ console.log(` downloading ${packageName}@${version}...`)
554
+ let response
555
+ try {
556
+ response = await fetch(tarballUrl, {
557
+ headers: {
558
+ "User-Agent": "vantaloom-cli",
559
+ },
560
+ signal: AbortSignal.timeout(120000),
561
+ })
562
+ } catch (error) {
563
+ const causeCode = error?.cause?.code || ""
564
+ const causeMsg = causeCode || error?.cause?.message || error.message || ""
565
+ const isSsl = causeCode.includes("CERT") || causeCode === "UNABLE_TO_GET_ISSUER_CERT_LOCALLY"
566
+ const hint = isSsl ? `\n Fix: run with --no-strict-ssl` : ""
567
+ throw new Error(`failed to download ${packageName}@${version} from ${tarballUrl}: ${causeMsg}${hint}`)
568
+ }
528
569
  if (!response.ok) {
529
570
  const detail = await response.text().catch(() => "")
530
571
  throw new Error(`failed to download ${packageName}@${version}: HTTP ${response.status}${detail ? ` ${detail.slice(0, 200)}` : ""}`)
@@ -532,6 +573,7 @@ async function downloadNpmTarball({ tarballUrl, target, packageName, version })
532
573
 
533
574
  const buffer = Buffer.from(await response.arrayBuffer())
534
575
  await writeFile(target, buffer)
576
+ console.log(` downloaded ${(buffer.length / 1024 / 1024).toFixed(1)} MB`)
535
577
  }
536
578
 
537
579
  function shouldUseSourceInstall(options) {
@@ -595,9 +637,9 @@ function mergeRuntimeConfig(packageConfig, existingConfig, overrides) {
595
637
  if (!merged.releaseTag) {
596
638
  merged.releaseTag = defaultReleaseTag
597
639
  }
598
- if (!merged.runtimePackage) {
599
- merged.runtimePackage = runtimePackageName(platformId())
600
- }
640
+ // Always force runtimePackage to match the running platform — a cross-compiled
641
+ // package may carry a config for a different platform (e.g. win32 inside darwin).
642
+ merged.runtimePackage = runtimePackageName(platformId())
601
643
  if (!merged.runtimeVersion) {
602
644
  merged.runtimeVersion = "latest"
603
645
  }