@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.
- package/README.md +92 -32
- package/lib/action/core.d.ts +2 -2
- package/lib/action/core.js +7 -2
- package/lib/action/core.js.map +1 -1
- package/lib/action/main.js +2 -0
- package/lib/action/main.js.map +1 -1
- package/lib/cli/index.d.ts +1 -1
- package/lib/cli/index.js +7 -1
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/parse-cli-arguments.js +8 -1
- package/lib/cli/parse-cli-arguments.js.map +1 -1
- package/lib/compare-and-publish/compare-and-publish.d.ts +21 -0
- package/lib/compare-and-publish/compare-and-publish.js +53 -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 +3 -0
- package/lib/errors.js +8 -1
- package/lib/errors.js.map +1 -1
- package/lib/format-publish-result.d.ts +3 -3
- package/lib/format-publish-result.js +5 -5
- package/lib/format-publish-result.js.map +1 -1
- package/lib/normalize-options.d.ts +5 -2
- package/lib/normalize-options.js +15 -12
- package/lib/normalize-options.js.map +1 -1
- package/lib/npm/call-npm-cli.d.ts +27 -4
- package/lib/npm/call-npm-cli.js +50 -27
- package/lib/npm/call-npm-cli.js.map +1 -1
- package/lib/npm/index.d.ts +2 -29
- package/lib/npm/index.js +16 -38
- package/lib/npm/index.js.map +1 -1
- package/lib/npm/use-npm-environment.d.ts +4 -2
- package/lib/npm/use-npm-environment.js +7 -5
- package/lib/npm/use-npm-environment.js.map +1 -1
- package/lib/npm-publish.js +7 -12
- package/lib/npm-publish.js.map +1 -1
- package/lib/options.d.ts +28 -9
- package/lib/read-manifest.d.ts +4 -7
- package/lib/read-manifest.js +4 -1
- package/lib/read-manifest.js.map +1 -1
- package/lib/results.d.ts +5 -1
- package/lib/results.js +3 -0
- package/lib/results.js.map +1 -1
- package/package.json +18 -14
- package/src/action/core.ts +7 -3
- package/src/action/main.ts +2 -0
- package/src/cli/index.ts +7 -1
- package/src/cli/parse-cli-arguments.ts +11 -1
- package/src/compare-and-publish/compare-and-publish.ts +79 -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 +7 -0
- package/src/format-publish-result.ts +6 -6
- package/src/normalize-options.ts +18 -12
- package/src/npm/call-npm-cli.ts +94 -48
- package/src/npm/index.ts +2 -64
- package/src/npm/use-npm-environment.ts +10 -4
- package/src/npm-publish.ts +11 -18
- package/src/options.ts +30 -9
- package/src/read-manifest.ts +8 -9
- package/src/results.ts +6 -1
- package/lib/compare-versions.d.ts +0 -20
- package/lib/compare-versions.js +0 -36
- package/lib/compare-versions.js.map +0 -1
- package/lib/npm/get-publish-arguments.d.ts +0 -9
- package/lib/npm/get-publish-arguments.js +0 -29
- package/lib/npm/get-publish-arguments.js.map +0 -1
- package/src/compare-versions.ts +0 -52
- package/src/npm/get-publish-arguments.ts +0 -34
package/src/npm/call-npm-cli.ts
CHANGED
|
@@ -5,20 +5,97 @@ import * as errors from "../errors.js";
|
|
|
5
5
|
import type { Logger } from "../options.js";
|
|
6
6
|
import type { NpmCliEnvironment } from "./use-npm-environment.js";
|
|
7
7
|
|
|
8
|
-
export interface NpmCliOptions
|
|
9
|
-
environment
|
|
10
|
-
|
|
8
|
+
export interface NpmCliOptions {
|
|
9
|
+
environment: NpmCliEnvironment;
|
|
10
|
+
ignoreScripts: boolean;
|
|
11
11
|
logger?: Logger | undefined;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface NpmCallResult<CommandT extends Command> {
|
|
15
|
+
successData: SuccessData<CommandT> | undefined;
|
|
16
|
+
errorCode: string | undefined;
|
|
17
|
+
error: Error | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type SuccessData<T extends Command> = T extends typeof VIEW
|
|
21
|
+
? NpmViewData
|
|
22
|
+
: T extends typeof PUBLISH
|
|
23
|
+
? NpmPublishData
|
|
24
|
+
: unknown;
|
|
25
|
+
|
|
26
|
+
export interface NpmViewData {
|
|
27
|
+
"dist-tags": Record<string, string>;
|
|
28
|
+
versions: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface NpmPublishData {
|
|
31
|
+
id: string;
|
|
32
|
+
files: { path: string; size: number }[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type Command = typeof VIEW | typeof PUBLISH | string;
|
|
36
|
+
export const VIEW = "view";
|
|
37
|
+
export const PUBLISH = "publish";
|
|
38
|
+
|
|
39
|
+
export const E404 = "E404";
|
|
40
|
+
export const EPUBLISHCONFLICT = "EPUBLISHCONFLICT";
|
|
41
|
+
|
|
14
42
|
const NPM = os.platform() === "win32" ? "npm.cmd" : "npm";
|
|
15
43
|
const JSON_MATCH_RE = /(\{[\s\S]*\})/mu;
|
|
16
44
|
|
|
17
|
-
const
|
|
45
|
+
const baseArguments = (options: NpmCliOptions) =>
|
|
46
|
+
options.ignoreScripts ? ["--ignore-scripts", "--json"] : ["--json"];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Call the NPM CLI in JSON mode.
|
|
50
|
+
*
|
|
51
|
+
* @param command The command of the NPM CLI to call
|
|
52
|
+
* @param cliArguments Any arguments to send to the command
|
|
53
|
+
* @param options Customize environment variables or add an error handler.
|
|
54
|
+
* @returns The parsed JSON, or stdout if unparsable.
|
|
55
|
+
*/
|
|
56
|
+
export async function callNpmCli<CommandT extends Command>(
|
|
57
|
+
command: CommandT,
|
|
58
|
+
cliArguments: string[],
|
|
59
|
+
options: NpmCliOptions
|
|
60
|
+
): Promise<NpmCallResult<CommandT>> {
|
|
61
|
+
const { stdout, stderr, exitCode } = await execNpm(
|
|
62
|
+
[command, ...baseArguments(options), ...cliArguments],
|
|
63
|
+
options.environment,
|
|
64
|
+
options.logger
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
let successData;
|
|
68
|
+
let errorCode;
|
|
69
|
+
let error;
|
|
70
|
+
|
|
71
|
+
if (exitCode === 0) {
|
|
72
|
+
successData = parseJson<SuccessData<CommandT>>(stdout);
|
|
73
|
+
} else {
|
|
74
|
+
const errorPayload = parseJson<{ error?: { code?: string | null } }>(
|
|
75
|
+
stdout,
|
|
76
|
+
stderr
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
errorCode = errorPayload?.error?.code?.toUpperCase();
|
|
80
|
+
error = new errors.NpmCallError(command, exitCode, stderr);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { successData, errorCode, error };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Execute the npm CLI.
|
|
88
|
+
*
|
|
89
|
+
* @param commandArguments Npm subcommand and arguments.
|
|
90
|
+
* @param environment Environment variables.
|
|
91
|
+
* @param logger Optional logger.
|
|
92
|
+
* @returns Stdout, stderr, and the exit code.
|
|
93
|
+
*/
|
|
94
|
+
async function execNpm(
|
|
18
95
|
commandArguments: string[],
|
|
19
|
-
environment: Record<string, string
|
|
96
|
+
environment: Record<string, string>,
|
|
20
97
|
logger?: Logger
|
|
21
|
-
): Promise<{ stdout: string; stderr: string; exitCode: number }>
|
|
98
|
+
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
|
|
22
99
|
logger?.debug?.(`Running command: ${NPM} ${commandArguments.join(" ")}`);
|
|
23
100
|
|
|
24
101
|
return new Promise((resolve) => {
|
|
@@ -39,9 +116,18 @@ const execNpm = (
|
|
|
39
116
|
});
|
|
40
117
|
});
|
|
41
118
|
});
|
|
42
|
-
}
|
|
119
|
+
}
|
|
43
120
|
|
|
44
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Parse CLI outputs for JSON data.
|
|
123
|
+
*
|
|
124
|
+
* Certain versions of the npm CLI may intersperse JSON with human-readable
|
|
125
|
+
* output, which this function accounts for.
|
|
126
|
+
*
|
|
127
|
+
* @param values CLI outputs to check
|
|
128
|
+
* @returns Parsed JSON, if able to parse.
|
|
129
|
+
*/
|
|
130
|
+
function parseJson<TParsed>(...values: string[]): TParsed | undefined {
|
|
45
131
|
for (const value of values) {
|
|
46
132
|
const jsonValue = JSON_MATCH_RE.exec(value)?.[1];
|
|
47
133
|
|
|
@@ -55,44 +141,4 @@ const parseJson = <TParsed>(...values: string[]): TParsed | undefined => {
|
|
|
55
141
|
}
|
|
56
142
|
|
|
57
143
|
return undefined;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Call the NPM CLI in JSON mode.
|
|
62
|
-
*
|
|
63
|
-
* @param command The command of the NPM CLI to call
|
|
64
|
-
* @param cliArguments Any arguments to send to the command
|
|
65
|
-
* @param options Customize environment variables or add an error handler.
|
|
66
|
-
* @returns The parsed JSON, or stdout if unparsable.
|
|
67
|
-
*/
|
|
68
|
-
export async function callNpmCli<TReturn = string>(
|
|
69
|
-
command: string,
|
|
70
|
-
cliArguments: string[],
|
|
71
|
-
options: NpmCliOptions<TReturn> = {}
|
|
72
|
-
): Promise<TReturn> {
|
|
73
|
-
const { stdout, stderr, exitCode } = await execNpm(
|
|
74
|
-
[command, "--ignore-scripts", "--json", ...cliArguments],
|
|
75
|
-
options.environment,
|
|
76
|
-
options.logger
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (exitCode !== 0) {
|
|
80
|
-
const errorPayload = parseJson<{ error?: { code?: string | null } }>(
|
|
81
|
-
stdout,
|
|
82
|
-
stderr
|
|
83
|
-
);
|
|
84
|
-
const errorCode = errorPayload?.error?.code?.toLowerCase();
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
typeof errorCode === "string" &&
|
|
88
|
-
options.ifError &&
|
|
89
|
-
errorCode in options.ifError
|
|
90
|
-
) {
|
|
91
|
-
return options.ifError[errorCode] as TReturn;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
throw new errors.NpmCallError(command, exitCode, stderr);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return parseJson(stdout) ?? (stdout as unknown as TReturn);
|
|
98
144
|
}
|
package/src/npm/index.ts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { callNpmCli } from "./call-npm-cli.js";
|
|
4
|
-
import { getPublishArguments } from "./get-publish-arguments.js";
|
|
5
|
-
|
|
6
|
-
export interface PublishedVersions {
|
|
7
|
-
"dist-tags": Record<string, string>;
|
|
8
|
-
versions: string[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface PublishFile {
|
|
12
|
-
path: string;
|
|
13
|
-
size: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface PublishResult {
|
|
17
|
-
id: string;
|
|
18
|
-
files: PublishFile[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get a package's published versions.
|
|
23
|
-
*
|
|
24
|
-
* @param packageName The name of the package to get published versions for.
|
|
25
|
-
* @param options Configuration options.
|
|
26
|
-
* @returns All published versions and tags.
|
|
27
|
-
*/
|
|
28
|
-
export async function getVersions(
|
|
29
|
-
packageName: string,
|
|
30
|
-
options: NormalizedOptions
|
|
31
|
-
): Promise<PublishedVersions> {
|
|
32
|
-
return useNpmEnvironment(options, (environment) => {
|
|
33
|
-
return callNpmCli<PublishedVersions>(
|
|
34
|
-
"view",
|
|
35
|
-
[packageName, "dist-tags", "versions"],
|
|
36
|
-
{
|
|
37
|
-
logger: options.logger,
|
|
38
|
-
environment,
|
|
39
|
-
ifError: { e404: { "dist-tags": {}, versions: [] } },
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Publish a package.
|
|
47
|
-
*
|
|
48
|
-
* @param packageSpec Package specification to pass to npm.
|
|
49
|
-
* @param options Configuration options.
|
|
50
|
-
* @returns Release metadata.
|
|
51
|
-
*/
|
|
52
|
-
export async function publish(
|
|
53
|
-
packageSpec: string,
|
|
54
|
-
options: NormalizedOptions
|
|
55
|
-
): Promise<PublishResult> {
|
|
56
|
-
const publishArguments = getPublishArguments(packageSpec, options);
|
|
57
|
-
|
|
58
|
-
return useNpmEnvironment(options, (environment) => {
|
|
59
|
-
return callNpmCli<PublishResult>("publish", publishArguments, {
|
|
60
|
-
logger: options.logger,
|
|
61
|
-
environment,
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
1
|
+
export * from "./call-npm-cli.js";
|
|
2
|
+
export * from "./use-npm-environment.js";
|
|
@@ -2,11 +2,14 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
+
import type { PackageManifest } from "../read-manifest.js";
|
|
5
6
|
import type { NormalizedOptions } from "../normalize-options.js";
|
|
6
7
|
|
|
7
8
|
export type NpmCliEnvironment = Record<string, string>;
|
|
8
9
|
|
|
9
10
|
export type NpmCliTask<TReturn> = (
|
|
11
|
+
manifest: PackageManifest,
|
|
12
|
+
options: NormalizedOptions,
|
|
10
13
|
environment: NpmCliEnvironment
|
|
11
14
|
) => Promise<TReturn>;
|
|
12
15
|
|
|
@@ -14,12 +17,14 @@ export type NpmCliTask<TReturn> = (
|
|
|
14
17
|
* Create a temporary .npmrc file with the given auth token, and call a task
|
|
15
18
|
* with env vars set to use that .npmrc.
|
|
16
19
|
*
|
|
20
|
+
* @param manifest Pacakge metadata.
|
|
17
21
|
* @param options Configuration options.
|
|
18
22
|
* @param task A function called with the configured environment. After the
|
|
19
23
|
* function resolves, the temporary .npmrc file will be removed.
|
|
20
24
|
* @returns The resolved value of `task`
|
|
21
25
|
*/
|
|
22
26
|
export async function useNpmEnvironment<TReturn>(
|
|
27
|
+
manifest: PackageManifest,
|
|
23
28
|
options: NormalizedOptions,
|
|
24
29
|
task: NpmCliTask<TReturn>
|
|
25
30
|
): Promise<TReturn> {
|
|
@@ -28,6 +33,10 @@ export async function useNpmEnvironment<TReturn>(
|
|
|
28
33
|
path.join(temporaryDirectory, "npm-publish-")
|
|
29
34
|
);
|
|
30
35
|
const npmrc = path.join(npmrcDirectory, ".npmrc");
|
|
36
|
+
const environment = {
|
|
37
|
+
NODE_AUTH_TOKEN: token,
|
|
38
|
+
npm_config_userconfig: npmrc,
|
|
39
|
+
};
|
|
31
40
|
|
|
32
41
|
const config = [
|
|
33
42
|
"; created by jsdevtools/npm-publish",
|
|
@@ -41,10 +50,7 @@ export async function useNpmEnvironment<TReturn>(
|
|
|
41
50
|
logger?.debug?.(`Temporary .npmrc created at ${npmrc}\n${config}`);
|
|
42
51
|
|
|
43
52
|
try {
|
|
44
|
-
return await task(
|
|
45
|
-
NODE_AUTH_TOKEN: token,
|
|
46
|
-
npm_config_userconfig: npmrc,
|
|
47
|
-
});
|
|
53
|
+
return await task(manifest, options, environment);
|
|
48
54
|
} finally {
|
|
49
55
|
await fs.rm(npmrcDirectory, { force: true, recursive: true });
|
|
50
56
|
}
|
package/src/npm-publish.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readManifest } from "./read-manifest.js";
|
|
2
2
|
import { normalizeOptions } from "./normalize-options.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useNpmEnvironment } from "./npm/index.js";
|
|
4
|
+
import { compareAndPublish } from "./compare-and-publish/index.js";
|
|
5
5
|
import { formatPublishResult } from "./format-publish-result.js";
|
|
6
6
|
import type { Options } from "./options.js";
|
|
7
7
|
import type { Results } from "./results.js";
|
|
@@ -13,31 +13,24 @@ import type { Results } from "./results.js";
|
|
|
13
13
|
* @returns Release metadata.
|
|
14
14
|
*/
|
|
15
15
|
export async function npmPublish(options: Options): Promise<Results> {
|
|
16
|
-
const
|
|
17
|
-
const normalizedOptions = normalizeOptions(
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
normalizedOptions
|
|
16
|
+
const manifest = await readManifest(options.package);
|
|
17
|
+
const normalizedOptions = normalizeOptions(manifest, options);
|
|
18
|
+
const publishResult = await useNpmEnvironment(
|
|
19
|
+
manifest,
|
|
20
|
+
normalizedOptions,
|
|
21
|
+
compareAndPublish
|
|
23
22
|
);
|
|
24
23
|
|
|
25
|
-
let publishResult;
|
|
26
|
-
|
|
27
|
-
if (versionComparison.type !== undefined) {
|
|
28
|
-
publishResult = await publish(packageSpec, normalizedOptions);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
24
|
normalizedOptions.logger?.info?.(
|
|
32
25
|
formatPublishResult(manifest, normalizedOptions, publishResult)
|
|
33
26
|
);
|
|
34
27
|
|
|
35
28
|
return {
|
|
36
|
-
id: publishResult
|
|
29
|
+
id: publishResult.id,
|
|
30
|
+
type: publishResult.type,
|
|
31
|
+
oldVersion: publishResult.oldVersion,
|
|
37
32
|
name: manifest.name,
|
|
38
33
|
version: manifest.version,
|
|
39
|
-
type: versionComparison.type,
|
|
40
|
-
oldVersion: versionComparison.oldVersion,
|
|
41
34
|
registry: normalizedOptions.registry,
|
|
42
35
|
tag: normalizedOptions.tag.value,
|
|
43
36
|
access: normalizedOptions.access.value,
|
package/src/options.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface Options {
|
|
|
39
39
|
*
|
|
40
40
|
* Defaults to "https://registry.npmjs.org/".
|
|
41
41
|
*
|
|
42
|
-
* Can be
|
|
42
|
+
* Can be set by the package.json's `publishConfig` field.
|
|
43
43
|
*/
|
|
44
44
|
registry?: string | URL | undefined;
|
|
45
45
|
|
|
@@ -48,7 +48,7 @@ export interface Options {
|
|
|
48
48
|
*
|
|
49
49
|
* Defaults to "latest".
|
|
50
50
|
*
|
|
51
|
-
* Can be
|
|
51
|
+
* Can be set by the package.json's `publishConfig` field.
|
|
52
52
|
*/
|
|
53
53
|
tag?: string | undefined;
|
|
54
54
|
|
|
@@ -60,23 +60,44 @@ export interface Options {
|
|
|
60
60
|
* packages.
|
|
61
61
|
*
|
|
62
62
|
* Defaults to "restricted" for scoped packages, unless that package has been
|
|
63
|
-
* previously published as `public
|
|
63
|
+
* previously published as `public`.
|
|
64
64
|
*
|
|
65
|
-
* Can be
|
|
65
|
+
* Can be set by the package.json's `publishConfig` field.
|
|
66
66
|
*/
|
|
67
67
|
access?: Access | undefined;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Generate provenance statements.
|
|
71
|
+
*
|
|
72
|
+
* Publish must be run from a supported CI provider to succeed. When run from
|
|
73
|
+
* GitHub Actions, requires `id-token: write` permission.
|
|
74
|
+
*
|
|
75
|
+
* Defaults to `false`.
|
|
71
76
|
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
* Can be set by the package.json's `publishConfig` field.
|
|
78
|
+
*/
|
|
79
|
+
provenance?: boolean | undefined;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Version check strategy.
|
|
75
83
|
*
|
|
76
|
-
*
|
|
84
|
+
* - `always` (default): the package will be published if its version is simply
|
|
85
|
+
* not yet published.
|
|
86
|
+
* - `upgrade`: the package will only be published if its version is higher than
|
|
87
|
+
* the existing version on the configured tag.
|
|
77
88
|
*/
|
|
78
89
|
strategy?: Strategy | undefined;
|
|
79
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Ignore lifecycle scripts.
|
|
93
|
+
*
|
|
94
|
+
* If `true` (default), `--ignore-scripts` will be passed to `npm`. If you
|
|
95
|
+
* rely on publish lifecycle scripts - i.e. `prepublishOnly`, `prepack`,
|
|
96
|
+
* `prepare`, `postpack`, `publish`, `postpublish` - you should set this to
|
|
97
|
+
* `false` or rework your build and publish workflow.
|
|
98
|
+
*/
|
|
99
|
+
ignoreScripts?: boolean | undefined;
|
|
100
|
+
|
|
80
101
|
/**
|
|
81
102
|
* Pretend to publish, but don't actually upload to the registry.
|
|
82
103
|
*
|
package/src/read-manifest.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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<
|
|
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
|
-
|
|
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 "
|
|
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 {};
|
package/lib/compare-versions.js
DELETED
|
@@ -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"}
|
package/src/compare-versions.ts
DELETED
|
@@ -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
|
-
}
|