fix(tools): use pnpm update for global self updates
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## Pending
|
||||
|
||||
### Fixes
|
||||
|
||||
- make global tool self-updates verify and use pnpm's update path
|
||||
- Uses `pnpm update -g <package> --latest` before falling back to install for latest-version updates.
|
||||
- Verifies installed package versions through `pnpm list -g` so pnpm v11 hash roots are handled correctly.
|
||||
|
||||
## 2026-06-05 - 2.19.6
|
||||
|
||||
### Fixes
|
||||
|
||||
@@ -425,14 +425,48 @@ export class PackageManagerUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
const packageSpecifier = `${packageName}@${version}`;
|
||||
console.log(` Installing ${packageSpecifier} via pnpm...`);
|
||||
let effectiveVersion = version;
|
||||
if (version === "latest") {
|
||||
const latestVersion = await this.getLatestMatureVersion(packageName);
|
||||
console.log(` Updating ${packageName} via pnpm...`);
|
||||
try {
|
||||
const updateResult = await this.shell.exec(
|
||||
`${pnpmCommand} update -g ${shellQuote(packageName)} --latest`,
|
||||
);
|
||||
const installedVersion = await this.getCurrentInstalledPackageVersion(
|
||||
packageName,
|
||||
);
|
||||
if (
|
||||
updateResult.exitCode === 0 &&
|
||||
installedVersion &&
|
||||
(!latestVersion || installedVersion === latestVersion)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
// Missing globals need an add instead of update.
|
||||
}
|
||||
|
||||
effectiveVersion = latestVersion || version;
|
||||
}
|
||||
|
||||
const packageSpecifier = `${packageName}@${effectiveVersion}`;
|
||||
console.log(` Installing ${packageSpecifier} via pnpm...`);
|
||||
try {
|
||||
const result = await this.shell.exec(
|
||||
`${pnpmCommand} add -g ${shellQuote(packageSpecifier)}`,
|
||||
);
|
||||
return result.exitCode === 0;
|
||||
if (result.exitCode !== 0) {
|
||||
return false;
|
||||
}
|
||||
if (effectiveVersion === "latest") {
|
||||
return true;
|
||||
}
|
||||
|
||||
const installedVersion = await this.getCurrentInstalledPackageVersion(
|
||||
packageName,
|
||||
);
|
||||
return installedVersion === effectiveVersion;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
@@ -636,6 +670,15 @@ export class PackageManagerUtil {
|
||||
return Array.from(packageMap.values());
|
||||
}
|
||||
|
||||
private async getCurrentInstalledPackageVersion(
|
||||
packageName: string,
|
||||
): Promise<string | null> {
|
||||
const installedPackage = (await this.getCurrentInstalledPackages()).find(
|
||||
(packageInfo) => packageInfo.name === packageName,
|
||||
);
|
||||
return installedPackage?.version || null;
|
||||
}
|
||||
|
||||
private async inspectGlobalRoot(
|
||||
globalDir: string,
|
||||
current: boolean,
|
||||
|
||||
@@ -328,7 +328,7 @@ async function handleSelfUpdate(
|
||||
return false;
|
||||
}
|
||||
|
||||
const success = await pmUtil.installLatest("@git.zone/cli", latestVersion);
|
||||
const success = await pmUtil.installLatest("@git.zone/cli");
|
||||
if (!success) {
|
||||
console.log(
|
||||
"\ngitzone self-update failed. Continuing with the current version.\n",
|
||||
|
||||
Reference in New Issue
Block a user