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

feat(package): .serialize() also writes package-lock version #2160

Conversation

mikemimik
Copy link

@mikemimik mikemimik commented Jun 28, 2019

Description

The @core/package class has a method called .serialize() which writes the in-memory package to disk. When running lerna version the .version property of the package is updated, written, and committed (depending on flags). However, the package-lock.json file (which also has a top level version property) doesn't get updated, and is then out of sync with the package.json file.

This change updates the serialize() function to check if the package has a package-lock.json file in the directory, and if it does: read it in, update the version, then write it to disk.

Motivation and Context

Any monorepo project that has package-lock.json files in it's package folders need to run another step to get the package-lock.json files to stay in sync with the package.json files. The script usually looks something like:

lerna exec -- npm install --no-audit --no-progress
git add packages/**/package-lock.json
git commit -m "chore(package-lock): bump package lock files [skip ci]"
git push

(or some such variation of the above)

Solves: #1998
Linked: #1415

How Has This Been Tested?

Tests where added to the core/package/__tests__/core-package.test.js file.

  • describe("get .lockFileLocation") was added
    • contains it("should return the package-lock location")
  • describe(".serialize()") was updated
    • contains it("writes changes to package.json to disk") updated
    • contains it("writes changes to package-lock to disk") added

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@mikemimik mikemimik force-pushed the feature/update-package-lock-version-prop branch from 90199a6 to 2ec8639 Compare June 28, 2019 20:32
@mikemimik mikemimik force-pushed the feature/update-package-lock-version-prop branch from 0ab7309 to a49d984 Compare July 3, 2019 15:01
@mikemimik
Copy link
Author

It occurs to me that while this update will bump the version property in the package-lock.json file to be the same as the version property in the package.json file, the package-lock.json tree structure does not reflect the changes in package versions. This is a fundamental flaw in this feature work, and thusly should not be merged in yet. I will work to remedy this.

@@ -77,6 +86,9 @@ class Package {
manifestLocation: {
value: path.join(location, "package.json"),
},
lockFileLocation: {
value: path.join(location, "package-lock.json"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be npm-shrinkwrap.json, or yarn.lock, or, or, or...

writeJsonFile(this.lockFileLocation, updatedLockFileData, { detectIndent: true }),
];

return hasPackageLock(this.lockFileLocation) ? pWaterfall(tasks) : Promise.resolve();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need p-waterfall just to chain promises. This check should be done way earlier, too.

@@ -7,7 +7,7 @@
"ci": "npm test -- --ci --maxWorkers=2 && npm run integration -- --ci",
"fix": "npm run lint -- --fix",
"integration": "jest --config jest.integration.js --maxWorkers=2",
"lint": "eslint . --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint",
"lint": "eslint . --ignore-path .gitignore --ignore-pattern \"**/node_modules/\" --cache --cache-location ./node_modules/.cache/eslint",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear why this is necessary, as it is already ignored.

@@ -30,6 +33,12 @@ function shallowCopy(json) {
}, {});
}

// determine if a package-lock.json file exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the appropriate place for lockfile maintenance. It's a function of the version command, not integral to the nature of a Package.

@evocateur
Copy link
Member

v3.18.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants