ds300 / ds300/patch-package

`patch-package --partial` returns errors for incorrect patch

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

Description

First of all, thanks again for all of the hard work and maintenance that goes into `patch-package`. It's also an inspiration for other tools in the ecosystem, leading to the `pnpm patch` feature (although `patch-package` is still a bit ahead in terms of DX).

I noticed a new error message which I thought showed an exciting [new feature called `--partial`](https://github.com/ds300/patch-package#partially-applying-a-broken-patch-file):

```bash
⛔ ERROR

Failed to apply patch file next+13.4.18.patch.

If this patch file is no longer useful, delete it and run

patch-package

To partially apply the patch (if possible) and output a log of errors to fix, run

patch-package --partial

After which you should make any required changes inside node_modules/next, and finally run

patch-package next

to update the patch file.
```

So I decided to give it a try, and ran `yarn patch-package --partial`:

```bash
$ yarn patch-package --partial
patch-package 8.0.0
Applying patches...
Saving errors to ./patch-package-errors.log
```

...as expected, I received errors - I expected these errors to match the updated `next` package and the patch which was failing, so that I could manually edit the offending files in `node_modules/next`.

However, the error log file contained errors about a completely different patch - one that actually does not have troubles applying, if I revert the version of the offending `next` package.

`./patch-package-errors.log`

````
Cannot apply hunk 0 for file node_modules/check-links/lib/check-link.js
```diff
@@ -3,6 +3,7 @@
const got = require('got')
const isRelativeUrl = require('is-relative-url')
const parse = require('url').parse
+const userAgents = require('top-user-agents')

const protocolWhitelist = new Set([
'https:',
```

Cannot apply hunk 1 for file node_modules/check-links/lib/check-link.js
```diff
@@ -3,6 +3,7 @@
const got = require('got')
const isRelativeUrl = require('is-relative-url')
const parse = require('url').parse
+const userAgents = require('top-user-agents')

const protocolWhitelist = new Set([
'https:',
@@ -89,4 +90,4 @@ module.exports.isValidUrl = (url, opts) => {
}
}

-module.exports.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
+module.exports.userAgent = userAgents[Math.floor(Math.random() * (userAgents.length - 1))]
```
````

---

One potentially related thing is that I noticed that `patch-package` started [retaining old, obsolete patch files](https://github.com/ds300/patch-package/issues/480) when upgrading dependencies, and this was also the case for the `next` package - I had two identical patches from when I ran `yarn patch-package next` the last time I upgraded versions. However, this does not appear to be related to `--partial` mode, because:

1. Removing the extra patch file did not resolve the bug reported above
2. The extra patch file was not causing any other problems

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.