fix(mod_update): try private registry (verdaccio.lossless.digital) first when fetching package versions; fall back to public npm; handle unknown latest versions gracefully in output

This commit is contained in:
2026-02-03 22:58:28 +00:00
parent 4c1608cf94
commit 00fef1ae06
4 changed files with 42 additions and 11 deletions

View File

@@ -128,8 +128,28 @@ export class PackageManagerUtil {
/**
* Get the latest version of a package from npm registry
* Tries private registry (verdaccio.lossless.digital) first via API, then falls back to public npm
*/
public async getLatestVersion(packageName: string): Promise<string | null> {
// URL-encode the package name for scoped packages (@scope/name -> @scope%2fname)
const encodedName = packageName.replace('/', '%2f');
// Try private registry first via direct API call (npm view doesn't work reliably)
try {
const result = await this.shell.execSilent(
`curl -sf "https://verdaccio.lossless.digital/${encodedName}" 2>/dev/null`
);
if (result.exitCode === 0 && result.stdout.trim()) {
const data = JSON.parse(result.stdout.trim());
if (data['dist-tags']?.latest) {
return data['dist-tags'].latest;
}
}
} catch {
// Continue to public registry
}
// Fall back to public npm
try {
const result = await this.shell.execSilent(`npm view ${packageName} version 2>/dev/null`);
if (result.exitCode === 0 && result.stdout.trim()) {

View File

@@ -46,15 +46,13 @@ export const run = async (options: IUpdateOptions = {}): Promise<void> => {
// Only include packages from our predefined list
if (GITZONE_PACKAGES.includes(pkg.name)) {
const latestVersion = await pmUtil.getLatestVersion(pkg.name);
if (latestVersion) {
allPackages.push({
name: pkg.name,
currentVersion: pkg.version,
latestVersion,
packageManager: pm,
needsUpdate: pmUtil.isNewerVersion(pkg.version, latestVersion),
});
}
allPackages.push({
name: pkg.name,
currentVersion: pkg.version,
latestVersion: latestVersion || 'unknown',
packageManager: pm,
needsUpdate: latestVersion ? pmUtil.isNewerVersion(pkg.version, latestVersion) : false,
});
}
}
}
@@ -74,7 +72,11 @@ export const run = async (options: IUpdateOptions = {}): Promise<void> => {
const current = pkg.currentVersion.padEnd(12);
const latest = pkg.latestVersion.padEnd(12);
const pm = pkg.packageManager.padEnd(8);
const status = pkg.needsUpdate ? '⬆️ Update available' : '✓ Up to date';
const status = pkg.latestVersion === 'unknown'
? '? Version unknown'
: pkg.needsUpdate
? '⬆️ Update available'
: '✓ Up to date';
console.log(` ${name}${current}${latest}${pm}${status}`);
}