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

[rush] Add support for Yarn resolutions when using Yarn #831

Closed
octogonz opened this issue Sep 20, 2018 · 4 comments · Fixed by #1360
Closed

[rush] Add support for Yarn resolutions when using Yarn #831

octogonz opened this issue Sep 20, 2018 · 4 comments · Fixed by #1360
Assignees
Labels
effort: easy Probably a quick fix. Want to contribute? :-) help wanted If you're looking to contribute, this issue is a good place to start!

Comments

@octogonz
Copy link
Collaborator

octogonz commented Sep 20, 2018

The Yarn package manager has a feature called "resolutions" that is similar in function to pnpmfile.js. It allows a package to specify fixup rules for indirect dependencies, for example:

{
  "name": "project",
  "version": "1.0.0",
  "dependencies": {
    "left-pad": "1.0.0",
    "c": "file:../c-1",
    "d2": "file:../d2-1"
  },
  "resolutions": {
    "d2/left-pad": "1.1.1",
    "c/**/left-pad": "1.1.2"
  }
}

The full docs are here:
https://yarnpkg.com/lang/en/docs/selective-version-resolutions/

We should figure out how to support this in a Rush repo when using the Yarn package manager.

@octogonz octogonz added help wanted If you're looking to contribute, this issue is a good place to start! needs design The next step is for someone to propose the details of an approach for solving the problem labels Sep 20, 2018
@octogonz octogonz changed the title [rush] Add support for Yarn resolutions [rush] Add support for Yarn resolutions when using Yarn Sep 20, 2018
@KevinGrandon
Copy link
Contributor

This one would be immensely useful for us. Any pointers on where to start looking in case a third-party contribution would be useful?

@RichiCoder1
Copy link

Just ran into this. Would love to know if there's a way to accomplish this or help.

@octogonz
Copy link
Collaborator Author

octogonz commented May 13, 2019

After thinking about it a little, I suspect that this feature may be fairly easy to implement.

Some background: rush install works by generating a fake package common/temp/package.json (called the "common package") that will get processed by a single yarn install invocation. (See this code.)

The common package contains references to tarballs (called the "temp packages"), one for each project project in your repo. (See this code.) If your real project is called my-lib, then the corresponding temp package name will be @rush-temp/my-lib, and the common package will contain something like this:

common/temp/package.json

{
  "name": "rush-common",
  "version": "0.0.0"
  "description": "Temporary file generated by the Rush tool",
  "private": true,
  "dependencies": {
    . . .
    "@rush-temp/my-lib": "file:./projects/my-lib.tgz",
    . . .
  }
}

If you extract the temp package tarball, it contains a single fake package.json file that describes the dependencies that Rush will install for the corresponding project. (You don't actually need to extract it, because its extracted contents are already present in common/temp/projects/my-lib/package.json. The reason for using a tarball is to make it easier for the package manager's cache to determine whether the fake package has changed or not.)

Thus, in theory in order to implement this feature, all we need to do is copy the "resolutions" field from the original project's package.json file (packageJson variable on this line) into the temp package's package.json (tempPackageJson variable in that same loop).

In practice, the question will be whether Yarn correctly respects it during installation. (All three package managers tend to be fairly buggy when handling file: version specifiers.)

If you can get it working, please create a PR! :-P

@octogonz octogonz added effort: easy Probably a quick fix. Want to contribute? :-) and removed needs design The next step is for someone to propose the details of an approach for solving the problem labels May 13, 2019
@halfnibble halfnibble self-assigned this Jun 21, 2019
@buffcode
Copy link

I would expect preferredVersions to be used for this? We wuold like to update some indirect dependencies due to security issues but rush will only add the prefererred version in addition to the older indirect dependency.

A global solution would be nice and though #1360 addresses this on package level, I think should be a first level option within rush itself for the whole mono-repo, in order to have consistent versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: easy Probably a quick fix. Want to contribute? :-) help wanted If you're looking to contribute, this issue is a good place to start!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants