From 95324a5adacc3bae33334906885eb31b68bc1c31 Mon Sep 17 00:00:00 2001 From: 4Source <38220764+4Source@users.noreply.github.com> Date: Fri, 13 Mar 2026 16:42:03 +0100 Subject: [PATCH] Fix missing package-lock update of version-change.mjs --- test/version.test.ts | 2 ++ version-change.mjs | 40 ++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/test/version.test.ts b/test/version.test.ts index 2e293f1..88ec82f 100644 --- a/test/version.test.ts +++ b/test/version.test.ts @@ -1,9 +1,11 @@ import { version as manifestVersion, minAppVersion as manifestMinAppVersion } from '../manifest.json'; import { version as packageVersion } from '../package.json'; +import { version as packageLockVersion } from '../package.json'; import versions from '../versions.json'; test('Versions matching', () => { expect(manifestVersion).toBe(packageVersion); + expect(manifestVersion).toBe(packageLockVersion); expect(Object.keys(versions).find(value => value === manifestVersion)).toBe(manifestVersion); expect(Object.entries(versions).find(value => value[0] === manifestVersion)?.[1]).toBe(manifestMinAppVersion); }); \ No newline at end of file diff --git a/version-change.mjs b/version-change.mjs index 240c6ae..3307364 100644 --- a/version-change.mjs +++ b/version-change.mjs @@ -1,45 +1,53 @@ -import { readFileSync, writeFileSync } from "fs"; -import { valid } from "semver"; +import { execSync } from 'child_process'; +import { readFileSync, writeFileSync } from 'fs'; +import { valid } from 'semver'; const newVersion = process.argv.find(value => value.startsWith('--new_version')); if (!newVersion) { - throw Error('Param --new_version is missing!'); + throw Error('Param --new_version is missing!'); } const targetVersion = newVersion.split('=')[1]; if (!targetVersion) { - throw Error('Param --new_version is empty!'); + throw Error('Param --new_version is empty!'); } if (!valid(targetVersion)) { - throw Error('New version is invalid!') + throw Error('New version is invalid!') } // read minAppVersion from manifest.json -let manifestFile = JSON.parse(readFileSync("manifest.json", "utf8")); +let manifestFile = JSON.parse(readFileSync('manifest.json', 'utf8')); const { minAppVersion } = manifestFile; -if (!minAppVersion || minAppVersion === "") { - throw Error('Missing minAppVersion in "manifest.json"'); +if (!minAppVersion || minAppVersion === '') { + throw Error(`Missing minAppVersion in 'manifest.json'`); } // update version to target version manifestFile.version = targetVersion; -writeFileSync("manifest.json", JSON.stringify(manifestFile, null, "\t")); +writeFileSync('manifest.json', JSON.stringify(manifestFile, null, '\t')); // update version in package -let packageFile = JSON.parse(readFileSync("package.json", "utf8")); +let packageFile = JSON.parse(readFileSync('package.json', 'utf8')); packageFile.version = targetVersion; -writeFileSync("package.json", JSON.stringify(packageFile, null, "\t")); +writeFileSync('package.json', JSON.stringify(packageFile, null, '\t')); + +// update version in package-lock +try { + execSync('npm install', { stdio: 'inherit' }); +} catch (error) { + throw Error('npm installed failed: ' + error); +} // read versions file -let versionsFile = JSON.parse(readFileSync("versions.json", "utf8")); +let versionsFile = JSON.parse(readFileSync('versions.json', 'utf8')); let keys = Object.keys(versionsFile); // remove existing versions with same minAppVersion keys.forEach(key => { - if (minAppVersion === versionsFile[key]) { - delete versionsFile[key]; - } + if (minAppVersion === versionsFile[key]) { + delete versionsFile[key]; + } }); // update versions.json with target version and minAppVersion from manifest.json versionsFile[targetVersion] = minAppVersion; -writeFileSync("versions.json", JSON.stringify(versionsFile, null, "\t")); +writeFileSync('versions.json', JSON.stringify(versionsFile, null, '\t'));