Repository navigation
[rush] Resolve PNPM catalog references in implicitly preferred versions - #6139
Draft
Bharat Middha (bmiddha) wants to merge 1 commit into
Draft
Bharat Middha (bmiddha) wants to merge 1 commit into
Bharat Middha (bmiddha) wants to merge 1 commit into
Conversation
This was referenced Oct 14, 2026
Bharat Middha (bmiddha)
force-pushed
the
bmiddha-catalog-aware-preferred-versions
branch
from
October 14, 2026 20:53
7d32ecd to
c0498ce
Compare
Bharat Middha (bmiddha)
added this pull request to stack #6134
October 14, 2026 21:29
DependencyAnalyzer resolves `catalog:` specifiers using the catalogs of each project's subspace, so implicitly preferred versions are real ranges instead of "catalog:". This fixes the semver.subset crash in rush install for cataloged packages listed in preferredVersions and restores pnpmfile shim range narrowing. Unresolvable catalog references are ignored. PnpmfileConfiguration skips semver.subset when either side is not a valid range. Also records catalogNamesByPackageName for rush add. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bharat Middha (bmiddha)
force-pushed
the
bmiddha-catalog-aware-preferred-versions
branch
from
October 15, 2026 01:43
c0498ce to
5e0ac4a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of the pnpm-catalog stack. It is based on #6138 (stack: #6138 → #6136 → #6133 → #6131).
When a project references a dependency through a PNPM catalog (
"typescript": "catalog:"), Rush used the literal stringcatalog:as that package's implicitly preferred version. As a result:rush installcrashed withTypeError: Invalid comparator: catalog:when the package is also listed inpreferredVersionsincommon-versions.json.PnpmfileConfigurationcallssemver.subset(explicit, implicit). In this repo that would hit typescript, eslint, and minimatch as soon as they move to catalogs."catalog:"was not a parseable range, so it was silently dropped.rush addandrush upgrade-interactivesawcatalog:as an "existing version".Rush now resolves catalog references to the versions in the catalog. It uses the catalogs of the subspace that the declaring project belongs to, which is the same thing
rush installwrites topnpm-workspace.yaml.Details
logic/pnpm/PnpmCatalogReference.tstryParsePnpmCatalogName(versionSpecifier)mapscatalog:andcatalog:defaulttodefault, andcatalog:<name>to<name>.tryGetPnpmCatalogVersion(catalogs, catalogName, packageName)does an own-property-safe lookup.tryResolvePnpmCatalogReference(packageName, versionSpecifier, catalogs)combines the two.rush checkandrush add) are meant to reuse these.DependencyAnalyzergetEffectivePnpmCatalogs(project.subspace, rushConfiguration), which is the layer-2 helper that honors thecommon/config/rush/pnpm-config.jsonfallback.workspace:and local-project checks.ERR_PNPM_CATALOG_ENTRY_NOT_FOUND_FOR_SPECfor these at install time, so Rush neither crashes nor invents a version here.catalogNamesByPackageName: Map<string, Set<string>>, which says which catalogs each package is referenced through. It is intended forrush addcatalog support.PnpmfileConfigurationsemver.subsetwhen both specifiers are valid SemVer ranges (semver.validRange).npm:aliases, git URLs,file:, or any leftover non-range spec can never crash install.catalog:specifiers, becauseparseRangerejects specs that contain:.PnpmShrinkwrapFile.isWorkspaceProjectModifiedAsynccomparescatalog:specifiers equal to the v9 lockfile importerspecifier: catalog:values. Tests are added for both directions.rush addandrush upgrade-interactivenow see resolved versions (e.g.~5.8.2) instead ofcatalog:. They still write literal versions; writingcatalog:references is left to therush addlayer of the stack.common/package.jsonnow gets real versions for cataloged packages.rush updatemay produce a slightly different lockfile.catalog:specifiers, and at most once per subspace per analysis.IDependencyAnalysisis internal, and there are no public API changes. Only a doc comment onRushConfiguration.getImplicitlyPreferredVersionschanged, and the API report is unchanged.How it was tested
New unit tests:
PnpmCatalogReference.test.ts: catalog name parsing, lookups, and resolution.DependencyAnalyzer.test.ts:catalog:andcatalog:defaultare equivalent.repoWithSubspacesCommonCatalogs, including the add-action path for a subspace with its own config and a subspace that falls back to common.PnpmfileConfiguration.test.ts:preferredVersionshastypescript: ~5.8.2and a project usestypescript: catalog:with the default catalogtypescript: ~5.8.2. Also covers a named catalog plusnpm:alias and git preferred versions.^5.0.0/^2.0.0/^9.0.0ranges to the catalog versions.catalog:specifiers untouched.PnpmShrinkwrapFile.test.ts: a v9 lockfile with catalog importer specifiers is not modified, and changing one specifier is detected as modified.logic/pnpm/test/repoWithCatalogs/and lockfilespnpm-lock-v9/catalogs-{not-,}modified.yaml.I confirmed the crash: with the original
PnpmfileConfiguration.tsand catalog resolution disabled, five of the new tests fail withTypeError: Invalid comparator: catalog:tools.Commands, run from the worktree root using the locally built dev Rush:
node <dev-rush>/apps/rush/lib-commonjs/start-dev.js install: passed.node <dev-rush>/apps/rush/lib-commonjs/start-dev.js build --to @microsoft/rush-lib: passed.cd libraries/rush-lib && node_modules/.bin/heft test --clean --test-path-pattern "DependencyAnalyzer|PnpmfileConfiguration|PnpmShrinkwrapFile|PnpmCatalogReference": passed, 56/56 tests in 4 suites.cd libraries/rush-lib && node_modules/.bin/heft test --clean --production:TarExecutable › kills tar when its signal aborts while it runs, which also fails on the base branch.A
rush changefile for@microsoft/rush(patch) is included.