@@ -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 }
0 commit comments