-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
bugSomething isn't workingSomething isn't workingupholdedReal issues without formal reproductionReal issues without formal reproduction
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
Running yarn patch
against a package that has already been patched has unexpected behavior, sometimes creating a "patch of a patch". This is undesired, as I would like Yarn to merge my patch changes together, if applicable.
To reproduce
I'll use lodash
for the examples but I believe this applies to any package.
Issue (1):
- Start a new Yarn project and add a package:
yarn set version berry && yarn add lodash
- Run
yarn patch lodash
. Make a change in the extracted directory, then runyarn patch-commit -s <dir> && yarn
. - Run
yarn patch lodash
again. At this point, I would expect to get the error message "Multiple candidate packages found" asking whether I'd like to patch the unpatched version or patched version oflodash
, but no such message appears. The unpatched source oflodash
is extracted.
Issue (2):
- Start a new Yarn project:
yarn set version berry
. - Create a workspace and add a package to one of them:
mkdir my-workspace && touch my-workspace/package.json
- Add
"workspaces": ["my-workspace"]
to the rootpackage.json
- Add the following to the
my-workspace/package.json
:
{
"name": "my-workspace",
"dependencies": {
"lodash": "4.17.21
},
}
- Run
yarn patch lodash
, make a change in the extracted directory, then runyarn patch-commit -s <dir> && yarn
- Run
yarn patch lodash
again, note that unlike in (1), the "Multiple candidate packages found" error message is displayed. - Run
yarn patch lodash@patch:lodash@npm...
, make a change in the extracted directory, then runyarn patch-commit -s <dir>
- Note that there are now two patches in
.yarn/patches
, and thepackage.json
resolutions field implies a "patch of a patch"
"resolutions": {
"lodash@4.17.21": "patch:lodash@npm%3A4.17.21#.yarn/patches/lodash-npm-4.17.21-6382451519::version=4.17.21&hash=b68992&locator=root-workspace-0b6124%40workspace%3A.#.yarn/patches/lodash-patch-af7531f881
}
- Running
yarn
at this point prints an error: "Patch locators must explicitly define their source".
Environment
System:
OS: Linux 5.15 Arch Linux
CPU: (16) x64 AMD Ryzen 7 PRO 5850U with Radeon Graphics
Binaries:
Node: 17.1.0 - /tmp/xfs-57237fea/node
Yarn: 3.1.1 - /tmp/xfs-57237fea/yarn
Additional context
It is possible to work around (2) by selecting the unpatched version of the package, remaking all previous patch changes, then adding in any new changes. However, I would expect that Yarn would handle this case automatically.
IAmMarcellus, dlech, finnmerlett, matt-m-mclaughlin, hypnodron and 8 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingupholdedReal issues without formal reproductionReal issues without formal reproduction