Skip to content

[rush] Add support for package aliases ("@npm:" in version specifier) - #1280

Merged
Ian Clanton-Thuon (iclanton) merged 18 commits into
microsoft:masterfrom
KevinGrandon:wip-add-npm-prefix-yarn-support
Sep 4, 2019
Merged

[rush] Add support for package aliases ("@npm:" in version specifier)#1280
Ian Clanton-Thuon (iclanton) merged 18 commits into
microsoft:masterfrom
KevinGrandon:wip-add-npm-prefix-yarn-support

Conversation

@KevinGrandon

@KevinGrandon Kevin Grandon (KevinGrandon) commented May 16, 2019

Copy link
Copy Markdown
Contributor

Hello, would love some guidance, or if you want to take this over and land it I'd be happy with that, but I'm very happy to continue contributing to this. This PR is currently working with my test case , but I have been unable to figure out how to write a properly functioning test case for this.

This is an attempt to add support for finding packages when their semver range starts with npm:, which is a useful mechanism for aliasing or forking packages. See #1279 for more details.

Refs #1279

@iclanton

Copy link
Copy Markdown
Member

Interesting. I've never seen this feature before. This is a feature of Yarn? Do you have a repro repo that we can test this against?

@KevinGrandon

Kevin Grandon (KevinGrandon) commented May 17, 2019

Copy link
Copy Markdown
Contributor Author

Interesting. I've never seen this feature before. This is a feature of Yarn? Do you have a repro repo that we can test this against?

Hello, thanks for chiming in. Yes, this is a feature of Yarn. I've created a test repository here: https://github.com/KevinGrandon/bug-rush-yarn-npm-resolution

You can clone it and run rush install to reproduce the issue. If you cd example-fusion-app and run yarn, you will see that everything works.

See Yarn aliasing for more info: https://yarnpkg.com/en/docs/cli/add#toc-yarn-add-alias

…m: prefix

Hello, would love some help here. No idea if this is working or not TBH and would love some help/guidance, or if you want to take this over and land it I'd be happy with that, but I'm very happy to continue contributing to this. I currently don't know if this works as I haven't been able to figure out how to link this locally, or get the tests working.

This is an attempt to add support for finding packages when their semver range starts with `npm:`, which is a useful mechanism for aliasing or forking packages. See microsoft#1279 for more details.

Refs microsoft#1279
@KevinGrandon
Kevin Grandon (KevinGrandon) force-pushed the wip-add-npm-prefix-yarn-support branch from 0aa473b to 4582508 Compare May 17, 2019 22:16
@KevinGrandon

Copy link
Copy Markdown
Contributor Author

Latest changes to npm/NpmLinkManager.ts get this working in my example repo. Tests still need help.

@KevinGrandon

Copy link
Copy Markdown
Contributor Author

Tried with the following ranges and this seems to work ok:

// Existant package, works
"fusion-core": "npm:fusion-core@1.0.0",
// Existant namespaced package, works
"fusion-core": "npm:@kevingorg/fusion-core",
// Existant namespaced package with range, works
"fusion-core": "npm:@kevingorg/fusion-core@0.0.1",
// Non-existant namespaced package with range, errors as expected
"fusion-core": "npm:@kevingorg/fusion-core@1000.0.0",

@octogonz Pete Gonzalez (octogonz) changed the title [WIP] - Attempt to locate packages by package alias when using the npm: prefix [rush] Add support for package aliases ("npm:" in version specifier) - WIP May 19, 2019
@octogonz

Copy link
Copy Markdown
Collaborator

In #1279 (comment) Zoltan said:

This is supported by pnpm, npm and jspm as well. (Actually, it was first introduced in jspm)

I wonder if we should implement this for PNPM as well (but maybe in a separate PR?).

@octogonz Pete Gonzalez (octogonz) changed the title [rush] Add support for package aliases ("npm:" in version specifier) - WIP [rush] Add support for package aliases ("@npm:" in version specifier) - WIP May 19, 2019
@octogonz

Copy link
Copy Markdown
Collaborator

This PR is awaiting the design discussion in #1279

I'm starting to believe it's an important feature, so if I get some time I may pitch in with the implementation.

@halfnibble

Copy link
Copy Markdown
Contributor

Kevin Grandon (@KevinGrandon) Do you have the information needed to proceed with this WIP, or is the design still unclear? (Or do you want someone else to take over this PR?) Thanks.

@octogonz

Copy link
Copy Markdown
Collaborator

Josh Wedekind (@halfnibble) I believe we arrived at a design.

Since all the package managers support this feature, it seems useful for Rush to support it as well. If Kevin doesn't have time, perhaps someone else could help out.

The main design changes that I had requested were:

  • Make the command line like rush add --package @acme/foo@~1.2.3 --alias @acme/my-foo; the NPM style is rush add --package @acme/my-foo@npm:@acme/foo@~1.2.3 which is too confusing

  • Change the parser as described in [rush] Add support for package aliases ("@npm:" in version specifier) #1279 (comment). The current PR uses versionRange.indexOf('npm:') === 0 which will not work correctly for certain variants. (The important token is @ not npm:.)

@KevinGrandon

Copy link
Copy Markdown
Contributor Author

Since all the package managers support this feature, it seems useful for Rush to support it as well. If Kevin doesn't have time, perhaps someone else could help out.

Since all the package managers support this feature, it seems useful for Rush to support it as well. If Kevin doesn't have time, perhaps someone else could help out.

Thanks for the updates here, I am short on time and not sure I am the right person to implement the parser. Please feel free to steal the code diff here or close this PR. Apologies I wasn't able to push this over the finish line.

…r instead of a string

(This is a pure refactoring change that should not alter any behavior.)
@octogonz

Pete Gonzalez (octogonz) commented Aug 11, 2019

Copy link
Copy Markdown
Collaborator

This PR is now code complete and seems to work with both PNPM and Yarn. The code review may be a bit tricky since I had to do a fair amount of refactoring.

Overall I believe this change should also improve some edge cases where rush update may have sometimes incorrectly analyzed the shrinkwrap file for PNPM.

Ian Clanton-Thuon (@iclanton)

@octogonz Pete Gonzalez (octogonz) changed the title [rush] Add support for package aliases ("@npm:" in version specifier) - WIP [rush] Add support for package aliases ("@npm:" in version specifier) Aug 11, 2019
@octogonz

Copy link
Copy Markdown
Collaborator

Ian Clanton-Thuon (@iclanton) let's try to get this merged.

…-prefix-yarn-support

# Conflicts:
#	common/config/rush/pnpm-lock.yaml
@iclanton
Ian Clanton-Thuon (iclanton) merged commit efacb55 into microsoft:master Sep 4, 2019
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.

5 participants