[rush] preferredVersions doesn't work when subspace is enabled.
Summary
I am trying to enable subspace in my repo by flowing the doc. Then discovered a problem: After enabling the subspace feature, the preferredVersions in common-version will not take effect.
Details
when subspace is disable, rush will create a file named as pnpmfileSettings.json including preferredVersions.
https://github.com/microsoft/rushstack/blob/e64a1e51976626f95250205cbb9d21b5fc805769/libraries/rush-lib/src/logic/pnpm/IPnpmfile.ts#L13-L22
Then, pnpmfile.cjs read preferredVersions from pnpmfileSettings.json and it can set the preferred versions on the dependency map
https://github.com/microsoft/rushstack/blob/e64a1e51976626f95250205cbb9d21b5fc805769/libraries/rush-lib/src/logic/pnpm/PnpmfileShim.ts#L82-L103
However, when subspace is enable, pnpmfileSettings.json no longer contains preferredVersion information
https://github.com/microsoft/rushstack/blob/e64a1e51976626f95250205cbb9d21b5fc805769/libraries/rush-lib/src/logic/pnpm/IPnpmfile.ts#L34-L39
rush create a file named as global-pnpmfile.cjs and it doesn't seem to implement any logic related to preferredVersions.
https://github.com/microsoft/rushstack/blob/e64a1e51976626f95250205cbb9d21b5fc805769/libraries/rush-lib/src/logic/pnpm/SubspaceGlobalPnpmfileShim.ts#L34-L64
Subspace does not support preferredVersions, does it?
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
@microsoft/rush globally installed version? |
5.147.2 |
rushVersion from rush.json? |
5.147.2 |
useWorkspaces from rush.json? |
Yes |
| Operating system? | Mac |
| Would you consider contributing a PR? | Yes |
Node.js version (node -v)? |
v20.16.0 |
After debugging rush-lib, I found that pnpmfileSettings.json will be written twice.
First time: https://github.com/microsoft/rushstack/blob/438525caf08bcbdb75d33f6747cc34e050837d46/libraries/rush-lib/src/logic/pnpm/PnpmfileConfiguration.ts#L80-L83
Second time: https://github.com/microsoft/rushstack/blob/438525caf08bcbdb75d33f6747cc34e050837d46/libraries/rush-lib/src/logic/pnpm/SubspacePnpmfileConfiguration.ts#L50-L56
The second write operation will overwrite the first write content. And pnpmfileSettings.json is read once by global-pnpmfile.cjs and pnpmfile.cjs respectively.
Maybe we should distinguish the file names written twice, one is named pnpmfileSettings.json and the other named is globalPnpmfileSettings.json.
@fzxen Hi I have facing same problem, do you have found some workaround?