@anolilab/semantic-release-clean-package-json 1.0.1-alpha.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -15
- package/README.md +67 -10
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
## @anolilab/semantic-release-clean-package-json [
|
|
1
|
+
## @anolilab/semantic-release-clean-package-json [2.0.0](https://github.com/anolilab/semantic-release/compare/@anolilab/semantic-release-clean-package-json@1.0.0...@anolilab/semantic-release-clean-package-json@2.0.0) (2025-01-22)
|
|
2
2
|
|
|
3
|
-
###
|
|
4
|
-
|
|
5
|
-
* fixed tests ([3efe795](https://github.com/anolilab/semantic-release/commit/3efe7952ee91a765fa281a17b17d122efc8c22a3))
|
|
6
|
-
* **semantic-release-clean-package-json:** try the new backup script ([e738d31](https://github.com/anolilab/semantic-release/commit/e738d3173499e96591b5b33cc3f12b1a8fb8546f))
|
|
7
|
-
|
|
8
|
-
### Reverts
|
|
9
|
-
|
|
10
|
-
* Revert "chore(release): @anolilab/semantic-release-clean-package-json@1.0.1-alpha.2 [skip ci]\n\n## @anolilab/semantic-release-clean-package-json [1.0.1-alpha.2](https://github.com/anolilab/semantic-release/compare/@anolilab/semantic-release-clean-package-json@1.0.1-alpha.1...@anolilab/semantic-release-clean-package-json@1.0.1-alpha.2) (2025-01-21)" ([81af859](https://github.com/anolilab/semantic-release/commit/81af859f7c07cb9c7344084243b0412230423ce4))
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
11
4
|
|
|
12
|
-
|
|
5
|
+
* **semantic-release-clean-package-json:** Changed plugin steps to publish and success from prepare
|
|
13
6
|
|
|
14
7
|
### Bug Fixes
|
|
15
8
|
|
|
16
|
-
* **semantic-release-clean-package-json:**
|
|
9
|
+
* **semantic-release-clean-package-json:** reworked this plugin to use the `publish` and `success` functions, to have the correct state on git ([#112](https://github.com/anolilab/semantic-release/issues/112)) ([734d48a](https://github.com/anolilab/semantic-release/commit/734d48a6c5a386a7ceecef5e84d758eb63708fcc))
|
|
17
10
|
|
|
18
11
|
|
|
19
12
|
### Dependencies
|
|
20
13
|
|
|
21
|
-
* **@anolilab/semantic-release-pnpm:** upgraded to 1.1.9
|
|
14
|
+
* **@anolilab/semantic-release-pnpm:** upgraded to 1.1.9
|
|
22
15
|
|
|
23
16
|
## @anolilab/semantic-release-clean-package-json 1.0.0 (2025-01-16)
|
|
24
17
|
|
|
@@ -28,10 +21,10 @@
|
|
|
28
21
|
|
|
29
22
|
### Bug Fixes
|
|
30
23
|
|
|
31
|
-
* changed plugin order to not publish cleaned package.json to
|
|
24
|
+
* changed plugin order to not publish cleaned package.json to GitHub ([6673e69](https://github.com/anolilab/semantic-release/commit/6673e69723fd340380250fa2d986e4c37091351f))
|
|
32
25
|
* remove usage of aggregate-error library ([e0c6e95](https://github.com/anolilab/semantic-release/commit/e0c6e95b07416d6694fa192ddca96e17a4c1c4b8))
|
|
33
26
|
* **semantic-release-clean-package-json:** fixed circular dependency ([93b51f9](https://github.com/anolilab/semantic-release/commit/93b51f9c03503e10f0c0a23dcd55273622b40aa0))
|
|
34
|
-
* **semantic-release-clean-package-json:** removed cjs exports, semantic-release
|
|
27
|
+
* **semantic-release-clean-package-json:** removed cjs exports, semantic-release don't support both types at the same time ([48c93c0](https://github.com/anolilab/semantic-release/commit/48c93c09cd5d6429b7658bc9a4fc573ea23462e2))
|
|
35
28
|
|
|
36
29
|
|
|
37
30
|
### Dependencies
|
|
@@ -42,7 +35,7 @@
|
|
|
42
35
|
|
|
43
36
|
### Bug Fixes
|
|
44
37
|
|
|
45
|
-
* changed plugin order to not publish cleaned package.json to
|
|
38
|
+
* changed plugin order to not publish cleaned package.json to GitHub ([6673e69](https://github.com/anolilab/semantic-release/commit/6673e69723fd340380250fa2d986e4c37091351f))
|
|
46
39
|
|
|
47
40
|
## @anolilab/semantic-release-clean-package-json 1.0.0-alpha.1 (2025-01-15)
|
|
48
41
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h3>anolilab semantic-release-clean-package-json</h3>
|
|
3
3
|
<p>
|
|
4
|
-
|
|
4
|
+
A semantic-release plugin that cleans and optimizes package.json before publishing by removing unnecessary development and build-time properties
|
|
5
5
|
</p>
|
|
6
6
|
</div>
|
|
7
7
|
|
|
@@ -25,6 +25,16 @@
|
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
|
+
## Why?
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
Key benefits:
|
|
33
|
+
- Reduces package size by removing development-only properties
|
|
34
|
+
- Prevents leaking internal configuration and metadata
|
|
35
|
+
- Maintains a clean and focused package.json for end users
|
|
36
|
+
- Customizable property preservation through configuration
|
|
37
|
+
|
|
28
38
|
## Install
|
|
29
39
|
|
|
30
40
|
```sh
|
|
@@ -44,16 +54,16 @@ pnpm add @anolilab/semantic-release-clean-package-json
|
|
|
44
54
|
The plugin can be configured in the [**semantic-release** configuration file](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration):
|
|
45
55
|
|
|
46
56
|
> [!IMPORTANT]
|
|
47
|
-
> Very important: The plugin must be placed
|
|
57
|
+
> 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.
|
|
48
58
|
|
|
49
59
|
```json
|
|
50
60
|
{
|
|
51
61
|
"plugins": [
|
|
52
62
|
"@semantic-release/commit-analyzer",
|
|
53
63
|
"@semantic-release/release-notes-generator",
|
|
54
|
-
"@semantic-release/github",
|
|
55
64
|
"@anolilab/semantic-release-clean-package-json",
|
|
56
|
-
"@anolilab/semantic-release-pnpm"
|
|
65
|
+
"@anolilab/semantic-release-pnpm",
|
|
66
|
+
"@semantic-release/github"
|
|
57
67
|
]
|
|
58
68
|
}
|
|
59
69
|
```
|
|
@@ -62,7 +72,8 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
62
72
|
|
|
63
73
|
| Step | Description |
|
|
64
74
|
| --------- | -------------------------------------------------------------------------------------------------------- |
|
|
65
|
-
| `
|
|
75
|
+
| `publish` | - Creates a backup of the original package.json file<br>- Removes all non-preserved properties from package.json<br>- Keeps properties specified in the default list and custom `keep` option<br>- Preserves specific npm scripts if they are in the keep list<br>- Writes the cleaned package.json file |
|
|
76
|
+
| `success` | - Restores the original package.json from backup<br>- Updates the version number to match the released version<br>- Removes the backup file<br>- Logs success or error messages |
|
|
66
77
|
|
|
67
78
|
### Options
|
|
68
79
|
|
|
@@ -77,6 +88,56 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
77
88
|
|
|
78
89
|
### Examples
|
|
79
90
|
|
|
91
|
+
The plugin can be configured with custom properties to keep in addition to the default preserved ones:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"plugins": [
|
|
96
|
+
"@semantic-release/commit-analyzer",
|
|
97
|
+
"@semantic-release/release-notes-generator",
|
|
98
|
+
[
|
|
99
|
+
"@anolilab/semantic-release-clean-package-json",
|
|
100
|
+
{
|
|
101
|
+
"keep": ["custom field"]
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"@anolilab/semantic-release-pnpm",
|
|
105
|
+
"@semantic-release/github"
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Example: Publishing a TypeScript Package
|
|
111
|
+
|
|
112
|
+
When publishing a TypeScript package, you might want to keep TypeScript-specific fields:
|
|
113
|
+
|
|
114
|
+
```jsonc
|
|
115
|
+
{
|
|
116
|
+
"plugins": [
|
|
117
|
+
"@semantic-release/commit-analyzer",
|
|
118
|
+
"@semantic-release/release-notes-generator",
|
|
119
|
+
[
|
|
120
|
+
"@anolilab/semantic-release-clean-package-json",
|
|
121
|
+
{
|
|
122
|
+
// This are the default values, just a example
|
|
123
|
+
"keep": [
|
|
124
|
+
"types",
|
|
125
|
+
"typings",
|
|
126
|
+
"typesVersions",
|
|
127
|
+
"module"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"@anolilab/semantic-release-pnpm",
|
|
132
|
+
"@semantic-release/github"
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Example: Custom Package Root
|
|
138
|
+
|
|
139
|
+
If your package.json is not in the root directory:
|
|
140
|
+
|
|
80
141
|
```json
|
|
81
142
|
{
|
|
82
143
|
"plugins": [
|
|
@@ -86,7 +147,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
86
147
|
[
|
|
87
148
|
"@anolilab/semantic-release-clean-package-json",
|
|
88
149
|
{
|
|
89
|
-
"
|
|
150
|
+
"pkgRoot": "dist"
|
|
90
151
|
}
|
|
91
152
|
],
|
|
92
153
|
"@anolilab/semantic-release-pnpm"
|
|
@@ -94,10 +155,6 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
94
155
|
}
|
|
95
156
|
```
|
|
96
157
|
|
|
97
|
-
<!-- Copied from https://github.com/privatenumber/clean-pkg-json/blob/develop/src/default-keep-properties.ts -->
|
|
98
|
-
<!-- MIT License -->
|
|
99
|
-
<!-- Copyright (c) Hiroki Osame <hiroki.osame@gmail.com> -->
|
|
100
|
-
|
|
101
158
|
### Default preserved properties
|
|
102
159
|
|
|
103
160
|
By default, these properties are preserved in `package.json`:
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var j=Object.defineProperty;var i=(s,e)=>j(s,"name",{value:e,configurable:!0});import{rm as
|
|
1
|
+
var j=Object.defineProperty;var i=(s,e)=>j(s,"name",{value:e,configurable:!0});import{rm as b}from"node:fs/promises";import{findUp as y,readJson as f,writeJson as p,isAccessible as h}from"@visulima/fs";import{resolve as g,join as c}from"@visulima/path";import{NotFoundError as v}from"@visulima/fs/error";import E from"@semantic-release/error";const N=["name","version","private","publishConfig","scripts.preinstall","scripts.install","scripts.postinstall","scripts.dependencies","files","bin","browser","main","man","jsdelivr","unpkg","dependencies","peerDependencies","peerDependenciesMeta","bundledDependencies","optionalDependencies","engines","os","cpu","description","keywords","author","contributors","license","homepage","repository","bugs","funding","type","exports","imports","sponsor","publisher","displayName","categories","galleryBanner","preview","contributes","activationEvents","badges","markdown","qna","extensionPack","extensionDependencies","extensionKind","icon","fesm2020","fesm2015","esm2020","es2020","types","typings","typesVersions","module","sideEffects"];var P=Object.defineProperty,l=i((s,e)=>P(s,"name",{value:e,configurable:!0}),"e");const O={ENOPKG:l(()=>({details:"A [package.json file](https://docs.npmjs.com/files/package.json) at the root of your project is required to release on npm.\nPlease follow the [npm guideline](https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid `package.json` file.",message:"Missing `package.json` file."}),"ENOPKG"),ENOPKGNAME:l(()=>({details:"The `package.json`'s [name](https://docs.npmjs.com/files/package.json#name) property is required in order to publish a package to the npm registry.\nPlease make sure to add a valid `name` for your package in your `package.json`.",message:"Missing `name` property in `package.json`."}),"ENOPKGNAME")};var K=Object.defineProperty,A=i((s,e)=>K(s,"name",{value:e,configurable:!0}),"o");const u=A((s,e={})=>{const{details:o,message:t}=O[s](e);return new E(t,s,o)},"default");var R=Object.defineProperty,m=i((s,e)=>R(s,"name",{value:e,configurable:!0}),"n");const G=m(async s=>{const e={type:"file"};s&&(e.cwd=s);const o=await y("package.json",e);if(!o)throw new v("No such file or directory, for package.json found.");return{packageJson:await f(o),path:o}},"findPackageJson"),k=m(async({pkgRoot:s},{cwd:e})=>{try{const{packageJson:o}=await G(s?g(e,s):e);if(!o.name){const t=u("ENOPKGNAME");throw new AggregateError([t],t.message)}return o}catch(o){if(o.code==="ENOENT"){const t=u("ENOPKG");throw new AggregateError([t],t.message)}throw o}},"default");var M=Object.defineProperty,w=i((s,e)=>M(s,"name",{value:e,configurable:!0}),"c");const C=w(async(s,e)=>{const o=await k(s,e),t=s.pkgRoot?g(e.cwd,s.pkgRoot):e.cwd;await p(c(t,"package.json.back"),o,{detectIndent:!0}),e.logger.log("Created a backup of the package.json file.");const a=new Set([...N,...s.keep??[]]);e.logger.log(`Keeping the following properties: ${[...a].join(", ")}`);const n={...o};for(const r in n)if(!a.has(r)){if(r==="scripts"){for(const d in n.scripts)a.has(`${r}.${d}`)||delete n.scripts[d];if(n.scripts&&Object.keys(n.scripts).length>0)continue}e.logger.log(`Removing property "${r}"`),delete n[r]}await p(c(t,"package.json"),n,{detectIndent:!0})},"publish"),T=w(async(s,e)=>{const o=s.pkgRoot?g(e.cwd,s.pkgRoot):e.cwd,t=c(o,"package.json.back");if(await h(t)){const a=await k(s,e),n=await f(t);n.version=a.version,await p(c(o,"package.json"),n,{detectIndent:!0,overwrite:!0}),await b(t),e.logger.log("Restored modified package.json from backup.")}else e.logger.error("No backup package.json found.")},"success");export{C as publish,T as success};
|