@jsdevtools/npm-publish 1.4.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +174 -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 +55 -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 +60 -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 +40 -0
  13. package/lib/cli/parse-cli-arguments.js.map +1 -0
  14. package/lib/compare-and-publish/compare-and-publish.d.ts +21 -0
  15. package/lib/compare-and-publish/compare-and-publish.js +49 -0
  16. package/lib/compare-and-publish/compare-and-publish.js.map +1 -0
  17. package/lib/compare-and-publish/compare-versions.d.ts +16 -0
  18. package/lib/compare-and-publish/compare-versions.js +41 -0
  19. package/lib/compare-and-publish/compare-versions.js.map +1 -0
  20. package/lib/compare-and-publish/get-arguments.d.ts +21 -0
  21. package/lib/compare-and-publish/get-arguments.js +50 -0
  22. package/lib/compare-and-publish/get-arguments.js.map +1 -0
  23. package/lib/compare-and-publish/index.d.ts +1 -0
  24. package/lib/compare-and-publish/index.js +18 -0
  25. package/lib/compare-and-publish/index.js.map +1 -0
  26. package/lib/errors.d.ts +39 -0
  27. package/lib/errors.js +121 -0
  28. package/lib/errors.js.map +1 -0
  29. package/lib/format-publish-result.d.ts +12 -0
  30. package/lib/format-publish-result.js +36 -0
  31. package/lib/format-publish-result.js.map +1 -0
  32. package/lib/index.d.ts +4 -5
  33. package/lib/index.js +11 -10
  34. package/lib/index.js.map +1 -1
  35. package/lib/normalize-options.d.ts +28 -1
  36. package/lib/normalize-options.js +89 -14
  37. package/lib/normalize-options.js.map +1 -1
  38. package/lib/npm/call-npm-cli.d.ts +38 -0
  39. package/lib/npm/call-npm-cli.js +113 -0
  40. package/lib/npm/call-npm-cli.js.map +1 -0
  41. package/lib/npm/index.d.ts +2 -0
  42. package/lib/npm/index.js +19 -0
  43. package/lib/npm/index.js.map +1 -0
  44. package/lib/npm/use-npm-environment.d.ts +15 -0
  45. package/lib/npm/use-npm-environment.js +44 -0
  46. package/lib/npm/use-npm-environment.js.map +1 -0
  47. package/lib/npm-publish.d.ts +7 -4
  48. package/lib/npm-publish.js +25 -26
  49. package/lib/npm-publish.js.map +1 -1
  50. package/lib/options.d.ts +67 -44
  51. package/lib/options.js +5 -0
  52. package/lib/options.js.map +1 -1
  53. package/lib/read-manifest.d.ts +22 -1
  54. package/lib/read-manifest.js +122 -22
  55. package/lib/read-manifest.js.map +1 -1
  56. package/lib/results.d.ts +30 -28
  57. package/lib/results.js +3 -0
  58. package/lib/results.js.map +1 -1
  59. package/package.json +47 -35
  60. package/src/action/core.ts +91 -0
  61. package/src/action/main.ts +32 -0
  62. package/src/cli/index.ts +72 -0
  63. package/src/cli/parse-cli-arguments.ts +49 -0
  64. package/src/compare-and-publish/compare-and-publish.ts +75 -0
  65. package/src/compare-and-publish/compare-versions.ts +48 -0
  66. package/src/compare-and-publish/get-arguments.ts +61 -0
  67. package/src/compare-and-publish/index.ts +1 -0
  68. package/src/errors.ts +137 -0
  69. package/src/format-publish-result.ts +40 -0
  70. package/src/index.ts +7 -0
  71. package/src/normalize-options.ts +123 -0
  72. package/src/npm/call-npm-cli.ts +140 -0
  73. package/src/npm/index.ts +2 -0
  74. package/src/npm/use-npm-environment.ts +57 -0
  75. package/src/npm-publish.ts +40 -0
  76. package/src/options.ts +108 -0
  77. package/src/read-manifest.ts +142 -0
  78. package/src/results.ts +50 -0
  79. package/CHANGELOG.md +0 -49
  80. package/lib/action/index.js +0 -67
  81. package/lib/action/index.js.map +0 -1
  82. package/lib/cli/exit-code.d.ts +0 -1
  83. package/lib/cli/exit-code.js +0 -16
  84. package/lib/cli/exit-code.js.map +0 -1
  85. package/lib/cli/help.d.ts +0 -1
  86. package/lib/cli/help.js +0 -28
  87. package/lib/cli/help.js.map +0 -1
  88. package/lib/cli/parse-args.d.ts +0 -1
  89. package/lib/cli/parse-args.js +0 -58
  90. package/lib/cli/parse-args.js.map +0 -1
  91. package/lib/npm-config.d.ts +0 -1
  92. package/lib/npm-config.js +0 -85
  93. package/lib/npm-config.js.map +0 -1
  94. package/lib/npm-env.d.ts +0 -6
  95. package/lib/npm-env.js +0 -24
  96. package/lib/npm-env.js.map +0 -1
  97. package/lib/npm.d.ts +0 -1
  98. package/lib/npm.js +0 -95
  99. package/lib/npm.js.map +0 -1
  100. /package/lib/action/{index.d.ts → main.d.ts} +0 -0
