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] Copy resolutions section from source package.json for yarn #1360

Merged
merged 12 commits into from
May 14, 2021

Conversation

MasterLambaster
Copy link
Contributor

Copy resolutions to the base package.json and to the project specific auto generated files.
Fixes #831.

@msftclas
Copy link

msftclas commented Jul 6, 2019

CLA assistant check
All CLA requirements met.

@iclanton iclanton changed the title Copy resolutions section from source package.json for yarn [rush] Copy resolutions section from source package.json for yarn Jul 12, 2019
apps/rush-lib/src/api/PackageJsonEditor.ts Outdated Show resolved Hide resolved
apps/rush-lib/src/api/PackageJsonEditor.ts Outdated Show resolved Hide resolved
apps/rush-lib/src/logic/InstallManager.ts Outdated Show resolved Hide resolved
libraries/node-core-library/src/IPackageJson.ts Outdated Show resolved Hide resolved
apps/rush-lib/src/logic/InstallManager.ts Outdated Show resolved Hide resolved
apps/rush-lib/src/logic/InstallManager.ts Outdated Show resolved Hide resolved
@iclanton iclanton added the PR: Waiting for author We reviewed your PR but had questions/suggestions. Let us know when you're ready for another look. label Jul 16, 2019
@MasterLambaster
Copy link
Contributor Author

MasterLambaster commented Jul 18, 2019

@iclanton The latest change to use index signature is causing issues on CI but not locally. Local run on node 8.16.0 passes successfully.

[12:06:45] Project @microsoft/rush-lib version:5.10.1
[12:06:45] Build tools version:3.9.26
[12:06:45] Node version:v8.16.0
[12:06:45] Total duration:30 s

With tslint version 5.12.1 and typescript version3.2.4.
Is there easy way to get typescript version on CI?
Or should I rollback those changes?

@iclanton
Copy link
Member

Sorry I didn't see this when you updated it. I'll take a look tomorrow when I'm at the office.

@iclanton
Copy link
Member

The typescript version is 3.4.

I fixed the issue you were seeing.

@rakeshpatnaik
Copy link

@MasterLambaster - Can you take a look and respond to the open comments?

@chriscasola
Copy link

@MasterLambaster @iclanton is there more work left here? I'd be happy to contribute, this change would be extremely useful to us.

@MasterLambaster
Copy link
Contributor Author

For whatever reasons there was one unresolved but yet redundant request open. It should be all good now.

@chriscasola
Copy link

@iclanton can this be reviewed again?

@chriscasola
Copy link

@iclanton any update?

@chriscasola
Copy link

@iclanton @octogonz Can I do anything to help get this merged?

@chriscasola
Copy link

@iclanton @octogonz any update? I can rebase this and open a new PR if it will be looked at.

@octogonz
Copy link
Collaborator

@apostolisms Could we get someone to review this? Overall the basic idea behind this PR seems sound to me. (Copy the resolutions from the project's package.json into the temp-project's package.json.)

