From 0f102b484f47d4ea36378f3288682e6b7cb45837 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 29 Nov 2022 20:59:52 +0800 Subject: [PATCH 1/8] fix(rush): rush-pnpm patch-commit can be run in repo root --- libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index 32a3c2d9131..9d9c6061706 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -331,6 +331,14 @@ export class RushPnpmCommandLineParser { ); throw new AlreadyReportedError(); } + // patch-commit internally calls installation under cwd instead of the common/temp folder + // It throws missing package.json error, so in this case, we need to set the dir to the common/temp folder here + if (pnpmArgs.indexOf('--dir') < 0 && pnpmArgs.indexOf('-C') < 0) { + if (!FileSystem.exists(`${process.cwd()}/package.json`)) { + pnpmArgs.push('--dir'); + pnpmArgs.push(this._rushConfiguration.commonTempFolder); + } + } break; } From 560bed003e91d70b0963fd163df500e8c85a3556 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Tue, 29 Nov 2022 21:05:57 +0800 Subject: [PATCH 2/8] chore: rush change --- .../fix-rush-pnpm-patch-commit_2022-11-29-13-05.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json new file mode 100644 index 00000000000..89bf4d6db14 --- /dev/null +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix rush-pnpm patch-commit, it can be run from the root of monorepo", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file From 13b69cacdeb063fa58b0fbb40ebf0f222dd27088 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 1 Dec 2022 11:26:40 +0800 Subject: [PATCH 3/8] fix(rush): rush-pnpm correctly sync patches when rerunning patch-commit for same dep --- .../src/cli/RushPnpmCommandLineParser.ts | 63 +++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index 9d9c6061706..6b72e455608 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -28,7 +28,6 @@ import { PurgeManager } from '../logic/PurgeManager'; import type { IBuiltInPluginConfiguration } from '../pluginFramework/PluginLoader/BuiltInPluginLoader'; import type { BaseInstallManager } from '../logic/base/BaseInstallManager'; import type { IInstallManagerOptions } from '../logic/base/BaseInstallManagerTypes'; -import { objectsAreDeepEqual } from '../utilities/objectUtilities'; import { Utilities } from '../utilities/Utilities'; import type { Subspace } from '../api/Subspace'; @@ -459,43 +458,41 @@ export class RushPnpmCommandLineParser { const commonPackageJson: JsonObject = JsonFile.load(commonPackageJsonFilename); const newGlobalPatchedDependencies: Record | undefined = commonPackageJson?.pnpm?.patchedDependencies; - const currentGlobalPatchedDependencies: Record | undefined = - this._rushConfiguration.pnpmOptions.globalPatchedDependencies; - - if (!objectsAreDeepEqual(currentGlobalPatchedDependencies, newGlobalPatchedDependencies)) { - const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`; - const rushPnpmPatchesFolder: string = `${this._rushConfiguration.commonFolder}/${RushConstants.pnpmPatchesCommonFolderName}`; - // Copy (or delete) common\temp\patches\ --> common\pnpm-patches\ - if (FileSystem.exists(commonTempPnpmPatchesFolder)) { - FileSystem.ensureEmptyFolder(rushPnpmPatchesFolder); - // eslint-disable-next-line no-console - console.log(`Copying ${commonTempPnpmPatchesFolder}`); + // const currentGlobalPatchedDependencies: Record | undefined = + // this._rushConfiguration.pnpmOptions.globalPatchedDependencies; + + const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`; + const rushPnpmPatchesFolder: string = `${this._rushConfiguration.commonFolder}/${RushConstants.pnpmPatchesCommonFolderName}`; + // Copy (or delete) common\temp\patches\ --> common\pnpm-patches\ + if (FileSystem.exists(commonTempPnpmPatchesFolder)) { + FileSystem.ensureEmptyFolder(rushPnpmPatchesFolder); + // eslint-disable-next-line no-console + console.log(`Copying ${commonTempPnpmPatchesFolder}`); + // eslint-disable-next-line no-console + console.log(` --> ${rushPnpmPatchesFolder}`); + FileSystem.copyFiles({ + sourcePath: commonTempPnpmPatchesFolder, + destinationPath: rushPnpmPatchesFolder + }); + } else { + if (FileSystem.exists(rushPnpmPatchesFolder)) { // eslint-disable-next-line no-console - console.log(` --> ${rushPnpmPatchesFolder}`); - FileSystem.copyFiles({ - sourcePath: commonTempPnpmPatchesFolder, - destinationPath: rushPnpmPatchesFolder - }); - } else { - if (FileSystem.exists(rushPnpmPatchesFolder)) { - // eslint-disable-next-line no-console - console.log(`Deleting ${rushPnpmPatchesFolder}`); - FileSystem.deleteFolder(rushPnpmPatchesFolder); - } + console.log(`Deleting ${rushPnpmPatchesFolder}`); + FileSystem.deleteFolder(rushPnpmPatchesFolder); } + } - // Update patchedDependencies to pnpm configuration file - this._rushConfiguration.pnpmOptions.updateGlobalPatchedDependencies(newGlobalPatchedDependencies); + // Update patchedDependencies to pnpm configuration file + this._rushConfiguration.pnpmOptions.updateGlobalPatchedDependencies(newGlobalPatchedDependencies); - // Rerun installation to update - await this._doRushUpdateAsync(); + // Rerun installation to update + await this._doRushUpdateAsync(); - this._terminal.writeWarningLine( - `Rush refreshed the ${RushConstants.pnpmConfigFilename}, shrinkwrap file and patch files under the ` + - `"${RushConstants.commonFolderName}/${RushConstants.pnpmPatchesCommonFolderName}" folder.\n` + - ' Please commit this change to Git.' - ); - } + this._terminal.writeWarningLine( + `Rush refreshed the ${RushConstants.pnpmConfigFilename}, shrinkwrap file and patch files under the ` + + `"${RushConstants.commonFolderName}/${RushConstants.pnpmPatchesCommonFolderName}" folder.\n` + + ' Please commit this change to Git.' + ); break; } } From b7d31d1f5225e3cff6d0377043df90266cb88e4e Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 1 Dec 2022 11:27:37 +0800 Subject: [PATCH 4/8] chore: rush change --- .../fix-rush-pnpm-patch-commit_2022-12-01-03-27.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json new file mode 100644 index 00000000000..1bfe3945131 --- /dev/null +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix rush-pnpm patch-commit, it can correctly sync patches when rerunning for a same dependency", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file From 5918ee39545d25b5f0c95e46b1b559e23b4b2428 Mon Sep 17 00:00:00 2001 From: Cheng Date: Mon, 5 Dec 2022 08:27:58 +0800 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Ian Clanton-Thuon --- .../rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json | 2 +- .../rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json index 89bf4d6db14..e4ead83d4e5 100644 --- a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-11-29-13-05.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@microsoft/rush", - "comment": "Fix rush-pnpm patch-commit, it can be run from the root of monorepo", + "comment": "Fix an issue with `rush-pnpm patch-commit`, where it would error if it was run from the root of the monorepo.", "type": "none" } ], diff --git a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json index 1bfe3945131..793397fcfd4 100644 --- a/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json +++ b/common/changes/@microsoft/rush/fix-rush-pnpm-patch-commit_2022-12-01-03-27.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@microsoft/rush", - "comment": "Fix rush-pnpm patch-commit, it can correctly sync patches when rerunning for a same dependency", + "comment": "Fix an issue with `rush-pnpm patch-commit` where it did not correctly sync patches on subsequent runs for the same dependency.", "type": "none" } ], From 5e8421a0caffe087d90ddcea4ae34990078e4d61 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Mon, 5 Dec 2022 08:30:04 +0800 Subject: [PATCH 6/8] chore: remove comments --- libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index 6b72e455608..4b2ca855042 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -458,8 +458,6 @@ export class RushPnpmCommandLineParser { const commonPackageJson: JsonObject = JsonFile.load(commonPackageJsonFilename); const newGlobalPatchedDependencies: Record | undefined = commonPackageJson?.pnpm?.patchedDependencies; - // const currentGlobalPatchedDependencies: Record | undefined = - // this._rushConfiguration.pnpmOptions.globalPatchedDependencies; const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`; const rushPnpmPatchesFolder: string = `${this._rushConfiguration.commonFolder}/${RushConstants.pnpmPatchesCommonFolderName}`; From f80c1e65b1970f9fc90d968016fb4ef936e6ad37 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Tue, 25 Jun 2024 18:15:28 -0700 Subject: [PATCH 7/8] Code cleanup --- .../src/cli/RushPnpmCommandLineParser.ts | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index 4b2ca855042..be53cc651ac 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as path from 'path'; import { AlreadyReportedError, EnvironmentMap, @@ -135,7 +134,7 @@ export class RushPnpmCommandLineParser { this._subspace = subspace; const workspaceFolder: string = subspace.getSubspaceTempFolder(); - const workspaceFilePath: string = path.join(workspaceFolder, 'pnpm-workspace.yaml'); + const workspaceFilePath: string = `${workspaceFolder}/pnpm-workspace.yaml`; if (!FileSystem.exists(workspaceFilePath)) { this._terminal.writeErrorLine('Error: The PNPM workspace file has not been generated:'); @@ -316,12 +315,10 @@ export class RushPnpmCommandLineParser { } break; } + case 'patch-commit': { - const pnpmOptionsJsonFilename: string = path.join( - this._rushConfiguration.commonRushConfigFolder, - RushConstants.pnpmConfigFilename - ); if (this._rushConfiguration.rushConfigurationJson.pnpmOptions) { + const pnpmOptionsJsonFilename: string = `${this._rushConfiguration.commonRushConfigFolder}/${RushConstants.pnpmConfigFilename}`; this._terminal.writeErrorLine( PrintUtilities.wrapWords( `Error: The "pnpm patch-commit" command is incompatible with specifying "pnpmOptions" in ${RushConstants.rushJsonFilename} file.` + @@ -330,10 +327,11 @@ export class RushPnpmCommandLineParser { ); throw new AlreadyReportedError(); } + // patch-commit internally calls installation under cwd instead of the common/temp folder // It throws missing package.json error, so in this case, we need to set the dir to the common/temp folder here - if (pnpmArgs.indexOf('--dir') < 0 && pnpmArgs.indexOf('-C') < 0) { - if (!FileSystem.exists(`${process.cwd()}/package.json`)) { + if (!pnpmArgs.includes('--dir') && !pnpmArgs.includes('-C')) { + if (!(await FileSystem.existsAsync(`${process.cwd()}/${FileConstants.PackageJson}`))) { pnpmArgs.push('--dir'); pnpmArgs.push(this._rushConfiguration.commonTempFolder); } @@ -455,28 +453,28 @@ export class RushPnpmCommandLineParser { case 'patch-commit': { // Example: "C:\MyRepo\common\temp\package.json" const commonPackageJsonFilename: string = `${subspaceTempFolder}/${FileConstants.PackageJson}`; - const commonPackageJson: JsonObject = JsonFile.load(commonPackageJsonFilename); + const commonPackageJson: JsonObject = await JsonFile.loadAsync(commonPackageJsonFilename); const newGlobalPatchedDependencies: Record | undefined = commonPackageJson?.pnpm?.patchedDependencies; const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`; const rushPnpmPatchesFolder: string = `${this._rushConfiguration.commonFolder}/${RushConstants.pnpmPatchesCommonFolderName}`; // Copy (or delete) common\temp\patches\ --> common\pnpm-patches\ - if (FileSystem.exists(commonTempPnpmPatchesFolder)) { - FileSystem.ensureEmptyFolder(rushPnpmPatchesFolder); + if (await FileSystem.existsAsync(commonTempPnpmPatchesFolder)) { + await FileSystem.ensureEmptyFolderAsync(rushPnpmPatchesFolder); // eslint-disable-next-line no-console console.log(`Copying ${commonTempPnpmPatchesFolder}`); // eslint-disable-next-line no-console console.log(` --> ${rushPnpmPatchesFolder}`); - FileSystem.copyFiles({ + await FileSystem.copyFilesAsync({ sourcePath: commonTempPnpmPatchesFolder, destinationPath: rushPnpmPatchesFolder }); } else { - if (FileSystem.exists(rushPnpmPatchesFolder)) { + if (await FileSystem.existsAsync(rushPnpmPatchesFolder)) { // eslint-disable-next-line no-console console.log(`Deleting ${rushPnpmPatchesFolder}`); - FileSystem.deleteFolder(rushPnpmPatchesFolder); + await FileSystem.deleteFolderAsync(rushPnpmPatchesFolder); } } From 9dcf4f453db6f46683d673111e1c6b15e5275d9b Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Tue, 5 Aug 2025 20:36:43 -0700 Subject: [PATCH 8/8] Fix build error --- libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts index fd24c4f1577..84a80c31199 100644 --- a/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts @@ -29,7 +29,6 @@ import type { BaseInstallManager } from '../logic/base/BaseInstallManager'; import type { IInstallManagerOptions } from '../logic/base/BaseInstallManagerTypes'; import { Utilities } from '../utilities/Utilities'; import type { Subspace } from '../api/Subspace'; -import type { PnpmOptionsConfiguration } from '../logic/pnpm/PnpmOptionsConfiguration'; import { EnvironmentVariableNames } from '../api/EnvironmentConfiguration'; import { initializeDotEnv } from '../logic/dotenv'; @@ -520,7 +519,7 @@ export class RushPnpmCommandLineParser { } // Update patchedDependencies to pnpm configuration file - pnpmOptions?.updateGlobalPatchedDependencies(newGlobalPatchedDependencies); + this._rushConfiguration.pnpmOptions.updateGlobalPatchedDependencies(newGlobalPatchedDependencies); // Rerun installation to update await this._doRushUpdateAsync();