patch-package
patch-package copied to clipboard
Specifying multiple --include or --exclude paths
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 Hey, is there any way that to do multiple files in one --include
as of now? thanks!
@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 thanks!
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"'
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.
Thanks @xan105.