Skip to content

Commit

Permalink
fix: properly update dependencies lockfile v2 (#3275)
Browse files Browse the repository at this point in the history
  • Loading branch information
natiz committed Aug 9, 2022
1 parent 4f9f301 commit d7c398b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -2,6 +2,10 @@
"name": "package-1",
"version": "1.0.0",
"dependencies": {
"tiny-tarball": "^1.0.0"
"tiny-tarball": "^1.0.0",
"package-2": "^1.0.0"
},
"devDependencies": {
"package-3": "2.0.0"
}
}
6 changes: 5 additions & 1 deletion commands/version/__tests__/update-lockfile-version.test.js
Expand Up @@ -30,14 +30,18 @@ test("updateLockfileVersion with lockfile v2", async () => {
const [pkg] = await getPackages(cwd);

pkg.version = "2.0.0";
pkg.dependencies["package-1"] = "^2.0.0";
pkg.devDependencies["package-2"] = "3.0.0";

const returnedLockfilePath = await updateLockfileVersion(pkg);

expect(returnedLockfilePath).toBe(path.join(pkg.location, "package-lock.json"));
expect(Array.from(loadJsonFile.registry.keys())).toStrictEqual(["/packages/package-1"]);
const updatedLockfile = fs.readJSONSync(returnedLockfilePath);
expect(updatedLockfile).toHaveProperty("version", "2.0.0");
expect(updatedLockfile).toHaveProperty(["packages", "", "version"], "2.0.0");
expect(updatedLockfile).toHaveProperty(["packages", "", "dependencies", "package-1"], "^2.0.0");
expect(updatedLockfile).toHaveProperty(["packages", "", "dependencies", "tiny-tarball"], "^1.0.0");
expect(updatedLockfile).toHaveProperty(["packages", "", "devDependencies", "package-2"], "3.0.0");
});

test("updateLockfileVersion without sibling lockfile", async () => {
Expand Down
6 changes: 6 additions & 0 deletions commands/version/lib/update-lockfile-version.js
Expand Up @@ -18,6 +18,12 @@ function updateLockfileVersion(pkg) {

if (obj.packages && obj.packages[""]) {
obj.packages[""].version = pkg.version;
if (obj.packages[""].dependencies) {
obj.packages[""].dependencies = pkg.dependencies;
}
if (obj.packages[""].devDependencies) {
obj.packages[""].devDependencies = pkg.devDependencies;
}
}

return writeJsonFile(lockfilePath, obj, {
Expand Down

0 comments on commit d7c398b

Please sign in to comment.