@jsdevtools/npm-publish 2.2.2 → 3.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/README.md +143 -101
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -6,23 +6,29 @@
|
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://plant.treeware.earth/JS-DevTools/npm-publish)
|
|
8
8
|
|
|
9
|
-
Publish
|
|
9
|
+
Publish packages to npm automatically in GitHub Actions by updating the version number.
|
|
10
|
+
|
|
11
|
+
- [Change log][releases]
|
|
12
|
+
- [v2 to v3 migration guide](#v2-to-v3)
|
|
13
|
+
- [v1 to v3 migration guide](#v1-to-v3)
|
|
14
|
+
|
|
15
|
+
[releases]: https://github.com/JS-DevTools/npm-publis/releases
|
|
10
16
|
|
|
11
17
|
## Features
|
|
12
18
|
|
|
13
|
-
- 🧠 **Smart
|
|
19
|
+
- 🧠 **Smart**
|
|
14
20
|
Only publishes if the version number in `package.json` differs from the latest on npm.
|
|
15
21
|
|
|
16
|
-
- 🛠 **Configurable
|
|
22
|
+
- 🛠 **Configurable**
|
|
17
23
|
Customize the version-checking behavior, the registry URL, and path of your package.
|
|
18
24
|
|
|
19
|
-
- 🔐 **Secure
|
|
20
|
-
Keeps your npm authentication token secret. Doesn't read
|
|
25
|
+
- 🔐 **Secure**
|
|
26
|
+
Keeps your npm authentication token secret. Doesn't read nor write to `~/.npmrc`.
|
|
21
27
|
|
|
22
|
-
- ⚡ **Fast
|
|
28
|
+
- ⚡ **Fast**
|
|
23
29
|
100% JavaScript (which is faster than Docker) and bundled to optimize loading time.
|
|
24
30
|
|
|
25
|
-
- 📤 **Outputs
|
|
31
|
+
- 📤 **Outputs**
|
|
26
32
|
Exposes the old and new version numbers, and the type of change (major, minor, patch, etc.) as variables that you can use in your workflow.
|
|
27
33
|
|
|
28
34
|
## Usage
|
|
@@ -35,78 +41,6 @@ This package can be used three different ways:
|
|
|
35
41
|
|
|
36
42
|
- 🖥 A [**CLI**](#command-line-interface) that you run in your terminal
|
|
37
43
|
|
|
38
|
-
## v2 Migration Guide
|
|
39
|
-
|
|
40
|
-
The v1 to v2 upgrade brought a few notable **breaking changes**. To migrate, make the following updates:
|
|
41
|
-
|
|
42
|
-
- The `type` output is now an empty string instead of `'none'` when no release occurs
|
|
43
|
-
```diff
|
|
44
|
-
- run: echo "Version changed!"
|
|
45
|
-
- if: ${{ steps.publish.outputs.type != 'none' }}
|
|
46
|
-
+ if: ${{ steps.publish.outputs.type }}
|
|
47
|
-
```
|
|
48
|
-
- The `--ignore-scripts` option is now passed to `npm publish` as a security precaution. If you define any publish lifecycle scripts - `prepublishOnly`, `prepack`, `prepare`, `postpack`, `publish`, `postpublish` - run them explicitly or set the `ignore-scripts` input to `false`.
|
|
49
|
-
```diff
|
|
50
|
-
with:
|
|
51
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
52
|
-
+ ignore-scripts: false
|
|
53
|
-
```
|
|
54
|
-
- The workflow's `.npmrc` file is no longer modified. If you have any workarounds to adjust for this misbehavior - for example, if you're using `actions/setup-node` to configure `.npmrc` - you should remove them.
|
|
55
|
-
|
|
56
|
-
```diff
|
|
57
|
-
- uses: actions/setup-node@v3
|
|
58
|
-
with:
|
|
59
|
-
node-version: '18'
|
|
60
|
-
registry-url: https://registry.npmjs.org/
|
|
61
|
-
|
|
62
|
-
- uses: JS-DevTools/npm-publish@v1
|
|
63
|
-
with:
|
|
64
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
65
|
-
|
|
66
|
-
- name: Do some more stuff with npm
|
|
67
|
-
run: npm whoami
|
|
68
|
-
env:
|
|
69
|
-
- INPUT_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
70
|
-
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
- The `check-version` and `greater-version-only` options have been removed and replaced with `strategy`.
|
|
74
|
-
- Use `strategy: all` (default) to publish all versions that do not yet exist in the registry.
|
|
75
|
-
```diff
|
|
76
|
-
with:
|
|
77
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
78
|
-
- check-version: true
|
|
79
|
-
- greater-version-only: false
|
|
80
|
-
+ strategy: all
|
|
81
|
-
```
|
|
82
|
-
- Use `strategy: upgrade` to only publish versions that upgrade the selected tag.
|
|
83
|
-
```diff
|
|
84
|
-
with:
|
|
85
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
86
|
-
- check-version: true
|
|
87
|
-
- greater-version-only: true
|
|
88
|
-
+ strategy: upgrade
|
|
89
|
-
```
|
|
90
|
-
- `check-version: false` has been removed. You may not need this action if you're not checking already published versions; [you can `npm` directly][publishing-nodejs-packages], instead.
|
|
91
|
-
```diff
|
|
92
|
-
- - uses: JS-DevTools/npm-publish@v1
|
|
93
|
-
- with:
|
|
94
|
-
- token: ${{ secrets.NPM_TOKEN }}
|
|
95
|
-
- check-version: false
|
|
96
|
-
+ - uses: actions/setup-node@v3
|
|
97
|
-
+ with:
|
|
98
|
-
+ node-version: '18'
|
|
99
|
-
+ registry-url: https://registry.npmjs.org/
|
|
100
|
-
+ - run: npm publish
|
|
101
|
-
+ env:
|
|
102
|
-
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
See the [change log][] for more details and other changes in the v2 release.
|
|
106
|
-
|
|
107
|
-
[publishing-nodejs-packages]: https://docs.github.com/actions/publishing-packages/publishing-nodejs-packages
|
|
108
|
-
[change log]: https://github.com/JS-DevTools/npm-publish/releases
|
|
109
|
-
|
|
110
44
|
## GitHub Action
|
|
111
45
|
|
|
112
46
|
To use the GitHub Action, you'll need to add it as a step in your [workflow file][]. By default, the only thing you need to do is set the `token` parameter to your [npm authentication token][].
|
|
@@ -120,13 +54,13 @@ jobs:
|
|
|
120
54
|
publish:
|
|
121
55
|
runs-on: ubuntu-latest
|
|
122
56
|
steps:
|
|
123
|
-
- uses: actions/checkout@
|
|
57
|
+
- uses: actions/checkout@v4
|
|
124
58
|
- uses: actions/setup-node@v3
|
|
125
59
|
with:
|
|
126
|
-
node-version: "
|
|
60
|
+
node-version: "20"
|
|
127
61
|
- run: npm ci
|
|
128
62
|
- run: npm test
|
|
129
|
-
- uses: JS-DevTools/npm-publish@
|
|
63
|
+
- uses: JS-DevTools/npm-publish@v3
|
|
130
64
|
with:
|
|
131
65
|
token: ${{ secrets.NPM_TOKEN }}
|
|
132
66
|
```
|
|
@@ -145,13 +79,13 @@ jobs:
|
|
|
145
79
|
contents: read
|
|
146
80
|
packages: write # allow GITHUB_TOKEN to publish packages
|
|
147
81
|
steps:
|
|
148
|
-
- uses: actions/checkout@
|
|
82
|
+
- uses: actions/checkout@v4
|
|
149
83
|
- uses: actions/setup-node@v3
|
|
150
84
|
with:
|
|
151
|
-
node-version: "
|
|
85
|
+
node-version: "20"
|
|
152
86
|
- run: npm ci
|
|
153
87
|
- run: npm test
|
|
154
|
-
- uses: JS-DevTools/npm-publish@
|
|
88
|
+
- uses: JS-DevTools/npm-publish@v3
|
|
155
89
|
with:
|
|
156
90
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
157
91
|
registry: "https://npm.pkg.github.com"
|
|
@@ -161,7 +95,7 @@ jobs:
|
|
|
161
95
|
[npm authentication token]: https://docs.npmjs.com/creating-and-viewing-authentication-tokens
|
|
162
96
|
[GitHub Package Registry]: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry
|
|
163
97
|
|
|
164
|
-
###
|
|
98
|
+
### Action usage
|
|
165
99
|
|
|
166
100
|
You can set any or all of the following input parameters using `with`:
|
|
167
101
|
|
|
@@ -184,19 +118,19 @@ You can set any or all of the following input parameters using `with`:
|
|
|
184
118
|
[npm-access]: https://docs.npmjs.com/cli/v9/commands/npm-publish#access
|
|
185
119
|
[provenance]: https://docs.npmjs.com/generating-provenance-statements
|
|
186
120
|
|
|
187
|
-
###
|
|
121
|
+
### Action output
|
|
188
122
|
|
|
189
|
-
npm-publish exposes
|
|
123
|
+
npm-publish exposes several output variables, which you can use in later steps of your workflow if you provide an `id` for the npm-publish step.
|
|
190
124
|
|
|
191
|
-
```
|
|
192
|
-
steps:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
125
|
+
```diff
|
|
126
|
+
steps:
|
|
127
|
+
- uses: JS-DevTools/npm-publish@v3
|
|
128
|
+
+ id: publish
|
|
129
|
+
with:
|
|
130
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
197
131
|
|
|
198
|
-
|
|
199
|
-
|
|
132
|
+
+ - if: ${{ steps.publish.outputs.type }}
|
|
133
|
+
+ run: echo "Version changed!"
|
|
200
134
|
```
|
|
201
135
|
|
|
202
136
|
| Name | Type | Description |
|
|
@@ -232,7 +166,7 @@ await npmPublish({ token: "YOUR_NPM_AUTH_TOKEN_HERE" });
|
|
|
232
166
|
|
|
233
167
|
[npm]: https://docs.npmjs.com/about-npm/
|
|
234
168
|
|
|
235
|
-
###
|
|
169
|
+
### API usage
|
|
236
170
|
|
|
237
171
|
As shown in the example above, you should pass an options object to the `npmPublish` function. In TypeScript, the `Options` interface is available as an import.
|
|
238
172
|
|
|
@@ -257,7 +191,7 @@ import type { Options } from "@jsdevtools/npm-publish";
|
|
|
257
191
|
1. May be specified using `publishConfig` in `package.json`.
|
|
258
192
|
2. Provenance requires npm `>=9.5.0`.
|
|
259
193
|
|
|
260
|
-
###
|
|
194
|
+
### API output
|
|
261
195
|
|
|
262
196
|
The `npmPublish()` function returns a promise of a `Results` object. In TypeScript, the `Results` interface is available as an import.
|
|
263
197
|
|
|
@@ -301,7 +235,7 @@ npx npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE --registry http://example.com .
|
|
|
301
235
|
|
|
302
236
|
Run `npm-publish --help` to see the full list of options available.
|
|
303
237
|
|
|
304
|
-
```
|
|
238
|
+
```text
|
|
305
239
|
Usage:
|
|
306
240
|
|
|
307
241
|
npm-publish <options> [package]
|
|
@@ -346,6 +280,116 @@ Examples:
|
|
|
346
280
|
$ npm-publish --token abc123 ./my-package
|
|
347
281
|
```
|
|
348
282
|
|
|
283
|
+
## Migration guides
|
|
284
|
+
|
|
285
|
+
Major releases of the action and libraries may contain breaking changes, documented here.
|
|
286
|
+
For more detailed change logs, see [releases][].
|
|
287
|
+
|
|
288
|
+
### v2 to v3
|
|
289
|
+
|
|
290
|
+
The v3 release does not require any changes to how you use `npm-publish` from `v2`. The version of Node.js used by the action was updated to v20 due to GitHub Action's [deprecation of Node.js v16][node16-deprecation]. The minimum required version of Node.js for the library and CLI remains v16.
|
|
291
|
+
|
|
292
|
+
[node16-deprecation]: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
|
|
293
|
+
|
|
294
|
+
### v1 to v3
|
|
295
|
+
|
|
296
|
+
The v2 release made several breaking changes to inputs, outputs, and behaviors that were present in `v1`. The examples below focus on the action, but the same changes are applicable to the library and CLI, too.
|
|
297
|
+
|
|
298
|
+
#### v2 option changes
|
|
299
|
+
|
|
300
|
+
The `check-version` and `greater-version-only` boolean options were replaced with the `strategy` option:
|
|
301
|
+
|
|
302
|
+
- `strategy: all` (default) will publish any version that does not yet exist in the registry
|
|
303
|
+
- `strategy: upgrade` will publish only if the version is a semver upgrade of the requested `dist-tag`
|
|
304
|
+
|
|
305
|
+
```diff
|
|
306
|
+
with:
|
|
307
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
308
|
+
- check-version: true
|
|
309
|
+
- greater-version-only: false
|
|
310
|
+
+ strategy: all
|
|
311
|
+
|
|
312
|
+
with:
|
|
313
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
314
|
+
- check-version: true
|
|
315
|
+
- greater-version-only: true
|
|
316
|
+
+ strategy: upgrade
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
`check-version: false` has been removed. If you only need to publish, without first checking whether the version exists in the registry, you can [use `npm` directly][publishing-nodejs-packages] instead:
|
|
320
|
+
|
|
321
|
+
```diff
|
|
322
|
+
- uses: actions/setup-node@v3
|
|
323
|
+
with:
|
|
324
|
+
node-version: '18'
|
|
325
|
+
+ registry-url: https://registry.npmjs.org/
|
|
326
|
+
|
|
327
|
+
- - uses: JS-DevTools/npm-publish@v1
|
|
328
|
+
- with:
|
|
329
|
+
- token: ${{ secrets.NPM_TOKEN }}
|
|
330
|
+
- check-version: false
|
|
331
|
+
+ - run: npm publish
|
|
332
|
+
+ env:
|
|
333
|
+
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
[publishing-nodejs-packages]: https://docs.github.com/actions/publishing-packages/publishing-nodejs-packages
|
|
337
|
+
|
|
338
|
+
#### v2 output changes
|
|
339
|
+
|
|
340
|
+
The `type` output is now an empty string instead of `'none'` when no release occurs
|
|
341
|
+
|
|
342
|
+
```diff
|
|
343
|
+
- run: echo "Version changed!"
|
|
344
|
+
- if: ${{ steps.publish.outputs.type != 'none' }}
|
|
345
|
+
+ if: ${{ steps.publish.outputs.type }}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### v2 behavior changes
|
|
349
|
+
|
|
350
|
+
The `--ignore-scripts` option is now passed to `npm publish` as a security precaution. If you define any publish lifecycle scripts - `prepublishOnly`, `prepack`, `prepare`, `postpack`, `publish`, `postpublish` - we recommend you run that logic as a separate explicit build step.
|
|
351
|
+
|
|
352
|
+
```diff
|
|
353
|
+
+ - run: npm run build
|
|
354
|
+
|
|
355
|
+
- - uses: JS-DevTools/npm-publish@v1
|
|
356
|
+
+ - uses: JS-DevTools/npm-publish@v3
|
|
357
|
+
with:
|
|
358
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
If you can't change your build, you can set the `ignore-scripts` input to `false` as a workaround. Be aware that failures during a lifecycle script can be difficult to debug, and any `stdout`/`stderr` output from your build script could interfere with how `npm-publish` interprets results from the `npm` CLI.
|
|
362
|
+
|
|
363
|
+
```diff
|
|
364
|
+
- - uses: JS-DevTools/npm-publish@v1
|
|
365
|
+
+ - uses: JS-DevTools/npm-publish@v3
|
|
366
|
+
with:
|
|
367
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
368
|
+
+ ignore-scripts: false
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
The global `.npmrc` file is no longer read nor modified. This means the `token` option is now required for the library and CLI. (It was already required for the action.) You may have workarounds in place referencing `INPUT_TOKEN`, which v1 [erroneously wrote][#15] to `.npmrc`. These workarounds should be removed.
|
|
372
|
+
|
|
373
|
+
```diff
|
|
374
|
+
- uses: actions/setup-node@v3
|
|
375
|
+
with:
|
|
376
|
+
node-version: '18'
|
|
377
|
+
registry-url: https://registry.npmjs.org/
|
|
378
|
+
|
|
379
|
+
- - uses: JS-DevTools/npm-publish@v1
|
|
380
|
+
+ - uses: JS-DevTools/npm-publish@v3
|
|
381
|
+
with:
|
|
382
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
383
|
+
|
|
384
|
+
- name: Do some more stuff with npm
|
|
385
|
+
run: npm whoami
|
|
386
|
+
env:
|
|
387
|
+
- INPUT_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
388
|
+
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
[#15]: https://github.com/JS-DevTools/npm-publish/issues/15
|
|
392
|
+
|
|
349
393
|
## License
|
|
350
394
|
|
|
351
395
|
npm-publish is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.
|
|
@@ -359,5 +403,3 @@ Thanks to these awesome companies for their support of Open Source developers
|
|
|
359
403
|
[](https://github.com/open-source)
|
|
360
404
|
[](https://www.npmjs.com/)
|
|
361
405
|
[](https://coveralls.io)
|
|
362
|
-
[](https://travis-ci.com)
|
|
363
|
-
[](https://saucelabs.com)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsdevtools/npm-publish",
|
|
3
3
|
"description": "Fast, easy publishing to NPM",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github-action",
|
|
7
7
|
"npm",
|
|
@@ -54,31 +54,31 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@actions/core": "^1.10.1",
|
|
56
56
|
"@types/command-line-args": "^5.2.1",
|
|
57
|
-
"@types/node": "^20.6
|
|
57
|
+
"@types/node": "^20.8.6",
|
|
58
58
|
"@types/tar": "^6.1.6",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.7.
|
|
60
|
-
"@typescript-eslint/parser": "^6.7.
|
|
61
|
-
"@vitest/coverage-istanbul": "^0.34.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
60
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
61
|
+
"@vitest/coverage-istanbul": "^0.34.6",
|
|
62
62
|
"concurrently": "^8.2.1",
|
|
63
|
-
"esbuild": "^0.19.
|
|
64
|
-
"eslint": "^8.
|
|
63
|
+
"esbuild": "^0.19.4",
|
|
64
|
+
"eslint": "^8.51.0",
|
|
65
65
|
"eslint-config-prettier": "^9.0.0",
|
|
66
|
-
"eslint-import-resolver-typescript": "^3.6.
|
|
66
|
+
"eslint-import-resolver-typescript": "^3.6.1",
|
|
67
67
|
"eslint-plugin-import": "npm:eslint-plugin-i@^2.28.1",
|
|
68
|
-
"eslint-plugin-jsdoc": "^46.
|
|
69
|
-
"eslint-plugin-n": "^16.
|
|
68
|
+
"eslint-plugin-jsdoc": "^46.8.2",
|
|
69
|
+
"eslint-plugin-n": "^16.2.0",
|
|
70
70
|
"eslint-plugin-promise": "^6.1.1",
|
|
71
71
|
"eslint-plugin-sonarjs": "^0.21.0",
|
|
72
72
|
"eslint-plugin-unicorn": "^48.0.1",
|
|
73
73
|
"prettier": "^3.0.3",
|
|
74
|
-
"prettier-plugin-jsdoc": "^1.
|
|
75
|
-
"rimraf": "^5.0.
|
|
74
|
+
"prettier-plugin-jsdoc": "^1.1.1",
|
|
75
|
+
"rimraf": "^5.0.5",
|
|
76
76
|
"typescript": "^5.2.2",
|
|
77
|
-
"vitest": "^0.34.
|
|
78
|
-
"vitest-when": "^0.
|
|
77
|
+
"vitest": "^0.34.6",
|
|
78
|
+
"vitest-when": "^0.2.0"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@types/semver": "^7.5.
|
|
81
|
+
"@types/semver": "^7.5.2",
|
|
82
82
|
"command-line-args": "^5.2.1",
|
|
83
83
|
"semver": "7.5.4",
|
|
84
84
|
"tar": "6.2.0"
|