@vantaloom/cli 0.3.4 → 0.3.6
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 +1 -1
- package/src/cli.mjs +66 -4
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync, spawnSync } from "node:child_process"
|
|
2
2
|
import {
|
|
3
|
+
appendFileSync,
|
|
3
4
|
chmodSync,
|
|
4
5
|
existsSync,
|
|
5
6
|
mkdirSync,
|
|
@@ -125,6 +126,7 @@ async function installFromSource(options) {
|
|
|
125
126
|
|
|
126
127
|
console.log(`${options.update ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
127
128
|
console.log(`version: ${version}`)
|
|
129
|
+
ensureInPath(prefix)
|
|
128
130
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
129
131
|
}
|
|
130
132
|
|
|
@@ -138,6 +140,7 @@ async function installFromPackage(options) {
|
|
|
138
140
|
|
|
139
141
|
console.log(`${options.update ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
140
142
|
console.log(`version: ${version}`)
|
|
143
|
+
ensureInPath(prefix)
|
|
141
144
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
142
145
|
}
|
|
143
146
|
|
|
@@ -292,7 +295,10 @@ async function applyPackage(packageRoot, prefix, options) {
|
|
|
292
295
|
async function syncFromNpmRegistry(options, action) {
|
|
293
296
|
const prefix = safeDirectory(options.prefix ?? defaultPrefix())
|
|
294
297
|
const installedConfig = readInstalledConfig(prefix)
|
|
295
|
-
|
|
298
|
+
// Always derive runtimePackage from current platform — never trust stale config
|
|
299
|
+
// from a different platform (e.g. win32 config baked into a darwin package).
|
|
300
|
+
// Only explicit --runtime-package flag can override.
|
|
301
|
+
const runtimePackage = options.runtimePackage || runtimePackageName(platformId())
|
|
296
302
|
const runtimeVersion = options.runtimeVersion || installedConfig.runtimeVersion || "latest"
|
|
297
303
|
const explicitRegistry = options.npmRegistry || installedConfig.npmRegistry
|
|
298
304
|
const registry = normalizeRegistry(explicitRegistry || detectNpmRegistry() || defaultNpmRegistry)
|
|
@@ -329,6 +335,7 @@ async function syncFromNpmRegistry(options, action) {
|
|
|
329
335
|
console.log(`version: ${version}`)
|
|
330
336
|
console.log(`source: ${runtimePackage}@${resolved.version}`)
|
|
331
337
|
console.log(`registry: ${resolved.registry}`)
|
|
338
|
+
ensureInPath(prefix)
|
|
332
339
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
333
340
|
} finally {
|
|
334
341
|
removeKnownPath(tempRoot, os.tmpdir())
|
|
@@ -370,6 +377,7 @@ async function syncFromRelease(options, action) {
|
|
|
370
377
|
console.log(`${action === "update" ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
371
378
|
console.log(`version: ${version}`)
|
|
372
379
|
console.log(`source: ${repo}@${releaseTag}`)
|
|
380
|
+
ensureInPath(prefix)
|
|
373
381
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
374
382
|
} finally {
|
|
375
383
|
removeKnownPath(tempRoot, os.tmpdir())
|
|
@@ -634,9 +642,9 @@ function mergeRuntimeConfig(packageConfig, existingConfig, overrides) {
|
|
|
634
642
|
if (!merged.releaseTag) {
|
|
635
643
|
merged.releaseTag = defaultReleaseTag
|
|
636
644
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
645
|
+
// Always force runtimePackage to match the running platform — a cross-compiled
|
|
646
|
+
// package may carry a config for a different platform (e.g. win32 inside darwin).
|
|
647
|
+
merged.runtimePackage = runtimePackageName(platformId())
|
|
640
648
|
if (!merged.runtimeVersion) {
|
|
641
649
|
merged.runtimeVersion = "latest"
|
|
642
650
|
}
|
|
@@ -1086,6 +1094,60 @@ async function writeText(filePath, content) {
|
|
|
1086
1094
|
await writeFile(filePath, content)
|
|
1087
1095
|
}
|
|
1088
1096
|
|
|
1097
|
+
// ensureInPath adds the Vantaloom install directory to the user's shell PATH
|
|
1098
|
+
// on macOS and Linux, so `vantaloom` can be run directly after install.
|
|
1099
|
+
// On Windows this is not needed (vantaloom.cmd is run by full path or added via installer).
|
|
1100
|
+
function ensureInPath(prefix) {
|
|
1101
|
+
if (process.platform === "win32") return
|
|
1102
|
+
|
|
1103
|
+
// Check if already in PATH
|
|
1104
|
+
const pathDirs = (process.env.PATH || "").split(":")
|
|
1105
|
+
if (pathDirs.includes(prefix)) return
|
|
1106
|
+
|
|
1107
|
+
// Determine shell profile file
|
|
1108
|
+
const home = os.homedir()
|
|
1109
|
+
const shell = process.env.SHELL || ""
|
|
1110
|
+
let profilePath
|
|
1111
|
+
if (shell.endsWith("/zsh") || existsSync(path.join(home, ".zshrc"))) {
|
|
1112
|
+
profilePath = path.join(home, ".zshrc")
|
|
1113
|
+
} else if (shell.endsWith("/bash")) {
|
|
1114
|
+
// On macOS, bash uses .bash_profile; on Linux, .bashrc
|
|
1115
|
+
profilePath = process.platform === "darwin"
|
|
1116
|
+
? path.join(home, ".bash_profile")
|
|
1117
|
+
: path.join(home, ".bashrc")
|
|
1118
|
+
} else if (existsSync(path.join(home, ".profile"))) {
|
|
1119
|
+
profilePath = path.join(home, ".profile")
|
|
1120
|
+
} else {
|
|
1121
|
+
profilePath = path.join(home, ".profile")
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// Use $HOME-relative path for portability
|
|
1125
|
+
const homeRelative = prefix.startsWith(home)
|
|
1126
|
+
? `$HOME${prefix.slice(home.length)}`
|
|
1127
|
+
: prefix
|
|
1128
|
+
const exportLine = `export PATH="${homeRelative}:$PATH"`
|
|
1129
|
+
const marker = "# vantaloom"
|
|
1130
|
+
|
|
1131
|
+
// Check if already added to profile
|
|
1132
|
+
try {
|
|
1133
|
+
if (existsSync(profilePath)) {
|
|
1134
|
+
const content = readFileSync(profilePath, "utf8")
|
|
1135
|
+
if (content.includes("vantaloom") && content.includes("PATH")) return
|
|
1136
|
+
}
|
|
1137
|
+
} catch {}
|
|
1138
|
+
|
|
1139
|
+
// Append to profile
|
|
1140
|
+
try {
|
|
1141
|
+
const entry = `\n${marker}\n${exportLine}\n`
|
|
1142
|
+
appendFileSync(profilePath, entry)
|
|
1143
|
+
console.log(`PATH: added ${prefix} to ${profilePath}`)
|
|
1144
|
+
console.log(` run: source ${profilePath} (or open a new terminal)`)
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
console.log(`PATH: could not update ${profilePath}: ${error.message}`)
|
|
1147
|
+
console.log(` add manually: ${exportLine}`)
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1089
1151
|
function killTrayProcess(prefix) {
|
|
1090
1152
|
if (process.platform === "win32") {
|
|
1091
1153
|
// Try PID file first (new tray versions write runtime/tray.pid).
|