-
Notifications
You must be signed in to change notification settings - Fork 29
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
Respect peer dependencies #59
base: master
Are you sure you want to change the base?
Conversation
src/commands/check.js
Outdated
@@ -76,7 +76,8 @@ export const handler = catchAsyncError(async opts => { | |||
.map(({ncuValue}) => ncuValue) | |||
.join(','); | |||
const currentVersions = ncu.getCurrentDependencies(packageJson, {dep: ncuDepGroups}); | |||
const latestVersions = await ncu.queryVersions(currentVersions, {versionTarget: 'latest'}); | |||
const peerDependencies = ncu.getPeerDependencies(currentVersions, {}); | |||
const latestVersions = await ncu.queryVersions(currentVersions, {versionTarget: 'latest', peerDependencies}); |
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.
Is there a way to show some explanation to the user e.g. that latest released version of the dependency is v2 but the latest version that satisfies peerDependencies
is v1.2?
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.
Currently, with npm-check-updates
, you can provide only one strategy at time. Hence, we would have to call ncu.queryVersions
two times (one call with peerDependencies and one call without them). However, the package data will then be fetched two times from npm servers which doubles the process time. I don't think that this would be a good solution.
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.
which doubles the process time
We can fetch them in parallel. My concern here is it may introduce confusion when you're absolutely sure the latest version of the package is v2
but npm-upgrade
tells you that the latest version is v1.2
without any explanation.
By the way, what does ncu.getPeerDependencies(currentVersions, {})
method actually do?
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.
We can fetch them in parallel. My concern here is it may introduce confusion when you're absolutely sure the latest version of the package is
v2
butnpm-upgrade
tells you that the latest version isv1.2
without any explanation.
I understand that and I just had a deeper insight in the code. It looks like npm-check-updates
caches the network responses, so a second call of ncu.queryVersions()
doesn't trigger any new network requests and hence runs quite fast. Therefore, we can call it indeed twice, without any problems.
I just pushed a new commit which adds a hint, if the suggested version is not the latest version. It prints (ignored incompatible latest version X.Y.Z)
in the output table.
For now, this is just a proof of concept. I think it would be better to show incompatible versions in a separate table just like the manually ignored versions. How about that?
By the way, what does
ncu.getPeerDependencies(currentVersions, {})
method actually do?
For every package in currentVersions
, it reads the local package.json
(from the directory node_modules/package/
) and extracts the section peerDependencies
. All results are merged and sorted by package. See https://github.com/raineorshine/npm-check-updates/blob/v11.4.1/lib/index.js#L232
The result is added to the options, so that the filterPredicate
can filter all versions that satisfy the peer dependencies.
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, I've changed the output for incompatible updates. Here are two examples:
First example
Checking for outdated dependencies for ".../package.json"...
[====================] 2/2 100%
New versions of active modules available:
ncu-test-return-version 1.0.0 → 1.1.0
Ignored incompatible updates (peer dependencies):
ncu-test-return-version 1.0.0 → 2.0.0
Second example
Checking for outdated dependencies for ".../package.json"...
[====================] 50/50 100%
New versions of active modules available:
@nextcloud/dialogs ^3.1.1 → ^3.1.2
@nextcloud/router ^1.2.0 → ^2.0.0
@nextcloud/vue ^3.8.0 → ^3.9.0
@nextcloud/webpack-vue-config ^4.0.1 → ^4.0.2
@babel/core ^7.13.14 → ^7.13.15
@babel/preset-env ^7.13.12 → ^7.13.15
core-js ^3.10.0 → ^3.10.1
eslint ^7.23.0 → ^7.24.0
eslint-plugin-vue ^7.8.0 → ^7.9.0
webpack ^5.28.0 → ^5.32.0
Ignored incompatible updates (peer dependencies):
css-loader ^4.3.0 → ^5.2.1
eslint-plugin-promise ^4.3.1 → ^5.1.0
sass-loader ^10.1.1 → ^11.0.1
Ignored updates:
From To Ignored versions Reason
vue-fragment 1.5.1 → 1.5.2 1.5.2 buggy version
87b4f9f
to
9778689
Compare
It's much better now, but it's still not clear what package is actually blocking other packages from updating. E.g. in my case I see the following:
So I want to know what package prevents |
Another issue is I had to run
After I have agreed with all updates and ran
After doing same steps again:
And only after 3rd time I've upgraded all the Angular packages. It happens because some packages has other packages in their peer dependencies e.g. So the issue is current logic doesn't take into account that version of the peer dependency may change after the actual upgrade - it only takes current peer versions into account. Another issue is only immediate peer deps are tracked which means an update to
|
You mentioned three aspects: 1. Show source of peer incompatibility
2. Multiple calls of
|
So what approach would work in your opinion? |
An approach would be to automatically call Another approach would be to execute Approach 1The above actions are executed before the list of upgradable packages are shown to the user. This means, the user gets the following list in your example:
However, if the user says Approach 2In this approach, we do this iteratively. When executing
But after the user has answered all questions, but before asking for updating |
I've made a PR for With that PR, it will be possible to add the reason to the list of incompatible updates. I will update this PR after the above PR has been merged and released. Teaser 1:
Teaser 2:
|
I'm moving some more code to |
Final update with much simplification was done. Ready for review and for merge 😁 |
@th0r Is there anything open that I should do? |
This PR improves the upgrade of dependencies which are peer dependencies of other dependencies.
Scenario
Your app has a dependency to the package
ncu-test-peer
.ncu-test-peer
has a peer dependency to the packagencu-test-return-version
and requires version1.x
of this package. I.e.,ncu-test-peer
has the followingpackage.json
:Hence, your app has the following
package.json
:Let us assume, that
ncu-test-return-version
has published versions1.0.0
,1.1.0
and2.0.0
.Current Situation (without this PR)
If you run the current release of
npm-upgrade
(3.0.0) for your app, you get an upgrade suggestion forncu-test-return-version
version2.0.0
. If you follow this suggestion, your app is broken, sincencu-test-peer
's peer dependency requirement is not met (2.0.0
does not satisfy1.x
). If you deny this suggestion, you will stay at version1.0.0
, although there is a newer version1.1.0
that satisfies the requirement1.x
.Situation with this PR
This PR adds the new peer dependency check of
npm-check-updates
which was introduced in version11.4.0
(see raineorshine/npm-check-updates#869). Now,npm-upgrade
provides an upgrade suggestion forncu-test-return-version
version1.1.0
-- which is the expected result for this scenario.