patch-package allow developers to update code in node_modules with still keeping your changes even after upgrading/downgrading your node_modules.
Consider you have install one package,
yarn add react-native-video-helper
Now, you want to update that package for fix some issues / customise it. So,
First Install patch-package dependency,
yarn add -D patch-package postinstall-postinstall
Turn back to node_module, Make necessary changes in your node_modules/react-native-video-helper/index.js,
Let’s say I have added console.log(“patch-package-testing”); Somewhere in file.
How to improve the performance of a React Native App? | KPITENG
See how you will boost your react native app performance, improve start-up time, decrease bundle size & memory usage.
npx patch-package react-native-video-helper
Which create patches directory in your project’s root folder and create one file, patches/react-native-video-helper+1.5.0
If you open it you can see, whatever changes you did in node_modules. In our case we can see,
+console.log(“Patch Package TEST”);
Now, go to your package.json,
Now, if you delete node_modules, and install again then it will first download react-native-video-helper plugin, and then apply your patch changes. Because you have added patch-package in post install scripts.
Securing React Native Application | KPITENG
Discover a ways to develop secure react native application. iOS Integration - Screenshot Restriction is not possible on…
rm -rf node_modules/ (to delete node_modules)
yarn (to install node_modules packages)
Now, Let’s downgrade your package version, So execute,
yarn add firstname.lastname@example.org
If you go to node_modules/react-native-video-helper, then you can see your console.log(“patch-package-testing”) which you have added, Because after upgrading/downgrading, it will execute post install script execute patch-package and your changes will be updated in your node_modules/react-native-video-helper.
Top 10 React Tricks Every Developer Should Use | KPITENG
Discover a set of React best coding practices, tips and tricks that should be known by all developers. Many times we…
If you think, you no more need of your changes then, simply remove patch files from patches/react-native-video-helper+1.5.0 and execute yarn install, so after yarn install postinstall will execute which check any patches are there to apply, if not found, and that’s it. Now, You are working with latest package.
Thanks for reading full article!
Read More Technical Articles