cleanup-package-json

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

cleanup-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
    /
    devDependencies
    の各パッケージをソースコード内の import 文で検索し、未使用を特定する
  • 検索対象ディレクトリはプロジェクト構造に応じて判断する(
    src/
    lib/
    app/
    など)
Read the
package.json
and identify issues from the following perspectives:
Script 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:
    preX
    /
    postX
    hooks (e.g.,
    "prebuild": "npm run codegen"
    )
  • Inconsistent Naming: Related scripts are not grouped (e.g.,
    e2e
    is not included in the
    test:*
    series)
Dependency Checkpoints:
  • Search each package in
    dependencies
    /
    devDependencies
    via import statements in the source code to identify unused ones
  • 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
を編集する。
典型的な変換パターン:
パターン変換前変換後
エイリアス統合
"build": "npm run build:app"
+
"build:app": "A && B"
"build": "A && B"
pre フック明示化
"prebuild": "npm run X"
+
"build": "Y"
"build": "npm run X && Y"
パススルー削除
"lint": "eslint"
削除(直接
eslint
を呼ぶか不要なら除去)
命名統一
"e2e": "playwright test"
"test:e2e": "playwright test"
パッケージマネージャーは
npm run
/
yarn
/
pnpm run
のいずれが使われているかを
package.json
や lockfile の存在から判断して使い分ける。
Edit the
package.json
once confirmation is obtained.
Typical Conversion Patterns:
PatternBefore ConversionAfter Conversion
Alias Integration
"build": "npm run build:app"
+
"build:app": "A && B"
"build": "A && B"
Pre-hook Explicitization
"prebuild": "npm run X"
+
"build": "Y"
"build": "npm run X && Y"
Passthrough Removal
"lint": "eslint"
Remove (either call
eslint
directly or eliminate if unnecessary)
Naming Unification
"e2e": "playwright test"
"test:e2e": "playwright test"
Determine which package manager (
npm run
/
yarn
/
pnpm run
) is being used from the
package.json
or the presence of lockfiles, and use the appropriate one.

4. ドキュメントの更新確認

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.md
    /
    AGENTS.md
  • Workflow files under
    .github/workflows/
  • Documents under
    docs/

5. 依存削除後のロックファイル再生成

5. Regenerate Lock Files After Dependency Removal

依存パッケージを削除した場合は、
node_modules
とロックファイルを削除してから install を実行する。
bash
undefined
If dependency packages are removed, delete
node_modules
and the lockfile, then run install.
bash
undefined

npm

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
undefined
rm -rf node_modules pnpm-lock.yaml && pnpm install
undefined

注意事項

Notes

  • pre フックの削除:
    preX
    フックを削除して明示的に呼び出す形にすると、そのスクリプトを単独で呼んだときも(意図しない)フックが走らなくなる。動作変更を伴うため、ユーザーに確認してから変換する。
  • スクリプト名の変更: CI やドキュメントで参照されているスクリプト名を変更する場合は、必ず参照先も合わせて更新する。
  • ネイティブ連携パッケージ: Tauri / Electron など、ネイティブ層との橋渡しをする npm パッケージは JS 側の import がなくても実際には必要なことがある。ランタイム要件を確認してから削除する。
  • 間接依存:
    dependencies
    に書かれていても直接 import していない場合がある(例: Babel プラグイン、ESLint プリセットなど設定ファイル経由で参照されるもの)。削除前にビルド・テストで確認する。
  • Removing Pre-hooks: If you remove
    preX
    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.
  • 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
    dependencies
    , some packages may not be imported directly (e.g., Babel plugins, ESLint presets referenced via configuration files). Confirm via build/test before deleting.