Prompt file imported from yu-iskw/llmops-demo-ts (
.cursor/commands/remove-unused-dependencies.md). Copyright stays with the author.
Remove Unused Dependencies
This command analyzes and removes unused dependencies from all packages in the workspace using pnpm and depcheck.
Steps
- Analyze Dependencies: Run depcheck on all workspace packages to identify unused dependencies
- Remove Unused Dependencies: Automatically remove identified unused dependencies from package.json files
- Update Lockfile: Run
pnpm installto update the lockfile - Verify Build: Run the full build to ensure no breaking changes
Prerequisites
pnpmmust be installeddepcheckmust be available (installed viapnpm dlx)
Usage
Run this command from the project root directory. Execute these steps:
-
Analyze dependencies recursively across all workspace packages:
pnpm recursive exec -- pnpm dlx depcheckNote: This command will show unused dependencies for each package. Review the output and manually remove unused dependencies from each package.json file.
-
Update lockfile after removing dependencies:
pnpm install -
Verify build:
pnpm build
What Gets Removed
The command identifies and removes:
- Unused runtime dependencies across all workspace packages
- Unused development dependencies across all workspace packages
- Unused type definitions across all workspace packages
Recursive Operations
The pnpm recursive exec command runs depcheck analysis across all packages in the workspace, allowing you to identify unused dependencies in each package simultaneously.
Safety
- Only removes dependencies that are confirmed unused by static analysis
- Preserves workspace references and internal imports
- Verifies build integrity after changes
