{"id":16747480,"url":"https://github.com/roydukkey/clean-package","last_synced_at":"2025-07-04T17:02:07.856Z","repository":{"id":46161118,"uuid":"285861032","full_name":"roydukkey/clean-package","owner":"roydukkey","description":"Remove configuration keys from 'package.json' before creating an NPM package.","archived":false,"fork":false,"pushed_at":"2024-11-08T20:38:11.000Z","size":197,"stargazers_count":41,"open_issues_count":7,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T07:04:19.053Z","etag":null,"topics":["clean","npm","npm-script","pack","publish"],"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/roydukkey.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["roydukkey"]}},"created_at":"2020-08-07T15:22:25.000Z","updated_at":"2025-02-16T14:28:32.000Z","dependencies_parsed_at":"2024-06-18T16:53:27.143Z","dependency_job_id":"fc4adcb2-9eb3-406c-bd58-61e03aaef4c4","html_url":"https://github.com/roydukkey/clean-package","commit_stats":{"total_commits":70,"total_committers":3,"mean_commits":"23.333333333333332","dds":0.0714285714285714,"last_synced_commit":"a03da14f3c9cb6fae61807ec299bc724d2ecd905"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydukkey%2Fclean-package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydukkey%2Fclean-package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydukkey%2Fclean-package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roydukkey%2Fclean-package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roydukkey","download_url":"https://codeload.github.com/roydukkey/clean-package/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305933,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","npm","npm-script","pack","publish"],"created_at":"2024-10-13T02:10:07.024Z","updated_at":"2025-04-05T08:05:17.355Z","avatar_url":"https://github.com/roydukkey.png","language":"TypeScript","funding_links":["https://github.com/sponsors/roydukkey"],"categories":[],"sub_categories":[],"readme":"# Clean Package\n\nThis `clean-package` tool is used for removing development configuration from 'package.json' before publishing the package to NPM.\n\n[![Release Version](https://img.shields.io/npm/v/clean-package.svg)](https://www.npmjs.com/package/clean-package)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n\n## Install\n\n```bash\nnpm install clean-package --save-dev\n```\n\n\n## Integrated Usage\n\nThe `clean-package` tool works directly on the 'package.json' file, to avoid breaking the NPM lifecycle. This allows you to add a script to the 'package.json' to clean the file during packing.\n\n```json\n{\n  \"name\": \"my-package\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"prepack\": \"clean-package\",\n    \"postpack\": \"clean-package restore\"\n  }\n}\n```\n\nWhen the \"prepack\" script executes, a backup of the original `package.json` will be created. Ensure this file doesn't make it into your release package.\n\nOne way to accomplish this is to add the following to your `.npmignore` file:\n\n```ignore\n*.backup\n```\n\nSee [CLI Usage](#command-line-usage 'Command Line Usage') for independent usage instructions.\n\n#### JSON Configuration Files\n\nOptions can be configured in `clean-package.config.json` at the root of your project (where the `package.json` is).\n\n```json\n{\n  \"indent\": 2,\n  \"remove\": [\n    \"eslintConfig\",\n    \"jest\"\n  ]\n}\n```\n\nAlternatively, you can choose to specify your configuration from within `package.json` using the `clean-package` key like so:\n\n```js\n{\n  \"name\": \"my-package\",\n  \"version\": \"1.0.0\",\n  \"clean-package\": {\n    \"indent\": 2,\n    \"remove\": [\n      \"eslintConfig\",\n      \"jest\"\n    ]\n  },\n\n  // Or, a file path to a configuration.\n  \"clean-package\": \"./build/clean-package.config.js\"\n}\n```\n\n#### JavaScript Configuration File\n\nYou can also create the configuration using JavaScript in the `clean-package.config.?(c|m)js` at the root of your project:\n\n```js\nmodule.exports = {\n  indent: '\\t',\n  replace: {\n    'config.port': '8080'\n  }\n};\n```\n\n\n### Options\n\n\u003cdl\u003e\n\n  \u003cdt\u003ebackupPath\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003eString\u003c/code\u003e\u003cbr /\u003e\n    \u003cem\u003eDefault:\u003c/em\u003e \u003ccode\u003e'./package.json.backup'\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003eSpecifies the location and filename to which the \u003ccode\u003epackage.json\u003c/code\u003e will be backed up.\u003c/dd\u003e\n\n  \u003cdt\u003eindent\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003eString | Number\u003c/code\u003e\u003cbr /\u003e\n    \u003cem\u003eDefault:\u003c/em\u003e \u003ccode\u003e2\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003e\n    Defines the indentation that's used to format the cleaned \u003ccode\u003epackage.json\u003c/code\u003e. See the \u003ccode\u003espace\u003c/code\u003e parameter of \u003ccode\u003eJSON.stringify\u003c/code\u003e for \u003ca href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters\"\u003emore information\u003c/a\u003e.\n  \u003c/dd\u003e\n\n  \u003cdt\u003eremove\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003eString[] | (keys: String[]) =\u003e String[]\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003e\n    \u003cp\u003eSpecifies the keys to be removed from the cleaned \u003ccode\u003epackage.json\u003c/code\u003e; otherwise, \u003ccode\u003enull\u003c/code\u003e when nothing is to be removed.\u003c/p\u003e\n    \u003cp\u003eDeeper keys can be accessed using a dot (e.g., \u003ccode\u003e'key.keyInsideKey'\u003c/code\u003e). Likewise, arrays are accessible using brackets (e.g., \u003ccode\u003e'key.arrKey[0]'\u003c/code\u003e).\u003c/p\u003e\n    \u003cp\u003eTo remove keys that contain a dot, the dot must be escaped. For example, \u003ccode\u003e'exports.\\\\.'\u003c/code\u003e will target \u003ccode\u003e\"exports\": { \".\" }\u003c/code\u003e\u003c/p\u003e\n  \u003c/dd\u003e\n\n  \u003cdt\u003ereplace\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003eObject | (pairs: Object) =\u003e Object\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003e\n    \u003cp\u003eSpecifies the keys to be replaced in the cleaned \u003ccode\u003epackage.json\u003c/code\u003e; otherwise, \u003ccode\u003enull\u003c/code\u003e when nothing is to be replaced.\u003c/p\u003e\n    \u003cp\u003eDeeper keys and arrays are accessible in the same manner and allow dot escaping. Additionally, the replaced keys may receive any valid JSON value, including objects.\u003c/p\u003e\n  \u003c/dd\u003e\n\n  \u003cdt\u003eextends\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003eString | String[]\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003e\n    \u003cp\u003eSpecifies the name/s of a shareable configuration.\u003c/p\u003e\n    \u003cp\u003eThis package \u003ca href=\"https://github.com/roydukkey/clean-package/blob/master/common.js\"\u003eshares a configuration\u003c/a\u003e with common settings that can be extended from \u003ccode\u003eclean-package/common\u003c/code\u003e.\n  \u003c/dd\u003e\n\n  \u003cdt\u003eonClean\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003e(hasChanged: boolean, config: CompiledConfig) =\u003e void\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003eNotified after the \u003ccode\u003epackage.json\u003c/code\u003e has been cleaned, supplied with an indication as to whether there were changes and the compiled configuration.\u003c/dd\u003e\n\n  \u003cdt\u003eonRestore\u003c/dt\u003e\n  \u003cdd\u003e\n    \u003cem\u003eType:\u003c/em\u003e \u003ccode\u003e(hasChanged: boolean, config: CompiledConfig) =\u003e void\u003c/code\u003e\n  \u003c/dd\u003e\n  \u003cdd\u003eNotified after the \u003ccode\u003epackage.json\u003c/code\u003e has been restored, supplied with an indication as to whether there were changes and the compiled configuration.\u003c/dd\u003e\n\n\u003c/dl\u003e\n\n## Command Line Usage\n\n```\nclean-package [[\u003csource-path\u003e] \u003cbackup-path\u003e] [\u003coption\u003e...]\n\nwhere \u003coption\u003e is one of:\n\n  -c,  --config \u003cpath\u003e                  Specify the path to a configuration file.\n\n  -e,  --extends \u003cname\u003e...              Specify the name to a shareable configuration. (e.g. 'clean-package/common')\n\n  -i,  --indent \u003cvalue\u003e                 Specify the indentation, overriding configuration from file.\n\n  -rm, --remove \u003ckey\u003e...                Specify the keys to remove, overriding configuration from file.\n\n       --remove-add \u003ckey\u003e...            Same as --remove without overriding configuration from file.\n\n  -r,  --replace \u003ckey\u003e=\u003cvalue\u003e...       Specify the keys to replace, overriding configuration from file.\n\n       --replace-add \u003ckey\u003e=\u003cvalue\u003e...   Same as --replace without overriding configuration from file.\n\n       --print-config                   Print the combined configuration without executing command.\n\n  -v,  --version                        Print the version number\n```\n\n```\nclean-package restore [[\u003csource-path\u003e] \u003cbackup-path\u003e] [\u003coption\u003e...]\n\nalias: r\n\nwhere \u003coption\u003e is one of:\n\n  -c,  --config \u003cpath\u003e                  Specify the path to a configuration file.\n\n  -e,  --extends \u003cname\u003e...              Specify the name to a shareable configuration. (e.g. 'clean-package/common')\n\n       --print-config                   Print the combined configuration without executing command.\n```\n\n## Usage in Code\n\nShould you desire, it is also possible to interface this package through code. Simply import the package like any other.\n\n```ts\nimport { load, clean, restore, version } from 'clean-package';\n```\n\n## Troubleshooting\n\n### How do I remove package scripts and use `clean-package restore`?\n\nIf you're integrating `clean-package` into the NPM lifecycle, removing all the `package.json` scripts with `clean-package` will also remove them from the current execution. This is just how NPM works.\n\nFor example, this configuration will remove the `postpack` script before it is ever requested by `npm pack` or `npm publish`, thereby effectively removing the event from the executing lifecycle.\n\n```json\n{\n  \"scripts\": {\n    \"prepack\": \"clean-package\",\n    \"postpack\": \"clean-package restore\"\n  },\n  \"clean-package\": {\n    \"remove\": [\n      \"clean-package\",\n      \"scripts\"\n    ]\n  }\n}\n```\n\nThere are multiple ways to work around this (more than are offered here). One solution might be to manually run the command with `npx clean-package restore`. Another might be to define a custom script that would call `pack` and `clean-package` in sequence:\n\n```json\n{\n  \"scripts\": {\n    \"prepack\": \"clean-package\",\n    \"new:pack\": \"npm pack \u0026\u0026 clean-package restore\",\n    \"new:publish\": \"npm publish \u0026\u0026 clean-package restore\"\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froydukkey%2Fclean-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froydukkey%2Fclean-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froydukkey%2Fclean-package/lists"}