Fix broken node modules with no fuss - create and apply patches to npm dependencies instantly
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete command-line interface for creating and applying patches to npm dependencies. The CLI supports both interactive development workflows and automated CI/CD environments with comprehensive error handling and flexible configuration options.
The primary patch-package command with multiple operation modes.
# Patch application mode (default)
patch-package [options]
# Patch creation mode
patch-package <package-name> [package-name...] [options]
# Rebase mode
patch-package --rebase <target> <package-name>
# Help and version
patch-package --help
patch-package --versionOptions for applying existing patches during package installation.
--patch-dir <dirname> # Specify patch directory (default: "patches")
--error-on-fail # Exit with code 1 on failure (auto-enabled in CI)
--error-on-warn # Exit with code 1 on warnings
--reverse # Un-apply all patches
--partial # Best-effort patch application, continue on failuresUsage Examples:
# Apply patches from custom directory
patch-package --patch-dir=custom-patches
# Apply patches with strict error handling
patch-package --error-on-fail --error-on-warn
# Reverse all applied patches
patch-package --reverse
# Apply patches with best-effort mode (continue on failures)
patch-package --partialOptions for creating new patch files from modified node_modules.
--create-issue # Open GitHub issue creation link
--use-yarn # Force use of yarn package manager
--include <regexp> # Include paths matching regexp (default: .*)
--exclude <regexp> # Exclude paths matching regexp (default: ^package\.json$)
--case-sensitive-path-filtering # Make path filters case-sensitive
--append [name] # Append new patch to sequence (name is optional)Usage Examples:
# Create patch for single package
patch-package react
# Create patches for multiple packages
patch-package react react-dom lodash
# Create patch with custom include/exclude patterns
patch-package lodash --include="src/.*" --exclude="test/.*"
# Create patch and open GitHub issue
patch-package broken-package --create-issue
# Append to existing patch sequence
patch-package some-package --append="fix-critical-bug"
# Force yarn usage even in npm project
patch-package some-package --use-yarnAdvanced functionality for rebasing patch sequences to different targets.
--rebase <target> <package-name> # Rebase patches to target patch file/numberUsage Examples:
# Rebase to specific patch file
patch-package --rebase patches/lodash+4.17.20.patch lodash
# Rebase to patch sequence number
patch-package --rebase 3 lodash
# Rebase to sequence name
patch-package --rebase security-fix lodash
# Rebase to beginning (un-apply all patches)
patch-package --rebase 0 lodashRebase Workflow:
When rebasing, patch-package will:
During Rebase:
# Update the current target patch
patch-package my-package
# Add new patch after target
patch-package my-package --append="new-feature"--help, -h # Show help information
--version, -v # Show version numberpatch-package automatically detects the intended operation mode:
--rebase flag is used with target and package nameThe CLI automatically detects CI environments and adjusts behavior:
--error-on-fail by default in CI environmentsAutomatically detects and works with:
Can be overridden with --use-yarn flag when needed.
Comprehensive error handling with configurable exit behavior:
--error-on-fail exits on any patch failure--error-on-warn exits on warnings--partial continues even when individual patches failAdvanced file filtering capabilities for patch creation:
--include regexp to specify which files to patch--exclude regexp to specify which files to ignore--case-sensitive-path-filtering for precise controlFiltering Examples:
# Only patch TypeScript files
patch-package my-lib --include=".*\.ts$"
# Exclude test and documentation files
patch-package my-lib --exclude="(test|docs|spec)/.*"
# Case-sensitive filtering
patch-package my-lib --include="src/.*" --case-sensitive-path-filteringSupport for sequential patches on the same package:
--append adds to existing patch sequenceSequence Examples:
# Create first patch
patch-package my-package
# Append additional patch with name
patch-package my-package --append="security-fix"
# Append patch without name (auto-numbered)
patch-package my-package --append
# Append another patch to sequence
patch-package my-package --append="performance-improvement"This creates a sequence like:
patches/my-package+1.0.0.patchpatches/my-package+1.0.0++001_security-fix.patchpatches/my-package+1.0.0++002_performance-improvement.patchInstall with Tessl CLI
npx tessl i tessl/npm-patch-package