clean-pkg-json
Publishes only consumer-relevant package.json properties using an allowlist.
Setup
{
"scripts": {
"prepack": "clean-pkg-json"
}
}
When chaining with other prepack commands:
{
"scripts": {
"prepack": "pnpm build && clean-pkg-json"
}
}
Flags
| Flag |
Description |
Example |
-k, --keep |
Preserve additional properties |
clean-pkg-json -k eslintConfig,devDependencies |
-r, --remove |
Drop default-kept properties |
clean-pkg-json -r scripts.postinstall |
-d, --dry |
Preview result without writing to disk |
clean-pkg-json --dry |
-v, --verbose |
Log details about which properties are preserved |
clean-pkg-json --verbose |
Both --keep and --remove accept multiple flags (-k foo -k bar) or comma-delimited lists (-k foo,bar).
Use --dry to preview changes before writing.
npm pack --dry-run and npm publish --dry-run are also auto-detected (via npm_config_dry_run) — no write happens when npm itself is in dry-run mode.
Behavior
The tool reads ./package.json in the current directory, keeps only allowlisted properties, and writes the result back in place.
Scripts Handling
Scripts use dot-notation in the allowlist. Only install hooks are preserved by default:
scripts.preinstall
scripts.install
scripts.postinstall
scripts.dependencies
To preserve additional scripts:
clean-pkg-json --keep scripts.prepare
If no scripts remain after filtering, the scripts key itself is omitted.
Default Allowlist
| Category |
Properties |
| npm required |
name, version, private, publishConfig |
| Entry points |
main, bin, browser, man, files |
| Dependencies |
dependencies, peerDependencies, peerDependenciesMeta, bundledDependencies, optionalDependencies |
| Node.js ESM |
type, exports, imports |
| Environment |
engines, os, cpu |
| Metadata |
description, keywords, author, maintainers, contributors, license, homepage, repository, bugs, funding |
| TypeScript |
types, typings, typesVersions |
| Bundlers |
module, sideEffects |
| CDNs |
jsdelivr, unpkg |
| VSCode extensions |
sponsor, publisher, displayName, categories, galleryBanner, preview, contributes, activationEvents, badges, markdown, qna, extensionPack, extensionDependencies, extensionKind, icon |
| Angular |
fesm2022, fesm2020, fesm2015, esm2020, es2020 |
1---2name: clean-pkg-json3description: Cleans package.json for npm publishing using an allowlist approach — preserves only consumer-relevant properties. Use when setting up prepack hooks, configuring npm publish workflows, or working with clean-pkg-json flags.4metadata:5 source: https://skillmd.com/skills/privatenumber/clean-pkg-json6---78# clean-pkg-json910Publishes only consumer-relevant `package.json` properties using an allowlist.1112## Setup1314```json15{16 "scripts": {17 "prepack": "clean-pkg-json"18 }19}20```2122When chaining with other prepack commands:2324```json25{26 "scripts": {27 "prepack": "pnpm build && clean-pkg-json"28 }29}30```3132## Flags3334| Flag | Description | Example |35|------|-------------|---------|36| `-k, --keep` | Preserve additional properties | `clean-pkg-json -k eslintConfig,devDependencies` |37| `-r, --remove` | Drop default-kept properties | `clean-pkg-json -r scripts.postinstall` |38| `-d, --dry` | Preview result without writing to disk | `clean-pkg-json --dry` |39| `-v, --verbose` | Log details about which properties are preserved | `clean-pkg-json --verbose` |4041Both `--keep` and `--remove` accept multiple flags (`-k foo -k bar`) or comma-delimited lists (`-k foo,bar`).4243Use `--dry` to preview changes before writing.4445`npm pack --dry-run` and `npm publish --dry-run` are also auto-detected (via `npm_config_dry_run`) — no write happens when npm itself is in dry-run mode.4647## Behavior4849The tool reads `./package.json` in the current directory, keeps only allowlisted properties, and writes the result back in place.5051### Scripts Handling5253Scripts use dot-notation in the allowlist. Only install hooks are preserved by default:5455- `scripts.preinstall`56- `scripts.install`57- `scripts.postinstall`58- `scripts.dependencies`5960To preserve additional scripts:6162```sh63clean-pkg-json --keep scripts.prepare64```6566If no scripts remain after filtering, the `scripts` key itself is omitted.6768## Default Allowlist6970| Category | Properties |71|----------|------------|72| npm required | `name`, `version`, `private`, `publishConfig` |73| Entry points | `main`, `bin`, `browser`, `man`, `files` |74| Dependencies | `dependencies`, `peerDependencies`, `peerDependenciesMeta`, `bundledDependencies`, `optionalDependencies` |75| Node.js ESM | `type`, `exports`, `imports` |76| Environment | `engines`, `os`, `cpu` |77| Metadata | `description`, `keywords`, `author`, `maintainers`, `contributors`, `license`, `homepage`, `repository`, `bugs`, `funding` |78| TypeScript | `types`, `typings`, `typesVersions` |79| Bundlers | `module`, `sideEffects` |80| CDNs | `jsdelivr`, `unpkg` |81| VSCode extensions | `sponsor`, `publisher`, `displayName`, `categories`, `galleryBanner`, `preview`, `contributes`, `activationEvents`, `badges`, `markdown`, `qna`, `extensionPack`, `extensionDependencies`, `extensionKind`, `icon` |82| Angular | `fesm2022`, `fesm2020`, `fesm2015`, `esm2020`, `es2020` |