fix(@angular/cli): handle npm-aliased and unfetchable packages in ng update#32943
Open
maruthang wants to merge 1 commit intoangular:mainfrom
Open
fix(@angular/cli): handle npm-aliased and unfetchable packages in ng update#32943maruthang wants to merge 1 commit intoangular:mainfrom
maruthang wants to merge 1 commit intoangular:mainfrom
Conversation
…update When `ng update` encounters packages using npm aliases (`npm:` protocol) or packages that cannot be fetched from the registry (private registries, JSR, AWS CodeArtifact), the entire update process would fail with a 404 error because `Promise.all()` rejects on any single fetch failure. The fix: 1. Filters out `npm:` aliased packages early in `isPkgFromRegistry()` since the dependency key name differs from the actual package name 2. Catches individual fetch errors in the parallel metadata fetch, returning a partial result that the existing reduce logic already handles gracefully Closes angular#28834
There was a problem hiding this comment.
Code Review
This pull request enhances the Angular CLI update schematic to better handle npm aliases and metadata fetch failures by returning partial results on error. The review feedback recommends a more robust implementation for alias detection using the npa.resolve result type rather than a simple string prefix check.
Comment on lines
+807
to
816
| // npm: aliases (e.g., "npm:real-package@^1.0.0") resolve as registry packages | ||
| // but the dependency key name differs from the actual package name, so registry | ||
| // lookups using the alias name would fail with a 404. | ||
| if (specifier.startsWith('npm:')) { | ||
| return false; | ||
| } | ||
|
|
||
| const result = npa.resolve(name, specifier); | ||
|
|
||
| return !!result.registry; |
There was a problem hiding this comment.
Using the result of npa.resolve to detect aliases is more robust than a manual string prefix check. This approach handles edge cases like case-insensitivity (e.g., NPM:) and potential whitespace consistently with how the rest of the package resolution logic operates.
Suggested change
| // npm: aliases (e.g., "npm:real-package@^1.0.0") resolve as registry packages | |
| // but the dependency key name differs from the actual package name, so registry | |
| // lookups using the alias name would fail with a 404. | |
| if (specifier.startsWith('npm:')) { | |
| return false; | |
| } | |
| const result = npa.resolve(name, specifier); | |
| return !!result.registry; | |
| // npm: aliases (e.g., "npm:real-package@^1.0.0") resolve as registry packages | |
| // but the dependency key name differs from the actual package name, so registry | |
| // lookups using the alias name would fail with a 404. | |
| const result = npa.resolve(name, specifier); | |
| return !!result.registry && result.type !== 'alias'; |
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
ng updatewould fail with a 404 error whenpackage.jsoncontains dependencies using npm aliases ("my-pkg": "npm:real-package@^1.0.0") or packages from private/non-npmjs registriesPromise.all()for fetching package metadata would reject entirely when any single package couldn't be fetched, even if it wasn't part of the updatenpm:aliased packages early (since the alias name differs from the real package name) and catches individual fetch errors gracefully, allowing the existing reduce logic to handle missing packagesCloses #28834
Test plan
ng updateon a project withnpm:aliased dependencies — should complete without errorng updateon a project with private registry packages — should skip unfetchable packages gracefullyng update @angular/coreon a normal project — should work as before