A lightweight and interactive CLI tool for uninstalling Node.js packages in bulk directly from your package.json
.
- Detects installed dependencies from
dependencies
,devDependencies
,peerDependencies
, andoptionalDependencies
. - Supports npm, yarn, and pnpm package managers.
- Batch uninstallation of selected packages for optimal performance.
- Fully interactive command-line interface using
inquirer
. - Automatically detects the package manager in use.
Install the pkg-uninstaller-cli
globally using npm:
npm install -g pkg-uninstaller-cli
Or using yarn:
yarn global add pkg-uninstaller-cli
Currently, the tool has two main commands:
pkg-uninstaller uninstall
: Uninstall selected packages interactively.pkg-uninstaller analyze
: Analyze and identify unused dependencies in the project.
Navigate to the project directory containing your package.json file and run the following command:
pkg-uninstaller uninstall
You can also use the shorthand command:
pkg-u uninstall
You can also use the tool without installing it globally by using npx
:
npx pkg-uninstaller-cli uninstall
- The tool lists all installed packages (from dependencies, devDependencies, etc.).
- You select multiple packages to uninstall using an interactive checkbox.
- The tool detects your package manager (npm or yarn) automatically.
- Packages are uninstalled in batches of 5 for efficiency.
$ pkg-uninstaller uninstall
Detected package manager: npm
? Select packages to uninstall: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◉ chalk
◉ lodash
◉ inquirer
Running: npm uninstall chalk lodash inquirer
Successfully uninstalled: chalk, lodash, inquirer
All batches processed.
Navigate to the project directory containing your package.json
file and run the following command:
pkg-uninstaller analyze
You can also use the shorthand command:
pkg-u analyze
You can also use the tool without installing it globally by using npx
:
npx pkg-uninstaller-cli analyze
-v, --verbose: Enable verbose logging for detailed output.
- The tool analyzes your project and lists all unused dependencies.
- You can choose to uninstall the unused dependencies interactively.
$ pkg-uninstaller analyze
The following dependencies appear to be unused:
- @react-native-community/datetimepicker
- @stream-io/flat-list-mvcp
✔ Would you like to uninstall unused dependencies? Yes
Detected package manager: npm
Running: npm uninstall @react-native-community/datetimepicker @stream-io/flat-list-mvcp
Successfully uninstalled: @react-native-community/datetimepicker @stream-io/flat-list-mvcp
All batches processed.
You can use a configuration file named .pkg-uninstaller.json to specify dependencies to ignore during the analysis.
Create a .pkg-uninstaller.json
file in the root of your project with the following format:
{
"ignoreDependencies": ["dependency1", "dependency2"]
}
Example Configuration
{
"ignoreDependencies": [
"expo-build-properties",
"expo-dev-client",
"expo-system-ui",
"patch-package"
]
}
The tool will automatically read the .pkg-uninstaller.json
file and ignore the specified dependencies during the analysis.
- Node.js v14.0.0 or higher
- npm or yarn installed
There is also a Visual Studio Code extension version of this project available. You can find it at:
- GitHub: https://github.com/theBGuy/vs-pkg-uninstaller
- Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=theBGuy.pkguninstaller
- Reads the package.json in the current working directory.
- Detects installed packages across all dependency types.
- Provides an interactive interface for selecting packages.
- Executes uninstallation commands in batches to enhance performance.
Planned features include:
- Undo Uninstall: Restore recently uninstalled packages.
- Search and Filter: Easily search for packages by name before selecting.
- Custom Batch Sizes: Allow users to configure batch sizes for uninstallation.
- Progress Indicators: Display progress bars for ongoing tasks.
Contributions are welcome! Feel free to fork the repository and open a pull request with your improvements.
- Fork the repository.
- Create a new branch for your feature or fix.
- Submit a pull request explaining your changes.
This project is licensed under the MIT License.