cleanup-package-json
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesecleanup-package-json
cleanup-package-json
ワークフロー
Workflow
1. 現状把握
1. Current Status Assessment
package.jsonスクリプトのチェックポイント:
- エイリアス: 別のスクリプトを呼ぶだけのスクリプト(例: )
"build": "npm run build:app" - パススルー: コマンドをそのまま渡すだけのスクリプト(例: )
"lint": "eslint" - 暗黙のライフサイクルフック: /
preXフック(例:postX)"prebuild": "npm run codegen" - 命名の不統一: 関連スクリプトがグループ化されていない(例: が
e2e系に混ざっていない)test:*
依存関係のチェックポイント:
- /
dependenciesの各パッケージをソースコード内の import 文で検索し、未使用を特定するdevDependencies - 検索対象ディレクトリはプロジェクト構造に応じて判断する(、
src/、lib/など)app/
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. 問題点の提示と確認
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. スクリプトの修正
3. Script Modifications
確認が取れたら を編集する。
package.json典型的な変換パターン:
| パターン | 変換前 | 変換後 |
|---|---|---|
| エイリアス統合 | | |
| pre フック明示化 | | |
| パススルー削除 | | 削除(直接 |
| 命名統一 | | |
パッケージマネージャーは / / のいずれが使われているかを や lockfile の存在から判断して使い分ける。
npm runyarnpnpm runpackage.jsonEdit 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. ドキュメントの更新確認
4. Confirm Document Updates
スクリプト名を変更・削除した場合は、以下のファイルにその名前が登場していないか確認し、必要であれば修正する。
README.md- /
CLAUDE.mdなどのエージェント向けドキュメントAGENTS.md - 配下のワークフローファイル
.github/workflows/ - 配下のドキュメント
docs/
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. 依存削除後のロックファイル再生成
5. Regenerate Lock Files After Dependency Removal
依存パッケージを削除した場合は、 とロックファイルを削除してから install を実行する。
node_modulesbash
undefinedIf dependency packages are removed, delete and the lockfile, then run install.
node_modulesbash
undefinednpm
npm
rm -rf node_modules package-lock.json && npm install
rm -rf node_modules package-lock.json && npm install
yarn
yarn
rm -rf node_modules yarn.lock && yarn install
rm -rf node_modules yarn.lock && yarn install
pnpm
pnpm
rm -rf node_modules pnpm-lock.yaml && pnpm install
undefinedrm -rf node_modules pnpm-lock.yaml && pnpm install
undefined注意事項
Notes
- pre フックの削除: フックを削除して明示的に呼び出す形にすると、そのスクリプトを単独で呼んだときも(意図しない)フックが走らなくなる。動作変更を伴うため、ユーザーに確認してから変換する。
preX - スクリプト名の変更: CI やドキュメントで参照されているスクリプト名を変更する場合は、必ず参照先も合わせて更新する。
- ネイティブ連携パッケージ: Tauri / Electron など、ネイティブ層との橋渡しをする npm パッケージは JS 側の import がなくても実際には必要なことがある。ランタイム要件を確認してから削除する。
- 間接依存: に書かれていても直接 import していない場合がある(例: Babel プラグイン、ESLint プリセットなど設定ファイル経由で参照されるもの)。削除前にビルド・テストで確認する。
dependencies
- 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