
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
clean-pkg-json
Advanced tools
Only publish necessary package.json properties.
Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️
Given a package.json with dev configs, scripts, and devDependencies:
{
"name": "my-package",
"version": "1.0.0",
"description": "A useful package",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "pkgroll",
"lint": "eslint .",
"test": "vitest",
"prepack": "clean-pkg-json"
},
"dependencies": {
"lodash": "^4.0.0"
},
"devDependencies": {
"pkgroll": "^2.0.0",
"vitest": "^1.0.0",
"clean-pkg-json": "^1.0.0"
},
"eslintConfig": {
"extends": [
"@pvtnbr"
]
},
"lint-staged": {
"*.ts": "eslint --fix"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
}
}
Running clean-pkg-json produces:
{
"name": "my-package",
"version": "1.0.0",
"description": "A useful package",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"lodash": "^4.0.0"
}
}
Uses an allowlist to preserve only properties relevant to package consumers, everything else is removed.
For scripts, only install hooks (preinstall, install, postinstall, dependencies) are preserved. All other scripts are removed.
For exports and imports, entries referencing files not included in the published package are pruned. This prevents consumers from resolving to non-existent source files. Conditional entries are partially pruned — only unpublished branches are removed. Pass --published-only=false to disable this behavior.
npm install -D clean-pkg-json
Add clean-pkg-json to the prepack script, which runs before npm publish and npm pack:
// package.json
{
"scripts": {
"prepack": "clean-pkg-json",
},
}
When invoked via npm pack --dry-run or npm publish --dry-run, clean-pkg-json auto-detects npm's dry-run mode (via the npm_config_dry_run env var) and skips writing to disk.
| Flag | Description |
|---|---|
-k, --keep <property name> | Property names to keep. Accepts multiple flags or a comma-delimited list. |
-r, --remove <property name> | Property names to remove. Accepts multiple flags or a comma-delimited list. |
-v, --verbose | Verbose logs. |
-d, --dry | Dry run — prints the result instead of writing to disk. |
--published-only=false | Disable pruning of unpublished paths in exports and imports. |
-h, --help | Show help |
--version | Show version |
nameversionprivatepublishConfigscripts.preinstallscripts.installscripts.postinstallscripts.dependenciesfilesbinbrowsermainmandependenciespeerDependenciespeerDependenciesMetabundledDependenciesoptionalDependenciesenginesoscpudescriptionkeywordsauthormaintainerscontributorslicensehomepagerepositorybugsfundingtypeexportsimportssponsorpublisherdisplayNamecategoriesgalleryBannerpreviewcontributesactivationEventsbadgesmarkdownqnaextensionPackextensionDependenciesextensionKindiconfesm2022fesm2020fesm2015esm2020es2020typestypingstypesVersionsThis package ships with agent skills for AI coding assistants. Set up skills-npm to use them.
FAQs
Clean package.json before publish by removing unnecessary properties
The npm package clean-pkg-json receives a total of 3,408 weekly downloads. As such, clean-pkg-json popularity was classified as popular.
We found that clean-pkg-json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.