enhanced-publish 1.1.7 → 1.1.9
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/index.js +43 -33
- package/package.json +12 -4
package/index.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
// @ts-check
|
|
4
4
|
|
|
5
|
-
const { spawn } = require("child_process")
|
|
6
|
-
const { readFileSync } = require("fs")
|
|
7
|
-
const pacote = require("pacote")
|
|
5
|
+
const { spawn } = require("child_process");
|
|
6
|
+
const { readFileSync } = require("fs");
|
|
7
|
+
const pacote = require("pacote");
|
|
8
8
|
|
|
9
9
|
function getPackageInfo() {
|
|
10
|
-
const pJson = JSON.parse(readFileSync("./package.json", "utf8"))
|
|
10
|
+
const pJson = JSON.parse(readFileSync("./package.json", "utf8"));
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
name: pJson.name,
|
|
14
14
|
version: pJson.version,
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -21,58 +21,68 @@ function getPackageInfo() {
|
|
|
21
21
|
async function existsPackageInRegistry(pkg) {
|
|
22
22
|
return await pacote.packument(pkg.name).then(
|
|
23
23
|
(packument) => {
|
|
24
|
-
if (packument.versions === undefined) return false
|
|
25
|
-
return packument.versions[pkg.version] !== undefined
|
|
24
|
+
if (packument.versions === undefined) return false;
|
|
25
|
+
return packument.versions[pkg.version] !== undefined;
|
|
26
26
|
},
|
|
27
27
|
() => {
|
|
28
|
-
console.warn(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
console.warn(
|
|
29
|
+
`Unable to determine published version, assuming ${pkg.name} unpublished.`,
|
|
30
|
+
);
|
|
31
|
+
return false;
|
|
32
|
+
},
|
|
33
|
+
);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
const newFlags = ["--if-possible", "--use-preid-as-tag"]
|
|
36
|
+
const newFlags = ["--if-possible", "--use-preid-as-tag"];
|
|
35
37
|
|
|
36
38
|
async function run() {
|
|
37
39
|
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
38
40
|
console.log(`This command will publish your package to the npm registry. It adds the following flags to the original publish command:
|
|
39
41
|
--if-possible - If the package is already published, it will not publish it again.
|
|
40
|
-
--use-preid-as-tag - Will use the 'preid' as the tag. e.g. '1.0.0-alpha.1' -> '--tag alpha'`)
|
|
41
|
-
process.exit(0)
|
|
42
|
+
--use-preid-as-tag - Will use the 'preid' as the tag. e.g. '1.0.0-alpha.1' -> '--tag alpha'`);
|
|
43
|
+
process.exit(0);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
const pkg = getPackageInfo()
|
|
46
|
+
const pkg = getPackageInfo();
|
|
45
47
|
|
|
46
|
-
const semverWithPreidRegex = /^\d+\.\d+\.\d+(?:-([a-z0-9]+)(?:\.\d+)+)
|
|
47
|
-
const semverMatches = semverWithPreidRegex.exec(pkg.version)
|
|
48
|
+
const semverWithPreidRegex = /^\d+\.\d+\.\d+(?:-([a-z0-9]+)(?:\.\d+)+)?$/;
|
|
49
|
+
const semverMatches = semverWithPreidRegex.exec(pkg.version);
|
|
48
50
|
|
|
49
51
|
if (process.argv.includes("--only-prerelease")) {
|
|
50
|
-
console.log("Only prerelease packages will be published.")
|
|
52
|
+
console.log("Only prerelease packages will be published.");
|
|
51
53
|
|
|
52
54
|
if (!semverMatches || !semverMatches[1]) {
|
|
53
|
-
console.error(
|
|
54
|
-
|
|
55
|
+
console.error(
|
|
56
|
+
`The version '${pkg.version}' of package '${pkg.name}' is not a prerelease version, aborting.`,
|
|
57
|
+
);
|
|
58
|
+
process.exit(0);
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
const isPublished = await existsPackageInRegistry(pkg)
|
|
62
|
+
const isPublished = await existsPackageInRegistry(pkg);
|
|
59
63
|
|
|
60
64
|
if (process.argv.includes("--if-possible") && isPublished) {
|
|
61
|
-
console.log(
|
|
62
|
-
|
|
65
|
+
console.log(
|
|
66
|
+
`${pkg.name} with version ${pkg.version} is already published.`,
|
|
67
|
+
);
|
|
68
|
+
process.exit(0);
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
let args = [...process.argv]
|
|
66
|
-
args.splice(0, 2)
|
|
67
|
-
args = args.filter((arg) => !newFlags.includes(arg))
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
let args = [...process.argv];
|
|
72
|
+
args.splice(0, 2);
|
|
73
|
+
args = args.filter((arg) => !newFlags.includes(arg));
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
process.argv.includes("--use-preid-as-tag") &&
|
|
77
|
+
semverMatches &&
|
|
78
|
+
semverMatches[1]
|
|
79
|
+
) {
|
|
80
|
+
const preid = semverMatches[1];
|
|
81
|
+
args.push("--tag", preid);
|
|
72
82
|
}
|
|
73
83
|
|
|
74
|
-
const child = spawn("npm", ["publish", ...args], { stdio: "inherit" })
|
|
75
|
-
child.on("exit", (code) => process.exit(code ?? 0))
|
|
84
|
+
const child = spawn("npm", ["publish", ...args], { stdio: "inherit" });
|
|
85
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
76
86
|
}
|
|
77
87
|
|
|
78
|
-
run()
|
|
88
|
+
run();
|
package/package.json
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "enhanced-publish",
|
|
3
|
-
"version": "1.1.7",
|
|
4
3
|
"description": "Npm publish command with lerna's from-package publish behaviour.",
|
|
5
4
|
"repository": "github:js-soft/enhanced-npm-publish",
|
|
6
5
|
"license": "MIT",
|
|
7
|
-
"author": "js-soft
|
|
6
|
+
"author": "js-soft AG",
|
|
8
7
|
"bin": "index.js",
|
|
9
8
|
"files": [
|
|
10
9
|
"index.js"
|
|
11
10
|
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"lint": "npm run lint:prettier && npm run lint:eslint && npm run lint:tsc",
|
|
13
|
+
"lint:prettier": "prettier --check ."
|
|
14
|
+
},
|
|
12
15
|
"dependencies": {
|
|
13
|
-
"pacote": "^
|
|
16
|
+
"pacote": "^22.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@js-soft/license-check": "^1.0.10",
|
|
20
|
+
"prettier": "^3.8.4"
|
|
14
21
|
},
|
|
15
22
|
"publishConfig": {
|
|
16
23
|
"access": "public"
|
|
17
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"version": "1.1.9"
|
|
18
26
|
}
|