@jsdevtools/npm-publish 2.0.0 → 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.
Files changed (73) hide show
  1. package/README.md +39 -26
  2. package/lib/action/main.js +1 -0
  3. package/lib/action/main.js.map +1 -1
  4. package/lib/cli/index.d.ts +1 -1
  5. package/lib/cli/index.js +4 -1
  6. package/lib/cli/index.js.map +1 -1
  7. package/lib/cli/parse-cli-arguments.js +1 -0
  8. package/lib/cli/parse-cli-arguments.js.map +1 -1
  9. package/lib/compare-and-publish/compare-and-publish.d.ts +21 -0
  10. package/lib/compare-and-publish/compare-and-publish.js +49 -0
  11. package/lib/compare-and-publish/compare-and-publish.js.map +1 -0
  12. package/lib/compare-and-publish/compare-versions.d.ts +16 -0
  13. package/lib/compare-and-publish/compare-versions.js +41 -0
  14. package/lib/compare-and-publish/compare-versions.js.map +1 -0
  15. package/lib/compare-and-publish/get-arguments.d.ts +21 -0
  16. package/lib/compare-and-publish/get-arguments.js +50 -0
  17. package/lib/compare-and-publish/get-arguments.js.map +1 -0
  18. package/lib/compare-and-publish/index.d.ts +1 -0
  19. package/lib/compare-and-publish/index.js +18 -0
  20. package/lib/compare-and-publish/index.js.map +1 -0
  21. package/lib/errors.d.ts +3 -0
  22. package/lib/errors.js +8 -1
  23. package/lib/errors.js.map +1 -1
  24. package/lib/format-publish-result.d.ts +3 -3
  25. package/lib/format-publish-result.js +5 -5
  26. package/lib/format-publish-result.js.map +1 -1
  27. package/lib/normalize-options.d.ts +4 -2
  28. package/lib/normalize-options.js +14 -12
  29. package/lib/normalize-options.js.map +1 -1
  30. package/lib/npm/call-npm-cli.d.ts +26 -4
  31. package/lib/npm/call-npm-cli.js +49 -27
  32. package/lib/npm/call-npm-cli.js.map +1 -1
  33. package/lib/npm/index.d.ts +2 -29
  34. package/lib/npm/index.js +16 -38
  35. package/lib/npm/index.js.map +1 -1
  36. package/lib/npm/use-npm-environment.d.ts +4 -2
  37. package/lib/npm/use-npm-environment.js +7 -5
  38. package/lib/npm/use-npm-environment.js.map +1 -1
  39. package/lib/npm-publish.js +7 -12
  40. package/lib/npm-publish.js.map +1 -1
  41. package/lib/options.d.ts +14 -3
  42. package/lib/read-manifest.d.ts +4 -7
  43. package/lib/read-manifest.js +4 -1
  44. package/lib/read-manifest.js.map +1 -1
  45. package/lib/results.d.ts +5 -1
  46. package/lib/results.js +3 -0
  47. package/lib/results.js.map +1 -1
  48. package/package.json +7 -3
  49. package/src/action/main.ts +1 -0
  50. package/src/cli/index.ts +4 -1
  51. package/src/cli/parse-cli-arguments.ts +1 -0
  52. package/src/compare-and-publish/compare-and-publish.ts +75 -0
  53. package/src/compare-and-publish/compare-versions.ts +48 -0
  54. package/src/compare-and-publish/get-arguments.ts +61 -0
  55. package/src/compare-and-publish/index.ts +1 -0
  56. package/src/errors.ts +7 -0
  57. package/src/format-publish-result.ts +6 -6
  58. package/src/normalize-options.ts +16 -12
  59. package/src/npm/call-npm-cli.ts +90 -48
  60. package/src/npm/index.ts +2 -64
  61. package/src/npm/use-npm-environment.ts +10 -4
  62. package/src/npm-publish.ts +11 -18
  63. package/src/options.ts +15 -3
  64. package/src/read-manifest.ts +8 -9
  65. package/src/results.ts +6 -1
  66. package/lib/compare-versions.d.ts +0 -20
  67. package/lib/compare-versions.js +0 -36
  68. package/lib/compare-versions.js.map +0 -1
  69. package/lib/npm/get-publish-arguments.d.ts +0 -9
  70. package/lib/npm/get-publish-arguments.js +0 -29
  71. package/lib/npm/get-publish-arguments.js.map +0 -1
  72. package/src/compare-versions.ts +0 -52
  73. package/src/npm/get-publish-arguments.ts +0 -34
@@ -5,14 +5,9 @@ import { list as tarList, type ReadEntry } from "tar";
5
5
 
6
6
  import * as errors from "./errors.js";
7
7
 
8
- /** The result of reading a package manifest */
9
- export interface ManifestReadResult {
10
- packageSpec: string;
11
- manifest: PackageManifest;
12
- }
13
-
14
- /** A package manifest (package.json) */
8
+ /** A package manifest (package.json) and associated details. */
15
9
  export interface PackageManifest {
10
+ packageSpec: string;
16
11
  name: string;
17
12
  version: string;
18
13
  scope: string | undefined;
@@ -24,6 +19,7 @@ export interface PackagePublishConfig {
24
19
  tag?: string;
25
20
  access?: string;
26
21
  registry?: string;
22
+ provenance?: boolean;
27
23
  }
28
24
 
29
25
  const SCOPE_RE = /^(@.+)\/.+$/u;
@@ -86,7 +82,7 @@ const readTarballPackageJson = async (file: string): Promise<string> => {
86
82
  */
87
83
  export async function readManifest(
88
84
  packagePath: unknown
89
- ): Promise<ManifestReadResult> {
85
+ ): Promise<PackageManifest> {
90
86
  let packageSpec: string | undefined;
91
87
  let manifestContents: string;
92
88
 
@@ -138,6 +134,9 @@ export async function readManifest(
138
134
 
139
135
  return {
140
136
  packageSpec,
141
- manifest: { name, version, publishConfig, scope: SCOPE_RE.exec(name)?.[1] },
137
+ name,
138
+ version,
139
+ publishConfig,
140
+ scope: SCOPE_RE.exec(name)?.[1],
142
141
  };
143
142
  }
package/src/results.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Access, Strategy } from "./options.js";
2
- import type { ReleaseType } from "./compare-versions.js";
2
+ import type { ReleaseType as SemverReleaseType } from "semver";
3
+
4
+ /** Release type */
5
+ export type ReleaseType = SemverReleaseType | typeof INITIAL | typeof DIFFERENT;
6
+ export const INITIAL = "initial";
7
+ export const DIFFERENT = "different";
3
8
 
4
9
  /** Results of the publish */
5
10
  export interface Results {
@@ -1,20 +0,0 @@
1
- import { type ReleaseType as SemverReleaseType } from "semver";
2
- import type { NormalizedOptions } from "./normalize-options.js";
3
- import type { PublishedVersions } from "./npm/index.js";
4
- export type ReleaseType = SemverReleaseType | typeof INITIAL | typeof DIFFERENT;
5
- export interface VersionComparison {
6
- type: ReleaseType | undefined;
7
- oldVersion: string | undefined;
8
- }
9
- declare const INITIAL = "initial";
10
- declare const DIFFERENT = "different";
11
- /**
12
- * Compare previously published versions with the package's current version.
13
- *
14
- * @param version The current package version.
15
- * @param publishedVersions The versions that have already been published.
16
- * @param options Configuration options
17
- * @returns The release type and previous version.
18
- */
19
- export declare function compareVersions(version: string, publishedVersions: PublishedVersions, options: NormalizedOptions): VersionComparison;
20
- export {};
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compareVersions = void 0;
4
- const semver_1 = require("semver");
5
- const options_js_1 = require("./options.js");
6
- const INITIAL = "initial";
7
- const DIFFERENT = "different";
8
- /**
9
- * Compare previously published versions with the package's current version.
10
- *
11
- * @param version 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
- function compareVersions(version, publishedVersions, options) {
17
- const { versions: existingVersions, "dist-tags": tags } = publishedVersions;
18
- const { strategy, tag: publishTag } = options;
19
- const oldVersion = (0, semver_1.valid)(tags[publishTag.value]) ?? undefined;
20
- const isUnique = !existingVersions.includes(version);
21
- let type;
22
- if (isUnique) {
23
- if (!oldVersion) {
24
- type = INITIAL;
25
- }
26
- else if ((0, semver_1.gt)(version, oldVersion)) {
27
- type = (0, semver_1.diff)(version, oldVersion) ?? DIFFERENT;
28
- }
29
- else if (strategy.value === options_js_1.STRATEGY_ALL) {
30
- type = DIFFERENT;
31
- }
32
- }
33
- return { type, oldVersion };
34
- }
35
- exports.compareVersions = compareVersions;
36
- //# sourceMappingURL=compare-versions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare-versions.js","sourceRoot":"","sources":["../src/compare-versions.ts"],"names":[],"mappings":";;;AAAA,mCAKgB;AAEhB,6CAA4C;AAW5C,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,SAAS,GAAG,WAAW,CAAC;AAE9B;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC7B,OAAe,EACf,iBAAoC,EACpC,OAA0B;IAE1B,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,iBAAiB,CAAC;IAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,UAAU,GAAG,IAAA,cAAW,EAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC;IACpE,MAAM,QAAQ,GAAG,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,IAA6B,CAAC;IAElC,IAAI,QAAQ,EAAE;QACZ,IAAI,CAAC,UAAU,EAAE;YACf,IAAI,GAAG,OAAO,CAAC;SAChB;aAAM,IAAI,IAAA,WAAiB,EAAC,OAAO,EAAE,UAAU,CAAC,EAAE;YACjD,IAAI,GAAG,IAAA,aAAgB,EAAC,OAAO,EAAE,UAAU,CAAC,IAAI,SAAS,CAAC;SAC3D;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"}
@@ -1,9 +0,0 @@
1
- import type { NormalizedOptions } from "../normalize-options.js";
2
- /**
3
- * Given a publish configuration, get the NPM CLI publish arguments.
4
- *
5
- * @param packageSpec Package specification path.
6
- * @param options Publish configuration.
7
- * @returns Arguments to pass to the NPM CLI.
8
- */
9
- export declare function getPublishArguments(packageSpec: string, options: NormalizedOptions): string[];
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPublishArguments = void 0;
4
- /**
5
- * Given a publish configuration, get the NPM CLI publish arguments.
6
- *
7
- * @param packageSpec Package specification path.
8
- * @param options Publish configuration.
9
- * @returns Arguments to pass to the NPM CLI.
10
- */
11
- function getPublishArguments(packageSpec, options) {
12
- const { tag, access, dryRun } = options;
13
- const publishArguments = [];
14
- if (packageSpec.length > 0) {
15
- publishArguments.push(packageSpec);
16
- }
17
- if (!tag.isDefault) {
18
- publishArguments.push("--tag", tag.value);
19
- }
20
- if (!access.isDefault && access.value) {
21
- publishArguments.push("--access", access.value);
22
- }
23
- if (dryRun.value) {
24
- publishArguments.push("--dry-run");
25
- }
26
- return publishArguments;
27
- }
28
- exports.getPublishArguments = getPublishArguments;
29
- //# sourceMappingURL=get-publish-arguments.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-publish-arguments.js","sourceRoot":"","sources":["../../src/npm/get-publish-arguments.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,OAA0B;IAE1B,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,gBAAgB,GAAG,EAAE,CAAC;IAE5B,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KACpC;IAED,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;QAClB,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;KAC3C;IAED,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,EAAE;QACrC,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;KACjD;IAED,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KACpC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAxBD,kDAwBC"}
@@ -1,52 +0,0 @@
1
- import {
2
- valid as semverValid,
3
- gt as semverGreaterThan,
4
- diff as semverDifference,
5
- type ReleaseType as SemverReleaseType,
6
- } from "semver";
7
-
8
- import { STRATEGY_ALL } from "./options.js";
9
- import type { NormalizedOptions } from "./normalize-options.js";
10
- import type { PublishedVersions } from "./npm/index.js";
11
-
12
- export type ReleaseType = SemverReleaseType | typeof INITIAL | typeof DIFFERENT;
13
-
14
- export interface VersionComparison {
15
- type: ReleaseType | undefined;
16
- oldVersion: string | undefined;
17
- }
18
-
19
- const INITIAL = "initial";
20
- const DIFFERENT = "different";
21
-
22
- /**
23
- * Compare previously published versions with the package's current version.
24
- *
25
- * @param version The current package version.
26
- * @param publishedVersions The versions that have already been published.
27
- * @param options Configuration options
28
- * @returns The release type and previous version.
29
- */
30
- export function compareVersions(
31
- version: string,
32
- publishedVersions: PublishedVersions,
33
- options: NormalizedOptions
34
- ): VersionComparison {
35
- const { versions: existingVersions, "dist-tags": tags } = publishedVersions;
36
- const { strategy, tag: publishTag } = options;
37
- const oldVersion = semverValid(tags[publishTag.value]) ?? undefined;
38
- const isUnique = !existingVersions.includes(version);
39
- let type: ReleaseType | undefined;
40
-
41
- if (isUnique) {
42
- if (!oldVersion) {
43
- type = INITIAL;
44
- } else if (semverGreaterThan(version, oldVersion)) {
45
- type = semverDifference(version, oldVersion) ?? DIFFERENT;
46
- } else if (strategy.value === STRATEGY_ALL) {
47
- type = DIFFERENT;
48
- }
49
- }
50
-
51
- return { type, oldVersion };
52
- }
@@ -1,34 +0,0 @@
1
- import type { NormalizedOptions } from "../normalize-options.js";
2
-
3
- /**
4
- * Given a publish configuration, get the NPM CLI publish arguments.
5
- *
6
- * @param packageSpec Package specification path.
7
- * @param options Publish configuration.
8
- * @returns Arguments to pass to the NPM CLI.
9
- */
10
- export function getPublishArguments(
11
- packageSpec: string,
12
- options: NormalizedOptions
13
- ): string[] {
14
- const { tag, access, dryRun } = options;
15
- const publishArguments = [];
16
-
17
- if (packageSpec.length > 0) {
18
- publishArguments.push(packageSpec);
19
- }
20
-
21
- if (!tag.isDefault) {
22
- publishArguments.push("--tag", tag.value);
23
- }
24
-
25
- if (!access.isDefault && access.value) {
26
- publishArguments.push("--access", access.value);
27
- }
28
-
29
- if (dryRun.value) {
30
- publishArguments.push("--dry-run");
31
- }
32
-
33
- return publishArguments;
34
- }