Repository navigation
perf(@angular/cli): verify the package manager binary on first use #34800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nigrosimone
wants to merge
4
commits into
angular:main
Choose a base branch
from
nigrosimone:cli-lazy-package-manager-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+262
−70
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
15f94d2
perf(@angular/cli): verify the package manager binary on first use
nigrosimone 2ca1d1f
fixup! perf(@angular/cli): verify the package manager binary on first…
nigrosimone eef594c
fixup! perf(@angular/cli): verify the package manager binary on first…
nigrosimone e211927
fixup! perf(@angular/cli): verify the package manager binary on first…
nigrosimone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { createPackageManager } from './factory'; | ||
| import { MockHost } from './testing/mock-host'; | ||
|
|
||
| describe('createPackageManager', () => { | ||
| let host: MockHost; | ||
| let runCommandSpy: jasmine.Spy; | ||
|
|
||
| beforeEach(() => { | ||
| host = new MockHost({ '/project': ['pnpm-lock.yaml'], '/empty': true }); | ||
| runCommandSpy = spyOn(host, 'runCommand').and.resolveTo({ stdout: '10.0.0', stderr: '' }); | ||
| }); | ||
|
|
||
| it('should not run the package manager binary', async () => { | ||
| const pm = await createPackageManager({ | ||
| cwd: '/project', | ||
| configuredPackageManager: ['npm'], | ||
| host, | ||
| }); | ||
|
|
||
| expect(pm.name).toBe('npm'); | ||
| expect(runCommandSpy).not.toHaveBeenCalled(); | ||
| expect(await pm.getVersion()).toBe('10.0.0'); | ||
| expect(runCommandSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
nigrosimone marked this conversation as resolved.
Resolved
|
||
|
|
||
| it('should explain that the default package manager is not installed on first use', async () => { | ||
| runCommandSpy.and.rejectWith(new Error('spawn npm ENOENT')); | ||
| const pm = await createPackageManager({ cwd: '/empty', host }); | ||
|
|
||
| expect(runCommandSpy).not.toHaveBeenCalled(); | ||
| await expectAsync(pm.install()).toBeRejectedWithError( | ||
| /'npm' was selected as the default package manager, but it is not installed/, | ||
| ); | ||
| }); | ||
|
|
||
| it('should explain that the configured package manager is not installed on first use', async () => { | ||
| runCommandSpy.and.rejectWith(new Error('spawn bun ENOENT')); | ||
| const pm = await createPackageManager({ | ||
| cwd: '/project', | ||
| configuredPackageManager: ['bun'], | ||
| host, | ||
| }); | ||
|
|
||
| expect(runCommandSpy).not.toHaveBeenCalled(); | ||
| await expectAsync(pm.install()).toBeRejectedWithError( | ||
| /The project is configured to use 'bun', but it is not installed/, | ||
| ); | ||
| }); | ||
|
|
||
| it('should explain that the discovered package manager is not installed on first use', async () => { | ||
| runCommandSpy.and.rejectWith(new Error('spawn pnpm ENOENT')); | ||
| const pm = await createPackageManager({ cwd: '/project', host }); | ||
|
|
||
| expect(pm.name).toBe('pnpm'); | ||
| await expectAsync(pm.install()).toBeRejectedWithError( | ||
| /The project is configured to use 'pnpm', but it is not installed/, | ||
| ); | ||
| }); | ||
|
|
||
| it('should not verify the package manager during a dry run', async () => { | ||
| const logger = { debug: () => {}, info: () => {} }; | ||
| const pm = await createPackageManager({ cwd: '/project', dryRun: true, logger, host }); | ||
|
|
||
| await pm.install(); | ||
| expect(runCommandSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not verify the package manager when the version is configured', async () => { | ||
| const pm = await createPackageManager({ | ||
| cwd: '/project', | ||
| configuredPackageManager: ['pnpm', '9.0.0'], | ||
| host, | ||
| }); | ||
|
|
||
| expect(await pm.getVersion()).toBe('9.0.0'); | ||
| await pm.install(); | ||
| expect(runCommandSpy).toHaveBeenCalledTimes(1); | ||
| expect(runCommandSpy).not.toHaveBeenCalledWith('pnpm', ['--version'], jasmine.anything()); | ||
| }); | ||
| }); | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.