@jsdevtools/npm-publish 1.4.2 → 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.
Files changed (90) hide show
  1. package/README.md +161 -147
  2. package/bin/npm-publish.js +10 -2
  3. package/lib/action/core.d.ts +45 -0
  4. package/lib/action/core.js +59 -0
  5. package/lib/action/core.js.map +1 -0
  6. package/lib/action/main.js +54 -0
  7. package/lib/action/main.js.map +1 -0
  8. package/lib/cli/index.d.ts +4 -2
  9. package/lib/cli/index.js +57 -53
  10. package/lib/cli/index.js.map +1 -1
  11. package/lib/cli/parse-cli-arguments.d.ts +17 -0
  12. package/lib/cli/parse-cli-arguments.js +39 -0
  13. package/lib/cli/parse-cli-arguments.js.map +1 -0
  14. package/lib/compare-versions.d.ts +20 -0
  15. package/lib/compare-versions.js +36 -0
  16. package/lib/compare-versions.js.map +1 -0
  17. package/lib/errors.d.ts +36 -0
  18. package/lib/errors.js +114 -0
  19. package/lib/errors.js.map +1 -0
  20. package/lib/format-publish-result.d.ts +12 -0
  21. package/lib/format-publish-result.js +36 -0
  22. package/lib/format-publish-result.js.map +1 -0
  23. package/lib/index.d.ts +4 -5
  24. package/lib/index.js +11 -10
  25. package/lib/index.js.map +1 -1
  26. package/lib/normalize-options.d.ts +26 -1
  27. package/lib/normalize-options.js +86 -13
  28. package/lib/normalize-options.js.map +1 -1
  29. package/lib/npm/call-npm-cli.d.ts +16 -0
  30. package/lib/npm/call-npm-cli.js +91 -0
  31. package/lib/npm/call-npm-cli.js.map +1 -0
  32. package/lib/npm/get-publish-arguments.d.ts +9 -0
  33. package/lib/npm/get-publish-arguments.js +29 -0
  34. package/lib/npm/get-publish-arguments.js.map +1 -0
  35. package/lib/npm/index.d.ts +29 -0
  36. package/lib/npm/index.js +41 -0
  37. package/lib/npm/index.js.map +1 -0
  38. package/lib/npm/use-npm-environment.d.ts +13 -0
  39. package/lib/npm/use-npm-environment.js +42 -0
  40. package/lib/npm/use-npm-environment.js.map +1 -0
  41. package/lib/npm-publish.d.ts +7 -4
  42. package/lib/npm-publish.js +29 -25
  43. package/lib/npm-publish.js.map +1 -1
  44. package/lib/options.d.ts +58 -46
  45. package/lib/options.js +5 -0
  46. package/lib/options.js.map +1 -1
  47. package/lib/read-manifest.d.ts +25 -1
  48. package/lib/read-manifest.js +119 -22
  49. package/lib/read-manifest.js.map +1 -1
  50. package/lib/results.d.ts +26 -28
  51. package/package.json +43 -35
  52. package/src/action/core.ts +91 -0
  53. package/src/action/main.ts +31 -0
  54. package/src/cli/index.ts +69 -0
  55. package/src/cli/parse-cli-arguments.ts +48 -0
  56. package/src/compare-versions.ts +52 -0
  57. package/src/errors.ts +130 -0
  58. package/src/format-publish-result.ts +40 -0
  59. package/src/index.ts +7 -0
  60. package/src/normalize-options.ts +119 -0
  61. package/src/npm/call-npm-cli.ts +98 -0
  62. package/src/npm/get-publish-arguments.ts +34 -0
  63. package/src/npm/index.ts +64 -0
  64. package/src/npm/use-npm-environment.ts +51 -0
  65. package/src/npm-publish.ts +47 -0
  66. package/src/options.ts +96 -0
  67. package/src/read-manifest.ts +143 -0
  68. package/src/results.ts +45 -0
  69. package/CHANGELOG.md +0 -49
  70. package/lib/action/index.js +0 -67
  71. package/lib/action/index.js.map +0 -1
  72. package/lib/cli/exit-code.d.ts +0 -1
  73. package/lib/cli/exit-code.js +0 -16
  74. package/lib/cli/exit-code.js.map +0 -1
  75. package/lib/cli/help.d.ts +0 -1
  76. package/lib/cli/help.js +0 -28
  77. package/lib/cli/help.js.map +0 -1
  78. package/lib/cli/parse-args.d.ts +0 -1
  79. package/lib/cli/parse-args.js +0 -58
  80. package/lib/cli/parse-args.js.map +0 -1
  81. package/lib/npm-config.d.ts +0 -1
  82. package/lib/npm-config.js +0 -85
  83. package/lib/npm-config.js.map +0 -1
  84. package/lib/npm-env.d.ts +0 -6
  85. package/lib/npm-env.js +0 -24
  86. package/lib/npm-env.js.map +0 -1
  87. package/lib/npm.d.ts +0 -1
  88. package/lib/npm.js +0 -95
  89. package/lib/npm.js.map +0 -1
  90. /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
