Skip to content

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

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

Open
fzxen opened this issue Apr 29, 2025 · 1 comment
Open

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

fzxen opened this issue Apr 29, 2025 · 1 comment

Comments

@fzxen
Copy link
Contributor

fzxen commented Apr 29, 2025

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.

} else if (currentVersion.startsWith('npm:')) {
// Case 3. "<alias>": "npm:<package_name>@<dep_version>"
const packageSpec: string = currentVersion.slice('npm:'.length);
const nameEndsAt: number =
packageSpec[0] === '@' ? packageSpec.slice(1).indexOf('@') + 1 : packageSpec.indexOf('@');
const aliasedPackageName: string = nameEndsAt > 0 ? packageSpec.slice(0, nameEndsAt) : packageSpec;
// const depVersion: string = nameEndsAt > 0 ? packageSpec.slice(nameEndsAt + 1) : '';
const aliasedWorkspaceProjectInfo: IWorkspaceProjectInfo | undefined =
settings.workspaceProjects[aliasedPackageName];
if (aliasedWorkspaceProjectInfo) {
const relativePath: string = path.normalize(
path.relative(
workspaceProject.projectRelativeFolder,
aliasedWorkspaceProjectInfo.projectRelativeFolder
)
);
const newVersion: string = 'link:' + relativePath;
dependencies[dependencyName] = newVersion;
}
}
}
}

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
@iclanton
Copy link
Member

Does this repro when subspaces aren't enabled?

Would you be willing to put together a fix?

@iclanton iclanton moved this from Needs triage to Low priority in Bug Triage Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Low priority
Development

No branches or pull requests

2 participants