rushstack
rushstack copied to clipboard
[rush] Fix rush pnpm patch commit
Summary
As @elliot-nelson pointed out at https://github.com/microsoft/rushstack/pull/3554#issuecomment-1325058523, 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
Updates: Feedback at https://github.com/microsoft/rushstack/pull/3554#issuecomment-1331477785, 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.