Repository navigation
perf(@angular/cli): verify the package manager binary on first use - #34800
Open
nigrosimone wants to merge 2 commits into
Open
nigrosimone wants to merge 2 commits into
nigrosimone wants to merge 2 commits into
Conversation
Every command awaited the package manager version command before running, also commands that never use the package manager like serve and build. The binary is now verified the first time a command needs it.
nigrosimone
marked this pull request as ready for review
November 28, 2026 16:43
There was a problem hiding this comment.
Code Review
This pull request defers the verification of package manager binaries to their first use rather than performing it during initialization. This is achieved by introducing a missingBinaryError option in PackageManager and checking the binary lazily via a new checkBinary method. While this improves startup performance for commands that do not require the package manager, a review comment points out that the lazily resolved version string in getVersion bypasses the semver validation check, which could lead to downstream errors if the version is invalid.
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.
Every
ngcommand awaitscreatePackageManager(), which runsnpm --version(or the configured package manager) to check that the binary is installed. Also commands that never use the package manager, likeserveandbuild, wait for this child process before they start.Now the factory only prepares the error, and
PackageManagerverifies the binary the first time a command runs it. The output is kept as the version, sogetVersion()does not run it again. The error message is the same.On Windows the child process takes ~190 ms:
ng servelistens at 2.50 s instead of 2.76 s,ng configgoes from ~650 ms to ~455 ms.Tests: new
factory_spec.tschecks thatcreatePackageManagerdoes not run the binary (fails without the change), and two specs inpackage-manager_spec.tsfor the lazy check and its error.