@ucdjs/release-scripts 0.1.0-beta.46 → 0.1.0-beta.47
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/dist/index.mjs +92 -31
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import farver from "farver";
|
|
|
8
8
|
import mri from "mri";
|
|
9
9
|
import { exec } from "tinyexec";
|
|
10
10
|
import { dedent } from "@luxass/utils";
|
|
11
|
+
import semver, { compare, gt } from "semver";
|
|
11
12
|
import prompts from "prompts";
|
|
12
|
-
import { compare, gt } from "semver";
|
|
13
13
|
|
|
14
14
|
//#region src/operations/changelog-format.ts
|
|
15
15
|
function formatCommitLine({ commit, owner, repo, authors }) {
|
|
@@ -1003,42 +1003,38 @@ function parseChangelog(content) {
|
|
|
1003
1003
|
//#endregion
|
|
1004
1004
|
//#region src/operations/semver.ts
|
|
1005
1005
|
function isValidSemver(version) {
|
|
1006
|
-
return
|
|
1006
|
+
return semver.valid(version) != null;
|
|
1007
1007
|
}
|
|
1008
1008
|
function getNextVersion(currentVersion, bump) {
|
|
1009
1009
|
if (bump === "none") return currentVersion;
|
|
1010
1010
|
if (!isValidSemver(currentVersion)) throw new Error(`Cannot bump version for invalid semver: ${currentVersion}`);
|
|
1011
|
-
const
|
|
1012
|
-
if (!
|
|
1013
|
-
|
|
1014
|
-
let newMajor = Number.parseInt(major, 10);
|
|
1015
|
-
let newMinor = Number.parseInt(minor, 10);
|
|
1016
|
-
let newPatch = Number.parseInt(patch, 10);
|
|
1017
|
-
switch (bump) {
|
|
1018
|
-
case "major":
|
|
1019
|
-
newMajor += 1;
|
|
1020
|
-
newMinor = 0;
|
|
1021
|
-
newPatch = 0;
|
|
1022
|
-
break;
|
|
1023
|
-
case "minor":
|
|
1024
|
-
newMinor += 1;
|
|
1025
|
-
newPatch = 0;
|
|
1026
|
-
break;
|
|
1027
|
-
case "patch":
|
|
1028
|
-
newPatch += 1;
|
|
1029
|
-
break;
|
|
1030
|
-
}
|
|
1031
|
-
return `${newMajor}.${newMinor}.${newPatch}`;
|
|
1011
|
+
const next = semver.inc(currentVersion, bump);
|
|
1012
|
+
if (!next) throw new Error(`Failed to bump version ${currentVersion} with bump ${bump}`);
|
|
1013
|
+
return next;
|
|
1032
1014
|
}
|
|
1033
1015
|
function calculateBumpType(oldVersion, newVersion) {
|
|
1034
1016
|
if (!isValidSemver(oldVersion) || !isValidSemver(newVersion)) throw new Error(`Cannot calculate bump type for invalid semver: ${oldVersion} or ${newVersion}`);
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
if (
|
|
1038
|
-
if (
|
|
1039
|
-
if (
|
|
1017
|
+
const diff = semver.diff(oldVersion, newVersion);
|
|
1018
|
+
if (!diff) return "none";
|
|
1019
|
+
if (diff === "major" || diff === "premajor") return "major";
|
|
1020
|
+
if (diff === "minor" || diff === "preminor") return "minor";
|
|
1021
|
+
if (diff === "patch" || diff === "prepatch" || diff === "prerelease") return "patch";
|
|
1022
|
+
if (semver.gt(newVersion, oldVersion)) return "patch";
|
|
1040
1023
|
return "none";
|
|
1041
1024
|
}
|
|
1025
|
+
function getPrereleaseIdentifier(version) {
|
|
1026
|
+
const parsed = semver.parse(version);
|
|
1027
|
+
if (!parsed || parsed.prerelease.length === 0) return;
|
|
1028
|
+
const identifier = parsed.prerelease[0];
|
|
1029
|
+
return typeof identifier === "string" ? identifier : void 0;
|
|
1030
|
+
}
|
|
1031
|
+
function getNextPrereleaseVersion(currentVersion, mode, identifier) {
|
|
1032
|
+
if (!isValidSemver(currentVersion)) throw new Error(`Cannot bump prerelease for invalid semver: ${currentVersion}`);
|
|
1033
|
+
const releaseType = mode === "next" ? "prerelease" : mode;
|
|
1034
|
+
const next = identifier ? semver.inc(currentVersion, releaseType, identifier) : semver.inc(currentVersion, releaseType);
|
|
1035
|
+
if (!next) throw new Error(`Failed to compute prerelease version for ${currentVersion}`);
|
|
1036
|
+
return next;
|
|
1037
|
+
}
|
|
1042
1038
|
|
|
1043
1039
|
//#endregion
|
|
1044
1040
|
//#region src/core/prompts.ts
|
|
@@ -1062,6 +1058,16 @@ async function selectPackagePrompt(packages) {
|
|
|
1062
1058
|
async function selectVersionPrompt(workspaceRoot, pkg, currentVersion, suggestedVersion, options) {
|
|
1063
1059
|
const defaultChoice = options?.defaultChoice ?? "auto";
|
|
1064
1060
|
const suggestedSuffix = options?.suggestedHint ? farver.dim(` (${options.suggestedHint})`) : "";
|
|
1061
|
+
const prereleaseIdentifier = getPrereleaseIdentifier(currentVersion);
|
|
1062
|
+
const nextDefaultPrerelease = getNextPrereleaseVersion(currentVersion, "next", prereleaseIdentifier === "alpha" || prereleaseIdentifier === "beta" ? prereleaseIdentifier : "beta");
|
|
1063
|
+
const nextBeta = getNextPrereleaseVersion(currentVersion, "next", "beta");
|
|
1064
|
+
const nextAlpha = getNextPrereleaseVersion(currentVersion, "next", "alpha");
|
|
1065
|
+
const prePatchBeta = getNextPrereleaseVersion(currentVersion, "prepatch", "beta");
|
|
1066
|
+
const preMinorBeta = getNextPrereleaseVersion(currentVersion, "preminor", "beta");
|
|
1067
|
+
const preMajorBeta = getNextPrereleaseVersion(currentVersion, "premajor", "beta");
|
|
1068
|
+
const prePatchAlpha = getNextPrereleaseVersion(currentVersion, "prepatch", "alpha");
|
|
1069
|
+
const preMinorAlpha = getNextPrereleaseVersion(currentVersion, "preminor", "alpha");
|
|
1070
|
+
const preMajorAlpha = getNextPrereleaseVersion(currentVersion, "premajor", "alpha");
|
|
1065
1071
|
const initial = defaultChoice === "skip" ? 0 : defaultChoice === "suggested" ? 4 : defaultChoice === "as-is" ? 5 : suggestedVersion === currentVersion ? 0 : 4;
|
|
1066
1072
|
const answers = await prompts([{
|
|
1067
1073
|
type: "autocomplete",
|
|
@@ -1084,6 +1090,42 @@ async function selectVersionPrompt(workspaceRoot, pkg, currentVersion, suggested
|
|
|
1084
1090
|
value: "patch",
|
|
1085
1091
|
title: `patch ${farver.bold(getNextVersion(pkg.version, "patch"))}`
|
|
1086
1092
|
},
|
|
1093
|
+
{
|
|
1094
|
+
value: "next",
|
|
1095
|
+
title: `next ${farver.bold(nextDefaultPrerelease)}`
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
value: "prepatch-beta",
|
|
1099
|
+
title: `pre-patch (beta) ${farver.bold(prePatchBeta)}`
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
value: "preminor-beta",
|
|
1103
|
+
title: `pre-minor (beta) ${farver.bold(preMinorBeta)}`
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
value: "premajor-beta",
|
|
1107
|
+
title: `pre-major (beta) ${farver.bold(preMajorBeta)}`
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
value: "prepatch-alpha",
|
|
1111
|
+
title: `pre-patch (alpha) ${farver.bold(prePatchAlpha)}`
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
value: "preminor-alpha",
|
|
1115
|
+
title: `pre-minor (alpha) ${farver.bold(preMinorAlpha)}`
|
|
1116
|
+
},
|
|
1117
|
+
{
|
|
1118
|
+
value: "premajor-alpha",
|
|
1119
|
+
title: `pre-major (alpha) ${farver.bold(preMajorAlpha)}`
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
value: "next-beta",
|
|
1123
|
+
title: `next beta ${farver.bold(nextBeta)}`
|
|
1124
|
+
},
|
|
1125
|
+
{
|
|
1126
|
+
value: "next-alpha",
|
|
1127
|
+
title: `next alpha ${farver.bold(nextAlpha)}`
|
|
1128
|
+
},
|
|
1087
1129
|
{
|
|
1088
1130
|
value: "suggested",
|
|
1089
1131
|
title: `suggested ${farver.bold(suggestedVersion)}${suggestedSuffix}`
|
|
@@ -1115,6 +1157,15 @@ async function selectVersionPrompt(workspaceRoot, pkg, currentVersion, suggested
|
|
|
1115
1157
|
if (!answers.custom) return null;
|
|
1116
1158
|
return answers.custom;
|
|
1117
1159
|
} else if (answers.version === "as-is") return currentVersion;
|
|
1160
|
+
else if (answers.version === "next") return nextDefaultPrerelease;
|
|
1161
|
+
else if (answers.version === "next-beta") return nextBeta;
|
|
1162
|
+
else if (answers.version === "next-alpha") return nextAlpha;
|
|
1163
|
+
else if (answers.version === "prepatch-beta") return prePatchBeta;
|
|
1164
|
+
else if (answers.version === "preminor-beta") return preMinorBeta;
|
|
1165
|
+
else if (answers.version === "premajor-beta") return preMajorBeta;
|
|
1166
|
+
else if (answers.version === "prepatch-alpha") return prePatchAlpha;
|
|
1167
|
+
else if (answers.version === "preminor-alpha") return preMinorAlpha;
|
|
1168
|
+
else if (answers.version === "premajor-alpha") return preMajorAlpha;
|
|
1118
1169
|
else return getNextVersion(pkg.version, answers.version);
|
|
1119
1170
|
}
|
|
1120
1171
|
|
|
@@ -2114,11 +2165,12 @@ async function buildPackage(packageName, workspaceRoot, options) {
|
|
|
2114
2165
|
* Publish a package to NPM
|
|
2115
2166
|
* Uses pnpm to handle workspace protocol and catalog: resolution automatically
|
|
2116
2167
|
* @param packageName - The package name to publish
|
|
2168
|
+
* @param version - The package version to publish
|
|
2117
2169
|
* @param workspaceRoot - Path to the workspace root
|
|
2118
2170
|
* @param options - Normalized release scripts options
|
|
2119
2171
|
* @returns Result indicating success or failure
|
|
2120
2172
|
*/
|
|
2121
|
-
async function publishPackage(packageName, workspaceRoot, options) {
|
|
2173
|
+
async function publishPackage(packageName, version, workspaceRoot, options) {
|
|
2122
2174
|
const args = [
|
|
2123
2175
|
"--filter",
|
|
2124
2176
|
packageName,
|
|
@@ -2128,7 +2180,16 @@ async function publishPackage(packageName, workspaceRoot, options) {
|
|
|
2128
2180
|
"--no-git-checks"
|
|
2129
2181
|
];
|
|
2130
2182
|
if (options.npm.otp) args.push("--otp", options.npm.otp);
|
|
2131
|
-
|
|
2183
|
+
const explicitTag = process.env.NPM_CONFIG_TAG;
|
|
2184
|
+
const prereleaseTag = (() => {
|
|
2185
|
+
const prerelease = semver.prerelease(version);
|
|
2186
|
+
if (!prerelease || prerelease.length === 0) return;
|
|
2187
|
+
const identifier = prerelease[0];
|
|
2188
|
+
if (identifier === "alpha" || identifier === "beta") return identifier;
|
|
2189
|
+
return "next";
|
|
2190
|
+
})();
|
|
2191
|
+
const publishTag = explicitTag || prereleaseTag;
|
|
2192
|
+
if (publishTag) args.push("--tag", publishTag);
|
|
2132
2193
|
const env = { ...process.env };
|
|
2133
2194
|
if (options.npm.provenance) env.NPM_CONFIG_PROVENANCE = "true";
|
|
2134
2195
|
try {
|
|
@@ -2192,7 +2253,7 @@ async function publishWorkflow(options) {
|
|
|
2192
2253
|
}
|
|
2193
2254
|
}
|
|
2194
2255
|
logger.step(`Publishing ${farver.cyan(`${packageName}@${version}`)} to NPM...`);
|
|
2195
|
-
const publishResult = await publishPackage(packageName, options.workspaceRoot, options);
|
|
2256
|
+
const publishResult = await publishPackage(packageName, version, options.workspaceRoot, options);
|
|
2196
2257
|
if (!publishResult.ok) {
|
|
2197
2258
|
logger.error(`Failed to publish: ${publishResult.error.message}`);
|
|
2198
2259
|
status.failed.push(packageName);
|