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 lockfile v2 #3091

Merged
merged 1 commit into from Jun 14, 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
3 changes: 3 additions & 0 deletions __fixtures__/lockfile-leaf-v2/lerna.json
@@ -0,0 +1,3 @@
{
"version": "1.0.0"
}
5 changes: 5 additions & 0 deletions __fixtures__/lockfile-leaf-v2/package.json
@@ -0,0 +1,5 @@
{
"name": "leaf-lockfile",
"version": "0.0.0-lerna",
"private": true
}
27 changes: 27 additions & 0 deletions __fixtures__/lockfile-leaf-v2/packages/package-1/package-lock.json

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

7 changes: 7 additions & 0 deletions __fixtures__/lockfile-leaf-v2/packages/package-1/package.json
@@ -0,0 +1,7 @@
{
"name": "package-1",
"version": "1.0.0",
"dependencies": {
"tiny-tarball": "^1.0.0"
}
}
17 changes: 16 additions & 1 deletion commands/version/__tests__/update-lockfile-version.test.js
Expand Up @@ -12,7 +12,7 @@ const initFixture = require("@lerna-test/init-fixture")(__dirname);

const { updateLockfileVersion } = require("../lib/update-lockfile-version");

test("updateLockfileVersion", async () => {
test("updateLockfileVersion with lockfile v1", async () => {
const cwd = await initFixture("lockfile-leaf");
const [pkg] = await getPackages(cwd);

Expand All @@ -25,6 +25,21 @@ test("updateLockfileVersion", async () => {
expect(fs.readJSONSync(returnedLockfilePath)).toHaveProperty("version", "2.0.0");
});

test("updateLockfileVersion with lockfile v2", async () => {
const cwd = await initFixture("lockfile-leaf-v2");
const [pkg] = await getPackages(cwd);

pkg.version = "2.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");
});

test("updateLockfileVersion without sibling lockfile", async () => {
const cwd = await initFixture("lifecycle", false);
const [pkg] = await getPackages(cwd);
Expand Down
4 changes: 4 additions & 0 deletions commands/version/lib/update-lockfile-version.js
Expand Up @@ -16,6 +16,10 @@ function updateLockfileVersion(pkg) {
if (obj) {
obj.version = pkg.version;

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

return writeJsonFile(lockfilePath, obj, {
detectIndent: true,
indent: 2,
Expand Down