@anolilab/semantic-release-clean-package-json

中文文档
5.5.29发布于 2026/11/03MITTypeScriptES Module构建来源已验证近 30 天下载 7.6万

Clean package.json before publish by removing unnecessary properties.

原始使用文档
文档目录13 节
  1. Clean package.json before publish by removing unnecessary p…
  2. Why?
  3. Install
  4. Usage
  5. Steps that are used
  6. Options
  7. Examples
  8. Default preserved properties
  9. Supported Node.js Versions
  10. Contributing
  11. Credits
  12. Made with ❤️ at Anolilab
  13. License
semantic-release-clean-package-json

Clean package.json before publish by removing unnecessary properties.


typescript-image mit licence npm downloads Chat PRs Welcome


Daniel Bannert's open source work is supported by the community on GitHub Sponsors


Why?

When publishing packages to npm, many properties in package.json are only needed during development and build time, but not in the published package. This plugin automatically removes unnecessary properties while preserving essential ones needed for the package to work correctly in production.

Key benefits:

  • Reduces package size by removing development-only properties
  • Prevents leaking internal configuration and metadata
  • Maintains a clean and focused package.json for end users
  • Customizable property preservation through configuration

Install

npm install @anolilab/semantic-release-clean-package-json
yarn add @anolilab/semantic-release-clean-package-json
pnpm add @anolilab/semantic-release-clean-package-json

Usage

The plugin can be configured in the semantic-release configuration file:

[!IMPORTANT] Very important: The plugin must be placed before the @semantic-release/github or @semantic-release/git and before @anolilab/semantic-release-pnpm or @semantic-release/npm plugin otherwise the package.json will be cleaned and published into GitHub / Your Git Provider.

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        "@anolilab/semantic-release-clean-package-json",
        "@anolilab/semantic-release-pnpm",
        "@semantic-release/github"
    ]
}

Steps that are used

StepDescription
publish- Creates a backup of the original package.json file
- Removes all non-preserved properties from package.json
- Keeps properties specified in the default list and custom keep option
- Preserves specific npm scripts if they are in the keep list
- Writes the cleaned package.json file
success- Restores the original package.json from backup
- Updates the version number to match the released version
- Removes the backup file
- Logs success or error messages

Options

OptionsDescriptionDefault
pkgRootDirectory path to publish..
keepProperty names to keep.[]

Note: The pkgRoot directory must contain a package.json. The version will be updated only in the package.json and npm-shrinkwrap.json within the pkgRoot directory.

Note: If you use a shareable configuration that defines one of these options you can set it to false in your semantic-release configuration in order to use the default value.

Examples

The plugin can be configured with custom properties to keep in addition to the default preserved ones:

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "@anolilab/semantic-release-clean-package-json",
            {
                "keep": ["custom field"]
            }
        ],
        "@anolilab/semantic-release-pnpm",
        "@semantic-release/github"
    ]
}

Example: Publishing a TypeScript Package

When publishing a TypeScript package, you might want to keep TypeScript-specific fields:

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "@anolilab/semantic-release-clean-package-json",
            {
                // This are the default values, just a example
                "keep": ["types", "typings", "typesVersions", "module"],
            },
        ],
        "@anolilab/semantic-release-pnpm",
        "@semantic-release/github",
    ],
}

Example: Custom Package Root

If your package.json is not in the root directory:

{
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        "@semantic-release/github",
        [
            "@anolilab/semantic-release-clean-package-json",
            {
                "pkgRoot": "dist"
            }
        ],
        "@anolilab/semantic-release-pnpm"
    ]
}

Default preserved properties

By default, these properties are preserved in package.json:

npm

  • name
  • version
  • private
  • publishConfig
  • scripts.preinstall
  • scripts.install
  • scripts.postinstall
  • scripts.dependencies
  • files
  • bin
  • browser
  • main
  • man
  • dependencies
  • peerDependencies
  • peerDependenciesMeta
  • bundledDependencies
  • optionalDependencies
  • engines
  • os
  • cpu
  • description
  • keywords
  • author
  • contributors
  • license
  • homepage
  • repository
  • bugs
  • funding

CDNs

Node.js

  • type
  • exports
  • imports

VSCode Extension Manifest

  • publisher
  • displayName
  • categories
  • galleryBanner
  • preview
  • contributes
  • activationEvents
  • badges
  • markdown
  • qna
  • sponsor
  • extensionPack
  • extensionDependencies
  • extensionKind
  • icon

Angular Package Format

  • fesm2020
  • fesm2015
  • esm2020
  • es2020

TypeScript

  • types
  • typings
  • typesVersions

Bundlers (Webpack, Rollup, esbuild)

Supported Node.js Versions

Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.

Contributing

If you would like to help take a look at the list of issues and check our Contributing guidelines.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

Made with ❤️ at Anolilab

This is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. Anolilab is a Development and AI Studio. Contact us at [email protected] if you need any help with these technologies or just want to say hi!

License

The anolilab semantic-release-clean-package-json is open-sourced software licensed under the MIT

版本与发布记录

@anolilab/semantic-release-clean-package-json 共发布 62 个版本,首次发布于 2025/01/15;过去 12 个月发布了 43 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.5.29latest2026/11/033 天前
5.5.282026/10/041 个月前
5.5.272026/09/261 个月前
5.5.262026/09/261 个月前
5.5.252026/09/221 个月前
5.5.242026/09/221 个月前

其他发布通道:alpha → 4.2.3-alpha.2。

关于 @anolilab/semantic-release-clean-package-json 的常见问题

@anolilab/semantic-release-clean-package-json 是什么?

Clean package.json before publish by removing unnecessary properties.

如何安装 @anolilab/semantic-release-clean-package-json?

在项目目录运行 npm install @anolilab/semantic-release-clean-package-json,或使用 pnpm add / yarn add / bun add。

@anolilab/semantic-release-clean-package-json 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anolilab/semantic-release-clean-package-json 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@anolilab/semantic-release-clean-package-json 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.14.0 || >=24.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anolilab/semantic-release-clean-package-json 可以商用吗?

@anolilab/semantic-release-clean-package-json 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@anolilab/semantic-release-clean-package-json 的下载量有多少?

根据 npm 官方下载统计,@anolilab/semantic-release-clean-package-json 在 2026/10/06 – 2026/11/04 这 30 天内被下载 75,866 次,日均约 2,529 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anolilab/semantic-release-clean-package-json 还在维护吗?

最新版本 5.5.29 发布于 2026/11/03(3 天前);至今共发布 62 个版本,其中过去 12 个月发布了 43 个;首次发布于 2025/01/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。