@@ -0,0 +1,140 @@
1
+ import childProcess from "node:child_process";
2
+ import os from "node:os";
3
+
4
+ import * as errors from "../errors.js";
5
+ import type { Logger } from "../options.js";
6
+ import type { NpmCliEnvironment } from "./use-npm-environment.js";
7
+
8
+ export interface NpmCliOptions {
9
+ environment: NpmCliEnvironment;
10
+ logger?: Logger | undefined;
11
+ }
12
+
13
+ export interface NpmCallResult<CommandT extends Command> {
14
+ successData: SuccessData<CommandT> | undefined;
15
+ errorCode: string | undefined;
16
+ error: Error | undefined;
17
+ }
18
+
19
+ type SuccessData<T extends Command> = T extends typeof VIEW
20
+ ? NpmViewData
21
+ : T extends typeof PUBLISH
22
+ ? NpmPublishData
23
+ : unknown;
24
+
25
+ export interface NpmViewData {
26
+ "dist-tags": Record<string, string>;
27
+ versions: string[];
28
+ }
29
+ export interface NpmPublishData {
30
+ id: string;
31
+ files: { path: string; size: number }[];
32
+ }
33
+
34
+ export type Command = typeof VIEW | typeof PUBLISH | string;
35
+ export const VIEW = "view";
36
+ export const PUBLISH = "publish";
37
+
38
+ export const E404 = "E404";
39
+ export const EPUBLISHCONFLICT = "EPUBLISHCONFLICT";
40
+
41
+ const NPM = os.platform() === "win32" ? "npm.cmd" : "npm";
42
+ const JSON_MATCH_RE = /(\{[\s\S]*\})/mu;
43
+
44
+ /**
45
+ * Call the NPM CLI in JSON mode.
46
+ *
47
+ * @param command The command of the NPM CLI to call
48
+ * @param cliArguments Any arguments to send to the command
49
+ * @param options Customize environment variables or add an error handler.
50
+ * @returns The parsed JSON, or stdout if unparsable.
51
+ */
52
+ export async function callNpmCli<CommandT extends Command>(
53
+ command: CommandT,
54
+ cliArguments: string[],
55
+ options: NpmCliOptions
56
+ ): Promise<NpmCallResult<CommandT>> {
57
+ const { stdout, stderr, exitCode } = await execNpm(
58
+ [command, "--ignore-scripts", "--json", ...cliArguments],
59
+ options.environment,
60
+ options.logger
61
+ );
62
+
63
+ let successData;
64
+ let errorCode;
65
+ let error;
66
+
67
+ if (exitCode === 0) {
68
+ successData = parseJson<SuccessData<CommandT>>(stdout);
69
+ } else {
70
+ const errorPayload = parseJson<{ error?: { code?: string | null } }>(
71
+ stdout,
72
+ stderr
73
+ );
74
+
75
+ errorCode = errorPayload?.error?.code?.toUpperCase();
76
+ error = new errors.NpmCallError(command, exitCode, stderr);
77
+ }
78
+
79
+ return { successData, errorCode, error };
80
+ }
81
+
82
+ /**
83
+ * Execute the npm CLI.
84
+ *
85
+ * @param commandArguments Npm subcommand and arguments.
86
+ * @param environment Environment variables.
87
+ * @param logger Optional logger.
88
+ * @returns Stdout, stderr, and the exit code.
89
+ */
90
+ async function execNpm(
91
+ commandArguments: string[],
92
+ environment: Record<string, string>,
93
+ logger?: Logger
94
+ ): Promise<{ stdout: string; stderr: string; exitCode: number }> {
95
+ logger?.debug?.(`Running command: ${NPM} ${commandArguments.join(" ")}`);
96
+
97
+ return new Promise((resolve) => {
98
+ let stdout = "";
99
+ let stderr = "";
100
+
101
+ const npm = childProcess.spawn(NPM, commandArguments, {
102
+ env: { ...process.env, ...environment },
103
+ });
104
+
105
+ npm.stdout.on("data", (data) => (stdout += data));
106
+ npm.stderr.on("data", (data) => (stderr += data));
107
+ npm.on("close", (code) => {
108
+ resolve({
109
+ stdout: stdout.trim(),
110
+ stderr: stderr.trim(),
111
+ exitCode: code ?? 0,
112
+ });
113
+ });
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Parse CLI outputs for JSON data.
119
+ *
120
+ * Certain versions of the npm CLI may intersperse JSON with human-readable
121
+ * output, which this function accounts for.
122
+ *
123
+ * @param values CLI outputs to check
124
+ * @returns Parsed JSON, if able to parse.
125
+ */
126
+ function parseJson<TParsed>(...values: string[]): TParsed | undefined {
127
+ for (const value of values) {
128
+ const jsonValue = JSON_MATCH_RE.exec(value)?.[1];
129
+
130
+ if (jsonValue) {
131
+ try {
132
+ return JSON.parse(jsonValue) as TParsed;
133
+ } catch {
134
+ return undefined;
135
+ }
136
+ }
137
+ }
138
+
139
+ return undefined;
140
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./call-npm-cli.js";
2
+ export * from "./use-npm-environment.js";
@@ -0,0 +1,57 @@
1
+ import fs from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ import type { PackageManifest } from "../read-manifest.js";
6
+ import type { NormalizedOptions } from "../normalize-options.js";
7
+
8
+ export type NpmCliEnvironment = Record<string, string>;
9
+
10
+ export type NpmCliTask<TReturn> = (
11
+ manifest: PackageManifest,
12
+ options: NormalizedOptions,
13
+ environment: NpmCliEnvironment
14
+ ) => Promise<TReturn>;
15
+
16
+ /**
17
+ * Create a temporary .npmrc file with the given auth token, and call a task
18
+ * with env vars set to use that .npmrc.
19
+ *
20
+ * @param manifest Pacakge metadata.
21
+ * @param options Configuration options.
22
+ * @param task A function called with the configured environment. After the
23
+ * function resolves, the temporary .npmrc file will be removed.
24
+ * @returns The resolved value of `task`
25
+ */
26
+ export async function useNpmEnvironment<TReturn>(
27
+ manifest: PackageManifest,
28
+ options: NormalizedOptions,
29
+ task: NpmCliTask<TReturn>
30
+ ): Promise<TReturn> {
31
+ const { registry, token, logger, temporaryDirectory } = options;
32
+ const npmrcDirectory = await fs.mkdtemp(
33
+ path.join(temporaryDirectory, "npm-publish-")
34
+ );
35
+ const npmrc = path.join(npmrcDirectory, ".npmrc");
36
+ const environment = {
37
+ NODE_AUTH_TOKEN: token,
38
+ npm_config_userconfig: npmrc,
39
+ };
40
+
41
+ const config = [
42
+ "; created by jsdevtools/npm-publish",
43
+ `//${registry.host}/:_authToken=\${NODE_AUTH_TOKEN}`,
44
+ `registry=${registry.href}`,
45
+ "",
46
+ ].join(os.EOL);
47
+
48
+ await fs.writeFile(npmrc, config, "utf8");
49
+
50
+ logger?.debug?.(`Temporary .npmrc created at ${npmrc}\n${config}`);
51
+
52
+ try {
53
+ return await task(manifest, options, environment);
54
+ } finally {
55
+ await fs.rm(npmrcDirectory, { force: true, recursive: true });
56
+ }
57
+ }
@@ -0,0 +1,40 @@
1
+ import { readManifest } from "./read-manifest.js";
2
+ import { normalizeOptions } from "./normalize-options.js";
3
+ import { useNpmEnvironment } from "./npm/index.js";
4
+ import { compareAndPublish } from "./compare-and-publish/index.js";
5
+ import { formatPublishResult } from "./format-publish-result.js";
6
+ import type { Options } from "./options.js";
7
+ import type { Results } from "./results.js";
8
+
9
+ /**
10
+ * Publishes a package to NPM, if its version has changed.
11
+ *
12
+ * @param options Publish options.
13
+ * @returns Release metadata.
14
+ */
15
+ export async function npmPublish(options: Options): Promise<Results> {
16
+ const manifest = await readManifest(options.package);
17
+ const normalizedOptions = normalizeOptions(manifest, options);
18
+ const publishResult = await useNpmEnvironment(
19
+ manifest,
20
+ normalizedOptions,
21
+ compareAndPublish
22
+ );
23
+
24
+ normalizedOptions.logger?.info?.(
25
+ formatPublishResult(manifest, normalizedOptions, publishResult)
26
+ );
27
+
28
+ return {
29
+ id: publishResult.id,
30
+ type: publishResult.type,
31
+ oldVersion: publishResult.oldVersion,
32
+ name: manifest.name,
33
+ version: manifest.version,
34
+ registry: normalizedOptions.registry,
35
+ tag: normalizedOptions.tag.value,
36
+ access: normalizedOptions.access.value,
37
+ strategy: normalizedOptions.strategy.value,
38
+ dryRun: normalizedOptions.dryRun.value,
39
+ };
40
+ }
package/src/options.ts ADDED
@@ -0,0 +1,108 @@
1
+ /** The possible access levels for an NPM package */
2
+ export type Access = typeof ACCESS_PUBLIC | typeof ACCESS_RESTRICTED;
3
+ export const ACCESS_PUBLIC = "public";
4
+ export const ACCESS_RESTRICTED = "restricted";
5
+
6
+ /**
7
+ * Version check strategy.
8
+ *
9
+ * - `upgrade`: the package will only be published if its version is higher than
10
+ * the existing version on the configured tag.
11
+ * - `all`: the package will be published if its version is not yet published,
12
+ * even if its lower that the existing tag.
13
+ */
14
+ export type Strategy = typeof STRATEGY_UPGRADE | typeof STRATEGY_ALL;
15
+ export const STRATEGY_UPGRADE = "upgrade";
16
+ export const STRATEGY_ALL = "all";
17
+
18
+ /** An interface that can be used to log messages. */
19
+ export interface Logger {
20
+ error: (message: string | Error) => void;
21
+ info?: undefined | ((message: string) => void);
22
+ debug?: undefined | ((message: string) => void);
23
+ }
24
+
25
+ /** Options that determine how/whether the package is published. */
26
+ export interface Options {
27
+ /** The NPM access token to use when publishing. */
28
+ token: string;
29
+
30
+ /**
31
+ * The absolute or relative path of your package.
32
+ *
33
+ * Defaults to the package in the current working directory.
34
+ */
35
+ package?: string | undefined;
36
+
37
+ /**
38
+ * The NPM registry URL to use.
39
+ *
40
+ * Defaults to "https://registry.npmjs.org/".
41
+ *
42
+ * Can be set by the package.json's `publishConfig` field.
43
+ */
44
+ registry?: string | URL | undefined;
45
+
46
+ /**
47
+ * The tag to publish to.
48
+ *
49
+ * Defaults to "latest".
50
+ *
51
+ * Can be set by the package.json's `publishConfig` field.
52
+ */
53
+ tag?: string | undefined;
54
+
55
+ /**
56
+ * Package access.
57
+ *
58
+ * Determines whether the published package should be publicly visible, or
59
+ * restricted to members of your NPM organization. This only applies to scoped
60
+ * packages.
61
+ *
62
+ * Defaults to "restricted" for scoped packages, unless that package has been
63
+ * previously published as `public`
64
+ *
65
+ * Can be set by the package.json's `publishConfig` field.
66
+ */
67
+ access?: Access | undefined;
68
+
69
+ /**
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`.
76
+ *
77
+ * Can be set by the package.json's `publishConfig` field.
78
+ */
79
+ provenance?: boolean | undefined;
80
+
81
+ /**
82
+ * Version check strategy.
83
+ *
84
+ * If "upgrade" (default), the package will only be published if its version
85
+ * is higher than the existing version on the configured tag. If "always", the
86
+ * package will be published if its version is simply not yet published.
87
+ *
88
+ * Defaults to `upgrade`.
89
+ */
90
+ strategy?: Strategy | undefined;
91
+
92
+ /**
93
+ * Pretend to publish, but don't actually upload to the registry.
94
+ *
95
+ * Defaults to `false`.
96
+ */
97
+ dryRun?: boolean | undefined;
98
+
99
+ /** Optional logger. */
100
+ logger?: Logger | undefined;
101
+
102
+ /**
103
+ * Temporary directory.
104
+ *
105
+ * Defaults to os.tmpdir()
106
+ */
107
+ temporaryDirectory?: string | undefined;
108
+ }
@@ -0,0 +1,142 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { valid as semverValid } from "semver";
4
+ import { list as tarList, type ReadEntry } from "tar";
5
+
6
+ import * as errors from "./errors.js";
7
+
8
+ /** A package manifest (package.json) and associated details. */
9
+ export interface PackageManifest {
10
+ packageSpec: string;
11
+ name: string;
12
+ version: string;
13
+ scope: string | undefined;
14
+ publishConfig: PackagePublishConfig | undefined;
15
+ }
16
+
17
+ /** Any publish configuration defined in package.json. */
18
+ export interface PackagePublishConfig {
19
+ tag?: string;
20
+ access?: string;
21
+ registry?: string;
22
+ provenance?: boolean;
23
+ }
24
+
25
+ const SCOPE_RE = /^(@.+)\/.+$/u;
26
+
27
+ const MANIFEST_BASENAME = "package.json";
28
+ const TARBALL_EXTNAME = ".tgz";
29
+
30
+ const isManifest = (file: unknown): file is string => {
31
+ return typeof file === "string" && path.basename(file) === MANIFEST_BASENAME;
32
+ };
33
+
34
+ const isDirectory = (file: unknown): file is string => {
35
+ return typeof file === "string" && path.extname(file) === "";
36
+ };
37
+
38
+ const isTarball = (file: unknown): file is string => {
39
+ return typeof file === "string" && path.extname(file) === TARBALL_EXTNAME;
40
+ };
41
+
42
+ const isVersion = (version: unknown): version is string => {
43
+ return semverValid(version as string) !== null;
44
+ };
45
+
46
+ const readPackageJson = async (...pathSegments: string[]): Promise<string> => {
47
+ const file = path.resolve(...pathSegments);
48
+
49
+ try {
50
+ return await fs.readFile(file, "utf8");
51
+ } catch (error) {
52
+ throw new errors.PackageJsonReadError(file, error);
53
+ }
54
+ };
55
+
56
+ const readTarballPackageJson = async (file: string): Promise<string> => {
57
+ const data: Buffer[] = [];
58
+ const onentry = (entry: ReadEntry) => {
59
+ if (entry.path === "package/package.json") {
60
+ entry.on("data", (chunk) => data.push(chunk));
61
+ }
62
+ };
63
+
64
+ try {
65
+ await tarList({ file, onentry });
66
+
67
+ if (data.length === 0) {
68
+ throw new Error("package.json not found inside archive");
69
+ }
70
+ } catch (error) {
71
+ throw new errors.PackageTarballReadError(file, error);
72
+ }
73
+
74
+ return Buffer.concat(data).toString();
75
+ };
76
+
77
+ /**
78
+ * Reads the package manifest (package.json) and returns its parsed contents.
79
+ *
80
+ * @param packagePath The path to the package being published.
81
+ * @returns The parsed package metadata.
82
+ */
83
+ export async function readManifest(
84
+ packagePath: unknown
85
+ ): Promise<PackageManifest> {
86
+ let packageSpec: string | undefined;
87
+ let manifestContents: string;
88
+
89
+ if (!packagePath) {
90
+ packageSpec = "";
91
+ manifestContents = await readPackageJson(MANIFEST_BASENAME);
92
+ } else if (isManifest(packagePath)) {
93
+ packageSpec = path.resolve(path.dirname(packagePath));
94
+ manifestContents = await readPackageJson(packagePath);
95
+ } else if (isDirectory(packagePath)) {
96
+ packageSpec = path.resolve(packagePath);
97
+ manifestContents = await readPackageJson(packagePath, MANIFEST_BASENAME);
98
+ } else if (isTarball(packagePath)) {
99
+ packageSpec = path.resolve(packagePath);
100
+ manifestContents = await readTarballPackageJson(packageSpec);
101
+ } else {
102
+ throw new errors.InvalidPackageError(packagePath);
103
+ }
104
+
105
+ let manifestJson: Record<string, unknown>;
106
+ let name: unknown;
107
+ let version: unknown;
108
+ let publishConfig: unknown;
109
+
110
+ try {
111
+ manifestJson = JSON.parse(manifestContents) as Record<string, unknown>;
112
+ name = manifestJson["name"];
113
+ version = manifestJson["version"];
114
+ publishConfig = manifestJson["publishConfig"] ?? {};
115
+ } catch (error) {
116
+ throw new errors.PackageJsonParseError(packageSpec, error);
117
+ }
118
+
119
+ if (typeof name !== "string" || name.length === 0) {
120
+ throw new errors.InvalidPackageNameError(name);
121
+ }
122
+
123
+ if (!isVersion(version)) {
124
+ throw new errors.InvalidPackageVersionError(version);
125
+ }
126
+
127
+ if (
128
+ typeof publishConfig !== "object" ||
129
+ Array.isArray(publishConfig) ||
130
+ !publishConfig
131
+ ) {
132
+ throw new errors.InvalidPackagePublishConfigError(publishConfig);
133
+ }
134
+
135
+ return {
136
+ packageSpec,
137
+ name,
138
+ version,
139
+ publishConfig,
140
+ scope: SCOPE_RE.exec(name)?.[1],
141
+ };
142
+ }
package/src/results.ts ADDED
@@ -0,0 +1,50 @@
1
+ import type { Access, Strategy } from "./options.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";
8
+
9
+ /** Results of the publish */
10
+ export interface Results {
11
+ /**
12
+ * The identifier of the published package, if published. Format is
13
+ * `${packageName}@${version}`
14
+ */
15
+ id: string | undefined;
16
+
17
+ /** The name of the NPM package that was published */
18
+ name: string;
19
+
20
+ /** The version that was published */
21
+ version: string;
22
+
23
+ /** The type of version change that occurred, if any. */
24
+ type: ReleaseType | undefined;
25
+
26
+ /** The version number that was previously published to NPM, if any. */
27
+ oldVersion: string | undefined;
28
+
29
+ /** The registry where the package was published */
30
+ registry: URL;
31
+
32
+ /** The tag that the package was published to. */
33
+ tag: string;
34
+
35
+ /**
36
+ * Indicates whether the published package is publicly visible or restricted
37
+ * to members of your NPM organization.
38
+ *
39
+ * If package is scoped, undefined means npm's scoped package defaults. If a
40
+ * scoped package has previously been published as public, the default is
41
+ * public. Otherwise, it is restricted.
42
+ */
43
+ access: Access | undefined;
44
+
45
+ /** Version check strategy used. */
46
+ strategy: Strategy;
47
+
48
+ /** Whether this was a dry run (not published to NPM) */
49
+ dryRun: boolean;
50
+ }
package/CHANGELOG.md DELETED
@@ -1,49 +0,0 @@
1
- Change Log
2
- ====================================================================================================
3
- All notable changes will be documented in this file.
4
- NPM Publish adheres to [Semantic Versioning](http://semver.org/).
5
-
6
-
7
-
8
- [v1.4.0](https://github.com/JS-DevTools/npm-publish/tree/v1.4.0) (2020-10-02)
9
- ----------------------------------------------------------------------------------------------------
10
-
11
- - Added support NPM's `--tag` argument, which allows packages to be published to a named tag that can then be installed using `npm install <package-name>@<tag>`
12
-
13
- - Added support for NPM's `--access` argument, which controls whether scoped packages are publicly accessible, or restricted to members of your NPM organization
14
-
15
- [Full Changelog](https://github.com/JS-DevTools/npm-publish/compare/v1.3.0...v1.4.0)
16
-
17
-
18
-
19
- [v1.3.0](https://github.com/JS-DevTools/npm-publish/tree/v1.3.0) (2020-10-01)
20
- ----------------------------------------------------------------------------------------------------
21
-
22
- - NPM-Publish can now successfully publish a brand-new package to NPM. Previously it failed because it couldn't determine the previous package version. ([PR #12](https://github.com/JS-DevTools/npm-publish/pull/12) from [@ZitRos](https://github.com/ZitRos))
23
-
24
- [Full Changelog](https://github.com/JS-DevTools/npm-publish/compare/v1.2.0...v1.3.0)
25
-
26
-
27
-
28
- [v1.2.0](https://github.com/JS-DevTools/npm-publish/tree/v1.2.0) (2020-07-23)
29
- ----------------------------------------------------------------------------------------------------
30
-
31
- - Added support for running NPM in "dry run" mode, which doesn't actually publish, but reports details of what _would_ have been published.
32
-
33
- [Full Changelog](https://github.com/JS-DevTools/npm-publish/compare/v1.1.2...v1.2.0)
34
-
35
-
36
-
37
- [v1.1.0](https://github.com/JS-DevTools/npm-publish/tree/v1.1.0) (2020-03-29)
38
- ----------------------------------------------------------------------------------------------------
39
-
40
- - FIX: The configured NPM registry and token are now used _all_ NPM commands, not just for publishing. This ensures that npm-publish works with private packages and custom registries
41
-
42
- [Full Changelog](https://github.com/JS-DevTools/npm-publish/compare/v1.0.13...v1.1.0)
43
-
44
-
45
-
46
- [v1.0.0](https://github.com/JS-DevTools/npm-publish/tree/v1.0.0) (2020-01-21)
47
- ----------------------------------------------------------------------------------------------------
48
-
49
- Initial release šŸŽ‰
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@actions/core");
4
- const npm_publish_1 = require("../npm-publish");
5
- /**
6
- * The main entry point of the GitHub Action
7
- * @internal
8
- */
9
- async function main() {
10
- try {
11
- // Setup global error handlers
12
- process.on("uncaughtException", errorHandler);
13
- process.on("unhandledRejection", errorHandler);
14
- // Get the GitHub Actions input options
15
- const options = {
16
- token: core_1.getInput("token", { required: true }),
17
- registry: core_1.getInput("registry", { required: true }),
18
- package: core_1.getInput("package", { required: true }),
19
- checkVersion: core_1.getInput("check-version", { required: true }).toLowerCase() === "true",
20
- tag: core_1.getInput("tag"),
21
- access: core_1.getInput("access"),
22
- dryRun: core_1.getInput("dry-run").toLowerCase() === "true",
23
- debug: debugHandler,
24
- };
25
- // Publish to NPM
26
- let results = await npm_publish_1.npmPublish(options);
27
- if (results.type === "none") {
28
- console.log(`\nšŸ“¦ ${results.package} v${results.version} is already published to NPM`);
29
- }
30
- else if (results.dryRun) {
31
- console.log(`\nšŸ“¦ ${results.package} v${results.version} was NOT actually published to NPM (dry run)`);
32
- }
33
- else {
34
- console.log(`\nšŸ“¦ Successfully published ${results.package} v${results.version} to NPM`);
35
- }
36
- // Set the GitHub Actions output variables
37
- core_1.setOutput("type", results.type);
38
- core_1.setOutput("version", results.version);
39
- core_1.setOutput("old-version", results.oldVersion);
40
- core_1.setOutput("tag", results.tag);
41
- core_1.setOutput("access", results.access);
42
- core_1.setOutput("dry-run", results.dryRun);
43
- }
44
- catch (error) {
45
- errorHandler(error);
46
- }
47
- }
48
- /**
49
- * Prints errors to the GitHub Actions console
50
- */
51
- function errorHandler(error) {
52
- let message = error.stack || error.message || String(error);
53
- core_1.setFailed(message);
54
- process.exit();
55
- }
56
- /**
57
- * Prints debug logs to the GitHub Actions console
58
- */
59
- function debugHandler(message, data) {
60
- if (data) {
61
- message += "\n" + JSON.stringify(data, undefined, 2);
62
- }
63
- core_1.debug(message);
64
- }
65
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
66
- main();
67
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/action/index.ts"],"names":[],"mappings":";;AAAA,wCAAsE;AACtE,gDAA4C;AAG5C;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,IAAI;QACF,8BAA8B;QAC9B,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;QAC9C,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;QAE/C,uCAAuC;QACvC,MAAM,OAAO,GAAY;YACvB,KAAK,EAAE,eAAQ,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YAC5C,QAAQ,EAAE,eAAQ,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YAClD,OAAO,EAAE,eAAQ,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YAChD,YAAY,EAAE,eAAQ,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM;YACpF,GAAG,EAAE,eAAQ,CAAC,KAAK,CAAC;YACpB,MAAM,EAAE,eAAQ,CAAC,QAAQ,CAAW;YACpC,MAAM,EAAE,eAAQ,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM;YACpD,KAAK,EAAE,YAAY;SACpB,CAAC;QAEF,iBAAiB;QACjB,IAAI,OAAO,GAAG,MAAM,wBAAU,CAAC,OAAO,CAAC,CAAC;QAExC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,QAAQ,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,8BAA8B,CAAC,CAAC;SACxF;aACI,IAAI,OAAO,CAAC,MAAM,EAAE;YACvB,OAAO,CAAC,GAAG,CAAC,QAAQ,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,8CAA8C,CAAC,CAAC;SACxG;aACI;YACH,OAAO,CAAC,GAAG,CAAC,+BAA+B,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,SAAS,CAAC,CAAC;SAC1F;QAED,0CAA0C;QAC1C,gBAAS,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,gBAAS,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACtC,gBAAS,CAAC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7C,gBAAS,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,gBAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACpC,gBAAS,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;KACtC;IACD,OAAO,KAAK,EAAE;QACZ,YAAY,CAAC,KAAc,CAAC,CAAC;KAC9B;AACH,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,KAAY;IAChC,IAAI,OAAO,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D,gBAAS,CAAC,OAAO,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,EAAE,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,OAAe,EAAE,IAAa;IAClD,IAAI,IAAI,EAAE;QACR,OAAO,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;KACtD;IAED,YAAK,CAAC,OAAO,CAAC,CAAC;AACjB,CAAC;AAED,mEAAmE;AACnE,IAAI,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExitCode = void 0;
4
- /**
5
- * CLI exit codes.
6
- *
7
- * @see https://nodejs.org/api/process.html#process_exit_codes
8
- * @internal
9
- */
10
- var ExitCode;
11
- (function (ExitCode) {
12
- ExitCode[ExitCode["Success"] = 0] = "Success";
13
- ExitCode[ExitCode["FatalError"] = 1] = "FatalError";
14
- ExitCode[ExitCode["InvalidArgument"] = 9] = "InvalidArgument";
15
- })(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
16
- //# sourceMappingURL=exit-code.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exit-code.js","sourceRoot":"","sources":["../../src/cli/exit-code.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,mDAAc,CAAA;IACd,6DAAmB,CAAA;AACrB,CAAC,EAJW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAInB"}