yarn-easy-patch
v1.1.1
Published
A simpler alternative to the cumbersome yarn patch workflow - automatically creates patches from your node_modules changes
Maintainers
Readme
yarn-easy-patch
A simpler alternative to the cumbersome yarn patch workflow.
The Problem
The standard Yarn patch workflow is an unusable aberration:
- Run
yarn patch <package>to get a temp folder - Manually edit files in that temp folder
- Run
yarn patch-committo create the patch
But often, you've already made changes directly in node_modules while debugging. Now you need to recreate those changes in the temp folder? 😩
The Solution
yarn-easy-patch automates this by:
- Detecting existing patches and applying them to
node_modulesfirst - Running
yarn patchto create the temp folder - Automatically copying your changes from
node_modulesto the temp folder - Running
yarn patch-committo create the patch - Cleaning up old patch files if a new one was created
Just make your changes in node_modules, then run one command!
Installation
Run directly (no install needed)
yarn dlx yarn-easy-patch <package-name>Install globally
npm install -g yarn-easy-patchThen run:
yarn-easy-patch <package-name>Usage
# Make your changes directly in node_modules
vim node_modules/some-package/lib/index.js
# Create the patch
yarn dlx yarn-easy-patch some-packageThe patch file will be created in your .yarn/patches/ directory and your package.json will be updated with the patch resolution.
Incremental Patching
If you already have a patch for a package and want to add more changes, yarn-easy-patch will:
- Detect the existing patch in
.yarn/patches/ - Apply it to
node_modulesbefore you make additional changes - Create a new combined patch with both old and new changes
- Remove the old patch file automatically
This lets you incrementally build on existing patches without losing previous work.
Options
yarn-easy-patch <package-name> [options]
Options:
-h, --help Show help message
-v, --version Show version number
--patches-dir <path> Directory to look for existing patches
(default: .yarn/patches)Examples
# Basic usage
yarn dlx yarn-easy-patch react-native
# Scoped packages
yarn dlx yarn-easy-patch @babel/core
# Custom patches directory
yarn dlx yarn-easy-patch some-package --patches-dir ./my-patchesRequirements
- Node.js >= 16
- Yarn Berry (Yarn 2+)
rsync(pre-installed on macOS/Linux)
How It Works
- Checks for existing patches in
.yarn/patches/and attempts to apply them tonode_modules - Runs
yarn patch <package>which creates a temporary folder - Uses
rsyncto copy your modified files fromnode_modules/<package>/to the temp folder - Runs the
yarn patch-commitcommand to generate the.patchfile - Removes old patch files if a new one with a different hash was created
License
MIT
