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

install/dedupe: fix hoisting of packages with peerDeps #147

Merged
merged 8 commits into from Jan 29, 2019

Conversation

Projects
None yet
7 participants
@sokra
Copy link
Contributor

sokra commented Jan 24, 2019

fixes https://npm.community/t/packages-with-peerdependencies-are-incorrectly-hoisted/4794

This PR changes earliestInstallable to respect peerDependencies in the package. It hoists packages with peer deps no further than the package containing dependencies on the peer dependencies.

It also changes dedupe to start looking for earliest installable location in the current tree instead of the parent. This ensures that break conditions (which return tree in earliestInstallable) are correctly followed. To avoid finding itself, the package is marked as removed (this could be solved differently with an argument on earliestInstallable to ignore itself).

Show resolved Hide resolved lib/install/deps.js Outdated
Fix typo
Co-Authored-By: sokra <tobias.koppers@googlemail.com>
@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jan 24, 2019

Hi! Thanks for submitting this PR. Me and @iarna are gonna be doing a more thorough review of this tomorrow when we can pair on it. The initial response is that we're pretty sure we've tried this approach before and it broke a different set of people, but we're gonna look at it closely and see if this addresses the other breakage.

@sokra

This comment has been minimized.

Copy link
Contributor Author

sokra commented Jan 25, 2019

Thanks for considering it 😀

@zkat
Copy link
Member

zkat left a comment

Thanks so much for this! Go figure that it'd be such a small patch to resolve this issue. I guess our assumptions about needing that rewrite weren't quite there, though that's coming anyway ;)

One last thing we'd like to see before landing this is a test to verify the behavior, and it looks like you're most of the way there because you have a repro repo, especially one that uses file:. A good way to make a test for this is to clone the repo and call scripts/maketest on it, which will give you a nice test template to work off of.

Thanks again, and let me know if you have any questions! 🎉

var peerDeps = pkg.peerDependencies
if (peerDeps) {
if (Object.keys(peerDeps).some(function (name) {
return deps[name] || devDeps[name]

This comment has been minimized.

@zkat

zkat Jan 25, 2019

Member

This should have a check where we only check devDeps if tree.isTop (see the var devDeps ... section just above this one). We think this is otherwise fine and actually a pretty nice patch!

// child is marked as removed so it's ignored when finding a location
child.removed = true
var hoistTo = earliestInstallable(tree, tree, child.package, log)
child.removed = false

This comment has been minimized.

@zkat

zkat Jan 25, 2019

Member

I think we'd rather add an argument here than patch a child statefully like this. This otherwise makes sense.

@sokra

This comment has been minimized.

Copy link
Contributor Author

sokra commented Jan 28, 2019

@zkat ready for review again

@zkat

zkat approved these changes Jan 28, 2019

Copy link
Member

zkat left a comment

Looks wonderful! Thank you so much again! This was such a pain for people (and us). 😅

@aeschright aeschright changed the base branch from latest to release-next Jan 29, 2019

@aeschright aeschright merged commit 91314e7 into npm:release-next Jan 29, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@manniL manniL referenced this pull request Jan 30, 2019

Closed

Error in ./.nuxt/router.js #4839

@sokra sokra deleted the sokra:bugfix/hoist-peer-dependencies branch Jan 30, 2019

zkat added a commit that referenced this pull request Feb 4, 2019

@ascoders ascoders referenced this pull request Feb 8, 2019

Open

Webpack acorn bug #20

@paulmelnikow

This comment has been minimized.

Copy link

paulmelnikow commented Feb 8, 2019

Hi! Do you know which version of npm includes / will include this fix? Thanks!

@aeschright

This comment has been minimized.

Copy link
Contributor

aeschright commented Feb 8, 2019

This landed in the 6.8.0 pre-release, details here: https://npm.community/t/release-npm-6-8-0-next-2/5199

@ljharb

This comment has been minimized.

Copy link
Contributor

ljharb commented Feb 8, 2019

(However, see #152; it's likely to be reverted before the 6.8.0 release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment