@jsdevtools/npm-publish 2.0.0 → 2.2.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 (77) hide show
  1. package/README.md +92 -32
  2. package/lib/action/core.d.ts +2 -2
  3. package/lib/action/core.js +7 -2
  4. package/lib/action/core.js.map +1 -1
  5. package/lib/action/main.js +2 -0
  6. package/lib/action/main.js.map +1 -1
  7. package/lib/cli/index.d.ts +1 -1
  8. package/lib/cli/index.js +7 -1
  9. package/lib/cli/index.js.map +1 -1
  10. package/lib/cli/parse-cli-arguments.js +8 -1
  11. package/lib/cli/parse-cli-arguments.js.map +1 -1
  12. package/lib/compare-and-publish/compare-and-publish.d.ts +21 -0
  13. package/lib/compare-and-publish/compare-and-publish.js +53 -0
  14. package/lib/compare-and-publish/compare-and-publish.js.map +1 -0
  15. package/lib/compare-and-publish/compare-versions.d.ts +16 -0
  16. package/lib/compare-and-publish/compare-versions.js +41 -0
  17. package/lib/compare-and-publish/compare-versions.js.map +1 -0
  18. package/lib/compare-and-publish/get-arguments.d.ts +21 -0
  19. package/lib/compare-and-publish/get-arguments.js +50 -0
  20. package/lib/compare-and-publish/get-arguments.js.map +1 -0
  21. package/lib/compare-and-publish/index.d.ts +1 -0
  22. package/lib/compare-and-publish/index.js +18 -0
  23. package/lib/compare-and-publish/index.js.map +1 -0
  24. package/lib/errors.d.ts +3 -0
  25. package/lib/errors.js +8 -1
  26. package/lib/errors.js.map +1 -1
  27. package/lib/format-publish-result.d.ts +3 -3
  28. package/lib/format-publish-result.js +5 -5
  29. package/lib/format-publish-result.js.map +1 -1
  30. package/lib/normalize-options.d.ts +5 -2
  31. package/lib/normalize-options.js +15 -12
  32. package/lib/normalize-options.js.map +1 -1
  33. package/lib/npm/call-npm-cli.d.ts +27 -4
  34. package/lib/npm/call-npm-cli.js +50 -27
  35. package/lib/npm/call-npm-cli.js.map +1 -1
  36. package/lib/npm/index.d.ts +2 -29
  37. package/lib/npm/index.js +16 -38
  38. package/lib/npm/index.js.map +1 -1
  39. package/lib/npm/use-npm-environment.d.ts +4 -2
  40. package/lib/npm/use-npm-environment.js +7 -5
  41. package/lib/npm/use-npm-environment.js.map +1 -1
  42. package/lib/npm-publish.js +7 -12
  43. package/lib/npm-publish.js.map +1 -1
  44. package/lib/options.d.ts +28 -9
  45. package/lib/read-manifest.d.ts +4 -7
  46. package/lib/read-manifest.js +4 -1
  47. package/lib/read-manifest.js.map +1 -1
  48. package/lib/results.d.ts +5 -1
  49. package/lib/results.js +3 -0
  50. package/lib/results.js.map +1 -1
  51. package/package.json +18 -14
  52. package/src/action/core.ts +7 -3
  53. package/src/action/main.ts +2 -0
  54. package/src/cli/index.ts +7 -1
  55. package/src/cli/parse-cli-arguments.ts +11 -1
  56. package/src/compare-and-publish/compare-and-publish.ts +79 -0
  57. package/src/compare-and-publish/compare-versions.ts +48 -0
  58. package/src/compare-and-publish/get-arguments.ts +61 -0
  59. package/src/compare-and-publish/index.ts +1 -0
  60. package/src/errors.ts +7 -0
  61. package/src/format-publish-result.ts +6 -6
  62. package/src/normalize-options.ts +18 -12
  63. package/src/npm/call-npm-cli.ts +94 -48
  64. package/src/npm/index.ts +2 -64
  65. package/src/npm/use-npm-environment.ts +10 -4
  66. package/src/npm-publish.ts +11 -18
  67. package/src/options.ts +30 -9
  68. package/src/read-manifest.ts +8 -9
  69. package/src/results.ts +6 -1
  70. package/lib/compare-versions.d.ts +0 -20
  71. package/lib/compare-versions.js +0 -36
  72. package/lib/compare-versions.js.map +0 -1
  73. package/lib/npm/get-publish-arguments.d.ts +0 -9
  74. package/lib/npm/get-publish-arguments.js +0 -29
  75. package/lib/npm/get-publish-arguments.js.map +0 -1
  76. package/src/compare-versions.ts +0 -52
  77. package/src/npm/get-publish-arguments.ts +0 -34
package/README.md CHANGED
@@ -31,7 +31,7 @@ This package can be used three different ways:
31
31
 
32
32
  - 🤖 A [**GitHub Action**](#github-action) as part of your CI/CD process
33
33
 
34
- - 🧩 A [**function**](#javascript-function) that you call in your JavaScript code
34
+ - 🧩 A [**function**](#javascript-api) that you call in your JavaScript code
35
35
 
36
36
  - 🖥 A [**CLI**](#command-line-interface) that you run in your terminal
37
37
 
@@ -39,12 +39,37 @@ This package can be used three different ways:
39
39
 
40
40
  The v1 to v2 upgrade brought a few notable **breaking changes**. To migrate, make the following updates:
41
41
 
42
- - The `type` output is now an empty string instead of `none` when no release occurs
42
+ - The `type` output is now an empty string instead of `'none'` when no release occurs
43
43
  ```diff
44
- - - if: ${{ steps.publish.outputs.type != 'none' }}
45
- + - if: ${{ steps.publish.outputs.type }}
46
- run: echo "Version changed!"
44
+ - run: echo "Version changed!"
45
+ - if: ${{ steps.publish.outputs.type != 'none' }}
46
+ + if: ${{ steps.publish.outputs.type }}
47
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
+
48
73
  - The `check-version` and `greater-version-only` options have been removed and replaced with `strategy`.
49
74
  - Use `strategy: all` (default) to publish all versions that do not yet exist in the registry.
50
75
  ```diff
@@ -62,10 +87,24 @@ The v1 to v2 upgrade brought a few notable **breaking changes**. To migrate, mak
62
87
  - greater-version-only: true
63
88
  + strategy: upgrade
64
89
  ```
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.
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
+ ```
66
104
 
67
105
  See the [change log][] for more details and other changes in the v2 release.
68
106
 
107
+ [publishing-nodejs-packages]: https://docs.github.com/actions/publishing-packages/publishing-nodejs-packages
69
108
  [change log]: https://github.com/JS-DevTools/npm-publish/releases
70
109
 
71
110
  ## GitHub Action
@@ -73,7 +112,9 @@ See the [change log][] for more details and other changes in the v2 release.
73
112
  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][].
74
113
 
75
114
  ```yaml
76
- on: push
115
+ on:
116
+ push:
117
+ branches: main
77
118
 
78
119
  jobs:
79
120
  publish:
@@ -82,7 +123,7 @@ jobs:
82
123
  - uses: actions/checkout@v3
83
124
  - uses: actions/setup-node@v3
84
125
  with:
85
- node-version: 18
126
+ node-version: "18"
86
127
  - run: npm ci
87
128
  - run: npm test
88
129
  - uses: JS-DevTools/npm-publish@v2
@@ -97,18 +138,24 @@ jobs:
97
138
 
98
139
  You can set any or all of the following input parameters using `with`:
99
140
 
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. |
141
+ | Name | Type | Default | Description |
142
+ | ---------------- | ---------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
143
+ | `token` | string | **required** | Authentication token to use with the configured registry. |
144
+ | `registry| string | `https://registry.npmjs.org/` | Registry URL to use. |
145
+ | `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish. |
146
+ | `tag| string | `latest` | [Distribution tag][npm-tag] to publish to. |
147
+ | `access| `public`, `restricted` | [npm defaults][npm-access] | Whether the package should be publicly visible or restricted. |
148
+ | `provenance`¹ ² | boolean | `false` | Run `npm publish` with the `--provenance` flag to add [provenance][] statements. |
149
+ | `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
150
+ | `ignore-scripts` | boolean | `true` | Run `npm publish` with the `--ignore-scripts` flag as a security precaution. |
151
+ | `dry-run` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
152
+
153
+ 1. May be specified using `publishConfig` in `package.json`.
154
+ 2. Provenance requires npm `>=9.5.0`.
109
155
 
110
156
  [npm-tag]: https://docs.npmjs.com/cli/v9/commands/npm-publish#tag
111
157
  [npm-access]: https://docs.npmjs.com/cli/v9/commands/npm-publish#access
158
+ [provenance]: https://docs.npmjs.com/generating-provenance-statements
112
159
 
113
160
  ### Output
114
161
 
@@ -135,11 +182,12 @@ steps:
135
182
  | `old-version` | string | Previously published version on `tag` or empty if no previous version on tag. |
136
183
  | `tag` | string | [Distribution tag][npm-tag] the package was published to. |
137
184
  | `access` | string | [Access level][npm-access] the package was published with, or `default` if scoped-package defaults were used. |
185
+ | `registry` | string | Registry the package was published to. |
138
186
  | `dry-run` | boolean | Whether `npm publish` was run in "dry run" mode. |
139
187
 
140
188
  [semver release type]: https://github.com/npm/node-semver#release_types
141
189
 
142
- ## JavaScript Function
190
+ ## JavaScript API
143
191
 
144
192
  To use npm-package in your JavaScript code, you'll need to install it using [npm][] or other package manager of choice:
145
193
 
@@ -166,17 +214,22 @@ As shown in the example above, you should pass an options object to the `npmPubl
166
214
  import type { Options } from "@jsdevtools/npm-publish";
167
215
  ```
168
216
 
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 |
217
+ | Name | Type | Default | Description |
218
+ | -------------------- | ---------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
219
+ | `token` | string | **required** | Authentication token to use with the configured registry. |
220
+ | `registry| string, `URL` | `https://registry.npmjs.org/` | Registry URL to use. |
221
+ | `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish. |
222
+ | `tag| string | `latest` | [Distribution tag][npm-tag] to publish to. |
223
+ | `access| `public`, `restricted` | [npm defaults][npm-access] | Whether the package should be publicly visible or restricted. |
224
+ | `provenance`¹ ² | boolean | `false` | Run `npm publish` with the `--provenance` flag to add [provenance][] statements. |
225
+ | `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
226
+ | `ignoreScripts` | boolean | `true` | Run `npm publish` with the `--ignore-scripts` flag as a security precaution. |
227
+ | `dryRun` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
228
+ | `logger` | object | `undefined` | Logging interface with `debug`, `info`, and `error` log methods. |
229
+ | `temporaryDirectory` | string | `os.tmpdir()` | Temporary directory to hold a generated `.npmrc` file |
230
+
231
+ 1. May be specified using `publishConfig` in `package.json`.
232
+ 2. Provenance requires npm `>=9.5.0`.
180
233
 
181
234
  ### Output
182
235
 
@@ -195,6 +248,7 @@ import type { Results } from "@jsdevtools/npm-publish";
195
248
  | `oldVersion` | Optional string | Previously published version on `tag` or `undefined` if no previous version. |
196
249
  | `tag` | string | [Distribution tag][npm-tag] that the package was published to. |
197
250
  | `access` | Optional string | [Access level][npm-access] the package was published with, or `undefined` if scoped-package defaults were used. |
251
+ | `registry` | `URL` | Registry the package was published to. |
198
252
  | `dryRun` | boolean | Whether `npm publish` was run in "dry run" mode. |
199
253
 
200
254
  ## Command Line Interface
@@ -214,7 +268,7 @@ npx npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE
214
268
  You can customize your call with options to change the registry, package, etc.
215
269
 
216
270
  ```bash
217
- npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE --registry http://example.com ./path/to/package
271
+ npx npm-publish --token YOUR_NPM_AUTH_TOKEN_HERE --registry http://example.com ./path/to/package
218
272
  ```
219
273
 
220
274
  ### Options
@@ -243,17 +297,23 @@ Options:
243
297
  Defaults to "latest".
244
298
 
245
299
  --access <access> Package access, may be "public" or "restricted".
246
- See documentation for details.
300
+ See npm documentation for details.
301
+
302
+ --provenance Publish with provenance statements.
303
+ See npm documentation for details.
247
304
 
248
305
  --strategy <strategy> Publish strategy, may be "all" or "upgrade".
249
306
  Defaults to "all", see documentation for details.
250
307
 
308
+ --no-ignore-scripts Allow lifecycle scripts, which are disabled by default
309
+ as a security precaution. Defaults to false.
310
+
251
311
  --dry-run Do not actually publish anything.
252
312
  --quiet Only print errors.
253
313
  --debug Print debug logs.
254
314
 
255
315
  -v, --version Print the version number.
256
- -h --help Show usage text.
316
+ -h, --help Show usage text.
257
317
 
258
318
  Examples:
259
319
 
@@ -19,9 +19,9 @@ export declare function getRequiredSecretInput(name: string): string;
19
19
  * Get a boolean input by name.
20
20
  *
21
21
  * @param name Input name
22
- * @returns True if value is "true", false if not
22
+ * @returns True if value is "true", false if "false", undefined if unset
23
23
  */
24
- export declare function getBooleanInput(name: string): boolean;
24
+ export declare function getBooleanInput(name: string): boolean | undefined;
25
25
  /**
26
26
  * Set the action as failed due to an error.
27
27
  *
@@ -36,10 +36,15 @@ exports.getRequiredSecretInput = getRequiredSecretInput;
36
36
  * Get a boolean input by name.
37
37
  *
38
38
  * @param name Input name
39
- * @returns True if value is "true", false if not
39
+ * @returns True if value is "true", false if "false", undefined if unset
40
40
  */
41
41
  function getBooleanInput(name) {
42
- return (0, core_1.getInput)(name) === "true";
42
+ const inputString = (0, core_1.getInput)(name).toLowerCase();
43
+ if (inputString === "true")
44
+ return true;
45
+ if (inputString === "false")
46
+ return false;
47
+ return undefined;
43
48
  }
44
49
  exports.getBooleanInput = getBooleanInput;
45
50
  /**
@@ -1 +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;IACr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;;;;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,MAAM,WAAW,GAAG,IAAA,eAAU,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAEnD,IAAI,WAAW,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,WAAW,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,SAAS,CAAC;AACnB,CAAC;AAND,0CAMC;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"}
@@ -34,7 +34,9 @@ async function run() {
34
34
  package: core.getInput("package"),
35
35
  tag: core.getInput("tag"),
36
36
  access: core.getInput("access"),
37
+ provenance: core.getBooleanInput("provenance"),
37
38
  strategy: core.getInput("strategy"),
39
+ ignoreScripts: core.getBooleanInput("ignore-scripts"),
38
40
  dryRun: core.getBooleanInput("dry-run"),
39
41
  logger: core.logger,
40
42
  temporaryDirectory: process.env["RUNNER_TEMP"],
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/action/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAyB;AACzB,0CAAyC;AACzC,gDAAkC;AAElC,sBA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,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,4 +1,4 @@
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
+ 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 --ignore-scripts Ignore lifecycle scripts as a security precaution.\n Defaults to true.\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";
2
2
  /**
3
3
  * The main entry point of the CLI
4
4
  *
package/lib/cli/index.js CHANGED
@@ -25,11 +25,17 @@ Options:
25
25
  Defaults to "latest".
26
26
 
27
27
  --access <access> Package access, may be "public" or "restricted".
28
- See documentation for details.
28
+ See npm documentation for details.
29
+
30
+ --provenance Publish with provenance statements.
31
+ See npm documentation for details.
29
32
 
30
33
  --strategy <strategy> Publish strategy, may be "all" or "upgrade".
31
34
  Defaults to "all", see documentation for details.
32
35
 
36
+ --ignore-scripts Ignore lifecycle scripts as a security precaution.
37
+ Defaults to true.
38
+
33
39
  --dry-run Do not actually publish anything.
34
40
  --quiet Only print errors.
35
41
  --debug Print debug logs.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAAA,0CAAsD;AACtD,qEAA6D;AAEhD,QAAA,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCpB,CAA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C,CAAC;QACtB,OAAO;KACR;IAED,MAAM,MAAM,GAAW;QACrB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,YAAY,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAC7D,KAAK,EAAE,YAAY,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;KAC/D,CAAC;IAEF,MAAM,IAAA,qBAAU,EAAC,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AACxD,CAAC;AApBD,oBAoBC"}
@@ -12,7 +12,9 @@ const ARGUMENTS_OPTIONS = [
12
12
  { name: "registry", type: String },
13
13
  { name: "tag", type: String },
14
14
  { name: "access", type: String },
15
+ { name: "provenance", type: Boolean },
15
16
  { name: "strategy", type: String },
17
+ { name: "no-ignore-scripts", type: Boolean },
16
18
  { name: "dry-run", type: Boolean },
17
19
  { name: "quiet", type: Boolean },
18
20
  { name: "debug", type: Boolean },
@@ -26,7 +28,12 @@ const ARGUMENTS_OPTIONS = [
26
28
  * @returns A parsed object of options.
27
29
  */
28
30
  function parseCliArguments(argv) {
29
- const { help, version, quiet, debug, ...options } = (0, command_line_args_1.default)(ARGUMENTS_OPTIONS, { argv, camelCase: true });
31
+ const { help, version, quiet, debug, ...optionFlags } = (0, command_line_args_1.default)(ARGUMENTS_OPTIONS, { argv, camelCase: true });
32
+ const options = Object.fromEntries(Object.entries(optionFlags).map(([key, value]) => {
33
+ return key === "noIgnoreScripts"
34
+ ? ["ignoreScripts", !value]
35
+ : [key, value];
36
+ }));
30
37
  return {
31
38
  help: Boolean(help),
32
39
  version: Boolean(version),
@@ -1 +1 @@
1
- {"version":3,"file":"parse-cli-arguments.js","sourceRoot":"","sources":["../../src/cli/parse-cli-arguments.ts"],"names":[],"mappings":";AAAA,2CAA2C;;;;;;AAE3C,0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AE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAC1B,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC/C,OAAO,GAAG,KAAK,iBAAiB;YAC9B,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC;QACrB,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC;QACrB,OAAO,EAAE,OAAkB;KAC5B,CAAC;AACJ,CAAC;AArBD,8CAqBC"}
@@ -0,0 +1,21 @@
1
+ import type { PackageManifest } from "../read-manifest.js";
2
+ import type { NormalizedOptions } from "../normalize-options.js";
3
+ import { type NpmCliEnvironment } from "../npm/index.js";
4
+ import { type VersionComparison } from "./compare-versions.js";
5
+ export interface PublishResult extends VersionComparison {
6
+ id: string | undefined;
7
+ files: PublishFile[];
8
+ }
9
+ export interface PublishFile {
10
+ path: string;
11
+ size: number;
12
+ }
13
+ /**
14
+ * Get the currently published versions of a package and publish if needed.
15
+ *
16
+ * @param manifest The package to potentially publish.
17
+ * @param options Configuration options.
18
+ * @param environment Environment variables for the npm cli.
19
+ * @returns Information about the publish, including if it occurred.
20
+ */
21
+ export declare function compareAndPublish(manifest: PackageManifest, options: NormalizedOptions, environment: NpmCliEnvironment): Promise<PublishResult>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareAndPublish = void 0;
4
+ const index_js_1 = require("../npm/index.js");
5
+ const compare_versions_js_1 = require("./compare-versions.js");
6
+ const get_arguments_js_1 = require("./get-arguments.js");
7
+ /**
8
+ * Get the currently published versions of a package and publish if needed.
9
+ *
10
+ * @param manifest The package to potentially publish.
11
+ * @param options Configuration options.
12
+ * @param environment Environment variables for the npm cli.
13
+ * @returns Information about the publish, including if it occurred.
14
+ */
15
+ async function compareAndPublish(manifest, options, environment) {
16
+ const { name, version, packageSpec } = manifest;
17
+ const cliOptions = {
18
+ environment,
19
+ ignoreScripts: options.ignoreScripts.value,
20
+ logger: options.logger,
21
+ };
22
+ const viewArguments = (0, get_arguments_js_1.getViewArguments)(name, options);
23
+ const publishArguments = (0, get_arguments_js_1.getPublishArguments)(packageSpec, options);
24
+ let viewCall = await (0, index_js_1.callNpmCli)(index_js_1.VIEW, viewArguments, cliOptions);
25
+ // `npm view` will succeed with no output the package exists in the registry
26
+ // with no `latest` tag. This is only possible with third-party registries.
27
+ // https://github.com/npm/cli/issues/6408
28
+ if (!viewCall.successData && !viewCall.error) {
29
+ // Retry the call to `npm view` with the configured publish tag,
30
+ // to at least try to get something.
31
+ const viewWithTagArguments = (0, get_arguments_js_1.getViewArguments)(name, options, true);
32
+ viewCall = await (0, index_js_1.callNpmCli)(index_js_1.VIEW, viewWithTagArguments, cliOptions);
33
+ }
34
+ if (viewCall.error && viewCall.errorCode !== index_js_1.E404) {
35
+ throw viewCall.error;
36
+ }
37
+ const comparison = (0, compare_versions_js_1.compareVersions)(version, viewCall.successData, options);
38
+ const publishCall = comparison.type
39
+ ? await (0, index_js_1.callNpmCli)(index_js_1.PUBLISH, publishArguments, cliOptions)
40
+ : { successData: undefined, errorCode: undefined, error: undefined };
41
+ if (publishCall.error && publishCall.errorCode !== index_js_1.EPUBLISHCONFLICT) {
42
+ throw publishCall.error;
43
+ }
44
+ const { successData: publishData } = publishCall;
45
+ return {
46
+ id: publishData?.id,
47
+ files: publishData?.files ?? [],
48
+ type: publishData ? comparison.type : undefined,
49
+ oldVersion: comparison.oldVersion,
50
+ };
51
+ }
52
+ exports.compareAndPublish = compareAndPublish;
53
+ //# sourceMappingURL=compare-and-publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare-and-publish.js","sourceRoot":"","sources":["../../src/compare-and-publish/compare-and-publish.ts"],"names":[],"mappings":";;;AAEA,8CAOyB;AACzB,+DAAgF;AAChF,yDAA2E;AAY3E;;;;;;;GAOG;AACI,KAAK,UAAU,iBAAiB,CACrC,QAAyB,EACzB,OAA0B,EAC1B,WAA8B;IAE9B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;IAChD,MAAM,UAAU,GAAG;QACjB,WAAW;QACX,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK;QAC1C,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC;IAEF,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,MAAM,gBAAgB,GAAG,IAAA,sCAAmB,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACnE,IAAI,QAAQ,GAAG,MAAM,IAAA,qBAAU,EAAC,eAAI,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IAEjE,4EAA4E;IAC5E,2EAA2E;IAC3E,yCAAyC;IACzC,IAAI,CAAC,QAAQ,CAAC,WAAW,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;QAC5C,gEAAgE;QAChE,oCAAoC;QACpC,MAAM,oBAAoB,GAAG,IAAA,mCAAgB,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACnE,QAAQ,GAAG,MAAM,IAAA,qBAAU,EAAC,eAAI,EAAE,oBAAoB,EAAE,UAAU,CAAC,CAAC;KACrE;IAED,IAAI,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,SAAS,KAAK,eAAI,EAAE;QACjD,MAAM,QAAQ,CAAC,KAAK,CAAC;KACtB;IAED,MAAM,UAAU,GAAG,IAAA,qCAAe,EAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC3E,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI;QACjC,CAAC,CAAC,MAAM,IAAA,qBAAU,EAAC,kBAAO,EAAE,gBAAgB,EAAE,UAAU,CAAC;QACzD,CAAC,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAEvE,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,SAAS,KAAK,2BAAgB,EAAE;QACnE,MAAM,WAAW,CAAC,KAAK,CAAC;KACzB;IAED,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC;IAEjD,OAAO;QACL,EAAE,EAAE,WAAW,EAAE,EAAE;QACnB,KAAK,EAAE,WAAW,EAAE,KAAK,IAAI,EAAE;QAC/B,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAC/C,UAAU,EAAE,UAAU,CAAC,UAAU;KAClC,CAAC;AACJ,CAAC;AA/CD,8CA+CC"}
@@ -0,0 +1,16 @@
1
+ import type { NormalizedOptions } from "../normalize-options.js";
2
+ import type { ReleaseType } from "../results.js";
3
+ import type { NpmViewData } from "../npm/index.js";
4
+ export interface VersionComparison {
5
+ type: ReleaseType | undefined;
6
+ oldVersion: string | undefined;
7
+ }
8
+ /**
9
+ * Compare previously published versions with the package's current version.
10
+ *
11
+ * @param currentVersion The current package version.
12
+ * @param publishedVersions The versions that have already been published.
13
+ * @param options Configuration options
14
+ * @returns The release type and previous version.
15
+ */
16
+ export declare function compareVersions(currentVersion: string, publishedVersions: NpmViewData | undefined, options: NormalizedOptions): VersionComparison;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compareVersions = void 0;
7
+ const diff_js_1 = __importDefault(require("semver/functions/diff.js"));
8
+ const gt_js_1 = __importDefault(require("semver/functions/gt.js"));
9
+ const valid_js_1 = __importDefault(require("semver/functions/valid.js"));
10
+ const options_js_1 = require("../options.js");
11
+ const INITIAL = "initial";
12
+ const DIFFERENT = "different";
13
+ /**
14
+ * Compare previously published versions with the package's current version.
15
+ *
16
+ * @param currentVersion The current package version.
17
+ * @param publishedVersions The versions that have already been published.
18
+ * @param options Configuration options
19
+ * @returns The release type and previous version.
20
+ */
21
+ function compareVersions(currentVersion, publishedVersions, options) {
22
+ const { versions, "dist-tags": tags } = publishedVersions ?? {};
23
+ const { strategy, tag: publishTag } = options;
24
+ const oldVersion = (0, valid_js_1.default)(tags?.[publishTag.value]) ?? undefined;
25
+ const isUnique = !versions?.includes(currentVersion);
26
+ let type;
27
+ if (isUnique) {
28
+ if (!oldVersion) {
29
+ type = INITIAL;
30
+ }
31
+ else if ((0, gt_js_1.default)(currentVersion, oldVersion)) {
32
+ type = (0, diff_js_1.default)(currentVersion, oldVersion) ?? DIFFERENT;
33
+ }
34
+ else if (strategy.value === options_js_1.STRATEGY_ALL) {
35
+ type = DIFFERENT;
36
+ }
37
+ }
38
+ return { type, oldVersion };
39
+ }
40
+ exports.compareVersions = compareVersions;
41
+ //# sourceMappingURL=compare-versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare-versions.js","sourceRoot":"","sources":["../../src/compare-and-publish/compare-versions.ts"],"names":[],"mappings":";;;;;;AAAA,uEAAwD;AACxD,mEAAuD;AACvD,yEAAoD;AAEpD,8CAA6C;AAU7C,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,SAAS,GAAG,WAAW,CAAC;AAE9B;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC7B,cAAsB,EACtB,iBAA0C,EAC1C,OAA0B;IAE1B,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,iBAAiB,IAAI,EAAE,CAAC;IAChE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,UAAU,GAAG,IAAA,kBAAW,EAAC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC;IACtE,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACrD,IAAI,IAA6B,CAAC;IAElC,IAAI,QAAQ,EAAE;QACZ,IAAI,CAAC,UAAU,EAAE;YACf,IAAI,GAAG,OAAO,CAAC;SAChB;aAAM,IAAI,IAAA,eAAiB,EAAC,cAAc,EAAE,UAAU,CAAC,EAAE;YACxD,IAAI,GAAG,IAAA,iBAAgB,EAAC,cAAc,EAAE,UAAU,CAAC,IAAI,SAAS,CAAC;SAClE;aAAM,IAAI,QAAQ,CAAC,KAAK,KAAK,yBAAY,EAAE;YAC1C,IAAI,GAAG,SAAS,CAAC;SAClB;KACF;IAED,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9B,CAAC;AAtBD,0CAsBC"}
@@ -0,0 +1,21 @@
1
+ import type { NormalizedOptions } from "../normalize-options.js";
2
+ /**
3
+ * Given a package name and publish configuration, get the NPM CLI view
4
+ * arguments.
5
+ *
6
+ * @param packageName Package name.
7
+ * @param options Publish configuration.
8
+ * @param retryWithTag Include a non-latest tag in the package spec for a rety
9
+ * attempt.
10
+ * @returns Arguments to pass to the NPM CLI. If `retryWithTag` is true, but the
11
+ * publish config is using the `latest` tag, will return `undefined`.
12
+ */
13
+ export declare function getViewArguments(packageName: string, options: NormalizedOptions, retryWithTag?: boolean): string[];
14
+ /**
15
+ * Given a publish configuration, get the NPM CLI publish arguments.
16
+ *
17
+ * @param packageSpec Package specification path.
18
+ * @param options Publish configuration.
19
+ * @returns Arguments to pass to the NPM CLI.
20
+ */
21
+ export declare function getPublishArguments(packageSpec: string, options: NormalizedOptions): string[];
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPublishArguments = exports.getViewArguments = void 0;
4
+ /**
5
+ * Given a package name and publish configuration, get the NPM CLI view
6
+ * arguments.
7
+ *
8
+ * @param packageName Package name.
9
+ * @param options Publish configuration.
10
+ * @param retryWithTag Include a non-latest tag in the package spec for a rety
11
+ * attempt.
12
+ * @returns Arguments to pass to the NPM CLI. If `retryWithTag` is true, but the
13
+ * publish config is using the `latest` tag, will return `undefined`.
14
+ */
15
+ function getViewArguments(packageName, options, retryWithTag = false) {
16
+ const packageSpec = retryWithTag
17
+ ? `${packageName}@${options.tag.value}`
18
+ : packageName;
19
+ return [packageSpec, "dist-tags", "versions"];
20
+ }
21
+ exports.getViewArguments = getViewArguments;
22
+ /**
23
+ * Given a publish configuration, get the NPM CLI publish arguments.
24
+ *
25
+ * @param packageSpec Package specification path.
26
+ * @param options Publish configuration.
27
+ * @returns Arguments to pass to the NPM CLI.
28
+ */
29
+ function getPublishArguments(packageSpec, options) {
30
+ const { tag, access, dryRun, provenance } = options;
31
+ const publishArguments = [];
32
+ if (packageSpec.length > 0) {
33
+ publishArguments.push(packageSpec);
34
+ }
35
+ if (!tag.isDefault) {
36
+ publishArguments.push("--tag", tag.value);
37
+ }
38
+ if (!access.isDefault && access.value) {
39
+ publishArguments.push("--access", access.value);
40
+ }
41
+ if (!provenance.isDefault && provenance.value) {
42
+ publishArguments.push("--provenance");
43
+ }
44
+ if (!dryRun.isDefault && dryRun.value) {
45
+ publishArguments.push("--dry-run");
46
+ }
47
+ return publishArguments;
48
+ }
49
+ exports.getPublishArguments = getPublishArguments;
50
+ //# sourceMappingURL=get-arguments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-arguments.js","sourceRoot":"","sources":["../../src/compare-and-publish/get-arguments.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;GAUG;A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+ 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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compare-and-publish.js"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compare-and-publish/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
package/lib/errors.d.ts CHANGED
@@ -25,6 +25,9 @@ export declare class InvalidRegistryUrlError extends TypeError {
25
25
  export declare class InvalidTokenError extends TypeError {
26
26
  constructor();
27
27
  }
28
+ export declare class InvalidTagError extends TypeError {
29
+ constructor(value: unknown);
30
+ }
28
31
  export declare class InvalidAccessError extends TypeError {
29
32
  constructor(value: unknown);
30
33
  }