@reelout/core 0.13.0 → 0.14.1
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/HookDispatcher-B_TrMRLU.js +236 -0
- package/dist/HookDispatcher-B_TrMRLU.js.map +1 -0
- package/dist/analyzer.js +12 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/buildChangelog-CkytKypk.js +187 -0
- package/dist/buildChangelog-CkytKypk.js.map +1 -0
- package/dist/buildReleaseNotes-Dk4bEclG.js +141 -0
- package/dist/buildReleaseNotes-Dk4bEclG.js.map +1 -0
- package/dist/builder.js +14 -6
- package/dist/builder.js.map +1 -1
- package/dist/changelog.js +17 -6
- package/dist/changelog.js.map +1 -1
- package/dist/index.js +1297 -20
- package/dist/index.js.map +1 -1
- package/dist/package-la-hLPRR.js +884 -0
- package/dist/package-la-hLPRR.js.map +1 -0
- package/dist/propagateDependencyUpdates-xcPvP5SP.js +306 -0
- package/dist/propagateDependencyUpdates-xcPvP5SP.js.map +1 -0
- package/dist/readPackageHistory-6dC72rZk.js +133 -0
- package/dist/readPackageHistory-6dC72rZk.js.map +1 -0
- package/dist/resolvePackageTag-2ldvH7PC.js +30 -0
- package/dist/resolvePackageTag-2ldvH7PC.js.map +1 -0
- package/dist/types.js +0 -1
- package/package.json +15 -3
- package/src/analyzer.ts +7 -2
- package/src/builder.ts +12 -3
- package/src/changelog.ts +17 -6
- package/src/config/resolvePlugin.ts +1 -1
- package/src/git/commit/getParsedGitCommit.ts +4 -1
- package/src/git/commit/parseGitCommit.ts +27 -2
- package/src/git/commit/parseGitPrettyFormat.ts +4 -1
- package/src/git/history/expandGitHistory.ts +17 -3
- package/src/git/history/readParsedGitHistory.ts +8 -2
- package/src/git/repository/isGitShallowRepository.ts +2 -1
- package/src/git/tag/ensureGitTag.ts +35 -3
- package/src/plugin/createHostReleasePlugin.ts +255 -0
- package/src/plugin/index.ts +1 -0
- package/src/types.ts +1 -0
- package/src/util/captureCommandOutput.ts +140 -0
- package/src/util/execCommand.ts +9 -0
- package/src/util/formatFile.ts +12 -3
- package/src/util/index.ts +1 -0
- package/src/util/interpolate.ts +5 -3
- package/src/util/isQuietEnvironment.ts +19 -13
- package/src/workflow/analysis/propagateDependencyUpdates.ts +1 -0
- package/src/workflow/changelog/buildChangelog.ts +27 -4
- package/src/workflow/changelog/buildReleaseNotes.ts +1 -1
- package/src/workflow/changelog/index.ts +0 -1
- package/src/workflow/changelog/prependChangelog.ts +5 -2
- package/src/workflow/changelog/writeChangelog.ts +5 -2
- package/src/workflow/commit/generateReleaseCommitMessage.ts +1 -1
- package/src/workflow/discovery/discoverPackageTag.ts +5 -2
- package/src/workflow/discovery/resolvePackageStableTag.ts +12 -7
- package/src/workflow/discovery/resolvePackageTag.ts +5 -2
- package/src/workflow/discovery/sortPackages.ts +5 -4
- package/src/workflow/discovery/verifyPackageTag.ts +6 -3
- package/src/workflow/report/printReleaseReport.ts +6 -1
- package/src/workflow/version/bumpVersion.ts +0 -1
- package/src/workflow/version/index.ts +0 -1
- package/dist/formatError-BMsun8Wi.js +0 -22
- package/dist/formatError-BMsun8Wi.js.map +0 -1
- package/dist/types-la_KkjCS.js +0 -1
- package/dist/workflow-Cqg6rLVB.js +0 -2936
- package/dist/workflow-Cqg6rLVB.js.map +0 -1
- package/src/workflow/changelog/extractPreviousVersion.ts +0 -77
- package/src/workflow/version/promotePrereleaseVersions.ts +0 -51
package/dist/index.js
CHANGED
|
@@ -1,8 +1,234 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { a as extractVersionQualifier, i as unique, n as readParsedGitHistory, r as readGitHistory, t as readPackageHistory } from "./readPackageHistory-6dC72rZk.js";
|
|
2
|
+
import { i as bumpVersion, n as resolvePackageStableTag, r as isSameReleaseCycle, t as buildReleaseNotes } from "./buildReleaseNotes-Dk4bEclG.js";
|
|
3
|
+
import { a as formatFile, i as extractPlainText, n as iterateChangelogVersions, o as compact, r as extractSemVer, s as isDefined, t as buildChangelog } from "./buildChangelog-CkytKypk.js";
|
|
4
|
+
import { A as DEV_NULL, C as isMatch, D as buildTrailerPattern, E as execCommand, M as RELEASE_HOOK_NAMES, N as SEMVER_REGEX, O as ALL_FILES, S as packageContainsCommit, T as execGit, _ as GIT_PRETTY_FORMAT, a as generateGitTagName, b as TTLCache, c as deleteGitTag, d as isGitAncestor, f as withShallowLock, g as GIT_PRETTY_FIELD_SEPARATOR, h as getParsedGitCommit, i as getGitTagMessage, j as GIT_TRAILER_RELEASE_AGENT, k as DEFAULT_CHANGELOG_FILE, l as expandGitHistory, m as countGitHistory, n as verifyPackageTag, o as ensureGitTag, p as isGitShallowRepository, r as isGitTagConnected, s as isGitTagPresent, t as version, u as resolveGitRevision, v as parseGitPrettyFormat, w as formatError, x as extractMentions, y as parseGitCommit } from "./package-la-hLPRR.js";
|
|
5
|
+
import { a as detectGitRelationship, c as deriveReleaseType, i as GIT_REL_FLAGS, l as pickPriorityReleaseType, n as buildDependencyGraph, o as deriveTransitionReleases, r as mergeGitHistory, s as deriveChangeReleases, t as propagateDependencyUpdates, u as deriveCommitReleaseType } from "./propagateDependencyUpdates-xcPvP5SP.js";
|
|
6
|
+
import { a as discoverPackageTag, i as prependChangelog, n as Priority, o as extractLatestVersion, r as writeChangelog, s as readGitFile, t as HookDispatcher } from "./HookDispatcher-B_TrMRLU.js";
|
|
7
|
+
import { t as resolvePackageTag } from "./resolvePackageTag-2ldvH7PC.js";
|
|
8
|
+
import "./types.js";
|
|
3
9
|
import { createRequire } from "node:module";
|
|
10
|
+
import semver from "semver";
|
|
11
|
+
import { colors } from "consola/utils";
|
|
12
|
+
import { Writable } from "node:stream";
|
|
13
|
+
import fs from "node:fs/promises";
|
|
4
14
|
import path from "node:path";
|
|
5
15
|
import { pathToFileURL } from "node:url";
|
|
16
|
+
import GitHost from "hosted-git-info";
|
|
17
|
+
import { appendFileSync } from "node:fs";
|
|
18
|
+
// src/workflow/version/isStableVersion.ts
|
|
19
|
+
/**
|
|
20
|
+
* Determine whether a version string represents a stable SemVer release.
|
|
21
|
+
*
|
|
22
|
+
* A version is considered stable when:
|
|
23
|
+
* - It is a valid SemVer string.
|
|
24
|
+
* - Its major version is greater than 0 (not 0.x.x).
|
|
25
|
+
* - It contains no prerelease identifiers (no `-alpha`, `-beta`, `-rc`, etc.).
|
|
26
|
+
*
|
|
27
|
+
* Build metadata (the `+` suffix) does not affect stability.
|
|
28
|
+
*
|
|
29
|
+
* @param version Semantic version string to check
|
|
30
|
+
* @returns `true` if `version` is a stable SemVer; otherwise `false`
|
|
31
|
+
* @throws If `version` is not a valid SemVer string
|
|
32
|
+
*/
|
|
33
|
+
function isStableVersion(version) {
|
|
34
|
+
const parsed = semver.parse(version);
|
|
35
|
+
if (!parsed) throw new Error(`The version "${colors.bold(version)}" is not a valid SemVer.`);
|
|
36
|
+
return parsed.major > 0 && parsed.prerelease.length === 0;
|
|
37
|
+
}
|
|
38
|
+
// src/util/captureCommandOutput.ts
|
|
39
|
+
/** Maximum bytes of command output kept per stream for failure diagnostics. */
|
|
40
|
+
var MAX_TAIL_BYTES = 65536;
|
|
41
|
+
/**
|
|
42
|
+
* Capture command output at the call site, optionally streaming it live.
|
|
43
|
+
*
|
|
44
|
+
* The returned wrappers keep a tail-bounded capture of everything written
|
|
45
|
+
* through them. When `pipe` is set they also forward the output to the
|
|
46
|
+
* context streams, so it keeps flowing live into the terminal or the CI
|
|
47
|
+
* job log; otherwise the output stays inside the capture.
|
|
48
|
+
*
|
|
49
|
+
* @param context Release context carrying the destination streams
|
|
50
|
+
* @param options Whether the captured output is forwarded to the context
|
|
51
|
+
* streams
|
|
52
|
+
* @returns Wrapping streams plus the captured tail readers
|
|
53
|
+
*/
|
|
54
|
+
function captureCommandOutput(context, options) {
|
|
55
|
+
const stdoutTail = new OutputTail();
|
|
56
|
+
const stderrTail = new OutputTail();
|
|
57
|
+
return {
|
|
58
|
+
stdout: createCapturingStream(options.pipe ? context.stdout : void 0, stdoutTail),
|
|
59
|
+
stderr: createCapturingStream(options.pipe ? context.stderr : void 0, stderrTail),
|
|
60
|
+
readStdout: () => stdoutTail.read().trim(),
|
|
61
|
+
readDiagnostics: () => stderrTail.read().trim() || stdoutTail.read().trim()
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Append captured command output to a failure error message.
|
|
66
|
+
*
|
|
67
|
+
* Command runs that stream through call-site wrappers carry no
|
|
68
|
+
* `execCommand` diagnostics of their own; this appends the captured tail
|
|
69
|
+
* so the publish-rejection classifiers keep reading the command output
|
|
70
|
+
* from the error message.
|
|
71
|
+
*
|
|
72
|
+
* @param cause The error thrown by the command
|
|
73
|
+
* @param capture The capture created for the run
|
|
74
|
+
* @returns The error, with the captured output appended to its message
|
|
75
|
+
*/
|
|
76
|
+
function appendCapturedDiagnostics(cause, capture) {
|
|
77
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
78
|
+
const diagnostics = capture.readDiagnostics();
|
|
79
|
+
if (diagnostics) error.message = `${error.message}\n${diagnostics}`;
|
|
80
|
+
return error;
|
|
81
|
+
}
|
|
82
|
+
var OutputTail = class {
|
|
83
|
+
chunks = [];
|
|
84
|
+
size = 0;
|
|
85
|
+
push(chunk) {
|
|
86
|
+
this.chunks.push(chunk);
|
|
87
|
+
this.size += chunk.length;
|
|
88
|
+
while (this.size > MAX_TAIL_BYTES && this.chunks.length > 1) {
|
|
89
|
+
const head = this.chunks.shift();
|
|
90
|
+
if (!head) break;
|
|
91
|
+
this.size -= head.length;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
read() {
|
|
95
|
+
let buffer = Buffer.concat(this.chunks);
|
|
96
|
+
if (buffer.length > MAX_TAIL_BYTES) buffer = trimUtf8Start(buffer.subarray(buffer.length - MAX_TAIL_BYTES));
|
|
97
|
+
return buffer.toString("utf-8");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
function trimUtf8Start(buffer) {
|
|
101
|
+
let start = 0;
|
|
102
|
+
while (start < 3 && start < buffer.length) {
|
|
103
|
+
const byte = buffer[start];
|
|
104
|
+
if (byte === void 0 || (byte & 192) !== 128) break;
|
|
105
|
+
start += 1;
|
|
106
|
+
}
|
|
107
|
+
return start === 0 ? buffer : buffer.subarray(start);
|
|
108
|
+
}
|
|
109
|
+
function createCapturingStream(target, tail) {
|
|
110
|
+
return new Writable({ write(chunk, _encoding, callback) {
|
|
111
|
+
tail.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
112
|
+
if (target) target.write(chunk, callback);
|
|
113
|
+
else callback();
|
|
114
|
+
} });
|
|
115
|
+
}
|
|
116
|
+
// src/util/interpolate.ts
|
|
117
|
+
var BACKSLASH = "\\";
|
|
118
|
+
var LEFT_BRACE = "{";
|
|
119
|
+
var RIGHT_BRACE = "}";
|
|
120
|
+
var DOT = ".";
|
|
121
|
+
var ESCAPE_CHARS = [
|
|
122
|
+
BACKSLASH,
|
|
123
|
+
LEFT_BRACE,
|
|
124
|
+
RIGHT_BRACE
|
|
125
|
+
];
|
|
126
|
+
var BANNED_KEYS = [
|
|
127
|
+
"__proto__",
|
|
128
|
+
"constructor",
|
|
129
|
+
"prototype"
|
|
130
|
+
];
|
|
131
|
+
/**
|
|
132
|
+
* Interpolate placeholders in `template` using values from `data`.
|
|
133
|
+
*
|
|
134
|
+
* - Placeholders use `{path.to.value}` (dot notation).
|
|
135
|
+
* - Backslash escapes are supported for `{`, `}`, `\`, and `.` inside tokens.
|
|
136
|
+
* - Tokens that reference banned keys (`__proto__`, `constructor`, `prototype`)
|
|
137
|
+
* are left unexpanded to avoid prototype pollution.
|
|
138
|
+
* - Only own properties are followed when resolving paths; when any step is
|
|
139
|
+
* missing, the token is preserved with its escape sequences already
|
|
140
|
+
* resolved, so an unresolved `{a\.b}` renders as `{a.b}`.
|
|
141
|
+
* - Resolved non-object, non-null values are stringified and inserted.
|
|
142
|
+
* - Unclosed tokens keep their opening brace and resolved body; a trailing
|
|
143
|
+
* backslash is emitted as-is.
|
|
144
|
+
*
|
|
145
|
+
* @param template Template string containing placeholders like `{user.name}`
|
|
146
|
+
* @param data Object used to resolve placeholder paths
|
|
147
|
+
* @returns The template with placeholders replaced by corresponding values
|
|
148
|
+
*/
|
|
149
|
+
function interpolate(template, data) {
|
|
150
|
+
let result = "";
|
|
151
|
+
let i = 0;
|
|
152
|
+
let char;
|
|
153
|
+
let nextChar;
|
|
154
|
+
while (char = template[i]) if (char === BACKSLASH) {
|
|
155
|
+
nextChar = template[i + 1];
|
|
156
|
+
if (nextChar !== void 0 && ESCAPE_CHARS.includes(nextChar)) {
|
|
157
|
+
result += nextChar;
|
|
158
|
+
i += 2;
|
|
159
|
+
} else {
|
|
160
|
+
result += char;
|
|
161
|
+
i += 1;
|
|
162
|
+
}
|
|
163
|
+
} else if (char === LEFT_BRACE) {
|
|
164
|
+
const keys = [];
|
|
165
|
+
let key = "";
|
|
166
|
+
let token = "";
|
|
167
|
+
let closed = false;
|
|
168
|
+
i += 1;
|
|
169
|
+
while (char = template[i]) {
|
|
170
|
+
if (char === RIGHT_BRACE) {
|
|
171
|
+
closed = true;
|
|
172
|
+
keys.push(key);
|
|
173
|
+
i += 1;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (char === BACKSLASH) {
|
|
177
|
+
nextChar = template[i + 1];
|
|
178
|
+
if (nextChar !== void 0 && [...ESCAPE_CHARS, DOT].includes(nextChar)) {
|
|
179
|
+
key += nextChar;
|
|
180
|
+
token += nextChar;
|
|
181
|
+
i += 2;
|
|
182
|
+
} else {
|
|
183
|
+
key += char;
|
|
184
|
+
token += char;
|
|
185
|
+
i += 1;
|
|
186
|
+
}
|
|
187
|
+
} else if (char === DOT) {
|
|
188
|
+
keys.push(key);
|
|
189
|
+
key = "";
|
|
190
|
+
token += char;
|
|
191
|
+
i += 1;
|
|
192
|
+
} else {
|
|
193
|
+
key += char;
|
|
194
|
+
token += char;
|
|
195
|
+
i += 1;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (closed) {
|
|
199
|
+
let value = data;
|
|
200
|
+
for (const key of keys) {
|
|
201
|
+
const isSafeKey = !BANNED_KEYS.includes(key);
|
|
202
|
+
if (value !== null && typeof value === "object" && Object.hasOwn(value, key) && isSafeKey) value = value[key];
|
|
203
|
+
else {
|
|
204
|
+
value = void 0;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (value == null || typeof value === "object") result += LEFT_BRACE + token + RIGHT_BRACE;
|
|
209
|
+
else result += String(value);
|
|
210
|
+
} else result += LEFT_BRACE + token;
|
|
211
|
+
} else {
|
|
212
|
+
result += char;
|
|
213
|
+
i += 1;
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
// src/util/isTruthyString.ts
|
|
218
|
+
/**
|
|
219
|
+
* Determine whether a string value represents a truthy boolean.
|
|
220
|
+
*
|
|
221
|
+
* Trims leading and trailing whitespace and coerces the target string to
|
|
222
|
+
* lowercase. Evaluates the string as truthy if it equals `'true'` or `'1'`.
|
|
223
|
+
*
|
|
224
|
+
* @param value The raw string to evaluate
|
|
225
|
+
* @returns `true` if `value` normalizes to `'true'` or `'1'`, otherwise `false`
|
|
226
|
+
*/
|
|
227
|
+
function isTruthyString(value) {
|
|
228
|
+
if (!value) return false;
|
|
229
|
+
const normalized = value.toLowerCase().trim();
|
|
230
|
+
return normalized === "true" || normalized === "1";
|
|
231
|
+
}
|
|
6
232
|
// src/util/isCI.ts
|
|
7
233
|
/**
|
|
8
234
|
* Determine whether the current process is running in a CI environment.
|
|
@@ -17,31 +243,182 @@ import { pathToFileURL } from "node:url";
|
|
|
17
243
|
function isCI(env) {
|
|
18
244
|
return isTruthyString(env.CI);
|
|
19
245
|
}
|
|
246
|
+
// src/util/isClass.ts
|
|
247
|
+
/**
|
|
248
|
+
* Determine whether a given value is a constructible class.
|
|
249
|
+
*
|
|
250
|
+
* Verifies that the input is a function with a non-writable prototype, can
|
|
251
|
+
* be successfully invoked via `Reflect.construct`, and matches ES6 class
|
|
252
|
+
* syntax.
|
|
253
|
+
*
|
|
254
|
+
* @param func The unknown value to inspect
|
|
255
|
+
* @returns True if the value is a class, false otherwise
|
|
256
|
+
*/
|
|
257
|
+
function isClass(func) {
|
|
258
|
+
if (typeof func !== "function") return false;
|
|
259
|
+
try {
|
|
260
|
+
Reflect.construct(Object, [], func);
|
|
261
|
+
} catch {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
const descriptor = Object.getOwnPropertyDescriptor(func, "prototype");
|
|
265
|
+
if (!descriptor || descriptor.writable) return false;
|
|
266
|
+
return /^class\s/.test(Function.prototype.toString.call(func));
|
|
267
|
+
}
|
|
268
|
+
// src/util/isGitHubActions.ts
|
|
269
|
+
/**
|
|
270
|
+
* Determine whether the current process runs on a GitHub Actions runner.
|
|
271
|
+
*
|
|
272
|
+
* Checks if the `GITHUB_ACTIONS` environment variable is set to a truthy
|
|
273
|
+
* value. Gates GitHub Actions-specific reporting such as job summaries and
|
|
274
|
+
* annotations.
|
|
275
|
+
*
|
|
276
|
+
* @param env Readonly process environment variables object
|
|
277
|
+
* @returns `true` if `env.GITHUB_ACTIONS` normalizes to a truthy string, otherwise `false`
|
|
278
|
+
*/
|
|
279
|
+
function isGitHubActions(env) {
|
|
280
|
+
return isTruthyString(env.GITHUB_ACTIONS);
|
|
281
|
+
}
|
|
20
282
|
// src/util/isQuietEnvironment.ts
|
|
21
283
|
/**
|
|
22
284
|
* Determine whether the current run should stay quiet about verbose output.
|
|
23
285
|
*
|
|
24
|
-
* A run is quiet when
|
|
25
|
-
* for a human
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* `
|
|
286
|
+
* A run is quiet when its verbose output would only accumulate noise: no
|
|
287
|
+
* terminal is attached for a human to read it live, or the run is inside CI
|
|
288
|
+
* where the provider records a job log that publish noise would pollute.
|
|
289
|
+
* The debug flag opts back in: a debug run is never quiet, not even inside
|
|
290
|
+
* CI, so `--debug` keeps the verbose output flowing. Quiet runs still
|
|
291
|
+
* surface command output on failure — `execCommand` attaches it to the
|
|
292
|
+
* failure diagnostics and captured commands attach their recorded output
|
|
293
|
+
* to the thrown error — so failures stay diagnosable.
|
|
29
294
|
*
|
|
30
|
-
* CI
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* escape hatch.
|
|
295
|
+
* CI runs stay quiet even when the provider attaches a pseudo-terminal: the
|
|
296
|
+
* `isCI` check guarantees it on top of the TTY check, so the job log keeps
|
|
297
|
+
* the publish results without the package manager noise.
|
|
34
298
|
*
|
|
35
299
|
* The verdict is per environment, not per stream, so a redirected stdout inside
|
|
36
300
|
* an interactive terminal still counts as quiet.
|
|
37
301
|
*
|
|
38
|
-
* @param context Release context carrying the
|
|
39
|
-
*
|
|
302
|
+
* @param context Release context carrying the debug flag, destination
|
|
303
|
+
* stream, and environment
|
|
304
|
+
* @returns `true` when the run is part of CI or no TTY is attached, unless
|
|
305
|
+
* the debug flag is set
|
|
40
306
|
*/
|
|
41
307
|
function isQuietEnvironment(context) {
|
|
42
|
-
if (
|
|
308
|
+
if (context.debug) return false;
|
|
309
|
+
if (isCI(context.env)) return true;
|
|
43
310
|
return context.stdout?.isTTY !== true;
|
|
44
311
|
}
|
|
312
|
+
// src/util/readJson.ts
|
|
313
|
+
/**
|
|
314
|
+
* Read and parse a JSON file.
|
|
315
|
+
*
|
|
316
|
+
* Throws a descriptive error when the file cannot be read or parsed, or when
|
|
317
|
+
* the parsed value is not an object.
|
|
318
|
+
*
|
|
319
|
+
* @param filePath Path to the JSON file
|
|
320
|
+
* @returns Parsed JSON object
|
|
321
|
+
* @throws If the file cannot be read, parsed, or is not an object
|
|
322
|
+
*/
|
|
323
|
+
async function readJson(filePath) {
|
|
324
|
+
let content;
|
|
325
|
+
try {
|
|
326
|
+
content = await fs.readFile(filePath, "utf-8");
|
|
327
|
+
} catch (err) {
|
|
328
|
+
throw new Error(`JSON file at "${colors.bold(filePath)}" could not be read.`, { cause: err });
|
|
329
|
+
}
|
|
330
|
+
let json;
|
|
331
|
+
try {
|
|
332
|
+
json = JSON.parse(content);
|
|
333
|
+
} catch (err) {
|
|
334
|
+
throw new Error(`JSON file at "${colors.bold(filePath)}" could not be parsed.`, { cause: err });
|
|
335
|
+
}
|
|
336
|
+
if (typeof json !== "object" || json === null) throw new Error(`JSON file at "${colors.bold(filePath)}" does not contain a valid object.`);
|
|
337
|
+
return json;
|
|
338
|
+
}
|
|
339
|
+
// src/util/writeJson.ts
|
|
340
|
+
/**
|
|
341
|
+
* Write a JSON `payload` to `filePath`, formatting the content first.
|
|
342
|
+
*
|
|
343
|
+
* Ensures the directory exists and writes the formatted JSON.
|
|
344
|
+
*
|
|
345
|
+
* @param filePath Path to write the JSON file
|
|
346
|
+
* @param payload JSON-serializable object to write
|
|
347
|
+
* @returns Promise that resolves when the file is written
|
|
348
|
+
*/
|
|
349
|
+
async function writeJson(filePath, payload) {
|
|
350
|
+
let content = JSON.stringify(payload, null, 2);
|
|
351
|
+
content = await formatFile(filePath, content);
|
|
352
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
353
|
+
await fs.writeFile(filePath, content);
|
|
354
|
+
}
|
|
355
|
+
// src/config/createPlugin.ts
|
|
356
|
+
/**
|
|
357
|
+
* Instantiate or invoke a plugin factory to produce a release plugin instance.
|
|
358
|
+
*
|
|
359
|
+
* Accepts class constructors, factory functions, tuple configurations, or
|
|
360
|
+
* existing plugin objects. Instantiates classes using `new` or invokes factory
|
|
361
|
+
* functions with options, validating that the resulting object satisfies the
|
|
362
|
+
* plugin structure.
|
|
363
|
+
*
|
|
364
|
+
* @param plugin A plugin constructor, factory function, tuple, or object
|
|
365
|
+
* @returns A validated release plugin instance or null
|
|
366
|
+
*/
|
|
367
|
+
async function createPlugin(plugin) {
|
|
368
|
+
let options;
|
|
369
|
+
if (Array.isArray(plugin)) [plugin, options] = plugin;
|
|
370
|
+
if (typeof plugin === "function") plugin = isClass(plugin) ? new plugin(options) : await plugin(options);
|
|
371
|
+
if (plugin != null && typeof plugin === "object" && Object.hasOwn(plugin, "name") && typeof plugin.name === "string") return plugin;
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
// src/config/findReleaseRule.ts
|
|
375
|
+
/**
|
|
376
|
+
* Find the first release rule matching a release reference.
|
|
377
|
+
*
|
|
378
|
+
* Matches rules sequentially against the reference type and pattern.
|
|
379
|
+
*
|
|
380
|
+
* @param ref Release reference object
|
|
381
|
+
* @param rules Array of release rules to match against
|
|
382
|
+
* @returns The first matching release rule or `undefined`
|
|
383
|
+
*/
|
|
384
|
+
function findReleaseRule(ref, rules) {
|
|
385
|
+
return rules.find((rule) => {
|
|
386
|
+
return (rule.type == null || rule.type === ref.type) && isMatch(ref.name, rule.pattern);
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
// src/config/isSemVer.ts
|
|
390
|
+
/**
|
|
391
|
+
* Determine whether a value is a valid Semantic Versioning string.
|
|
392
|
+
*
|
|
393
|
+
* Rejects non-string values, leading or trailing whitespace, and leading `v`
|
|
394
|
+
* prefixes. Validates the candidate string using `semver.parse`.
|
|
395
|
+
*
|
|
396
|
+
* @param version Candidate value to evaluate for SemVer compliance
|
|
397
|
+
* @returns `true` if `version` is a valid SemVer string, or `false` otherwise
|
|
398
|
+
*/
|
|
399
|
+
function isSemVer(version) {
|
|
400
|
+
if (typeof version !== "string") return false;
|
|
401
|
+
if (version !== version.trim()) return false;
|
|
402
|
+
if (version.startsWith("v")) return false;
|
|
403
|
+
return semver.parse(version) != null;
|
|
404
|
+
}
|
|
405
|
+
// src/config/isSemVerGitTag.ts
|
|
406
|
+
/**
|
|
407
|
+
* Determine whether a tag string is a valid SemVer-style Git tag.
|
|
408
|
+
*
|
|
409
|
+
* Anchors `SEMVER_REGEX.source` for full-string matching and applies the
|
|
410
|
+
* repository's Git-tag acceptance rules.
|
|
411
|
+
*
|
|
412
|
+
* @param tag Tag string to validate
|
|
413
|
+
* @returns `true` if `tag` is accepted as a SemVer-style Git tag; otherwise `false`
|
|
414
|
+
*/
|
|
415
|
+
function isSemVerGitTag(tag) {
|
|
416
|
+
const match = new RegExp(`^${SEMVER_REGEX.source}$`).exec(tag);
|
|
417
|
+
if (!match) return false;
|
|
418
|
+
const isScopedPackage = Boolean(match[1]);
|
|
419
|
+
const hasVersionPrefix = tag.startsWith("v");
|
|
420
|
+
return isScopedPackage || hasVersionPrefix;
|
|
421
|
+
}
|
|
45
422
|
// src/config/normalizeCommitFilter.ts
|
|
46
423
|
/**
|
|
47
424
|
* Normalize a commit classifier into a consistent function.
|
|
@@ -61,6 +438,19 @@ function normalizeCommitFilter(classifier) {
|
|
|
61
438
|
}));
|
|
62
439
|
return (commit) => commit.type ? map.get(commit.type) : null;
|
|
63
440
|
}
|
|
441
|
+
// src/config/sanitizePrereleaseLabel.ts
|
|
442
|
+
/**
|
|
443
|
+
* Sanitize a string into a safe, SemVer-compliant prerelease label.
|
|
444
|
+
*
|
|
445
|
+
* Replaces sequences of non-alphanumeric characters with a single hyphen and
|
|
446
|
+
* removes leading or trailing hyphens.
|
|
447
|
+
*
|
|
448
|
+
* @param label Raw string to sanitize
|
|
449
|
+
* @returns Safe SemVer prerelease label
|
|
450
|
+
*/
|
|
451
|
+
function sanitizePrereleaseLabel(label) {
|
|
452
|
+
return label.replace(/[^a-zA-Z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
453
|
+
}
|
|
64
454
|
// src/config/normalizeReleaseRule.ts
|
|
65
455
|
/**
|
|
66
456
|
* Normalize a release rule input into a resolved release rule object.
|
|
@@ -135,22 +525,360 @@ function normalizeWorkspace(cwd, workspace) {
|
|
|
135
525
|
async function resolvePlugin(cwd, plugin) {
|
|
136
526
|
let options;
|
|
137
527
|
if (Array.isArray(plugin)) [plugin, options] = plugin;
|
|
138
|
-
if (typeof plugin === "string") plugin = await import(createRequire(pathToFileURL(cwd)).resolve(plugin));
|
|
528
|
+
if (typeof plugin === "string") plugin = await import(createRequire(pathToFileURL(`${cwd}/`)).resolve(plugin));
|
|
139
529
|
if (plugin != null && typeof plugin === "object" && "default" in plugin) plugin = plugin.default;
|
|
140
530
|
if (typeof plugin === "function") return [plugin, options];
|
|
141
531
|
if (plugin != null && typeof plugin === "object" && Object.hasOwn(plugin, "name") && typeof plugin.name === "string") return plugin;
|
|
142
532
|
return null;
|
|
143
533
|
}
|
|
534
|
+
// src/config/resolveReleaseChannel.ts
|
|
535
|
+
/**
|
|
536
|
+
* Resolve the release channel for a release context.
|
|
537
|
+
*
|
|
538
|
+
* Uses the release rule when `channel` is `boolean` or omitted. Sanitizes the
|
|
539
|
+
* reference name when enabling default channel resolution and interpolates
|
|
540
|
+
* `templateParams` into the result.
|
|
541
|
+
*
|
|
542
|
+
* @param options Options for resolving the release channel
|
|
543
|
+
* @returns Resolved release channel string or `undefined`
|
|
544
|
+
*/
|
|
545
|
+
function resolveReleaseChannel(options) {
|
|
546
|
+
const { ref, rule, templateParams } = options;
|
|
547
|
+
let { channel } = options;
|
|
548
|
+
let resolved;
|
|
549
|
+
if (channel === true || channel == null) channel = rule?.releaseChannel ?? channel;
|
|
550
|
+
if (typeof channel === "string") resolved = channel;
|
|
551
|
+
else if (channel) resolved = sanitizePrereleaseLabel(ref.name);
|
|
552
|
+
if (typeof resolved === "string") resolved = interpolate(resolved, templateParams);
|
|
553
|
+
return resolved;
|
|
554
|
+
}
|
|
555
|
+
// src/config/resolveVersionQualifier.ts
|
|
556
|
+
/**
|
|
557
|
+
* Resolve the version qualifier for a release context.
|
|
558
|
+
*
|
|
559
|
+
* Uses the release rule when `qualifier` is `boolean` or omitted. Interpolates
|
|
560
|
+
* `templateParams` into `qualifier` and validates that the result forms a
|
|
561
|
+
* valid SemVer prerelease identifier.
|
|
562
|
+
*
|
|
563
|
+
* @param options Options for resolving the version qualifier
|
|
564
|
+
* @returns Resolved version qualifier string or `undefined`
|
|
565
|
+
* @throws If the resolved string is not a valid SemVer prerelease identifier
|
|
566
|
+
*/
|
|
567
|
+
function resolveVersionQualifier(options) {
|
|
568
|
+
const { rule, templateParams } = options;
|
|
569
|
+
let { qualifier } = options;
|
|
570
|
+
let resolved;
|
|
571
|
+
if (qualifier === true || qualifier == null) qualifier = rule?.versionQualifier ?? qualifier;
|
|
572
|
+
if (typeof qualifier === "string") resolved = qualifier;
|
|
573
|
+
else if (qualifier) resolved = "";
|
|
574
|
+
if (typeof resolved === "string") resolved = interpolate(resolved, templateParams);
|
|
575
|
+
if (resolved && !isSemVer(`1.0.0-${resolved}.1`)) throw new Error(`The resolved version qualifier "${resolved}" is not a valid SemVer prerelease identifier.`);
|
|
576
|
+
return resolved;
|
|
577
|
+
}
|
|
578
|
+
// src/git/branch/getCurrentGitBranch.ts
|
|
579
|
+
/**
|
|
580
|
+
* Get the current Git branch name.
|
|
581
|
+
*
|
|
582
|
+
* Uses `execGit` to run `git symbolic-ref -q --short HEAD` in the provided
|
|
583
|
+
* working directory and trims the result. Returns an empty string when the
|
|
584
|
+
* repository is in a detached HEAD state.
|
|
585
|
+
*
|
|
586
|
+
* @param cwd The working directory to run the Git command in
|
|
587
|
+
* @returns The current branch name as a string
|
|
588
|
+
*/
|
|
589
|
+
async function getCurrentGitBranch(cwd) {
|
|
590
|
+
return (await execGit(cwd, [
|
|
591
|
+
"symbolic-ref",
|
|
592
|
+
"-q",
|
|
593
|
+
"--short",
|
|
594
|
+
"HEAD"
|
|
595
|
+
])).trim();
|
|
596
|
+
}
|
|
597
|
+
// src/git/commit/createGitCommit.ts
|
|
598
|
+
/**
|
|
599
|
+
* Stage all changes and create a git commit with the specified message.
|
|
600
|
+
*
|
|
601
|
+
* Validates the commit message and working directory status before staging
|
|
602
|
+
* all changes and executing the commit command.
|
|
603
|
+
*
|
|
604
|
+
* @param cwd The target directory path for executing git commands
|
|
605
|
+
* @param message The message to associate with the commit
|
|
606
|
+
* @returns A promise that resolves when the operation completes
|
|
607
|
+
*/
|
|
608
|
+
async function createGitCommit(cwd, message) {
|
|
609
|
+
if (!message) return;
|
|
610
|
+
await execGit(cwd, ["add", "."]);
|
|
611
|
+
if (!(await execGit(cwd, ["status", "--porcelain"])).trim()) return;
|
|
612
|
+
await execGit(cwd, [
|
|
613
|
+
"commit",
|
|
614
|
+
"--message",
|
|
615
|
+
message
|
|
616
|
+
]);
|
|
617
|
+
}
|
|
618
|
+
// src/git/commit/getCurrentGitCommit.ts
|
|
619
|
+
/**
|
|
620
|
+
* Resolve the current `HEAD` commit in the repository.
|
|
621
|
+
*
|
|
622
|
+
* @param cwd Repository working directory path
|
|
623
|
+
* @param markers Optional array of custom trailer marker strings
|
|
624
|
+
* @returns Parsed commit object for the current `HEAD` commit
|
|
625
|
+
*/
|
|
626
|
+
function getCurrentGitCommit(cwd, markers = []) {
|
|
627
|
+
return getParsedGitCommit(cwd, "HEAD", markers);
|
|
628
|
+
}
|
|
629
|
+
// src/git/history/restoreFullGitHistory.ts
|
|
630
|
+
/**
|
|
631
|
+
* Convert a shallow clone into a full clone by fetching additional history.
|
|
632
|
+
*
|
|
633
|
+
* Runs `git fetch --unshallow`. Returns `true` when the operation succeeds
|
|
634
|
+
* and `false` on error.
|
|
635
|
+
*
|
|
636
|
+
* @param cwd Repository working directory
|
|
637
|
+
* @returns `true` when the operation succeeded, otherwise `false`
|
|
638
|
+
*/
|
|
639
|
+
function restoreFullGitHistory(cwd) {
|
|
640
|
+
return execGit(cwd, ["fetch", "--unshallow"]).then(() => true).catch(() => false);
|
|
641
|
+
}
|
|
642
|
+
// src/git/repository/getGitConfigValue.ts
|
|
643
|
+
/**
|
|
644
|
+
* Get a local git configuration value for `key` in the repository at `cwd`.
|
|
645
|
+
*
|
|
646
|
+
* Returns the config value when present; otherwise `undefined`.
|
|
647
|
+
*
|
|
648
|
+
* @param cwd Repository working directory
|
|
649
|
+
* @param key Git config key to read
|
|
650
|
+
* @returns The config value or `undefined` if not set
|
|
651
|
+
*/
|
|
652
|
+
async function getGitConfigValue(cwd, key) {
|
|
653
|
+
try {
|
|
654
|
+
const value = (await execGit(cwd, [
|
|
655
|
+
"config",
|
|
656
|
+
"--local",
|
|
657
|
+
"--get",
|
|
658
|
+
key
|
|
659
|
+
])).trim();
|
|
660
|
+
return value ? value : void 0;
|
|
661
|
+
} catch {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
// src/git/repository/ensureGitUserConfig.ts
|
|
666
|
+
/**
|
|
667
|
+
* Ensure Git user configuration is set and return a cleanup handle.
|
|
668
|
+
*
|
|
669
|
+
* Checks the existing `user.name` and `user.email` configuration for the given
|
|
670
|
+
* working directory. Updates the configuration if either value is missing and
|
|
671
|
+
* returns an `AsyncDisposable` resource that restores the original state upon
|
|
672
|
+
* disposal.
|
|
673
|
+
*
|
|
674
|
+
* @param cwd Working directory path in which to check and set Git configuration
|
|
675
|
+
* @param user Git author details containing name and email
|
|
676
|
+
* @returns Async disposable cleanup object if updated, or undefined if already set
|
|
677
|
+
*/
|
|
678
|
+
async function ensureGitUserConfig(cwd, user) {
|
|
679
|
+
const initialName = await getGitConfigValue(cwd, "user.name");
|
|
680
|
+
const initialEmail = await getGitConfigValue(cwd, "user.email");
|
|
681
|
+
if (initialName && initialEmail) return;
|
|
682
|
+
await execGit(cwd, [
|
|
683
|
+
"config",
|
|
684
|
+
"user.name",
|
|
685
|
+
user.name
|
|
686
|
+
]);
|
|
687
|
+
await execGit(cwd, [
|
|
688
|
+
"config",
|
|
689
|
+
"user.email",
|
|
690
|
+
user.email
|
|
691
|
+
]);
|
|
692
|
+
return { async [Symbol.asyncDispose]() {
|
|
693
|
+
if (initialName) await execGit(cwd, [
|
|
694
|
+
"config",
|
|
695
|
+
"user.name",
|
|
696
|
+
initialName
|
|
697
|
+
]);
|
|
698
|
+
else await execGit(cwd, [
|
|
699
|
+
"config",
|
|
700
|
+
"--unset",
|
|
701
|
+
"user.name"
|
|
702
|
+
]);
|
|
703
|
+
if (initialEmail) await execGit(cwd, [
|
|
704
|
+
"config",
|
|
705
|
+
"user.email",
|
|
706
|
+
initialEmail
|
|
707
|
+
]);
|
|
708
|
+
else await execGit(cwd, [
|
|
709
|
+
"config",
|
|
710
|
+
"--unset",
|
|
711
|
+
"user.email"
|
|
712
|
+
]);
|
|
713
|
+
} };
|
|
714
|
+
}
|
|
715
|
+
// src/git/repository/getGitRemote.ts
|
|
716
|
+
/**
|
|
717
|
+
* Get the URL for the named remote (defaults to `origin`).
|
|
718
|
+
*
|
|
719
|
+
* @param cwd Repository working directory
|
|
720
|
+
* @param remoteName Remote name (defaults to `'origin'`)
|
|
721
|
+
* @returns Remote URL string or `null` when unavailable
|
|
722
|
+
*/
|
|
723
|
+
function getGitRemote(cwd, remoteName = "origin") {
|
|
724
|
+
return execGit(cwd, [
|
|
725
|
+
"remote",
|
|
726
|
+
"get-url",
|
|
727
|
+
remoteName
|
|
728
|
+
]).then((stdout) => stdout.trim()).catch(() => null);
|
|
729
|
+
}
|
|
730
|
+
// src/git/repository/pushGitChanges.ts
|
|
731
|
+
/**
|
|
732
|
+
* Push a branch and optional tags to the `origin` remote using an atomic push.
|
|
733
|
+
*
|
|
734
|
+
* @param cwd Repository working directory
|
|
735
|
+
* @param branch Branch name to push
|
|
736
|
+
* @param additionalTags Optional list of tag names to push alongside the branch
|
|
737
|
+
* @returns Promise that resolves when the push completes
|
|
738
|
+
*/
|
|
739
|
+
async function pushGitChanges(cwd, branch, ...additionalTags) {
|
|
740
|
+
await execGit(cwd, [
|
|
741
|
+
"push",
|
|
742
|
+
"origin",
|
|
743
|
+
...compact([branch, ...additionalTags]),
|
|
744
|
+
"--atomic",
|
|
745
|
+
"--no-verify"
|
|
746
|
+
]);
|
|
747
|
+
}
|
|
748
|
+
// src/git/repository/resolveGitRepository.ts
|
|
749
|
+
/**
|
|
750
|
+
* Resolve Git repository host, owner, and project metadata from the `origin` remote URL.
|
|
751
|
+
*
|
|
752
|
+
* @param cwd Repository working directory
|
|
753
|
+
* @returns Promise that resolves to a `GitRepository` object, or `null` when unavailable
|
|
754
|
+
*/
|
|
755
|
+
async function resolveGitRepository(cwd) {
|
|
756
|
+
const origin = await getGitRemote(cwd);
|
|
757
|
+
if (!origin) return null;
|
|
758
|
+
const info = GitHost.fromUrl(origin);
|
|
759
|
+
if (info && typeof info.type === "string" && typeof info.user === "string" && typeof info.project === "string") return {
|
|
760
|
+
host: info.type,
|
|
761
|
+
owner: info.user,
|
|
762
|
+
repo: info.project,
|
|
763
|
+
url: info.browse()
|
|
764
|
+
};
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
// src/git/tag/createGitTag.ts
|
|
768
|
+
/**
|
|
769
|
+
* Create a git tag in the repository at `cwd`.
|
|
770
|
+
*
|
|
771
|
+
* Creates an annotated tag when `message` is provided.
|
|
772
|
+
*
|
|
773
|
+
* @param cwd Repository working directory
|
|
774
|
+
* @param tag Tag name to create
|
|
775
|
+
* @param message Optional tag message (creates an annotated tag when present)
|
|
776
|
+
* @returns Promise that resolves when the tag is created
|
|
777
|
+
*/
|
|
778
|
+
async function createGitTag(cwd, tag, message) {
|
|
779
|
+
await execGit(cwd, ["tag", ...message ? [
|
|
780
|
+
"-a",
|
|
781
|
+
tag,
|
|
782
|
+
"-m",
|
|
783
|
+
message,
|
|
784
|
+
"--cleanup=whitespace"
|
|
785
|
+
] : [tag]]);
|
|
786
|
+
}
|
|
787
|
+
// src/git/tag/getCurrentGitTag.ts
|
|
788
|
+
/**
|
|
789
|
+
* Get the tag name that exactly matches the current `HEAD`, if any.
|
|
790
|
+
*
|
|
791
|
+
* @param cwd Repository working directory
|
|
792
|
+
* @returns Tag name or `null` when no exact tag matches HEAD
|
|
793
|
+
*/
|
|
794
|
+
async function getCurrentGitTag(cwd) {
|
|
795
|
+
try {
|
|
796
|
+
const tag = (await execGit(cwd, [
|
|
797
|
+
"describe",
|
|
798
|
+
"--tags",
|
|
799
|
+
"--exact-match"
|
|
800
|
+
])).trim();
|
|
801
|
+
/* istanbul ignore next */
|
|
802
|
+
return tag ? tag : null;
|
|
803
|
+
} catch {
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
// src/git/tag/getLatestGitTag.ts
|
|
808
|
+
/**
|
|
809
|
+
* Get the most recent tag reachable from `HEAD`.
|
|
810
|
+
*
|
|
811
|
+
* @param cwd Repository working directory
|
|
812
|
+
* @returns Latest tag string or `null` when none is found
|
|
813
|
+
*/
|
|
814
|
+
async function getLatestGitTag(cwd) {
|
|
815
|
+
try {
|
|
816
|
+
const tag = (await execGit(cwd, [
|
|
817
|
+
"describe",
|
|
818
|
+
"--tags",
|
|
819
|
+
"--abbrev=0"
|
|
820
|
+
])).trim();
|
|
821
|
+
/* istanbul ignore next */
|
|
822
|
+
return tag ? tag : null;
|
|
823
|
+
} catch {
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
// src/git/tag/isGitTagExact.ts
|
|
828
|
+
/**
|
|
829
|
+
* Check whether a given tag points to the provided commit.
|
|
830
|
+
*
|
|
831
|
+
* @param cwd Repository working directory
|
|
832
|
+
* @param tag Tag name to resolve
|
|
833
|
+
* @param commit Commit hash to compare against
|
|
834
|
+
* @returns `true` when the tag points at `commit`, otherwise `false`
|
|
835
|
+
*/
|
|
836
|
+
async function isGitTagExact(cwd, tag, commit) {
|
|
837
|
+
try {
|
|
838
|
+
await execGit(cwd, [
|
|
839
|
+
"merge-base",
|
|
840
|
+
"--is-ancestor",
|
|
841
|
+
`refs/tags/${tag}^{commit}`,
|
|
842
|
+
commit
|
|
843
|
+
]);
|
|
844
|
+
await execGit(cwd, [
|
|
845
|
+
"merge-base",
|
|
846
|
+
"--is-ancestor",
|
|
847
|
+
commit,
|
|
848
|
+
`refs/tags/${tag}^{commit}`
|
|
849
|
+
]);
|
|
850
|
+
return true;
|
|
851
|
+
} catch {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
// src/workflow/discovery/filterPackages.ts
|
|
856
|
+
/**
|
|
857
|
+
* Filter packages by name patterns.
|
|
858
|
+
*
|
|
859
|
+
* Keeps the packages whose names match `patterns`, scoping a release run to
|
|
860
|
+
* a subset of the discovered workspace. Returns a copy of every package when
|
|
861
|
+
* `patterns` is empty.
|
|
862
|
+
*
|
|
863
|
+
* @param packages Workspace packages to filter
|
|
864
|
+
* @param patterns Minimatch patterns to match package names against
|
|
865
|
+
* @returns Packages whose names match the patterns
|
|
866
|
+
*/
|
|
867
|
+
function filterPackages(packages, patterns) {
|
|
868
|
+
if (patterns.length === 0) return [...packages];
|
|
869
|
+
return packages.filter((pkg) => isMatch(pkg.name ?? "", patterns));
|
|
870
|
+
}
|
|
144
871
|
// src/workflow/discovery/sortPackages.ts
|
|
145
872
|
/**
|
|
146
873
|
* Sort workspace packages topologically based on their dependency graphs.
|
|
147
874
|
*
|
|
148
|
-
* Deepest
|
|
149
|
-
* a package always
|
|
150
|
-
* are resolved deterministically using an alphabetical sort on the package
|
|
875
|
+
* Deepest dependencies are placed first in the resulting array, ensuring that
|
|
876
|
+
* a package always follows its own dependencies. Ties and circular dependencies
|
|
877
|
+
* are resolved deterministically using an alphabetical sort on the package
|
|
878
|
+
* location (`location`).
|
|
151
879
|
*
|
|
152
880
|
* @param packages The workspace packages to sort.
|
|
153
|
-
* @returns A new array of packages sorted by dependency depth and
|
|
881
|
+
* @returns A new array of packages sorted by dependency depth and location.
|
|
154
882
|
*/
|
|
155
883
|
function sortPackages(packages) {
|
|
156
884
|
const packageNodes = [];
|
|
@@ -176,6 +904,555 @@ function sortPackages(packages) {
|
|
|
176
904
|
}
|
|
177
905
|
return packageNodes.toSorted((a, b) => b.level - a.level).map((node) => node.package);
|
|
178
906
|
}
|
|
179
|
-
|
|
907
|
+
// src/workflow/commit/generateReleaseCommitMessage.ts
|
|
908
|
+
var NOTABLE_TYPES = [
|
|
909
|
+
"feat",
|
|
910
|
+
"fix",
|
|
911
|
+
"perf",
|
|
912
|
+
"refactor",
|
|
913
|
+
"revert"
|
|
914
|
+
];
|
|
915
|
+
/**
|
|
916
|
+
* Generate a formatted release commit message based on release plans and
|
|
917
|
+
* custom trailers.
|
|
918
|
+
*
|
|
919
|
+
* Compiles package version updates and included commit logs into a standardized
|
|
920
|
+
* conventional commit message body, appending configured release agent and
|
|
921
|
+
* custom trailers. Returns `null` if no valid release subject can be derived.
|
|
922
|
+
*
|
|
923
|
+
* @param cwd The working directory path
|
|
924
|
+
* @param plans Readonly array of release plans containing package changes and commit history
|
|
925
|
+
* @param trailers Optional record of custom git trailers to append to the commit
|
|
926
|
+
* @returns The formatted release commit message string or `null` if the subject is empty
|
|
927
|
+
* @example
|
|
928
|
+
* ```
|
|
929
|
+
* chore: release pkg-a@2.1.0, pkg-b@1.0.4
|
|
930
|
+
*
|
|
931
|
+
* Version Updates:
|
|
932
|
+
* - pkg-a: 2.0.0 → 2.1.0
|
|
933
|
+
* - pkg-b: 1.0.3 → 1.0.4
|
|
934
|
+
*
|
|
935
|
+
* Notable Changes:
|
|
936
|
+
* - feat(pkg-a): support custom plugin entrypoints (#210)
|
|
937
|
+
* - fix(pkg-b): correct minor typography bug in help text (#212)
|
|
938
|
+
*
|
|
939
|
+
* Release-Mode: Deferred
|
|
940
|
+
* ```
|
|
941
|
+
*/
|
|
942
|
+
async function generateReleaseCommitMessage(cwd, plans, trailers = {}) {
|
|
943
|
+
const standalone = plans.length === 1;
|
|
944
|
+
trailers = {
|
|
945
|
+
[GIT_TRAILER_RELEASE_AGENT]: `ReelOut/${/* istanbul ignore next */ version}`,
|
|
946
|
+
...trailers
|
|
947
|
+
};
|
|
948
|
+
plans = plans.filter((plan) => plan.release?.tag?.name).toSorted((a, b) => {
|
|
949
|
+
if (a.package.entry) return -1;
|
|
950
|
+
if (b.package.entry) return 1;
|
|
951
|
+
/* istanbul ignore next */
|
|
952
|
+
return (a.package.name ?? "").localeCompare(b.package.name ?? "");
|
|
953
|
+
});
|
|
954
|
+
let subject;
|
|
955
|
+
if (plans.length === 1) subject = standalone ? plans[0]?.release?.version : plans[0]?.release?.tag?.name;
|
|
956
|
+
else if (plans.length >= 2 && plans.length <= 3) subject = plans.map((plan) => plan.release?.tag?.name).join(", ");
|
|
957
|
+
else if (plans.length > 3) subject = `${plans.length} packages (${plans.slice(0, 2).map((plan) => plan.release?.tag?.name).join(", ")}, +${plans.length - 2} more)`;
|
|
958
|
+
if (!subject) return null;
|
|
959
|
+
const packages = plans.map((plan) => {
|
|
960
|
+
return `- ${plan.package.name || plan.package.location}: ${plan.package.version} → ${plan.release?.version}`;
|
|
961
|
+
});
|
|
962
|
+
const commits = (await plans.reduce(async (acc, plan) => mergeGitHistory(cwd, await acc, plan.history), Promise.resolve([]))).filter((commit) => {
|
|
963
|
+
const isNotableType = commit.type && NOTABLE_TYPES.includes(commit.type);
|
|
964
|
+
const isBreaking = commit.notes.length > 0;
|
|
965
|
+
return isNotableType || isBreaking;
|
|
966
|
+
}).toReversed().map(({ header }) => `- ${header}`);
|
|
967
|
+
return [
|
|
968
|
+
`chore: release ${subject}`,
|
|
969
|
+
packages.length >= 2 ? ["Version Updates:", ...packages].join("\n") : void 0,
|
|
970
|
+
commits.length > 0 ? ["Notable Changes:", ...commits].join("\n") : void 0,
|
|
971
|
+
Object.entries(trailers).map(([key, value]) => key && value != null ? `${key}: ${value}` : "").filter(Boolean).join("\n")
|
|
972
|
+
].filter(Boolean).join("\n\n");
|
|
973
|
+
}
|
|
974
|
+
// src/plugin/createHostReleasePlugin.ts
|
|
975
|
+
/**
|
|
976
|
+
* Read the release token from the release environment.
|
|
977
|
+
*
|
|
978
|
+
* Treats unset and whitespace-only values as missing.
|
|
979
|
+
*
|
|
980
|
+
* @param env Release environment variables
|
|
981
|
+
* @param tokenEnvKey Environment variable holding the release token
|
|
982
|
+
* @returns The trimmed token, or undefined when it is not set
|
|
983
|
+
*/
|
|
984
|
+
var readToken = (env, tokenEnvKey) => {
|
|
985
|
+
const token = env[tokenEnvKey]?.trim();
|
|
986
|
+
return token ? token : void 0;
|
|
987
|
+
};
|
|
988
|
+
/**
|
|
989
|
+
* Run the collected release rollbacks, logging individual rollback failures
|
|
990
|
+
* without aborting the remaining rollbacks.
|
|
991
|
+
*
|
|
992
|
+
* @param logger Logger used to report rollback failures
|
|
993
|
+
* @param displayName Human-readable host name used in log messages
|
|
994
|
+
* @param rollbacks Rollbacks collected during publishing
|
|
995
|
+
*/
|
|
996
|
+
var rollbackReleases = async (logger, displayName, rollbacks) => {
|
|
997
|
+
const results = await Promise.allSettled(rollbacks.map(({ rollback }) => rollback()));
|
|
998
|
+
for (const [index, entry] of rollbacks.entries()) {
|
|
999
|
+
const result = results[index];
|
|
1000
|
+
if (result?.status === "rejected") logger.error(`A ${displayName} release for tag "${entry.tag}" could not be rolled back: ${formatError(result.reason)}`);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
/**
|
|
1004
|
+
* Create a built-in plugin that publishes releases to a git host.
|
|
1005
|
+
*
|
|
1006
|
+
* Produces the shared skeleton behind the host release plugins. The plugin
|
|
1007
|
+
* stays inactive unless the release repository is hosted on the given host,
|
|
1008
|
+
* and verifies the token during the `configure` stage: a missing token
|
|
1009
|
+
* skips the plugin's `publish` step with a debug message — or fails the run in
|
|
1010
|
+
* strict mode — and a provided token is verified against the release
|
|
1011
|
+
* repository before any mutation. During `publish`, host releases are
|
|
1012
|
+
* created in reverse alphabetical package order (ensuring the root package
|
|
1013
|
+
* release is created last) and rolled back when subsequent publishing
|
|
1014
|
+
* stages fail.
|
|
1015
|
+
*
|
|
1016
|
+
* @param options Host release plugin options
|
|
1017
|
+
* @returns A release plugin configured for the given host
|
|
1018
|
+
*/
|
|
1019
|
+
function createHostReleasePlugin(options) {
|
|
1020
|
+
return {
|
|
1021
|
+
name: options.name,
|
|
1022
|
+
version: options.version,
|
|
1023
|
+
configure: async (context, next) => {
|
|
1024
|
+
const repository = context.repository;
|
|
1025
|
+
if (repository?.host !== options.host) {
|
|
1026
|
+
context.logger.debug(`${options.displayName} releases will not be created: no ${options.displayName}-hosted repository was detected.`);
|
|
1027
|
+
return next(context);
|
|
1028
|
+
}
|
|
1029
|
+
const token = readToken(context.env, options.tokenEnvKey);
|
|
1030
|
+
if (!token) {
|
|
1031
|
+
if (context.strict) throw new Error(`The ${options.tokenEnvKey} environment variable is required in strict mode.`);
|
|
1032
|
+
context.logger.debug(`${options.displayName} releases will not be created: ${options.tokenEnvKey} is not set.`);
|
|
1033
|
+
return next(context);
|
|
1034
|
+
}
|
|
1035
|
+
await options.verifyToken(token, repository);
|
|
1036
|
+
return next(context);
|
|
1037
|
+
},
|
|
1038
|
+
publish: async (context, next) => {
|
|
1039
|
+
if (context.repository?.host !== options.host) {
|
|
1040
|
+
context.logger.debug(`${options.displayName} publishing was skipped: no ${options.displayName}-hosted repository was detected.`);
|
|
1041
|
+
return next(context);
|
|
1042
|
+
}
|
|
1043
|
+
const token = readToken(context.env, options.tokenEnvKey);
|
|
1044
|
+
if (!token) return next(context);
|
|
1045
|
+
if (context.dryRun) {
|
|
1046
|
+
context.logger.debug(`[DRY RUN] ${options.displayName} releases will not be created.`);
|
|
1047
|
+
return next(context);
|
|
1048
|
+
}
|
|
1049
|
+
const plans = context.plans.toSorted((a, b) => (a.package.name || "").localeCompare(b.package.name || ""));
|
|
1050
|
+
const repository = context.repository;
|
|
1051
|
+
const rollbacks = [];
|
|
1052
|
+
try {
|
|
1053
|
+
for (const plan of plans.toReversed()) {
|
|
1054
|
+
const rollback = await options.createRelease(context, plan, token, repository);
|
|
1055
|
+
if (rollback) rollbacks.push({
|
|
1056
|
+
tag: plan.release?.tag?.name ?? "unknown",
|
|
1057
|
+
rollback
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
await rollbackReleases(context.logger, options.displayName, rollbacks);
|
|
1062
|
+
throw err;
|
|
1063
|
+
}
|
|
1064
|
+
try {
|
|
1065
|
+
return await next(context);
|
|
1066
|
+
} catch (err) {
|
|
1067
|
+
await rollbackReleases(context.logger, options.displayName, rollbacks);
|
|
1068
|
+
throw err;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
// src/workflow/report/resolveErrorMessage.ts
|
|
1074
|
+
/**
|
|
1075
|
+
* Resolve a displayable message from an unknown error value.
|
|
1076
|
+
*
|
|
1077
|
+
* Normalizes `Error` instances to their `message` and passes string values
|
|
1078
|
+
* through unchanged. Returns `null` for any other shape so callers can fall
|
|
1079
|
+
* back to a generic message.
|
|
1080
|
+
*
|
|
1081
|
+
* @param error Unknown error value carried on a release outcome
|
|
1082
|
+
* @returns The resolved error message, or `null` when none can be resolved
|
|
1083
|
+
*/
|
|
1084
|
+
function resolveErrorMessage(error) {
|
|
1085
|
+
if (Error.isError(error)) return error.message;
|
|
1086
|
+
return typeof error === "string" ? error : null;
|
|
1087
|
+
}
|
|
1088
|
+
var FALLBACK_ERROR_MESSAGE = "An unexpected error occurred during the release process.";
|
|
1089
|
+
/**
|
|
1090
|
+
* Resolve a displayable failure message from a release outcome.
|
|
1091
|
+
*
|
|
1092
|
+
* Normalizes the outcome error to its message and falls back to a generic
|
|
1093
|
+
* message when the error carries no displayable content.
|
|
1094
|
+
*
|
|
1095
|
+
* @param outcome Failure outcome whose error is rendered
|
|
1096
|
+
* @returns The resolved error message, or the fallback message
|
|
1097
|
+
*/
|
|
1098
|
+
function resolveOutcomeErrorMessage(outcome) {
|
|
1099
|
+
return resolveErrorMessage(outcome.error) || FALLBACK_ERROR_MESSAGE;
|
|
1100
|
+
}
|
|
1101
|
+
// src/workflow/report/appendReleaseReportSummary.ts
|
|
1102
|
+
var STATUS_LABELS = {
|
|
1103
|
+
success: "Success",
|
|
1104
|
+
failure: "Failure"
|
|
1105
|
+
};
|
|
1106
|
+
/**
|
|
1107
|
+
* Append a Markdown release report to the GitHub Actions job summary.
|
|
1108
|
+
*
|
|
1109
|
+
* Detects a GitHub Actions runner through the `GITHUB_ACTIONS` environment
|
|
1110
|
+
* variable and appends the rendered `report` to the file referenced by
|
|
1111
|
+
* `GITHUB_STEP_SUMMARY`, so GitHub displays it on the run summary page. Dry
|
|
1112
|
+
* runs append a `(dry run)` marker to the status line; real releases render
|
|
1113
|
+
* the status unmarked. Does nothing outside GitHub Actions or when no summary
|
|
1114
|
+
* file is configured, and logs a warning instead of throwing when the summary
|
|
1115
|
+
* file cannot be written.
|
|
1116
|
+
*
|
|
1117
|
+
* @param logger Logger instance for reporting summary write failures
|
|
1118
|
+
* @param env Readonly process environment variables object
|
|
1119
|
+
* @param report Release report containing outcome and package details
|
|
1120
|
+
*/
|
|
1121
|
+
function appendReleaseReportSummary(logger, env, report) {
|
|
1122
|
+
if (!isGitHubActions(env)) return;
|
|
1123
|
+
const filePath = env.GITHUB_STEP_SUMMARY;
|
|
1124
|
+
if (!filePath) return;
|
|
1125
|
+
try {
|
|
1126
|
+
appendFileSync(filePath, `\n${formatReleaseReportSummary(report)}`);
|
|
1127
|
+
} catch (error) {
|
|
1128
|
+
logger.warn(`GitHub Actions job summary could not be written to "${filePath}": ${error instanceof Error ? error.message : error}`);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
var formatPackageLabel = (plan) => {
|
|
1132
|
+
if (plan.package.name) return `\`${plan.package.name}\``;
|
|
1133
|
+
return `\`${plan.package.location}\``;
|
|
1134
|
+
};
|
|
1135
|
+
var formatReleaseReportSummary = (report) => {
|
|
1136
|
+
const lines = ["## ReelOut Release Report", ""];
|
|
1137
|
+
if (report.outcome) {
|
|
1138
|
+
const status = STATUS_LABELS[report.outcome.status];
|
|
1139
|
+
const label = report.dryRun ? `${status} (dry run)` : status;
|
|
1140
|
+
lines.push(`**Status:** ${label}`, "");
|
|
1141
|
+
}
|
|
1142
|
+
if (report.outcome?.status === "failure") {
|
|
1143
|
+
const message = resolveOutcomeErrorMessage(report.outcome);
|
|
1144
|
+
lines.push(...message.split("\n").map((line) => `> ${line}`), "");
|
|
1145
|
+
return lines.join("\n");
|
|
1146
|
+
}
|
|
1147
|
+
if (report.plans.length === 0) {
|
|
1148
|
+
lines.push("No packages are scheduled for release.", "");
|
|
1149
|
+
return lines.join("\n");
|
|
1150
|
+
}
|
|
1151
|
+
const plans = report.plans.toSorted((a, b) => (a.package.name || "").localeCompare(b.package.name || ""));
|
|
1152
|
+
lines.push("| Package | Version | Type | Tag |", "| --- | --- | --- | --- |");
|
|
1153
|
+
for (const plan of plans) {
|
|
1154
|
+
const version = `\`${plan.release.version}\` ← \`${plan.package.version}\``;
|
|
1155
|
+
lines.push([
|
|
1156
|
+
`| ${formatPackageLabel(plan)}`,
|
|
1157
|
+
version,
|
|
1158
|
+
plan.release.type,
|
|
1159
|
+
plan.release.tag ? `\`${plan.release.tag}\`` : ""
|
|
1160
|
+
].join(" | ") + " |");
|
|
1161
|
+
}
|
|
1162
|
+
lines.push("");
|
|
1163
|
+
for (const plan of plans) {
|
|
1164
|
+
const changelog = plan.release.changelog?.trim();
|
|
1165
|
+
if (!changelog) continue;
|
|
1166
|
+
lines.push("<details>", `<summary>${formatPackageLabel(plan)} ${plan.release.version}</summary>`, "", changelog, "", "</details>", "");
|
|
1167
|
+
}
|
|
1168
|
+
return lines.join("\n");
|
|
1169
|
+
};
|
|
1170
|
+
// src/workflow/report/generateReleaseReport.ts
|
|
1171
|
+
/**
|
|
1172
|
+
* Generate a structured release report from the current workflow state.
|
|
1173
|
+
*
|
|
1174
|
+
* Extracts state information from `context` and organizes it into a report
|
|
1175
|
+
* containing the `dryRun` flag, the terminal release outcome, release plans,
|
|
1176
|
+
* and package metadata. Omits unversioned release plans from the finalized
|
|
1177
|
+
* output.
|
|
1178
|
+
*
|
|
1179
|
+
* @param context Release execution context containing workflow state and plans
|
|
1180
|
+
* @returns Structured release report object containing workflow results
|
|
1181
|
+
*/
|
|
1182
|
+
function generateReleaseReport(context) {
|
|
1183
|
+
return {
|
|
1184
|
+
dryRun: context.dryRun,
|
|
1185
|
+
outcome: context.outcome,
|
|
1186
|
+
packages: context.packages.map((pkg) => ({
|
|
1187
|
+
location: pkg.location,
|
|
1188
|
+
name: pkg.name,
|
|
1189
|
+
version: pkg.version
|
|
1190
|
+
})),
|
|
1191
|
+
plans: compact(context.plans.map((plan) => {
|
|
1192
|
+
if (!plan.release?.version) return null;
|
|
1193
|
+
return {
|
|
1194
|
+
package: {
|
|
1195
|
+
provider: plan.package.provider,
|
|
1196
|
+
entry: plan.package.entry,
|
|
1197
|
+
location: plan.package.location,
|
|
1198
|
+
name: plan.package.name,
|
|
1199
|
+
version: plan.package.version,
|
|
1200
|
+
private: !!plan.package.private
|
|
1201
|
+
},
|
|
1202
|
+
release: {
|
|
1203
|
+
type: plan.release.type,
|
|
1204
|
+
version: plan.release.version,
|
|
1205
|
+
tag: plan.release.tag?.name,
|
|
1206
|
+
changelog: plan.release.changelog
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
}))
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
// src/workflow/report/printReleaseReport.ts
|
|
1213
|
+
/**
|
|
1214
|
+
* Print a formatted release report to the logger.
|
|
1215
|
+
*
|
|
1216
|
+
* Logs the terminal outcome status and details for planned package releases.
|
|
1217
|
+
* Displays package names, directories, and version changes on success, or
|
|
1218
|
+
* outputs the error message on failure. Dry runs append a `(dry run)` marker
|
|
1219
|
+
* to the status line; real releases print the status unmarked.
|
|
1220
|
+
*
|
|
1221
|
+
* @param logger Logger instance for outputting messages
|
|
1222
|
+
* @param report Release report containing outcome and package details
|
|
1223
|
+
*/
|
|
1224
|
+
function printReleaseReport(logger, report) {
|
|
1225
|
+
if (report.outcome) {
|
|
1226
|
+
const statusLabel = {
|
|
1227
|
+
success: colors.green("SUCCESS"),
|
|
1228
|
+
failure: colors.red("FAILURE")
|
|
1229
|
+
}[report.outcome.status];
|
|
1230
|
+
logger.info(`Status: ${[statusLabel, report.dryRun && colors.yellow("(dry run)")].filter(Boolean).join(" ")}`);
|
|
1231
|
+
}
|
|
1232
|
+
if (report.outcome?.status === "failure") return logger.error(["Release complete:", colors.red(resolveOutcomeErrorMessage(report.outcome))].join(" "));
|
|
1233
|
+
if (report.plans.length === 0) return logger.info(["Release complete:", colors.yellow("No packages are scheduled for release.")].join(" "));
|
|
1234
|
+
const header = [
|
|
1235
|
+
"Release complete:",
|
|
1236
|
+
colors.bold(colors.green(`${report.plans.length} released`)),
|
|
1237
|
+
colors.gray(`(${report.packages.length})`)
|
|
1238
|
+
].join(" ");
|
|
1239
|
+
const list = report.plans.toSorted((a, b) => (a.package.name || "").localeCompare(b.package.name || "")).map((plan) => {
|
|
1240
|
+
let dir = path.normalize(path.join(plan.package.location, "."));
|
|
1241
|
+
dir = dir === "." ? dir : `./${dir}`;
|
|
1242
|
+
const name = plan.package.name ? colors.bgBlue(` ${plan.package.name} `) : !plan.package.entry && colors.gray(` ${dir} `);
|
|
1243
|
+
let version = [plan.release.version, plan.package.version].join(" ← ");
|
|
1244
|
+
version = ` ${version} `;
|
|
1245
|
+
const type = plan.release.type ? colors.gray(` ${plan.release.type} `) : void 0;
|
|
1246
|
+
return [[
|
|
1247
|
+
name,
|
|
1248
|
+
plan.release.type === "major" ? colors.bgRed(version) : colors.bgGreen(version),
|
|
1249
|
+
type
|
|
1250
|
+
].filter(Boolean).join(""), plan.release.changelog?.replace(/^(#+ .+)$/gm, (_, header) => colors.cyan(header)).trim()].filter(Boolean).join("\n\n");
|
|
1251
|
+
}).join("\n\n");
|
|
1252
|
+
logger.info(`${header}\n\n${list}\n`);
|
|
1253
|
+
}
|
|
1254
|
+
// src/workflow/report/printReleaseReportAnnotation.ts
|
|
1255
|
+
/**
|
|
1256
|
+
* Print a GitHub Actions error annotation for a failed release.
|
|
1257
|
+
*
|
|
1258
|
+
* Detects a GitHub Actions runner through the `GITHUB_ACTIONS` environment
|
|
1259
|
+
* variable and writes a `::error` workflow command carrying the failure
|
|
1260
|
+
* reason to `stdout`, so GitHub surfaces the failure as an annotation on the
|
|
1261
|
+
* run page. Does nothing outside GitHub Actions or when the release did not
|
|
1262
|
+
* fail.
|
|
1263
|
+
*
|
|
1264
|
+
* @param env Readonly process environment variables object
|
|
1265
|
+
* @param stdout Writable stream receiving the annotation command
|
|
1266
|
+
* @param report Release report containing outcome and failure details
|
|
1267
|
+
*/
|
|
1268
|
+
function printReleaseReportAnnotation(env, stdout, report) {
|
|
1269
|
+
if (!isGitHubActions(env) || report.outcome?.status !== "failure") return;
|
|
1270
|
+
const message = formatAnnotationMessage(resolveOutcomeErrorMessage(report.outcome));
|
|
1271
|
+
stdout.write(`::error title=Release failed::${message}\n`);
|
|
1272
|
+
}
|
|
1273
|
+
var formatAnnotationMessage = (message) => message.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
1274
|
+
// src/workflow/executeReleaseWorkflow.ts
|
|
1275
|
+
/**
|
|
1276
|
+
* Resolve a plugin's hook entry into a normalized hook definition.
|
|
1277
|
+
*
|
|
1278
|
+
* Accepts a bare middleware function or a `{ priority, middleware }`
|
|
1279
|
+
* definition and extracts its middleware and priority.
|
|
1280
|
+
*
|
|
1281
|
+
* @param hookName Name of the hook to resolve
|
|
1282
|
+
* @param plugin Plugin owning the hook entry
|
|
1283
|
+
* @returns Normalized hook definition, or `undefined` when unimplemented
|
|
1284
|
+
*/
|
|
1285
|
+
function resolvePluginHook(hookName, plugin) {
|
|
1286
|
+
let hook = plugin[hookName];
|
|
1287
|
+
if (typeof hook === "function") hook = { middleware: hook };
|
|
1288
|
+
const middleware = hook?.middleware;
|
|
1289
|
+
const priority = hook?.priority;
|
|
1290
|
+
if (!middleware) return;
|
|
1291
|
+
return {
|
|
1292
|
+
priority,
|
|
1293
|
+
middleware
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Throw a cancellation error when the context abort signal has fired.
|
|
1298
|
+
*
|
|
1299
|
+
* Wraps the underlying `AbortError` so the workflow reports a readable
|
|
1300
|
+
* cancellation instead of a bare DOM exception.
|
|
1301
|
+
*
|
|
1302
|
+
* @param context Release execution context carrying the optional abort signal
|
|
1303
|
+
* @throws If the context abort signal has already fired
|
|
1304
|
+
*/
|
|
1305
|
+
function throwIfCancelled(context) {
|
|
1306
|
+
const signal = context.signal;
|
|
1307
|
+
if (!signal?.aborted) return;
|
|
1308
|
+
try {
|
|
1309
|
+
signal.throwIfAborted();
|
|
1310
|
+
} catch (err) {
|
|
1311
|
+
throw new Error("Release cancelled.", { cause: err });
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Format a duration in milliseconds as a seconds string.
|
|
1316
|
+
*
|
|
1317
|
+
* @param duration Duration in milliseconds
|
|
1318
|
+
* @returns Duration formatted as seconds with two decimal places
|
|
1319
|
+
*/
|
|
1320
|
+
function formatDuration(duration) {
|
|
1321
|
+
return `${(duration / 1e3).toFixed(2)}s`;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Pick the console color for a duration, highlighting slow middleware.
|
|
1325
|
+
*
|
|
1326
|
+
* @param duration Duration in milliseconds
|
|
1327
|
+
* @returns Color function that highlights durations of five seconds or more
|
|
1328
|
+
*/
|
|
1329
|
+
function durationColor(duration) {
|
|
1330
|
+
return duration >= 5e3 ? colors.yellow : colors.cyan;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Format a hook and its owning plugin as a display label.
|
|
1334
|
+
*
|
|
1335
|
+
* @param hook Name of the hook
|
|
1336
|
+
* @param plugin Name of the plugin owning the hook
|
|
1337
|
+
* @returns Gray hook name followed by the plugin name
|
|
1338
|
+
*/
|
|
1339
|
+
function hookLabel(hook, plugin) {
|
|
1340
|
+
return `${colors.gray(`[${hook}]`)} ${plugin}`;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Execute the complete release workflow across all configured plugins.
|
|
1344
|
+
*
|
|
1345
|
+
* Runs each lifecycle phase sequentially, dispatching plugin hooks in onion
|
|
1346
|
+
* order based on declared priority, and checks the abort signal before each
|
|
1347
|
+
* phase. Each dispatched middleware runs through a single constructor
|
|
1348
|
+
* interceptor that also attributes failures to the owning hook and plugin,
|
|
1349
|
+
* collects middleware failures, and rescues `finalize` errors so the
|
|
1350
|
+
* remaining `finalize` middleware still runs. Outside `test` mode the
|
|
1351
|
+
* interceptor logs every middleware's exclusive duration — its wall-clock
|
|
1352
|
+
* time minus the time consumed by downstream middleware — on completion.
|
|
1353
|
+
* When a phase hook throws, plugin rollbacks run while the error unwinds,
|
|
1354
|
+
* then every `finalize` middleware runs with the failure recorded on
|
|
1355
|
+
* `context.outcome`. Each `finalize` failure is logged as a warning after
|
|
1356
|
+
* the report. A failing `finalize` middleware never changes the workflow
|
|
1357
|
+
* outcome and never masks the original workflow error.
|
|
1358
|
+
*
|
|
1359
|
+
* @param context Release execution context containing runtime options and logger
|
|
1360
|
+
* @param plugins List of release plugins to execute
|
|
1361
|
+
* @returns Promise that resolves when all phases and `finalize` middleware
|
|
1362
|
+
* complete
|
|
1363
|
+
* @throws If a lifecycle hook fails or the workflow is cancelled
|
|
1364
|
+
*/
|
|
1365
|
+
async function executeReleaseWorkflow(context, plugins) {
|
|
1366
|
+
context.outcome = null;
|
|
1367
|
+
const middlewareFailures = [];
|
|
1368
|
+
const dispatcher = new HookDispatcher(async (context, registration, next) => {
|
|
1369
|
+
const plugin = registration.meta;
|
|
1370
|
+
/* istanbul ignore next */
|
|
1371
|
+
if (!plugin) throw new Error(`Registration for hook "${registration.hook}" is missing plugin metadata.`);
|
|
1372
|
+
const hook = registration.hook;
|
|
1373
|
+
const label = hookLabel(hook, plugin.name);
|
|
1374
|
+
context.logger.start(label);
|
|
1375
|
+
const startedAt = performance.now();
|
|
1376
|
+
let downstreamDuration = 0;
|
|
1377
|
+
const runNext = async () => {
|
|
1378
|
+
const downstreamStart = performance.now();
|
|
1379
|
+
try {
|
|
1380
|
+
return await next(context);
|
|
1381
|
+
} finally {
|
|
1382
|
+
downstreamDuration += performance.now() - downstreamStart;
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
const finish = (hasError) => {
|
|
1386
|
+
const duration = performance.now() - startedAt - downstreamDuration;
|
|
1387
|
+
const color = durationColor(duration);
|
|
1388
|
+
const message = [label, color(formatDuration(duration))].join(" ");
|
|
1389
|
+
if (hasError) context.logger.error(message);
|
|
1390
|
+
else context.logger.success(message);
|
|
1391
|
+
};
|
|
1392
|
+
try {
|
|
1393
|
+
const result = await registration.middleware.call(plugin, context, runNext);
|
|
1394
|
+
finish(false);
|
|
1395
|
+
return result;
|
|
1396
|
+
} catch (error) {
|
|
1397
|
+
const phase = {
|
|
1398
|
+
hook,
|
|
1399
|
+
plugin: plugin.name
|
|
1400
|
+
};
|
|
1401
|
+
middlewareFailures.push({
|
|
1402
|
+
...phase,
|
|
1403
|
+
error
|
|
1404
|
+
});
|
|
1405
|
+
context.outcome ??= {
|
|
1406
|
+
status: "failure",
|
|
1407
|
+
error,
|
|
1408
|
+
phase
|
|
1409
|
+
};
|
|
1410
|
+
finish(true);
|
|
1411
|
+
if (hook === "finalize") return next(context);
|
|
1412
|
+
throw error;
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
for (const hookName of RELEASE_HOOK_NAMES) for (const plugin of plugins) {
|
|
1416
|
+
const definition = resolvePluginHook(hookName, plugin);
|
|
1417
|
+
if (!definition) continue;
|
|
1418
|
+
dispatcher.on(hookName, definition.middleware, {
|
|
1419
|
+
priority: definition.priority,
|
|
1420
|
+
meta: plugin
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
const dispatch = async (index, context) => {
|
|
1424
|
+
const hook = RELEASE_HOOK_NAMES[index];
|
|
1425
|
+
if (!hook) return;
|
|
1426
|
+
if (hook === "finalize") return await dispatch(index + 1, context);
|
|
1427
|
+
throwIfCancelled(context);
|
|
1428
|
+
return await dispatcher.dispatch(hook, context, (context) => dispatch(index + 1, context));
|
|
1429
|
+
};
|
|
1430
|
+
try {
|
|
1431
|
+
await dispatch(0, context);
|
|
1432
|
+
context.outcome = {
|
|
1433
|
+
status: "success",
|
|
1434
|
+
error: null,
|
|
1435
|
+
phase: null
|
|
1436
|
+
};
|
|
1437
|
+
} catch (err) {
|
|
1438
|
+
context.outcome ??= {
|
|
1439
|
+
status: "failure",
|
|
1440
|
+
error: err,
|
|
1441
|
+
phase: null
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
await dispatcher.dispatch("finalize", context);
|
|
1445
|
+
const report = generateReleaseReport(context);
|
|
1446
|
+
printReleaseReport(context.logger, report);
|
|
1447
|
+
appendReleaseReportSummary(context.logger, context.env, report);
|
|
1448
|
+
printReleaseReportAnnotation(context.env, context.stdout, report);
|
|
1449
|
+
for (const failure of middlewareFailures) {
|
|
1450
|
+
if (failure.hook !== "finalize") continue;
|
|
1451
|
+
if (failure.error === context.outcome.error) continue;
|
|
1452
|
+
context.logger.warn(`Plugin "${failure.plugin}" could not finalize: ${failure.error instanceof Error ? failure.error.message : String(failure.error)}`);
|
|
1453
|
+
}
|
|
1454
|
+
if (context.outcome.status === "failure") throw context.outcome.error;
|
|
1455
|
+
}
|
|
1456
|
+
export { ALL_FILES, DEFAULT_CHANGELOG_FILE, DEV_NULL, GIT_PRETTY_FIELD_SEPARATOR, GIT_PRETTY_FORMAT, GIT_REL_FLAGS, GIT_TRAILER_RELEASE_AGENT, HookDispatcher, Priority, RELEASE_HOOK_NAMES, SEMVER_REGEX, TTLCache, appendCapturedDiagnostics, appendReleaseReportSummary, buildChangelog, buildDependencyGraph, buildReleaseNotes, buildTrailerPattern, bumpVersion, captureCommandOutput, compact, countGitHistory, createGitCommit, createGitTag, createHostReleasePlugin, createPlugin, deleteGitTag, deriveChangeReleases, deriveCommitReleaseType, deriveReleaseType, deriveTransitionReleases, detectGitRelationship, discoverPackageTag, ensureGitTag, ensureGitUserConfig, execCommand, execGit, executeReleaseWorkflow, expandGitHistory, extractLatestVersion, extractMentions, extractPlainText, extractSemVer, extractVersionQualifier, filterPackages, findReleaseRule, formatError, formatFile, generateGitTagName, generateReleaseCommitMessage, generateReleaseReport, getCurrentGitBranch, getCurrentGitCommit, getCurrentGitTag, getGitConfigValue, getGitRemote, getGitTagMessage, getLatestGitTag, getParsedGitCommit, interpolate, isCI, isClass, isDefined, isGitAncestor, isGitHubActions, isGitShallowRepository, isGitTagConnected, isGitTagExact, isGitTagPresent, isMatch, isQuietEnvironment, isSameReleaseCycle, isSemVer, isSemVerGitTag, isStableVersion, isTruthyString, iterateChangelogVersions, mergeGitHistory, normalizeCommitFilter, normalizeReleaseRule, normalizeWorkspace, packageContainsCommit, parseGitCommit, parseGitPrettyFormat, pickPriorityReleaseType, prependChangelog, printReleaseReport, printReleaseReportAnnotation, propagateDependencyUpdates, pushGitChanges, readGitFile, readGitHistory, readJson, readPackageHistory, readParsedGitHistory, resolveGitRepository, resolveGitRevision, resolvePackageStableTag, resolvePackageTag, resolvePlugin, resolveReleaseChannel, resolveVersionQualifier, restoreFullGitHistory, sanitizePrereleaseLabel, sortPackages, unique, verifyPackageTag, withShallowLock, writeChangelog, writeJson };
|
|
180
1457
|
|
|
181
1458
|
//# sourceMappingURL=index.js.map
|