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 transient symlinks overriding direct ones v2 #5016

Conversation

rally25rs
Copy link
Contributor

Summary

This PR is a replacement for #5012 with a different fix.

fixes #4937

Added a sort to the top level bin links to ensure that direct dependencies are linked last. Since bin links are overwritten if they already exist, this will ensure that direct deps bin links will overwrite transitive ones.

Test plan

Run the test suite.

AndersAstrand and others added 3 commits November 28, 2017 17:26
If a transient dependency has a bin link with the same name as a direct
dependency, sometimes the top level bin link with lead to the transient
dependency rather than the direct one after install.

This test asserts that bin links from direct dependencies are installed.
The bin links are created in two passes during install. In the first
pass all direct dependencies for the installing module and transient
dependencies are created in their respective bin directories. In the
second pass top level bin links are created for all modules, including
transient dependencies.

This patch makes sure the second pass doesn't overwrite links from the
first pass which fixes a problem where links from transient dependencies
could overwrite links from direct dependencies.
@buildsize
Copy link

buildsize bot commented Nov 30, 2017

This change will increase the build size from 10.26 MB to 10.26 MB, an increase of 2.94 KB (0%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 886.52 KB 886.75 KB 238 bytes (0%)
yarn-[version].js 3.86 MB 3.86 MB 1.11 KB (0%)
yarn-legacy-[version].js 4.01 MB 4.01 MB 1.15 KB (0%)
yarn-v[version].tar.gz 891.28 KB 891.5 KB 228 bytes (0%)
yarn_[version]all.deb 668.08 KB 668.3 KB 234 bytes (0%)

Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

Thanks! What do you think about my suggestion?

return -1;
}
return 0;
});
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about splitting the array rather than doing a full sort? The algorithmic complexity would be better:

let transientBins = [], topLevelBins = [];
for (let ... of Array.from(linksToCreate.values())) {
    if (isDirectRequire) {
        topLevelBins.push();
    } else {
        transientBins.push();
    }
}

return [... transientBins, ... topLevelBins];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that. The code is easier to read.

@arcanis arcanis self-assigned this Dec 4, 2017
@AndersAstrand
Copy link

This bug is still present in master (fb6511c) and is blocking us from switching to yarn. Is there anything I can do to help move this PR forward?

@rally25rs
Copy link
Contributor Author

@arcanis think we can merge this?

@arcanis
Copy link
Member

arcanis commented Jan 15, 2018

Totally! This will be in the next release, hopefully today or tomorrow 👍

@arcanis arcanis merged commit 7ed01cf 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.

Sub dependency .bin symlinks can override top level dependency .bin symlink
3 participants