-
-
Notifications
You must be signed in to change notification settings - Fork 938
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
pnpm patch does not seem to work with workspaces #6048
Comments
No, the patch should be applied to all projects. |
Ok, that would definitely be appropriate in my opinion. However, when I committed the patch it did not update the lockfile for any projects and they are all still running the original unpatched version of the dependency. I can create a reproduction if that helps. |
I've created a repository at https://github.com/shawnmcknight/pnpm-patch-tests to show a minimal reproduction. In the repository there are two folders, each representing a pnpm root folder: In the In the Please let me know if I can do anything else or answer any questions. Thanks! |
I'm having the same issue with pnpm version 7.26.3 and node version 16.18.0.
When a package of the same version exists in multiple workspaces, the root package is being patched, but the same package in any workspace is not being patched. |
I've noticed a couple of interesting things that if I do I can get the patch commit to apply to the workspaces. Upon running
|
Along the same lines as the above, running So it seems that running operations which don't "trust" the integrity of the lockfile (i.e. |
I debugged through the workflow differences between From what I can tell, the primary difference between the two workflows is that I tried changing that line from: (cmd === 'install' || cmd === 'import' || cmd === "dedupe") to: (cmd === 'install' || cmd === 'import' || cmd === "dedupe" || cmd === "patch-commit") in the hopes that this would allow things to work properly. That change did make it so all packages were included when the patch-commit workflow called the installer. However, this introduced a different problem because the packages' manifests were read into variables at the time of filtering. Since I don't know enough about the pnpm codebase to determine how this workflow should be fixed. However, from what I can tell, the @zkochan Does this provide any additional insight into the problem? Does my proposed solution to supply project filters to |
Hey, From the repo you provided, i just run If I have misunderstood anything, please let me know, thanks a lot. |
@await-ovo Sorry, I had missed the fact that it's actually installing the dependency properly in that scenario, so maybe the setup of my reproduction isn't ideal. Seems like if Locally, when I created that reproduction, after I ran and the lockfile looks like this, with the workspace dependencies pointing to the original If I re-run However, if I run `pnpm install --fix-lockfile then things will change. The lockfile now looks like this, with the dependencies pointing to the patch hash: and the actual dependencies are updated as well. So I guess, unfortunately, it has to start from a blanker slate than the reproduction I provided. If you start with just workspaces a and b, no patches applied, and an up-to-date node_modules then the failure scenario occurs. I think even in the scenario you saw, where because Let me know if I can provide any more information. Thanks! |
@await-ovo I've set up a scenario that should be easier to see the problem.
The main difference between this flow and what you originally saw is that the |
@await-ovo One more note that's probably helpful. This compare of the |
I have not followed everything in this discussion, but I have encountered the same issue that as soon as I introduce a pnpm-workspace.yaml file, any previously working patches are no longer applied. |
@shawnmcknight I think I reproduced the problem and I will try to solve it |
I took a peek at your PR and it looks to be what I thought would be the solution to the problem. Basically making sure that the Thanks for taking care of this! |
@zkochan @await-ovo If I understand the linked issue #6120 correctly, it should have landed in v7.28.0? I have re-tested the simple example I linked above, and there patching still does not work with workspaces.
|
Everything has seemed to work properly for me in 7.28.0. I did a patch yesterday and it all went through as expected. |
But you have not tried my example? Maybe your use case's problem had a different root cause... If so, I could also open a new ticket, if that is preferable process-wise? |
@ChristianKaeser Hi, you should create a
Then move |
We should probably print a warning when there is a |
Sounds good to me ~ |
Thanks, that was the issue! I would second the wish for a warning by pnpm in this situation, especially as the docs do not mention the patching + workspace combination case last I checked. It really did not occur to me that a root package.json could be required next to the pnpm-workspace.yaml file. |
Are there any plans to make local patching of a package possible without the workaround of copying it to the root package.json? Are there any reasons this is neccessary? |
no, there are no plans. It is not a workaround. It is by design this way. Workspace projects don't have their own node_modules, all dependencies are at |
I am attempting to patch a transitive dependency which is in the dependency tree of multiple workspaces. In this example, the dependency is
extract-files@9.0.0
.From the workspace root, I run
pnpm patch extract-files@9.0.0
which gives me the temporary folder link as expected. I open the folder and make the necessary changes. After completing I runpnpm patch-commit <path>
which generates the patch file in the rootpatches
folder, adds apnpm.patchedDependencies
property to the rootpackage.json
, and adds apatchedDependencies
section at the top of thepnpm-lock.yaml
file. However, it does not alter any of the references to that dependency elsewhere in the lockfile, and as a result, the versions being used by the workspaces are unchanged.I revert all changes and then tried making my current working directory one of the workspace folders. I follow the same exact procedure described above and the end result is different. The
patches
folder is still added to the root, the rootpackage.json
still has thepnpm.patchedDependencies
property, and thepatchedDependencies
section is added to the top of thepnpm-lock.yaml
file. However, this time the lockfile has also been modified to patch the versions of that dependency relative to that workspace. My initial thought here is that the patch needs to be applied one workspace at a time.I then change my current working directory to another workspace. I repeat the process. This time the temporary folder already shows the patch (this seems expected). I try committing the patch but there is no change. The patch was not applied to that workspace.
Basically what I'm looking to have happen here is to either apply the patch to all workspaces or at least have a procedure where I can patch each workspace one a time. Ideally something like:
pnpm -r patch dependency@version
orpnpm --filter=<workspace> patch dependency@version
It's definitely possible that I'm doing something wrong here so if there is a procedure that should be taken to make this happen please let me know.
Possibly related issue: #5255
pnpm version:
7.26.3
Code to reproduce the issue:
Expected behavior:
Patches all versions of the dependency
Actual behavior:
Does not patch any versions of the dependency
Additional information:
node -v
prints: v16.16.0The text was updated successfully, but these errors were encountered: