fix(@angular/cli): handle pnpm catalog: protocol in ng update#32938
fix(@angular/cli): handle pnpm catalog: protocol in ng update#32938maruthang wants to merge 1 commit intoangular:mainfrom
Conversation
When using pnpm's `catalog:` protocol for dependency versions in `package.json`, `ng update` would fail with "Package X was not found on the registry" because the `catalog:` specifier is not a valid npm package argument and cannot be resolved by the npm registry. This change adds two fixes: - `isPkgFromRegistry()` now recognizes `catalog:` as referencing registry packages instead of rejecting them - `_getAllDependencies()` resolves `catalog:` specifiers to `^<version>` using the installed version from node_modules, providing a valid semver range for downstream processing Fixes angular#30443
There was a problem hiding this comment.
Code Review
This pull request introduces support for the pnpm catalog: protocol in the Angular CLI update schematic. It resolves catalog: specifiers by attempting to read the actual version from the installed package's package.json in node_modules and ensures these specifiers are correctly identified as registry packages. A new test case has been added to verify this functionality. The review feedback suggests adding error handling when reading package.json files to prevent the update process from failing due to malformed JSON content.
| // Fall back to the installed version from node_modules | ||
| const pkgJsonPath = `/node_modules/${name}/package.json`; | ||
| if (tree.exists(pkgJsonPath)) { | ||
| const { version } = tree.readJson(pkgJsonPath) as PackageManifest; |
There was a problem hiding this comment.
The call to tree.readJson could potentially throw an error if the package.json file is malformed. While tree.exists is checked, it does not guarantee valid JSON content. Consider wrapping this in a try-catch block to gracefully handle potential parsing errors, ensuring the update process isn't halted by a single corrupted metadata file.
PR Checklist
PR Type
What is the current behavior?
When using pnpm's
catalog:protocol for dependency versions inpackage.json(e.g.,"@angular/core": "catalog:"),ng updatefails because:isPkgFromRegistry()usesnpm-package-argto parse the specifier, which doesn't recognizecatalog:— causing all catalog dependencies to be skipped with "Package X was not found on the registry"catalog:is not a valid semver range, so version resolution failsIssue Number: #30443
What is the new behavior?
Two targeted fixes:
isPkgFromRegistry()now recognizescatalog:specifiers as referencing registry packages (they always do — catalogs are just version aliases defined inpnpm-workspace.yaml)_getAllDependencies()resolvescatalog:specifiers to^<installed-version>by reading the actual installed version fromnode_modules/<pkg>/package.json. This provides a valid semver range for all downstream processing (version comparison, satisfying version lookup, etc.)Does this PR introduce a breaking change?