refactor(@angular/cli): migrate ng add to new package manager abstraction#31543
Closed
clydin wants to merge 3 commits intoangular:mainfrom
Closed
refactor(@angular/cli): migrate ng add to new package manager abstraction#31543clydin wants to merge 3 commits intoangular:mainfrom
ng add to new package manager abstraction#31543clydin wants to merge 3 commits intoangular:mainfrom
Conversation
b43ff52 to
bee6f4b
Compare
…ifest The `getPackageManifest` method in the package manager abstraction was previously limited to fetching manifests from an NPM registry. This commit refactors the method to accept a generic `packageSpecifier` string. This allows the abstraction to leverage the underlying package manager's native ability to read manifests from various sources, including local tarballs (`.tgz`), local directories (`file:`), and git URLs, in addition to registry specifiers. This makes the `PackageManager` class more robust and capable of handling all package sources supported by commands like `ng add`.
…action This commit fully refactors the `ng add` command to use the new, centralized package manager abstraction. All package installation and metadata fetching logic now goes through the new API. This includes: - Using `createPackageManager` to detect the project's package manager. - Replacing `fetchPackageMetadata` with `packageManager.getRegistryMetadata`. - Replacing `fetchPackageManifest` with `packageManager.getPackageManifest`. - Replacing the `install` and `installTemp` methods with the `packageManager.add` and `packageManager.acquireTempPackage` methods. This change improves security by eliminating `shell: true` execution as well as enhances reliability with better error handling and caching.
The `ng add` command's version discovery mechanism could be slow when the `latest` tag of a package was incompatible, as it would fall back to exhaustively fetching the manifest for every available version. This commit introduces a performance optimization that uses a heuristic-based search. The new logic first identifies the latest release within each major version line and checks only those for compatibility. This dramatically reduces the number of network requests in the common case where peer dependency conflicts align with major versions. The exhaustive, version-by-version search is retained as a fallback to ensure correctness in edge cases.
bee6f4b to
a512fb3
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This commit fully refactors the
ng addcommand to use the new, centralized package manager abstraction.All package installation and metadata fetching logic now goes through the new API. This includes:
createPackageManagerto detect the project's package manager.fetchPackageMetadatawithpackageManager.getRegistryMetadata.fetchPackageManifestwithpackageManager.getPackageManifest.installandinstallTempmethods with thepackageManager.addandpackageManager.acquireTempPackagemethods.This change improves security by eliminating
shell: trueexecution as well as enhances reliability with better error handling and caching.