Skip to content

[rush] Fix rush pnpm patch commit#3791

Open
chengcyber wants to merge 9 commits intomicrosoft:mainfrom
chengcyber:fix-rush-pnpm-patch-commit
Open

[rush] Fix rush pnpm patch commit#3791
chengcyber wants to merge 9 commits intomicrosoft:mainfrom
chengcyber:fix-rush-pnpm-patch-commit

Conversation

@chengcyber
Copy link
Contributor

@chengcyber chengcyber commented Nov 29, 2022

Summary

As @elliot-nelson pointed out at #3554 (comment), rush-pnpm patch-commit fails when running it from the root of monorepo, this PR makes rush-pnpm patch-commit works from the repo root folder.

Details

The reason rush-pnpm patch-commit fails is because pnpm patch-commit internally calls a logic which tries to read package.json file under procss.cwd(). While the actual top-level package.json in Rush.js monorepo is common/temp/package.json. So when ${cwd}/package.json doesn't exists and -C or --dir CLI parameter is not specified, Rush internally specifies --dir common/temp parameter for rush-pnpm patch-commit

How it was tested

Tested it with this repo: https://github.com/chengcyber/rush-pnpm-patch-demo

@chengcyber
Copy link
Contributor Author

Updates: Feedback at #3554 (comment), when re-running rush-pnpm patch-commit <path> for the same dependency, the patches folder are not synced to "common/pnpm-patches" folder. I updated the code to handle this case as well in this PR.

@octogonz octogonz requested a review from dmichon-msft as a code owner April 22, 2023 19:03
@iclanton iclanton force-pushed the fix-rush-pnpm-patch-commit branch from de65df1 to 2d636cd Compare June 26, 2024 01:07
@iclanton iclanton force-pushed the fix-rush-pnpm-patch-commit branch from 2d636cd to f80c1e6 Compare June 26, 2024 01:15
@iclanton iclanton enabled auto-merge June 26, 2024 01:16
// 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.includes('--dir') && !pnpmArgs.includes('-C')) {
if (!(await FileSystem.existsAsync(`${process.cwd()}/${FileConstants.PackageJson}`))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some repos that have a package.json in the root of a Rush repo, even though it's not considered by Rush/PNPM during install. Does this condition interfere with that scenario?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that I mentioned this in my last round of reviews a couple years ago... I'm not sure where that landed in the comments though. Do we not need to care about this?

// 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.includes('--dir') && !pnpmArgs.includes('-C')) {
if (!(await FileSystem.existsAsync(`${process.cwd()}/${FileConstants.PackageJson}`))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that I mentioned this in my last round of reviews a couple years ago... I'm not sure where that landed in the comments though. Do we not need to care about this?

@kenrick95
Copy link
Contributor

Today my colleague encountered the bug of not being able to update a patch previously generated by rush-pnpm patch (basically #3554 (comment) ) and my digging have led me to this PR...

@chengcyber @iclanton Would you help to update this PR so it can be merged?

Thanks a lot~

# Conflicts:
#	libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts
@octogonz
Copy link
Collaborator

octogonz commented Aug 6, 2025

@kenrick95 I've merged main into the PR branch. Now we just need to test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants