@anolilab/semantic-release-clean-package-json v2.0.3
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 thepackage.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
Step | Description |
---|---|
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
Options | Description | Default |
---|---|---|
pkgRoot | Directory path to publish. | . |
keep | Property 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
License
The anolilab semantic-release-clean-package-json is open-sourced software licensed under the MIT
4 months ago
5 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago