@reelout/core 0.12.0 → 0.14.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/HookDispatcher-Di79rwtu.js +236 -0
- package/dist/HookDispatcher-Di79rwtu.js.map +1 -0
- package/dist/analyzer.js +12 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/buildChangelog-Cxm9_lq2.js +187 -0
- package/dist/buildChangelog-Cxm9_lq2.js.map +1 -0
- package/dist/buildReleaseNotes-S6HcEQnE.js +141 -0
- package/dist/buildReleaseNotes-S6HcEQnE.js.map +1 -0
- package/dist/builder.js +14 -6
- package/dist/builder.js.map +1 -1
- package/dist/changelog.js +17 -6
- package/dist/changelog.js.map +1 -1
- package/dist/index.js +1201 -8
- package/dist/index.js.map +1 -1
- package/dist/package-Bczytil1.js +884 -0
- package/dist/package-Bczytil1.js.map +1 -0
- package/dist/propagateDependencyUpdates-QWn0H1qa.js +306 -0
- package/dist/propagateDependencyUpdates-QWn0H1qa.js.map +1 -0
- package/dist/readPackageHistory-CN5nqMcE.js +133 -0
- package/dist/readPackageHistory-CN5nqMcE.js.map +1 -0
- package/dist/resolvePackageTag-cwqG1GGt.js +30 -0
- package/dist/resolvePackageTag-cwqG1GGt.js.map +1 -0
- package/dist/types.js +0 -1
- package/package.json +15 -3
- package/src/analyzer.ts +7 -2
- package/src/builder.ts +12 -3
- package/src/changelog.ts +17 -6
- package/src/config/resolvePlugin.ts +1 -1
- package/src/git/commit/getParsedGitCommit.ts +4 -1
- package/src/git/commit/parseGitCommit.ts +27 -2
- package/src/git/commit/parseGitPrettyFormat.ts +4 -1
- package/src/git/history/expandGitHistory.ts +17 -3
- package/src/git/history/readParsedGitHistory.ts +8 -2
- package/src/git/repository/isGitShallowRepository.ts +2 -1
- package/src/git/tag/ensureGitTag.ts +35 -3
- package/src/plugin/createHostReleasePlugin.ts +255 -0
- package/src/plugin/index.ts +1 -0
- package/src/util/execCommand.ts +9 -0
- package/src/util/formatFile.ts +12 -3
- package/src/util/interpolate.ts +5 -3
- package/src/workflow/analysis/propagateDependencyUpdates.ts +1 -0
- package/src/workflow/changelog/buildChangelog.ts +27 -4
- package/src/workflow/changelog/buildReleaseNotes.ts +1 -1
- package/src/workflow/changelog/index.ts +0 -1
- package/src/workflow/changelog/prependChangelog.ts +5 -2
- package/src/workflow/changelog/writeChangelog.ts +5 -2
- package/src/workflow/commit/generateReleaseCommitMessage.ts +1 -1
- package/src/workflow/discovery/discoverPackageTag.ts +5 -2
- package/src/workflow/discovery/resolvePackageStableTag.ts +12 -7
- package/src/workflow/discovery/resolvePackageTag.ts +5 -2
- package/src/workflow/discovery/sortPackages.ts +5 -4
- package/src/workflow/discovery/verifyPackageTag.ts +6 -3
- package/src/workflow/report/printReleaseReport.ts +6 -1
- package/src/workflow/version/bumpVersion.ts +0 -1
- package/src/workflow/version/index.ts +0 -1
- package/dist/formatError-BMsun8Wi.js +0 -22
- package/dist/formatError-BMsun8Wi.js.map +0 -1
- package/dist/types-la_KkjCS.js +0 -1
- package/dist/workflow-WWJphdYg.js +0 -2936
- package/dist/workflow-WWJphdYg.js.map +0 -1
- package/src/workflow/changelog/extractPreviousVersion.ts +0 -77
- package/src/workflow/version/promotePrereleaseVersions.ts +0 -51
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { T as execGit, a as generateGitTagName, i as getGitTagMessage, n as verifyPackageTag, u as resolveGitRevision } from "./package-Bczytil1.js";
|
|
2
|
+
import { a as formatFile, n as iterateChangelogVersions } from "./buildChangelog-Cxm9_lq2.js";
|
|
3
|
+
import fs, { readFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
6
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
7
|
+
// src/git/revision/readGitFile.ts
|
|
8
|
+
/**
|
|
9
|
+
* Read a file's contents from a specific Git revision.
|
|
10
|
+
*
|
|
11
|
+
* Runs `git show <ref>:<filePath>` and returns the command output as a
|
|
12
|
+
* string. If the file does not exist at the given revision or the Git
|
|
13
|
+
* command fails for any reason, the function returns `null`.
|
|
14
|
+
*
|
|
15
|
+
* The returned string is the raw file contents as emitted by Git; callers
|
|
16
|
+
* that need binary-safe handling should decode or process the bytes
|
|
17
|
+
* accordingly. This function intentionally swallows Git errors and signals
|
|
18
|
+
* absence via a `null` result rather than throwing.
|
|
19
|
+
*
|
|
20
|
+
* @param cwd Repository working directory
|
|
21
|
+
* @param ref Commit-ish reference (commit SHA, tag, or branch) to read from
|
|
22
|
+
* @param filePath Path to the file relative to the repository root
|
|
23
|
+
* @returns File contents as a string, or `null` if the file is unavailable at the ref
|
|
24
|
+
*/
|
|
25
|
+
function readGitFile(cwd, ref, filePath) {
|
|
26
|
+
return execGit(cwd, ["show", `${ref}:${filePath}`]).catch(() => null);
|
|
27
|
+
}
|
|
28
|
+
// src/workflow/changelog/extractLatestVersion.ts
|
|
29
|
+
/**
|
|
30
|
+
* Find the highest semantic version from the first version-bearing element.
|
|
31
|
+
*
|
|
32
|
+
* Pulls the first available version string from the parsed markdown iterator.
|
|
33
|
+
* Short-circuits execution immediately upon locating a match to avoid passing
|
|
34
|
+
* through the remaining document structure.
|
|
35
|
+
*
|
|
36
|
+
* @param changelogContent The raw markdown string representing the changelog
|
|
37
|
+
* @returns The highest valid semantic version string found or null
|
|
38
|
+
*/
|
|
39
|
+
function extractLatestVersion(changelogContent) {
|
|
40
|
+
for (const version of iterateChangelogVersions(changelogContent)) return version;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
// src/workflow/discovery/discoverPackageTag.ts
|
|
44
|
+
/**
|
|
45
|
+
* Discover and validate the Git tag for a package.
|
|
46
|
+
*
|
|
47
|
+
* Returns the existing tag if already present on the `pkg` object. Resolves
|
|
48
|
+
* the local changelog file path, extracts the current version, and generates
|
|
49
|
+
* the expected Git tag name. Verifies the tag against the repository and
|
|
50
|
+
* ensures its historical changelog version matches the current local version.
|
|
51
|
+
*
|
|
52
|
+
* @param cwd The current working directory
|
|
53
|
+
* @param pkg The package configuration object
|
|
54
|
+
* @param options Dry-run and logging guards for the local tag cleanup
|
|
55
|
+
* @returns The validated `Tag` object or null if validation fails
|
|
56
|
+
*/
|
|
57
|
+
async function discoverPackageTag(cwd, pkg, options) {
|
|
58
|
+
if (pkg.tag) return pkg.tag;
|
|
59
|
+
const changelogFile = pkg.changelogFile || "CHANGELOG.md";
|
|
60
|
+
const changelogFilePath = path.resolve(cwd, pkg.location, changelogFile);
|
|
61
|
+
let localChangelogContent;
|
|
62
|
+
try {
|
|
63
|
+
localChangelogContent = await readFile(changelogFilePath, "utf-8");
|
|
64
|
+
} catch {}
|
|
65
|
+
if (!localChangelogContent) return null;
|
|
66
|
+
const currentVersion = extractLatestVersion(localChangelogContent);
|
|
67
|
+
if (!currentVersion) return null;
|
|
68
|
+
let expectedTagName;
|
|
69
|
+
try {
|
|
70
|
+
expectedTagName = generateGitTagName(pkg.entry, pkg.name, currentVersion);
|
|
71
|
+
} catch {}
|
|
72
|
+
if (!expectedTagName) return null;
|
|
73
|
+
if (!await verifyPackageTag(cwd, pkg, expectedTagName, options)) return null;
|
|
74
|
+
const tagRef = `refs/tags/${expectedTagName}`;
|
|
75
|
+
const historicalChangelogContent = await readGitFile(cwd, await resolveGitRevision(cwd, tagRef), path.relative(cwd, changelogFilePath));
|
|
76
|
+
if (!historicalChangelogContent) return null;
|
|
77
|
+
const historicalChangelogVersion = extractLatestVersion(historicalChangelogContent);
|
|
78
|
+
if (!historicalChangelogVersion || historicalChangelogVersion !== currentVersion) return null;
|
|
79
|
+
return {
|
|
80
|
+
name: expectedTagName,
|
|
81
|
+
message: await getGitTagMessage(cwd, expectedTagName)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// src/workflow/changelog/prependChangelog.ts
|
|
85
|
+
var defaultChangelogTitle = "Changelog";
|
|
86
|
+
/**
|
|
87
|
+
* Prepend changelog content to a markdown file, creating it if necessary.
|
|
88
|
+
*
|
|
89
|
+
* Reads the existing file if present, prepends the new content before the main heading,
|
|
90
|
+
* formats and writes the result back.
|
|
91
|
+
*
|
|
92
|
+
* @param filePath Path to the changelog file
|
|
93
|
+
* @param revision Changelog content to prepend
|
|
94
|
+
* @param logger Optional logger that receives formatting failures
|
|
95
|
+
* @returns Promise that resolves when the changelog is written
|
|
96
|
+
*/
|
|
97
|
+
async function prependChangelog(filePath, revision, logger) {
|
|
98
|
+
let content = "";
|
|
99
|
+
try {
|
|
100
|
+
content = await fs.readFile(filePath, "utf-8");
|
|
101
|
+
} catch (err) {
|
|
102
|
+
/* istanbul ignore next */
|
|
103
|
+
if (err.code !== "ENOENT") throw err;
|
|
104
|
+
}
|
|
105
|
+
const root = fromMarkdown(content);
|
|
106
|
+
let index = root.children.findIndex((node) => node.type === "heading" && node.depth === 1);
|
|
107
|
+
if (index === -1) {
|
|
108
|
+
index = 0;
|
|
109
|
+
root.children.unshift({
|
|
110
|
+
type: "heading",
|
|
111
|
+
depth: 1,
|
|
112
|
+
children: [{
|
|
113
|
+
type: "text",
|
|
114
|
+
value: defaultChangelogTitle
|
|
115
|
+
}]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
root.children.splice(index + 1, 0, ...fromMarkdown(revision).children);
|
|
119
|
+
content = toMarkdown(root);
|
|
120
|
+
content = await formatFile(filePath, content, logger);
|
|
121
|
+
await fs.writeFile(filePath, content);
|
|
122
|
+
}
|
|
123
|
+
// src/workflow/changelog/writeChangelog.ts
|
|
124
|
+
/**
|
|
125
|
+
* Write changelog content to the file system based on the release plan.
|
|
126
|
+
*
|
|
127
|
+
* @param cwd Repository working directory
|
|
128
|
+
* @param plan Release plan containing package and changelog content
|
|
129
|
+
* @param logger Optional logger that receives formatting failures
|
|
130
|
+
* @returns Promise that resolves when the changelog file has been written
|
|
131
|
+
*/
|
|
132
|
+
async function writeChangelog(cwd, plan, logger) {
|
|
133
|
+
if (plan.release?.changelog) {
|
|
134
|
+
const changelogFile = plan.package.changelogFile || "CHANGELOG.md";
|
|
135
|
+
await prependChangelog(path.join(cwd, plan.package.location, changelogFile), plan.release.changelog, logger);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// src/plugin/HookDispatcher.ts
|
|
139
|
+
/**
|
|
140
|
+
* Priority ranks that order middleware within a hook.
|
|
141
|
+
*/
|
|
142
|
+
var Priority = {
|
|
143
|
+
High: 50,
|
|
144
|
+
Normal: 0,
|
|
145
|
+
Low: -50
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Dispatch registered hooks through asynchronous execution chains.
|
|
149
|
+
*
|
|
150
|
+
* Stores middleware in a prioritized registry and executes them sequentially
|
|
151
|
+
* in priority order.
|
|
152
|
+
*/
|
|
153
|
+
var HookDispatcher = class {
|
|
154
|
+
#registry = /* @__PURE__ */ new Map();
|
|
155
|
+
#interceptor;
|
|
156
|
+
/**
|
|
157
|
+
* Create a hook dispatcher.
|
|
158
|
+
*
|
|
159
|
+
* @param interceptor Wrapper invoked in place of every registered
|
|
160
|
+
* middleware during dispatch
|
|
161
|
+
*/
|
|
162
|
+
constructor(interceptor) {
|
|
163
|
+
this.#interceptor = interceptor;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Register middleware for a specific hook.
|
|
167
|
+
*
|
|
168
|
+
* Adds the `middleware` to the internal registry for `hook` and sorts the
|
|
169
|
+
* list so higher-priority middleware runs first. An omitted or `undefined`
|
|
170
|
+
* `options.priority` defaults to `Priority.Normal`; `options.meta` is
|
|
171
|
+
* carried on the registration for the constructor interceptor.
|
|
172
|
+
*
|
|
173
|
+
* @param hook Name of the hook to register
|
|
174
|
+
* @param middleware Function executed when the hook dispatches
|
|
175
|
+
* @param options Registration options carrying the execution order rank and
|
|
176
|
+
* the metadata exposed to the constructor interceptor
|
|
177
|
+
*/
|
|
178
|
+
on(hook, middleware, options) {
|
|
179
|
+
const registrations = this.#registry.get(hook) ?? [];
|
|
180
|
+
registrations.push({
|
|
181
|
+
hook,
|
|
182
|
+
middleware,
|
|
183
|
+
priority: options?.priority ?? Priority.Normal,
|
|
184
|
+
meta: options?.meta
|
|
185
|
+
});
|
|
186
|
+
registrations.sort((a, b) => b.priority - a.priority);
|
|
187
|
+
this.#registry.set(hook, registrations);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Unregister middleware from a specific hook.
|
|
191
|
+
*
|
|
192
|
+
* Removes matching `middleware` references from the internal registry for
|
|
193
|
+
* `hook`. Takes no action if `hook` has no registered middleware.
|
|
194
|
+
*
|
|
195
|
+
* @param hook Name of the hook to unregister from
|
|
196
|
+
* @param middleware Reference of the middleware function to remove
|
|
197
|
+
*/
|
|
198
|
+
off(hook, middleware) {
|
|
199
|
+
const registrations = this.#registry.get(hook);
|
|
200
|
+
if (!registrations) return;
|
|
201
|
+
this.#registry.set(hook, registrations.filter((registration) => registration.middleware !== middleware));
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Dispatch all middleware registered to a hook.
|
|
205
|
+
*
|
|
206
|
+
* Passes `context` through the middleware pipeline in descending priority
|
|
207
|
+
* order and dispatches each registration through the constructor
|
|
208
|
+
* interceptor when one is provided. Enables middleware to control
|
|
209
|
+
* execution flow using `next` and executes `done` after the last
|
|
210
|
+
* middleware completes.
|
|
211
|
+
*
|
|
212
|
+
* @param hook Name of the hook to dispatch
|
|
213
|
+
* @param context Shared payload passed into each middleware
|
|
214
|
+
* @param done Optional final callback run after the pipeline completes
|
|
215
|
+
* @returns Promise that resolves when execution completes
|
|
216
|
+
*/
|
|
217
|
+
async dispatch(hook, context, done) {
|
|
218
|
+
const registrations = this.#registry.get(hook) ?? [];
|
|
219
|
+
const interceptor = this.#interceptor;
|
|
220
|
+
const run = async (index, context) => {
|
|
221
|
+
const registration = registrations[index];
|
|
222
|
+
if (!registration) return done ? await done(context) : void 0;
|
|
223
|
+
let isNextCalled = false;
|
|
224
|
+
const next = async (context) => {
|
|
225
|
+
if (isNextCalled) return;
|
|
226
|
+
isNextCalled = true;
|
|
227
|
+
return await run(index + 1, context);
|
|
228
|
+
};
|
|
229
|
+
return await (interceptor ? (context, next) => interceptor(context, registration, next) : registration.middleware)(context, next);
|
|
230
|
+
};
|
|
231
|
+
return await run(0, context);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
export { discoverPackageTag as a, prependChangelog as i, Priority as n, extractLatestVersion as o, writeChangelog as r, readGitFile as s, HookDispatcher as t };
|
|
235
|
+
|
|
236
|
+
//# sourceMappingURL=HookDispatcher-Di79rwtu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HookDispatcher-Di79rwtu.js","names":[],"sources":["../src/git/revision/readGitFile.ts","../src/workflow/changelog/extractLatestVersion.ts","../src/workflow/discovery/discoverPackageTag.ts","../src/workflow/changelog/prependChangelog.ts","../src/workflow/changelog/writeChangelog.ts","../src/plugin/HookDispatcher.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { execGit } from '#util'\n\n/**\n * Read a file's contents from a specific Git revision.\n *\n * Runs `git show <ref>:<filePath>` and returns the command output as a\n * string. If the file does not exist at the given revision or the Git\n * command fails for any reason, the function returns `null`.\n *\n * The returned string is the raw file contents as emitted by Git; callers\n * that need binary-safe handling should decode or process the bytes\n * accordingly. This function intentionally swallows Git errors and signals\n * absence via a `null` result rather than throwing.\n *\n * @param cwd Repository working directory\n * @param ref Commit-ish reference (commit SHA, tag, or branch) to read from\n * @param filePath Path to the file relative to the repository root\n * @returns File contents as a string, or `null` if the file is unavailable at the ref\n */\nexport function readGitFile(\n cwd: string,\n ref: string,\n filePath: string\n): Promise<string | null> {\n return execGit(cwd, ['show', `${ref}:${filePath}`]).catch(() => null)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { iterateChangelogVersions } from './iterateChangelogVersions'\n\n/**\n * Find the highest semantic version from the first version-bearing element.\n *\n * Pulls the first available version string from the parsed markdown iterator.\n * Short-circuits execution immediately upon locating a match to avoid passing\n * through the remaining document structure.\n *\n * @param changelogContent The raw markdown string representing the changelog\n * @returns The highest valid semantic version string found or null\n */\nexport function extractLatestVersion(changelogContent: string): string | null {\n for (const version of iterateChangelogVersions(changelogContent)) {\n return version\n }\n\n return null\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { DEFAULT_CHANGELOG_FILE } from '#config'\nimport {\n generateGitTagName,\n getGitTagMessage,\n readGitFile,\n resolveGitRevision,\n} from '#git'\nimport type { EnsureGitTagOptions } from '#git'\nimport type { Package, Tag } from '#types'\nimport { readFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport { extractLatestVersion } from '../changelog/extractLatestVersion'\nimport { verifyPackageTag } from './verifyPackageTag'\n\n/**\n * Discover and validate the Git tag for a package.\n *\n * Returns the existing tag if already present on the `pkg` object. Resolves\n * the local changelog file path, extracts the current version, and generates\n * the expected Git tag name. Verifies the tag against the repository and\n * ensures its historical changelog version matches the current local version.\n *\n * @param cwd The current working directory\n * @param pkg The package configuration object\n * @param options Dry-run and logging guards for the local tag cleanup\n * @returns The validated `Tag` object or null if validation fails\n */\nexport async function discoverPackageTag(\n cwd: string,\n pkg: Package,\n options?: EnsureGitTagOptions\n): Promise<Tag | null> {\n if (pkg.tag) {\n return pkg.tag\n }\n\n const changelogFile = pkg.changelogFile || DEFAULT_CHANGELOG_FILE\n\n const changelogFilePath = path.resolve(cwd, pkg.location, changelogFile)\n\n let localChangelogContent: string | null | undefined\n\n try {\n localChangelogContent = await readFile(changelogFilePath, 'utf-8')\n } catch {}\n\n if (!localChangelogContent) {\n return null\n }\n\n const currentVersion = extractLatestVersion(localChangelogContent)\n\n if (!currentVersion) {\n return null\n }\n\n let expectedTagName: string | null | undefined\n\n try {\n expectedTagName = generateGitTagName(pkg.entry, pkg.name, currentVersion)\n } catch {}\n\n if (!expectedTagName) {\n return null\n }\n\n if (!(await verifyPackageTag(cwd, pkg, expectedTagName, options))) {\n return null\n }\n\n const tagRef = `refs/tags/${expectedTagName}`\n\n const historicalChangelogContent = await readGitFile(\n cwd,\n await resolveGitRevision(cwd, tagRef),\n path.relative(cwd, changelogFilePath)\n )\n\n if (!historicalChangelogContent) {\n return null\n }\n\n const historicalChangelogVersion = extractLatestVersion(\n historicalChangelogContent\n )\n\n if (\n !historicalChangelogVersion ||\n historicalChangelogVersion !== currentVersion\n ) {\n return null\n }\n\n return {\n name: expectedTagName,\n message: await getGitTagMessage(cwd, expectedTagName),\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { formatFile } from '#util'\nimport type { ConsolaInstance } from 'consola/core'\nimport { fromMarkdown } from 'mdast-util-from-markdown'\nimport { toMarkdown } from 'mdast-util-to-markdown'\nimport fs from 'node:fs/promises'\n\nconst defaultChangelogTitle = 'Changelog'\n\n/**\n * Prepend changelog content to a markdown file, creating it if necessary.\n *\n * Reads the existing file if present, prepends the new content before the main heading,\n * formats and writes the result back.\n *\n * @param filePath Path to the changelog file\n * @param revision Changelog content to prepend\n * @param logger Optional logger that receives formatting failures\n * @returns Promise that resolves when the changelog is written\n */\nexport async function prependChangelog(\n filePath: string,\n revision: string,\n logger?: ConsolaInstance\n): Promise<void> {\n let content = ''\n\n try {\n content = await fs.readFile(filePath, 'utf-8')\n } catch (err) {\n /* istanbul ignore next */\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw err\n }\n }\n\n const root = fromMarkdown(content)\n\n let index = root.children.findIndex(\n (node) => node.type === 'heading' && node.depth === 1\n )\n\n if (index === -1) {\n index = 0\n\n root.children.unshift({\n type: 'heading',\n depth: 1,\n children: [{ type: 'text', value: defaultChangelogTitle }],\n })\n }\n\n root.children.splice(index + 1, 0, ...fromMarkdown(revision).children)\n\n content = toMarkdown(root)\n\n content = await formatFile(filePath, content, logger)\n\n await fs.writeFile(filePath, content)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { DEFAULT_CHANGELOG_FILE } from '#config'\nimport type { ReleasePlan } from '#types'\nimport type { ConsolaInstance } from 'consola/core'\nimport path from 'node:path'\nimport { prependChangelog } from './prependChangelog'\n\n/**\n * Write changelog content to the file system based on the release plan.\n *\n * @param cwd Repository working directory\n * @param plan Release plan containing package and changelog content\n * @param logger Optional logger that receives formatting failures\n * @returns Promise that resolves when the changelog file has been written\n */\nexport async function writeChangelog(\n cwd: string,\n plan: ReleasePlan,\n logger?: ConsolaInstance\n): Promise<void> {\n if (plan.release?.changelog) {\n const changelogFile = plan.package.changelogFile || DEFAULT_CHANGELOG_FILE\n\n const filePath = path.join(cwd, plan.package.location, changelogFile)\n\n await prependChangelog(filePath, plan.release.changelog, logger)\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Continuation that resumes the chain with the following middleware.\n */\nexport type Next<Context> = (context: Context) => Promise<void>\n\n/**\n * Function executed as a single link in a hook dispatch chain.\n */\nexport type Middleware<Context> = {\n bivariant(context: Context, next: Next<Context>): void | Promise<void>\n}['bivariant']\n\n/**\n * Priority ranks that order middleware within a hook.\n */\nexport const Priority = {\n High: 50,\n Normal: 0,\n Low: -50,\n} as const\n\n/**\n * Registration options accepted by `on`.\n */\nexport interface RegistrationOptions<Meta> {\n priority?: number | undefined\n meta?: Meta | undefined\n}\n\n/**\n * A registration entry captured by `on`.\n *\n * Carries the `middleware`, its `priority` sort rank, and the `meta` exposed\n * to the constructor interceptor.\n */\nexport interface Registration<HookName, Context, Meta = undefined> {\n hook: HookName\n priority: number\n middleware: Middleware<Context>\n meta: Meta | undefined\n}\n\n/**\n * Intercept a registered middleware during dispatch.\n *\n * Runs in place of every registered middleware, receiving the shared\n * `context`, the `registration` being dispatched — including its `priority`\n * and `meta` — and the `next` function that continues with the following\n * middleware.\n */\nexport type Interceptor<HookName, Context, Meta = undefined> = (\n context: Context,\n registration: Registration<HookName, Context, Meta>,\n next: Next<Context>\n) => void | Promise<void>\n\ntype InferContext<M extends Middleware<unknown>> =\n M extends Middleware<infer Context> ? Context : never\n\n/**\n * Dispatch registered hooks through asynchronous execution chains.\n *\n * Stores middleware in a prioritized registry and executes them sequentially\n * in priority order.\n */\nexport class HookDispatcher<\n HookMap extends Record<keyof HookMap, Middleware<unknown>>,\n Meta = undefined,\n> {\n readonly #registry = new Map<\n keyof HookMap,\n Registration<keyof HookMap, InferContext<HookMap[keyof HookMap]>, Meta>[]\n >()\n\n readonly #interceptor:\n | Interceptor<keyof HookMap, InferContext<HookMap[keyof HookMap]>, Meta>\n | undefined\n\n /**\n * Create a hook dispatcher.\n *\n * @param interceptor Wrapper invoked in place of every registered\n * middleware during dispatch\n */\n constructor(\n interceptor?: Interceptor<\n keyof HookMap,\n InferContext<HookMap[keyof HookMap]>,\n Meta\n >\n ) {\n this.#interceptor = interceptor\n }\n\n /**\n * Register middleware for a specific hook.\n *\n * Adds the `middleware` to the internal registry for `hook` and sorts the\n * list so higher-priority middleware runs first. An omitted or `undefined`\n * `options.priority` defaults to `Priority.Normal`; `options.meta` is\n * carried on the registration for the constructor interceptor.\n *\n * @param hook Name of the hook to register\n * @param middleware Function executed when the hook dispatches\n * @param options Registration options carrying the execution order rank and\n * the metadata exposed to the constructor interceptor\n */\n on<HookName extends keyof HookMap>(\n hook: HookName,\n middleware: Middleware<InferContext<HookMap[HookName]>>,\n options?: RegistrationOptions<Meta>\n ): void {\n const registrations = this.#registry.get(hook) ?? []\n\n registrations.push({\n hook,\n middleware,\n priority: options?.priority ?? Priority.Normal,\n meta: options?.meta,\n })\n\n registrations.sort((a, b) => b.priority - a.priority)\n\n this.#registry.set(hook, registrations)\n }\n\n /**\n * Unregister middleware from a specific hook.\n *\n * Removes matching `middleware` references from the internal registry for\n * `hook`. Takes no action if `hook` has no registered middleware.\n *\n * @param hook Name of the hook to unregister from\n * @param middleware Reference of the middleware function to remove\n */\n off<HookName extends keyof HookMap>(\n hook: HookName,\n middleware: Middleware<InferContext<HookMap[HookName]>>\n ): void {\n const registrations = this.#registry.get(hook)\n\n if (!registrations) return\n\n this.#registry.set(\n hook,\n registrations.filter(\n (registration) => registration.middleware !== middleware\n )\n )\n }\n\n /**\n * Dispatch all middleware registered to a hook.\n *\n * Passes `context` through the middleware pipeline in descending priority\n * order and dispatches each registration through the constructor\n * interceptor when one is provided. Enables middleware to control\n * execution flow using `next` and executes `done` after the last\n * middleware completes.\n *\n * @param hook Name of the hook to dispatch\n * @param context Shared payload passed into each middleware\n * @param done Optional final callback run after the pipeline completes\n * @returns Promise that resolves when execution completes\n */\n async dispatch<HookName extends keyof HookMap>(\n hook: HookName,\n context: InferContext<HookMap[HookName]>,\n done?: Next<InferContext<HookMap[HookName]>>\n ): Promise<void> {\n type Context = InferContext<HookMap[HookName]>\n\n const registrations = this.#registry.get(hook) ?? []\n\n const interceptor = this.#interceptor\n\n const run = async (index: number, context: Context): Promise<void> => {\n const registration = registrations[index]\n\n if (!registration) {\n return done ? await done(context) : undefined\n }\n\n let isNextCalled = false\n\n const next: Next<Context> = async (context) => {\n if (isNextCalled) return\n isNextCalled = true\n return await run(index + 1, context)\n }\n\n const middleware: Middleware<Context> = interceptor\n ? (context, next) => interceptor(context, registration, next)\n : registration.middleware\n\n return await middleware(context, next)\n }\n\n return await run(0, context)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,YACd,KACA,KACA,UACwB;CACxB,OAAO,QAAQ,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,IAAI;AACtE;;;;;;;;;;;;ACbA,SAAgB,qBAAqB,kBAAyC;CAC5E,KAAK,MAAM,WAAW,yBAAyB,gBAAgB,GAC7D,OAAO;CAGT,OAAO;AACT;;;;;;;;;;;;;;;ACSA,eAAsB,mBACpB,KACA,KACA,SACqB;CACrB,IAAI,IAAI,KACN,OAAO,IAAI;CAGb,MAAM,gBAAgB,IAAI,iBAAA;CAE1B,MAAM,oBAAoB,KAAK,QAAQ,KAA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O,MAAM,KAAK,OAAO,IAAI,KAAA;GAGtC,IAAI,eAAe;GAEnB,MAAM,OAAsB,OAAO,YAAY;IAC7C,IAAI,cAAc;IAClB,eAAe;IACf,OAAO,MAAM,IAAI,QAAQ,GAAG,OAAO;GACrC;GAMA,OAAO,OAJiC,eACnC,SAAS,SAAS,YAAY,SAAS,cAAc,IAAI,IAC1D,aAAa,WAAA,CAEO,SAAS,IAAI;EACvC;EAEA,OAAO,MAAM,IAAI,GAAG,OAAO;CAC7B;AACF"}
|
package/dist/analyzer.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as deriveTransitionReleases, s as deriveChangeReleases, t as propagateDependencyUpdates } from "./propagateDependencyUpdates-QWn0H1qa.js";
|
|
2
|
+
import { t as readPackageHistory } from "./readPackageHistory-CN5nqMcE.js";
|
|
3
|
+
import { t as resolvePackageTag } from "./resolvePackageTag-cwqG1GGt.js";
|
|
4
|
+
import { t as version } from "./package-Bczytil1.js";
|
|
2
5
|
// src/analyzer.ts
|
|
3
6
|
/**
|
|
4
7
|
* Built-in plugin that inspects repository history and produces release plans for packages.
|
|
@@ -32,9 +35,15 @@ var analyzer = () => ({
|
|
|
32
35
|
for (const plan of context.plans) {
|
|
33
36
|
let history = [];
|
|
34
37
|
if (plan.package.entry || plan.package.name) {
|
|
35
|
-
const tag = plan.package.tag ?? await resolvePackageTag(context.cwd, plan.package
|
|
38
|
+
const tag = plan.package.tag ?? await resolvePackageTag(context.cwd, plan.package, {
|
|
39
|
+
logger: context.logger,
|
|
40
|
+
dryRun: context.dryRun
|
|
41
|
+
});
|
|
36
42
|
if (tag && !plan.package.tag) plan.package.tag = tag;
|
|
37
|
-
history = readPackageHistory(context.cwd, plan.package, tag ? {
|
|
43
|
+
history = readPackageHistory(context.cwd, plan.package, tag ? {
|
|
44
|
+
until: tag.name,
|
|
45
|
+
logger: context.logger
|
|
46
|
+
} : { logger: context.logger });
|
|
38
47
|
}
|
|
39
48
|
plans.push(...await deriveChangeReleases(context.type, context.classifier, [plan], history));
|
|
40
49
|
}
|
package/dist/analyzer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","names":[],"sources":["../src/analyzer.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { GitCommit, ReleasePlan, ReleasePlugin } from '#types'\nimport {\n deriveChangeReleases,\n deriveTransitionReleases,\n propagateDependencyUpdates,\n readPackageHistory,\n resolvePackageTag,\n} from '#workflow'\nimport { version } from '../package.json'\n\n/**\n * Built-in plugin that inspects repository history and produces release plans for packages.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `analyze`: Initializes release plans if empty, extracts unreleased Git\n * commit history, calculates package version bumps based on commit\n * classifications, handles transition releases for empty changesets (if\n * enabled), and propagates dependency updates across internal packages.\n *\n * History slicing starts at each package's own verified release tag: the\n * tag matching the package's current version is resolved and verified, and\n * only commits after it are analyzed. Packages that can never be tagged\n * (workspace packages without a name) are ignored: they keep their release\n * plan but receive no history-based release. Packages without a verified\n * tag are analyzed from the beginning of history.\n *\n * @returns A release plugin configured for package change analysis.\n */\nconst analyzer = (): ReleasePlugin => ({\n name: '@reelout/core/analyzer',\n version,\n analyze: async (context, next) => {\n if (context.plans.length === 0) {\n context.plans = context.packages.map((pkg): ReleasePlan => ({\n package: pkg,\n history: [],\n release: null,\n }))\n }\n\n const plans: ReleasePlan[] = []\n\n for (const plan of context.plans) {\n let history: Iterable<GitCommit> | AsyncIterable<GitCommit> = []\n\n if (plan.package.entry || plan.package.name) {\n const tag =\n plan.package.tag ??\n (await resolvePackageTag(context.cwd, plan.package))\n\n if (tag && !plan.package.tag) {\n plan.package.tag = tag\n }\n\n history = readPackageHistory(\n context.cwd,\n plan.package,\n tag
|
|
1
|
+
{"version":3,"file":"analyzer.js","names":[],"sources":["../src/analyzer.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { GitCommit, ReleasePlan, ReleasePlugin } from '#types'\nimport {\n deriveChangeReleases,\n deriveTransitionReleases,\n propagateDependencyUpdates,\n readPackageHistory,\n resolvePackageTag,\n} from '#workflow'\nimport { version } from '../package.json'\n\n/**\n * Built-in plugin that inspects repository history and produces release plans for packages.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `analyze`: Initializes release plans if empty, extracts unreleased Git\n * commit history, calculates package version bumps based on commit\n * classifications, handles transition releases for empty changesets (if\n * enabled), and propagates dependency updates across internal packages.\n *\n * History slicing starts at each package's own verified release tag: the\n * tag matching the package's current version is resolved and verified, and\n * only commits after it are analyzed. Packages that can never be tagged\n * (workspace packages without a name) are ignored: they keep their release\n * plan but receive no history-based release. Packages without a verified\n * tag are analyzed from the beginning of history.\n *\n * @returns A release plugin configured for package change analysis.\n */\nconst analyzer = (): ReleasePlugin => ({\n name: '@reelout/core/analyzer',\n version,\n analyze: async (context, next) => {\n if (context.plans.length === 0) {\n context.plans = context.packages.map((pkg): ReleasePlan => ({\n package: pkg,\n history: [],\n release: null,\n }))\n }\n\n const plans: ReleasePlan[] = []\n\n for (const plan of context.plans) {\n let history: Iterable<GitCommit> | AsyncIterable<GitCommit> = []\n\n if (plan.package.entry || plan.package.name) {\n const tag =\n plan.package.tag ??\n (await resolvePackageTag(context.cwd, plan.package, {\n logger: context.logger,\n dryRun: context.dryRun,\n }))\n\n if (tag && !plan.package.tag) {\n plan.package.tag = tag\n }\n\n history = readPackageHistory(\n context.cwd,\n plan.package,\n tag\n ? { until: tag.name, logger: context.logger }\n : { logger: context.logger }\n )\n }\n\n plans.push(\n ...(await deriveChangeReleases(\n context.type,\n context.classifier,\n [plan],\n history\n ))\n )\n }\n\n context.plans = plans\n\n if (context.allowEmpty) {\n context.plans = deriveTransitionReleases(\n context.type,\n context.versionQualifier,\n context.plans\n )\n }\n\n context.plans = await propagateDependencyUpdates(context.cwd, context.plans)\n\n return next(context)\n },\n})\n\nexport default analyzer\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,kBAAiC;CACrC,MAAM;CACN;CACA,SAAS,OAAO,SAAS,SAAS;EAChC,IAAI,QAAQ,MAAM,WAAW,GAC3B,QAAQ,QAAQ,QAAQ,SAAS,KAAK,SAAsB;GAC1D,SAAS;GACT,SAAS,CAAC;GACV,SAAS;EACX,EAAE;EAGJ,MAAM,QAAuB,CAAC;EAE9B,KAAK,MAAM,QAAQ,QAAQ,OAAO;GAChC,IAAI,UAA0D,CAAC;GAE/D,IAAI,KAAK,QAAQ,SAAS,KAAK,QAAQ,MAAM;IAC3C,MAAM,MACJ,KAAK,QAAQ,OACZ,MAAM,kBAAkB,QAAQ,KAAK,KAAK,SAAS;KAClD,QAAQ,QAAQ;KAChB,QAAQ,QAAQ;IAClB,CAAC;IAEH,IAAI,OAAO,CAAC,KAAK,QAAQ,KACvB,KAAK,QAAQ,MAAM;IAGrB,UAAU,mBACR,QAAQ,KACR,KAAK,SACL,MACI;KAAE,OAAO,IAAI;KAAM,QAAQ,QAAQ;IAAO,IAC1C,EAAE,QAAQ,QAAQ,OAAO,CAC/B;GACF;GAEA,MAAM,KACJ,GAAI,MAAM,qBACR,QAAQ,MACR,QAAQ,YACR,CAAC,IAAI,GACL,OACF,CACF;EACF;EAEA,QAAQ,QAAQ;EAEhB,IAAI,QAAQ,YACV,QAAQ,QAAQ,yBACd,QAAQ,MACR,QAAQ,kBACR,QAAQ,KACV;EAGF,QAAQ,QAAQ,MAAM,2BAA2B,QAAQ,KAAK,QAAQ,KAAK;EAE3E,OAAO,KAAK,OAAO;CACrB;AACF"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { N as SEMVER_REGEX, w as formatError } from "./package-Bczytil1.js";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
import prettier from "prettier";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
6
|
+
import createPreset from "conventional-changelog-conventionalcommits";
|
|
7
|
+
import { writeChangelogString } from "conventional-changelog-writer";
|
|
8
|
+
// src/util/isDefined.ts
|
|
9
|
+
/**
|
|
10
|
+
* Type guard that asserts a value is neither `null` nor `undefined`.
|
|
11
|
+
*
|
|
12
|
+
* @param value Value to test
|
|
13
|
+
* @returns `true` when `value` is not `null` or `undefined`
|
|
14
|
+
*/
|
|
15
|
+
function isDefined(value) {
|
|
16
|
+
return value != null;
|
|
17
|
+
}
|
|
18
|
+
// src/util/compact.ts
|
|
19
|
+
/**
|
|
20
|
+
* Remove `null` and `undefined` values from an array.
|
|
21
|
+
*
|
|
22
|
+
* @param array The array to compact
|
|
23
|
+
* @returns A new array that does not contain `null` or `undefined` values
|
|
24
|
+
*/
|
|
25
|
+
function compact(array) {
|
|
26
|
+
return array.filter(isDefined);
|
|
27
|
+
}
|
|
28
|
+
// src/util/formatFile.ts
|
|
29
|
+
/**
|
|
30
|
+
* Format `content` for `filePath` using Prettier when possible.
|
|
31
|
+
*
|
|
32
|
+
* Resolves project/editorconfig settings and formats the provided content.
|
|
33
|
+
* Returns the original content on error or when no parser is inferred, and
|
|
34
|
+
* reports the failure through `logger` at debug level when one is provided.
|
|
35
|
+
*
|
|
36
|
+
* @param filePath Path used to infer parser and config
|
|
37
|
+
* @param content Source content to format
|
|
38
|
+
* @param logger Optional logger that receives formatting failures
|
|
39
|
+
* @returns Formatted content or original content on failure
|
|
40
|
+
*/
|
|
41
|
+
async function formatFile(filePath, content, logger) {
|
|
42
|
+
try {
|
|
43
|
+
const info = await prettier.getFileInfo(filePath, { resolveConfig: true });
|
|
44
|
+
const config = await prettier.resolveConfig(filePath, { editorconfig: true });
|
|
45
|
+
if (info.inferredParser == null) return content;
|
|
46
|
+
return await prettier.format(content, {
|
|
47
|
+
...config,
|
|
48
|
+
parser: info.inferredParser,
|
|
49
|
+
filepath: filePath
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger?.debug(`Formatting "${filePath}" failed and content stays unformatted: ${formatError(error)}`);
|
|
53
|
+
return content;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// src/workflow/changelog/extractPlainText.ts
|
|
57
|
+
/**
|
|
58
|
+
* Extract trimmed plain text from a Heading, Paragraph, or PhrasingContent node.
|
|
59
|
+
*
|
|
60
|
+
* Performs a depth-first traversal, concatenating string `value` tokens in
|
|
61
|
+
* document order. Non-string values are ignored. Returns `null` for empty or
|
|
62
|
+
* missing input.
|
|
63
|
+
*
|
|
64
|
+
* @param node Node to extract text from
|
|
65
|
+
* @returns The trimmed plain-text string, or null if empty
|
|
66
|
+
*/
|
|
67
|
+
function extractPlainText(node) {
|
|
68
|
+
if (!node) return null;
|
|
69
|
+
const queue = [node];
|
|
70
|
+
let result = "";
|
|
71
|
+
while (node = queue.shift()) {
|
|
72
|
+
if ("value" in node && typeof node.value === "string") result += node.value;
|
|
73
|
+
/* istanbul ignore else */
|
|
74
|
+
if ("children" in node && Array.isArray(node.children)) queue.unshift(...node.children);
|
|
75
|
+
}
|
|
76
|
+
return result.trim() || null;
|
|
77
|
+
}
|
|
78
|
+
// src/workflow/changelog/extractSemVer.ts
|
|
79
|
+
var ANCHORED_SEMVER_REGEX = new RegExp(`^${SEMVER_REGEX.source}$`);
|
|
80
|
+
var BRACKETED_SEMVER_REGEX = new RegExp(`\\[${SEMVER_REGEX.source}\\]`);
|
|
81
|
+
/**
|
|
82
|
+
* Extract SemVer core strings from a line.
|
|
83
|
+
*
|
|
84
|
+
* Splits the line on runs of spaces or tabs and on `..`/`...`. For each token,
|
|
85
|
+
* first attempts an anchored SemVer match (must match the whole token), then
|
|
86
|
+
* a bracketed match that finds a SemVer inside `[...]`. Returns the captured
|
|
87
|
+
* SemVer core (capture group 2) for each successful match; falsy results are
|
|
88
|
+
* filtered out.
|
|
89
|
+
*
|
|
90
|
+
* @param line Line to scan for SemVer cores
|
|
91
|
+
* @returns Array of extracted SemVer core strings; empty if none
|
|
92
|
+
*/
|
|
93
|
+
function extractSemVer(line) {
|
|
94
|
+
return compact(line.split(/[ \t]+|\.{2,3}/).map((token) => {
|
|
95
|
+
return (ANCHORED_SEMVER_REGEX.exec(token) ?? BRACKETED_SEMVER_REGEX.exec(token))?.at(2);
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
// src/workflow/changelog/iterateChangelogVersions.ts
|
|
99
|
+
var SENTENCE_TERMINAL_REGEX = /\p{Sentence_Terminal}$/u;
|
|
100
|
+
/**
|
|
101
|
+
* Iterate over Semantic Version strings extracted from a Markdown changelog.
|
|
102
|
+
*
|
|
103
|
+
* Parses `changelogContent` into an AST and evaluates nodes sequentially using
|
|
104
|
+
* custom extractors. Evaluates heading nodes first before checking short
|
|
105
|
+
* paragraph nodes. Stops execution after the first strategy yields valid
|
|
106
|
+
* versions.
|
|
107
|
+
*
|
|
108
|
+
* @param changelogContent Raw Markdown text of the changelog
|
|
109
|
+
* @yields Valid SemVer strings found in headings or candidate paragraphs
|
|
110
|
+
*/
|
|
111
|
+
function* iterateChangelogVersions(changelogContent) {
|
|
112
|
+
const root = fromMarkdown(changelogContent);
|
|
113
|
+
const nodeExtractors = [(node) => {
|
|
114
|
+
return node.type === "heading" ? extractPlainText(node) : null;
|
|
115
|
+
}, (node) => {
|
|
116
|
+
if (node.type !== "paragraph") return null;
|
|
117
|
+
const paragraphText = extractPlainText(node);
|
|
118
|
+
if (!paragraphText || paragraphText.length > 48 || SENTENCE_TERMINAL_REGEX.test(paragraphText)) return null;
|
|
119
|
+
return paragraphText;
|
|
120
|
+
}];
|
|
121
|
+
for (const extractText of nodeExtractors) {
|
|
122
|
+
let isVersionFound = false;
|
|
123
|
+
for (const node of root.children) {
|
|
124
|
+
const extractedText = extractText(node);
|
|
125
|
+
const candidateVersion = extractedText ? semver.sort(extractSemVer(extractedText)).pop() : null;
|
|
126
|
+
if (candidateVersion && semver.valid(candidateVersion)) {
|
|
127
|
+
isVersionFound = true;
|
|
128
|
+
yield candidateVersion;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (isVersionFound) return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// src/workflow/changelog/buildChangelog.ts
|
|
135
|
+
var presetCache;
|
|
136
|
+
/**
|
|
137
|
+
* Load the conventional commits preset on first use.
|
|
138
|
+
*
|
|
139
|
+
* Creating the preset performs setup work that used to run at import time
|
|
140
|
+
* through a module-level await; loading it lazily keeps importing this
|
|
141
|
+
* module synchronous and skips the cost for consumers that never build a
|
|
142
|
+
* changelog.
|
|
143
|
+
*
|
|
144
|
+
* @returns The cached preset, created on the first call
|
|
145
|
+
*/
|
|
146
|
+
async function loadPreset() {
|
|
147
|
+
presetCache ??= await createPreset();
|
|
148
|
+
return presetCache;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Build the changelog string for a release.
|
|
152
|
+
*
|
|
153
|
+
* Compiles commit history and release context into a formatted changelog using
|
|
154
|
+
* conventional commits and writer configurations. Resolves file paths and handles
|
|
155
|
+
* tag comparisons when repository URLs are available.
|
|
156
|
+
*
|
|
157
|
+
* @param context The release context containing repository and working directory details
|
|
158
|
+
* @param history The iterable or async iterable collection of commits to process
|
|
159
|
+
* @param options The build configuration options for the changelog
|
|
160
|
+
* @returns The formatted changelog content string
|
|
161
|
+
*/
|
|
162
|
+
async function buildChangelog(context, history, options = {}) {
|
|
163
|
+
const preset = await loadPreset();
|
|
164
|
+
const repository = context.repository?.url || void 0;
|
|
165
|
+
const version = options.version || void 0;
|
|
166
|
+
const previousTag = options.previousTag || void 0;
|
|
167
|
+
const currentTag = options.currentTag || void 0;
|
|
168
|
+
const filePath = path.join(context.cwd, options.packageDir || ".", options.changelogFile || "CHANGELOG.md");
|
|
169
|
+
const headerPartial = (context) => {
|
|
170
|
+
return context.version ? preset.writer.headerPartial?.(context) : void 0;
|
|
171
|
+
};
|
|
172
|
+
return formatFile(filePath, await writeChangelogString(history, {
|
|
173
|
+
date: context.today,
|
|
174
|
+
version,
|
|
175
|
+
previousTag,
|
|
176
|
+
currentTag,
|
|
177
|
+
linkCompare: !!repository && !!previousTag && !!currentTag,
|
|
178
|
+
linkReferences: !!repository,
|
|
179
|
+
repoUrl: repository,
|
|
180
|
+
commit: "commit",
|
|
181
|
+
issue: "issues",
|
|
182
|
+
headerPartial
|
|
183
|
+
}, preset.writer), context.logger);
|
|
184
|
+
}
|
|
185
|
+
export { formatFile as a, extractPlainText as i, iterateChangelogVersions as n, compact as o, extractSemVer as r, isDefined as s, buildChangelog as t };
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=buildChangelog-Cxm9_lq2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildChangelog-Cxm9_lq2.js","names":[],"sources":["../src/util/isDefined.ts","../src/util/compact.ts","../src/util/formatFile.ts","../src/workflow/changelog/extractPlainText.ts","../src/workflow/changelog/extractSemVer.ts","../src/workflow/changelog/iterateChangelogVersions.ts","../src/workflow/changelog/buildChangelog.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Type guard that asserts a value is neither `null` nor `undefined`.\n *\n * @param value Value to test\n * @returns `true` when `value` is not `null` or `undefined`\n */\nexport function isDefined<T>(value: T): value is NonNullable<T> {\n return value != null\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { isDefined } from './isDefined'\n\n/**\n * Remove `null` and `undefined` values from an array.\n *\n * @param array The array to compact\n * @returns A new array that does not contain `null` or `undefined` values\n */\nexport function compact<T>(array: readonly (T | null | undefined)[]): T[] {\n return array.filter(isDefined)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ConsolaInstance } from 'consola/core'\nimport prettier from 'prettier'\nimport { formatError } from './formatError'\n\n/**\n * Format `content` for `filePath` using Prettier when possible.\n *\n * Resolves project/editorconfig settings and formats the provided content.\n * Returns the original content on error or when no parser is inferred, and\n * reports the failure through `logger` at debug level when one is provided.\n *\n * @param filePath Path used to infer parser and config\n * @param content Source content to format\n * @param logger Optional logger that receives formatting failures\n * @returns Formatted content or original content on failure\n */\nexport async function formatFile(\n filePath: string,\n content: string,\n logger?: ConsolaInstance\n): Promise<string> {\n try {\n const info = await prettier.getFileInfo(filePath, {\n resolveConfig: true,\n })\n\n const config = await prettier.resolveConfig(filePath, {\n editorconfig: true,\n })\n\n if (info.inferredParser == null) {\n return content\n }\n\n return await prettier.format(content, {\n ...config,\n parser: info.inferredParser,\n filepath: filePath,\n })\n } catch (error: unknown) {\n logger?.debug(\n `Formatting \"${filePath}\" failed and content stays unformatted: ${formatError(error)}`\n )\n\n return content\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Heading, Paragraph, PhrasingContent } from 'mdast'\n\n/**\n * Extract trimmed plain text from a Heading, Paragraph, or PhrasingContent node.\n *\n * Performs a depth-first traversal, concatenating string `value` tokens in\n * document order. Non-string values are ignored. Returns `null` for empty or\n * missing input.\n *\n * @param node Node to extract text from\n * @returns The trimmed plain-text string, or null if empty\n */\nexport function extractPlainText(\n node: Heading | Paragraph | PhrasingContent | null | undefined\n): string | null {\n if (!node) {\n return null\n }\n\n const queue = [node]\n let result = ''\n\n while ((node = queue.shift())) {\n if ('value' in node && typeof node.value === 'string') {\n result += node.value\n }\n\n /* istanbul ignore else */\n if ('children' in node && Array.isArray(node.children)) {\n queue.unshift(...node.children)\n }\n }\n\n return result.trim() || null\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { SEMVER_REGEX } from '#config'\nimport { compact } from '#util'\n\nconst ANCHORED_SEMVER_REGEX = new RegExp(`^${SEMVER_REGEX.source}$`)\n\nconst BRACKETED_SEMVER_REGEX = new RegExp(`\\\\[${SEMVER_REGEX.source}\\\\]`)\n\n/**\n * Extract SemVer core strings from a line.\n *\n * Splits the line on runs of spaces or tabs and on `..`/`...`. For each token,\n * first attempts an anchored SemVer match (must match the whole token), then\n * a bracketed match that finds a SemVer inside `[...]`. Returns the captured\n * SemVer core (capture group 2) for each successful match; falsy results are\n * filtered out.\n *\n * @param line Line to scan for SemVer cores\n * @returns Array of extracted SemVer core strings; empty if none\n */\nexport function extractSemVer(line: string): string[] {\n const tokens = line.split(/[ \\t]+|\\.{2,3}/)\n\n return compact(\n tokens.map((token) => {\n return (\n ANCHORED_SEMVER_REGEX.exec(token) ?? BRACKETED_SEMVER_REGEX.exec(token)\n )?.at(2)\n })\n )\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { RootContent } from 'mdast'\nimport { fromMarkdown } from 'mdast-util-from-markdown'\nimport semver from 'semver'\nimport { extractPlainText } from './extractPlainText'\nimport { extractSemVer } from './extractSemVer'\n\nconst SENTENCE_TERMINAL_REGEX = /\\p{Sentence_Terminal}$/u\n\n/**\n * Iterate over Semantic Version strings extracted from a Markdown changelog.\n *\n * Parses `changelogContent` into an AST and evaluates nodes sequentially using\n * custom extractors. Evaluates heading nodes first before checking short\n * paragraph nodes. Stops execution after the first strategy yields valid\n * versions.\n *\n * @param changelogContent Raw Markdown text of the changelog\n * @yields Valid SemVer strings found in headings or candidate paragraphs\n */\nexport function* iterateChangelogVersions(\n changelogContent: string\n): Generator<string> {\n const root = fromMarkdown(changelogContent)\n\n const nodeExtractors = [\n (node: RootContent): string | null => {\n return node.type === 'heading' ? extractPlainText(node) : null\n },\n\n (node: RootContent): string | null => {\n if (node.type !== 'paragraph') return null\n\n const paragraphText = extractPlainText(node)\n\n if (\n !paragraphText ||\n paragraphText.length > 48 ||\n SENTENCE_TERMINAL_REGEX.test(paragraphText)\n ) {\n return null\n }\n\n return paragraphText\n },\n ]\n\n for (const extractText of nodeExtractors) {\n let isVersionFound = false\n\n for (const node of root.children) {\n const extractedText = extractText(node)\n\n const candidateVersion = extractedText\n ? semver.sort(extractSemVer(extractedText)).pop()\n : null\n\n if (candidateVersion && semver.valid(candidateVersion)) {\n isVersionFound = true\n yield candidateVersion\n }\n }\n\n if (isVersionFound) {\n return\n }\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { DEFAULT_CHANGELOG_FILE } from '#config'\nimport type { GitCommit, ReleaseContext } from '#types'\nimport { formatFile } from '#util'\nimport createPreset from 'conventional-changelog-conventionalcommits'\nimport {\n writeChangelogString,\n type CommitKnownProps,\n type FinalTemplateContext,\n type Options,\n type TemplateContext,\n} from 'conventional-changelog-writer'\nimport path from 'node:path'\n\nexport interface BuildChangelogOptions {\n packageDir?: string | undefined\n changelogFile?: string | undefined\n version?: string | null | undefined\n previousTag?: string | null | undefined\n currentTag?: string | null | undefined\n}\n\ninterface ConventionalCommitsPreset {\n writer: Options\n}\n\nlet presetCache: ConventionalCommitsPreset | undefined\n\n/**\n * Load the conventional commits preset on first use.\n *\n * Creating the preset performs setup work that used to run at import time\n * through a module-level await; loading it lazily keeps importing this\n * module synchronous and skips the cost for consumers that never build a\n * changelog.\n *\n * @returns The cached preset, created on the first call\n */\nasync function loadPreset(): Promise<ConventionalCommitsPreset> {\n presetCache ??= await createPreset()\n\n return presetCache\n}\n\n/**\n * Build the changelog string for a release.\n *\n * Compiles commit history and release context into a formatted changelog using\n * conventional commits and writer configurations. Resolves file paths and handles\n * tag comparisons when repository URLs are available.\n *\n * @param context The release context containing repository and working directory details\n * @param history The iterable or async iterable collection of commits to process\n * @param options The build configuration options for the changelog\n * @returns The formatted changelog content string\n */\nexport async function buildChangelog(\n context: ReleaseContext,\n history: Iterable<GitCommit> | AsyncIterable<GitCommit>,\n options: BuildChangelogOptions = {}\n): Promise<string> {\n const preset = await loadPreset()\n\n const repository = context.repository?.url || undefined\n\n const version = options.version || undefined\n\n const previousTag = options.previousTag || undefined\n\n const currentTag = options.currentTag || undefined\n\n const filePath = path.join(\n context.cwd,\n options.packageDir || '.',\n options.changelogFile || DEFAULT_CHANGELOG_FILE\n )\n\n const headerPartial = (context: FinalTemplateContext) => {\n return context.version ? preset.writer.headerPartial?.(context) : undefined\n }\n\n const content = await writeChangelogString<CommitKnownProps>(\n history,\n {\n date: context.today,\n version,\n previousTag,\n currentTag,\n linkCompare: !!repository && !!previousTag && !!currentTag,\n linkReferences: !!repository,\n repoUrl: repository,\n commit: 'commit',\n issue: 'issues',\n headerPartial,\n } as TemplateContext,\n preset.writer\n )\n\n return formatFile(filePath, content, context.logger)\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAgB,UAAa,OAAmC;CAC9D,OAAO,SAAS;AAClB;;;;;;;;ACAA,SAAgB,QAAW,OAA+C;CACxE,OAAO,MAAM,OAAO,SAAS;AAC/B;;;;;;;;;;;;;;ACMA,eAAsB,WACpB,UACA,SACA,QACiB;CACjB,IAAI;EACF,MAAM,OAAO,MAAM,SAAS,YAAY,UAAU,EAChD,eAAe,KACjB,CAAC;EAED,MAAM,SAAS,MAAM,SAAS,cAAc,UAAU,EACpD,cAAc,KAChB,CAAC;EAED,IAAI,KAAK,kBAAkB,MACzB,OAAO;EAGT,OAAO,MAAM,SAAS,OAAO,SAAS;GACpC,GAAG;GACH,QAAQ,KAAK;GACb,UAAU;EACZ,CAAC;CACH,SAAS,OAAgB;EACvB,QAAQ,MACN,eAAe,SAAS,0CAA0C,YAAY,KAAK,GACrF;EAEA,OAAO;CACT;AACF;;;;;;;;;;;;AClCA,SAAgB,iBACd,MACe;CACf,IAAI,CAAC,MACH,OAAO;CAGT,MAAM,QAAQ,CAAC,IAAI;CACnB,IAAI,SAAS;CAEb,OAAQ,OAAO,MAAM,MAAM,GAAI;EAC7B,IAAI,WAAW,QAAQ,OAAO,KAAK,UAAU,UAC3C,UAAU,KAAK;;EAIjB,IAAI,cAAc,QAAQ,MAAM,QAAQ,KAAK,QAAQ,GACnD,MAAM,QAAQ,GAAG,KAAK,QAAQ;CAElC;CAEA,OAAO,OAAO,KAAK,KAAK;AAC1B;;AC/BA,IAAM,wBAAwB,IAAI,OAAO,IAAI,aAAa,OAAO,EAAE;AAEnE,IAAM,yBAAyB,IAAI,OAAO,MAAM,aAAa,OAAO,IA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