Skip to content

Commit 7b49802

Browse files
CopilotAzgaar
andauthored
fix: sync package-lock.json version fields during automated version bump (#1345)
* Initial plan * fix: update package-lock.json version fields during version bump Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
1 parent 2eeb016 commit 7b49802

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/bump-version.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Updates:
88
* - public/versioning.js — VERSION constant
99
* - package.json — "version" field
10+
* - package-lock.json — top-level "version" and packages[""].version fields
1011
* - src/index.html — ?v= cache-busting hashes for changed public/*.js files
1112
*
1213
* Usage:
@@ -28,6 +29,7 @@ const {execSync} = require("child_process");
2829

2930
const repoRoot = path.resolve(__dirname, "..");
3031
const packageJsonPath = path.join(repoRoot, "package.json");
32+
const packageLockJsonPath = path.join(repoRoot, "package-lock.json");
3133
const versioningPath = path.join(repoRoot, "public", "versioning.js");
3234
const indexHtmlPath = path.join(repoRoot, "src", "index.html");
3335

@@ -138,6 +140,22 @@ function updatePackageJson(newVersion, dry) {
138140
console.log(` package.json ${oldVersion}${newVersion}`);
139141
}
140142

143+
function updatePackageLockJson(newVersion, dry) {
144+
if (!fs.existsSync(packageLockJsonPath)) {
145+
console.log(" package-lock.json (not found, skipping)");
146+
return;
147+
}
148+
const original = readFile(packageLockJsonPath);
149+
const lock = JSON.parse(original);
150+
const oldVersion = lock.version;
151+
lock.version = newVersion;
152+
if (lock.packages && lock.packages[""]) {
153+
lock.packages[""].version = newVersion;
154+
}
155+
if (!dry) writeFile(packageLockJsonPath, `${JSON.stringify(lock, null, 2)}\n`);
156+
console.log(` package-lock.json ${oldVersion}${newVersion}`);
157+
}
158+
141159
function updateIndexHtmlHashes(newVersion, dry) {
142160
const changedFiles = getChangedPublicJsFiles();
143161

@@ -231,6 +249,7 @@ async function main() {
231249

232250
updateVersioningJs(newVersion, dry);
233251
updatePackageJson(newVersion, dry);
252+
updatePackageLockJson(newVersion, dry);
234253
updateIndexHtmlHashes(newVersion, dry);
235254

236255
console.log(`\n[bump-version] ${dry ? "(dry run) " : ""}done.\n`);

0 commit comments

Comments
 (0)