Dependency Management
removeDependencies
Removes dependencies fromdependencies and devDependencies in package.json, then optionally runs the detected package manager install command.
string | string[]
required
Package name(s) to remove from both
dependencies and devDependenciesobject
Promise<string | null>
- Returns updated
package.jsoncontent as a string when changes are applied - Returns
nullwhen:- There is nothing to remove
- No
package.jsonexists at the specified path - A parsing or runtime failure occurs
Package Manager Detection
The function automatically detects the package manager in this order:
package.jsonpackageManagerfield- Lockfile detection:
pnpm-lock.yaml→ pnpmyarn.lock→ yarn
- Defaults to npm
runInstall is enabled (default), it runs <package-manager> install in the package directory.Usage Examples
- Basic Removal
- Preview Mode
- Monorepo Usage
Script Analysis
getScriptsNode
Finds the “scripts” section in a package.json AST.SgRoot
required
The root node of the package.json AST (parsed as JSON)
SgNode[] - Array of nodes representing pairs in the scripts section
getNodeJsUsage
Finds all references tonode or node.exe in package.json scripts.
SgRoot
required
The root node of the package.json AST
Array<{ node: SgNode, text: () => string }> - Array of objects containing:
node: The AST node for the scripttext(): Function that returns the unquoted script content
Node.js Argument Transformation
replaceNodeJsArgs
Replaces Node.js script arguments inpackage.json scripts. Useful for normalizing or rewriting CLI arguments used with node.
SgRoot
required
The root node of the package.json AST
Record<string, string>
required
A mapping of argument names to their replacement values. Use empty string to remove an argument.
Edit[] - Array of edit operations to apply
removeNodeJsArgs
Removes specified arguments from Node.js script usages inpackage.json.
SgRoot
required
The root node of the package.json AST
string[]
required
Array of argument names to remove from Node.js commands in scripts
Edit[] - Array of edit operations to apply