@reelout/core 0.5.2 → 0.6.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/dist/analyzer.js +19 -6
- package/dist/analyzer.js.map +1 -1
- package/dist/builder.js +2 -2
- package/dist/builder.js.map +1 -1
- package/dist/changelog.js +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/{workflow-9iNWXQsA.js → workflow-c9uKSARL.js} +1405 -1315
- package/dist/workflow-c9uKSARL.js.map +1 -0
- package/package.json +1 -1
- package/src/analyzer.ts +34 -11
- package/src/builder.ts +2 -2
- package/src/config/const.ts +2 -0
- package/src/types.ts +1 -0
- package/src/util/isMatch.ts +11 -7
- package/src/workflow/analysis/collectUnreleased.ts +44 -0
- package/src/workflow/analysis/deriveChangeReleases.ts +4 -2
- package/src/workflow/analysis/index.ts +3 -1
- package/src/workflow/analysis/{streamPackageCommits.ts → readPackageHistory.ts} +2 -2
- package/src/workflow/analysis/sliceUnreleased.ts +6 -18
- package/src/workflow/analysis/sliceUnreleasedForPackage.ts +41 -0
- package/src/workflow/committing/formatReleaseFilterPatterns.ts +18 -0
- package/src/workflow/committing/index.ts +2 -0
- package/src/workflow/committing/readReleaseFilterPatterns.ts +38 -0
- package/src/workflow/discovery/filterPackages.ts +27 -0
- package/src/workflow/discovery/index.ts +1 -0
- package/src/workflow/versioning/deriveReleaseType.ts +11 -9
- package/src/workflow/versioning/determineReleaseType.ts +11 -5
- package/dist/workflow-9iNWXQsA.js.map +0 -1
|
@@ -1,233 +1,19 @@
|
|
|
1
|
-
import semver from "semver";
|
|
2
|
-
import { colors } from "consola/utils";
|
|
3
|
-
import { Writable } from "node:stream";
|
|
4
1
|
import { spawn } from "node:child_process";
|
|
5
2
|
import prettier from "prettier";
|
|
6
3
|
import { minimatch } from "minimatch";
|
|
4
|
+
import { colors } from "consola/utils";
|
|
7
5
|
import fs, { readFile } from "node:fs/promises";
|
|
8
6
|
import path from "node:path";
|
|
9
7
|
import { CommitParser } from "conventional-commits-parser";
|
|
10
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
9
|
import GitHost from "hosted-git-info";
|
|
10
|
+
import { Writable } from "node:stream";
|
|
11
|
+
import semver from "semver";
|
|
12
12
|
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
13
13
|
import assert from "node:assert";
|
|
14
14
|
import createPreset from "conventional-changelog-conventionalcommits";
|
|
15
15
|
import { writeChangelogString } from "conventional-changelog-writer";
|
|
16
16
|
import { toMarkdown } from "mdast-util-to-markdown";
|
|
17
|
-
// src/workflow/versioning/extractVersionQualifier.ts
|
|
18
|
-
/**
|
|
19
|
-
* Extract the version qualifier string from a parsed `SemVer` instance.
|
|
20
|
-
*
|
|
21
|
-
* Strips the trailing numeric counter from the `prerelease` components if
|
|
22
|
-
* present. Joins any remaining prerelease identifiers with a dot separator.
|
|
23
|
-
*
|
|
24
|
-
* @param version Parsed `SemVer` instance or nullish value to inspect
|
|
25
|
-
* @returns The extracted qualifier string or `undefined` if no prerelease exists
|
|
26
|
-
*/
|
|
27
|
-
function extractVersionQualifier(version) {
|
|
28
|
-
if (version != null && version.prerelease.length > 0) {
|
|
29
|
-
const prerelease = [...version.prerelease];
|
|
30
|
-
if (typeof prerelease.at(-1) === "number") prerelease.pop();
|
|
31
|
-
return prerelease.join(".");
|
|
32
|
-
} else return;
|
|
33
|
-
}
|
|
34
|
-
// src/workflow/versioning/bumpVersion.ts
|
|
35
|
-
/**
|
|
36
|
-
* Bump a semantic version string based on release and transition rules.
|
|
37
|
-
*
|
|
38
|
-
* Parses the target version and determines the next version string using the
|
|
39
|
-
* specified release type, prerelease identifier, and transition mode. Adjusts
|
|
40
|
-
* prerelease types when continuing an existing qualifier and returns `null` when
|
|
41
|
-
* `options.release` is omitted or if transition conditions fail.
|
|
42
|
-
*
|
|
43
|
-
* @param options Version bump configuration including release type, identifier, and transition rules
|
|
44
|
-
* @returns The bumped semantic version string, or `null` if no bump occurs
|
|
45
|
-
* @throws If `options.version` is not a valid semantic version
|
|
46
|
-
*/
|
|
47
|
-
function bumpVersion(options) {
|
|
48
|
-
const { version } = options;
|
|
49
|
-
const parsed = semver.parse(version);
|
|
50
|
-
if (!parsed) throw new Error(`Version "${version}" is not a valid semantic version.`);
|
|
51
|
-
if (!options.release) return null;
|
|
52
|
-
if (parsed.prerelease.length > 0) {
|
|
53
|
-
if (options.transition === "advance" && options.identifier == null) return null;
|
|
54
|
-
} else if (options.transition === "continue") return null;
|
|
55
|
-
let release = options.release;
|
|
56
|
-
let identifier;
|
|
57
|
-
if (typeof options.identifier === "string") {
|
|
58
|
-
release = `pre${options.release}`;
|
|
59
|
-
identifier = options.identifier;
|
|
60
|
-
const parsedIdentifier = extractVersionQualifier(parsed);
|
|
61
|
-
const transition = options.transition ?? (parsedIdentifier && identifier === "" ? "advance" : "continue");
|
|
62
|
-
if (typeof parsedIdentifier === "string" && transition === "continue") {
|
|
63
|
-
if (release === "premajor" && parsed.minor === 0 && parsed.patch === 0 || release === "preminor" && parsed.patch === 0 || release === "prepatch") release = "prerelease";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return semver.inc(parsed, release, { loose: false }, identifier, "0");
|
|
67
|
-
}
|
|
68
|
-
// src/workflow/versioning/determineReleaseType.ts
|
|
69
|
-
/**
|
|
70
|
-
* Determine the release type for a single commit.
|
|
71
|
-
*
|
|
72
|
-
* Automatically returns `'major'` if the commit is marked as a breaking change.
|
|
73
|
-
* Otherwise, routes the commit through the custom `classifier` and ensures the
|
|
74
|
-
* resolved value is a valid semantic versioning release type.
|
|
75
|
-
*
|
|
76
|
-
* @param classifier Function mapping commits to release types
|
|
77
|
-
* @param commit Parsed commit to evaluate
|
|
78
|
-
* @returns `ReleaseType` string, or `null` when no matching rule applies
|
|
79
|
-
*/
|
|
80
|
-
function determineReleaseType(classifier, commit) {
|
|
81
|
-
if (commit.notes.length > 0) return "major";
|
|
82
|
-
const type = classifier(commit);
|
|
83
|
-
switch (type) {
|
|
84
|
-
case "major":
|
|
85
|
-
case "minor":
|
|
86
|
-
case "patch": return type;
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
// src/workflow/versioning/pickPriorityReleaseType.ts
|
|
91
|
-
/**
|
|
92
|
-
* Determine the highest-priority release type between two candidates.
|
|
93
|
-
*
|
|
94
|
-
* Compares release types by precedence order: `major` > `minor` > `patch`.
|
|
95
|
-
* Returns the higher-precedence type, or `null` if neither applies.
|
|
96
|
-
*
|
|
97
|
-
* @param curr Current accumulated release type
|
|
98
|
-
* @param next Candidate release type to consider
|
|
99
|
-
* @returns Highest-precedence `ReleaseType`, or `null` if neither applies
|
|
100
|
-
*/
|
|
101
|
-
function pickPriorityReleaseType(curr, next) {
|
|
102
|
-
for (const type of [
|
|
103
|
-
"major",
|
|
104
|
-
"minor",
|
|
105
|
-
"patch"
|
|
106
|
-
]) if (curr === type || next === type) return type;
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
// src/workflow/versioning/deriveReleaseType.ts
|
|
110
|
-
/**
|
|
111
|
-
* Derive the combined release type from a commit history collection.
|
|
112
|
-
*
|
|
113
|
-
* Processes commits sequentially, accumulating the highest-precedence release
|
|
114
|
-
* type found by evaluating each individual commit and comparing it against the
|
|
115
|
-
* current maximum via `pickPriorityReleaseType`.
|
|
116
|
-
*
|
|
117
|
-
* @param classifier Function mapping commits to release types
|
|
118
|
-
* @param history Array of parsed commits to evaluate
|
|
119
|
-
* @returns `ReleaseType` string, or `null` when no matching rule applies
|
|
120
|
-
*/
|
|
121
|
-
function deriveReleaseType(classifier, history) {
|
|
122
|
-
let releaseType = null;
|
|
123
|
-
for (const commit of history) releaseType = pickPriorityReleaseType(releaseType, determineReleaseType(classifier, commit));
|
|
124
|
-
return releaseType;
|
|
125
|
-
}
|
|
126
|
-
// src/workflow/versioning/isSameReleaseCycle.ts
|
|
127
|
-
/**
|
|
128
|
-
* Determine whether two semantic version strings or objects belong to the same release cycle.
|
|
129
|
-
*
|
|
130
|
-
* Compares the main version components of `currentVersion` and `nextVersion` to
|
|
131
|
-
* determine equality. Treats a transition from a non-zero `0.x` version to
|
|
132
|
-
* `1.0.0` as part of the same release cycle. Returns `false` if either input
|
|
133
|
-
* cannot be parsed.
|
|
134
|
-
*
|
|
135
|
-
* @param currentVersion Starting version string, `semver.SemVer` instance, or nullish value
|
|
136
|
-
* @param nextVersion Target version string, `semver.SemVer` instance, or nullish value
|
|
137
|
-
* @returns `true` if both versions belong to the same release cycle, `false` otherwise
|
|
138
|
-
*/
|
|
139
|
-
function isSameReleaseCycle(currentVersion, nextVersion) {
|
|
140
|
-
const current = semver.parse(currentVersion);
|
|
141
|
-
const next = semver.parse(nextVersion);
|
|
142
|
-
if (!current || !next) return false;
|
|
143
|
-
if (current.compareMain(next) === 0) return true;
|
|
144
|
-
return current.major === 0 && (current.minor > 0 || current.patch > 0) && next.major === 1 && next.minor === 0 && next.patch === 0;
|
|
145
|
-
}
|
|
146
|
-
// src/workflow/versioning/isStableVersion.ts
|
|
147
|
-
/**
|
|
148
|
-
* Determine whether a version string represents a stable SemVer release.
|
|
149
|
-
*
|
|
150
|
-
* A version is considered stable when:
|
|
151
|
-
* - It is a valid SemVer string.
|
|
152
|
-
* - Its major version is greater than 0 (not 0.x.x).
|
|
153
|
-
* - It contains no prerelease identifiers (no `-alpha`, `-beta`, `-rc`, etc.).
|
|
154
|
-
*
|
|
155
|
-
* Build metadata (the `+` suffix) does not affect stability.
|
|
156
|
-
*
|
|
157
|
-
* @param version Semantic version string to check
|
|
158
|
-
* @returns `true` if `version` is a stable SemVer; otherwise `false`
|
|
159
|
-
* @throws If `version` is not a valid SemVer string
|
|
160
|
-
*/
|
|
161
|
-
function isStableVersion(version) {
|
|
162
|
-
const parsed = semver.parse(version);
|
|
163
|
-
if (!parsed) throw new Error(`The version "${colors.bold(version)}" is not a valid SemVer.`);
|
|
164
|
-
return parsed.major > 0 && parsed.prerelease.length === 0;
|
|
165
|
-
}
|
|
166
|
-
// src/config/const.ts
|
|
167
|
-
var ALL_FILES = "**/*";
|
|
168
|
-
var DEFAULT_CHANGELOG_FILE = "CHANGELOG.md";
|
|
169
|
-
var GIT_TRAILER_RELEASE_AGENT = "Release-Agent";
|
|
170
|
-
/**
|
|
171
|
-
* 1. Primitive Building Blocks
|
|
172
|
-
*
|
|
173
|
-
* Base regular expression patterns for wildcards, alphanumeric strings with hyphens,
|
|
174
|
-
* and standard non-negative integers.
|
|
175
|
-
*/
|
|
176
|
-
var WILDCARD = "\\*";
|
|
177
|
-
var ALPHANUM_DASH = "[0-9a-zA-Z-]+";
|
|
178
|
-
var NUMERIC_IDENTIFIER = "0|[1-9]\\d*";
|
|
179
|
-
/**
|
|
180
|
-
* 2. Package Name & Prefix Constructs
|
|
181
|
-
*
|
|
182
|
-
* Matches package name prefixes (unscoped or scoped) or a simple `v` prefix.
|
|
183
|
-
*
|
|
184
|
-
* Capture Groups:
|
|
185
|
-
* - Group 1: Package name (e.g., `my-package` or `@scope/my-package`)
|
|
186
|
-
*/
|
|
187
|
-
var PKG_NAME_PART = `(?:${WILDCARD}|${ALPHANUM_DASH})`;
|
|
188
|
-
var OPTIONAL_VERSION_PREFIX = `(?:v|${`(${PKG_NAME_PART}|@${PKG_NAME_PART}\\/${PKG_NAME_PART})`}@)`;
|
|
189
|
-
/**
|
|
190
|
-
* 3. Core SemVer Components
|
|
191
|
-
*
|
|
192
|
-
* Matches standard `MAJOR.MINOR.PATCH` versions or wildcard variants (e.g., `1.0.0`, `*.*.*`).
|
|
193
|
-
*
|
|
194
|
-
* Capture Groups:
|
|
195
|
-
* - Group 3: Major version
|
|
196
|
-
* - Group 4: Minor version
|
|
197
|
-
* - Group 5: Patch version
|
|
198
|
-
*/
|
|
199
|
-
var CAPTURED_VERSION_DIGIT = `(${WILDCARD}|${NUMERIC_IDENTIFIER})`;
|
|
200
|
-
var SEMVER_CORE = `${CAPTURED_VERSION_DIGIT}\\.${CAPTURED_VERSION_DIGIT}\\.${CAPTURED_VERSION_DIGIT}`;
|
|
201
|
-
var PRERELEASE_IDENTIFIER = `(?:${WILDCARD}|${NUMERIC_IDENTIFIER}|(\\d*[a-zA-Z-][0-9a-zA-Z-]*))`;
|
|
202
|
-
var FULL_SEMVER_PATTERN = `${OPTIONAL_VERSION_PREFIX}?${`(${SEMVER_CORE}${`(?:-(${PRERELEASE_IDENTIFIER}(?:\\.${PRERELEASE_IDENTIFIER})*))`}?${`(?:\\+(${ALPHANUM_DASH}(?:\\.${ALPHANUM_DASH})*))`}?)`}`;
|
|
203
|
-
/**
|
|
204
|
-
* Regular expression to match and capture Semantic Versioning (SemVer) strings,
|
|
205
|
-
* including optional package prefixes (e.g., `@scope/pkg@`) and `v` prefixes.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```ts
|
|
209
|
-
* SEMVER_REGEX.test('1.0.0') // true
|
|
210
|
-
* SEMVER_REGEX.test('v1.2.3-beta.1+sha.1234') // true
|
|
211
|
-
* SEMVER_REGEX.test('@scope/package@1.0.0') // true
|
|
212
|
-
* ```
|
|
213
|
-
*
|
|
214
|
-
* @see {@link https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string SemVer Specification}
|
|
215
|
-
*/
|
|
216
|
-
var SEMVER_REGEX = new RegExp(FULL_SEMVER_PATTERN);
|
|
217
|
-
var DEV_NULL = new Writable({
|
|
218
|
-
/* istanbul ignore next */
|
|
219
|
-
write(_chunk, _encoding, callback) {
|
|
220
|
-
callback();
|
|
221
|
-
} });
|
|
222
|
-
var RELEASE_HOOK_NAMES = [
|
|
223
|
-
"configure",
|
|
224
|
-
"discover",
|
|
225
|
-
"analyze",
|
|
226
|
-
"build",
|
|
227
|
-
"write",
|
|
228
|
-
"publish",
|
|
229
|
-
"finalize"
|
|
230
|
-
];
|
|
231
17
|
// src/util/buildTrailerPattern.ts
|
|
232
18
|
/**
|
|
233
19
|
* Build a regular expression to match trailer lines using custom markers.
|
|
@@ -534,18 +320,17 @@ function isClass(func) {
|
|
|
534
320
|
/**
|
|
535
321
|
* Determine whether a target string matches glob patterns.
|
|
536
322
|
*
|
|
537
|
-
* Matches positive and negative glob patterns using dotfile support.
|
|
538
|
-
*
|
|
323
|
+
* Matches positive and negative glob patterns using dotfile support.
|
|
324
|
+
* Negation-only patterns are expanded with a catch-all pattern so they match
|
|
325
|
+
* every named target the patterns do not exclude.
|
|
539
326
|
*
|
|
540
327
|
* @param target Target string to evaluate against glob patterns
|
|
541
328
|
* @param patterns Single glob pattern or list of patterns to evaluate
|
|
542
329
|
* @returns True if target matches positive patterns and satisfies negative patterns
|
|
543
330
|
*/
|
|
544
331
|
function isMatch(target, patterns) {
|
|
545
|
-
if (typeof patterns === "string")
|
|
546
|
-
|
|
547
|
-
else patterns = [patterns];
|
|
548
|
-
}
|
|
332
|
+
if (typeof patterns === "string") patterns = [patterns];
|
|
333
|
+
if (patterns.length > 0 && patterns.every((pattern) => pattern.startsWith("!"))) patterns = ["**/*", ...patterns];
|
|
549
334
|
const positives = [];
|
|
550
335
|
const negatives = [];
|
|
551
336
|
for (const pattern of patterns) if (pattern.startsWith("!")) negatives.push(pattern);
|
|
@@ -595,1254 +380,1532 @@ async function writeJson(filePath, payload) {
|
|
|
595
380
|
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
596
381
|
await fs.writeFile(filePath, content);
|
|
597
382
|
}
|
|
598
|
-
// src/
|
|
383
|
+
// src/git/branch/getCurrentGitBranch.ts
|
|
599
384
|
/**
|
|
600
|
-
*
|
|
385
|
+
* Get the current Git branch name.
|
|
601
386
|
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
* plugin structure.
|
|
387
|
+
* Uses `execGit` to run `git symbolic-ref -q --short HEAD` in the provided
|
|
388
|
+
* working directory and trims the result. Returns an empty string when the
|
|
389
|
+
* repository is in a detached HEAD state.
|
|
606
390
|
*
|
|
607
|
-
* @param
|
|
608
|
-
* @returns
|
|
391
|
+
* @param cwd The working directory to run the Git command in
|
|
392
|
+
* @returns The current branch name as a string
|
|
609
393
|
*/
|
|
610
|
-
async function
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
394
|
+
async function getCurrentGitBranch(cwd) {
|
|
395
|
+
return (await execGit(cwd, [
|
|
396
|
+
"symbolic-ref",
|
|
397
|
+
"-q",
|
|
398
|
+
"--short",
|
|
399
|
+
"HEAD"
|
|
400
|
+
])).trim();
|
|
616
401
|
}
|
|
617
|
-
// src/
|
|
402
|
+
// src/git/commit/createGitCommit.ts
|
|
618
403
|
/**
|
|
619
|
-
*
|
|
404
|
+
* Stage all changes and create a git commit with the specified message.
|
|
620
405
|
*
|
|
621
|
-
*
|
|
406
|
+
* Validates the commit message and working directory status before staging
|
|
407
|
+
* all changes and executing the commit command.
|
|
622
408
|
*
|
|
623
|
-
* @param
|
|
624
|
-
* @param
|
|
625
|
-
* @returns
|
|
409
|
+
* @param cwd The target directory path for executing git commands
|
|
410
|
+
* @param message The message to associate with the commit
|
|
411
|
+
* @returns A promise that resolves when the operation completes
|
|
626
412
|
*/
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
413
|
+
async function createGitCommit(cwd, message) {
|
|
414
|
+
if (!message) return;
|
|
415
|
+
await execGit(cwd, ["add", "."]);
|
|
416
|
+
if (!(await execGit(cwd, ["status", "--porcelain"])).trim()) return;
|
|
417
|
+
await execGit(cwd, [
|
|
418
|
+
"commit",
|
|
419
|
+
"--message",
|
|
420
|
+
message
|
|
421
|
+
]);
|
|
422
|
+
}
|
|
423
|
+
// src/git/commit/extractMentions.ts
|
|
424
|
+
var ALPHANUMERIC = "[a-zA-Z0-9]";
|
|
425
|
+
var SEPARATOR = "[-_]";
|
|
426
|
+
var USERNAME = `${ALPHANUMERIC}+(?:${SEPARATOR}+${ALPHANUMERIC}+)*`;
|
|
427
|
+
var EMAIL_LOCAL = "[a-zA-Z0-9._%+-]";
|
|
428
|
+
var DOMAIN_SUFFIX = "[a-zA-Z0-9.-]*\\.[a-zA-Z]{2,}";
|
|
429
|
+
var SCOPED_PACKAGE_SPEC_SUFFIX = `/${USERNAME}@[0-9]+\\.[0-9]+\\.[0-9]+`;
|
|
633
430
|
/**
|
|
634
|
-
*
|
|
431
|
+
* Extract unique mention handles from the input text string.
|
|
635
432
|
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
433
|
+
* Evaluates `text` against boundary rules to isolate valid handles while
|
|
434
|
+
* excluding email addresses, domain names, and scoped package specs, then
|
|
435
|
+
* de-duplicates the resulting handles.
|
|
638
436
|
*
|
|
639
|
-
* @param
|
|
640
|
-
* @returns
|
|
437
|
+
* @param text The input string to parse for mentions
|
|
438
|
+
* @returns An array of unique mention handles
|
|
641
439
|
*/
|
|
642
|
-
function
|
|
643
|
-
if (
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
440
|
+
function extractMentions(text) {
|
|
441
|
+
if (!text) return [];
|
|
442
|
+
const regex = new RegExp(`(?<!${EMAIL_LOCAL})@(${USERNAME})\\b(?!${SEPARATOR}|${DOMAIN_SUFFIX}|${SCOPED_PACKAGE_SPEC_SUFFIX})`, "g");
|
|
443
|
+
const matches = text.matchAll(regex);
|
|
444
|
+
const mentions = new Set(matches.map((match) => match[1]));
|
|
445
|
+
return Array.from(mentions);
|
|
647
446
|
}
|
|
648
|
-
// src/
|
|
447
|
+
// src/cache/TTLCache.ts
|
|
649
448
|
/**
|
|
650
|
-
*
|
|
449
|
+
* A simple time-to-live cache that automatically evicts entries after a TTL.
|
|
651
450
|
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
451
|
+
* - Entries are removed automatically when their TTL expires.
|
|
452
|
+
* - Reading an entry resets its TTL to the original value.
|
|
453
|
+
* - Setting an existing key clears its previous timer and resets the TTL.
|
|
654
454
|
*
|
|
655
|
-
* @
|
|
656
|
-
* @
|
|
455
|
+
* @template K Type of cache keys
|
|
456
|
+
* @template V Type of cache values
|
|
657
457
|
*/
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
458
|
+
var TTLCache = class {
|
|
459
|
+
constructor() {
|
|
460
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Store a value under `key` for `ttl` milliseconds.
|
|
464
|
+
*
|
|
465
|
+
* If the key already exists its previous timer is cleared and the TTL is reset.
|
|
466
|
+
*
|
|
467
|
+
* @param key Cache key
|
|
468
|
+
* @param value Value to store
|
|
469
|
+
* @param ttl Time to live in milliseconds (default: 60_000)
|
|
470
|
+
*/
|
|
471
|
+
set(key, value, ttl = 6e4) {
|
|
472
|
+
const ref = this.cache.get(key);
|
|
473
|
+
if (ref) clearTimeout(ref.timer);
|
|
474
|
+
const timer = setTimeout(() => {
|
|
475
|
+
this.cache.delete(key);
|
|
476
|
+
}, ttl).unref();
|
|
477
|
+
this.cache.set(key, {
|
|
478
|
+
value,
|
|
479
|
+
timer,
|
|
480
|
+
ttl
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Retrieve the value for `key`, or `undefined` if not present.
|
|
485
|
+
*
|
|
486
|
+
* Reading an entry resets its TTL to the original `ttl` provided when it was set.
|
|
487
|
+
*
|
|
488
|
+
* @param key Cache key
|
|
489
|
+
* @returns The stored value or `undefined` if not present
|
|
490
|
+
*/
|
|
491
|
+
get(key) {
|
|
492
|
+
const ref = this.cache.get(key);
|
|
493
|
+
if (!ref) return void 0;
|
|
494
|
+
this.set(key, ref.value, ref.ttl);
|
|
495
|
+
return ref.value;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Check whether `key` exists in the cache.
|
|
499
|
+
*
|
|
500
|
+
* @param key Cache key
|
|
501
|
+
* @returns `true` if present; otherwise `false`
|
|
502
|
+
*/
|
|
503
|
+
has(key) {
|
|
504
|
+
return this.cache.has(key);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Remove `key` from the cache and clear its eviction timer.
|
|
508
|
+
*
|
|
509
|
+
* @param key Cache key
|
|
510
|
+
* @returns `true` if the key was present and removed; otherwise `false`
|
|
511
|
+
*/
|
|
512
|
+
delete(key) {
|
|
513
|
+
const ref = this.cache.get(key);
|
|
514
|
+
if (!ref) return false;
|
|
515
|
+
clearTimeout(ref.timer);
|
|
516
|
+
return this.cache.delete(key);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Clear all entries and their timers.
|
|
520
|
+
*/
|
|
521
|
+
clear() {
|
|
522
|
+
for (const { timer } of this.cache.values()) clearTimeout(timer);
|
|
523
|
+
this.cache.clear();
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
// src/git/commit/parseGitCommit.ts
|
|
527
|
+
var BREAKING_HEADER_REGEX = /^([\w-]+)(?:\(([^)]+)\))?!: (.*)$/;
|
|
528
|
+
var BREAKING_MARKERS = ["BREAKING CHANGE", "BREAKING-CHANGE"];
|
|
666
529
|
/**
|
|
667
|
-
*
|
|
530
|
+
* Parse a git log entry into a structured commit object.
|
|
668
531
|
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
532
|
+
* Combines the commit subject and body, extracts conventional commit metadata
|
|
533
|
+
* using custom trailer markers and breaking header patterns, and normalizes
|
|
534
|
+
* dates to ISO format strings.
|
|
671
535
|
*
|
|
672
|
-
* @param
|
|
673
|
-
* @
|
|
536
|
+
* @param entry The raw git log entry to parse
|
|
537
|
+
* @param markers Optional array of custom trailer marker strings
|
|
538
|
+
* @returns A structured commit object containing parsed details, notes, and mentions
|
|
674
539
|
*/
|
|
675
|
-
function
|
|
676
|
-
|
|
540
|
+
async function parseGitCommit(entry, markers = []) {
|
|
541
|
+
const message = [entry.subject, entry.body].filter(Boolean).join("\n\n");
|
|
542
|
+
const commit = new CommitParser({
|
|
543
|
+
breakingHeaderPattern: BREAKING_HEADER_REGEX,
|
|
544
|
+
noteKeywords: [],
|
|
545
|
+
notesPattern: () => buildTrailerPattern(BREAKING_MARKERS.concat(markers))
|
|
546
|
+
}).parse(message);
|
|
547
|
+
const notes = [];
|
|
548
|
+
const trailers = [];
|
|
549
|
+
for (const note of commit.notes) {
|
|
550
|
+
if (BREAKING_MARKERS.includes(note.title.toUpperCase())) notes.push(note);
|
|
551
|
+
trailers.push({
|
|
552
|
+
key: note.title,
|
|
553
|
+
value: note.text
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
if (notes.length === 0 && BREAKING_HEADER_REGEX.test(commit.header)) {
|
|
557
|
+
const note = {
|
|
558
|
+
title: "BREAKING CHANGE",
|
|
559
|
+
text: commit.subject
|
|
560
|
+
};
|
|
561
|
+
notes.push(note);
|
|
562
|
+
trailers.push({
|
|
563
|
+
key: note.title,
|
|
564
|
+
value: note.text
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
const mentions = extractMentions(message);
|
|
568
|
+
return {
|
|
569
|
+
...commit,
|
|
570
|
+
hash: entry.hash,
|
|
571
|
+
parent: entry.parent,
|
|
572
|
+
authorDate: new Date(entry.authorDate).toISOString(),
|
|
573
|
+
committerDate: new Date(entry.committerDate).toISOString(),
|
|
574
|
+
type: commit.type?.toLowerCase() || null,
|
|
575
|
+
scope: commit.scope || null,
|
|
576
|
+
subject: commit.subject || null,
|
|
577
|
+
header: commit.header,
|
|
578
|
+
body: commit.body,
|
|
579
|
+
footer: commit.footer,
|
|
580
|
+
notes,
|
|
581
|
+
mentions,
|
|
582
|
+
trailers,
|
|
583
|
+
files: entry.files
|
|
584
|
+
};
|
|
677
585
|
}
|
|
678
|
-
// src/
|
|
586
|
+
// src/git/commit/parseGitPrettyFormat.ts
|
|
679
587
|
/**
|
|
680
|
-
*
|
|
681
|
-
|
|
682
|
-
* Uses the release rule when `channel` is `boolean` or omitted. Sanitizes the
|
|
683
|
-
* reference name when enabling default channel resolution and interpolates
|
|
684
|
-
* `templateParams` into the result.
|
|
685
|
-
*
|
|
686
|
-
* @param options Options for resolving the release channel
|
|
687
|
-
* @returns Resolved release channel string or `undefined`
|
|
588
|
+
* Field separator used in the git pretty format to produce a single-line
|
|
589
|
+
*, machine-parseable record.
|
|
688
590
|
*/
|
|
689
|
-
|
|
690
|
-
const { ref, rule, templateParams } = options;
|
|
691
|
-
let { channel } = options;
|
|
692
|
-
let resolved;
|
|
693
|
-
if (channel === true || channel == null) channel = rule?.releaseChannel ?? channel;
|
|
694
|
-
if (typeof channel === "string") resolved = channel;
|
|
695
|
-
else if (channel) resolved = sanitizePrereleaseLabel(ref.name);
|
|
696
|
-
if (typeof resolved === "string") resolved = interpolate(resolved, templateParams);
|
|
697
|
-
return resolved;
|
|
698
|
-
}
|
|
699
|
-
// src/config/resolveVersionQualifier.ts
|
|
591
|
+
var GIT_PRETTY_FIELD_SEPARATOR = "";
|
|
700
592
|
/**
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
* `templateParams` into `qualifier` and validates that the result forms a
|
|
705
|
-
* valid SemVer prerelease identifier.
|
|
706
|
-
*
|
|
707
|
-
* @param options Options for resolving the version qualifier
|
|
708
|
-
* @returns Resolved version qualifier string or `undefined`
|
|
709
|
-
* @throws If the resolved string is not a valid SemVer prerelease identifier
|
|
593
|
+
* Pretty format string passed to `git log --pretty=format:`. Produces seven
|
|
594
|
+
* fields separated by `GIT_PRETTY_FIELD_SEPARATOR`:
|
|
595
|
+
* hash, parents, author date, committer date, subject, body, files.
|
|
710
596
|
*/
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
return resolved;
|
|
721
|
-
}
|
|
722
|
-
// src/workflow/analysis/isCommitForPackage.ts
|
|
597
|
+
var GIT_PRETTY_FORMAT = [
|
|
598
|
+
"%H",
|
|
599
|
+
"%P",
|
|
600
|
+
"%aI",
|
|
601
|
+
"%cI",
|
|
602
|
+
"%s",
|
|
603
|
+
"%b",
|
|
604
|
+
""
|
|
605
|
+
].join("");
|
|
723
606
|
/**
|
|
724
|
-
*
|
|
607
|
+
* Parse a single line produced by `git log --pretty=format:${GIT_PRETTY_FORMAT}`.
|
|
725
608
|
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
*
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
// src/workflow/analysis/deriveChangeReleases.ts
|
|
737
|
-
/**
|
|
738
|
-
* Analyze commit history to update release plans for packages.
|
|
609
|
+
* The input is expected to contain seven fields separated by
|
|
610
|
+
* `GIT_PRETTY_FIELD_SEPARATOR`:
|
|
611
|
+
* 1. `hash` (commit hash)
|
|
612
|
+
* 2. `parent` (space-separated parent hashes)
|
|
613
|
+
* 3. `authorDate` (ISO 8601)
|
|
614
|
+
* 4. `committerDate` (ISO 8601)
|
|
615
|
+
* 5. `subject`
|
|
616
|
+
* 6. `body`
|
|
617
|
+
* 7. `files` (newline-separated list)
|
|
739
618
|
*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
* provided `hint` or existing release priority.
|
|
619
|
+
* The function trims fields, converts parent hashes into an array, normalizes
|
|
620
|
+
* dates to ISO strings, and splits `files` into an array. Missing optional
|
|
621
|
+
* fields are normalized to sensible defaults.
|
|
744
622
|
*
|
|
745
|
-
* @param
|
|
746
|
-
* @
|
|
747
|
-
* @
|
|
748
|
-
* @param history Stream or iterable of git commits to process
|
|
749
|
-
* @returns Updated release plans with updated commit histories and release types
|
|
623
|
+
* @param raw Raw pretty-format string produced by git
|
|
624
|
+
* @returns Parsed `GitLogEntry` with `hash`, `parent`, `authorDate`, `committerDate`, `subject`, `body`, and `files`
|
|
625
|
+
* @throws If required fields (hash, authorDate, committerDate, subject) are missing or malformed
|
|
750
626
|
*/
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
if (releaseType) release = {
|
|
771
|
-
...release,
|
|
772
|
-
type: releaseType
|
|
773
|
-
};
|
|
774
|
-
return {
|
|
775
|
-
...plan,
|
|
776
|
-
release
|
|
777
|
-
};
|
|
778
|
-
});
|
|
627
|
+
function parseGitPrettyFormat(raw) {
|
|
628
|
+
let [hash, parentHashes, authorDate, committerDate, subject, body, files] = raw.split("");
|
|
629
|
+
hash = hash?.trim();
|
|
630
|
+
parentHashes = parentHashes?.trim();
|
|
631
|
+
authorDate = authorDate?.trim();
|
|
632
|
+
committerDate = committerDate?.trim();
|
|
633
|
+
subject = subject?.trim();
|
|
634
|
+
body = body?.trim();
|
|
635
|
+
files = files?.trim();
|
|
636
|
+
if (!hash || !authorDate || !committerDate || typeof subject !== "string") throw new Error(`The input "${colors.bold(raw)}" is not in the expected pretty format.`);
|
|
637
|
+
return {
|
|
638
|
+
hash,
|
|
639
|
+
parent: parentHashes ? parentHashes.split(/\s+/) : [],
|
|
640
|
+
authorDate: new Date(authorDate).toISOString(),
|
|
641
|
+
committerDate: new Date(committerDate).toISOString(),
|
|
642
|
+
subject,
|
|
643
|
+
body: body ?? "",
|
|
644
|
+
files: files ? files.split("\n") : []
|
|
645
|
+
};
|
|
779
646
|
}
|
|
780
|
-
// src/
|
|
647
|
+
// src/git/commit/getParsedGitCommit.ts
|
|
648
|
+
var cache = new TTLCache();
|
|
781
649
|
/**
|
|
782
|
-
*
|
|
650
|
+
* Retrieve and parse a git commit by its reference.
|
|
783
651
|
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
* `versionQualifier` and assigns `major`, `minor`, or `patch` release types
|
|
787
|
-
* according to `hint`. When `hint` is `patch`, every package receives an
|
|
788
|
-
* update: stable packages are assigned a patch release even without a
|
|
789
|
-
* `versionQualifier`, and prerelease packages (pre-major, pre-minor, and
|
|
790
|
-
* pre-patch cycles) continue their cycle with an incremented counter,
|
|
791
|
-
* redirect to `versionQualifier` when it differs, or release their stable
|
|
792
|
-
* base when no `versionQualifier` is set.
|
|
652
|
+
* Fetches the raw git log entry for the specified `ref`, checking the local cache
|
|
653
|
+
* prior to parsing missing entries.
|
|
793
654
|
*
|
|
794
|
-
* @param
|
|
795
|
-
* @param
|
|
796
|
-
* @param
|
|
797
|
-
* @returns
|
|
655
|
+
* @param cwd Current working directory path
|
|
656
|
+
* @param ref Git reference to fetch
|
|
657
|
+
* @param markers Optional array of custom trailer marker strings
|
|
658
|
+
* @returns Structured commit object
|
|
798
659
|
*/
|
|
799
|
-
function
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
} else if (minor === 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "major";
|
|
814
|
-
break;
|
|
815
|
-
case "minor":
|
|
816
|
-
if (parsed.prerelease.length === 0) {
|
|
817
|
-
if (typeof versionQualifier === "string") releaseType = "minor";
|
|
818
|
-
} else if (minor > 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "minor";
|
|
819
|
-
break;
|
|
820
|
-
case "patch":
|
|
821
|
-
releaseType = "patch";
|
|
822
|
-
break;
|
|
823
|
-
default: if (parsed.prerelease.length === 0) {
|
|
824
|
-
if (major === 0 && (minor > 0 || patch > 0)) releaseType = "major";
|
|
825
|
-
} else if (minor === 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "major";
|
|
826
|
-
else if (minor > 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "minor";
|
|
827
|
-
else if (patch > 0 && parsedVersionQualifier !== versionQualifier) releaseType = "patch";
|
|
828
|
-
}
|
|
829
|
-
if (parsedVersionQualifier == null || parsedVersionQualifier !== "" && versionQualifier === "") versionTransition = "advance";
|
|
830
|
-
else versionTransition = "continue";
|
|
831
|
-
if (!releaseType) return plan;
|
|
832
|
-
return {
|
|
833
|
-
...plan,
|
|
834
|
-
release: {
|
|
835
|
-
type: releaseType,
|
|
836
|
-
transition: versionTransition
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
});
|
|
660
|
+
async function getParsedGitCommit(cwd, ref, markers = []) {
|
|
661
|
+
const entry = parseGitPrettyFormat(await execGit(cwd, [
|
|
662
|
+
"log",
|
|
663
|
+
"-1",
|
|
664
|
+
ref,
|
|
665
|
+
"--name-only",
|
|
666
|
+
`--pretty=format:${GIT_PRETTY_FORMAT}`
|
|
667
|
+
]));
|
|
668
|
+
const key = `${entry.hash}:${entry.parent}:${markers}`;
|
|
669
|
+
const cached = cache.get(key);
|
|
670
|
+
if (cached) return cached;
|
|
671
|
+
const parsed = await parseGitCommit(entry, markers);
|
|
672
|
+
cache.set(key, parsed);
|
|
673
|
+
return parsed;
|
|
840
674
|
}
|
|
841
|
-
// src/
|
|
675
|
+
// src/git/commit/getCurrentGitCommit.ts
|
|
842
676
|
/**
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
* Analyzes prerelease and zero-major versions to determine an appropriate
|
|
846
|
-
* release type for graduation:
|
|
847
|
-
* - Prerelease versions are promoted based on their highest incremented component
|
|
848
|
-
* (patch, minor, or major)
|
|
849
|
-
* - Zero-major versions (0.y.z) are promoted to major
|
|
850
|
-
* - Stable versions (1.0.0+) remain unchanged
|
|
851
|
-
* - Plans with explicit releases are preserved as-is
|
|
677
|
+
* Resolve the current `HEAD` commit in the repository.
|
|
852
678
|
*
|
|
853
|
-
* @param
|
|
854
|
-
* @
|
|
679
|
+
* @param cwd Repository working directory path
|
|
680
|
+
* @param markers Optional array of custom trailer marker strings
|
|
681
|
+
* @returns Parsed commit object for the current `HEAD` commit
|
|
855
682
|
*/
|
|
856
|
-
|
|
857
|
-
return
|
|
858
|
-
if (plan.release) return plan;
|
|
859
|
-
if (!plan.package.tag) return plan;
|
|
860
|
-
const parsed = semver.parse(plan.package.version);
|
|
861
|
-
if (!parsed) return plan;
|
|
862
|
-
let type;
|
|
863
|
-
if (parsed.prerelease.length) {
|
|
864
|
-
if (parsed.patch !== 0) type = "patch";
|
|
865
|
-
else if (parsed.minor !== 0) type = "minor";
|
|
866
|
-
else if (parsed.major !== 0) type = "major";
|
|
867
|
-
else type = "major";
|
|
868
|
-
} else if (parsed.major === 0) type = "major";
|
|
869
|
-
if (type) return {
|
|
870
|
-
...plan,
|
|
871
|
-
release: { type }
|
|
872
|
-
};
|
|
873
|
-
return plan;
|
|
874
|
-
});
|
|
683
|
+
function getCurrentGitCommit(cwd, markers = []) {
|
|
684
|
+
return getParsedGitCommit(cwd, "HEAD", markers);
|
|
875
685
|
}
|
|
876
|
-
// src/git/
|
|
686
|
+
// src/git/history/countGitHistory.ts
|
|
877
687
|
/**
|
|
878
|
-
*
|
|
688
|
+
* Count mainline commits reachable from a given reference.
|
|
879
689
|
*
|
|
880
|
-
* Uses `
|
|
881
|
-
*
|
|
882
|
-
* repository is in a detached HEAD state.
|
|
690
|
+
* Uses `git rev-list --count --first-parent` to calculate the length of the
|
|
691
|
+
* primary history trunk, excluding commits introduced by side-branch merges.
|
|
883
692
|
*
|
|
884
|
-
* @param cwd
|
|
885
|
-
* @
|
|
693
|
+
* @param cwd Repository working directory
|
|
694
|
+
* @param ref Commit reference to count from (defaults to `HEAD`)
|
|
695
|
+
* @returns Number of commits along the primary branch line up to `ref`
|
|
886
696
|
*/
|
|
887
|
-
async function
|
|
888
|
-
|
|
889
|
-
"
|
|
890
|
-
"
|
|
891
|
-
"--
|
|
892
|
-
|
|
893
|
-
])
|
|
697
|
+
async function countGitHistory(cwd, ref = "HEAD") {
|
|
698
|
+
const stdout = await execGit(cwd, [
|
|
699
|
+
"rev-list",
|
|
700
|
+
"--count",
|
|
701
|
+
"--first-parent",
|
|
702
|
+
ref
|
|
703
|
+
]);
|
|
704
|
+
return Number.parseInt(stdout.trim(), 10);
|
|
894
705
|
}
|
|
895
|
-
// src/git/
|
|
706
|
+
// src/git/repository/isGitShallowRepository.ts
|
|
896
707
|
/**
|
|
897
|
-
*
|
|
708
|
+
* Determine whether the repository at `cwd` is a shallow clone.
|
|
898
709
|
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
710
|
+
* Runs `git rev-parse --is-shallow-repository` to detect shallow clones.
|
|
711
|
+
* Useful before operations that require full history.
|
|
901
712
|
*
|
|
902
|
-
* @param cwd
|
|
903
|
-
* @
|
|
904
|
-
* @returns A promise that resolves when the operation completes
|
|
713
|
+
* @param cwd Repository working directory
|
|
714
|
+
* @returns `true` if shallow, `false` if full clone, or `null` on error
|
|
905
715
|
*/
|
|
906
|
-
async function
|
|
907
|
-
|
|
908
|
-
await execGit(cwd, ["add", "."]);
|
|
909
|
-
if (!(await execGit(cwd, ["status", "--porcelain"])).trim()) return;
|
|
910
|
-
await execGit(cwd, [
|
|
911
|
-
"commit",
|
|
912
|
-
"--message",
|
|
913
|
-
message
|
|
914
|
-
]);
|
|
716
|
+
async function isGitShallowRepository(cwd) {
|
|
717
|
+
return (await execGit(cwd, ["rev-parse", "--is-shallow-repository"])).trim() === "true";
|
|
915
718
|
}
|
|
916
|
-
// src/git/
|
|
917
|
-
var
|
|
918
|
-
var
|
|
919
|
-
var USERNAME = `${ALPHANUMERIC}+(?:${SEPARATOR}+${ALPHANUMERIC}+)*`;
|
|
920
|
-
var EMAIL_LOCAL = "[a-zA-Z0-9._%+-]";
|
|
921
|
-
var DOMAIN_SUFFIX = "[a-zA-Z0-9.-]*\\.[a-zA-Z]{2,}";
|
|
922
|
-
var SCOPED_PACKAGE_SPEC_SUFFIX = `/${USERNAME}@[0-9]+\\.[0-9]+\\.[0-9]+`;
|
|
719
|
+
// src/git/repository/withShallowLock.ts
|
|
720
|
+
var lockQueue = /* @__PURE__ */ new Map();
|
|
721
|
+
var context = new AsyncLocalStorage();
|
|
923
722
|
/**
|
|
924
|
-
*
|
|
723
|
+
* Serialize access to a shallow Git repository while running a callback.
|
|
925
724
|
*
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
725
|
+
* If `cwd` is a shallow clone, callers from different async contexts are
|
|
726
|
+
* executed one at a time; nested calls within the same async context run
|
|
727
|
+
* immediately without waiting. If the repository becomes non-shallow before
|
|
728
|
+
* a queued turn runs, downstream waiters are released early.
|
|
929
729
|
*
|
|
930
|
-
* @param
|
|
931
|
-
* @
|
|
730
|
+
* @param cwd Repository working directory path string
|
|
731
|
+
* @param callback Function to execute while the lock is held
|
|
732
|
+
* @returns Promise resolving to the result of `callback`
|
|
932
733
|
*/
|
|
933
|
-
function
|
|
934
|
-
if (!
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
const
|
|
938
|
-
|
|
734
|
+
async function withShallowLock(cwd, callback) {
|
|
735
|
+
if (!await isGitShallowRepository(cwd)) return callback();
|
|
736
|
+
const active = context.getStore();
|
|
737
|
+
if (active?.has(cwd)) return callback();
|
|
738
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
739
|
+
const previous = lockQueue.get(cwd) ?? Promise.resolve();
|
|
740
|
+
const queued = previous.then(() => promise);
|
|
741
|
+
lockQueue.set(cwd, queued);
|
|
742
|
+
await previous;
|
|
743
|
+
if (!await isGitShallowRepository(cwd)) resolve();
|
|
744
|
+
try {
|
|
745
|
+
return await context.run(new Set(active).add(cwd), callback);
|
|
746
|
+
} finally {
|
|
747
|
+
resolve();
|
|
748
|
+
if (lockQueue.get(cwd) === queued) lockQueue.delete(cwd);
|
|
749
|
+
}
|
|
939
750
|
}
|
|
940
|
-
// src/
|
|
751
|
+
// src/git/revision/isGitAncestor.ts
|
|
941
752
|
/**
|
|
942
|
-
*
|
|
753
|
+
* Determine whether `ancestor` is an ancestor of `descendant`.
|
|
943
754
|
*
|
|
944
|
-
* -
|
|
945
|
-
*
|
|
946
|
-
*
|
|
755
|
+
* Runs `git merge-base --is-ancestor <ancestor> <descendant>` in the repository at `cwd`.
|
|
756
|
+
* Resolves to `true` if `ancestor` is an ancestor, `false` if not.
|
|
757
|
+
* Rethrows errors for invalid refs or other failures.
|
|
947
758
|
*
|
|
948
|
-
* @
|
|
949
|
-
* @
|
|
759
|
+
* @param cwd Repository working directory
|
|
760
|
+
* @param ancestor Candidate ancestor ref
|
|
761
|
+
* @param descendant Candidate descendant ref
|
|
762
|
+
* @returns Resolves to `true` if `ancestor` is an ancestor of `descendant`, `false` otherwise
|
|
763
|
+
* @throws If a ref is invalid or the Git command fails
|
|
950
764
|
*/
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
*/
|
|
964
|
-
set(key, value, ttl = 6e4) {
|
|
965
|
-
const ref = this.cache.get(key);
|
|
966
|
-
if (ref) clearTimeout(ref.timer);
|
|
967
|
-
const timer = setTimeout(() => {
|
|
968
|
-
this.cache.delete(key);
|
|
969
|
-
}, ttl).unref();
|
|
970
|
-
this.cache.set(key, {
|
|
971
|
-
value,
|
|
972
|
-
timer,
|
|
973
|
-
ttl
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* Retrieve the value for `key`, or `undefined` if not present.
|
|
978
|
-
*
|
|
979
|
-
* Reading an entry resets its TTL to the original `ttl` provided when it was set.
|
|
980
|
-
*
|
|
981
|
-
* @param key Cache key
|
|
982
|
-
* @returns The stored value or `undefined` if not present
|
|
983
|
-
*/
|
|
984
|
-
get(key) {
|
|
985
|
-
const ref = this.cache.get(key);
|
|
986
|
-
if (!ref) return void 0;
|
|
987
|
-
this.set(key, ref.value, ref.ttl);
|
|
988
|
-
return ref.value;
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* Check whether `key` exists in the cache.
|
|
992
|
-
*
|
|
993
|
-
* @param key Cache key
|
|
994
|
-
* @returns `true` if present; otherwise `false`
|
|
995
|
-
*/
|
|
996
|
-
has(key) {
|
|
997
|
-
return this.cache.has(key);
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Remove `key` from the cache and clear its eviction timer.
|
|
1001
|
-
*
|
|
1002
|
-
* @param key Cache key
|
|
1003
|
-
* @returns `true` if the key was present and removed; otherwise `false`
|
|
1004
|
-
*/
|
|
1005
|
-
delete(key) {
|
|
1006
|
-
const ref = this.cache.get(key);
|
|
1007
|
-
if (!ref) return false;
|
|
1008
|
-
clearTimeout(ref.timer);
|
|
1009
|
-
return this.cache.delete(key);
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Clear all entries and their timers.
|
|
1013
|
-
*/
|
|
1014
|
-
clear() {
|
|
1015
|
-
for (const { timer } of this.cache.values()) clearTimeout(timer);
|
|
1016
|
-
this.cache.clear();
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
// src/git/commit/parseGitCommit.ts
|
|
1020
|
-
var BREAKING_HEADER_REGEX = /^([\w-]+)(?:\(([^)]+)\))?!: (.*)$/;
|
|
1021
|
-
var BREAKING_MARKERS = ["BREAKING CHANGE", "BREAKING-CHANGE"];
|
|
765
|
+
function isGitAncestor(cwd, ancestor, descendant) {
|
|
766
|
+
return execGit(cwd, [
|
|
767
|
+
"merge-base",
|
|
768
|
+
"--is-ancestor",
|
|
769
|
+
ancestor,
|
|
770
|
+
descendant
|
|
771
|
+
]).then(() => true).catch((err) => {
|
|
772
|
+
if (err?.code === 1) return false;
|
|
773
|
+
throw err;
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
// src/git/revision/resolveGitRevision.ts
|
|
1022
777
|
/**
|
|
1023
|
-
*
|
|
778
|
+
* Resolve a Git revision or commit-ish expression to its full commit hash.
|
|
1024
779
|
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
* dates to ISO format strings.
|
|
780
|
+
* Runs `git rev-parse --verify <revision>^{commit}` under the hood. Peels annotated
|
|
781
|
+
* tags, branches, short SHAs, and relative expressions down to a verified commit object.
|
|
1028
782
|
*
|
|
1029
|
-
* @param
|
|
1030
|
-
* @param
|
|
1031
|
-
* @returns A
|
|
783
|
+
* @param cwd The repository working directory
|
|
784
|
+
* @param revision The Git revision or expression to resolve
|
|
785
|
+
* @returns A promise that resolves to the full, trimmed commit SHA-1 string
|
|
1032
786
|
*/
|
|
1033
|
-
async function
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}).parse(message);
|
|
1040
|
-
const notes = [];
|
|
1041
|
-
const trailers = [];
|
|
1042
|
-
for (const note of commit.notes) {
|
|
1043
|
-
if (BREAKING_MARKERS.includes(note.title.toUpperCase())) notes.push(note);
|
|
1044
|
-
trailers.push({
|
|
1045
|
-
key: note.title,
|
|
1046
|
-
value: note.text
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
if (notes.length === 0 && BREAKING_HEADER_REGEX.test(commit.header)) {
|
|
1050
|
-
const note = {
|
|
1051
|
-
title: "BREAKING CHANGE",
|
|
1052
|
-
text: commit.subject
|
|
1053
|
-
};
|
|
1054
|
-
notes.push(note);
|
|
1055
|
-
trailers.push({
|
|
1056
|
-
key: note.title,
|
|
1057
|
-
value: note.text
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
const mentions = extractMentions(message);
|
|
1061
|
-
return {
|
|
1062
|
-
...commit,
|
|
1063
|
-
hash: entry.hash,
|
|
1064
|
-
parent: entry.parent,
|
|
1065
|
-
authorDate: new Date(entry.authorDate).toISOString(),
|
|
1066
|
-
committerDate: new Date(entry.committerDate).toISOString(),
|
|
1067
|
-
type: commit.type?.toLowerCase() || null,
|
|
1068
|
-
scope: commit.scope || null,
|
|
1069
|
-
subject: commit.subject || null,
|
|
1070
|
-
header: commit.header,
|
|
1071
|
-
body: commit.body,
|
|
1072
|
-
footer: commit.footer,
|
|
1073
|
-
notes,
|
|
1074
|
-
mentions,
|
|
1075
|
-
trailers,
|
|
1076
|
-
files: entry.files
|
|
1077
|
-
};
|
|
787
|
+
async function resolveGitRevision(cwd, revision) {
|
|
788
|
+
return (await execGit(cwd, [
|
|
789
|
+
"rev-parse",
|
|
790
|
+
"--verify",
|
|
791
|
+
`${revision}^{commit}`
|
|
792
|
+
])).trim();
|
|
1078
793
|
}
|
|
1079
|
-
// src/git/
|
|
794
|
+
// src/git/history/expandGitHistory.ts
|
|
1080
795
|
/**
|
|
1081
|
-
*
|
|
1082
|
-
|
|
796
|
+
* Deepen a shallow clone so additional commits become available.
|
|
797
|
+
*
|
|
798
|
+
* Attempts a single `--shallow-since` fetch to reach `until` (if provided),
|
|
799
|
+
* otherwise deepens by `pageSize`, accounting for existing depth when `from`
|
|
800
|
+
* is supplied. Operation is serialized to avoid concurrent deepens.
|
|
801
|
+
*
|
|
802
|
+
* @param cwd Repository working directory
|
|
803
|
+
* @param options Options: { pageSize?, from?, until? }
|
|
804
|
+
* @returns true if history was deepened or already sufficient, otherwise false
|
|
1083
805
|
*/
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
806
|
+
async function expandGitHistory(cwd, options = {}) {
|
|
807
|
+
if (!await isGitShallowRepository(cwd)) return false;
|
|
808
|
+
return withShallowLock(cwd, async () => {
|
|
809
|
+
const { until } = options;
|
|
810
|
+
let { from } = options;
|
|
811
|
+
let { pageSize = 50 } = options;
|
|
812
|
+
if (until) {
|
|
813
|
+
if (await isGitAncestor(cwd, until, "HEAD")) return true;
|
|
814
|
+
const commitDate = (await execGit(cwd, [
|
|
815
|
+
"show",
|
|
816
|
+
"-s",
|
|
817
|
+
"--format=%cI",
|
|
818
|
+
`${until}^{commit}`
|
|
819
|
+
])).trim();
|
|
820
|
+
try {
|
|
821
|
+
await execGit(cwd, [
|
|
822
|
+
"-c",
|
|
823
|
+
"fetch.negotiationAlgorithm=skipping",
|
|
824
|
+
"fetch",
|
|
825
|
+
`--shallow-since=${commitDate}`,
|
|
826
|
+
"--update-shallow",
|
|
827
|
+
"--filter=blob:none"
|
|
828
|
+
]);
|
|
829
|
+
return true;
|
|
830
|
+
} catch {}
|
|
831
|
+
}
|
|
832
|
+
if (from) {
|
|
833
|
+
from = await resolveGitRevision(cwd, from);
|
|
834
|
+
const depth = await countGitHistory(cwd, from);
|
|
835
|
+
if (depth > pageSize) return true;
|
|
836
|
+
pageSize -= depth - 1;
|
|
837
|
+
}
|
|
838
|
+
try {
|
|
839
|
+
await execGit(cwd, [
|
|
840
|
+
"-c",
|
|
841
|
+
"fetch.negotiationAlgorithm=skipping",
|
|
842
|
+
"fetch",
|
|
843
|
+
`--deepen=${pageSize}`,
|
|
844
|
+
"--update-shallow",
|
|
845
|
+
"--filter=blob:none",
|
|
846
|
+
...from && !await isGitAncestor(cwd, from, "HEAD") ? [
|
|
847
|
+
"origin",
|
|
848
|
+
from,
|
|
849
|
+
"HEAD"
|
|
850
|
+
] : []
|
|
851
|
+
]);
|
|
852
|
+
return true;
|
|
853
|
+
} catch {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
// src/git/revision/detectGitRelationship.ts
|
|
859
|
+
var GIT_REL_FLAGS = {
|
|
860
|
+
NONE: 0,
|
|
861
|
+
IS_ANCESTOR: 1,
|
|
862
|
+
IS_DESCENDANT: 2,
|
|
863
|
+
IS_EQUAL: 3
|
|
864
|
+
};
|
|
865
|
+
/**
|
|
866
|
+
* Determine the relationship between two git refs.
|
|
867
|
+
*
|
|
868
|
+
* Runs `git merge-base --is-ancestor` in both directions and returns a
|
|
869
|
+
* numeric bitmask using `GIT_REL_FLAGS`. A successful check (exit code 0)
|
|
870
|
+
* indicates an ancestor relationship; non-zero exit is treated as "not ancestor".
|
|
871
|
+
*
|
|
872
|
+
* @param cwd Repository working directory
|
|
873
|
+
* @param refA First ref (candidate ancestor)
|
|
874
|
+
* @param refB Second ref (candidate descendant)
|
|
875
|
+
* @returns Bitmask of type `GitRelFlags`
|
|
876
|
+
*/
|
|
877
|
+
async function detectGitRelationship(cwd, refA, refB) {
|
|
878
|
+
let flags = GIT_REL_FLAGS.NONE;
|
|
879
|
+
const [aIsAncestor, bIsAncestor] = await Promise.all([isGitAncestor(cwd, refA, refB), isGitAncestor(cwd, refB, refA)]);
|
|
880
|
+
if (aIsAncestor) flags |= GIT_REL_FLAGS.IS_ANCESTOR;
|
|
881
|
+
if (bIsAncestor) flags |= GIT_REL_FLAGS.IS_DESCENDANT;
|
|
882
|
+
return flags;
|
|
883
|
+
}
|
|
884
|
+
// src/git/history/mergeGitHistory.ts
|
|
885
|
+
/**
|
|
886
|
+
* Merge two newest-first commit lists into a single deduplicated newest-first list.
|
|
887
|
+
*
|
|
888
|
+
* Compares commits by hash, uses git relationship (ancestor/descendant) when needed,
|
|
889
|
+
* and falls back to committerDate for unrelated commits.
|
|
890
|
+
*
|
|
891
|
+
* @param cwd Repository working directory used for relationship checks
|
|
892
|
+
* @param a Commits from the first source (newest-first)
|
|
893
|
+
* @param b Commits from the second source (newest-first)
|
|
894
|
+
* @returns Merged commits in newest-first order with duplicates removed
|
|
895
|
+
*/
|
|
896
|
+
async function mergeGitHistory(cwd, a, b) {
|
|
897
|
+
const merged = [];
|
|
898
|
+
const a2 = [...a];
|
|
899
|
+
const b2 = [...b];
|
|
900
|
+
let i = a2.shift();
|
|
901
|
+
let j = b2.shift();
|
|
902
|
+
while (i && j) switch (i.hash === j.hash ? GIT_REL_FLAGS.IS_EQUAL : await detectGitRelationship(cwd, i.hash, j.hash)) {
|
|
903
|
+
case GIT_REL_FLAGS.IS_EQUAL:
|
|
904
|
+
merged.push(i);
|
|
905
|
+
i = a2.shift();
|
|
906
|
+
j = b2.shift();
|
|
907
|
+
break;
|
|
908
|
+
case GIT_REL_FLAGS.IS_ANCESTOR:
|
|
909
|
+
merged.push(j);
|
|
910
|
+
j = b2.shift();
|
|
911
|
+
break;
|
|
912
|
+
case GIT_REL_FLAGS.IS_DESCENDANT:
|
|
913
|
+
merged.push(i);
|
|
914
|
+
i = a2.shift();
|
|
915
|
+
break;
|
|
916
|
+
case GIT_REL_FLAGS.NONE: if (i.committerDate < j.committerDate) {
|
|
917
|
+
merged.push(j);
|
|
918
|
+
j = b2.shift();
|
|
919
|
+
} else {
|
|
920
|
+
merged.push(i);
|
|
921
|
+
i = a2.shift();
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (i) merged.push(i);
|
|
925
|
+
if (j) merged.push(j);
|
|
926
|
+
return merged.concat(a2).concat(b2);
|
|
927
|
+
}
|
|
928
|
+
// src/git/history/restoreFullGitHistory.ts
|
|
929
|
+
/**
|
|
930
|
+
* Convert a shallow clone into a full clone by fetching additional history.
|
|
931
|
+
*
|
|
932
|
+
* Runs `git fetch --unshallow`. Returns `true` when the operation succeeds
|
|
933
|
+
* and `false` on error.
|
|
934
|
+
*
|
|
935
|
+
* @param cwd Repository working directory
|
|
936
|
+
* @returns `true` when the operation succeeded, otherwise `false`
|
|
937
|
+
*/
|
|
938
|
+
function restoreFullGitHistory(cwd) {
|
|
939
|
+
return execGit(cwd, ["fetch", "--unshallow"]).then(() => true).catch(() => false);
|
|
940
|
+
}
|
|
941
|
+
// src/git/history/showGitHistory.ts
|
|
942
|
+
/**
|
|
943
|
+
* Yield commit SHAs from repository history in paginated order.
|
|
944
|
+
*
|
|
945
|
+
* Ensures commits are available via `expandGitHistory`, resolves `until` to a
|
|
946
|
+
* commit id, and pages from `from` toward `until`, yielding each commit SHA.
|
|
947
|
+
* If a git command fails the generator ends silently.
|
|
948
|
+
*
|
|
949
|
+
* @param cwd Repository working directory
|
|
950
|
+
* @param options Supports `from`, `until`, `pageSize`, and `filePath`
|
|
951
|
+
* @yields Commit SHA strings in paginated order
|
|
952
|
+
*/
|
|
953
|
+
async function* showGitHistory(cwd, options = {}) {
|
|
954
|
+
try {
|
|
955
|
+
const { filePath, pageSize = 50 } = options;
|
|
956
|
+
let from = options.from || "HEAD";
|
|
957
|
+
let until = options.until || void 0;
|
|
958
|
+
if (until) until = await resolveGitRevision(cwd, until);
|
|
959
|
+
while (true) {
|
|
960
|
+
await expandGitHistory(cwd, {
|
|
961
|
+
from,
|
|
962
|
+
until,
|
|
963
|
+
pageSize
|
|
964
|
+
});
|
|
965
|
+
const args = [
|
|
966
|
+
"rev-list",
|
|
967
|
+
`--max-count=${pageSize}`,
|
|
968
|
+
from
|
|
969
|
+
];
|
|
970
|
+
if (until) args.push(`^${until}`);
|
|
971
|
+
if (filePath) args.push("--", ...(Array.isArray(filePath) ? filePath : [filePath]).filter(Boolean));
|
|
972
|
+
const list = (await execGit(cwd, args)).trim().split("\n").filter(Boolean);
|
|
973
|
+
for (const item of list.slice(0, -1)) yield item;
|
|
974
|
+
const tail = list.at(-1);
|
|
975
|
+
if (!tail) return;
|
|
976
|
+
if (tail === from) {
|
|
977
|
+
yield tail;
|
|
978
|
+
from = `${tail}^`;
|
|
979
|
+
from = await resolveGitRevision(cwd, from);
|
|
980
|
+
} else from = tail;
|
|
981
|
+
}
|
|
982
|
+
} catch {}
|
|
983
|
+
}
|
|
984
|
+
// src/git/history/showParsedGitHistory.ts
|
|
985
|
+
/**
|
|
986
|
+
* Yield parsed commits sequentially from repository history.
|
|
987
|
+
*
|
|
988
|
+
* Fetches commits using `showGitHistory` and parses each commit with
|
|
989
|
+
* `getParsedGitCommit`. Yields successfully parsed `GitCommit` objects on demand
|
|
990
|
+
* and skips unparsable commits.
|
|
991
|
+
*
|
|
992
|
+
* @param cwd Repository working directory path
|
|
993
|
+
* @param options Filter and pagination options passed to `showGitHistory`
|
|
994
|
+
* @yields Parsed `GitCommit` objects in historical order
|
|
995
|
+
*/
|
|
996
|
+
async function* showParsedGitHistory(cwd, options) {
|
|
997
|
+
for await (const commit of showGitHistory(cwd, options)) try {
|
|
998
|
+
yield await getParsedGitCommit(cwd, commit);
|
|
999
|
+
} catch {}
|
|
1000
|
+
}
|
|
1001
|
+
// src/git/repository/getGitConfigValue.ts
|
|
1002
|
+
/**
|
|
1003
|
+
* Get a local git configuration value for `key` in the repository at `cwd`.
|
|
1004
|
+
*
|
|
1005
|
+
* Returns the config value when present; otherwise `undefined`.
|
|
1006
|
+
*
|
|
1007
|
+
* @param cwd Repository working directory
|
|
1008
|
+
* @param key Git config key to read
|
|
1009
|
+
* @returns The config value or `undefined` if not set
|
|
1010
|
+
*/
|
|
1011
|
+
async function getGitConfigValue(cwd, key) {
|
|
1012
|
+
try {
|
|
1013
|
+
const value = (await execGit(cwd, [
|
|
1014
|
+
"config",
|
|
1015
|
+
"--local",
|
|
1016
|
+
"--get",
|
|
1017
|
+
key
|
|
1018
|
+
])).trim();
|
|
1019
|
+
return value ? value : void 0;
|
|
1020
|
+
} catch {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
// src/git/repository/ensureGitUserConfig.ts
|
|
1025
|
+
/**
|
|
1026
|
+
* Ensure Git user configuration is set and return a cleanup handle.
|
|
1027
|
+
*
|
|
1028
|
+
* Checks the existing `user.name` and `user.email` configuration for the given
|
|
1029
|
+
* working directory. Updates the configuration if either value is missing and
|
|
1030
|
+
* returns an `AsyncDisposable` resource that restores the original state upon
|
|
1031
|
+
* disposal.
|
|
1032
|
+
*
|
|
1033
|
+
* @param cwd Working directory path in which to check and set Git configuration
|
|
1034
|
+
* @param user Git author details containing name and email
|
|
1035
|
+
* @returns Async disposable cleanup object if updated, or undefined if already set
|
|
1036
|
+
*/
|
|
1037
|
+
async function ensureGitUserConfig(cwd, user) {
|
|
1038
|
+
const initialName = await getGitConfigValue(cwd, "user.name");
|
|
1039
|
+
const initialEmail = await getGitConfigValue(cwd, "user.email");
|
|
1040
|
+
if (initialName && initialEmail) return;
|
|
1041
|
+
await execGit(cwd, [
|
|
1042
|
+
"config",
|
|
1043
|
+
"user.name",
|
|
1044
|
+
user.name
|
|
1045
|
+
]);
|
|
1046
|
+
await execGit(cwd, [
|
|
1047
|
+
"config",
|
|
1048
|
+
"user.email",
|
|
1049
|
+
user.email
|
|
1050
|
+
]);
|
|
1051
|
+
return { async [Symbol.asyncDispose]() {
|
|
1052
|
+
if (initialName) await execGit(cwd, [
|
|
1053
|
+
"config",
|
|
1054
|
+
"user.name",
|
|
1055
|
+
initialName
|
|
1056
|
+
]);
|
|
1057
|
+
else await execGit(cwd, [
|
|
1058
|
+
"config",
|
|
1059
|
+
"--unset",
|
|
1060
|
+
"user.name"
|
|
1061
|
+
]);
|
|
1062
|
+
if (initialEmail) await execGit(cwd, [
|
|
1063
|
+
"config",
|
|
1064
|
+
"user.email",
|
|
1065
|
+
initialEmail
|
|
1066
|
+
]);
|
|
1067
|
+
else await execGit(cwd, [
|
|
1068
|
+
"config",
|
|
1069
|
+
"--unset",
|
|
1070
|
+
"user.email"
|
|
1071
|
+
]);
|
|
1072
|
+
} };
|
|
1073
|
+
}
|
|
1074
|
+
// src/git/repository/getGitRemote.ts
|
|
1075
|
+
/**
|
|
1076
|
+
* Get the URL for the named remote (defaults to `origin`).
|
|
1077
|
+
*
|
|
1078
|
+
* @param cwd Repository working directory
|
|
1079
|
+
* @param remoteName Remote name (defaults to `'origin'`)
|
|
1080
|
+
* @returns Remote URL string or `null` when unavailable
|
|
1081
|
+
*/
|
|
1082
|
+
function getGitRemote(cwd, remoteName = "origin") {
|
|
1083
|
+
return execGit(cwd, [
|
|
1084
|
+
"remote",
|
|
1085
|
+
"get-url",
|
|
1086
|
+
remoteName
|
|
1087
|
+
]).then((stdout) => stdout.trim()).catch(() => null);
|
|
1088
|
+
}
|
|
1089
|
+
// src/git/repository/pushGitChanges.ts
|
|
1090
|
+
/**
|
|
1091
|
+
* Push a branch and optional tags to the `origin` remote using an atomic push.
|
|
1092
|
+
*
|
|
1093
|
+
* @param cwd Repository working directory
|
|
1094
|
+
* @param branch Branch name to push
|
|
1095
|
+
* @param additionalTags Optional list of tag names to push alongside the branch
|
|
1096
|
+
* @returns Promise that resolves when the push completes
|
|
1097
|
+
*/
|
|
1098
|
+
async function pushGitChanges(cwd, branch, ...additionalTags) {
|
|
1099
|
+
await execGit(cwd, [
|
|
1100
|
+
"push",
|
|
1101
|
+
"origin",
|
|
1102
|
+
...compact([branch, ...additionalTags]),
|
|
1103
|
+
"--atomic",
|
|
1104
|
+
"--no-verify"
|
|
1105
|
+
]);
|
|
1106
|
+
}
|
|
1107
|
+
// src/git/repository/resolveGitRepository.ts
|
|
1108
|
+
/**
|
|
1109
|
+
* Resolve Git repository host, owner, and project metadata from the `origin` remote URL.
|
|
1110
|
+
*
|
|
1111
|
+
* @param cwd Repository working directory
|
|
1112
|
+
* @returns Promise that resolves to a `GitRepository` object, or `null` when unavailable
|
|
1113
|
+
*/
|
|
1114
|
+
async function resolveGitRepository(cwd) {
|
|
1115
|
+
const origin = await getGitRemote(cwd);
|
|
1116
|
+
if (!origin) return null;
|
|
1117
|
+
const info = GitHost.fromUrl(origin);
|
|
1118
|
+
if (info && typeof info.type === "string" && typeof info.user === "string" && typeof info.project === "string") return {
|
|
1119
|
+
host: info.type,
|
|
1120
|
+
owner: info.user,
|
|
1121
|
+
repo: info.project,
|
|
1122
|
+
url: info.browse()
|
|
1123
|
+
};
|
|
1124
|
+
return null;
|
|
1125
|
+
}
|
|
1126
|
+
// src/git/revision/readGitFile.ts
|
|
1127
|
+
/**
|
|
1128
|
+
* Read a file's contents from a specific Git revision.
|
|
1129
|
+
*
|
|
1130
|
+
* Runs `git show <ref>:<filePath>` and returns the command output as a
|
|
1131
|
+
* string. If the file does not exist at the given revision or the Git
|
|
1132
|
+
* command fails for any reason, the function returns `null`.
|
|
1133
|
+
*
|
|
1134
|
+
* The returned string is the raw file contents as emitted by Git; callers
|
|
1135
|
+
* that need binary-safe handling should decode or process the bytes
|
|
1136
|
+
* accordingly. This function intentionally swallows Git errors and signals
|
|
1137
|
+
* absence via a `null` result rather than throwing.
|
|
1138
|
+
*
|
|
1139
|
+
* @param cwd Repository working directory
|
|
1140
|
+
* @param ref Commit-ish reference (commit SHA, tag, or branch) to read from
|
|
1141
|
+
* @param filePath Path to the file relative to the repository root
|
|
1142
|
+
* @returns File contents as a string, or `null` if the file is unavailable at the ref
|
|
1089
1143
|
*/
|
|
1090
|
-
|
|
1091
|
-
"
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
"%cI",
|
|
1095
|
-
"%s",
|
|
1096
|
-
"%b",
|
|
1097
|
-
""
|
|
1098
|
-
].join("");
|
|
1144
|
+
function readGitFile(cwd, ref, filePath) {
|
|
1145
|
+
return execGit(cwd, ["show", `${ref}:${filePath}`]).catch(() => null);
|
|
1146
|
+
}
|
|
1147
|
+
// src/git/tag/createGitTag.ts
|
|
1099
1148
|
/**
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
* The input is expected to contain seven fields separated by
|
|
1103
|
-
* `GIT_PRETTY_FIELD_SEPARATOR`:
|
|
1104
|
-
* 1. `hash` (commit hash)
|
|
1105
|
-
* 2. `parent` (space-separated parent hashes)
|
|
1106
|
-
* 3. `authorDate` (ISO 8601)
|
|
1107
|
-
* 4. `committerDate` (ISO 8601)
|
|
1108
|
-
* 5. `subject`
|
|
1109
|
-
* 6. `body`
|
|
1110
|
-
* 7. `files` (newline-separated list)
|
|
1149
|
+
* Create a git tag in the repository at `cwd`.
|
|
1111
1150
|
*
|
|
1112
|
-
*
|
|
1113
|
-
* dates to ISO strings, and splits `files` into an array. Missing optional
|
|
1114
|
-
* fields are normalized to sensible defaults.
|
|
1151
|
+
* Creates an annotated tag when `message` is provided.
|
|
1115
1152
|
*
|
|
1116
|
-
* @param
|
|
1117
|
-
* @
|
|
1118
|
-
* @
|
|
1153
|
+
* @param cwd Repository working directory
|
|
1154
|
+
* @param tag Tag name to create
|
|
1155
|
+
* @param message Optional tag message (creates an annotated tag when present)
|
|
1156
|
+
* @returns Promise that resolves when the tag is created
|
|
1119
1157
|
*/
|
|
1120
|
-
function
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
files = files?.trim();
|
|
1129
|
-
if (!hash || !authorDate || !committerDate || typeof subject !== "string") throw new Error(`The input "${colors.bold(raw)}" is not in the expected pretty format.`);
|
|
1130
|
-
return {
|
|
1131
|
-
hash,
|
|
1132
|
-
parent: parentHashes ? parentHashes.split(/\s+/) : [],
|
|
1133
|
-
authorDate: new Date(authorDate).toISOString(),
|
|
1134
|
-
committerDate: new Date(committerDate).toISOString(),
|
|
1135
|
-
subject,
|
|
1136
|
-
body: body ?? "",
|
|
1137
|
-
files: files ? files.split("\n") : []
|
|
1138
|
-
};
|
|
1158
|
+
async function createGitTag(cwd, tag, message) {
|
|
1159
|
+
await execGit(cwd, ["tag", ...message ? [
|
|
1160
|
+
"-a",
|
|
1161
|
+
tag,
|
|
1162
|
+
"-m",
|
|
1163
|
+
message,
|
|
1164
|
+
"--cleanup=whitespace"
|
|
1165
|
+
] : [tag]]);
|
|
1139
1166
|
}
|
|
1140
|
-
// src/git/
|
|
1141
|
-
var cache = new TTLCache();
|
|
1167
|
+
// src/git/tag/deleteGitTag.ts
|
|
1142
1168
|
/**
|
|
1143
|
-
*
|
|
1144
|
-
*
|
|
1145
|
-
* Fetches the raw git log entry for the specified `ref`, checking the local cache
|
|
1146
|
-
* prior to parsing missing entries.
|
|
1169
|
+
* Delete a local git tag in the repository at `cwd`.
|
|
1147
1170
|
*
|
|
1148
|
-
* @param cwd
|
|
1149
|
-
* @param
|
|
1150
|
-
* @
|
|
1151
|
-
* @returns Structured commit object
|
|
1171
|
+
* @param cwd Repository working directory
|
|
1172
|
+
* @param tag Tag name to delete
|
|
1173
|
+
* @returns `true` when deletion succeeded, otherwise `false`
|
|
1152
1174
|
*/
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
"
|
|
1156
|
-
"-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
`--pretty=format:${GIT_PRETTY_FORMAT}`
|
|
1160
|
-
]));
|
|
1161
|
-
const key = `${entry.hash}:${entry.parent}:${markers}`;
|
|
1162
|
-
const cached = cache.get(key);
|
|
1163
|
-
if (cached) return cached;
|
|
1164
|
-
const parsed = await parseGitCommit(entry, markers);
|
|
1165
|
-
cache.set(key, parsed);
|
|
1166
|
-
return parsed;
|
|
1175
|
+
function deleteGitTag(cwd, tag) {
|
|
1176
|
+
return execGit(cwd, [
|
|
1177
|
+
"tag",
|
|
1178
|
+
"-d",
|
|
1179
|
+
tag
|
|
1180
|
+
]).then(() => true).catch(() => false);
|
|
1167
1181
|
}
|
|
1168
|
-
// src/git/
|
|
1182
|
+
// src/git/tag/isGitTagPresent.ts
|
|
1169
1183
|
/**
|
|
1170
|
-
*
|
|
1184
|
+
* Determine whether a specific git tag exists locally in the repository.
|
|
1171
1185
|
*
|
|
1172
|
-
* @param cwd
|
|
1173
|
-
* @param
|
|
1174
|
-
* @returns
|
|
1186
|
+
* @param cwd Working directory for the git command
|
|
1187
|
+
* @param tag Name of the tag to evaluate
|
|
1188
|
+
* @returns True if the tag reference exists locally, false otherwise
|
|
1175
1189
|
*/
|
|
1176
|
-
function
|
|
1177
|
-
return
|
|
1190
|
+
function isGitTagPresent(cwd, tag) {
|
|
1191
|
+
return resolveGitRevision(cwd, `refs/tags/${tag}`).then(() => true).catch(() => false);
|
|
1178
1192
|
}
|
|
1179
|
-
// src/git/
|
|
1193
|
+
// src/git/tag/ensureGitTag.ts
|
|
1194
|
+
var MIN_HISTORY_DEPTH = 2;
|
|
1195
|
+
var ORIGIN_NOT_REPO = `fatal: 'origin' does not appear to be a git repository`;
|
|
1196
|
+
var REMOTE_REF_NOT_FOUND = `fatal: couldn't find remote ref`;
|
|
1180
1197
|
/**
|
|
1181
|
-
*
|
|
1198
|
+
* Ensure a tag exists locally, fetching it shallowly from `origin` if needed.
|
|
1182
1199
|
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1200
|
+
* Acquires a shallow-fetch lock, verifies local presence and history depth,
|
|
1201
|
+
* attempts a shallow fetch of `refs/tags/<tag>` when required, and removes a
|
|
1202
|
+
* local tag if the remote reports the tag is missing.
|
|
1203
|
+
*
|
|
1204
|
+
* @param cwd Working directory
|
|
1205
|
+
* @param tag Tag name (for example `v1.2.0`)
|
|
1206
|
+
* @returns `true` if the tag is present or was fetched; otherwise `false`
|
|
1207
|
+
*/
|
|
1208
|
+
function ensureGitTag(cwd, tag) {
|
|
1209
|
+
return withShallowLock(cwd, async () => {
|
|
1210
|
+
const tagRef = `refs/tags/${tag}`;
|
|
1211
|
+
if (await isGitTagPresent(cwd, tag) && await countGitHistory(cwd, tagRef) >= MIN_HISTORY_DEPTH) return true;
|
|
1212
|
+
try {
|
|
1213
|
+
await execGit(cwd, [
|
|
1214
|
+
"fetch",
|
|
1215
|
+
"origin",
|
|
1216
|
+
`${tagRef}:${tagRef}`,
|
|
1217
|
+
`--depth=${MIN_HISTORY_DEPTH}`,
|
|
1218
|
+
"--update-shallow",
|
|
1219
|
+
"--force"
|
|
1220
|
+
]);
|
|
1221
|
+
return true;
|
|
1222
|
+
} catch (err) {
|
|
1223
|
+
const errorMessage = err?.message;
|
|
1224
|
+
if (errorMessage?.includes(ORIGIN_NOT_REPO)) return await isGitTagPresent(cwd, tag);
|
|
1225
|
+
if (errorMessage?.includes(REMOTE_REF_NOT_FOUND)) {
|
|
1226
|
+
if (await isGitTagPresent(cwd, tag)) await deleteGitTag(cwd, tag);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return false;
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
// src/git/tag/generateGitTagName.ts
|
|
1233
|
+
function generateGitTagName(entry, name, version) {
|
|
1234
|
+
if (!version) return null;
|
|
1235
|
+
if (entry) return `v${version}`;
|
|
1236
|
+
if (!name) throw new Error("Package name is required to build a tag name.");
|
|
1237
|
+
return `${name}@${version}`;
|
|
1238
|
+
}
|
|
1239
|
+
// src/git/tag/getCurrentGitTag.ts
|
|
1240
|
+
/**
|
|
1241
|
+
* Get the tag name that exactly matches the current `HEAD`, if any.
|
|
1185
1242
|
*
|
|
1186
1243
|
* @param cwd Repository working directory
|
|
1187
|
-
* @
|
|
1188
|
-
* @returns Number of commits along the primary branch line up to `ref`
|
|
1244
|
+
* @returns Tag name or `null` when no exact tag matches HEAD
|
|
1189
1245
|
*/
|
|
1190
|
-
async function
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1246
|
+
async function getCurrentGitTag(cwd) {
|
|
1247
|
+
try {
|
|
1248
|
+
const tag = (await execGit(cwd, [
|
|
1249
|
+
"describe",
|
|
1250
|
+
"--tags",
|
|
1251
|
+
"--exact-match"
|
|
1252
|
+
])).trim();
|
|
1253
|
+
/* istanbul ignore next */
|
|
1254
|
+
return tag ? tag : null;
|
|
1255
|
+
} catch {
|
|
1256
|
+
return null;
|
|
1257
|
+
}
|
|
1198
1258
|
}
|
|
1199
|
-
// src/git/
|
|
1259
|
+
// src/git/tag/getGitTagMessage.ts
|
|
1200
1260
|
/**
|
|
1201
|
-
*
|
|
1261
|
+
* Get the message of an annotated git tag in the repository at `cwd`.
|
|
1202
1262
|
*
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1263
|
+
* @param cwd Repository working directory
|
|
1264
|
+
* @param tag Tag name to query
|
|
1265
|
+
* @returns The tag message string when found, otherwise `undefined`
|
|
1266
|
+
*/
|
|
1267
|
+
async function getGitTagMessage(cwd, tag) {
|
|
1268
|
+
try {
|
|
1269
|
+
const [objectType, message] = (await execGit(cwd, [
|
|
1270
|
+
"for-each-ref",
|
|
1271
|
+
"--format=%(objecttype)%00%(contents)",
|
|
1272
|
+
`refs/tags/${tag}`
|
|
1273
|
+
])).split("\0");
|
|
1274
|
+
if (objectType?.trim() !== "tag") return;
|
|
1275
|
+
return message?.trim() || void 0;
|
|
1276
|
+
} catch {
|
|
1277
|
+
/* istanbul ignore next */
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
// src/git/tag/getLatestGitTag.ts
|
|
1282
|
+
/**
|
|
1283
|
+
* Get the most recent tag reachable from `HEAD`.
|
|
1205
1284
|
*
|
|
1206
1285
|
* @param cwd Repository working directory
|
|
1207
|
-
* @returns
|
|
1286
|
+
* @returns Latest tag string or `null` when none is found
|
|
1208
1287
|
*/
|
|
1209
|
-
async function
|
|
1210
|
-
|
|
1288
|
+
async function getLatestGitTag(cwd) {
|
|
1289
|
+
try {
|
|
1290
|
+
const tag = (await execGit(cwd, [
|
|
1291
|
+
"describe",
|
|
1292
|
+
"--tags",
|
|
1293
|
+
"--abbrev=0"
|
|
1294
|
+
])).trim();
|
|
1295
|
+
/* istanbul ignore next */
|
|
1296
|
+
return tag ? tag : null;
|
|
1297
|
+
} catch {
|
|
1298
|
+
return null;
|
|
1299
|
+
}
|
|
1211
1300
|
}
|
|
1212
|
-
// src/git/
|
|
1213
|
-
var lockQueue = /* @__PURE__ */ new Map();
|
|
1214
|
-
var context = new AsyncLocalStorage();
|
|
1301
|
+
// src/git/tag/isGitTagConnected.ts
|
|
1215
1302
|
/**
|
|
1216
|
-
*
|
|
1303
|
+
* Determine whether a specific git tag commit is reachable from the current HEAD.
|
|
1217
1304
|
*
|
|
1218
|
-
*
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
1221
|
-
* a queued turn runs, downstream waiters are released early.
|
|
1305
|
+
* Uses `git merge-base --is-ancestor refs/tags/<tag>^{commit} HEAD` to verify
|
|
1306
|
+
* that the tag's commit is an ancestor of the current reference. Any non-zero
|
|
1307
|
+
* exit status or execution error is treated as "not reachable".
|
|
1222
1308
|
*
|
|
1223
|
-
* @param cwd
|
|
1224
|
-
* @param
|
|
1225
|
-
* @returns
|
|
1226
|
-
*/
|
|
1227
|
-
async function
|
|
1228
|
-
if (!await isGitShallowRepository(cwd)) return callback();
|
|
1229
|
-
const active = context.getStore();
|
|
1230
|
-
if (active?.has(cwd)) return callback();
|
|
1231
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
1232
|
-
const previous = lockQueue.get(cwd) ?? Promise.resolve();
|
|
1233
|
-
const queued = previous.then(() => promise);
|
|
1234
|
-
lockQueue.set(cwd, queued);
|
|
1235
|
-
await previous;
|
|
1236
|
-
if (!await isGitShallowRepository(cwd)) resolve();
|
|
1309
|
+
* @param cwd Working directory where the git command will run
|
|
1310
|
+
* @param tag Tag name to evaluate (for example, "v1.2.0")
|
|
1311
|
+
* @returns True if the tag commit is reachable from HEAD, false otherwise
|
|
1312
|
+
*/
|
|
1313
|
+
async function isGitTagConnected(cwd, tag) {
|
|
1237
1314
|
try {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1315
|
+
await execGit(cwd, [
|
|
1316
|
+
"merge-base",
|
|
1317
|
+
"--is-ancestor",
|
|
1318
|
+
`refs/tags/${tag}^{commit}`,
|
|
1319
|
+
"HEAD"
|
|
1320
|
+
]);
|
|
1321
|
+
return true;
|
|
1322
|
+
} catch {
|
|
1323
|
+
return false;
|
|
1242
1324
|
}
|
|
1243
1325
|
}
|
|
1244
|
-
// src/git/
|
|
1326
|
+
// src/git/tag/isGitTagPointed.ts
|
|
1245
1327
|
/**
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1248
|
-
* Runs `git merge-base --is-ancestor <ancestor> <descendant>` in the repository at `cwd`.
|
|
1249
|
-
* Resolves to `true` if `ancestor` is an ancestor, `false` if not.
|
|
1250
|
-
* Rethrows errors for invalid refs or other failures.
|
|
1328
|
+
* Check whether a given tag points to the provided commit.
|
|
1251
1329
|
*
|
|
1252
1330
|
* @param cwd Repository working directory
|
|
1253
|
-
* @param
|
|
1254
|
-
* @param
|
|
1255
|
-
* @returns
|
|
1256
|
-
* @throws If a ref is invalid or the Git command fails
|
|
1331
|
+
* @param tag Tag name to resolve
|
|
1332
|
+
* @param commit Commit hash to compare against
|
|
1333
|
+
* @returns `true` when the tag points at `commit`, otherwise `false`
|
|
1257
1334
|
*/
|
|
1258
|
-
function
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1335
|
+
async function isGitTagPointed(cwd, tag, commit) {
|
|
1336
|
+
try {
|
|
1337
|
+
await execGit(cwd, [
|
|
1338
|
+
"merge-base",
|
|
1339
|
+
"--is-ancestor",
|
|
1340
|
+
`refs/tags/${tag}^{commit}`,
|
|
1341
|
+
commit
|
|
1342
|
+
]);
|
|
1343
|
+
await execGit(cwd, [
|
|
1344
|
+
"merge-base",
|
|
1345
|
+
"--is-ancestor",
|
|
1346
|
+
commit,
|
|
1347
|
+
`refs/tags/${tag}^{commit}`
|
|
1348
|
+
]);
|
|
1349
|
+
return true;
|
|
1350
|
+
} catch {
|
|
1351
|
+
return false;
|
|
1352
|
+
}
|
|
1268
1353
|
}
|
|
1269
|
-
// src/
|
|
1354
|
+
// src/config/const.ts
|
|
1355
|
+
var ALL_FILES = "**/*";
|
|
1356
|
+
var DEFAULT_CHANGELOG_FILE = "CHANGELOG.md";
|
|
1357
|
+
var GIT_TRAILER_RELEASE_AGENT = "Release-Agent";
|
|
1358
|
+
var GIT_TRAILER_RELEASE_FILTER = "Release-Filter";
|
|
1270
1359
|
/**
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
* Runs `git rev-parse --verify <revision>^{commit}` under the hood. Peels annotated
|
|
1274
|
-
* tags, branches, short SHAs, and relative expressions down to a verified commit object.
|
|
1360
|
+
* 1. Primitive Building Blocks
|
|
1275
1361
|
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
* @returns A promise that resolves to the full, trimmed commit SHA-1 string
|
|
1362
|
+
* Base regular expression patterns for wildcards, alphanumeric strings with hyphens,
|
|
1363
|
+
* and standard non-negative integers.
|
|
1279
1364
|
*/
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
"--verify",
|
|
1284
|
-
`${revision}^{commit}`
|
|
1285
|
-
])).trim();
|
|
1286
|
-
}
|
|
1287
|
-
// src/git/history/expandGitHistory.ts
|
|
1365
|
+
var WILDCARD = "\\*";
|
|
1366
|
+
var ALPHANUM_DASH = "[0-9a-zA-Z-]+";
|
|
1367
|
+
var NUMERIC_IDENTIFIER = "0|[1-9]\\d*";
|
|
1288
1368
|
/**
|
|
1289
|
-
*
|
|
1369
|
+
* 2. Package Name & Prefix Constructs
|
|
1290
1370
|
*
|
|
1291
|
-
*
|
|
1292
|
-
* otherwise deepens by `pageSize`, accounting for existing depth when `from`
|
|
1293
|
-
* is supplied. Operation is serialized to avoid concurrent deepens.
|
|
1371
|
+
* Matches package name prefixes (unscoped or scoped) or a simple `v` prefix.
|
|
1294
1372
|
*
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
1297
|
-
* @returns true if history was deepened or already sufficient, otherwise false
|
|
1373
|
+
* Capture Groups:
|
|
1374
|
+
* - Group 1: Package name (e.g., `my-package` or `@scope/my-package`)
|
|
1298
1375
|
*/
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
return withShallowLock(cwd, async () => {
|
|
1302
|
-
const { until } = options;
|
|
1303
|
-
let { from } = options;
|
|
1304
|
-
let { pageSize = 50 } = options;
|
|
1305
|
-
if (until) {
|
|
1306
|
-
if (await isGitAncestor(cwd, until, "HEAD")) return true;
|
|
1307
|
-
const commitDate = (await execGit(cwd, [
|
|
1308
|
-
"show",
|
|
1309
|
-
"-s",
|
|
1310
|
-
"--format=%cI",
|
|
1311
|
-
`${until}^{commit}`
|
|
1312
|
-
])).trim();
|
|
1313
|
-
try {
|
|
1314
|
-
await execGit(cwd, [
|
|
1315
|
-
"-c",
|
|
1316
|
-
"fetch.negotiationAlgorithm=skipping",
|
|
1317
|
-
"fetch",
|
|
1318
|
-
`--shallow-since=${commitDate}`,
|
|
1319
|
-
"--update-shallow",
|
|
1320
|
-
"--filter=blob:none"
|
|
1321
|
-
]);
|
|
1322
|
-
return true;
|
|
1323
|
-
} catch {}
|
|
1324
|
-
}
|
|
1325
|
-
if (from) {
|
|
1326
|
-
from = await resolveGitRevision(cwd, from);
|
|
1327
|
-
const depth = await countGitHistory(cwd, from);
|
|
1328
|
-
if (depth > pageSize) return true;
|
|
1329
|
-
pageSize -= depth - 1;
|
|
1330
|
-
}
|
|
1331
|
-
try {
|
|
1332
|
-
await execGit(cwd, [
|
|
1333
|
-
"-c",
|
|
1334
|
-
"fetch.negotiationAlgorithm=skipping",
|
|
1335
|
-
"fetch",
|
|
1336
|
-
`--deepen=${pageSize}`,
|
|
1337
|
-
"--update-shallow",
|
|
1338
|
-
"--filter=blob:none",
|
|
1339
|
-
...from && !await isGitAncestor(cwd, from, "HEAD") ? [
|
|
1340
|
-
"origin",
|
|
1341
|
-
from,
|
|
1342
|
-
"HEAD"
|
|
1343
|
-
] : []
|
|
1344
|
-
]);
|
|
1345
|
-
return true;
|
|
1346
|
-
} catch {
|
|
1347
|
-
return false;
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
// src/git/revision/detectGitRelationship.ts
|
|
1352
|
-
var GIT_REL_FLAGS = {
|
|
1353
|
-
NONE: 0,
|
|
1354
|
-
IS_ANCESTOR: 1,
|
|
1355
|
-
IS_DESCENDANT: 2,
|
|
1356
|
-
IS_EQUAL: 3
|
|
1357
|
-
};
|
|
1376
|
+
var PKG_NAME_PART = `(?:${WILDCARD}|${ALPHANUM_DASH})`;
|
|
1377
|
+
var OPTIONAL_VERSION_PREFIX = `(?:v|${`(${PKG_NAME_PART}|@${PKG_NAME_PART}\\/${PKG_NAME_PART})`}@)`;
|
|
1358
1378
|
/**
|
|
1359
|
-
*
|
|
1379
|
+
* 3. Core SemVer Components
|
|
1360
1380
|
*
|
|
1361
|
-
*
|
|
1362
|
-
* numeric bitmask using `GIT_REL_FLAGS`. A successful check (exit code 0)
|
|
1363
|
-
* indicates an ancestor relationship; non-zero exit is treated as "not ancestor".
|
|
1381
|
+
* Matches standard `MAJOR.MINOR.PATCH` versions or wildcard variants (e.g., `1.0.0`, `*.*.*`).
|
|
1364
1382
|
*
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1383
|
+
* Capture Groups:
|
|
1384
|
+
* - Group 3: Major version
|
|
1385
|
+
* - Group 4: Minor version
|
|
1386
|
+
* - Group 5: Patch version
|
|
1369
1387
|
*/
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
if (bIsAncestor) flags |= GIT_REL_FLAGS.IS_DESCENDANT;
|
|
1375
|
-
return flags;
|
|
1376
|
-
}
|
|
1377
|
-
// src/git/history/mergeGitHistory.ts
|
|
1388
|
+
var CAPTURED_VERSION_DIGIT = `(${WILDCARD}|${NUMERIC_IDENTIFIER})`;
|
|
1389
|
+
var SEMVER_CORE = `${CAPTURED_VERSION_DIGIT}\\.${CAPTURED_VERSION_DIGIT}\\.${CAPTURED_VERSION_DIGIT}`;
|
|
1390
|
+
var PRERELEASE_IDENTIFIER = `(?:${WILDCARD}|${NUMERIC_IDENTIFIER}|(\\d*[a-zA-Z-][0-9a-zA-Z-]*))`;
|
|
1391
|
+
var FULL_SEMVER_PATTERN = `${OPTIONAL_VERSION_PREFIX}?${`(${SEMVER_CORE}${`(?:-(${PRERELEASE_IDENTIFIER}(?:\\.${PRERELEASE_IDENTIFIER})*))`}?${`(?:\\+(${ALPHANUM_DASH}(?:\\.${ALPHANUM_DASH})*))`}?)`}`;
|
|
1378
1392
|
/**
|
|
1379
|
-
*
|
|
1393
|
+
* Regular expression to match and capture Semantic Versioning (SemVer) strings,
|
|
1394
|
+
* including optional package prefixes (e.g., `@scope/pkg@`) and `v` prefixes.
|
|
1380
1395
|
*
|
|
1381
|
-
*
|
|
1382
|
-
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```ts
|
|
1398
|
+
* SEMVER_REGEX.test('1.0.0') // true
|
|
1399
|
+
* SEMVER_REGEX.test('v1.2.3-beta.1+sha.1234') // true
|
|
1400
|
+
* SEMVER_REGEX.test('@scope/package@1.0.0') // true
|
|
1401
|
+
* ```
|
|
1383
1402
|
*
|
|
1384
|
-
* @
|
|
1385
|
-
* @param a Commits from the first source (newest-first)
|
|
1386
|
-
* @param b Commits from the second source (newest-first)
|
|
1387
|
-
* @returns Merged commits in newest-first order with duplicates removed
|
|
1403
|
+
* @see {@link https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string SemVer Specification}
|
|
1388
1404
|
*/
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
if (
|
|
1419
|
-
|
|
1405
|
+
var SEMVER_REGEX = new RegExp(FULL_SEMVER_PATTERN);
|
|
1406
|
+
var DEV_NULL = new Writable({
|
|
1407
|
+
/* istanbul ignore next */
|
|
1408
|
+
write(_chunk, _encoding, callback) {
|
|
1409
|
+
callback();
|
|
1410
|
+
} });
|
|
1411
|
+
var RELEASE_HOOK_NAMES = [
|
|
1412
|
+
"configure",
|
|
1413
|
+
"discover",
|
|
1414
|
+
"analyze",
|
|
1415
|
+
"build",
|
|
1416
|
+
"write",
|
|
1417
|
+
"publish",
|
|
1418
|
+
"finalize"
|
|
1419
|
+
];
|
|
1420
|
+
// src/config/createPlugin.ts
|
|
1421
|
+
/**
|
|
1422
|
+
* Instantiate or invoke a plugin factory to produce a release plugin instance.
|
|
1423
|
+
*
|
|
1424
|
+
* Accepts class constructors, factory functions, tuple configurations, or
|
|
1425
|
+
* existing plugin objects. Instantiates classes using `new` or invokes factory
|
|
1426
|
+
* functions with options, validating that the resulting object satisfies the
|
|
1427
|
+
* plugin structure.
|
|
1428
|
+
*
|
|
1429
|
+
* @param plugin A plugin constructor, factory function, tuple, or object
|
|
1430
|
+
* @returns A validated release plugin instance or null
|
|
1431
|
+
*/
|
|
1432
|
+
async function createPlugin(plugin) {
|
|
1433
|
+
let options;
|
|
1434
|
+
if (Array.isArray(plugin)) [plugin, options] = plugin;
|
|
1435
|
+
if (typeof plugin === "function") plugin = isClass(plugin) ? new plugin(options) : await plugin(options);
|
|
1436
|
+
if (plugin != null && typeof plugin === "object" && Object.hasOwn(plugin, "name") && typeof plugin.name === "string") return plugin;
|
|
1437
|
+
return null;
|
|
1420
1438
|
}
|
|
1421
|
-
// src/
|
|
1439
|
+
// src/config/findReleaseRule.ts
|
|
1422
1440
|
/**
|
|
1423
|
-
*
|
|
1441
|
+
* Find the first release rule matching a release reference.
|
|
1424
1442
|
*
|
|
1425
|
-
*
|
|
1426
|
-
* and `false` on error.
|
|
1443
|
+
* Matches rules sequentially against the reference type and pattern.
|
|
1427
1444
|
*
|
|
1428
|
-
* @param
|
|
1429
|
-
* @
|
|
1445
|
+
* @param ref Release reference object
|
|
1446
|
+
* @param rules Array of release rules to match against
|
|
1447
|
+
* @returns The first matching release rule or `undefined`
|
|
1430
1448
|
*/
|
|
1431
|
-
function
|
|
1432
|
-
return
|
|
1449
|
+
function findReleaseRule(ref, rules) {
|
|
1450
|
+
return rules.find((rule) => {
|
|
1451
|
+
return (rule.type == null || rule.type === ref.type) && isMatch(ref.name, rule.pattern);
|
|
1452
|
+
});
|
|
1433
1453
|
}
|
|
1434
|
-
// src/
|
|
1454
|
+
// src/config/isSemVer.ts
|
|
1435
1455
|
/**
|
|
1436
|
-
*
|
|
1456
|
+
* Determine whether a value is a valid Semantic Versioning string.
|
|
1437
1457
|
*
|
|
1438
|
-
*
|
|
1439
|
-
*
|
|
1440
|
-
* If a git command fails the generator ends silently.
|
|
1458
|
+
* Rejects non-string values, leading or trailing whitespace, and leading `v`
|
|
1459
|
+
* prefixes. Validates the candidate string using `semver.parse`.
|
|
1441
1460
|
*
|
|
1442
|
-
* @param
|
|
1443
|
-
* @
|
|
1444
|
-
* @yields Commit SHA strings in paginated order
|
|
1461
|
+
* @param version Candidate value to evaluate for SemVer compliance
|
|
1462
|
+
* @returns `true` if `version` is a valid SemVer string, or `false` otherwise
|
|
1445
1463
|
*/
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
if (until) until = await resolveGitRevision(cwd, until);
|
|
1452
|
-
while (true) {
|
|
1453
|
-
await expandGitHistory(cwd, {
|
|
1454
|
-
from,
|
|
1455
|
-
until,
|
|
1456
|
-
pageSize
|
|
1457
|
-
});
|
|
1458
|
-
const args = [
|
|
1459
|
-
"rev-list",
|
|
1460
|
-
`--max-count=${pageSize}`,
|
|
1461
|
-
from
|
|
1462
|
-
];
|
|
1463
|
-
if (until) args.push(`^${until}`);
|
|
1464
|
-
if (filePath) args.push("--", ...(Array.isArray(filePath) ? filePath : [filePath]).filter(Boolean));
|
|
1465
|
-
const list = (await execGit(cwd, args)).trim().split("\n").filter(Boolean);
|
|
1466
|
-
for (const item of list.slice(0, -1)) yield item;
|
|
1467
|
-
const tail = list.at(-1);
|
|
1468
|
-
if (!tail) return;
|
|
1469
|
-
if (tail === from) {
|
|
1470
|
-
yield tail;
|
|
1471
|
-
from = `${tail}^`;
|
|
1472
|
-
from = await resolveGitRevision(cwd, from);
|
|
1473
|
-
} else from = tail;
|
|
1474
|
-
}
|
|
1475
|
-
} catch {}
|
|
1464
|
+
function isSemVer(version) {
|
|
1465
|
+
if (typeof version !== "string") return false;
|
|
1466
|
+
if (version !== version.trim()) return false;
|
|
1467
|
+
if (version.startsWith("v")) return false;
|
|
1468
|
+
return semver.parse(version) != null;
|
|
1476
1469
|
}
|
|
1477
|
-
// src/
|
|
1470
|
+
// src/config/isSemVerGitTag.ts
|
|
1478
1471
|
/**
|
|
1479
|
-
*
|
|
1472
|
+
* Determine whether a tag string is a valid SemVer-style Git tag.
|
|
1480
1473
|
*
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1483
|
-
* and skips unparsable commits.
|
|
1474
|
+
* Anchors `SEMVER_REGEX.source` for full-string matching and applies the
|
|
1475
|
+
* repository's Git-tag acceptance rules.
|
|
1484
1476
|
*
|
|
1485
|
-
* @param
|
|
1486
|
-
* @
|
|
1487
|
-
* @yields Parsed `GitCommit` objects in historical order
|
|
1477
|
+
* @param tag Tag string to validate
|
|
1478
|
+
* @returns `true` if `tag` is accepted as a SemVer-style Git tag; otherwise `false`
|
|
1488
1479
|
*/
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1480
|
+
function isSemVerGitTag(tag) {
|
|
1481
|
+
const match = new RegExp(`^${SEMVER_REGEX.source}$`).exec(tag);
|
|
1482
|
+
if (!match) return false;
|
|
1483
|
+
const isScopedPackage = Boolean(match[1]);
|
|
1484
|
+
const hasVersionPrefix = tag.startsWith("v");
|
|
1485
|
+
return isScopedPackage || hasVersionPrefix;
|
|
1493
1486
|
}
|
|
1494
|
-
// src/
|
|
1487
|
+
// src/config/sanitizePrereleaseLabel.ts
|
|
1495
1488
|
/**
|
|
1496
|
-
*
|
|
1489
|
+
* Sanitize a string into a safe, SemVer-compliant prerelease label.
|
|
1497
1490
|
*
|
|
1498
|
-
*
|
|
1491
|
+
* Replaces sequences of non-alphanumeric characters with a single hyphen and
|
|
1492
|
+
* removes leading or trailing hyphens.
|
|
1499
1493
|
*
|
|
1500
|
-
* @param
|
|
1501
|
-
* @
|
|
1502
|
-
* @returns The config value or `undefined` if not set
|
|
1494
|
+
* @param label Raw string to sanitize
|
|
1495
|
+
* @returns Safe SemVer prerelease label
|
|
1503
1496
|
*/
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
const value = (await execGit(cwd, [
|
|
1507
|
-
"config",
|
|
1508
|
-
"--local",
|
|
1509
|
-
"--get",
|
|
1510
|
-
key
|
|
1511
|
-
])).trim();
|
|
1512
|
-
return value ? value : void 0;
|
|
1513
|
-
} catch {
|
|
1514
|
-
return;
|
|
1515
|
-
}
|
|
1497
|
+
function sanitizePrereleaseLabel(label) {
|
|
1498
|
+
return label.replace(/[^a-zA-Z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
1516
1499
|
}
|
|
1517
|
-
// src/
|
|
1500
|
+
// src/config/resolveReleaseChannel.ts
|
|
1518
1501
|
/**
|
|
1519
|
-
*
|
|
1502
|
+
* Resolve the release channel for a release context.
|
|
1520
1503
|
*
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1524
|
-
* disposal.
|
|
1504
|
+
* Uses the release rule when `channel` is `boolean` or omitted. Sanitizes the
|
|
1505
|
+
* reference name when enabling default channel resolution and interpolates
|
|
1506
|
+
* `templateParams` into the result.
|
|
1525
1507
|
*
|
|
1526
|
-
* @param
|
|
1527
|
-
* @
|
|
1528
|
-
* @returns Async disposable cleanup object if updated, or undefined if already set
|
|
1508
|
+
* @param options Options for resolving the release channel
|
|
1509
|
+
* @returns Resolved release channel string or `undefined`
|
|
1529
1510
|
*/
|
|
1530
|
-
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
await execGit(cwd, [
|
|
1540
|
-
"config",
|
|
1541
|
-
"user.email",
|
|
1542
|
-
user.email
|
|
1543
|
-
]);
|
|
1544
|
-
return { async [Symbol.asyncDispose]() {
|
|
1545
|
-
if (initialName) await execGit(cwd, [
|
|
1546
|
-
"config",
|
|
1547
|
-
"user.name",
|
|
1548
|
-
initialName
|
|
1549
|
-
]);
|
|
1550
|
-
else await execGit(cwd, [
|
|
1551
|
-
"config",
|
|
1552
|
-
"--unset",
|
|
1553
|
-
"user.name"
|
|
1554
|
-
]);
|
|
1555
|
-
if (initialEmail) await execGit(cwd, [
|
|
1556
|
-
"config",
|
|
1557
|
-
"user.email",
|
|
1558
|
-
initialEmail
|
|
1559
|
-
]);
|
|
1560
|
-
else await execGit(cwd, [
|
|
1561
|
-
"config",
|
|
1562
|
-
"--unset",
|
|
1563
|
-
"user.email"
|
|
1564
|
-
]);
|
|
1565
|
-
} };
|
|
1511
|
+
function resolveReleaseChannel(options) {
|
|
1512
|
+
const { ref, rule, templateParams } = options;
|
|
1513
|
+
let { channel } = options;
|
|
1514
|
+
let resolved;
|
|
1515
|
+
if (channel === true || channel == null) channel = rule?.releaseChannel ?? channel;
|
|
1516
|
+
if (typeof channel === "string") resolved = channel;
|
|
1517
|
+
else if (channel) resolved = sanitizePrereleaseLabel(ref.name);
|
|
1518
|
+
if (typeof resolved === "string") resolved = interpolate(resolved, templateParams);
|
|
1519
|
+
return resolved;
|
|
1566
1520
|
}
|
|
1567
|
-
// src/
|
|
1521
|
+
// src/config/resolveVersionQualifier.ts
|
|
1568
1522
|
/**
|
|
1569
|
-
*
|
|
1523
|
+
* Resolve the version qualifier for a release context.
|
|
1570
1524
|
*
|
|
1571
|
-
*
|
|
1572
|
-
*
|
|
1573
|
-
*
|
|
1525
|
+
* Uses the release rule when `qualifier` is `boolean` or omitted. Interpolates
|
|
1526
|
+
* `templateParams` into `qualifier` and validates that the result forms a
|
|
1527
|
+
* valid SemVer prerelease identifier.
|
|
1528
|
+
*
|
|
1529
|
+
* @param options Options for resolving the version qualifier
|
|
1530
|
+
* @returns Resolved version qualifier string or `undefined`
|
|
1531
|
+
* @throws If the resolved string is not a valid SemVer prerelease identifier
|
|
1574
1532
|
*/
|
|
1575
|
-
function
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1533
|
+
function resolveVersionQualifier(options) {
|
|
1534
|
+
const { rule, templateParams } = options;
|
|
1535
|
+
let { qualifier } = options;
|
|
1536
|
+
let resolved;
|
|
1537
|
+
if (qualifier === true || qualifier == null) qualifier = rule?.versionQualifier ?? qualifier;
|
|
1538
|
+
if (typeof qualifier === "string") resolved = qualifier;
|
|
1539
|
+
else if (qualifier) resolved = "";
|
|
1540
|
+
if (typeof resolved === "string") resolved = interpolate(resolved, templateParams);
|
|
1541
|
+
if (resolved && !isSemVer(`1.0.0-${resolved}.1`)) throw new Error(`The resolved version qualifier "${resolved}" is not a valid SemVer prerelease identifier.`);
|
|
1542
|
+
return resolved;
|
|
1581
1543
|
}
|
|
1582
|
-
// src/
|
|
1544
|
+
// src/workflow/committing/isReleaseCommit.ts
|
|
1583
1545
|
/**
|
|
1584
|
-
*
|
|
1546
|
+
* Determine whether a commit represents a release or matches a release marker.
|
|
1585
1547
|
*
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1548
|
+
* Resolves string commit identifiers to parsed commit objects, checks if any
|
|
1549
|
+
* associated trailer matches the `marker` predicate, and falls back to
|
|
1550
|
+
* verifying exact tag matches for the `commit` hash.
|
|
1551
|
+
*
|
|
1552
|
+
* @param cwd Working directory path for Git commands
|
|
1553
|
+
* @param commit Commit object, hash string, or nullish value
|
|
1554
|
+
* @param marker Trailer key string or predicate function to evaluate
|
|
1555
|
+
* @returns `true` if the commit is a release commit, otherwise `false`
|
|
1590
1556
|
*/
|
|
1591
|
-
async function
|
|
1592
|
-
|
|
1593
|
-
"
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1557
|
+
async function isReleaseCommit(cwd, commit, marker = GIT_TRAILER_RELEASE_AGENT) {
|
|
1558
|
+
if (typeof commit === "string") try {
|
|
1559
|
+
commit = await getParsedGitCommit(cwd, commit, typeof marker === "string" ? [marker] : []);
|
|
1560
|
+
} catch {
|
|
1561
|
+
commit = null;
|
|
1562
|
+
}
|
|
1563
|
+
if (!commit) return false;
|
|
1564
|
+
const predicate = typeof marker === "string" ? (trailer) => trailer.key === marker && !!trailer.value : marker;
|
|
1565
|
+
if (commit.trailers.some(predicate)) return true;
|
|
1566
|
+
return execGit(cwd, [
|
|
1567
|
+
"describe",
|
|
1568
|
+
"--tags",
|
|
1569
|
+
"--exact-match",
|
|
1570
|
+
commit.hash
|
|
1571
|
+
]).then(() => true).catch(() => false);
|
|
1599
1572
|
}
|
|
1600
|
-
// src/
|
|
1573
|
+
// src/workflow/analysis/collectUnreleased.ts
|
|
1601
1574
|
/**
|
|
1602
|
-
*
|
|
1575
|
+
* Collect unreleased commits from repository history.
|
|
1603
1576
|
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1577
|
+
* Walks parsed commit history in order and gathers every commit preceding the
|
|
1578
|
+
* first release commit. Exposes the release commit that ended the walk so
|
|
1579
|
+
* callers can inspect it, for example to read its release filter trailer.
|
|
1580
|
+
*
|
|
1581
|
+
* @param cwd Path to the working directory for git commands
|
|
1582
|
+
* @param options Options for configuring Git history retrieval
|
|
1583
|
+
* @returns The unreleased commits and the release commit that stopped the walk
|
|
1606
1584
|
*/
|
|
1607
|
-
async function
|
|
1608
|
-
const
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1585
|
+
async function collectUnreleased(cwd, options = {}) {
|
|
1586
|
+
const history = [];
|
|
1587
|
+
for await (const commit of showParsedGitHistory(cwd, options)) {
|
|
1588
|
+
if (await isReleaseCommit(cwd, commit, options.marker)) return {
|
|
1589
|
+
history,
|
|
1590
|
+
stop: commit
|
|
1591
|
+
};
|
|
1592
|
+
history.push(commit);
|
|
1593
|
+
}
|
|
1594
|
+
return {
|
|
1595
|
+
history,
|
|
1596
|
+
stop: null
|
|
1616
1597
|
};
|
|
1617
|
-
return null;
|
|
1618
1598
|
}
|
|
1619
|
-
// src/
|
|
1599
|
+
// src/workflow/versioning/extractVersionQualifier.ts
|
|
1620
1600
|
/**
|
|
1621
|
-
*
|
|
1622
|
-
*
|
|
1623
|
-
* Runs `git show <ref>:<filePath>` and returns the command output as a
|
|
1624
|
-
* string. If the file does not exist at the given revision or the Git
|
|
1625
|
-
* command fails for any reason, the function returns `null`.
|
|
1601
|
+
* Extract the version qualifier string from a parsed `SemVer` instance.
|
|
1626
1602
|
*
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
1629
|
-
* accordingly. This function intentionally swallows Git errors and signals
|
|
1630
|
-
* absence via a `null` result rather than throwing.
|
|
1603
|
+
* Strips the trailing numeric counter from the `prerelease` components if
|
|
1604
|
+
* present. Joins any remaining prerelease identifiers with a dot separator.
|
|
1631
1605
|
*
|
|
1632
|
-
* @param
|
|
1633
|
-
* @
|
|
1634
|
-
* @param filePath Path to the file relative to the repository root
|
|
1635
|
-
* @returns File contents as a string, or `null` if the file is unavailable at the ref
|
|
1606
|
+
* @param version Parsed `SemVer` instance or nullish value to inspect
|
|
1607
|
+
* @returns The extracted qualifier string or `undefined` if no prerelease exists
|
|
1636
1608
|
*/
|
|
1637
|
-
function
|
|
1638
|
-
|
|
1609
|
+
function extractVersionQualifier(version) {
|
|
1610
|
+
if (version != null && version.prerelease.length > 0) {
|
|
1611
|
+
const prerelease = [...version.prerelease];
|
|
1612
|
+
if (typeof prerelease.at(-1) === "number") prerelease.pop();
|
|
1613
|
+
return prerelease.join(".");
|
|
1614
|
+
} else return;
|
|
1639
1615
|
}
|
|
1640
|
-
// src/
|
|
1616
|
+
// src/workflow/versioning/bumpVersion.ts
|
|
1641
1617
|
/**
|
|
1642
|
-
*
|
|
1618
|
+
* Bump a semantic version string based on release and transition rules.
|
|
1643
1619
|
*
|
|
1644
|
-
*
|
|
1620
|
+
* Parses the target version and determines the next version string using the
|
|
1621
|
+
* specified release type, prerelease identifier, and transition mode. Adjusts
|
|
1622
|
+
* prerelease types when continuing an existing qualifier and returns `null` when
|
|
1623
|
+
* `options.release` is omitted or if transition conditions fail.
|
|
1645
1624
|
*
|
|
1646
|
-
* @param
|
|
1647
|
-
* @
|
|
1648
|
-
* @
|
|
1649
|
-
* @returns Promise that resolves when the tag is created
|
|
1625
|
+
* @param options Version bump configuration including release type, identifier, and transition rules
|
|
1626
|
+
* @returns The bumped semantic version string, or `null` if no bump occurs
|
|
1627
|
+
* @throws If `options.version` is not a valid semantic version
|
|
1650
1628
|
*/
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
"
|
|
1658
|
-
|
|
1629
|
+
function bumpVersion(options) {
|
|
1630
|
+
const { version } = options;
|
|
1631
|
+
const parsed = semver.parse(version);
|
|
1632
|
+
if (!parsed) throw new Error(`Version "${version}" is not a valid semantic version.`);
|
|
1633
|
+
if (!options.release) return null;
|
|
1634
|
+
if (parsed.prerelease.length > 0) {
|
|
1635
|
+
if (options.transition === "advance" && options.identifier == null) return null;
|
|
1636
|
+
} else if (options.transition === "continue") return null;
|
|
1637
|
+
let release = options.release;
|
|
1638
|
+
let identifier;
|
|
1639
|
+
if (typeof options.identifier === "string") {
|
|
1640
|
+
release = `pre${options.release}`;
|
|
1641
|
+
identifier = options.identifier;
|
|
1642
|
+
const parsedIdentifier = extractVersionQualifier(parsed);
|
|
1643
|
+
const transition = options.transition ?? (parsedIdentifier && identifier === "" ? "advance" : "continue");
|
|
1644
|
+
if (typeof parsedIdentifier === "string" && transition === "continue") {
|
|
1645
|
+
if (release === "premajor" && parsed.minor === 0 && parsed.patch === 0 || release === "preminor" && parsed.patch === 0 || release === "prepatch") release = "prerelease";
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return semver.inc(parsed, release, { loose: false }, identifier, "0");
|
|
1659
1649
|
}
|
|
1660
|
-
// src/
|
|
1650
|
+
// src/workflow/versioning/determineReleaseType.ts
|
|
1661
1651
|
/**
|
|
1662
|
-
*
|
|
1652
|
+
* Determine the release type for a single commit.
|
|
1663
1653
|
*
|
|
1664
|
-
*
|
|
1665
|
-
*
|
|
1666
|
-
*
|
|
1654
|
+
* Returns `'minor'` for a commit marked as a breaking change while the
|
|
1655
|
+
* supplied `version` is zero-major (`0.y.z`), and `'major'` otherwise, since
|
|
1656
|
+
* SemVer treats `0.y.z` as initial development where breaking changes do not
|
|
1657
|
+
* require a new major version. Otherwise, routes the commit through the
|
|
1658
|
+
* custom `classifier` and ensures the resolved value is a valid semantic
|
|
1659
|
+
* versioning release type.
|
|
1660
|
+
*
|
|
1661
|
+
* @param classifier Function mapping commits to release types
|
|
1662
|
+
* @param commit Parsed commit to evaluate
|
|
1663
|
+
* @param version Current package version used to adjust zero-major breaking releases
|
|
1664
|
+
* @returns `ReleaseType` string, or `null` when no matching rule applies
|
|
1667
1665
|
*/
|
|
1668
|
-
function
|
|
1669
|
-
return
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1666
|
+
function determineReleaseType(classifier, commit, version) {
|
|
1667
|
+
if (commit.notes.length > 0) return semver.parse(version)?.major === 0 ? "minor" : "major";
|
|
1668
|
+
const type = classifier(commit);
|
|
1669
|
+
switch (type) {
|
|
1670
|
+
case "major":
|
|
1671
|
+
case "minor":
|
|
1672
|
+
case "patch": return type;
|
|
1673
|
+
}
|
|
1674
|
+
return null;
|
|
1674
1675
|
}
|
|
1675
|
-
// src/
|
|
1676
|
+
// src/workflow/versioning/pickPriorityReleaseType.ts
|
|
1676
1677
|
/**
|
|
1677
|
-
* Determine
|
|
1678
|
+
* Determine the highest-priority release type between two candidates.
|
|
1678
1679
|
*
|
|
1679
|
-
*
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1680
|
+
* Compares release types by precedence order: `major` > `minor` > `patch`.
|
|
1681
|
+
* Returns the higher-precedence type, or `null` if neither applies.
|
|
1682
|
+
*
|
|
1683
|
+
* @param curr Current accumulated release type
|
|
1684
|
+
* @param next Candidate release type to consider
|
|
1685
|
+
* @returns Highest-precedence `ReleaseType`, or `null` if neither applies
|
|
1682
1686
|
*/
|
|
1683
|
-
function
|
|
1684
|
-
|
|
1687
|
+
function pickPriorityReleaseType(curr, next) {
|
|
1688
|
+
for (const type of [
|
|
1689
|
+
"major",
|
|
1690
|
+
"minor",
|
|
1691
|
+
"patch"
|
|
1692
|
+
]) if (curr === type || next === type) return type;
|
|
1693
|
+
return null;
|
|
1685
1694
|
}
|
|
1686
|
-
// src/
|
|
1687
|
-
var MIN_HISTORY_DEPTH = 2;
|
|
1688
|
-
var ORIGIN_NOT_REPO = `fatal: 'origin' does not appear to be a git repository`;
|
|
1689
|
-
var REMOTE_REF_NOT_FOUND = `fatal: couldn't find remote ref`;
|
|
1695
|
+
// src/workflow/versioning/deriveReleaseType.ts
|
|
1690
1696
|
/**
|
|
1691
|
-
*
|
|
1697
|
+
* Derive the combined release type from a release plan.
|
|
1692
1698
|
*
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1695
|
-
*
|
|
1699
|
+
* Processes the plan's commits sequentially, accumulating the
|
|
1700
|
+
* highest-precedence release type found by evaluating each individual commit
|
|
1701
|
+
* and comparing it against the current maximum via `pickPriorityReleaseType`.
|
|
1702
|
+
* Breaking commits resolve to `minor` while the plan's package version is
|
|
1703
|
+
* zero-major (`0.y.z`).
|
|
1696
1704
|
*
|
|
1697
|
-
* @param
|
|
1698
|
-
* @param
|
|
1699
|
-
* @returns `
|
|
1705
|
+
* @param classifier Function mapping commits to release types
|
|
1706
|
+
* @param plan Release plan carrying the commit history and package version
|
|
1707
|
+
* @returns `ReleaseType` string, or `null` when no matching rule applies
|
|
1700
1708
|
*/
|
|
1701
|
-
function
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
try {
|
|
1706
|
-
await execGit(cwd, [
|
|
1707
|
-
"fetch",
|
|
1708
|
-
"origin",
|
|
1709
|
-
`${tagRef}:${tagRef}`,
|
|
1710
|
-
`--depth=${MIN_HISTORY_DEPTH}`,
|
|
1711
|
-
"--update-shallow",
|
|
1712
|
-
"--force"
|
|
1713
|
-
]);
|
|
1714
|
-
return true;
|
|
1715
|
-
} catch (err) {
|
|
1716
|
-
const errorMessage = err?.message;
|
|
1717
|
-
if (errorMessage?.includes(ORIGIN_NOT_REPO)) return await isGitTagPresent(cwd, tag);
|
|
1718
|
-
if (errorMessage?.includes(REMOTE_REF_NOT_FOUND)) {
|
|
1719
|
-
if (await isGitTagPresent(cwd, tag)) await deleteGitTag(cwd, tag);
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
return false;
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
// src/git/tag/generateGitTagName.ts
|
|
1726
|
-
function generateGitTagName(entry, name, version) {
|
|
1727
|
-
if (!version) return null;
|
|
1728
|
-
if (entry) return `v${version}`;
|
|
1729
|
-
if (!name) throw new Error("Package name is required to build a tag name.");
|
|
1730
|
-
return `${name}@${version}`;
|
|
1709
|
+
function deriveReleaseType(classifier, plan) {
|
|
1710
|
+
let releaseType = null;
|
|
1711
|
+
for (const commit of plan.history) releaseType = pickPriorityReleaseType(releaseType, determineReleaseType(classifier, commit, plan.package.version));
|
|
1712
|
+
return releaseType;
|
|
1731
1713
|
}
|
|
1732
|
-
// src/
|
|
1714
|
+
// src/workflow/versioning/isSameReleaseCycle.ts
|
|
1733
1715
|
/**
|
|
1734
|
-
*
|
|
1716
|
+
* Determine whether two semantic version strings or objects belong to the same release cycle.
|
|
1735
1717
|
*
|
|
1736
|
-
*
|
|
1737
|
-
*
|
|
1718
|
+
* Compares the main version components of `currentVersion` and `nextVersion` to
|
|
1719
|
+
* determine equality. Treats a transition from a non-zero `0.x` version to
|
|
1720
|
+
* `1.0.0` as part of the same release cycle. Returns `false` if either input
|
|
1721
|
+
* cannot be parsed.
|
|
1722
|
+
*
|
|
1723
|
+
* @param currentVersion Starting version string, `semver.SemVer` instance, or nullish value
|
|
1724
|
+
* @param nextVersion Target version string, `semver.SemVer` instance, or nullish value
|
|
1725
|
+
* @returns `true` if both versions belong to the same release cycle, `false` otherwise
|
|
1738
1726
|
*/
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
])).trim();
|
|
1746
|
-
/* istanbul ignore next */
|
|
1747
|
-
return tag ? tag : null;
|
|
1748
|
-
} catch {
|
|
1749
|
-
return null;
|
|
1750
|
-
}
|
|
1727
|
+
function isSameReleaseCycle(currentVersion, nextVersion) {
|
|
1728
|
+
const current = semver.parse(currentVersion);
|
|
1729
|
+
const next = semver.parse(nextVersion);
|
|
1730
|
+
if (!current || !next) return false;
|
|
1731
|
+
if (current.compareMain(next) === 0) return true;
|
|
1732
|
+
return current.major === 0 && (current.minor > 0 || current.patch > 0) && next.major === 1 && next.minor === 0 && next.patch === 0;
|
|
1751
1733
|
}
|
|
1752
|
-
// src/
|
|
1734
|
+
// src/workflow/versioning/isStableVersion.ts
|
|
1753
1735
|
/**
|
|
1754
|
-
*
|
|
1736
|
+
* Determine whether a version string represents a stable SemVer release.
|
|
1755
1737
|
*
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1738
|
+
* A version is considered stable when:
|
|
1739
|
+
* - It is a valid SemVer string.
|
|
1740
|
+
* - Its major version is greater than 0 (not 0.x.x).
|
|
1741
|
+
* - It contains no prerelease identifiers (no `-alpha`, `-beta`, `-rc`, etc.).
|
|
1742
|
+
*
|
|
1743
|
+
* Build metadata (the `+` suffix) does not affect stability.
|
|
1744
|
+
*
|
|
1745
|
+
* @param version Semantic version string to check
|
|
1746
|
+
* @returns `true` if `version` is a stable SemVer; otherwise `false`
|
|
1747
|
+
* @throws If `version` is not a valid SemVer string
|
|
1759
1748
|
*/
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1749
|
+
function isStableVersion(version) {
|
|
1750
|
+
const parsed = semver.parse(version);
|
|
1751
|
+
if (!parsed) throw new Error(`The version "${colors.bold(version)}" is not a valid SemVer.`);
|
|
1752
|
+
return parsed.major > 0 && parsed.prerelease.length === 0;
|
|
1753
|
+
}
|
|
1754
|
+
// src/workflow/analysis/isCommitForPackage.ts
|
|
1755
|
+
/**
|
|
1756
|
+
* Test whether a commit modifies files in a package.
|
|
1757
|
+
*
|
|
1758
|
+
* @param pkg Package with an explicit file pattern or base directory
|
|
1759
|
+
* @param commit Parsed commit containing changed file paths
|
|
1760
|
+
* @returns `true` if any changed file matches the package pattern
|
|
1761
|
+
*/
|
|
1762
|
+
function isCommitForPackage(pkg, commit) {
|
|
1763
|
+
return commit.files.some((file) => {
|
|
1764
|
+
const { location } = pkg;
|
|
1765
|
+
return isMatch(file, pkg.files || path.join(location, "**/*"));
|
|
1766
|
+
});
|
|
1773
1767
|
}
|
|
1774
|
-
// src/
|
|
1768
|
+
// src/workflow/analysis/deriveChangeReleases.ts
|
|
1775
1769
|
/**
|
|
1776
|
-
*
|
|
1770
|
+
* Analyze commit history to update release plans for packages.
|
|
1777
1771
|
*
|
|
1778
|
-
*
|
|
1779
|
-
*
|
|
1772
|
+
* Maps commit `history` across package release `plans` to associate matching
|
|
1773
|
+
* commits with their target packages. Calculates the release type for each
|
|
1774
|
+
* plan based on classified `history` and applies overrides according to the
|
|
1775
|
+
* provided `hint` or existing release priority. Downgrades breaking-change
|
|
1776
|
+
* `major` release types to `minor` while the package version is zero-major
|
|
1777
|
+
* (`0.y.z`).
|
|
1778
|
+
*
|
|
1779
|
+
* @param hint Release type override hint or default preference
|
|
1780
|
+
* @param classifier Classifier function to determine commit release types
|
|
1781
|
+
* @param plans List of release plans to analyze and update
|
|
1782
|
+
* @param history Stream or iterable of git commits to process
|
|
1783
|
+
* @returns Updated release plans with updated commit histories and release types
|
|
1780
1784
|
*/
|
|
1781
|
-
async function
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1785
|
+
async function deriveChangeReleases(hint, classifier, plans, history) {
|
|
1786
|
+
for await (const commit of history) plans = plans.map((plan) => {
|
|
1787
|
+
if (!isCommitForPackage(plan.package, commit)) return plan;
|
|
1788
|
+
return {
|
|
1789
|
+
...plan,
|
|
1790
|
+
history: plan.history.concat(commit)
|
|
1791
|
+
};
|
|
1792
|
+
});
|
|
1793
|
+
return plans.map((plan) => {
|
|
1794
|
+
let { release } = plan;
|
|
1795
|
+
let releaseType = deriveReleaseType(classifier, plan);
|
|
1796
|
+
if (releaseType) switch (hint) {
|
|
1797
|
+
case "major":
|
|
1798
|
+
case "minor":
|
|
1799
|
+
case "patch":
|
|
1800
|
+
releaseType = hint;
|
|
1801
|
+
break;
|
|
1802
|
+
default: releaseType = pickPriorityReleaseType(release?.type, releaseType);
|
|
1803
|
+
}
|
|
1804
|
+
if (releaseType) release = {
|
|
1805
|
+
...release,
|
|
1806
|
+
type: releaseType
|
|
1807
|
+
};
|
|
1808
|
+
return {
|
|
1809
|
+
...plan,
|
|
1810
|
+
release
|
|
1811
|
+
};
|
|
1812
|
+
});
|
|
1793
1813
|
}
|
|
1794
|
-
// src/
|
|
1814
|
+
// src/workflow/analysis/deriveTransitionReleases.ts
|
|
1795
1815
|
/**
|
|
1796
|
-
*
|
|
1816
|
+
* Derive transition release types for release plans based on version qualifiers.
|
|
1797
1817
|
*
|
|
1798
|
-
*
|
|
1799
|
-
*
|
|
1800
|
-
*
|
|
1818
|
+
* Evaluates unreleased `plans` by parsing package `semver` strings and checking
|
|
1819
|
+
* prerelease tags. Compares parsed version qualifiers against
|
|
1820
|
+
* `versionQualifier` and assigns `major`, `minor`, or `patch` release types
|
|
1821
|
+
* according to `hint`. When `hint` is `patch`, every package receives an
|
|
1822
|
+
* update: stable packages are assigned a patch release even without a
|
|
1823
|
+
* `versionQualifier`, and prerelease packages (pre-major, pre-minor, and
|
|
1824
|
+
* pre-patch cycles) continue their cycle with an incremented counter,
|
|
1825
|
+
* redirect to `versionQualifier` when it differs, or release their stable
|
|
1826
|
+
* base when no `versionQualifier` is set.
|
|
1801
1827
|
*
|
|
1802
|
-
* @param
|
|
1803
|
-
* @param
|
|
1804
|
-
* @
|
|
1828
|
+
* @param hint Release type override hint to guide release classification
|
|
1829
|
+
* @param versionQualifier Optional qualifier string to compare against prerelease tags
|
|
1830
|
+
* @param plans List of release plans to analyze and update
|
|
1831
|
+
* @returns Updated release plans with derived transition release types
|
|
1805
1832
|
*/
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1833
|
+
function deriveTransitionReleases(hint, versionQualifier, plans) {
|
|
1834
|
+
return plans.map((plan) => {
|
|
1835
|
+
if (plan.release) return plan;
|
|
1836
|
+
const parsed = semver.parse(plan.package.version);
|
|
1837
|
+
if (!parsed) return plan;
|
|
1838
|
+
const { major, minor, patch } = parsed;
|
|
1839
|
+
const parsedVersionQualifier = extractVersionQualifier(parsed);
|
|
1840
|
+
let releaseType;
|
|
1841
|
+
let versionTransition;
|
|
1842
|
+
switch (hint) {
|
|
1843
|
+
case "major":
|
|
1844
|
+
if (parsed.prerelease.length === 0) {
|
|
1845
|
+
if (typeof versionQualifier === "string") releaseType = "major";
|
|
1846
|
+
else if (major === 0 && (minor > 0 || patch > 0)) releaseType = "major";
|
|
1847
|
+
} else if (minor === 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "major";
|
|
1848
|
+
break;
|
|
1849
|
+
case "minor":
|
|
1850
|
+
if (parsed.prerelease.length === 0) {
|
|
1851
|
+
if (typeof versionQualifier === "string") releaseType = "minor";
|
|
1852
|
+
} else if (minor > 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "minor";
|
|
1853
|
+
break;
|
|
1854
|
+
case "patch":
|
|
1855
|
+
releaseType = "patch";
|
|
1856
|
+
break;
|
|
1857
|
+
default: if (parsed.prerelease.length === 0) {
|
|
1858
|
+
if (major === 0 && (minor > 0 || patch > 0)) releaseType = "major";
|
|
1859
|
+
} else if (minor === 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "major";
|
|
1860
|
+
else if (minor > 0 && patch === 0 && parsedVersionQualifier !== versionQualifier) releaseType = "minor";
|
|
1861
|
+
else if (patch > 0 && parsedVersionQualifier !== versionQualifier) releaseType = "patch";
|
|
1862
|
+
}
|
|
1863
|
+
if (parsedVersionQualifier == null || parsedVersionQualifier !== "" && versionQualifier === "") versionTransition = "advance";
|
|
1864
|
+
else versionTransition = "continue";
|
|
1865
|
+
if (!releaseType) return plan;
|
|
1866
|
+
return {
|
|
1867
|
+
...plan,
|
|
1868
|
+
release: {
|
|
1869
|
+
type: releaseType,
|
|
1870
|
+
transition: versionTransition
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
});
|
|
1818
1874
|
}
|
|
1819
|
-
// src/
|
|
1875
|
+
// src/workflow/analysis/promotePrereleaseVersions.ts
|
|
1820
1876
|
/**
|
|
1821
|
-
*
|
|
1877
|
+
* Promote prerelease versions when they have no explicit release type.
|
|
1822
1878
|
*
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
*
|
|
1879
|
+
* Analyzes prerelease and zero-major versions to determine an appropriate
|
|
1880
|
+
* release type for graduation:
|
|
1881
|
+
* - Prerelease versions are promoted based on their highest incremented component
|
|
1882
|
+
* (patch, minor, or major)
|
|
1883
|
+
* - Zero-major versions (0.y.z) are promoted to major
|
|
1884
|
+
* - Stable versions (1.0.0+) remain unchanged
|
|
1885
|
+
* - Plans with explicit releases are preserved as-is
|
|
1886
|
+
*
|
|
1887
|
+
* @param plans Release plans to analyze
|
|
1888
|
+
* @returns Plans with inferred release types for prerelease versions
|
|
1827
1889
|
*/
|
|
1828
|
-
async function
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
"
|
|
1838
|
-
"
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1890
|
+
async function promotePrereleaseVersions(plans) {
|
|
1891
|
+
return plans.map((plan) => {
|
|
1892
|
+
if (plan.release) return plan;
|
|
1893
|
+
if (!plan.package.tag) return plan;
|
|
1894
|
+
const parsed = semver.parse(plan.package.version);
|
|
1895
|
+
if (!parsed) return plan;
|
|
1896
|
+
let type;
|
|
1897
|
+
if (parsed.prerelease.length) {
|
|
1898
|
+
if (parsed.patch !== 0) type = "patch";
|
|
1899
|
+
else if (parsed.minor !== 0) type = "minor";
|
|
1900
|
+
else if (parsed.major !== 0) type = "major";
|
|
1901
|
+
else type = "major";
|
|
1902
|
+
} else if (parsed.major === 0) type = "major";
|
|
1903
|
+
if (type) return {
|
|
1904
|
+
...plan,
|
|
1905
|
+
release: { type }
|
|
1906
|
+
};
|
|
1907
|
+
return plan;
|
|
1908
|
+
});
|
|
1846
1909
|
}
|
|
1847
1910
|
// src/workflow/discovery/buildDependencyGraph.ts
|
|
1848
1911
|
/**
|
|
@@ -2022,6 +2085,22 @@ async function discoverPackageTag(cwd, pkg) {
|
|
|
2022
2085
|
message: await getGitTagMessage(cwd, expectedTagName)
|
|
2023
2086
|
};
|
|
2024
2087
|
}
|
|
2088
|
+
// src/workflow/discovery/filterPackages.ts
|
|
2089
|
+
/**
|
|
2090
|
+
* Filter packages by name patterns.
|
|
2091
|
+
*
|
|
2092
|
+
* Keeps the packages whose names match `patterns`, scoping a release run to
|
|
2093
|
+
* a subset of the discovered workspace. Returns a copy of every package when
|
|
2094
|
+
* `patterns` is empty.
|
|
2095
|
+
*
|
|
2096
|
+
* @param packages Workspace packages to filter
|
|
2097
|
+
* @param patterns Minimatch patterns to match package names against
|
|
2098
|
+
* @returns Packages whose names match the patterns
|
|
2099
|
+
*/
|
|
2100
|
+
function filterPackages(packages, patterns) {
|
|
2101
|
+
if (patterns.length === 0) return [...packages];
|
|
2102
|
+
return packages.filter((pkg) => isMatch(pkg.name ?? "", patterns));
|
|
2103
|
+
}
|
|
2025
2104
|
// src/workflow/discovery/resolvePackageStableTag.ts
|
|
2026
2105
|
/**
|
|
2027
2106
|
* Resolve the latest stable Git tag for a package.
|
|
@@ -2128,70 +2207,81 @@ async function propagateDependencyUpdates(cwd, plans) {
|
|
|
2128
2207
|
return plan;
|
|
2129
2208
|
});
|
|
2130
2209
|
}
|
|
2131
|
-
// src/workflow/
|
|
2210
|
+
// src/workflow/analysis/readPackageHistory.ts
|
|
2132
2211
|
/**
|
|
2133
|
-
*
|
|
2212
|
+
* Yield commits from git history associated with a package.
|
|
2134
2213
|
*
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
2137
|
-
* verifying exact tag matches for the `commit` hash.
|
|
2214
|
+
* Filters git commit history to yield only entries relevant to the target
|
|
2215
|
+
* `pkg` directory.
|
|
2138
2216
|
*
|
|
2139
|
-
* @param cwd
|
|
2140
|
-
* @param
|
|
2141
|
-
* @param
|
|
2142
|
-
* @
|
|
2217
|
+
* @param cwd Path to the working directory for git commands
|
|
2218
|
+
* @param pkg Package configuration containing the target directory
|
|
2219
|
+
* @param options Options for parsing and filtering git history
|
|
2220
|
+
* @yields Commits belonging to the specified package
|
|
2143
2221
|
*/
|
|
2144
|
-
async function
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
if (!commit) return false;
|
|
2151
|
-
const predicate = typeof marker === "string" ? (trailer) => trailer.key === marker && !!trailer.value : marker;
|
|
2152
|
-
if (commit.trailers.some(predicate)) return true;
|
|
2153
|
-
return execGit(cwd, [
|
|
2154
|
-
"describe",
|
|
2155
|
-
"--tags",
|
|
2156
|
-
"--exact-match",
|
|
2157
|
-
commit.hash
|
|
2158
|
-
]).then(() => true).catch(() => false);
|
|
2222
|
+
async function* readPackageHistory(cwd, pkg, options = {}) {
|
|
2223
|
+
options = {
|
|
2224
|
+
...options,
|
|
2225
|
+
filePath: options.filePath || pkg.location
|
|
2226
|
+
};
|
|
2227
|
+
for await (const commit of showParsedGitHistory(cwd, options)) if (isCommitForPackage(pkg, commit)) yield commit;
|
|
2159
2228
|
}
|
|
2160
2229
|
// src/workflow/analysis/sliceUnreleased.ts
|
|
2161
2230
|
/**
|
|
2162
2231
|
* Yield parsed commits from the workspace until a release commit is found.
|
|
2163
2232
|
*
|
|
2164
|
-
*
|
|
2165
|
-
*
|
|
2233
|
+
* Collects unreleased commits ahead of the most recent release commit and
|
|
2234
|
+
* yields them in order.
|
|
2166
2235
|
*
|
|
2167
2236
|
* @param cwd Path to the working directory
|
|
2168
2237
|
* @param options Options for configuring Git history retrieval
|
|
2169
2238
|
* @yields Parsed `Commit` objects up to the most recent release commit
|
|
2170
2239
|
*/
|
|
2171
2240
|
async function* sliceUnreleased(cwd, options) {
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
yield commit;
|
|
2175
|
-
}
|
|
2241
|
+
const { history } = await collectUnreleased(cwd, options);
|
|
2242
|
+
yield* history;
|
|
2176
2243
|
}
|
|
2177
|
-
// src/workflow/
|
|
2244
|
+
// src/workflow/committing/readReleaseFilterPatterns.ts
|
|
2178
2245
|
/**
|
|
2179
|
-
*
|
|
2246
|
+
* Read release filter patterns from a parsed commit.
|
|
2180
2247
|
*
|
|
2181
|
-
*
|
|
2182
|
-
*
|
|
2248
|
+
* Collects the release filter trailer values and splits them into individual
|
|
2249
|
+
* comma-separated filter patterns, unescaping the commas within patterns.
|
|
2250
|
+
* Returns `null` when the commit carries no release filter trailer, so
|
|
2251
|
+
* callers can treat it as a release of every package.
|
|
2252
|
+
*
|
|
2253
|
+
* @param commit Parsed commit object or nullish value
|
|
2254
|
+
* @returns Filter patterns carried by the trailer, or `null` when absent
|
|
2255
|
+
*/
|
|
2256
|
+
function readReleaseFilterPatterns(commit) {
|
|
2257
|
+
if (!commit) return null;
|
|
2258
|
+
const values = commit.trailers.filter((trailer) => trailer.key === GIT_TRAILER_RELEASE_FILTER).map((trailer) => trailer.value);
|
|
2259
|
+
if (values.length === 0) return null;
|
|
2260
|
+
return values.flatMap((value) => value.split(/(?<!\\),/)).map((pattern) => pattern.trim()).map((pattern) => pattern.replaceAll("\\,", ",")).filter((pattern) => pattern.length > 0);
|
|
2261
|
+
}
|
|
2262
|
+
// src/workflow/analysis/sliceUnreleasedForPackage.ts
|
|
2263
|
+
/**
|
|
2264
|
+
* Yield unreleased commits from the history of a single package.
|
|
2265
|
+
*
|
|
2266
|
+
* Streams commits that touch the package files in historical order and stops
|
|
2267
|
+
* at the first release commit that released the package. Release commits
|
|
2268
|
+
* created by filtered runs that excluded the package are themselves yielded
|
|
2269
|
+
* as unreleased changes, so every package keeps its own release boundary
|
|
2270
|
+
* instead of sharing the latest repository-wide release commit.
|
|
2183
2271
|
*
|
|
2184
2272
|
* @param cwd Path to the working directory for git commands
|
|
2185
|
-
* @param pkg Package
|
|
2186
|
-
* @param options Options for
|
|
2187
|
-
* @yields
|
|
2273
|
+
* @param pkg Package whose files scope the commit history
|
|
2274
|
+
* @param options Options for configuring Git history retrieval
|
|
2275
|
+
* @yields Parsed commits up to the package's most recent release commit
|
|
2188
2276
|
*/
|
|
2189
|
-
async function*
|
|
2190
|
-
options
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2277
|
+
async function* sliceUnreleasedForPackage(cwd, pkg, options = {}) {
|
|
2278
|
+
for await (const commit of readPackageHistory(cwd, pkg, options)) {
|
|
2279
|
+
if (await isReleaseCommit(cwd, commit, options.marker)) {
|
|
2280
|
+
const patterns = readReleaseFilterPatterns(commit);
|
|
2281
|
+
if (patterns === null || isMatch(pkg.name ?? "", patterns)) break;
|
|
2282
|
+
}
|
|
2283
|
+
yield commit;
|
|
2284
|
+
}
|
|
2195
2285
|
}
|
|
2196
2286
|
// src/workflow/changelog/buildChangelog.ts
|
|
2197
2287
|
var preset = await createPreset();
|
|
@@ -2347,7 +2437,7 @@ async function writeChangelog(cwd, plan) {
|
|
|
2347
2437
|
}
|
|
2348
2438
|
}
|
|
2349
2439
|
// package.json
|
|
2350
|
-
var version = "0.5.
|
|
2440
|
+
var version = "0.5.3";
|
|
2351
2441
|
// src/workflow/committing/generateReleaseCommitMessage.ts
|
|
2352
2442
|
var NOTABLE_TYPES = [
|
|
2353
2443
|
"feat",
|
|
@@ -2645,6 +2735,6 @@ async function executeReleaseWorkflow(context, plugins) {
|
|
|
2645
2735
|
printReleaseReport(context.logger, generateReleaseReport(context));
|
|
2646
2736
|
}
|
|
2647
2737
|
}
|
|
2648
|
-
export {
|
|
2738
|
+
export { RELEASE_HOOK_NAMES as $, deriveChangeReleases as A, getParsedGitCommit as At, isReleaseCommit as B, readJson as Bt, extractLatestVersion as C, expandGitHistory as Ct, buildDependencyGraph as D, isGitShallowRepository as Dt, extractPlainText as E, withShallowLock as Et, pickPriorityReleaseType as F, TTLCache as Ft, isSemVer as G, execGit as Gt, resolveReleaseChannel as H, isClass as Ht, determineReleaseType as I, extractMentions as It, ALL_FILES as J, isDefined as Jt, findReleaseRule as K, execCommand as Kt, bumpVersion as L, createGitCommit as Lt, isStableVersion as M, GIT_PRETTY_FORMAT as Mt, isSameReleaseCycle as N, parseGitPrettyFormat as Nt, promotePrereleaseVersions as O, countGitHistory as Ot, deriveReleaseType as P, parseGitCommit as Pt, GIT_TRAILER_RELEASE_FILTER as Q, extractVersionQualifier as R, getCurrentGitBranch as Rt, verifyPackageTag as S, detectGitRelationship as St, extractSemVer as T, isGitAncestor as Tt, sanitizePrereleaseLabel as U, interpolate as Ut, resolveVersionQualifier as V, isMatch as Vt, isSemVerGitTag as W, formatFile as Wt, DEV_NULL as X, DEFAULT_CHANGELOG_FILE as Y, buildTrailerPattern as Yt, GIT_TRAILER_RELEASE_AGENT as Z, propagateDependencyUpdates as _, showParsedGitHistory as _t, HookPriority as a, getCurrentGitTag as at, filterPackages as b, mergeGitHistory as bt, writeChangelog as c, isGitTagPresent as ct, buildReleaseNotes as d, readGitFile as dt, SEMVER_REGEX as et, buildChangelog as f, resolveGitRepository as ft, readPackageHistory as g, getGitConfigValue as gt, sliceUnreleased as h, ensureGitUserConfig as ht, HookManager as i, getGitTagMessage as it, isCommitForPackage as j, GIT_PRETTY_FIELD_SEPARATOR as jt, deriveTransitionReleases as k, getCurrentGitCommit as kt, prependChangelog as l, deleteGitTag as lt, readReleaseFilterPatterns as m, getGitRemote as mt, printReleaseReport as n, isGitTagConnected as nt, generateReleaseCommitMessage as o, generateGitTagName as ot, sliceUnreleasedForPackage as p, pushGitChanges as pt, createPlugin as q, compact as qt, generateReleaseReport as r, getLatestGitTag as rt, version as s, ensureGitTag as st, executeReleaseWorkflow as t, isGitTagPointed as tt, extractPreviousVersion as u, createGitTag as ut, resolvePackageTag as v, showGitHistory as vt, iterateChangelogVersions as w, resolveGitRevision as wt, discoverPackageTag as x, GIT_REL_FLAGS as xt, resolvePackageStableTag as y, restoreFullGitHistory as yt, collectUnreleased as z, writeJson as zt };
|
|
2649
2739
|
|
|
2650
|
-
//# sourceMappingURL=workflow-
|
|
2740
|
+
//# sourceMappingURL=workflow-c9uKSARL.js.map
|