rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush] Rush treats npm alias as link when subspace is enabled

Open fzxen opened this issue 9 months ago • 2 comments

Summary

Rush treats npm alias as link when subspace is enabled.

Repro steps

This repository can reproduce this issue:https://github.com/fzxen/rushstack_reproduce

My project has two subspaces, one is default subspace, and the other is named test-library.

There is a package existing under the default space, which uses npm alias to declare its dependencies.

{
  "devDependencies": {
      "@testing-library/dom": "workspace:*",
      "@testing-library/dom-npm": "npm:@testing-library/dom@^10.4.0"
    }
}

@testing-library/dom is a package in test-library subspace. I expect @testing-library/dom-npm can be downloaded from npm instead of directly creating a local symbol link.

Expected result:

pnpm will download @testing-library/dom from npm.

  ../../../projects/project1:
    devDependencies:
      '@testing-library/dom':
        specifier: link:../test-library-dom
        version: link:../test-library-dom
      '@testing-library/dom-npm':
        specifier: npm:@testing-library/dom@^10.4.0
        version: 10.4.0

Actual result:

pnpm directly links to a package named @testing-library/dom in another sub-space. I also tried adding @testing-library/dom-npm to decoupledLocalDependencies, but got the same result.

  ../../../projects/project1:
    devDependencies:
      '@testing-library/dom':
        specifier: link:../test-library-dom
        version: link:../test-library-dom
      '@testing-library/dom-npm':
        specifier: link:../test-library-dom
        version: link:../test-library-dom

Details

I located the code causing this problem. https://github.com/microsoft/rushstack/blob/66196fff404de7c7459ba3db5373d1f9b7e2a201/libraries/rush-lib/src/logic/pnpm/SubspaceGlobalPnpmfileShim.ts#L127-L148

The rush pnpmfile script will resolve npm aliases. As long as there is a dependency with the same name in the workspace, it will directly change to link:.

I think that the original specifier should be maintained and should not be changed to link: When this dependency is added to decoupledLocalDependencies.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? 5.153.1
rushVersion from rush.json? 5.153.1
useWorkspaces from rush.json? Yes
Operating system? Mac
Would you consider contributing a PR? Yes
Node.js version (node -v)? 20.16.0

fzxen avatar Apr 29 '25 06:04 fzxen

Does this repro when subspaces aren't enabled?

Would you be willing to put together a fix?

iclanton avatar Apr 30 '25 18:04 iclanton

When the subspace is not enabled, this issue does not exist. I will raise a PR later to try to fix this issue.

fzxen avatar Jun 09 '25 11:06 fzxen