Skip to content

Commit 6c6ed43

Browse files
g-chaooctogonz
andauthored
[rush] Fix an issue that rush-pnpm patch-commit can not generate correct pnpm-config.json file in subspace case (#4838)
* fix: rush-pnpm patch-commit * chore: rush change * chore: address PR comments * fix: handle case where the pnpm-config.json not exists * chore: add comments * Improve error message wording * Prepare to publish a PATCH release --------- Co-authored-by: Pete Gonzalez <[email protected]>
1 parent f0c756b commit 6c6ed43

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Fix an issue where `rush-pnpm patch-commit` did not work correctly when subspaces are enabled.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,29 @@ export class RushPnpmCommandLineParser {
446446

447447
switch (commandName) {
448448
case 'patch-commit': {
449+
// why need to throw error when pnpm-config.json not exists?
450+
// 1. pnpm-config.json is required for `rush-pnpm patch-commit`. Rush writes the patched dependency to the pnpm-config.json when finishes.
451+
// 2. we can not fallback to use Monorepo config folder (common/config/rush) due to that this command is intended to apply to input subspace only.
452+
// It will produce unexpected behavior if we use the fallback.
453+
if (this._subspace.getPnpmOptions() === undefined) {
454+
this._terminal.writeErrorLine(
455+
`The "rush-pnpm patch-commit" command cannot proceed without a pnpm-config.json file.` +
456+
` Create one in this folder: ${this._subspace.getSubspaceConfigFolder()}`
457+
);
458+
break;
459+
}
460+
449461
// Example: "C:\MyRepo\common\temp\package.json"
450462
const commonPackageJsonFilename: string = `${subspaceTempFolder}/${FileConstants.PackageJson}`;
451463
const commonPackageJson: JsonObject = JsonFile.load(commonPackageJsonFilename);
452464
const newGlobalPatchedDependencies: Record<string, string> | undefined =
453465
commonPackageJson?.pnpm?.patchedDependencies;
454466
const currentGlobalPatchedDependencies: Record<string, string> | undefined =
455-
this._rushConfiguration.pnpmOptions.globalPatchedDependencies;
467+
this._subspace.getPnpmOptions()?.globalPatchedDependencies;
456468

457469
if (!objectsAreDeepEqual(currentGlobalPatchedDependencies, newGlobalPatchedDependencies)) {
458470
const commonTempPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesFolderName}`;
459-
const rushPnpmPatchesFolder: string = `${this._rushConfiguration.commonFolder}/${RushConstants.pnpmPatchesCommonFolderName}`;
471+
const rushPnpmPatchesFolder: string = `${subspaceTempFolder}/${RushConstants.pnpmPatchesCommonFolderName}`;
460472
// Copy (or delete) common\temp\patches\ --> common\pnpm-patches\
461473
if (FileSystem.exists(commonTempPnpmPatchesFolder)) {
462474
FileSystem.ensureEmptyFolder(rushPnpmPatchesFolder);
@@ -477,14 +489,14 @@ export class RushPnpmCommandLineParser {
477489
}
478490

479491
// Update patchedDependencies to pnpm configuration file
480-
this._rushConfiguration.pnpmOptions.updateGlobalPatchedDependencies(newGlobalPatchedDependencies);
492+
this._subspace.getPnpmOptions()?.updateGlobalPatchedDependencies(newGlobalPatchedDependencies);
481493

482494
// Rerun installation to update
483495
await this._doRushUpdateAsync();
484496

485497
this._terminal.writeWarningLine(
486498
`Rush refreshed the ${RushConstants.pnpmConfigFilename}, shrinkwrap file and patch files under the ` +
487-
`"${RushConstants.commonFolderName}/${RushConstants.pnpmPatchesCommonFolderName}" folder.\n` +
499+
`"${commonTempPnpmPatchesFolder}" folder.\n` +
488500
' Please commit this change to Git.'
489501
);
490502
}

libraries/rush-lib/src/logic/RepoStateFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class RepoStateFile {
213213
// means users may turn off the injected installation
214214
// so we will need to remove unused fields in repo-state.json as well
215215
this._packageJsonInjectedDependenciesHash = undefined;
216-
this._modified = true
216+
this._modified = true;
217217
}
218218
}
219219

0 commit comments

Comments
 (0)