fix(tools): use pnpm update for global self updates

This commit is contained in:
2026-06-05 17:03:16 +00:00
parent 5279f5dcec
commit ae91c8f23d
3 changed files with 55 additions and 4 deletions
+8
View File
@@ -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
+46 -3
View File
@@ -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,
+1 -1
View File
@@ -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",