Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly update dependencies lockfile v2 #3275

Merged
merged 3 commits into from Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

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