Skip to content

Instantly share code, notes, and snippets.

@4sskick
Created October 10, 2025 08:02
Show Gist options
  • Save 4sskick/682a56b75e76b0f5d6cd4e0ea71ffc60 to your computer and use it in GitHub Desktop.
Save 4sskick/682a56b75e76b0f5d6cd4e0ea71ffc60 to your computer and use it in GitHub Desktop.
A quick reference for detecting modified files inside node_modules after manual edits. Since Git ignores node_modules, this guide uses sha1sum (or md5sum) to track file integrity and identify which packages need patching — ideal for developers using yarn patch-package.

Detecting Changes in node_modules for Patch Package

When you edit files inside node_modules, Git does not track them --- so git status won't help detect changes.
This guide explains how to use sha1sum (or md5sum) to detect modified packages.


🧰 Check Compatibility

Ensure that sha1sum is available in your system (run this in bash, not PowerShell):

$ sha1sum --help
Usage: sha1sum [OPTION]... [FILE]...
Print or check SHA1 (160-bit) checksums.

If you see similar output, the command is ready to use.


🔍 Generate Hash for node_modules

1. Generate hash for all .js files

find node_modules -type f -name "*.js" | sort | xargs sha1sum > .node_modules.hash

2. Generate hash for all files

find node_modules -type f | sort | xargs sha1sum > .node_modules.hash

3. Skip large/binary files

To skip .png, .jpg, .jar, and .aar files:

find node_modules -type f ! -name "*.png" ! -name "*.jpg" ! -name "*.jar" ! -name "*.aar" | sort | xargs sha1sum > .node_modules.hash

4. Faster hash using md5sum

find node_modules -type f -name "*.js" | sort | xargs md5sum > .node_modules.hash

📄 Example of Generated .node_modules.hash

Each line includes the hash and file path:

116d3be5fc68bb1840a26330c47bd986508c7e5b *node_modules/@twotalltotems/react-native-otp-input/index.js

🧪 Detect Changed Files

After editing and saving files inside node_modules, run:

sha1sum -c .node_modules.hash | grep FAILED | awk -F'[:/]' '{print $1} {print $2} {print $3}' | sort -u

Example output:

sha1sum: WARNING: 1 computed checksum did NOT match
@twotalltotems
node_modules
react-native-otp-input

This output indicates which package(s) need to be patched.


🧩 Create Patch with Yarn

Once you've identified the modified package, create a patch using:

yarn patch-package

✅ Done!
You can now track which packages have been manually edited and safely generate patch files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment