Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5ecf7b4

Browse files
committed
Update package-lock.json in version.mjs
1 parent ca7a9f8 commit 5ecf7b4

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

scripts/version.mjs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from "assert";
2+
import fs from "fs/promises";
23
import path from "path";
34
import {
45
getPackage,
@@ -13,17 +14,23 @@ const argv = process.argv.slice(2);
1314
const version = argv[0];
1415
assert(version);
1516

17+
/**
18+
* Returns true if this name belongs to a Miniflare package
19+
* @param {string} name
20+
* @returns {boolean}
21+
*/
22+
function isMiniflarePkg(name) {
23+
return name.startsWith(scope) || name === "miniflare";
24+
}
25+
1626
/**
1727
* Updates the version number for all scoped dependencies in <dependencies>
1828
* @param {string} newVersion
1929
* @param {Record<string, string>} dependencies
2030
*/
2131
function updateDependencyVersions(newVersion, dependencies) {
2232
for (const dependency in dependencies) {
23-
if (
24-
dependencies.hasOwnProperty(dependency) &&
25-
(dependency.startsWith(scope) || dependency === "miniflare")
26-
) {
33+
if (dependencies.hasOwnProperty(dependency) && isMiniflarePkg(dependency)) {
2734
dependencies[dependency] = newVersion;
2835
}
2936
}
@@ -41,6 +48,34 @@ async function updateVersions(newVersion) {
4148
rootPkg.version = newVersion;
4249
await setPackage(projectRoot, rootPkg);
4350

51+
// Update package-lock.json
52+
console.log("--> Updating package-lock.json's versions...");
53+
const pkgLockPath = path.join(projectRoot, "package-lock.json");
54+
const pkgLock = JSON.parse(await fs.readFile(pkgLockPath, "utf8"));
55+
pkgLock.version = newVersion;
56+
for (const [pkgPath, pkg] of Object.entries(pkgLock.packages)) {
57+
if (
58+
(pkg.name && isMiniflarePkg(pkg.name)) ||
59+
pkgPath === "packages/miniflare"
60+
) {
61+
pkg.version = newVersion;
62+
updateDependencyVersions(newVersion, pkg.dependencies);
63+
updateDependencyVersions(newVersion, pkg.devDependencies);
64+
updateDependencyVersions(newVersion, pkg.peerDependencies);
65+
updateDependencyVersions(newVersion, pkg.optionalDependencies);
66+
}
67+
}
68+
for (const [pkgName, pkg] of Object.entries(pkgLock.dependencies)) {
69+
if (isMiniflarePkg(pkgName)) {
70+
updateDependencyVersions(newVersion, pkg.requires);
71+
}
72+
}
73+
await fs.writeFile(
74+
pkgLockPath,
75+
JSON.stringify(pkgLock, null, 2) + "\n",
76+
"utf8"
77+
);
78+
4479
// Update sub-packages
4580
for (const name of pkgsList) {
4681
console.log(`--> Updating ${name}'s version...`);

0 commit comments

Comments
 (0)