diff --git a/changelog.md b/changelog.md index 9e6ba66..2d8f91a 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ ## Pending +### Fixes + +- Prevent startup update checks from crashing when installed package metadata is incomplete. + ## 2026-05-10 - 2.16.0 diff --git a/ts/gitzone.cli.ts b/ts/gitzone.cli.ts index 7b00379..d6fa53b 100644 --- a/ts/gitzone.cli.ts +++ b/ts/gitzone.cli.ts @@ -2,6 +2,7 @@ import * as plugins from "./plugins.js"; import * as paths from "./paths.js"; import { GitzoneConfig } from "./classes.gitzoneconfig.js"; import { getRawCliMode } from "./helpers.climode.js"; +import { commitinfo } from "./00_commitinfo_data.js"; const gitzoneSmartcli = new plugins.smartcli.Smartcli(); @@ -11,20 +12,29 @@ export let run = async () => { // get packageInfo const projectInfo = new plugins.projectinfo.ProjectInfo(paths.packageDir); + const projectInfoVersion = (projectInfo.npm as any)?.version; + const packageVersion = + typeof projectInfoVersion === "string" && projectInfoVersion.length > 0 + ? projectInfoVersion + : commitinfo.version; // check for updates if (rawCliMode.checkUpdates) { const smartupdateInstance = new plugins.smartupdate.SmartUpdate(); - await smartupdateInstance.check( - "gitzone", - projectInfo.npm.version, - "http://gitzone.gitlab.io/gitzone/changelog.html", - ); + try { + await smartupdateInstance.check( + "gitzone", + packageVersion, + "http://gitzone.gitlab.io/gitzone/changelog.html", + ); + } catch { + // Update checks must never block actual CLI commands. + } } if (rawCliMode.output === "human") { console.log("---------------------------------------------"); } - gitzoneSmartcli.addVersion(projectInfo.npm.version); + gitzoneSmartcli.addVersion(packageVersion); // ======> Standard task <======