@jsdevtools/npm-publish 1.4.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -147
- package/bin/npm-publish.js +10 -2
- package/lib/action/core.d.ts +45 -0
- package/lib/action/core.js +59 -0
- package/lib/action/core.js.map +1 -0
- package/lib/action/main.js +54 -0
- package/lib/action/main.js.map +1 -0
- package/lib/cli/index.d.ts +4 -2
- package/lib/cli/index.js +57 -53
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/parse-cli-arguments.d.ts +17 -0
- package/lib/cli/parse-cli-arguments.js +39 -0
- package/lib/cli/parse-cli-arguments.js.map +1 -0
- package/lib/compare-versions.d.ts +20 -0
- package/lib/compare-versions.js +36 -0
- package/lib/compare-versions.js.map +1 -0
- package/lib/errors.d.ts +36 -0
- package/lib/errors.js +114 -0
- package/lib/errors.js.map +1 -0
- package/lib/format-publish-result.d.ts +12 -0
- package/lib/format-publish-result.js +36 -0
- package/lib/format-publish-result.js.map +1 -0
- package/lib/index.d.ts +4 -5
- package/lib/index.js +11 -10
- package/lib/index.js.map +1 -1
- package/lib/normalize-options.d.ts +26 -1
- package/lib/normalize-options.js +86 -13
- package/lib/normalize-options.js.map +1 -1
- package/lib/npm/call-npm-cli.d.ts +16 -0
- package/lib/npm/call-npm-cli.js +91 -0
- package/lib/npm/call-npm-cli.js.map +1 -0
- package/lib/npm/get-publish-arguments.d.ts +9 -0
- package/lib/npm/get-publish-arguments.js +29 -0
- package/lib/npm/get-publish-arguments.js.map +1 -0
- package/lib/npm/index.d.ts +29 -0
- package/lib/npm/index.js +41 -0
- package/lib/npm/index.js.map +1 -0
- package/lib/npm/use-npm-environment.d.ts +13 -0
- package/lib/npm/use-npm-environment.js +42 -0
- package/lib/npm/use-npm-environment.js.map +1 -0
- package/lib/npm-publish.d.ts +7 -4
- package/lib/npm-publish.js +29 -25
- package/lib/npm-publish.js.map +1 -1
- package/lib/options.d.ts +58 -46
- package/lib/options.js +5 -0
- package/lib/options.js.map +1 -1
- package/lib/read-manifest.d.ts +25 -1
- package/lib/read-manifest.js +119 -22
- package/lib/read-manifest.js.map +1 -1
- package/lib/results.d.ts +26 -28
- package/package.json +43 -35
- package/src/action/core.ts +91 -0
- package/src/action/main.ts +31 -0
- package/src/cli/index.ts +69 -0
- package/src/cli/parse-cli-arguments.ts +48 -0
- package/src/compare-versions.ts +52 -0
- package/src/errors.ts +130 -0
- package/src/format-publish-result.ts +40 -0
- package/src/index.ts +7 -0
- package/src/normalize-options.ts +119 -0
- package/src/npm/call-npm-cli.ts +98 -0
- package/src/npm/get-publish-arguments.ts +34 -0
- package/src/npm/index.ts +64 -0
- package/src/npm/use-npm-environment.ts +51 -0
- package/src/npm-publish.ts +47 -0
- package/src/options.ts +96 -0
- package/src/read-manifest.ts +143 -0
- package/src/results.ts +45 -0
- package/CHANGELOG.md +0 -49
- package/lib/action/index.js +0 -67
- package/lib/action/index.js.map +0 -1
- package/lib/cli/exit-code.d.ts +0 -1
- package/lib/cli/exit-code.js +0 -16
- package/lib/cli/exit-code.js.map +0 -1
- package/lib/cli/help.d.ts +0 -1
- package/lib/cli/help.js +0 -28
- package/lib/cli/help.js.map +0 -1
- package/lib/cli/parse-args.d.ts +0 -1
- package/lib/cli/parse-args.js +0 -58
- package/lib/cli/parse-args.js.map +0 -1
- package/lib/npm-config.d.ts +0 -1
- package/lib/npm-config.js +0 -85
- package/lib/npm-config.js.map +0 -1
- package/lib/npm-env.d.ts +0 -6
- package/lib/npm-env.js +0 -24
- package/lib/npm-env.js.map +0 -1
- package/lib/npm.d.ts +0 -1
- package/lib/npm.js +0 -95
- package/lib/npm.js.map +0 -1
- /package/lib/action/{index.d.ts → main.d.ts} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import type { NormalizedOptions } from "../normalize-options.js";
|
|
6
|
+
|
|
7
|
+
export type NpmCliEnvironment = Record<string, string>;
|
|
8
|
+
|
|
9
|
+
export type NpmCliTask<TReturn> = (
|
|
10
|
+
environment: NpmCliEnvironment
|
|
11
|
+
) => Promise<TReturn>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a temporary .npmrc file with the given auth token, and call a task
|
|
15
|
+
* with env vars set to use that .npmrc.
|
|
16
|
+
*
|
|
17
|
+
* @param options Configuration options.
|
|
18
|
+
* @param task A function called with the configured environment. After the
|
|
19
|
+
* function resolves, the temporary .npmrc file will be removed.
|
|
20
|
+
* @returns The resolved value of `task`
|
|
21
|
+
*/
|
|
22
|
+
export async function useNpmEnvironment<TReturn>(
|
|
23
|
+
options: NormalizedOptions,
|
|
24
|
+
task: NpmCliTask<TReturn>
|
|
25
|
+
): Promise<TReturn> {
|
|
26
|
+
const { registry, token, logger, temporaryDirectory } = options;
|
|
27
|
+
const npmrcDirectory = await fs.mkdtemp(
|
|
28
|
+
path.join(temporaryDirectory, "npm-publish-")
|
|
29
|
+
);
|
|
30
|
+
const npmrc = path.join(npmrcDirectory, ".npmrc");
|
|
31
|
+
|
|
32
|
+
const config = [
|
|
33
|
+
"; created by jsdevtools/npm-publish",
|
|
34
|
+
`//${registry.host}/:_authToken=\${NODE_AUTH_TOKEN}`,
|
|
35
|
+
`registry=${registry.href}`,
|
|
36
|
+
"",
|
|
37
|
+
].join(os.EOL);
|
|
38
|
+
|
|
39
|
+
await fs.writeFile(npmrc, config, "utf8");
|
|
40
|
+
|
|
41
|
+
logger?.debug?.(`Temporary .npmrc created at ${npmrc}\n${config}`);
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
return await task({
|
|
45
|
+
NODE_AUTH_TOKEN: token,
|
|
46
|
+
npm_config_userconfig: npmrc,
|
|
47
|
+
});
|
|
48
|
+
} finally {
|
|
49
|
+
await fs.rm(npmrcDirectory, { force: true, recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readManifest } from "./read-manifest.js";
|
|
2
|
+
import { normalizeOptions } from "./normalize-options.js";
|
|
3
|
+
import { getVersions, publish } from "./npm/index.js";
|
|
4
|
+
import { compareVersions } from "./compare-versions.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 { packageSpec, manifest } = await readManifest(options.package);
|
|
17
|
+
const normalizedOptions = normalizeOptions(options, manifest);
|
|
18
|
+
const publishedVersions = await getVersions(manifest.name, normalizedOptions);
|
|
19
|
+
const versionComparison = compareVersions(
|
|
20
|
+
manifest.version,
|
|
21
|
+
publishedVersions,
|
|
22
|
+
normalizedOptions
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
let publishResult;
|
|
26
|
+
|
|
27
|
+
if (versionComparison.type !== undefined) {
|
|
28
|
+
publishResult = await publish(packageSpec, normalizedOptions);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
normalizedOptions.logger?.info?.(
|
|
32
|
+
formatPublishResult(manifest, normalizedOptions, publishResult)
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
id: publishResult?.id,
|
|
37
|
+
name: manifest.name,
|
|
38
|
+
version: manifest.version,
|
|
39
|
+
type: versionComparison.type,
|
|
40
|
+
oldVersion: versionComparison.oldVersion,
|
|
41
|
+
registry: normalizedOptions.registry,
|
|
42
|
+
tag: normalizedOptions.tag.value,
|
|
43
|
+
access: normalizedOptions.access.value,
|
|
44
|
+
strategy: normalizedOptions.strategy.value,
|
|
45
|
+
dryRun: normalizedOptions.dryRun.value,
|
|
46
|
+
};
|
|
47
|
+
}
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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 overridden 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 overridden 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 overridden by the package.json's `publishConfig` field.
|
|
66
|
+
*/
|
|
67
|
+
access?: Access | undefined;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Version check strategy.
|
|
71
|
+
*
|
|
72
|
+
* If "upgrade" (default), the package will only be published if its version
|
|
73
|
+
* is higher than the existing version on the configured tag. If "always", the
|
|
74
|
+
* package will be published if its version is simply not yet published.
|
|
75
|
+
*
|
|
76
|
+
* Defaults to `upgrade`.
|
|
77
|
+
*/
|
|
78
|
+
strategy?: Strategy | undefined;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Pretend to publish, but don't actually upload to the registry.
|
|
82
|
+
*
|
|
83
|
+
* Defaults to `false`.
|
|
84
|
+
*/
|
|
85
|
+
dryRun?: boolean | undefined;
|
|
86
|
+
|
|
87
|
+
/** Optional logger. */
|
|
88
|
+
logger?: Logger | undefined;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Temporary directory.
|
|
92
|
+
*
|
|
93
|
+
* Defaults to os.tmpdir()
|
|
94
|
+
*/
|
|
95
|
+
temporaryDirectory?: string | undefined;
|
|
96
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
/** 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) */
|
|
15
|
+
export interface PackageManifest {
|
|
16
|
+
name: string;
|
|
17
|
+
version: string;
|
|
18
|
+
scope: string | undefined;
|
|
19
|
+
publishConfig: PackagePublishConfig | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Any publish configuration defined in package.json. */
|
|
23
|
+
export interface PackagePublishConfig {
|
|
24
|
+
tag?: string;
|
|
25
|
+
access?: string;
|
|
26
|
+
registry?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const SCOPE_RE = /^(@.+)\/.+$/u;
|
|
30
|
+
|
|
31
|
+
const MANIFEST_BASENAME = "package.json";
|
|
32
|
+
const TARBALL_EXTNAME = ".tgz";
|
|
33
|
+
|
|
34
|
+
const isManifest = (file: unknown): file is string => {
|
|
35
|
+
return typeof file === "string" && path.basename(file) === MANIFEST_BASENAME;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isDirectory = (file: unknown): file is string => {
|
|
39
|
+
return typeof file === "string" && path.extname(file) === "";
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const isTarball = (file: unknown): file is string => {
|
|
43
|
+
return typeof file === "string" && path.extname(file) === TARBALL_EXTNAME;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const isVersion = (version: unknown): version is string => {
|
|
47
|
+
return semverValid(version as string) !== null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const readPackageJson = async (...pathSegments: string[]): Promise<string> => {
|
|
51
|
+
const file = path.resolve(...pathSegments);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
return await fs.readFile(file, "utf8");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new errors.PackageJsonReadError(file, error);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const readTarballPackageJson = async (file: string): Promise<string> => {
|
|
61
|
+
const data: Buffer[] = [];
|
|
62
|
+
const onentry = (entry: ReadEntry) => {
|
|
63
|
+
if (entry.path === "package/package.json") {
|
|
64
|
+
entry.on("data", (chunk) => data.push(chunk));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await tarList({ file, onentry });
|
|
70
|
+
|
|
71
|
+
if (data.length === 0) {
|
|
72
|
+
throw new Error("package.json not found inside archive");
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new errors.PackageTarballReadError(file, error);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return Buffer.concat(data).toString();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Reads the package manifest (package.json) and returns its parsed contents.
|
|
83
|
+
*
|
|
84
|
+
* @param packagePath The path to the package being published.
|
|
85
|
+
* @returns The parsed package metadata.
|
|
86
|
+
*/
|
|
87
|
+
export async function readManifest(
|
|
88
|
+
packagePath: unknown
|
|
89
|
+
): Promise<ManifestReadResult> {
|
|
90
|
+
let packageSpec: string | undefined;
|
|
91
|
+
let manifestContents: string;
|
|
92
|
+
|
|
93
|
+
if (!packagePath) {
|
|
94
|
+
packageSpec = "";
|
|
95
|
+
manifestContents = await readPackageJson(MANIFEST_BASENAME);
|
|
96
|
+
} else if (isManifest(packagePath)) {
|
|
97
|
+
packageSpec = path.resolve(path.dirname(packagePath));
|
|
98
|
+
manifestContents = await readPackageJson(packagePath);
|
|
99
|
+
} else if (isDirectory(packagePath)) {
|
|
100
|
+
packageSpec = path.resolve(packagePath);
|
|
101
|
+
manifestContents = await readPackageJson(packagePath, MANIFEST_BASENAME);
|
|
102
|
+
} else if (isTarball(packagePath)) {
|
|
103
|
+
packageSpec = path.resolve(packagePath);
|
|
104
|
+
manifestContents = await readTarballPackageJson(packageSpec);
|
|
105
|
+
} else {
|
|
106
|
+
throw new errors.InvalidPackageError(packagePath);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let manifestJson: Record<string, unknown>;
|
|
110
|
+
let name: unknown;
|
|
111
|
+
let version: unknown;
|
|
112
|
+
let publishConfig: unknown;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
manifestJson = JSON.parse(manifestContents) as Record<string, unknown>;
|
|
116
|
+
name = manifestJson["name"];
|
|
117
|
+
version = manifestJson["version"];
|
|
118
|
+
publishConfig = manifestJson["publishConfig"] ?? {};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
throw new errors.PackageJsonParseError(packageSpec, error);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
124
|
+
throw new errors.InvalidPackageNameError(name);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!isVersion(version)) {
|
|
128
|
+
throw new errors.InvalidPackageVersionError(version);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
typeof publishConfig !== "object" ||
|
|
133
|
+
Array.isArray(publishConfig) ||
|
|
134
|
+
!publishConfig
|
|
135
|
+
) {
|
|
136
|
+
throw new errors.InvalidPackagePublishConfigError(publishConfig);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
packageSpec,
|
|
141
|
+
manifest: { name, version, publishConfig, scope: SCOPE_RE.exec(name)?.[1] },
|
|
142
|
+
};
|
|
143
|
+
}
|
package/src/results.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Access, Strategy } from "./options.js";
|
|
2
|
+
import type { ReleaseType } from "./compare-versions.js";
|
|
3
|
+
|
|
4
|
+
/** Results of the publish */
|
|
5
|
+
export interface Results {
|
|
6
|
+
/**
|
|
7
|
+
* The identifier of the published package, if published. Format is
|
|
8
|
+
* `${packageName}@${version}`
|
|
9
|
+
*/
|
|
10
|
+
id: string | undefined;
|
|
11
|
+
|
|
12
|
+
/** The name of the NPM package that was published */
|
|
13
|
+
name: string;
|
|
14
|
+
|
|
15
|
+
/** The version that was published */
|
|
16
|
+
version: string;
|
|
17
|
+
|
|
18
|
+
/** The type of version change that occurred, if any. */
|
|
19
|
+
type: ReleaseType | undefined;
|
|
20
|
+
|
|
21
|
+
/** The version number that was previously published to NPM, if any. */
|
|
22
|
+
oldVersion: string | undefined;
|
|
23
|
+
|
|
24
|
+
/** The registry where the package was published */
|
|
25
|
+
registry: URL;
|
|
26
|
+
|
|
27
|
+
/** The tag that the package was published to. */
|
|
28
|
+
tag: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Indicates whether the published package is publicly visible or restricted
|
|
32
|
+
* to members of your NPM organization.
|
|
33
|
+
*
|
|
34
|
+
* If package is scoped, undefined means npm's scoped package defaults. If a
|
|
35
|
+
* scoped package has previously been published as public, the default is
|
|
36
|
+
* public. Otherwise, it is restricted.
|
|
37
|
+
*/
|
|
38
|
+
access: Access | undefined;
|
|
39
|
+
|
|
40
|
+
/** Version check strategy used. */
|
|
41
|
+
strategy: Strategy;
|
|
42
|
+
|
|
43
|
+
/** Whether this was a dry run (not published to NPM) */
|
|
44
|
+
dryRun: boolean;
|
|
45
|
+
}
|
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 🎉
|
package/lib/action/index.js
DELETED
|
@@ -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
|
package/lib/action/index.js.map
DELETED
|
@@ -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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AC,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"}
|
package/lib/cli/exit-code.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/cli/exit-code.js
DELETED
|
@@ -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
|
package/lib/cli/exit-code.js.map
DELETED
|
@@ -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"}
|
package/lib/cli/help.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/cli/help.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usageText = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Text explaining how to use the CLI
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
exports.usageText = `
|
|
9
|
-
Usage: npm-publish [options] [package_path]
|
|
10
|
-
|
|
11
|
-
options:
|
|
12
|
-
--token <token> The NPM access token to use when publishing
|
|
13
|
-
|
|
14
|
-
--registry <url> The NPM registry URL to use
|
|
15
|
-
|
|
16
|
-
--debug, -d Enable debug mode, with increased logging
|
|
17
|
-
|
|
18
|
-
--quiet, -q Suppress unnecessary output
|
|
19
|
-
|
|
20
|
-
--version, -v Print the version number
|
|
21
|
-
|
|
22
|
-
--help, -h Show help
|
|
23
|
-
|
|
24
|
-
package_path The absolute or relative path of the NPM package to publish.
|
|
25
|
-
Can be a directory path, or the path of a package.json file.
|
|
26
|
-
Defaults to the current directory.
|
|
27
|
-
`;
|
|
28
|
-
//# sourceMappingURL=help.js.map
|
package/lib/cli/help.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,SAAS,GAAG;;;;;;;;;;;;;;;;;;;CAmBxB,CAAC"}
|
package/lib/cli/parse-args.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/cli/parse-args.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseArgs = void 0;
|
|
4
|
-
const commandLineArgs = require("command-line-args");
|
|
5
|
-
const exit_code_1 = require("./exit-code");
|
|
6
|
-
const help_1 = require("./help");
|
|
7
|
-
/**
|
|
8
|
-
* Parses the command-line arguments
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
function parseArgs(argv) {
|
|
12
|
-
try {
|
|
13
|
-
let args = commandLineArgs([
|
|
14
|
-
{ name: "token", type: String },
|
|
15
|
-
{ name: "registry", type: String },
|
|
16
|
-
{ name: "package", type: String, defaultOption: true },
|
|
17
|
-
{ name: "tag", type: String },
|
|
18
|
-
{ name: "access", type: String },
|
|
19
|
-
{ name: "dry-run", type: Boolean },
|
|
20
|
-
{ name: "debug", alias: "d", type: Boolean },
|
|
21
|
-
{ name: "quiet", alias: "q", type: Boolean },
|
|
22
|
-
{ name: "version", alias: "v", type: Boolean },
|
|
23
|
-
{ name: "help", alias: "h", type: Boolean },
|
|
24
|
-
], { argv });
|
|
25
|
-
if (args.token === null) {
|
|
26
|
-
throw new SyntaxError("The --token argument requires a value");
|
|
27
|
-
}
|
|
28
|
-
if (args.registry === null) {
|
|
29
|
-
throw new SyntaxError("The --registry argument requires a value");
|
|
30
|
-
}
|
|
31
|
-
let parsedArgs = {
|
|
32
|
-
help: args.help,
|
|
33
|
-
version: args.version,
|
|
34
|
-
options: {
|
|
35
|
-
token: args.token,
|
|
36
|
-
registry: args.registry,
|
|
37
|
-
package: args.package,
|
|
38
|
-
tag: args.tag,
|
|
39
|
-
access: args.access,
|
|
40
|
-
dryRun: args["dry-run"],
|
|
41
|
-
debug: args.debug ? console.debug : undefined,
|
|
42
|
-
quiet: args.quiet,
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
return parsedArgs;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
// There was an error parsing the command-line args
|
|
49
|
-
return errorHandler(error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.parseArgs = parseArgs;
|
|
53
|
-
function errorHandler(error) {
|
|
54
|
-
console.error(error.message);
|
|
55
|
-
console.error(help_1.usageText);
|
|
56
|
-
return process.exit(exit_code_1.ExitCode.InvalidArgument);
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=parse-args.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-args.js","sourceRoot":"","sources":["../../src/cli/parse-args.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AAErD,2CAAuC;AACvC,iCAAmC;AAYnC;;;GAGG;AACH,SAAgB,SAAS,CAAC,IAAc;IACtC,IAAI;QACF,IAAI,IAAI,GAAG,eAAe,CACxB;YACE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;YAC/B,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE;YAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE;YACtD,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE;YAC7B,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE;YAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;YAClC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE;YAC5C,EAAE,IAAI,EAAE,OAAO,EAAE,KAA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