-
-
Notifications
You must be signed in to change notification settings - Fork 289
fix(provider): fix npm provider to update package-lock.json and npm-shrinkwrap.json if they exist #813
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
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #813 +/- ##
==========================================
+ Coverage 97.33% 97.43% +0.09%
==========================================
Files 42 42
Lines 2104 2141 +37
==========================================
+ Hits 2048 2086 +38
+ Misses 56 55 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left a few comments 🙂
commitizen/providers.py
Outdated
@@ -1,6 +1,7 @@ | |||
from __future__ import annotations | |||
|
|||
import json | |||
import jsonpath_ng # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I know why do we need #type: ignore
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, may I know why do we need to install this package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also like to know, is it not possible to update it accessing like a json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem came from trying to access the correct element in "packages". Here's the sample JSON:
{
"name": "whatever",
"version": "0.1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "whatever",
"version": "0.1.0"
},
"someotherpackage": {
"version": "0.1.0"
}
}
}
The json path expression is $.packages.''.version
, but I couldn't get that to work via the json object directly.
And the # type: ignore
is there b/c the library doesn't appear to have type hints, nor is there anything available for it on typeshed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay - so not sure why I was struggling with using the json.loads and updated the dict, but I have that working now. Will remove the dependency on jsonpath_ng.
commitizen/providers.py
Outdated
@@ -166,6 +167,87 @@ class NpmProvider(JsonProvider): | |||
filename = "package.json" | |||
|
|||
|
|||
class Npm2Provider(VersionProvider): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the issue, I'd suggest we update the NpmProvider
directly, but I'm not a JavaScript users. Would love to see how @woile thinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so as well, if package-lock.json
and or npm-shrinkwrap.json
exists they should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll go back and update the existing NpmProvider and take out the Npm2Provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the PR from feat to fix then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @davidlday , thanks for your contribution! The overall implementation is great! Just a few minor thing needs to be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you so much! @Lee-W take a last look and if ready go ahead and merge 🙏🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidlday Awesome! Just left one minor suggestion. After rebasing, we're good to go
tests/test_version_providers.py
Outdated
@pytest.mark.parametrize( | ||
"pkg_lock_content,pkg_lock_expected,pkg_shrinkwrap_content,pkg_shrinkwrap_expected", | ||
( | ||
(None, None, None, None), | ||
(NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED, None, None), | ||
(None, None, NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), | ||
( | ||
NPM_LOCKFILE_JSON, | ||
NPM_LOCKFILE_EXPECTED, | ||
NPM_LOCKFILE_JSON, | ||
NPM_LOCKFILE_EXPECTED, | ||
), | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pytest.mark.parametrize( | |
"pkg_lock_content,pkg_lock_expected,pkg_shrinkwrap_content,pkg_shrinkwrap_expected", | |
( | |
(None, None, None, None), | |
(NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED, None, None), | |
(None, None, NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), | |
( | |
NPM_LOCKFILE_JSON, | |
NPM_LOCKFILE_EXPECTED, | |
NPM_LOCKFILE_JSON, | |
NPM_LOCKFILE_EXPECTED, | |
), | |
), | |
) | |
@pytest.mark.parametrize( | |
"pkg_shrinkwrap_content, pkg_shrinkwrap_expected", | |
( | |
(NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), | |
(None, None) | |
) | |
) | |
@pytest.mark.parametrize( | |
"pkg_lock_content, pkg_lock_expected", | |
( | |
(NPM_LOCKFILE_JSON, NPM_LOCKFILE_EXPECTED), | |
(None, None) | |
) | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lee-W - Applying suggestion now. Sorry, you made this suggestion earlier, and I wasn't getting it. Makes sense to me now.
Hi @davidlday , could you please rebase from the master branch so that we can merge it? You can do it through |
…k.json, and npm-shrinkwrap.json closes commitizen-tools#804
…hrinkwrap.json if they exist closes commitizen-tools#804
…nd npm-shrinkwrap.json if they exist closes commitizen-tools#804
@Lee-W - apologies, been awhile since I've done a rebase. Let me know if I messed anything up. |
No worry 🙂 Just want to fix a CI issue along with this PR. |
closes #804
Description
Added new version provider
npm2
which usesjsonpath_ng
to update version in$.version
$.version
,$.packages.''.version
$.version
,$.packages.''.version
package-lock.json
andnpm-shrinkwrap.json
may or may not exist.Checklist
./scripts/format
and./scripts/test
locally to ensure this change passes linter check and testExpected behavior
When using
npm2
as the version provider, the following files will have the project's version number updated appropriately:package.json
(required)package-lock.json
(optional)npm-shrinkwrap.json
(optional)Steps to Test This Pull Request
Test cases added to
tests/test_version_providers.py
.Additional context