cleanup-package-json
Original:🇨🇳 Chinese
Translated
Organize and clean up scripts and dependencies in package.json. Use this for requests such as 'I want to clean up package.json', 'I want to organize scripts', or 'I want to remove unused dependencies'. Specifically, it targets the following: (1) Delete or integrate redundant scripts (aliases/passthroughs), (2) Explicitize implicit lifecycle hooks (pre/post), (3) Unify script naming conventions, (4) Detect and remove unused dependency packages, (5) Update documents and CI following script name changes, (6) Regenerate lock files after removing dependencies.
1installs
Sourcenimiusrd/agent-skills
Added on
NPX Install
npx skill4agent add nimiusrd/agent-skills cleanup-package-jsonTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →cleanup-package-json
Workflow
1. Current Status Assessment
Read the and identify issues from the following perspectives:
package.jsonScript Checkpoints:
- Aliases: Scripts that only call another script (e.g., )
"build": "npm run build:app" - Passthroughs: Scripts that just pass through commands directly (e.g., )
"lint": "eslint" - Implicit Lifecycle Hooks: /
preXhooks (e.g.,postX)"prebuild": "npm run codegen" - Inconsistent Naming: Related scripts are not grouped (e.g., is not included in the
e2eseries)test:*
Dependency Checkpoints:
- Search each package in /
dependenciesvia import statements in the source code to identify unused onesdevDependencies - Determine the target search directories based on the project structure (e.g., ,
src/,lib/)app/
2. Present Issues and Confirm
Present the identified issues to the user and confirm which ones to fix. Provide options and obtain consensus before proceeding with the work.
3. Script Modifications
Edit the once confirmation is obtained.
package.jsonTypical Conversion Patterns:
| Pattern | Before Conversion | After Conversion |
|---|---|---|
| Alias Integration | | |
| Pre-hook Explicitization | | |
| Passthrough Removal | | Remove (either call |
| Naming Unification | | |
Determine which package manager (//) is being used from the or the presence of lockfiles, and use the appropriate one.
npm runyarnpnpm runpackage.json4. Confirm Document Updates
If script names are changed or deleted, check if those names appear in the following files and modify them if necessary:
README.md- Agent-facing documents such as /
CLAUDE.mdAGENTS.md - Workflow files under
.github/workflows/ - Documents under
docs/
5. Regenerate Lock Files After Dependency Removal
If dependency packages are removed, delete and the lockfile, then run install.
node_modulesbash
# npm
rm -rf node_modules package-lock.json && npm install
# yarn
rm -rf node_modules yarn.lock && yarn install
# pnpm
rm -rf node_modules pnpm-lock.yaml && pnpm installNotes
- Removing Pre-hooks: If you remove hooks and call them explicitly, the (unintended) hooks will no longer run even when the script is called alone. Since this changes the behavior, confirm with the user before converting.
preX - Changing Script Names: If you change script names that are referenced in CI or documents, be sure to update the references accordingly.
- Native Integration Packages: npm packages that bridge with native layers such as Tauri/Electron may actually be necessary even if there are no imports on the JS side. Check runtime requirements before deleting.
- Indirect Dependencies: Even if listed in , some packages may not be imported directly (e.g., Babel plugins, ESLint presets referenced via configuration files). Confirm via build/test before deleting.
dependencies