@jsdevtools/npm-publish 1.4.3 → 2.1.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 +174 -147
- package/bin/npm-publish.js +10 -2
- package/lib/action/core.d.ts +45 -0
- package/lib/action/core.js +59 -0
- package/lib/action/core.js.map +1 -0
- package/lib/action/main.js +55 -0
- package/lib/action/main.js.map +1 -0
- package/lib/cli/index.d.ts +4 -2
- package/lib/cli/index.js +60 -53
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/parse-cli-arguments.d.ts +17 -0
- package/lib/cli/parse-cli-arguments.js +40 -0
- package/lib/cli/parse-cli-arguments.js.map +1 -0
- package/lib/compare-and-publish/compare-and-publish.d.ts +21 -0
- package/lib/compare-and-publish/compare-and-publish.js +49 -0
- package/lib/compare-and-publish/compare-and-publish.js.map +1 -0
- package/lib/compare-and-publish/compare-versions.d.ts +16 -0
- package/lib/compare-and-publish/compare-versions.js +41 -0
- package/lib/compare-and-publish/compare-versions.js.map +1 -0
- package/lib/compare-and-publish/get-arguments.d.ts +21 -0
- package/lib/compare-and-publish/get-arguments.js +50 -0
- package/lib/compare-and-publish/get-arguments.js.map +1 -0
- package/lib/compare-and-publish/index.d.ts +1 -0
- package/lib/compare-and-publish/index.js +18 -0
- package/lib/compare-and-publish/index.js.map +1 -0
- package/lib/errors.d.ts +39 -0
- package/lib/errors.js +121 -0
- package/lib/errors.js.map +1 -0
- package/lib/format-publish-result.d.ts +12 -0
- package/lib/format-publish-result.js +36 -0
- package/lib/format-publish-result.js.map +1 -0
- package/lib/index.d.ts +4 -5
- package/lib/index.js +11 -10
- package/lib/index.js.map +1 -1
- package/lib/normalize-options.d.ts +28 -1
- package/lib/normalize-options.js +89 -14
- package/lib/normalize-options.js.map +1 -1
- package/lib/npm/call-npm-cli.d.ts +38 -0
- package/lib/npm/call-npm-cli.js +113 -0
- package/lib/npm/call-npm-cli.js.map +1 -0
- package/lib/npm/index.d.ts +2 -0
- package/lib/npm/index.js +19 -0
- package/lib/npm/index.js.map +1 -0
- package/lib/npm/use-npm-environment.d.ts +15 -0
- package/lib/npm/use-npm-environment.js +44 -0
- package/lib/npm/use-npm-environment.js.map +1 -0
- package/lib/npm-publish.d.ts +7 -4
- package/lib/npm-publish.js +25 -26
- package/lib/npm-publish.js.map +1 -1
- package/lib/options.d.ts +67 -44
- package/lib/options.js +5 -0
- package/lib/options.js.map +1 -1
- package/lib/read-manifest.d.ts +22 -1
- package/lib/read-manifest.js +122 -22
- package/lib/read-manifest.js.map +1 -1
- package/lib/results.d.ts +30 -28
- package/lib/results.js +3 -0
- package/lib/results.js.map +1 -1
- package/package.json +47 -35
- package/src/action/core.ts +91 -0
- package/src/action/main.ts +32 -0
- package/src/cli/index.ts +72 -0
- package/src/cli/parse-cli-arguments.ts +49 -0
- package/src/compare-and-publish/compare-and-publish.ts +75 -0
- package/src/compare-and-publish/compare-versions.ts +48 -0
- package/src/compare-and-publish/get-arguments.ts +61 -0
- package/src/compare-and-publish/index.ts +1 -0
- package/src/errors.ts +137 -0
- package/src/format-publish-result.ts +40 -0
- package/src/index.ts +7 -0
- package/src/normalize-options.ts +123 -0
- package/src/npm/call-npm-cli.ts +140 -0
- package/src/npm/index.ts +2 -0
- package/src/npm/use-npm-environment.ts +57 -0
- package/src/npm-publish.ts +40 -0
- package/src/options.ts +108 -0
- package/src/read-manifest.ts +142 -0
- package/src/results.ts +50 -0
- package/CHANGELOG.md +0 -49
- package/lib/action/index.js +0 -67
- package/lib/action/index.js.map +0 -1
- package/lib/cli/exit-code.d.ts +0 -1
- package/lib/cli/exit-code.js +0 -16
- package/lib/cli/exit-code.js.map +0 -1
- package/lib/cli/help.d.ts +0 -1
- package/lib/cli/help.js +0 -28
- package/lib/cli/help.js.map +0 -1
- package/lib/cli/parse-args.d.ts +0 -1
- package/lib/cli/parse-args.js +0 -58
- package/lib/cli/parse-args.js.map +0 -1
- package/lib/npm-config.d.ts +0 -1
- package/lib/npm-config.js +0 -85
- package/lib/npm-config.js.map +0 -1
- package/lib/npm-env.d.ts +0 -6
- package/lib/npm-env.js +0 -24
- package/lib/npm-env.js.map +0 -1
- package/lib/npm.d.ts +0 -1
- package/lib/npm.js +0 -95
- package/lib/npm.js.map +0 -1
- /package/lib/action/{index.d.ts → main.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
Fast, easy publishing to NPM
|
|
2
|
-
==============================================
|
|
1
|
+
# Fast, easy publishing to NPM
|
|
3
2
|
|
|
4
|
-
[](https://github.com/JS-DevTools/npm-publish/actions)
|
|
5
3
|
[](https://github.com/JS-DevTools/npm-publish/actions)
|
|
6
|
-
|
|
7
|
-
[](https://coveralls.io/github/JS-DevTools/npm-publish)
|
|
8
|
-
[](https://david-dm.org/JS-DevTools/npm-publish)
|
|
9
|
-
|
|
4
|
+
[](https://coveralls.io/github/JS-DevTools/npm-publish)
|
|
10
5
|
[](https://www.npmjs.com/package/@jsdevtools/npm-publish)
|
|
11
6
|
[](LICENSE)
|
|
12
7
|
[](https://plant.treeware.earth/JS-DevTools/npm-publish)
|
|
13
8
|
|
|
9
|
+
Publish your packages to npm automatically in GitHub Actions by updating the version number.
|
|
14
10
|
|
|
11
|
+
## Features
|
|
15
12
|
|
|
16
|
-
Features
|
|
17
|
-
--------------------------
|
|
18
13
|
- 🧠 **Smart**<br>
|
|
19
|
-
Only publishes if the version number in `package.json` differs from the latest on
|
|
14
|
+
Only publishes if the version number in `package.json` differs from the latest on npm.
|
|
20
15
|
|
|
21
16
|
- 🛠 **Configurable**<br>
|
|
22
|
-
Customize the version-checking behavior, the registry URL, and path of your package
|
|
17
|
+
Customize the version-checking behavior, the registry URL, and path of your package.
|
|
23
18
|
|
|
24
19
|
- 🔐 **Secure**<br>
|
|
25
|
-
Keeps your
|
|
20
|
+
Keeps your npm authentication token secret. Doesn't read from or write to `~/.npmrc`.
|
|
26
21
|
|
|
27
22
|
- ⚡ **Fast**<br>
|
|
28
|
-
100% JavaScript (which is faster than Docker) and bundled to optimize loading time
|
|
23
|
+
100% JavaScript (which is faster than Docker) and bundled to optimize loading time.
|
|
29
24
|
|
|
30
25
|
- 📤 **Outputs**<br>
|
|
31
|
-
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.
|
|
26
|
+
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.
|
|
32
27
|
|
|
28
|
+
## Usage
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
Usage
|
|
36
|
-
--------------------------
|
|
37
30
|
This package can be used three different ways:
|
|
38
31
|
|
|
39
32
|
- 🤖 A [**GitHub Action**](#github-action) as part of your CI/CD process
|
|
@@ -42,218 +35,252 @@ This package can be used three different ways:
|
|
|
42
35
|
|
|
43
36
|
- 🖥 A [**CLI**](#command-line-interface) that you run in your terminal
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 `check-version` and `greater-version-only` options have been removed and replaced with `strategy`.
|
|
49
|
+
- Use `strategy: all` (default) to publish all versions that do not yet exist in the registry.
|
|
50
|
+
```diff
|
|
51
|
+
with:
|
|
52
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
53
|
+
- check-version: true
|
|
54
|
+
- greater-version-only: false
|
|
55
|
+
+ strategy: all
|
|
56
|
+
```
|
|
57
|
+
- Use `strategy: upgrade` to only publish versions that upgrade the selected tag.
|
|
58
|
+
```diff
|
|
59
|
+
with:
|
|
60
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
61
|
+
- check-version: true
|
|
62
|
+
- greater-version-only: true
|
|
63
|
+
+ strategy: upgrade
|
|
64
|
+
```
|
|
65
|
+
- `check-version: false` has been removed. You don't need this action if you're not checking already published versions; use `npm` directly, instead.
|
|
66
|
+
|
|
67
|
+
See the [change log][] for more details and other changes in the v2 release.
|
|
68
|
+
|
|
69
|
+
[change log]: https://github.com/JS-DevTools/npm-publish/releases
|
|
70
|
+
|
|
71
|
+
## GitHub Action
|
|
72
|
+
|
|
73
|
+
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][].
|
|
50
74
|
|
|
51
75
|
```yaml
|
|
52
|
-
on:
|
|
76
|
+
on:
|
|
77
|
+
push:
|
|
78
|
+
branches: main
|
|
53
79
|
|
|
54
80
|
jobs:
|
|
55
81
|
publish:
|
|
56
82
|
runs-on: ubuntu-latest
|
|
57
83
|
steps:
|
|
58
|
-
- uses: actions/checkout@
|
|
59
|
-
- uses: actions/setup-node@
|
|
84
|
+
- uses: actions/checkout@v3
|
|
85
|
+
- uses: actions/setup-node@v3
|
|
60
86
|
with:
|
|
61
|
-
node-version:
|
|
62
|
-
- run: npm
|
|
87
|
+
node-version: "18"
|
|
88
|
+
- run: npm ci
|
|
63
89
|
- run: npm test
|
|
64
|
-
- uses: JS-DevTools/npm-publish@
|
|
90
|
+
- uses: JS-DevTools/npm-publish@v2
|
|
65
91
|
with:
|
|
66
92
|
token: ${{ secrets.NPM_TOKEN }}
|
|
67
93
|
```
|
|
68
94
|
|
|
95
|
+
[workflow file]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions
|
|
96
|
+
[npm authentication token]: https://docs.npmjs.com/creating-and-viewing-authentication-tokens
|
|
97
|
+
|
|
98
|
+
### Usage
|
|
69
99
|
|
|
100
|
+
You can set any or all of the following input parameters using `with`:
|
|
70
101
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
102
|
+
| Name | Type | Default | Description |
|
|
103
|
+
| ------------ | ---------------------- | -------------------------------- | ----------------------------------------------------------------------------- |
|
|
104
|
+
| `token` | string | **required** | Authentication token to use with the configured registry. |
|
|
105
|
+
| `registry` | string | `https://registry.npmjs.org/` \* | Registry URL to use. |
|
|
106
|
+
| `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish |
|
|
107
|
+
| `tag` | string | `latest` \* | [Distribution tag][npm-tag] to publish to. |
|
|
108
|
+
| `access` | `public`, `restricted` | [npm defaults][npm-access] \* | Whether the package should be publicly visible or restricted. |
|
|
109
|
+
| `provenance` | boolean | `false` \* | Run `npm publish` with the `--provenance` flag to add provenance statements. |
|
|
110
|
+
| `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
|
|
111
|
+
| `dry-run` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
|
|
74
112
|
|
|
75
|
-
|
|
76
|
-
|----------------|--------|----------|----------------------------|------------------------------------
|
|
77
|
-
|`token` |string |yes | |The NPM auth token to use for publishing
|
|
78
|
-
|`registry` |string |no |https://registry.npmjs.org/ |The NPM registry URL to use
|
|
79
|
-
|`package` |string |no |./package.json |The path of your package.json file
|
|
80
|
-
|`tag` |string |no |"latest" |The tag to publish to. This allows people to install the package using `npm install <package-name>@<tag>`.
|
|
81
|
-
|`access` |string |no |"public" for non-scoped packages. "restricted" for scoped packages.|Determines whether the published package should be publicly visible, or restricted to members of your NPM organization.
|
|
82
|
-
|`dry-run` |boolean |no |false |Run NPM publish with the `--dry-run` flag to prevent publication
|
|
83
|
-
|`check-version` |boolean |no |true |Only publish to NPM if the version number in `package.json` differs from the latest on NPM
|
|
113
|
+
\* Default values for these options may be specified using `publishConfig` in `package.json`.
|
|
84
114
|
|
|
115
|
+
[npm-tag]: https://docs.npmjs.com/cli/v9/commands/npm-publish#tag
|
|
116
|
+
[npm-access]: https://docs.npmjs.com/cli/v9/commands/npm-publish#access
|
|
85
117
|
|
|
118
|
+
### Output
|
|
86
119
|
|
|
87
|
-
Output Variables
|
|
88
|
-
--------------------------
|
|
89
120
|
npm-publish exposes some output variables, which you can use in later steps of your workflow. To access the output variables, you'll need to set an `id` for the npm-publish step.
|
|
90
121
|
|
|
91
122
|
```yaml
|
|
92
123
|
steps:
|
|
93
124
|
- id: publish
|
|
94
|
-
uses: JS-DevTools/npm-publish@
|
|
125
|
+
uses: JS-DevTools/npm-publish@v2
|
|
95
126
|
with:
|
|
96
127
|
token: ${{ secrets.NPM_TOKEN }}
|
|
97
128
|
|
|
98
|
-
- if: steps.publish.outputs.type
|
|
129
|
+
- if: ${{ steps.publish.outputs.type }}
|
|
99
130
|
run: |
|
|
100
|
-
echo "Version changed
|
|
131
|
+
echo "Version changed!"
|
|
101
132
|
```
|
|
102
133
|
|
|
134
|
+
| Name | Type | Description |
|
|
135
|
+
| ------------- | ------- | ------------------------------------------------------------------------------------------------------------- |
|
|
136
|
+
| `id` | string | Package identifier of the release: `${name}@${version}` or empty if no release. |
|
|
137
|
+
| `type` | string | [Semver release type][], `initial` if first release, `different` if other change, or empty if no release. |
|
|
138
|
+
| `name` | string | Name of the package. |
|
|
139
|
+
| `version` | string | Version of the package. |
|
|
140
|
+
| `old-version` | string | Previously published version on `tag` or empty if no previous version on tag. |
|
|
141
|
+
| `tag` | string | [Distribution tag][npm-tag] the package was published to. |
|
|
142
|
+
| `access` | string | [Access level][npm-access] the package was published with, or `default` if scoped-package defaults were used. |
|
|
143
|
+
| `registry` | string | Registry the package was published to. |
|
|
144
|
+
| `dry-run` | boolean | Whether `npm publish` was run in "dry run" mode. |
|
|
103
145
|
|
|
104
|
-
|
|
105
|
-
|--------------|--------|------------------------------------
|
|
106
|
-
|`type` |string |The type of version change that occurred ("major", "minor", "patch", etc.). If there was no version change, then type will be "none".
|
|
107
|
-
|`version` |string |The version that was published
|
|
108
|
-
|`old-version` |string |The version number that was previously published to NPM
|
|
109
|
-
|`tag` |string |The tag that the package was published to.
|
|
110
|
-
|`access` |string |Indicates whether the published package is publicly visible or restricted to members of your NPM organization.
|
|
111
|
-
|`dry-run` |boolean |Indicates whether NPM was run in "dry run" mode
|
|
146
|
+
[semver release type]: https://github.com/npm/node-semver#release_types
|
|
112
147
|
|
|
148
|
+
## JavaScript Function
|
|
113
149
|
|
|
114
|
-
|
|
115
|
-
JavaScript Function
|
|
116
|
-
------------------------------
|
|
117
|
-
To use npm-package in your JavaScript code, you'll need to install it using [NPM](https://docs.npmjs.com/about-npm/):
|
|
150
|
+
To use npm-package in your JavaScript code, you'll need to install it using [npm][] or other package manager of choice:
|
|
118
151
|
|
|
119
152
|
```bash
|
|
120
|
-
npm install @jsdevtools/npm-publish
|
|
153
|
+
npm install --save-dev @jsdevtools/npm-publish
|
|
121
154
|
```
|
|
122
155
|
|
|
123
156
|
You can then import it and use it in your code like this:
|
|
124
157
|
|
|
125
158
|
```javascript
|
|
126
|
-
|
|
159
|
+
import { npmPublish } from "@jsdevtools/npm-publish";
|
|
127
160
|
|
|
128
161
|
// Run npm-publish with all defaults
|
|
129
|
-
await npmPublish();
|
|
130
|
-
|
|
131
|
-
// Run npm-publish with options
|
|
132
|
-
await npmPublish({
|
|
133
|
-
package: "./path/to/package.json",
|
|
134
|
-
token: "YOUR_NPM_AUTH_TOKEN_HERE"
|
|
135
|
-
});
|
|
162
|
+
await npmPublish({ token: "YOUR_NPM_AUTH_TOKEN_HERE" });
|
|
136
163
|
```
|
|
137
164
|
|
|
138
|
-
|
|
139
|
-
As shown in the example above, you can pass options to the `npmPublish()` function. Here are the available options:
|
|
140
|
-
|
|
141
|
-
|Name |Type |Default |Description
|
|
142
|
-
|----------------|---------|----------------------------|------------------------------------
|
|
143
|
-
|`token` |string |NPM's default credentials |The NPM auth token to use for publishing. If not set, then NPM will
|
|
144
|
-
|`registry` |string |https://registry.npmjs.org/ |The NPM registry URL to use
|
|
145
|
-
|`package` |string |./package.json |The path of your package.json file
|
|
146
|
-
|`tag` |string |"latest" |The tag to publish to. This allows people to install the package using `npm install <package-name>@<tag>`.
|
|
147
|
-
|`access` |string |"public" for non-scoped packages. "restricted" for scoped packages.|Determines whether the published package should be publicly visible, or restricted to members of your NPM organization.
|
|
148
|
-
|`dryRun` |boolean |false |Run NPM publish with the `--dry-run` flag to prevent publication
|
|
149
|
-
|`checkVersion` |boolean |true |Only publish to NPM if the version number in `package.json` differs from the latest on NPM
|
|
150
|
-
|`quiet` |boolean |false |Suppress console output from NPM and npm-publish
|
|
151
|
-
|`debug` |function |no-op |A function to log debug messages. You can set this to a custom function to receive debug messages, or just set it to `console.debug` to print debug messages to the console.
|
|
152
|
-
|
|
153
|
-
### Return Value
|
|
154
|
-
The `npmPublish()` function asynchronously returns an object with the following properties:
|
|
155
|
-
|
|
156
|
-
|Name |Type |Description
|
|
157
|
-
|----------------|---------|------------------------------------
|
|
158
|
-
|`type` |string |The type of version change that occurred ("major", "minor", "patch", etc.) If there was no version change, then the the type is "none".
|
|
159
|
-
|`package` |string |The name of the NPM package that was published
|
|
160
|
-
|`version` |string |The version number that was published
|
|
161
|
-
|`oldVersion` |string |The version number that was previously published to NPM
|
|
162
|
-
|`tag` |string |The tag that the package was published to.
|
|
163
|
-
|`access` |string |Indicates whether the published package is publicly visible or restricted to members of your NPM organization.
|
|
164
|
-
|`dryRun` |boolean |Indicates whether NPM was run in "dry run" mode
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
Command Line Interface
|
|
169
|
-
------------------------------
|
|
170
|
-
To use npm-package from as a command-line tool in your terminal, you'll need to install it globally using [NPM](https://docs.npmjs.com/about-npm/):
|
|
165
|
+
[npm]: https://docs.npmjs.com/about-npm/
|
|
171
166
|
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
### Usage
|
|
168
|
+
|
|
169
|
+
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.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import type { Options } from "@jsdevtools/npm-publish";
|
|
174
173
|
```
|
|
175
174
|
|
|
176
|
-
|
|
175
|
+
| Name | Type | Default | Description |
|
|
176
|
+
| -------------------- | ---------------------- | -------------------------------- | ----------------------------------------------------------------------------- |
|
|
177
|
+
| `token` | string | **required** | Authentication token to use with the configured registry. |
|
|
178
|
+
| `registry` | string, `URL` | `https://registry.npmjs.org/` \* | Registry URL to use. |
|
|
179
|
+
| `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish |
|
|
180
|
+
| `tag` | string | `latest` \* | [Distribution tag][npm-tag] to publish to. |
|
|
181
|
+
| `access` | `public`, `restricted` | [npm defaults][npm-access] \* | Whether the package should be publicly visible or restricted. |
|
|
182
|
+
| `provenance` | boolean | `false` \* | Run `npm publish` with the `--provenance` flag to add provenance statements. |
|
|
183
|
+
| `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
|
|
184
|
+
| `dryRun` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
|
|
185
|
+
| `logger` | object | `undefined` | Logging interface with `debug`, `info`, and `error` log methods. |
|
|
186
|
+
| `temporaryDirectory` | string | `os.tmpdir()` | Temporary directory to hold a generated `.npmrc` file |
|
|
177
187
|
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
\* Default values for these options may be specified using `publishConfig` in `package.json`.
|
|
189
|
+
|
|
190
|
+
### Output
|
|
191
|
+
|
|
192
|
+
The `npmPublish()` function returns a promise of a `Results` object. In TypeScript, the `Results` interface is available as an import.
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import type { Results } from "@jsdevtools/npm-publish";
|
|
180
196
|
```
|
|
181
197
|
|
|
182
|
-
|
|
198
|
+
| Name | Type | Description |
|
|
199
|
+
| ------------ | --------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
200
|
+
| `id` | Optional string | Package identifier of the release: `${name}@${version}` or `undefined` if no release. |
|
|
201
|
+
| `type` | Optional string | [Semver release type][], `initial` if first release, `different` if other change, or `undefined` if no release. |
|
|
202
|
+
| `name` | string | Name of the package. |
|
|
203
|
+
| `version` | string | Version of the package. |
|
|
204
|
+
| `oldVersion` | Optional string | Previously published version on `tag` or `undefined` if no previous version. |
|
|
205
|
+
| `tag` | string | [Distribution tag][npm-tag] that the package was published to. |
|
|
206
|
+
| `access` | Optional string | [Access level][npm-access] the package was published with, or `undefined` if scoped-package defaults were used. |
|
|
207
|
+
| `registry` | `URL` | Registry the package was published to. |
|
|
208
|
+
| `dryRun` | boolean | Whether `npm publish` was run in "dry run" mode. |
|
|
209
|
+
|
|
210
|
+
## Command Line Interface
|
|
211
|
+
|
|
212
|
+
You can also use `npm-publish` as a command-line tool in your terminal.
|
|
183
213
|
|
|
184
214
|
```bash
|
|
185
|
-
npm
|
|
215
|
+
npm install --save-dev @jsdevtools/npm-publish
|
|
186
216
|
```
|
|
187
217
|
|
|
188
|
-
|
|
189
|
-
Run `npm-publish --help` to see the full list of options available.
|
|
218
|
+
You can then use it in your terminal or in `npm run` scripts.
|
|
190
219
|
|
|
220
|
+
```bash
|
|
221
|
+
npx npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE
|
|
191
222
|
```
|
|
192
|
-
> npm-publish --help
|
|
193
223
|
|
|
194
|
-
|
|
224
|
+
You can customize your call with options to change the registry, package, etc.
|
|
195
225
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
--registry <url> The NPM registry URL to use
|
|
226
|
+
```bash
|
|
227
|
+
npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE --registry http://example.com ./path/to/package
|
|
228
|
+
```
|
|
200
229
|
|
|
201
|
-
|
|
202
|
-
using "npm install <package-name>@<tag>"
|
|
230
|
+
### Options
|
|
203
231
|
|
|
204
|
-
|
|
205
|
-
"restricted" = The package will only be visible to members
|
|
206
|
-
of your NPM organization.
|
|
232
|
+
Run `npm-publish --help` to see the full list of options available.
|
|
207
233
|
|
|
208
|
-
|
|
209
|
-
|
|
234
|
+
```
|
|
235
|
+
Usage:
|
|
210
236
|
|
|
211
|
-
|
|
237
|
+
npm-publish <options> [package]
|
|
212
238
|
|
|
213
|
-
|
|
239
|
+
Arguments:
|
|
214
240
|
|
|
215
|
-
|
|
241
|
+
package The path to the package to publish.
|
|
242
|
+
May be a directory, package.json, or .tgz file.
|
|
243
|
+
Defaults to the package in the current directory.
|
|
216
244
|
|
|
217
|
-
|
|
245
|
+
Options:
|
|
218
246
|
|
|
219
|
-
|
|
220
|
-
Can be a directory path, or the path of a package.json file.
|
|
221
|
-
Defaults to the current directory.
|
|
222
|
-
```
|
|
247
|
+
--token <token> (Required) npm authentication token.
|
|
223
248
|
|
|
249
|
+
--registry <url> Registry to read from and write to.
|
|
250
|
+
Defaults to "https://registry.npmjs.org/".
|
|
224
251
|
|
|
252
|
+
--tag <tag> The distribution tag to check against and publish to.
|
|
253
|
+
Defaults to "latest".
|
|
225
254
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
Contributions, enhancements, and bug-fixes are welcome! [Open an issue](https://github.com/JS-DevTools/npm-publish/issues) on GitHub and [submit a pull request](https://github.com/JS-DevTools/npm-publish/pulls).
|
|
255
|
+
--access <access> Package access, may be "public" or "restricted".
|
|
256
|
+
See npm documentation for details.
|
|
229
257
|
|
|
230
|
-
|
|
231
|
-
|
|
258
|
+
--provenance Publish with provenance statements.
|
|
259
|
+
See npm documentation for details.
|
|
232
260
|
|
|
233
|
-
|
|
234
|
-
|
|
261
|
+
--strategy <strategy> Publish strategy, may be "all" or "upgrade".
|
|
262
|
+
Defaults to "all", see documentation for details.
|
|
235
263
|
|
|
236
|
-
|
|
237
|
-
|
|
264
|
+
--dry-run Do not actually publish anything.
|
|
265
|
+
--quiet Only print errors.
|
|
266
|
+
--debug Print debug logs.
|
|
238
267
|
|
|
239
|
-
|
|
240
|
-
|
|
268
|
+
-v, --version Print the version number.
|
|
269
|
+
-h --help Show usage text.
|
|
241
270
|
|
|
242
|
-
|
|
243
|
-
`npm test`
|
|
271
|
+
Examples:
|
|
244
272
|
|
|
273
|
+
$ npm-publish --token abc123 ./my-package
|
|
274
|
+
```
|
|
245
275
|
|
|
276
|
+
## License
|
|
246
277
|
|
|
247
|
-
License
|
|
248
|
-
--------------------------
|
|
249
278
|
npm-publish is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.
|
|
250
279
|
|
|
251
280
|
This package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/JS-DevTools/npm-publish) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
|
|
252
281
|
|
|
282
|
+
## Big Thanks To
|
|
253
283
|
|
|
254
|
-
|
|
255
|
-
Big Thanks To
|
|
256
|
-
--------------------------
|
|
257
284
|
Thanks to these awesome companies for their support of Open Source developers ❤
|
|
258
285
|
|
|
259
286
|
[](https://github.com/open-source)
|
package/bin/npm-publish.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable unicorn/prefer-module, unicorn/prefer-top-level-await */
|
|
2
3
|
"use strict";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
const process = require("node:process");
|
|
6
|
+
const { version } = require("../package.json");
|
|
7
|
+
const { main } = require("../lib/cli/index.js");
|
|
8
|
+
|
|
9
|
+
main(process.argv.slice(2), version).catch((error) => {
|
|
10
|
+
console.error(error);
|
|
11
|
+
process.exitCode = 1;
|
|
12
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Logger } from "../options.js";
|
|
2
|
+
/** Logger using the methods from @actions/core. */
|
|
3
|
+
export declare const logger: Logger;
|
|
4
|
+
/**
|
|
5
|
+
* Get input by name.
|
|
6
|
+
*
|
|
7
|
+
* @param name Input name
|
|
8
|
+
* @returns The input string value, or undefined if not set
|
|
9
|
+
*/
|
|
10
|
+
export declare function getInput<T extends string>(name: string): T | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Get a required secret input by name.
|
|
13
|
+
*
|
|
14
|
+
* @param name Input name
|
|
15
|
+
* @returns The input secret value.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getRequiredSecretInput(name: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Get a boolean input by name.
|
|
20
|
+
*
|
|
21
|
+
* @param name Input name
|
|
22
|
+
* @returns True if value is "true", false if not
|
|
23
|
+
*/
|
|
24
|
+
export declare function getBooleanInput(name: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Set the action as failed due to an error.
|
|
27
|
+
*
|
|
28
|
+
* @param error An value from a `catch`
|
|
29
|
+
*/
|
|
30
|
+
export declare function setFailed(error: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Set an output by name.
|
|
33
|
+
*
|
|
34
|
+
* @param name Output name
|
|
35
|
+
* @param value Output value
|
|
36
|
+
*/
|
|
37
|
+
export declare function setOutput(name: string, value: string | boolean): void;
|
|
38
|
+
/**
|
|
39
|
+
* Set an output by name.
|
|
40
|
+
*
|
|
41
|
+
* @param name Output name
|
|
42
|
+
* @param value Output value
|
|
43
|
+
* @param defaultValue Default value if value is undefined.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setOutput(name: string, value: string | boolean | undefined, defaultValue: string | boolean): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setOutput = exports.setFailed = exports.getBooleanInput = exports.getRequiredSecretInput = exports.getInput = exports.logger = void 0;
|
|
4
|
+
/** Wrapper module for @actions/core */
|
|
5
|
+
const core_1 = require("@actions/core");
|
|
6
|
+
/** Logger using the methods from @actions/core. */
|
|
7
|
+
exports.logger = {
|
|
8
|
+
debug: core_1.debug,
|
|
9
|
+
info: core_1.info,
|
|
10
|
+
error: core_1.error,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Get input by name.
|
|
14
|
+
*
|
|
15
|
+
* @param name Input name
|
|
16
|
+
* @returns The input string value, or undefined if not set
|
|
17
|
+
*/
|
|
18
|
+
function getInput(name) {
|
|
19
|
+
const inputString = (0, core_1.getInput)(name);
|
|
20
|
+
return inputString.length > 0 ? inputString : undefined;
|
|
21
|
+
}
|
|
22
|
+
exports.getInput = getInput;
|
|
23
|
+
/**
|
|
24
|
+
* Get a required secret input by name.
|
|
25
|
+
*
|
|
26
|
+
* @param name Input name
|
|
27
|
+
* @returns The input secret value.
|
|
28
|
+
*/
|
|
29
|
+
function getRequiredSecretInput(name) {
|
|
30
|
+
const inputString = (0, core_1.getInput)(name, { required: true });
|
|
31
|
+
(0, core_1.setSecret)(inputString);
|
|
32
|
+
return inputString;
|
|
33
|
+
}
|
|
34
|
+
exports.getRequiredSecretInput = getRequiredSecretInput;
|
|
35
|
+
/**
|
|
36
|
+
* Get a boolean input by name.
|
|
37
|
+
*
|
|
38
|
+
* @param name Input name
|
|
39
|
+
* @returns True if value is "true", false if not
|
|
40
|
+
*/
|
|
41
|
+
function getBooleanInput(name) {
|
|
42
|
+
return (0, core_1.getInput)(name) === "true";
|
|
43
|
+
}
|
|
44
|
+
exports.getBooleanInput = getBooleanInput;
|
|
45
|
+
/**
|
|
46
|
+
* Set the action as failed due to an error.
|
|
47
|
+
*
|
|
48
|
+
* @param error An value from a `catch`
|
|
49
|
+
*/
|
|
50
|
+
function setFailed(error) {
|
|
51
|
+
(0, core_1.setFailed)(error);
|
|
52
|
+
}
|
|
53
|
+
exports.setFailed = setFailed;
|
|
54
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
55
|
+
function setOutput(name, value, defaultValue) {
|
|
56
|
+
(0, core_1.setOutput)(name, value ?? defaultValue);
|
|
57
|
+
}
|
|
58
|
+
exports.setOutput = setOutput;
|
|
59
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/action/core.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,wCAQuB;AAIvB,mDAAmD;AACtC,QAAA,MAAM,GAAW;IAC5B,KAAK,EAAE,YAAU;IACjB,IAAI,EAAE,WAAS;IACf,KAAK,EAAE,YAAU;CAClB,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,QAAQ,CAAmB,IAAY;IACrD,MAAM,WAAW,GAAG,IAAA,eAAU,EAAC,IAAI,CAAC,CAAC;IACrC,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAE,WAAiB,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC;AAHD,4BAGC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,IAAY;IACjD,MAAM,WAAW,GAAG,IAAA,eAAU,EAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,IAAA,gBAAW,EAAC,WAAW,CAAC,CAAC;IACzB,OAAO,WAAW,CAAC;AACrB,CAAC;AAJD,wDAIC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAA,eAAU,EAAC,IAAI,CAAC,KAAK,MAAM,CAAC;AACrC,CAAC;AAFD,0CAEC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAC,KAAc;IACtC,IAAA,gBAAW,EAAC,KAAc,CAAC,CAAC;AAC9B,CAAC;AAFD,8BAEC;AAuBD,+CAA+C;AAC/C,SAAgB,SAAS,CACvB,IAAY,EACZ,KAAmC,EACnC,YAA2C;IAE3C,IAAA,gBAAW,EAAC,IAAI,EAAE,KAAK,IAAI,YAAY,CAAC,CAAC;AAC3C,CAAC;AAND,8BAMC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
/** Action entry point */
|
|
27
|
+
const index_js_1 = require("../index.js");
|
|
28
|
+
const core = __importStar(require("./core.js"));
|
|
29
|
+
/** Run the action. */
|
|
30
|
+
async function run() {
|
|
31
|
+
const results = await (0, index_js_1.npmPublish)({
|
|
32
|
+
token: core.getRequiredSecretInput("token"),
|
|
33
|
+
registry: core.getInput("registry"),
|
|
34
|
+
package: core.getInput("package"),
|
|
35
|
+
tag: core.getInput("tag"),
|
|
36
|
+
access: core.getInput("access"),
|
|
37
|
+
provenance: core.getBooleanInput("provenance"),
|
|
38
|
+
strategy: core.getInput("strategy"),
|
|
39
|
+
dryRun: core.getBooleanInput("dry-run"),
|
|
40
|
+
logger: core.logger,
|
|
41
|
+
temporaryDirectory: process.env["RUNNER_TEMP"],
|
|
42
|
+
});
|
|
43
|
+
core.setOutput("id", results.id, "");
|
|
44
|
+
core.setOutput("name", results.name);
|
|
45
|
+
core.setOutput("version", results.version);
|
|
46
|
+
core.setOutput("type", results.type, "");
|
|
47
|
+
core.setOutput("old-version", results.oldVersion, "");
|
|
48
|
+
core.setOutput("registry", results.registry.href);
|
|
49
|
+
core.setOutput("tag", results.tag);
|
|
50
|
+
core.setOutput("access", results.access, "default");
|
|
51
|
+
core.setOutput("strategy", results.strategy);
|
|
52
|
+
core.setOutput("dry-run", results.dryRun);
|
|
53
|
+
}
|
|
54
|
+
run().catch((error) => core.setFailed(error));
|
|
55
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/action/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAyB;AACzB,0CAAyC;AACzC,gDAAkC;AAElC,sBAAsB;AACtB,KAAK,UAAU,GAAG;IAChB,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAU,EAAC;QAC/B,KAAK,EAAE,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;QAC3C,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QACnC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACjC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC/B,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC;QAC9C,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QACnC,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;QACvC,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;KAC/C,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACzC,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACtD,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC"}
|
package/lib/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export declare const USAGE = "\nUsage:\n\n npm-publish <options> [package]\n\nArguments:\n\n package The path to the package to publish.\n May be a directory, package.json, or .tgz file.\n Defaults to the package in the current directory.\n\nOptions:\n\n --token <token> (Required) npm authentication token.\n\n --registry <url> Registry to read from and write to.\n Defaults to \"https://registry.npmjs.org/\".\n\n --tag <tag> The distribution tag to check against and publish to.\n Defaults to \"latest\".\n\n --access <access> Package access, may be \"public\" or \"restricted\".\n See npm documentation for details.\n\n --provenance Publish with provenance statements.\n See npm documentation for details.\n\n --strategy <strategy> Publish strategy, may be \"all\" or \"upgrade\".\n Defaults to \"all\", see documentation for details.\n\n --dry-run Do not actually publish anything.\n --quiet Only print errors.\n --debug Print debug logs.\n\n -v, --version Print the version number.\n -h, --help Show usage text.\n\nExamples:\n\n $ npm-publish --token abc123 ./my-package\n";
|
|
1
2
|
/**
|
|
2
3
|
* The main entry point of the CLI
|
|
3
4
|
*
|
|
4
|
-
* @param
|
|
5
|
+
* @param argv - The list of argument strings passed to the program.
|
|
6
|
+
* @param version - The version of this program.
|
|
5
7
|
*/
|
|
6
|
-
export declare function main(
|
|
8
|
+
export declare function main(argv: string[], version: string): Promise<void>;
|