Patch Package

patch-package allow developers to update code in node_modules with still keeping your changes even after upgrading/downgrading your node_modules.

patch-package — kpiteng

Consider you have install one package,

Now, you want to update that package for fix some issues / customise it. So,

First Install patch-package dependency,

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.

Now execute,

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.

Commands -

rm -rf node_modules/ (to delete node_modules)

yarn (to install node_modules packages)

Now, Let’s downgrade your package version, So execute,

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.

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

KPITENG || hello@kpiteng.com ||DIGITAL TRANSFORMATION

Connect Us — Linkedin | Facebook | Instagram

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store