fix(cli): resolve package updates on Windows
This commit is contained in:
@@ -63,14 +63,16 @@ const execFileAsync = promisify(execFile);
|
||||
|
||||
/** Resolve every installed WRNexus dependency independently and in parallel. */
|
||||
export async function latestPackageVersions(names: string[]): Promise<Map<string, string>> {
|
||||
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
||||
const unique = [...new Set(names.filter((name) => name.startsWith("@wrnexus/")))];
|
||||
const entries = await Promise.all(
|
||||
unique.map(async (name) => {
|
||||
try {
|
||||
const { stdout } = await execFileAsync(npm, ["view", name, "version", "--json"], {
|
||||
encoding: "utf8",
|
||||
});
|
||||
const command = process.platform === "win32" ? (process.env.ComSpec ?? "cmd.exe") : "npm";
|
||||
const args =
|
||||
process.platform === "win32"
|
||||
? ["/d", "/s", "/c", "npm", "view", name, "version", "--json"]
|
||||
: ["view", name, "version", "--json"];
|
||||
const { stdout } = await execFileAsync(command, args, { encoding: "utf8" });
|
||||
const parsed = JSON.parse(stdout.trim()) as string | string[];
|
||||
const version = Array.isArray(parsed) ? parsed.at(-1) : parsed;
|
||||
return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version)
|
||||
@@ -1274,6 +1276,13 @@ export async function runUpdate(dir: string, args: string[]): Promise<void> {
|
||||
? new Map<string, string>()
|
||||
: await latestPackageVersions(dependencyNames);
|
||||
|
||||
if (!versionArg && dependencyNames.length > 0 && packageVersions.size === 0) {
|
||||
throw new Error(
|
||||
`Unable to resolve any of ${new Set(dependencyNames).size} installed WRNexus package ` +
|
||||
`version(s) from npm. Check the @wrnexus registry and authentication before retrying.`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`\n ⚡ wrnexus update → migrations ${target}${dryRun ? " (dry run)" : ""}`);
|
||||
if (!versionArg) {
|
||||
console.log(
|
||||
|
||||
Reference in New Issue
Block a user