Better handling for cached 'node_modules' folder · Issue #37 · ds300/patch-package (original) (raw)
Use case
We are using patch-package
to fix some nasty dependency issues, it works great during development. But it sometimes causes CircleCI failures when a partially patched node_modules
folder is cached by CI.
The issue
- Install
patch-package
and add it asprepare
script, as instructed by README. - Patch module
foo-bar
usingpatch-package foo-bar
. Commit the resultedpatches/foo-bar+X.X.X.patch
to repo. - When CI is run, CircleCI installs and patches the
node_modules
folder and saves the result to cache. - Modify module
foo-bar
and regenerate patch file. - CircleCI restores the previous cached
node_modules
folder (which has incorporated previous version of the patch). - CircleCI fails when applying new patch to
node_modules
:
**ERROR** Failed to apply patch for package foo-bar
This error was caused because Git cannot apply the following patch file:
patches/foo-bar+X.X.X.patch
This is usually caused by inconsistent whitespace in the patch file.
Proposed solutions
- Add a checksum file for the
patches
folder so we can easily check if patches has been changed before restoring cache from CI. - Or, add a operation that can revert applied patches, such as
patch-package revert
. So we can revert the patches and save the cleannode_modules
folder to cache.