ds300 / ds300/patch-package

Log the right patchDir when error happens

Open
#488 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.2k
Forks
325
PR merge metrics
No merged PRs in 30d

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used [patch-package](https://github.com/ds300/patch-package) to patch `patch-package@8.0.0` for the project I'm working on.

MY PROBLEM : When I specify `--patch-dir` as an argument, and then the patch application fails, the log outputs the wrong `patch-dir`. It outputs the default `patchDir` value (`patches/`) instead of the specified one. When this happens in CI, it causes long debugging sessions to figure out what happens, because we have multiple patches and we don't know which one errored.

Example command :
`patch-package --patch-dir patches/change-sections-order-in-security-privacy-settings`

Obtained output :
```
**ERROR** Failed to apply patch for package matrix-react-sdk at path

node_modules/matrix-react-sdk

This error was caused because matrix-react-sdk has changed since you
made the patch file for it. This introduced conflicts with your patch,
just like a merge conflict in Git when separate incompatible changes are
made to the same piece of code.

Maybe this means your patch file is no longer necessary, in which case
hooray! Just delete it!

Otherwise, you need to generate a new patch file.

To generate a new one, just repeat the steps you made to generate the first
one.

i.e. manually make the appropriate file changes, then run

patch-package matrix-react-sdk

Info:
Patch file: patches/matrix-react-sdk+3.71.1.patch
Patch was made for version: 3.71.1
Installed version: 3.78.0
```

Expected last lines of output to be instead :
```
Info:
Patch file: patches/change-sections-order-in-security-privacy-settings/matrix-react-sdk+3.71.1.patch
Patch was made for version: 3.71.1
Installed version: 3.78.0
```

Here is the diff that solved my problem:

```diff
diff --git a/node_modules/patch-package/dist/applyPatches.js b/node_modules/patch-package/dist/applyPatches.js
index 2d6344b..71720a6 100644
--- a/node_modules/patch-package/dist/applyPatches.js
+++ b/node_modules/patch-package/dist/applyPatches.js
@@ -213,6 +213,7 @@ function applyPatchesForPackage({ patches, appPath, patchDir, reverse, warnings,
patchFilename,
path,
pathSpecifier,
+ patchDir,
}));
// in case the package has multiple patches, we need to break out of this inner loop
// because we don't want to apply more patches on top of the broken state
@@ -375,7 +376,7 @@ ${chalk_1.default.red.bold("**ERROR**")} ${chalk_1.default.red(`Failed to apply

`;
}
-function createPatchApplicationFailureError({ packageName, actualVersion, originalVersion, patchFilename, path, pathSpecifier, }) {
+function createPatchApplicationFailureError({ packageName, actualVersion, originalVersion, patchFilename, path, pathSpecifier, patchDir, }) {
return `
${chalk_1.default.red.bold("**ERROR**")} ${chalk_1.default.red(`Failed to apply patch for package ${chalk_1.default.bold(packageName)} at path`)}

@@ -399,7 +400,7 @@ ${chalk_1.default.red.bold("**ERROR**")} ${chalk_1.default.red(`Failed to apply
patch-package ${pathSpecifier}

Info:
- Patch file: patches/${patchFilename}
+ Patch file: ${patchDir}${patchFilename}
Patch was made for version: ${chalk_1.default.green.bold(originalVersion)}
Installed version: ${chalk_1.default.red.bold(actualVersion)}
`;
```

This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.