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(resolution) Eliminate "missing peerDep" warning when dep exists at root level. #5088

Merged
merged 4 commits into from
Jan 15, 2018

Conversation

rally25rs
Copy link
Contributor

fixes #4743

Summary

Previously, the logic in PackageResolver would return if a pattern was already resolved (ignore duplicate patterns). However, the check for peerDependencies needs to check all references.

This was causing an issue where if there was a peerDep on depZ, and depZ was resolved from a deeply nested transitive dep first, possibly > depA > depB > depC > depZ. And also depZ was directly included from package.json > depZ that second shallow PackageReference would not be tracked.

peerDep resolution would then only see the reference from > depA > depB > depC > depZ which may be too far down the tree to satisfy the dependency, thus a missing peerDep warning was issued.

Fortunately the underlying data structure seems to already support the concept of multiplePackageReferences for a dependency, so I changed the PackageResolver logic to always call PackageRequest .find() which already had its own duplication check, so now adds allPackageReferences to the data structure. This causes the peerDep resolution process to check all included references to the dependency.

Additionally, this exposed a problem with yarn why where if a package with the exact same pattern was added at the root package.json, and by transitive deps, yarn why would duplicate Specified in "dependencies" output, like:

info Reasons this module exists
   - "b#caniuse-api" depends on it
   - "b#caniuse-api#browserslist" depends on it
   - Specified in "dependencies"
   - Specified in "dependencies"

This was fixed by making a unique set of dependency patterns in the why command code instead of allowing duplicates.

Test plan

Added tests for both of the above bugs.

…pkg#4743

Added a failing unit test to reproduce issue yarnpkg#4743. It seems that if a peerDep exists deeper in the
dep tree than where it is included, yarn will output a earning, even if that peerDep is satisfied by
the same library included shallower in the tree, or at the root level.
…multiple levels.

A missing peerDep warning was being issued if the exact same pattern was a deep transitive dep and a
direct dep. This was due to only the first request for a pattern being added to the list of requests
that peerDep was checking. Now all references are tracked. Also fixed a logic error in Warn where a
dep would be reported multiple times.

yarnpkg#4743
@rally25rs rally25rs requested a review from BYK December 13, 2017 20:09
@buildsize
Copy link

buildsize bot commented Dec 13, 2017

This change will decrease the build size from 10.39 MB to 10.26 MB, a decrease of 132.82 KB (1%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 900.19 KB 887.41 KB -12.78 KB (1%)
yarn-[version].js 3.91 MB 3.86 MB -53.26 KB (1%)
yarn-legacy-[version].js 4.06 MB 4.01 MB -53.26 KB (1%)
yarn-v[version].tar.gz 905.32 KB 892.1 KB -13.22 KB (1%)
yarn_[version]all.deb 669.06 KB 668.76 KB -312 bytes (0%)

…t local vs ci. Now assert with

Remove snapshot test of "yarn why" due to different output local vs ci. Now assert with actual
object value comparison.
@arcanis
Copy link
Member

arcanis commented Jan 15, 2018

Awesome 👍

@arcanis arcanis merged commit 6adbd47 into yarnpkg:master Jan 15, 2018
agoldis added a commit to agoldis/yarn that referenced this pull request Feb 2, 2018
…readdir_files

* upstream/master: (34 commits)
  feat(upgrade, add): Separately log added/upgraded dependencies (yarnpkg#5227)
  feat(publish): Publish command uses publishConfig.access in package.json (yarnpkg#5290)
  fix(CLI): Use process exit instead of exitCode for node < 4 (yarnpkg#5291)
  feat(cli): error on missing workspace directory (yarnpkg#5206) (yarnpkg#5222)
  feat: better error when package is not found (yarnpkg#5213)
  Allow scoped package as alias source (yarnpkg#5229)
  fix(cli): Use correct directory for upgrade-interactive (yarnpkg#5272)
  nohoist baseline implementation (yarnpkg#4979)
  1.4.1
  1.4.0
  Show current version, when new version is not supplied on "yarn publish" (yarnpkg#4947)
  fix(install): use node-gyp from homebrew npm (yarnpkg#4994)
  Fix transient symlinks overriding direct ones v2 (yarnpkg#5016)
  fix(auth): Fixes authentication conditions and logic with registries (yarnpkg#5216)
  chore(package): move devDeps to appropriate place (yarnpkg#5166)
  fix(resolution) Eliminate "missing peerDep" warning when dep exists at root level. (yarnpkg#5088)
  fix(cli): improve guessing of package names that contain a dot (yarnpkg#5102) (yarnpkg#5135)
  feat(cli): include notice with license when generating disclaimer (yarnpkg#5072) (yarnpkg#5111)
  feat(cli): group by license in licenses list (yarnpkg#5074) (yarnpkg#5110)
  feat(cli): improve error message when file resolver can't find file (yarnpkg#5134) (yarnpkg#5145)
  ...
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.

Workspaces complain about missing hoisted peer dependencies
2 participants