{"id":13847195,"url":"https://github.com/privatenumber/clean-pkg-json","last_synced_at":"2026-04-20T14:01:38.172Z","repository":{"id":43599679,"uuid":"511285383","full_name":"privatenumber/clean-pkg-json","owner":"privatenumber","description":"Script to remove unnecessary properties from package.json on prepublish hook","archived":false,"fork":false,"pushed_at":"2026-03-21T18:06:14.000Z","size":226,"stargazers_count":69,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2026-03-30T04:27:53.857Z","etag":null,"topics":["clean","hook","npm","package-json","prepublish"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/privatenumber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"privatenumber"}},"created_at":"2022-07-06T20:39:41.000Z","updated_at":"2026-03-21T18:05:46.000Z","dependencies_parsed_at":"2025-05-18T12:05:48.917Z","dependency_job_id":"4988a643-861f-4f61-a734-3749b558f705","html_url":"https://github.com/privatenumber/clean-pkg-json","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/privatenumber/clean-pkg-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fclean-pkg-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fclean-pkg-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fclean-pkg-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fclean-pkg-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/privatenumber","download_url":"https://codeload.github.com/privatenumber/clean-pkg-json/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/privatenumber%2Fclean-pkg-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31229940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-31T09:14:28.471Z","status":"ssl_error","status_checked_at":"2026-03-31T09:14:19.506Z","response_time":111,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean","hook","npm","package-json","prepublish"],"created_at":"2024-08-04T18:01:12.834Z","updated_at":"2026-04-20T14:01:38.165Z","avatar_url":"https://github.com/privatenumber.png","language":"TypeScript","funding_links":["https://github.com/sponsors/privatenumber"],"categories":["TypeScript"],"sub_categories":[],"readme":"# clean-pkg-json\n\nOnly publish necessary `package.json` properties.\n\n\u003csub\u003eSupport this project by ⭐️ starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️\u003c/sub\u003e\n\n## Example\n\nGiven a `package.json` with dev configs, scripts, and devDependencies:\n\n```json\n{\n    \"name\": \"my-package\",\n    \"version\": \"1.0.0\",\n    \"description\": \"A useful package\",\n    \"type\": \"module\",\n    \"main\": \"dist/index.js\",\n    \"types\": \"dist/index.d.ts\",\n    \"files\": [\n        \"dist\"\n    ],\n    \"scripts\": {\n        \"build\": \"pkgroll\",\n        \"lint\": \"eslint .\",\n        \"test\": \"vitest\",\n        \"prepack\": \"clean-pkg-json\"\n    },\n    \"dependencies\": {\n        \"lodash\": \"^4.0.0\"\n    },\n    \"devDependencies\": {\n        \"pkgroll\": \"^2.0.0\",\n        \"vitest\": \"^1.0.0\",\n        \"clean-pkg-json\": \"^1.0.0\"\n    },\n    \"eslintConfig\": {\n        \"extends\": [\n            \"@pvtnbr\"\n        ]\n    },\n    \"lint-staged\": {\n        \"*.ts\": \"eslint --fix\"\n    },\n    \"simple-git-hooks\": {\n        \"pre-commit\": \"npx lint-staged\"\n    }\n}\n```\n\nRunning `clean-pkg-json` produces:\n\n```json\n{\n    \"name\": \"my-package\",\n    \"version\": \"1.0.0\",\n    \"description\": \"A useful package\",\n    \"type\": \"module\",\n    \"main\": \"dist/index.js\",\n    \"types\": \"dist/index.d.ts\",\n    \"files\": [\n        \"dist\"\n    ],\n    \"dependencies\": {\n        \"lodash\": \"^4.0.0\"\n    }\n}\n```\n\n## How it works\n\nUses an allowlist to preserve only [properties relevant to package consumers](#default-preserved-properties), everything else is removed.\n\nFor `scripts`, only install hooks (`preinstall`, `install`, `postinstall`, `dependencies`) are preserved. All other scripts are removed.\n\nFor `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.\n\n## Install\n\n```sh\nnpm install -D clean-pkg-json\n```\n\n## Setup\n\nAdd `clean-pkg-json` to the [`prepack`](https://docs.npmjs.com/cli/v8/using-npm/scripts#:~:text=on%20npm%20publish.-,prepack,-Runs%20BEFORE%20a) script, which runs before `npm publish` and `npm pack`:\n\n```json5\n// package.json\n{\n    \"scripts\": {\n        \"prepack\": \"clean-pkg-json\",\n    },\n}\n```\n\nWhen 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.\n\n### Flags\n\n| Flag | Description |\n| - | - |\n| `-k, --keep \u003cproperty name\u003e` | Property names to keep. Accepts multiple flags or a comma-delimited list. |\n| `-r, --remove \u003cproperty name\u003e` | Property names to remove. Accepts multiple flags or a comma-delimited list. |\n| `-v, --verbose` | Verbose logs. |\n| `-d, --dry` | Dry run — prints the result instead of writing to disk. |\n| `--published-only=false` | Disable pruning of unpublished paths in `exports` and `imports`. |\n| `-h, --help` | Show help |\n| `--version` | Show version |\n\n## Default preserved properties\n\n\u003cdetails\u003e\n\u003csummary\u003eView full list\u003c/summary\u003e\n\n### [npm](https://docs.npmjs.com/cli/v8/configuring-npm/package-json)\n- `name`\n- `version`\n- `private`\n- `publishConfig`\n- `scripts.preinstall`\n- `scripts.install`\n- `scripts.postinstall`\n- `scripts.dependencies`\n- `files`\n- `bin`\n- `browser`\n- `main`\n- `man`\n- `dependencies`\n- `peerDependencies`\n- `peerDependenciesMeta`\n- `bundledDependencies`\n- `optionalDependencies`\n- `engines`\n- `os`\n- `cpu`\n- `description`\n- `keywords`\n- `author`\n- `maintainers`\n- `contributors`\n- `license`\n- `homepage`\n- `repository`\n- `bugs`\n- `funding`\n\n### CDNs\n- [`jsdelivr`](https://www.jsdelivr.com/documentation#id-configuring-a-default-file-in-packagejson)\n- [`unpkg`](https://unpkg.com/)\n\n### [Node.js](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions)\n- `type`\n- `exports`\n- `imports`\n\n### [VSCode Extension Manifest](https://code.visualstudio.com/api/references/extension-manifest)\n- `sponsor`\n- `publisher`\n- `displayName`\n- `categories`\n- `galleryBanner`\n- `preview`\n- `contributes`\n- `activationEvents`\n- `badges`\n- `markdown`\n- `qna`\n- `extensionPack`\n- `extensionDependencies`\n- `extensionKind`\n- `icon`\n\n### [Angular Package Format](https://angular.dev/tools/libraries/angular-package-format)\n- `fesm2022`\n- `fesm2020`\n- `fesm2015`\n- `esm2020`\n- `es2020`\n\n### [TypeScript](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)\n- `types`\n- `typings`\n- `typesVersions`\n\n### Bundlers (Webpack, Rollup, esbuild)\n- [`module`](https://stackoverflow.com/questions/42708484/what-is-the-module-package-json-field-for)\n- [`sideEffects`](https://webpack.js.org/guides/tree-shaking/)\n\n\u003c/details\u003e\n\n## Agent Skills\n\nThis package ships with [agent skills](https://agentskills.io) for AI coding assistants. Set up [`skills-npm`](https://github.com/antfu/skills-npm) to use them.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivatenumber%2Fclean-pkg-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprivatenumber%2Fclean-pkg-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprivatenumber%2Fclean-pkg-json/lists"}