Skip to content

Commit cced41a

Browse files
committed
add --partial option
1 parent 1981d42 commit cced41a

17 files changed

+293
-37
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,17 @@ Then, update your hash key to include a checksum of that file:
107107
```yaml
108108
- restore_cache:
109109
key:
110-
app-node_modules-v1-{{ checksum "yarn.lock" }}-{{ checksum "patches.hash" }}
110+
app-node_modules-v1-{{ checksum "yarn.lock" }}-{{ checksum "patches.hash"
111+
}}
111112
```
112113
113114
As well as the save_cache
114115
115116
```yaml
116117
- save_cache:
117118
key:
118-
app-node_modules-v1-{{ checksum "yarn.lock" }}-{{ checksum "patches.hash" }}
119+
app-node_modules-v1-{{ checksum "yarn.lock" }}-{{ checksum "patches.hash"
120+
}}
119121
paths:
120122
- ./node_modules
121123
```
@@ -342,6 +344,21 @@ If you deleted one of the patch files other than the last one, you don't need to
342344
update the sequence numbers in the successive patch file names, but you might
343345
want to do so to keep things tidy.
344346

347+
#### Partially applying a broken patch file
348+
349+
Normally patch application is atomic per patch file. i.e. if a patch file
350+
contains an error anywhere then none of the changes in the patch file will be
351+
applied and saved to disk.
352+
353+
This can be problematic if you have a patch with many changes and you want to
354+
keep some of them and update others.
355+
356+
In this case you can use the `--partial` option. Patch-package will apply as
357+
many of the changes as it can and then leave it to you to fix the rest.
358+
359+
Any errors encountered will be written to a file `./patch-package-errors.log` to
360+
help you keep track of what needs fixing.
361+
345362
## Benefits of patching over forking
346363

347364
- Sometimes forks need extra build steps, e.g. with react-native for Android.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test partial-apply: 00: patch-package fails when one of the patches in the sequence fails 1`] = `
4+
"SNAPSHOT: patch-package fails when one of the patches in the sequence fails
5+
patch-package 0.0.0
6+
Applying patches...
7+
[email protected] (1 hello) ✔
8+
9+
⛔ ERROR
10+
11+
Failed to apply patch file left-pad+1.3.0+002+world.patch.
12+
13+
If this patch file is no longer useful, delete it and run
14+
15+
patch-package
16+
17+
To partially apply the patch (if possible) and output a log of errors to fix, run
18+
19+
patch-package --partial
20+
21+
After which you should make any required changes inside node_modules/left-pad, and finally run
22+
23+
patch-package left-pad
24+
25+
to update the patch file.
26+
27+
END SNAPSHOT"
28+
`;
29+
30+
exports[`Test partial-apply: 01: patch-package --partial saves a log 1`] = `
31+
"SNAPSHOT: patch-package --partial saves a log
32+
patch-package 0.0.0
33+
Applying patches...
34+
[email protected] (1 hello) ✔
35+
Saving errors to ./patch-package-errors.log
36+
patch-package-errors.log
37+
Cannot apply hunk 0 for file node_modules/left-pad/index.js
38+
\`\`\`diff
39+
@@ -3,7 +3,7 @@
40+
* and/or modify it under the terms of the Do What The Fuck You Want
41+
* To Public License, Version 2, as published by Sam Hocevar. See
42+
* http://www.wtfpl.net/ for more details. */
43+
-'use oops';
44+
+'use world';
45+
module.exports = leftPad;
46+
47+
var cache = [
48+
\`\`\`
49+
END SNAPSHOT"
50+
`;

integration-tests/partial-apply/package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "partial-apply",
3+
"version": "1.0.0",
4+
"description": "integration test for patch-package",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "ISC",
8+
"dependencies": {
9+
"left-pad": "^1.3.0"
10+
}
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# make sure errors stop the script
3+
set -e
4+
5+
npm install
6+
7+
echo "add patch-package"
8+
npm add $1
9+
10+
function patch-package {
11+
./node_modules/.bin/patch-package "$@"
12+
}
13+
14+
echo "SNAPSHOT: patch-package fails when one of the patches in the sequence fails"
15+
if patch-package
16+
then
17+
exit 1
18+
fi
19+
echo "END SNAPSHOT"
20+
21+
22+
echo "SNAPSHOT: patch-package --partial saves a log"
23+
patch-package --partial
24+
echo 'patch-package-errors.log'
25+
cat patch-package-errors.log
26+
echo "END SNAPSHOT"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
runIntegrationTest({
3+
projectName: "partial-apply",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
2+
index e90aec3..1a2ec5f 100644
3+
--- a/node_modules/left-pad/index.js
4+
+++ b/node_modules/left-pad/index.js
5+
@@ -3,7 +3,7 @@
6+
* and/or modify it under the terms of the Do What The Fuck You Want
7+
* To Public License, Version 2, as published by Sam Hocevar. See
8+
* http://www.wtfpl.net/ for more details. */
9+
-'use strict';
10+
+'use hello';
11+
module.exports = leftPad;
12+
13+
var cache = [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
2+
index 1a2ec5f..5aa41be 100644
3+
--- a/node_modules/left-pad/index.js
4+
+++ b/node_modules/left-pad/index.js
5+
@@ -3,7 +3,7 @@
6+
* and/or modify it under the terms of the Do What The Fuck You Want
7+
* To Public License, Version 2, as published by Sam Hocevar. See
8+
* http://www.wtfpl.net/ for more details. */
9+
-'use oops';
10+
+'use world';
11+
module.exports = leftPad;
12+
13+
var cache = [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
2+
index 5aa41be..5ee751b 100644
3+
--- a/node_modules/left-pad/index.js
4+
+++ b/node_modules/left-pad/index.js
5+
@@ -3,7 +3,7 @@
6+
* and/or modify it under the terms of the Do What The Fuck You Want
7+
* To Public License, Version 2, as published by Sam Hocevar. See
8+
* http://www.wtfpl.net/ for more details. */
9+
-'use world';
10+
+'goodbye world';
11+
module.exports = leftPad;
12+
13+
var cache = [

property-based-tests/executeTestCase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function executeTestCase(testCase: TestCase) {
132132
fs.setWorkingFiles({ ...testCase.cleanFiles })
133133
reportingFailures(() => {
134134
const effects = parsePatchFile(patchFileContents)
135-
executeEffects(effects, { dryRun: false })
135+
executeEffects(effects, { dryRun: false, bestEffort: false })
136136
expect(fs.getWorkingFiles()).toEqual(testCase.modifiedFiles)
137137
})
138138
})
@@ -141,7 +141,7 @@ export function executeTestCase(testCase: TestCase) {
141141
fs.setWorkingFiles({ ...testCase.modifiedFiles })
142142
reportingFailures(() => {
143143
const effects = reversePatch(parsePatchFile(patchFileContents))
144-
executeEffects(effects, { dryRun: false })
144+
executeEffects(effects, { dryRun: false, bestEffort: false })
145145
expect(fs.getWorkingFiles()).toEqual(testCase.cleanFiles)
146146
})
147147
})

0 commit comments

Comments
 (0)