bun patch
Persistently patch node_modules packages in a git-friendly way
bun patch persistently patches packages in node_modules in a maintainable, git-friendly way.
Sometimes you need a small change to a package in node_modules/ to fix a bug or add a feature. bun patch lets you do this without vendoring the entire package.
Features:
- Generates
.patchfiles that Bun applies to dependencies innode_moduleson install - You can commit
.patchfiles to your repository and reuse them across installs, projects, and machines "patchedDependencies"inpackage.jsonkeeps track of patched packages- Patches packages in
node_modules/while preserving the integrity of Bun's Global Cache - Test your changes locally before committing them with
bun patch --commit <pkg> - To preserve disk space and keep
bun installfast, Bun commits patched packages to the Global Cache and shares them across projects where possible
Step 1. Prepare the package for patching#
Use bun patch <pkg> to prepare the package for patching:
# you can supply the package name
bun patch react
# ...and a precise version in case multiple versions are installed
bun patch react@17.0.2
# or the path to the package
bun patch node_modules/reactAlways run bun patch <pkg> first. It ensures the package folder in node_modules/ contains a fresh copy of the package with no symlinks or hardlinks to Bun's cache.
If you skip it, you might end up editing the package globally in the cache.
Step 2. Test your changes locally#
bun patch <pkg> makes it safe to edit <pkg> in node_modules/ directly, while preserving the integrity of Bun's Global Cache. It works by re-creating an unlinked clone of the package in node_modules/. bun patch --commit <pkg> then diffs that clone against the original package in the Global Cache.
Step 3. Commit your changes#
Once you're happy with your changes, run bun patch --commit <path or pkg>.
Bun generates a patch file in patches/, updates your package.json and lockfile, and starts using the patched package:
# you can supply the path to the patched package
bun patch --commit node_modules/react
# ... or the package name and optionally the version
bun patch --commit react@17.0.2
# choose the directory to store the patch files
bun patch --commit react --patches-dir=mypatches
# `patch-commit` is available for compatibility with pnpm
bun patch-commit reactCLI Usage#
bun patch <package>@<version>Patch Generation#
Install a package containing modifications in dir
The directory to put the patch file in (only if --commit is used)
Dependency Management#
Don't install devDependencies. Alias: -p
Skip lifecycle scripts for all packages, including the project's package.json and trusted dependencies
Add to trustedDependencies in the project's package.json and install the package(s)
Install globally. Alias: -g
Exclude dev, optional, or peer dependencies from install
Project Files & Lockfiles#
Write a yarn.lock file (yarn v1). Alias: -y
Don't update package.json or save a lockfile
Save to package.json (true by default)
Disallow changes to lockfile
Save a text-based lockfile
Generate a lockfile without installing dependencies
Installation Control#
Platform-specific optimizations for installing dependencies. Possible values: clonefile (default on
macOS), hardlink (default on Linux and Windows), symlink, copyfile
Linker strategy (one of isolated or hoisted)
Only install packages published at least N seconds ago (security feature)
Don't install packages, update package.json, or save a lockfile. The package is still copied into
node_modules for patching, and --commit still writes the patch file
Always request the latest versions from the registry & reinstall all dependencies. Alias: -f
Skip verifying integrity of newly downloaded packages
Network & Registry#
Provide a Certificate Authority signing certificate
Same as --ca, but as a file path to the certificate
Use a specific registry by default, overriding .npmrc, bunfig.toml, and environment
variables
Maximum number of concurrent network requests (default 48)
Performance & Resource#
Maximum number of concurrent jobs for lifecycle scripts (default: 2x CPU cores)
Caching#
Store & load cached data from a specific directory path
Ignore manifest cache entirely
Output & Logging#
Don't log anything
Disable the progress bar
Excessively verbose logging
Disable the progress bar
Don't print a summary
Platform Targeting#
Override CPU architecture for optional dependencies (e.g., x64, arm64, * for
all)
Override operating system for optional dependencies (e.g., linux, darwin, * for
all)
Global Configuration & Context#
Specify path to config file (bunfig.toml). Alias: -c
Set a specific current working directory
Help#
Print this help menu. Alias: -h