patch-package icon indicating copy to clipboard operation
patch-package copied to clipboard

Specifying multiple --include or --exclude paths

Open chr-sk opened this issue 4 years ago • 6 comments

When creating a patch, a regex is expected for the --include and --exclude arguments. So the natural way to specify multiple paths would be a regex with a pipe ( | ) in it. For example:

npx patch-package my-module --include file1.java|file2.java

Output:

file2.java: The term 'file2.java' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

It doesn't work with quotes either:

npx patch-package my-module --include 'file1.java|file2.java'

Output:

'file2.java' is not recognized as an internal or external command,
operable program or batch file.

The error occurs with PowerShell 7.0.2 under Windows 10. Under macOS everything works fine. Linux wasn't tested.

chr-sk avatar Sep 20 '20 19:09 chr-sk

@chr-sk Hey, is there any way that to do multiple files in one --include as of now? thanks!

Swor71 avatar Oct 06 '20 07:10 Swor71

@Swor71 I had to work around the issue by patching patch-package itself 😄

In makeRegExp.js, change the line return new RegExp(reString, caseSensitive ? "" : "i"); to return new RegExp(reString.replace(/,/g, "|"), caseSensitive ? "" : "i");

Then use the patch-package command like so: npx patch-package my-module --include 'file1.java,file2.java'

Of course, this only works if your filenames have no comma in them 😉

Btw: the error with the pipe only occurs under Windows. I've tested it with the macOS Terminal recently and the pipe worked without problems, so the patch wouldn't be neccessary there.

chr-sk avatar Oct 06 '20 18:10 chr-sk

@chr-sk thanks!

Swor71 avatar Oct 14 '20 10:10 Swor71

FYI regarding the issue where PowerShell interprets the pipe operator you have to quote the pipe character. Doubling up the quotes is an easy way of doing it:

npx patch-package modulename --exclude '"build|package.json"'

xan105 avatar Oct 22 '22 05:10 xan105

Thanks to @xan105, I have added the following scripts to my React Native app's package.json:

"scripts": {
    "postinstall": "npx --yes patch-package",
    "create-patch": "npx --yes patch-package --exclude 'android/build/|xcodeproj'"
}

And then I create my patches like:

yarn create-patch react-native-jw-media-player

The patch gets created by excluding:

  • folders named build
  • files having xcodeproj in their names

PS: I am using macOS.

SufianBabri avatar Mar 28 '23 19:03 SufianBabri

Thanks @xan105.

trungledangAxonActive avatar Jan 30 '24 04:01 trungledangAxonActive