@jsdevtools/npm-publish 1.4.2 → 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
package/lib/options.d.ts
CHANGED
|
@@ -1,73 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** The possible access levels for an NPM package */
|
|
2
|
+
export type Access = typeof ACCESS_PUBLIC | typeof ACCESS_RESTRICTED;
|
|
3
|
+
export declare const ACCESS_PUBLIC = "public";
|
|
4
|
+
export declare const ACCESS_RESTRICTED = "restricted";
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
6
|
+
* Version check strategy.
|
|
7
|
+
*
|
|
8
|
+
* - `upgrade`: the package will only be published if its version is higher than
|
|
9
|
+
* the existing version on the configured tag.
|
|
10
|
+
* - `all`: the package will be published if its version is not yet published,
|
|
11
|
+
* even if its lower that the existing tag.
|
|
5
12
|
*/
|
|
13
|
+
export type Strategy = typeof STRATEGY_UPGRADE | typeof STRATEGY_ALL;
|
|
14
|
+
export declare const STRATEGY_UPGRADE = "upgrade";
|
|
15
|
+
export declare const STRATEGY_ALL = "all";
|
|
16
|
+
/** An interface that can be used to log messages. */
|
|
17
|
+
export interface Logger {
|
|
18
|
+
error: (message: string | Error) => void;
|
|
19
|
+
info?: undefined | ((message: string) => void);
|
|
20
|
+
debug?: undefined | ((message: string) => void);
|
|
21
|
+
}
|
|
22
|
+
/** Options that determine how/whether the package is published. */
|
|
6
23
|
export interface Options {
|
|
24
|
+
/** The NPM access token to use when publishing. */
|
|
25
|
+
token: string;
|
|
7
26
|
/**
|
|
8
|
-
* The
|
|
27
|
+
* The absolute or relative path of your package.
|
|
28
|
+
*
|
|
29
|
+
* Defaults to the package in the current working directory.
|
|
9
30
|
*/
|
|
10
|
-
|
|
31
|
+
package?: string | undefined;
|
|
11
32
|
/**
|
|
12
33
|
* The NPM registry URL to use.
|
|
13
34
|
*
|
|
14
|
-
* Defaults to "https://registry.npmjs.org/"
|
|
15
|
-
*/
|
|
16
|
-
registry?: string | URL;
|
|
17
|
-
/**
|
|
18
|
-
* The absolute or relative path of your package.json file.
|
|
35
|
+
* Defaults to "https://registry.npmjs.org/".
|
|
19
36
|
*
|
|
20
|
-
*
|
|
37
|
+
* Can be overridden by the package.json's `publishConfig` field.
|
|
21
38
|
*/
|
|
22
|
-
|
|
39
|
+
registry?: string | URL | undefined;
|
|
23
40
|
/**
|
|
24
|
-
* The tag to publish to.
|
|
25
|
-
* using "npm install <package-name>@<tag>".
|
|
41
|
+
* The tag to publish to.
|
|
26
42
|
*
|
|
27
|
-
* Defaults to "latest"
|
|
28
|
-
*/
|
|
29
|
-
tag?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Determines whether the published package should be publicly visible,
|
|
32
|
-
* or restricted to members of your NPM organization. This only applies
|
|
33
|
-
* to scoped packages.
|
|
43
|
+
* Defaults to "latest".
|
|
34
44
|
*
|
|
35
|
-
*
|
|
45
|
+
* Can be overridden by the package.json's `publishConfig` field.
|
|
36
46
|
*/
|
|
37
|
-
|
|
47
|
+
tag?: string | undefined;
|
|
38
48
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
49
|
+
* Package access.
|
|
50
|
+
*
|
|
51
|
+
* Determines whether the published package should be publicly visible, or
|
|
52
|
+
* restricted to members of your NPM organization. This only applies to scoped
|
|
53
|
+
* packages.
|
|
42
54
|
*
|
|
43
|
-
* Defaults to
|
|
55
|
+
* Defaults to "restricted" for scoped packages, unless that package has been
|
|
56
|
+
* previously published as `public`
|
|
57
|
+
*
|
|
58
|
+
* Can be overridden by the package.json's `publishConfig` field.
|
|
44
59
|
*/
|
|
45
|
-
|
|
60
|
+
access?: Access | undefined;
|
|
46
61
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
62
|
+
* Version check strategy.
|
|
63
|
+
*
|
|
64
|
+
* If "upgrade" (default), the package will only be published if its version
|
|
65
|
+
* is higher than the existing version on the configured tag. If "always", the
|
|
66
|
+
* package will be published if its version is simply not yet published.
|
|
49
67
|
*
|
|
50
|
-
* Defaults to `
|
|
68
|
+
* Defaults to `upgrade`.
|
|
51
69
|
*/
|
|
52
|
-
|
|
70
|
+
strategy?: Strategy | undefined;
|
|
53
71
|
/**
|
|
54
|
-
*
|
|
72
|
+
* Pretend to publish, but don't actually upload to the registry.
|
|
55
73
|
*
|
|
56
|
-
* Defaults to `false
|
|
74
|
+
* Defaults to `false`.
|
|
57
75
|
*/
|
|
58
|
-
|
|
76
|
+
dryRun?: boolean | undefined;
|
|
77
|
+
/** Optional logger. */
|
|
78
|
+
logger?: Logger | undefined;
|
|
59
79
|
/**
|
|
60
|
-
*
|
|
80
|
+
* Temporary directory.
|
|
61
81
|
*
|
|
62
|
-
* Defaults to
|
|
82
|
+
* Defaults to os.tmpdir()
|
|
63
83
|
*/
|
|
64
|
-
|
|
84
|
+
temporaryDirectory?: string | undefined;
|
|
65
85
|
}
|
|
66
|
-
/**
|
|
67
|
-
* The possible access levels for an NPM package
|
|
68
|
-
*/
|
|
69
|
-
export declare type Access = "public" | "restricted";
|
|
70
|
-
/**
|
|
71
|
-
* A function that receives debug messages
|
|
72
|
-
*/
|
|
73
|
-
export declare type Debug = (message: string, data?: object) => void;
|
package/lib/options.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STRATEGY_ALL = exports.STRATEGY_UPGRADE = exports.ACCESS_RESTRICTED = exports.ACCESS_PUBLIC = void 0;
|
|
4
|
+
exports.ACCESS_PUBLIC = "public";
|
|
5
|
+
exports.ACCESS_RESTRICTED = "restricted";
|
|
6
|
+
exports.STRATEGY_UPGRADE = "upgrade";
|
|
7
|
+
exports.STRATEGY_ALL = "all";
|
|
3
8
|
//# sourceMappingURL=options.js.map
|
package/lib/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AAEa,QAAA,aAAa,GAAG,QAAQ,CAAC;AACzB,QAAA,iBAAiB,GAAG,YAAY,CAAC;AAWjC,QAAA,gBAAgB,GAAG,SAAS,CAAC;AAC7B,QAAA,YAAY,GAAG,KAAK,CAAC"}
|
package/lib/read-manifest.d.ts
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/** The result of reading a package manifest */
|
|
2
|
+
export interface ManifestReadResult {
|
|
3
|
+
packageSpec: string;
|
|
4
|
+
manifest: PackageManifest;
|
|
5
|
+
}
|
|
6
|
+
/** A package manifest (package.json) */
|
|
7
|
+
export interface PackageManifest {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
scope: string | undefined;
|
|
11
|
+
publishConfig: PackagePublishConfig | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Any publish configuration defined in package.json. */
|
|
14
|
+
export interface PackagePublishConfig {
|
|
15
|
+
tag?: string;
|
|
16
|
+
access?: string;
|
|
17
|
+
registry?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads the package manifest (package.json) and returns its parsed contents.
|
|
21
|
+
*
|
|
22
|
+
* @param packagePath The path to the package being published.
|
|
23
|
+
* @returns The parsed package metadata.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readManifest(packagePath: unknown): Promise<ManifestReadResult>;
|
package/lib/read-manifest.js
CHANGED
|
@@ -1,38 +1,135 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.readManifest = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const path_1 = require("path");
|
|
30
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
31
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
32
|
const semver_1 = require("semver");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
const tar_1 = require("tar");
|
|
34
|
+
const errors = __importStar(require("./errors.js"));
|
|
35
|
+
const SCOPE_RE = /^(@.+)\/.+$/u;
|
|
36
|
+
const MANIFEST_BASENAME = "package.json";
|
|
37
|
+
const TARBALL_EXTNAME = ".tgz";
|
|
38
|
+
const isManifest = (file) => {
|
|
39
|
+
return typeof file === "string" && node_path_1.default.basename(file) === MANIFEST_BASENAME;
|
|
40
|
+
};
|
|
41
|
+
const isDirectory = (file) => {
|
|
42
|
+
return typeof file === "string" && node_path_1.default.extname(file) === "";
|
|
43
|
+
};
|
|
44
|
+
const isTarball = (file) => {
|
|
45
|
+
return typeof file === "string" && node_path_1.default.extname(file) === TARBALL_EXTNAME;
|
|
46
|
+
};
|
|
47
|
+
const isVersion = (version) => {
|
|
48
|
+
return (0, semver_1.valid)(version) !== null;
|
|
49
|
+
};
|
|
50
|
+
const readPackageJson = async (...pathSegments) => {
|
|
51
|
+
const file = node_path_1.default.resolve(...pathSegments);
|
|
15
52
|
try {
|
|
16
|
-
|
|
53
|
+
return await promises_1.default.readFile(file, "utf8");
|
|
17
54
|
}
|
|
18
55
|
catch (error) {
|
|
19
|
-
throw
|
|
56
|
+
throw new errors.PackageJsonReadError(file, error);
|
|
20
57
|
}
|
|
58
|
+
};
|
|
59
|
+
const readTarballPackageJson = async (file) => {
|
|
60
|
+
const data = [];
|
|
61
|
+
const onentry = (entry) => {
|
|
62
|
+
if (entry.path === "package/package.json") {
|
|
63
|
+
entry.on("data", (chunk) => data.push(chunk));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
21
66
|
try {
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
throw new
|
|
67
|
+
await (0, tar_1.list)({ file, onentry });
|
|
68
|
+
if (data.length === 0) {
|
|
69
|
+
throw new Error("package.json not found inside archive");
|
|
25
70
|
}
|
|
26
|
-
let manifest = {
|
|
27
|
-
name,
|
|
28
|
-
version: new semver_1.SemVer(version),
|
|
29
|
-
};
|
|
30
|
-
debug && debug("MANIFEST:", manifest);
|
|
31
|
-
return manifest;
|
|
32
71
|
}
|
|
33
72
|
catch (error) {
|
|
34
|
-
throw
|
|
73
|
+
throw new errors.PackageTarballReadError(file, error);
|
|
74
|
+
}
|
|
75
|
+
return Buffer.concat(data).toString();
|
|
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
|
+
async function readManifest(packagePath) {
|
|
84
|
+
let packageSpec;
|
|
85
|
+
let manifestContents;
|
|
86
|
+
if (!packagePath) {
|
|
87
|
+
packageSpec = "";
|
|
88
|
+
manifestContents = await readPackageJson(MANIFEST_BASENAME);
|
|
89
|
+
}
|
|
90
|
+
else if (isManifest(packagePath)) {
|
|
91
|
+
packageSpec = node_path_1.default.resolve(node_path_1.default.dirname(packagePath));
|
|
92
|
+
manifestContents = await readPackageJson(packagePath);
|
|
93
|
+
}
|
|
94
|
+
else if (isDirectory(packagePath)) {
|
|
95
|
+
packageSpec = node_path_1.default.resolve(packagePath);
|
|
96
|
+
manifestContents = await readPackageJson(packagePath, MANIFEST_BASENAME);
|
|
97
|
+
}
|
|
98
|
+
else if (isTarball(packagePath)) {
|
|
99
|
+
packageSpec = node_path_1.default.resolve(packagePath);
|
|
100
|
+
manifestContents = await readTarballPackageJson(packageSpec);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new errors.InvalidPackageError(packagePath);
|
|
104
|
+
}
|
|
105
|
+
let manifestJson;
|
|
106
|
+
let name;
|
|
107
|
+
let version;
|
|
108
|
+
let publishConfig;
|
|
109
|
+
try {
|
|
110
|
+
manifestJson = JSON.parse(manifestContents);
|
|
111
|
+
name = manifestJson["name"];
|
|
112
|
+
version = manifestJson["version"];
|
|
113
|
+
publishConfig = manifestJson["publishConfig"] ?? {};
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
throw new errors.PackageJsonParseError(packageSpec, error);
|
|
117
|
+
}
|
|
118
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
119
|
+
throw new errors.InvalidPackageNameError(name);
|
|
120
|
+
}
|
|
121
|
+
if (!isVersion(version)) {
|
|
122
|
+
throw new errors.InvalidPackageVersionError(version);
|
|
123
|
+
}
|
|
124
|
+
if (typeof publishConfig !== "object" ||
|
|
125
|
+
Array.isArray(publishConfig) ||
|
|
126
|
+
!publishConfig) {
|
|
127
|
+
throw new errors.InvalidPackagePublishConfigError(publishConfig);
|
|
35
128
|
}
|
|
129
|
+
return {
|
|
130
|
+
packageSpec,
|
|
131
|
+
manifest: { name, version, publishConfig, scope: SCOPE_RE.exec(name)?.[1] },
|
|
132
|
+
};
|
|
36
133
|
}
|
|
37
134
|
exports.readManifest = readManifest;
|
|
38
135
|
//# sourceMappingURL=read-manifest.js.map
|
package/lib/read-manifest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-manifest.js","sourceRoot":"","sources":["../src/read-manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-manifest.js","sourceRoot":"","sources":["../src/read-manifest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAkC;AAClC,0DAA6B;AAC7B,mCAA8C;AAC9C,6BAAsD;AAEtD,oDAAsC;AAuBtC,MAAM,QAAQ,GAAG,cAAc,CAAC;AAEhC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,MAAM,UAAU,GAAG,CAAC,IAAa,EAAkB,EAAE;IACnD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,mBAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,iBAAiB,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,IAAa,EAAkB,EAAE;IACpD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,mBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,IAAa,EAAkB,EAAE;IAClD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,mBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,eAAe,CAAC;AAC5E,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAqB,EAAE;IACxD,OAAO,IAAA,cAAW,EAAC,OAAiB,CAAC,KAAK,IAAI,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,KAAK,EAAE,GAAG,YAAsB,EAAmB,EAAE;IAC3E,MAAM,IAAI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S,CAAC,OAAO,CAAC,EAAE;QACvB,MAAM,IAAI,MAAM,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;KACtD;IAED,IACE,OAAO,aAAa,KAAK,QAAQ;QACjC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;QAC5B,CAAC,aAAa,EACd;QACA,MAAM,IAAI,MAAM,CAAC,gCAAgC,CAAC,aAAa,CAAC,CAAC;KAClE;IAED,OAAO;QACL,WAAW;QACX,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;KAC5E,CAAC;AACJ,CAAC;AAxDD,oCAwDC"}
|
package/lib/results.d.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Results of the publish
|
|
6
|
-
*/
|
|
1
|
+
import type { Access, Strategy } from "./options.js";
|
|
2
|
+
import type { ReleaseType } from "./compare-versions.js";
|
|
3
|
+
/** Results of the publish */
|
|
7
4
|
export interface Results {
|
|
8
5
|
/**
|
|
9
|
-
* The
|
|
10
|
-
|
|
11
|
-
type: ReleaseType | "none";
|
|
12
|
-
/**
|
|
13
|
-
* The name of the NPM package that was published
|
|
14
|
-
*/
|
|
15
|
-
package: string;
|
|
16
|
-
/**
|
|
17
|
-
* The version that was published
|
|
6
|
+
* The identifier of the published package, if published. Format is
|
|
7
|
+
* `${packageName}@${version}`
|
|
18
8
|
*/
|
|
9
|
+
id: string | undefined;
|
|
10
|
+
/** The name of the NPM package that was published */
|
|
11
|
+
name: string;
|
|
12
|
+
/** The version that was published */
|
|
19
13
|
version: string;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
oldVersion: string;
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
/** The type of version change that occurred, if any. */
|
|
15
|
+
type: ReleaseType | undefined;
|
|
16
|
+
/** The version number that was previously published to NPM, if any. */
|
|
17
|
+
oldVersion: string | undefined;
|
|
18
|
+
/** The registry where the package was published */
|
|
19
|
+
registry: URL;
|
|
20
|
+
/** The tag that the package was published to. */
|
|
27
21
|
tag: string;
|
|
28
22
|
/**
|
|
29
|
-
* Indicates whether the published package is publicly visible
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
23
|
+
* Indicates whether the published package is publicly visible or restricted
|
|
24
|
+
* to members of your NPM organization.
|
|
25
|
+
*
|
|
26
|
+
* If package is scoped, undefined means npm's scoped package defaults. If a
|
|
27
|
+
* scoped package has previously been published as public, the default is
|
|
28
|
+
* public. Otherwise, it is restricted.
|
|
35
29
|
*/
|
|
30
|
+
access: Access | undefined;
|
|
31
|
+
/** Version check strategy used. */
|
|
32
|
+
strategy: Strategy;
|
|
33
|
+
/** Whether this was a dry run (not published to NPM) */
|
|
36
34
|
dryRun: boolean;
|
|
37
35
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsdevtools/npm-publish",
|
|
3
3
|
"description": "Fast, easy publishing to NPM",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github-action",
|
|
7
7
|
"npm",
|
|
@@ -26,49 +26,57 @@
|
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"bin",
|
|
29
|
-
"lib"
|
|
29
|
+
"lib",
|
|
30
|
+
"src",
|
|
31
|
+
"!__tests__"
|
|
30
32
|
],
|
|
31
33
|
"scripts": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"build
|
|
37
|
-
"build:
|
|
38
|
-
"
|
|
39
|
-
"test": "
|
|
40
|
-
"coverage": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"release": "npm run upgrade && npm run clean && npm run build && npm test && npm run bump"
|
|
34
|
+
"all": "npm run clean && npm run build && npm run lint && npm run coverage",
|
|
35
|
+
"clean": "rimraf coverage lib dist e2e/fixture *.tgz",
|
|
36
|
+
"lint": "npm run _eslint && npm run _prettier -- --check",
|
|
37
|
+
"format": "npm run _eslint -- --fix && npm run _prettier -- --write",
|
|
38
|
+
"build": "concurrently -g npm:build:*",
|
|
39
|
+
"build:dist": "esbuild src/action/main.ts --bundle --sourcemap --outdir=dist --platform=node --target=node16",
|
|
40
|
+
"build:lib": "tsc",
|
|
41
|
+
"test": "vitest",
|
|
42
|
+
"coverage": "vitest run --coverage",
|
|
43
|
+
"_eslint": "eslint \"**/*.@(js|ts)\"",
|
|
44
|
+
"_prettier": "prettier \"**/*.@(js|ts|json|md|yml)\""
|
|
44
45
|
},
|
|
45
46
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
47
|
+
"node": ">=16"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@actions/core": "^1.
|
|
50
|
-
"@jsdevtools/chai-exec": "^2.1.1",
|
|
51
|
-
"@jsdevtools/eslint-config": "^1.1.4",
|
|
52
|
-
"@jsdevtools/version-bump-prompt": "^6.1.0",
|
|
53
|
-
"@types/chai": "^4.2.14",
|
|
50
|
+
"@actions/core": "^1.10.0",
|
|
54
51
|
"@types/command-line-args": "^5.0.0",
|
|
55
|
-
"@types/
|
|
56
|
-
"@types/
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
52
|
+
"@types/node": "^18.15.11",
|
|
53
|
+
"@types/tar": "^6.1.4",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
55
|
+
"@typescript-eslint/parser": "^5.59.0",
|
|
56
|
+
"@vitest/coverage-istanbul": "^0.30.1",
|
|
57
|
+
"concurrently": "^8.0.1",
|
|
58
|
+
"esbuild": "0.17.17",
|
|
59
|
+
"eslint": "^8.38.0",
|
|
60
|
+
"eslint-config-prettier": "^8.8.0",
|
|
61
|
+
"eslint-import-resolver-typescript": "^3.5.5",
|
|
62
|
+
"eslint-plugin-import": "npm:eslint-plugin-i@^2.27.5-1",
|
|
63
|
+
"eslint-plugin-jsdoc": "^43.0.6",
|
|
64
|
+
"eslint-plugin-n": "^15.7.0",
|
|
65
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
66
|
+
"eslint-plugin-sonarjs": "^0.19.0",
|
|
67
|
+
"eslint-plugin-unicorn": "^46.0.0",
|
|
68
|
+
"prettier": "^2.8.7",
|
|
69
|
+
"prettier-plugin-jsdoc": "^0.4.2",
|
|
70
|
+
"rimraf": "^5.0.0",
|
|
71
|
+
"testdouble": "^3.17.2",
|
|
72
|
+
"testdouble-vitest": "^0.1.2",
|
|
73
|
+
"typescript": "^5.0.4",
|
|
74
|
+
"vitest": "^0.30.1"
|
|
67
75
|
},
|
|
68
76
|
"dependencies": {
|
|
69
|
-
"@
|
|
70
|
-
"@jsdevtools/ono": "^7.1.3",
|
|
77
|
+
"@types/semver": "^7.3.13",
|
|
71
78
|
"command-line-args": "^5.1.1",
|
|
72
|
-
"semver": "^7.
|
|
79
|
+
"semver": "^7.5.0",
|
|
80
|
+
"tar": "^6.1.13"
|
|
73
81
|
}
|
|
74
82
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Wrapper module for @actions/core */
|
|
2
|
+
import {
|
|
3
|
+
getInput as ghGetInput,
|
|
4
|
+
setOutput as ghSetOutput,
|
|
5
|
+
setSecret as ghSetSecret,
|
|
6
|
+
setFailed as ghSetFailed,
|
|
7
|
+
debug as ghLogDebug,
|
|
8
|
+
info as ghLogInfo,
|
|
9
|
+
error as ghLogError,
|
|
10
|
+
} from "@actions/core";
|
|
11
|
+
|
|
12
|
+
import type { Logger } from "../options.js";
|
|
13
|
+
|
|
14
|
+
/** Logger using the methods from @actions/core. */
|
|
15
|
+
export const logger: Logger = {
|
|
16
|
+
debug: ghLogDebug,
|
|
17
|
+
info: ghLogInfo,
|
|
18
|
+
error: ghLogError,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get input by name.
|
|
23
|
+
*
|
|
24
|
+
* @param name Input name
|
|
25
|
+
* @returns The input string value, or undefined if not set
|
|
26
|
+
*/
|
|
27
|
+
export function getInput<T extends string>(name: string): T | undefined {
|
|
28
|
+
const inputString = ghGetInput(name);
|
|
29
|
+
return inputString.length > 0 ? (inputString as T) : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get a required secret input by name.
|
|
34
|
+
*
|
|
35
|
+
* @param name Input name
|
|
36
|
+
* @returns The input secret value.
|
|
37
|
+
*/
|
|
38
|
+
export function getRequiredSecretInput(name: string): string {
|
|
39
|
+
const inputString = ghGetInput(name, { required: true });
|
|
40
|
+
ghSetSecret(inputString);
|
|
41
|
+
return inputString;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get a boolean input by name.
|
|
46
|
+
*
|
|
47
|
+
* @param name Input name
|
|
48
|
+
* @returns True if value is "true", false if not
|
|
49
|
+
*/
|
|
50
|
+
export function getBooleanInput(name: string): boolean {
|
|
51
|
+
return ghGetInput(name) === "true";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Set the action as failed due to an error.
|
|
56
|
+
*
|
|
57
|
+
* @param error An value from a `catch`
|
|
58
|
+
*/
|
|
59
|
+
export function setFailed(error: unknown) {
|
|
60
|
+
ghSetFailed(error as Error);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Set an output by name.
|
|
65
|
+
*
|
|
66
|
+
* @param name Output name
|
|
67
|
+
* @param value Output value
|
|
68
|
+
*/
|
|
69
|
+
export function setOutput(name: string, value: string | boolean): void;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Set an output by name.
|
|
73
|
+
*
|
|
74
|
+
* @param name Output name
|
|
75
|
+
* @param value Output value
|
|
76
|
+
* @param defaultValue Default value if value is undefined.
|
|
77
|
+
*/
|
|
78
|
+
export function setOutput(
|
|
79
|
+
name: string,
|
|
80
|
+
value: string | boolean | undefined,
|
|
81
|
+
defaultValue: string | boolean
|
|
82
|
+
): void;
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
85
|
+
export function setOutput(
|
|
86
|
+
name: string,
|
|
87
|
+
value: string | boolean | undefined,
|
|
88
|
+
defaultValue?: string | boolean | undefined
|
|
89
|
+
): void {
|
|
90
|
+
ghSetOutput(name, value ?? defaultValue);
|
|
91
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Action entry point */
|
|
2
|
+
import { npmPublish } from "../index.js";
|
|
3
|
+
import * as core from "./core.js";
|
|
4
|
+
|
|
5
|
+
/** Run the action. */
|
|
6
|
+
async function run(): Promise<void> {
|
|
7
|
+
const results = await npmPublish({
|
|
8
|
+
token: core.getRequiredSecretInput("token"),
|
|
9
|
+
registry: core.getInput("registry"),
|
|
10
|
+
package: core.getInput("package"),
|
|
11
|
+
tag: core.getInput("tag"),
|
|
12
|
+
access: core.getInput("access"),
|
|
13
|
+
strategy: core.getInput("strategy"),
|
|
14
|
+
dryRun: core.getBooleanInput("dry-run"),
|
|
15
|
+
logger: core.logger,
|
|
16
|
+
temporaryDirectory: process.env["RUNNER_TEMP"],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
core.setOutput("id", results.id, "");
|
|
20
|
+
core.setOutput("name", results.name);
|
|
21
|
+
core.setOutput("version", results.version);
|
|
22
|
+
core.setOutput("type", results.type, "");
|
|
23
|
+
core.setOutput("old-version", results.oldVersion, "");
|
|
24
|
+
core.setOutput("registry", results.registry.href);
|
|
25
|
+
core.setOutput("tag", results.tag);
|
|
26
|
+
core.setOutput("access", results.access, "default");
|
|
27
|
+
core.setOutput("strategy", results.strategy);
|
|
28
|
+
core.setOutput("dry-run", results.dryRun);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
run().catch((error: Error) => core.setFailed(error));
|