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
Advanced patch sequence management for reordering, editing, and managing complex patch workflows. The rebase functionality enables developers to modify patch history, insert changes at specific points, and manage complex patch sequences with confidence.
Core function for rebasing patch sequences to different targets.
/**
* Rebase patches to a specific target in the sequence
* @param options - Rebase configuration options
*/
function rebase(options: RebaseOptions): void;
interface RebaseOptions {
/** Application root path */
appPath: string;
/** Directory containing patch files */
patchDir: string;
/** Package path specifier to rebase */
packagePathSpecifier: string;
/** Target patch identifier (file name, number, name, or "0") */
targetPatch: string;
}Usage Examples:
import { rebase } from "patch-package/dist/rebase";
import { getAppRootPath } from "patch-package/dist/getAppRootPath";
// Rebase to specific patch file
rebase({
appPath: getAppRootPath(),
patchDir: "patches",
packagePathSpecifier: "lodash",
targetPatch: "lodash+4.17.21.patch"
});
// Rebase to sequence number
rebase({
appPath: process.cwd(),
patchDir: "patches",
packagePathSpecifier: "react",
targetPatch: "3"
});
// Reset to beginning (un-apply all patches)
rebase({
appPath: process.cwd(),
patchDir: "patches",
packagePathSpecifier: "lodash",
targetPatch: "0"
});Target a specific patch file by its exact filename.
patch-package --rebase "lodash+4.17.21.patch" lodashTarget patches by their position in the sequence (1-based indexing).
patch-package --rebase "3" lodashTarget patches by their descriptive names (if using named sequences).
patch-package --rebase "security-fix" lodashUse "0" to un-apply all patches and start fresh.
patch-package --rebase "0" lodashBefore rebasing, patch-package validates:
Patches after the target are reversed in order:
The package enters "rebasing" state where:
During rebase, you can:
# Update the target patch
patch-package my-package
# Add new patch after target
patch-package my-package --append="description"Rebase operations integrate with patch application state for safe operation.
/**
* Internal function for un-applying patches during rebase
* @param options - Un-apply configuration
*/
function unApplyPatches(options: UnApplyPatchesOptions): void;
interface UnApplyPatchesOptions {
/** Array of patches to un-apply */
patches: PatchedPackageDetails[];
/** Application path */
appPath: string;
/** Patch directory */
patchDir: string;
}Comprehensive error handling for rebase operations:
Error Recovery:
# If rebase fails, you can:
# 1. Reinstall node_modules to reset state
npm install
# 2. Delete problematic patch files
rm patches/broken-package+1.0.0.patch
# 3. Restart the rebase process
patch-package --rebase 0 my-packageWhen rebase enters interactive mode, patch-package provides clear instructions:
# Output example during rebase
Make any changes you need inside /path/to/package
When you are done, do one of the following:
To update lodash+4.17.21.patch run
patch-package lodash
To create a new patch file after lodash+4.17.21.patch run
patch-package lodash --append 'MyChangeDescription'# Rebase to position 2
patch-package --rebase 2 my-package
# Make changes and insert new patch
patch-package my-package --append="hotfix"# Rebase to first patch
patch-package --rebase 1 my-package
# Modify files and update the patch
patch-package my-package# Rebase to earlier position
patch-package --rebase 3 my-package
# Don't add new patches - effectively truncates sequence# Reset to beginning
patch-package --rebase 0 my-package
# Create entirely new patch sequence
patch-package my-package --append="complete-rewrite"patch-package to verify patches applyComplete Rebase Example:
import { rebase } from "patch-package/dist/rebase";
import { getAppRootPath } from "patch-package/dist/getAppRootPath";
import { getPatchApplicationState } from "patch-package/dist/stateFile";
// Check current state before rebasing
const appPath = getAppRootPath();
const packageDetails = { name: "lodash", path: "/path/to/lodash" };
const currentState = getPatchApplicationState(packageDetails);
if (currentState && !currentState.isRebasing) {
// Safe to begin rebase
rebase({
appPath,
patchDir: "patches",
packagePathSpecifier: "lodash",
targetPatch: "2" // Rebase to second patch
});
console.log("Rebase initiated - make your changes and run patch-package");
} else {
console.log("Cannot rebase: operation already in progress or no state");
}This comprehensive rebase system enables sophisticated patch management workflows while maintaining safety and providing clear guidance throughout the process.
Install with Tessl CLI
npx tessl i tessl/npm-patch-package