File tree Expand file tree Collapse file tree 4 files changed +1438
-1310
lines changed Expand file tree Collapse file tree 4 files changed +1438
-1310
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ Run `patch-package` without arguments to apply all patches in your project.
229229
230230 Specify the name for the directory in which the patch files are located
231231
232+ - ` --expect-patch`
233+
234+ Prints error when no patches happen. Best combined with `--error-on-fail` (enabled by default on CI).
235+
232236# ### Notes
233237
234238To apply patches individually, you may use `git` :
Original file line number Diff line number Diff line change @@ -95,28 +95,34 @@ export function applyPatchesForApp({
9595 appPath,
9696 reverse,
9797 patchDir,
98+ expectPatch,
9899 shouldExitWithError,
99100 shouldExitWithWarning,
100101 bestEffort,
101102} : {
102103 appPath : string
103104 reverse : boolean
104105 patchDir : string
106+ expectPatch : boolean
105107 shouldExitWithError : boolean
106108 shouldExitWithWarning : boolean
107109 bestEffort : boolean
108110} ) : void {
109111 const patchesDirectory = join ( appPath , patchDir )
110112 const groupedPatches = getGroupedPatches ( patchesDirectory )
111113
112- if ( groupedPatches . numPatchFiles === 0 ) {
113- console . log ( chalk . blueBright ( "No patch files found" ) )
114- return
115- }
116-
117114 const errors : string [ ] = [ ]
118115 const warnings : string [ ] = [ ...groupedPatches . warnings ]
119116
117+ if ( groupedPatches . numPatchFiles === 0 ) {
118+ if ( expectPatch ) {
119+ errors . push ( "No patch files found" )
120+ } else {
121+ console . log ( chalk . blueBright ( "No patch files found" ) )
122+ return
123+ }
124+ }
125+
120126 for ( const patches of Object . values (
121127 groupedPatches . pathSpecifierToPatchFiles ,
122128 ) ) {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const argv = minimist(process.argv.slice(2), {
2525 "error-on-warn" ,
2626 "create-issue" ,
2727 "partial" ,
28+ "expect-patch" ,
2829 "" ,
2930 ] ,
3031 string : [ "patch-dir" , "append" , "rebase" ] ,
@@ -114,11 +115,13 @@ if (argv.version || argv.v) {
114115 process . env . NODE_ENV === "test"
115116
116117 const shouldExitWithWarning = ! ! argv [ "error-on-warn" ]
118+ const expectPatch = ! ! argv [ "expect-patch" ]
117119
118120 applyPatchesForApp ( {
119121 appPath,
120122 reverse,
121123 patchDir,
124+ expectPatch,
122125 shouldExitWithError,
123126 shouldExitWithWarning,
124127 bestEffort : argv . partial ,
@@ -177,6 +180,15 @@ Usage:
177180 This option was added to help people using CircleCI avoid an issue around caching
178181 and patch file updates (https://github.com/ds300/patch-package/issues/37),
179182 but might be useful in other contexts too.
183+
184+ ${ chalk . bold ( "--expect-patch" ) }
185+
186+ Prints an error if no patch files were found.
187+
188+ This option works in tandem with ${ chalk . bold (
189+ "--error-on-fail" ,
190+ ) } (enabled by default in CI) to prevent
191+ accidental skips due to patch folder was missed or ignored. For example during COPY in Dockerfile, or in .dockerignore.
180192
181193
182194 2. Creating patch files
You can’t perform that action at this time.
0 commit comments