nodejs-package-json
Patch a Node.js project's package.json for standard build automation. Use when asked to add/standardize package.json scripts like prebuild/postbuild for TypeScript builds (rimraf dist + tsc-alias), adjust prebuild for Next.js (rimraf dist .next), or ensure an existing package.json pkg config includes required scripts/assets/targets/outputPath.
When & Why to Use This Skill
This Claude skill automates the standardization of Node.js build processes by patching `package.json` files. It ensures projects follow best practices for build automation, specifically handling TypeScript path aliasing, Next.js build cleanup, and executable packaging configurations to reduce manual setup errors and improve CI/CD reliability.
Use Cases
- Standardizing Build Pipelines: Automatically adding prebuild and postbuild scripts to ensure a clean build environment using rimraf and tsc-alias.
- Next.js Project Optimization: Configuring specialized cleanup scripts that target both the 'dist' and '.next' directories to prevent stale build artifacts.
- Binary Distribution Setup: Validating and patching the 'pkg' configuration object to ensure all necessary assets, targets, and output paths are correctly defined for standalone executable generation.
- TypeScript Path Resolution: Streamlining the integration of tsc-alias into the build workflow to resolve module aliases in compiled output, preventing runtime import errors.
| name | nodejs-package-json |
|---|---|
| description | Patch a Node.js project's package.json for standard build automation. Use when asked to add/standardize package.json scripts like prebuild/postbuild for TypeScript builds (rimraf dist + tsc-alias), adjust prebuild for Next.js (rimraf dist .next), or ensure an existing package.json pkg config includes required scripts/assets/targets/outputPath. |
Node.js package.json
Goal
Quickly and safely update package.json to include:
scripts.prebuild:rimraf dist(orrimraf dist .nextfor Next.js)scripts.postbuild:tsc-alias- If
pkgconfig exists: ensurescripts/assets/targets/outputPathcontain required entries
Workflow
Run the patcher (auto-detects Next.js):
python3 "${CODEX_HOME:-$HOME/.codex}/skills/nodejs-package-json/scripts/patch_package_json.py" --path package.json
If Next.js auto-detection is wrong, force it:
- Force Next.js:
--nextjs true - Force non-Next.js:
--nextjs false
- Force Next.js:
If
prebuildorpostbuildalready exist with different values:- Re-run with
--forceto overwrite to the recommended defaults.
- Re-run with
Notes
- This skill edits
package.jsononly; it does not install dependencies. Ensurerimrafandtsc-aliasare available (typically asdevDependencies). - The patcher only edits
pkgsettings if a top-levelpkgobject already exists (it does not add one).