If I remember right, this is the only way for Yarn to work around the @types versioning issue (yarnpkg/yarn#6695). So it's an important fix.

@iclanton
Copy link
Member

iclanton commented Jan 29, 2020

I just put together a repo to test this change and it doesn't seem to be working for me.

Here's my test repo:

This project has a "resolutions" field. and I checked in the yarn.lock file from a normal yarn install in that project's folder. Notice that z-schema is resolved to 5.18.3, when it would normally be 5.18.4.

However, no analogous resolution shows up in the common/config/rush/yarn.link file: z-schema is resolved to 5.18.4.

Does someone have a repo where this is working?

@MasterLambaster
Copy link
Contributor Author

MasterLambaster commented Jan 29, 2020

That's correct behavior.
Resolutions are applied only on the project level. I.e. that'll mandate version only within project1.
We've discussed behavior you're referencing to here( For whatever reasons conversation link does not work)
In order to support global resolution we need either to combine all resolutions from all packages and deal with conflicts, either do it some other way.

@iclanton
Copy link
Member

@MasterLambaster - but the resolution does seem to even be applying on the project level. I've specified a resolution in proj1, but it's still getting [email protected], not 3.18.3

@MasterLambaster
Copy link
Contributor Author

MasterLambaster commented Jan 29, 2020

@iclanton could you please describe how do you verify it?
yarn.lock file resolves to 3.18.3
common/temp/proj1/package.json contains

 "resolutions": {
    "**/z-schema": "3.18.3"
  }

That resolutions are never making into common/temp/package.json because of the reasons I've described earlier.

It's been quite a while since initial PR and I'm struggling to recall why even having that within package were making sense 😂

@iclanton
Copy link
Member

The yarn.lock file you linked to is the one I generated by just running yarn install in /proj1. The yarn.lock file produced by this PR is here. Notice that z-schema is resolved to version 3.18.4 in that yarn.lock file.

@MasterLambaster
Copy link
Contributor Author

MasterLambaster commented Jan 30, 2020

Notice that z-schema is resolved to version 3.18.4 in that yarn.lock file.

That's absolutely correct. In order to support that I need collect all resolutions from project package.json files and put into common/temp/package.json file. That imply some conflict resolution or at least warning system for that purposes.

Do you want me to restore this functionality?
Is it enough to start with the warnings if there are conflicts with different resolution instructions or just do general case to begin with?

@iclanton
Copy link
Member

Do you want me to restore this functionality?

That behavior will probably produce undesired results.

Perhaps I'm confused here. Can you provide a Rush repo where the a project's "resolutions" field changes something when running rush update with the version of Rush in this PR?

@MasterLambaster
Copy link
Contributor Author

So, I've took a deeper look and tired to recall all circumstances.
The current PR have just some if none utility.
This code change only copying resolutions into projects package.json files that are placed into the project tarball. The aggregated package.json(common/temp/package.json) does not use any of those files and is generated by combining all dependencies from all packages.
I.e this PR has no effect on common/config/rush/yarn.lock which is desired outcome.

Having that said I can think of following possible solutions:

  • Add new rush/yarn specific field that'll control global rush resolutions
    CONS: Specific field that might not meet package.json schema. Does not save from conflicts. Details are hidden within package and might be hard to find
  • Automatically combine all resolutions and put those into global package.json
    CONS: Quite complex conflict resolution system if any, otherwise can lead to unexpected errors
  • Add resolutions section to yarnOptions section in rush.json
    CONS: Can duplicate and force-overwrite resolutions inside packages that can have some minor side effects as well.

@iclanton do you see any other places that we can use to configure resolutions explicitly?

@liyikun
Copy link

liyikun commented May 11, 2021

When will it be merged? @octogonz

@octogonz
Copy link
Collaborator

@liyikun Lemme figure out what's up. For future reference, if a PR is getting overlooked, please let us know in the #contributor-helpline chat room.


// NOTE: The "resolutions" field is a yarn specific feature that controls package
// resolution override within yarn.
private readonly _resolutions: { [name: string]: string };
Copy link
Member

Choose a reason for hiding this comment

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

Should be a Map<string, string> to match what others are doing

Copy link
Member

Choose a reason for hiding this comment

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

Or I guess, Map<string, PackageJsonDependency> if this matches a version specifier format?

Copy link
Collaborator

@octogonz octogonz May 14, 2021

Choose a reason for hiding this comment

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

@D4N14L I agree that we should make this a complete PackageJsonEditor API rather than just a way to pass the options along. A config-file-with-data is generally preferable to a script-with-code, so for everyday problems, resolutions is actually a better design than pnpmfile.js. (Although pnpmfile.js is still a good feature for advanced problems.)

I thought about adapting the PNPM shim to apply resolutions for PNPM. But it turns out that PNPM later implemented this same feature, but they call it overrides. (pnpm/pnpm#2946) Docs are here. In the issue pnpm/pnpm#1221 they point out that NPM reinvented the same feature in their "overrides" RFC but with some differences in its design. So all 3 package managers implement this feature in slightly different ways, all using different package.json fields.

We should support PNPM overrides and recommend it over pnpmfile.js. But that's not part of this PR. (I opened #2698 to track it)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed

/**
* This field is a Yarn-specific feature that allows overriding of package resolution.
*/
public get resolutions(): { [name: string]: string } {
Copy link
Member

Choose a reason for hiding this comment

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

ReadonlyArray<PackageJsonDependency> if that type can be supported, otherwise return the a readonly object

Copy link
Collaborator

Choose a reason for hiding this comment

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

The structure is Record<string, string> basically the same as "dependencies" and "devDependenices", with the only difference being that the name can include glob-like patterns. I think we can model it the same way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed

apps/rush-lib/src/logic/InstallManager.ts Outdated Show resolved Hide resolved
octogonz added 2 commits May 13, 2021 18:54
…tions

# Conflicts:
#	apps/rush-lib/src/api/PackageJsonEditor.ts
#	apps/rush-lib/src/logic/InstallManager.ts
#	common/reviews/api/rush-lib.api.md
@octogonz
Copy link
Collaborator

@D4N14L I have addressed your feedback

Copy link
Member

@D4N14L D4N14L left a comment

Choose a reason for hiding this comment

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

Approving to avoid blocking but comment needs to be addressed before merge

@octogonz octogonz removed the PR: Waiting for author We reviewed your PR but had questions/suggestions. Let us know when you're ready for another look. label May 14, 2021
@octogonz
Copy link
Collaborator

I tested this in a Rush repo with Yarn and confirmed that "resolutions" is copied to the common/temp/projects/*/package.json files.

I also tested the error message for PNPM repos, but found that it is only printed with useWorkspaces=fase. Lemme see if we can fix that.

…son field is used without Yarn. This check only worked with useWorkspaces=false, and there may be valid use cases for packages that target multiple package managers
@octogonz octogonz merged commit b0b9804 into microsoft:master May 14, 2021
@octogonz
Copy link
Collaborator

Released with Rush 5.47.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[rush] Add support for Yarn resolutions when using Yarn
10 participants