- [![Cross-Platform Compatibility](https://jstools.dev/img/badges/os-badges.svg)](https://github.com/JS-DevTools/npm-publish/actions)
5
3
  [![Build Status](https://github.com/JS-DevTools/npm-publish/workflows/CI-CD/badge.svg)](https://github.com/JS-DevTools/npm-publish/actions)
6
-
7
- [![Coverage Status](https://coveralls.io/repos/github/JS-DevTools/npm-publish/badge.svg?branch=master)](https://coveralls.io/github/JS-DevTools/npm-publish)
8
- [![Dependencies](https://david-dm.org/JS-DevTools/npm-publish/status.svg)](https://david-dm.org/JS-DevTools/npm-publish)
9
-
4
+ [![Coverage Status](https://coveralls.io/repos/github/JS-DevTools/npm-publish/badge.svg?branch=main)](https://coveralls.io/github/JS-DevTools/npm-publish)
10
5
  [![npm](https://img.shields.io/npm/v/@jsdevtools/npm-publish.svg)](https://www.npmjs.com/package/@jsdevtools/npm-publish)
11
6
  [![License](https://img.shields.io/npm/l/@jsdevtools/npm-publish.svg)](LICENSE)
12
7
  [![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](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 NPM
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 NPM access token secret. Doesn't write it to `~/.npmrc`
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,11 +35,42 @@ 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
- GitHub Action
48
- -----------------------------
49
- To use the GitHub Action, you'll need to add it as a step in your [Workflow file](https://help.github.com/en/actions/automating-your-workflow-with-github-actions). By default, the only thing you need to do is set the `token` parameter to your [NPM auth token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens).
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
+ - - if: ${{ steps.publish.outputs.type != 'none' }}
45
+ + - if: ${{ steps.publish.outputs.type }}
46
+ run: echo "Version changed!"
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
76
  on: push
@@ -55,205 +79,195 @@ jobs:
55
79
  publish:
56
80
  runs-on: ubuntu-latest
57
81
  steps:
58
- - uses: actions/checkout@v1
59
- - uses: actions/setup-node@v1
82
+ - uses: actions/checkout@v3
83
+ - uses: actions/setup-node@v3
60
84
  with:
61
- node-version: 10
62
- - run: npm install
85
+ node-version: 18
86
+ - run: npm ci
63
87
  - run: npm test
64
- - uses: JS-DevTools/npm-publish@v1
88
+ - uses: JS-DevTools/npm-publish@v2
65
89
  with:
66
90
  token: ${{ secrets.NPM_TOKEN }}
67
91
  ```
68
92
 
93
+ [workflow file]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions
94
+ [npm authentication token]: https://docs.npmjs.com/creating-and-viewing-authentication-tokens
69
95
 
96
+ ### Usage
70
97
 
71
- Input Parameters
72
- --------------------------
73
- You can set any or all of the following input parameters:
98
+ You can set any or all of the following input parameters using `with`:
74
99
 
75
- |Name |Type |Required? |Default |Description
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
100
+ | Name | Type | Default | Description |
101
+ | ---------- | ---------------------- | ----------------------------- | ----------------------------------------------------------------------------- |
102
+ | `token` | string | **required** | Authentication token to use with the configured registry. |
103
+ | `registry` | string | `https://registry.npmjs.org/` | Registry URL to use. |
104
+ | `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish |
105
+ | `tag` | string | `latest` | [Distribution tag][npm-tag] to publish to. |
106
+ | `access` | `public`, `restricted` | [npm defaults][npm-access] | Whether the package should be publicly visible or restricted. |
107
+ | `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
108
+ | `dry-run` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
84
109
 
110
+ [npm-tag]: https://docs.npmjs.com/cli/v9/commands/npm-publish#tag
111
+ [npm-access]: https://docs.npmjs.com/cli/v9/commands/npm-publish#access
85
112
 
113
+ ### Output
86
114
 
87
- Output Variables
88
- --------------------------
89
115
  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
116
 
91
117
  ```yaml
92
118
  steps:
93
119
  - id: publish
94
- uses: JS-DevTools/npm-publish@v1
120
+ uses: JS-DevTools/npm-publish@v2
95
121
  with:
96
122
  token: ${{ secrets.NPM_TOKEN }}
97
123
 
98
- - if: steps.publish.outputs.type != 'none'
124
+ - if: ${{ steps.publish.outputs.type }}
99
125
  run: |
100
- echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}"
126
+ echo "Version changed!"
101
127
  ```
102
128
 
129
+ | Name | Type | Description |
130
+ | ------------- | ------- | ------------------------------------------------------------------------------------------------------------- |
131
+ | `id` | string | Package identifier of the release: `${name}@${version}` or empty if no release. |
132
+ | `type` | string | [Semver release type][], `initial` if first release, `different` if other change, or empty if no release. |
133
+ | `name` | string | Name of the package. |
134
+ | `version` | string | Version of the package. |
135
+ | `old-version` | string | Previously published version on `tag` or empty if no previous version on tag. |
136
+ | `tag` | string | [Distribution tag][npm-tag] the package was published to. |
137
+ | `access` | string | [Access level][npm-access] the package was published with, or `default` if scoped-package defaults were used. |
138
+ | `dry-run` | boolean | Whether `npm publish` was run in "dry run" mode. |
103
139
 
104
- |Variable |Type |Description
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
112
-
140
+ [semver release type]: https://github.com/npm/node-semver#release_types
113
141
 
142
+ ## JavaScript Function
114
143
 
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/):
144
+ To use npm-package in your JavaScript code, you'll need to install it using [npm][] or other package manager of choice:
118
145
 
119
146
  ```bash
120
- npm install @jsdevtools/npm-publish
147
+ npm install --save-dev @jsdevtools/npm-publish
121
148
  ```
122
149
 
123
150
  You can then import it and use it in your code like this:
124
151
 
125
152
  ```javascript
126
- const npmPublish = require("@jsdevtools/npm-publish");
153
+ import { npmPublish } from "@jsdevtools/npm-publish";
127
154
 
128
155
  // 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
- });
156
+ await npmPublish({ token: "YOUR_NPM_AUTH_TOKEN_HERE" });
136
157
  ```
137
158
 
138
- ### Options
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/):
159
+ [npm]: https://docs.npmjs.com/about-npm/
171
160
 
172
- ```bash
173
- npm install -g @jsdevtools/npm-publish
174
- ```
161
+ ### Usage
175
162
 
176
- You can then use it in your terminal or in Bash scripts. You can call it without any arguments, and it will publish the current directory using NPM's default credentials.
163
+ 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.
177
164
 
178
- ```bash
179
- npm-publish
165
+ ```ts
166
+ import type { Options } from "@jsdevtools/npm-publish";
180
167
  ```
181
168
 
182
- Or you can call it with arguments to explicitly set the NPM auth token, registry, package path, etc.
169
+ | Name | Type | Default | Description |
170
+ | -------------------- | ---------------------- | ----------------------------- | ----------------------------------------------------------------------------- |
171
+ | `token` | string | **required** | Authentication token to use with the configured registry. |
172
+ | `registry` | string, `URL` | `https://registry.npmjs.org/` | Registry URL to use. |
173
+ | `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish |
174
+ | `tag` | string | `latest` | [Distribution tag][npm-tag] to publish to. |
175
+ | `access` | `public`, `restricted` | [npm defaults][npm-access] | Whether the package should be publicly visible or restricted. |
176
+ | `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
177
+ | `dryRun` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
178
+ | `logger` | object | `undefined` | Logging interface with `debug`, `info`, and `error` log methods. |
179
+ | `temporaryDirectory` | string | `os.tmpdir()` | Temporary directory to hold a generated `.npmrc` file |
183
180
 
184
- ```bash
185
- npm-publish --token=YOUR_NPM_AUTH_TOKEN_HERE ./path/to/package.json
186
- ```
181
+ ### Output
187
182
 
188
- ### Options
189
- Run `npm-publish --help` to see the full list of options available.
183
+ The `npmPublish()` function returns a promise of a `Results` object. In TypeScript, the `Results` interface is available as an import.
190
184
 
185
+ ```ts
186
+ import type { Results } from "@jsdevtools/npm-publish";
191
187
  ```
192
- > npm-publish --help
193
188
 
194
- Usage: npm-publish [options] [package_path]
189
+ | Name | Type | Description |
190
+ | ------------ | --------------- | --------------------------------------------------------------------------------------------------------------- |
191
+ | `id` | Optional string | Package identifier of the release: `${name}@${version}` or `undefined` if no release. |
192
+ | `type` | Optional string | [Semver release type][], `initial` if first release, `different` if other change, or `undefined` if no release. |
193
+ | `name` | string | Name of the package. |
194
+ | `version` | string | Version of the package. |
195
+ | `oldVersion` | Optional string | Previously published version on `tag` or `undefined` if no previous version. |
196
+ | `tag` | string | [Distribution tag][npm-tag] that the package was published to. |
197
+ | `access` | Optional string | [Access level][npm-access] the package was published with, or `undefined` if scoped-package defaults were used. |
198
+ | `dryRun` | boolean | Whether `npm publish` was run in "dry run" mode. |
195
199
 
196
- options:
197
- --token <token> The NPM access token to use when publishing
200
+ ## Command Line Interface
198
201
 
199
- --registry <url> The NPM registry URL to use
202
+ You can also use `npm-publish` as a command-line tool in your terminal.
200
203
 
201
- --tag <tag> The tag to publish to. Allows the package to be installed
202
- using "npm install <package-name>@<tag>"
204
+ ```bash
205
+ npm install --save-dev @jsdevtools/npm-publish
206
+ ```
203
207
 
204
- --access <access> "public" = The package will be publicly visible.
205
- "restricted" = The package will only be visible to members
206
- of your NPM organization.
208
+ You can then use it in your terminal or in `npm run` scripts.
207
209
 
208
- --dry-run Don't actually publish to NPM, but report what would have
209
- been published
210
+ ```bash
211
+ npx npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE
212
+ ```
210
213
 
211
- --debug, -d Enable debug mode, with increased logging
214
+ You can customize your call with options to change the registry, package, etc.
212
215
 
213
- --quiet, -q Suppress unnecessary output
216
+ ```bash
217
+ npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE --registry http://example.com ./path/to/package
218
+ ```
214
219
 
215
- --version, -v Print the version number
220
+ ### Options
216
221
 
217
- --help, -h Show help
222
+ Run `npm-publish --help` to see the full list of options available.
218
223
 
219
- package_path The absolute or relative path of the NPM package to publish.
220
- Can be a directory path, or the path of a package.json file.
221
- Defaults to the current directory.
222
224
  ```
225
+ Usage:
226
+
227
+ npm-publish <options> [package]
223
228
 
229
+ Arguments:
224
230
 
231
+ package The path to the package to publish.
232
+ May be a directory, package.json, or .tgz file.
233
+ Defaults to the package in the current directory.
225
234
 
226
- Contributing
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).
235
+ Options:
229
236
 
230
- #### Building
231
- To build the project locally on your computer:
237
+ --token <token> (Required) npm authentication token.
232
238
 
233
- 1. __Clone this repo__<br>
234
- `git clone https://github.com/JS-DevTools/npm-publish.git`
239
+ --registry <url> Registry to read from and write to.
240
+ Defaults to "https://registry.npmjs.org/".
235
241
 
236
- 2. __Install dependencies__<br>
237
- `npm install`
242
+ --tag <tag> The distribution tag to check against and publish to.
243
+ Defaults to "latest".
238
244
 
239
- 3. __Build the code__<br>
240
- `npm run build`
245
+ --access <access> Package access, may be "public" or "restricted".
246
+ See documentation for details.
241
247
 
242
- 4. __Run the tests__<br>
243
- `npm test`
248
+ --strategy <strategy> Publish strategy, may be "all" or "upgrade".
249
+ Defaults to "all", see documentation for details.
244
250
 
251
+ --dry-run Do not actually publish anything.
252
+ --quiet Only print errors.
253
+ --debug Print debug logs.
245
254
 
255
+ -v, --version Print the version number.
256
+ -h --help Show usage text.
257
+
258
+ Examples:
259
+
260
+ $ npm-publish --token abc123 ./my-package
261
+ ```
262
+
263
+ ## License
246
264
 
247
- License
248
- --------------------------
249
265
  npm-publish is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.
250
266
 
251
267
  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
268
 
269
+ ## Big Thanks To
253
270
 
254
-
255
- Big Thanks To
256
- --------------------------
257
271
  Thanks to these awesome companies for their support of Open Source developers ❤
258
272
 
259
273
  [![GitHub](https://jstools.dev/img/badges/github.svg)](https://github.com/open-source)
@@ -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
- const { main } = require("../lib/cli");
4
- main(process.argv.slice(2));
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,54 @@
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
+ strategy: core.getInput("strategy"),
38
+ dryRun: core.getBooleanInput("dry-run"),
39
+ logger: core.logger,
40
+ temporaryDirectory: process.env["RUNNER_TEMP"],
41
+ });
42
+ core.setOutput("id", results.id, "");
43
+ core.setOutput("name", results.name);
44
+ core.setOutput("version", results.version);
45
+ core.setOutput("type", results.type, "");
46
+ core.setOutput("old-version", results.oldVersion, "");
47
+ core.setOutput("registry", results.registry.href);
48
+ core.setOutput("tag", results.tag);
49
+ core.setOutput("access", results.access, "default");
50
+ core.setOutput("strategy", results.strategy);
51
+ core.setOutput("dry-run", results.dryRun);
52
+ }
53
+ run().catch((error) => core.setFailed(error));
54
+ //# 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,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"}
@@ -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 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 args - The command-line arguments
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(args: string[]): Promise<void>;
8
+ export declare function main(argv: string[], version: string): Promise<void>;