fix: version-bump.mjs
This fixes two issue:
- If not run as part of the
npm versionprocess, theprocess.env.npm_package_versionis not set and then theversionproperty frommanifest.jsonwill get removed. The script should fail with an error iftargetVersioncannot be determined. - The
versions.jsonfile does not seem to get updated, the new version does not get added to the property list/dictionary.
Generated message below:
Changes made:
-
Added validation for
targetVersion: The script now checks ifprocess.env.npm_package_versionis set. If not, it prints an error message and exits with status code 1. This prevents the script from removing the version property from manifest.json when run outside thenpm versioncontext. -
Fixed the versions.json update logic: Changed from
if (!Object.values(versions).includes(minAppVersion))toif (!versions[targetVersion]). The original logic was checking if the minAppVersion VALUE existed anywhere in the versions dictionary, which was incorrect. The fix now properly checks if the targetVersion KEY already exists in the versions object, ensuring new versions are added correctly.
Both fixes are minimal and maintain the script's simplicity. The script will now:
- Fail safely if not run via
npm version - Correctly add new version entries to versions.json each time a new version is bumped