Skip to content
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

[rush] Fix an issue that rush-pnpm patch-commit can not generate correct pnpm-config.json file in subspace case #4838

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue where `rush-pnpm patch-commit` did not work correctly when subspaces are enabled.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
20 changes: 16 additions & 4 deletions libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,29 @@ export class RushPnpmCommandLineParser {

switch (commandName) {
case 'patch-commit': {
// why need to throw error when pnpm-config.json not exists?
// 1. pnpm-config.json is required for `rush-pnpm patch-commit`. Rush writes the patched dependency to the pnpm-config.json when finishes.
// 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.
// It will produce unexpected behavior if we use the fallback.
if (this._subspace.getPnpmOptions() === undefined) {
this._terminal.writeErrorLine(
`You are using rush-pnpm patch-commit command, but Rush could not find the pnpm-config.json for ${this._subspace.subspaceName} subspace! ` +
`Make sure the pnpm-config.json exists in ${this._subspace.getSubspaceConfigFolder()}`
);
break;
}

// Example: "C:\MyRepo\common\temp\package.json"
const commonPackageJsonFilename: string = `${subspaceTempFolder}/${FileConstants.PackageJson}`;
const commonPackageJson: JsonObject = JsonFile.load(commonPackageJsonFilename);
const newGlobalPatchedDependencies: Record<string, string> | undefined =
commonPackageJson?.pnpm?.patchedDependencies;
const currentGlobalPatchedDependencies: Record<string, string> | undefined =
this._rushConfiguration.pnpmOptions.globalPatchedDependencies;
this._subspace.getPnpmOptions()?.globalPatchedDependencies;

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

// Update patchedDependencies to pnpm configuration file
this._rushConfiguration.pnpmOptions.updateGlobalPatchedDependencies(newGlobalPatchedDependencies);
this._subspace.getPnpmOptions()?.updateGlobalPatchedDependencies(newGlobalPatchedDependencies);
g-chao marked this conversation as resolved.
Show resolved Hide resolved

// 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` +
`"${commonTempPnpmPatchesFolder}" folder.\n` +
' Please commit this change to Git.'
);
}
Expand Down
Loading