-
Notifications
You must be signed in to change notification settings - Fork 694
[rush] Avoid unnecessary package manager install lock #5844
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
EscapeB
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
EscapeB:codex/package-manager-install-lock
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.
+164
−32
Open
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions
11
common/changes/@microsoft/rush/package-manager-install-lock_2026-06-23-13-27.json
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,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@microsoft/rush", | ||
| "comment": "Avoid acquiring the global package manager install lock when the requested package manager is already installed and no install lock file exists.", | ||
| "type": "patch" | ||
| } | ||
| ], | ||
| "packageName": "@microsoft/rush", | ||
| "email": "[email protected]" | ||
| } |
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 |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import { type IPackageJson, JsonFile } from '@rushstack/node-core-library'; | ||
| import * as path from 'node:path'; | ||
|
|
||
| import { FileSystem, type IPackageJson, JsonFile, LockFile } from '@rushstack/node-core-library'; | ||
| import { StringBufferTerminalProvider, Terminal } from '@rushstack/terminal'; | ||
| import { TestUtilities } from '@rushstack/heft-config-file'; | ||
|
|
||
| import { InstallHelpers } from '../installManager/InstallHelpers'; | ||
| import { RushConfiguration } from '../../api/RushConfiguration'; | ||
| import { LastInstallFlag } from '../../api/LastInstallFlag'; | ||
| import type { RushGlobalFolder } from '../../api/RushGlobalFolder'; | ||
| import { Utilities } from '../../utilities/Utilities'; | ||
|
|
||
| describe('InstallHelpers', () => { | ||
| describe('generateCommonPackageJson', () => { | ||
|
|
@@ -73,4 +78,71 @@ describe('InstallHelpers', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe(InstallHelpers.ensureLocalPackageManagerAsync.name, () => { | ||
| const tempFolderPath: string = `${__dirname}/temp/${InstallHelpers.name}`; | ||
|
|
||
| beforeEach(() => { | ||
| FileSystem.ensureEmptyFolder(tempFolderPath); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| FileSystem.deleteFolder(tempFolderPath); | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('does not acquire the global lock when the package manager is already installed', async () => { | ||
| const rushGlobalFolder: RushGlobalFolder = { | ||
| path: `${tempFolderPath}/rush-global`, | ||
| nodeSpecificPath: `${tempFolderPath}/rush-global/node-${process.version}` | ||
| } as RushGlobalFolder; | ||
| const packageManagerToolFolder: string = path.join(rushGlobalFolder.nodeSpecificPath, 'pnpm-10.27.0'); | ||
| await new LastInstallFlag(packageManagerToolFolder, { node: process.versions.node }).createAsync(); | ||
|
|
||
| const lockAcquireSpy: jest.SpyInstance = jest.spyOn(LockFile, 'acquireAsync'); | ||
| const rushConfiguration: RushConfiguration = { | ||
| commonRushConfigFolder: `${tempFolderPath}/common/config/rush`, | ||
| commonTempFolder: `${tempFolderPath}/common/temp`, | ||
| packageManager: 'pnpm', | ||
| packageManagerToolVersion: '10.27.0' | ||
| } as RushConfiguration; | ||
|
|
||
| await InstallHelpers.ensureLocalPackageManagerAsync(rushConfiguration, rushGlobalFolder, 1, true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the lockAcquireSpy returns false so that the test doesn't try to actually install the package if something goes wrong. |
||
|
|
||
| expect(lockAcquireSpy).not.toHaveBeenCalled(); | ||
| expect(FileSystem.exists(`${rushConfiguration.commonTempFolder}/pnpm-local`)).toEqual(true); | ||
| }); | ||
|
|
||
| it('acquires the global lock if an install lock file is present', async () => { | ||
| const rushGlobalFolder: RushGlobalFolder = { | ||
| path: `${tempFolderPath}/rush-global`, | ||
| nodeSpecificPath: `${tempFolderPath}/rush-global/node-${process.version}` | ||
| } as RushGlobalFolder; | ||
| const packageManagerToolFolder: string = path.join(rushGlobalFolder.nodeSpecificPath, 'pnpm-10.27.0'); | ||
| await new LastInstallFlag(packageManagerToolFolder, { node: process.versions.node }).createAsync(); | ||
| FileSystem.writeFile(`${rushGlobalFolder.nodeSpecificPath}/pnpm-10.27.0#123.lock`, ''); | ||
|
|
||
| const releaseAsync: jest.Mock = jest.fn(); | ||
| const lockAcquireSpy: jest.SpyInstance = jest.spyOn(LockFile, 'acquireAsync').mockResolvedValue({ | ||
| dirtyWhenAcquired: true, | ||
| release: releaseAsync | ||
| } as unknown as LockFile); | ||
| const installSpy: jest.SpyInstance = jest | ||
| .spyOn(Utilities, 'installPackageInDirectoryAsync') | ||
| .mockResolvedValue(); | ||
| const rushConfiguration: RushConfiguration = { | ||
| commonRushConfigFolder: `${tempFolderPath}/common/config/rush`, | ||
| commonTempFolder: `${tempFolderPath}/common/temp`, | ||
| packageManager: 'pnpm', | ||
| packageManagerToolVersion: '10.27.0' | ||
| } as RushConfiguration; | ||
|
|
||
| await InstallHelpers.ensureLocalPackageManagerAsync(rushConfiguration, rushGlobalFolder, 1, true); | ||
|
|
||
| expect(lockAcquireSpy).toHaveBeenCalledTimes(1); | ||
| expect(installSpy).toHaveBeenCalledTimes(1); | ||
| expect(releaseAsync).toHaveBeenCalledTimes(1); | ||
| expect(FileSystem.exists(`${rushConfiguration.commonTempFolder}/pnpm-local`)).toEqual(true); | ||
| }); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this version of pnpm selected, and when was it installed? I don't see anything mocking the file system checks to ensure that the version exists and/or writing files to do so.