@releasekit/notes 0.44.1 → 0.46.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/README.md +6 -6
- package/dist/{aggregator-JHRFNT67.js → aggregator-XM2XIYDF.js} +1 -2
- package/dist/{chunk-VD3TYCTF.js → chunk-EI7LLVJN.js} +294 -140
- package/dist/{chunk-KTLNPX37.js → chunk-JOA56Y7A.js} +261 -203
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +108 -23
- package/dist/index.js +12 -10
- package/docs/llm-providers.md +7 -6
- package/docs/llm-release-notes.md +15 -39
- package/docs/monorepo.md +41 -0
- package/docs/templates.md +73 -58
- package/package.json +2 -2
- package/templates/angular/document.hbs +12 -0
- package/templates/angular/entry.hbs +1 -2
- package/templates/angular/version.hbs +14 -4
- package/templates/github-release/release.md.ejs +40 -15
- package/templates/keep-a-changelog/document.liquid +11 -0
- package/templates/keep-a-changelog/entry.liquid +1 -2
- package/templates/keep-a-changelog/version.liquid +19 -52
- package/dist/chunk-YCULLVSG.js +0 -150
package/README.md
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
**Changelog and release notes generation from conventional commits**
|
|
11
11
|
|
|
12
|
-
Generates CHANGELOG.md and release notes from `@releasekit/version` output, with optional LLM-
|
|
12
|
+
Generates CHANGELOG.md and release notes from `@releasekit/version` output, with flexible templating and optional LLM-enhanced release notes.
|
|
13
13
|
|
|
14
14
|
## Features
|
|
15
15
|
|
|
16
16
|
- 📝 **Conventional changelog** — Keep a Changelog, Angular, or custom format
|
|
17
|
-
- 🤖 **LLM
|
|
17
|
+
- 🤖 **LLM-enhanced release notes** (optional) — enhance descriptions, summarize, categorize, or generate prose; `CHANGELOG.md` stays commit-derived
|
|
18
18
|
- 🎨 **Flexible templating** — Liquid, Handlebars, or EJS; single-file or composable layout
|
|
19
19
|
- 📦 **Monorepo support** — root aggregation, per-package changelogs, or both
|
|
20
20
|
- 🔀 **Changelog + release notes** — a cumulative `CHANGELOG.md` and per-release notes (GitHub release body, or opt-in per-version files), configured independently
|
|
@@ -48,8 +48,9 @@ releasekit-notes --input version-data.json
|
|
|
48
48
|
# Preview without writing
|
|
49
49
|
releasekit-notes --dry-run
|
|
50
50
|
|
|
51
|
-
# With LLM
|
|
51
|
+
# With LLM-enhanced release notes
|
|
52
52
|
releasekit-notes --input version-data.json \
|
|
53
|
+
--release-notes-dir release-notes \
|
|
53
54
|
--llm-provider openai \
|
|
54
55
|
--llm-model gpt-4o-mini \
|
|
55
56
|
--llm-tasks enhance,summarize
|
|
@@ -84,8 +85,7 @@ All options live under the `notes` key in `releasekit.config.json`:
|
|
|
84
85
|
"summarize": true
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
}
|
|
88
|
-
"updateStrategy": "prepend"
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
```
|
|
@@ -107,7 +107,7 @@ LLM configuration lives under `notes.releaseNotes.llm`:
|
|
|
107
107
|
|
|
108
108
|
| Task | What it does |
|
|
109
109
|
|------|-------------|
|
|
110
|
-
| `enhance` | Rewrites each
|
|
110
|
+
| `enhance` | Rewrites each entry description in the release notes to be clearer |
|
|
111
111
|
| `summarize` | Generates a one-paragraph summary of the release |
|
|
112
112
|
| `categorize` | Groups entries into semantic categories (default set: Breaking, New, Changed, Fixed, Developer) |
|
|
113
113
|
| `releaseNotes` | Generates full prose release notes (use as GitHub release body) |
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// src/monorepo/aggregator.ts
|
|
2
|
+
import * as fs5 from "fs";
|
|
3
|
+
import * as path6 from "path";
|
|
4
|
+
|
|
1
5
|
// ../core/dist/index.js
|
|
2
6
|
import fs from "fs";
|
|
3
7
|
import path from "path";
|
|
@@ -12,13 +16,11 @@ import * as fs3 from "fs";
|
|
|
12
16
|
import * as os from "os";
|
|
13
17
|
import * as path4 from "path";
|
|
14
18
|
var CODE_SPAN_OR_COMMENT_OPEN = /(?<!(?<!\\)\\(?:\\\\)*)`[^`]*`|<!--/g;
|
|
15
|
-
function escapeCommentOpeners(text
|
|
16
|
-
return text.replace(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return opts?.keepCodeSpans ? match : match.replaceAll("<!--", "<!\u200B--");
|
|
21
|
-
});
|
|
19
|
+
function escapeCommentOpeners(text) {
|
|
20
|
+
return text.replace(
|
|
21
|
+
CODE_SPAN_OR_COMMENT_OPEN,
|
|
22
|
+
(match) => match.startsWith("`") ? match.replaceAll("<!--", "<!\u200B--") : "<!--"
|
|
23
|
+
);
|
|
22
24
|
}
|
|
23
25
|
function parseGitHubOwnerRepo(repoUrl) {
|
|
24
26
|
const [, scpOwner, scpRepo] = repoUrl.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/) ?? [];
|
|
@@ -97,6 +99,18 @@ function removeDescriptionRefs(text, refs) {
|
|
|
97
99
|
return num !== void 0 && remove.has(Number(num)) ? "" : match;
|
|
98
100
|
}).trim();
|
|
99
101
|
}
|
|
102
|
+
function renderChangelogEntryLine(entry, mode, repoUrl, suffix = "") {
|
|
103
|
+
const description = neutralizeDescriptionRefs(
|
|
104
|
+
entry.description,
|
|
105
|
+
[...entry.issueIds ?? [], entry.prNumber],
|
|
106
|
+
mode,
|
|
107
|
+
repoUrl
|
|
108
|
+
);
|
|
109
|
+
const label = entry.leadIn || entry.scope;
|
|
110
|
+
const refs = renderIssueRefs(entry.issueIds ?? [], mode, repoUrl, entry.prNumber);
|
|
111
|
+
const line = `- ${label ? `**${label}**: ` : ""}${description}${refs ? ` ${refs}` : ""}${suffix}`;
|
|
112
|
+
return escapeCommentOpeners(escapeChangelogMentions(line));
|
|
113
|
+
}
|
|
100
114
|
var BREAKING_SECTION = "Breaking";
|
|
101
115
|
var DEMOTED_SECTION = "Dependencies & version bumps";
|
|
102
116
|
var CHANGELOG_TYPE_LABELS = {
|
|
@@ -122,8 +136,11 @@ var CHANGELOG_LABEL_ORDER = [...new Set(Object.values(CHANGELOG_TYPE_LABELS))];
|
|
|
122
136
|
function changelogTypeLabel(type) {
|
|
123
137
|
return Object.hasOwn(CHANGELOG_TYPE_LABELS, type) ? CHANGELOG_TYPE_LABELS[type] : type.charAt(0).toUpperCase() + type.slice(1);
|
|
124
138
|
}
|
|
125
|
-
|
|
126
|
-
|
|
139
|
+
var DEMOTED_SCOPES = /* @__PURE__ */ new Set(["deps", "deps-dev"]);
|
|
140
|
+
function groupChangelogSections(items, entryOf, categorized) {
|
|
141
|
+
if (categorized && categorized.categories.length > 0) {
|
|
142
|
+
return groupByCategory(categorized, entryOf);
|
|
143
|
+
}
|
|
127
144
|
const breaking = [];
|
|
128
145
|
const demoted = [];
|
|
129
146
|
const byLabel = /* @__PURE__ */ new Map();
|
|
@@ -131,7 +148,7 @@ function groupChangelogSections(items, entryOf, { demoteScopes = [] } = {}) {
|
|
|
131
148
|
const entry = entryOf(item);
|
|
132
149
|
if (entry.breaking) {
|
|
133
150
|
breaking.push(item);
|
|
134
|
-
} else if (entry.scope !== void 0 &&
|
|
151
|
+
} else if (entry.scope !== void 0 && DEMOTED_SCOPES.has(entry.scope)) {
|
|
135
152
|
demoted.push(item);
|
|
136
153
|
} else {
|
|
137
154
|
const label = changelogTypeLabel(entry.type);
|
|
@@ -162,6 +179,87 @@ function groupChangelogSections(items, entryOf, { demoteScopes = [] } = {}) {
|
|
|
162
179
|
}
|
|
163
180
|
return sections;
|
|
164
181
|
}
|
|
182
|
+
function groupByCategory({ categories, order = [] }, entryOf) {
|
|
183
|
+
const breaking = [];
|
|
184
|
+
const sections = categories.map(({ name, entries }) => ({
|
|
185
|
+
label: name,
|
|
186
|
+
items: entries.filter((item) => {
|
|
187
|
+
if (entryOf(item).breaking) {
|
|
188
|
+
breaking.push(item);
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
})
|
|
193
|
+
}));
|
|
194
|
+
const llmBreaking = sections.find((s) => s.label === BREAKING_SECTION);
|
|
195
|
+
if (llmBreaking) {
|
|
196
|
+
llmBreaking.items.unshift(...breaking);
|
|
197
|
+
} else {
|
|
198
|
+
sections.push({ label: BREAKING_SECTION, items: breaking });
|
|
199
|
+
}
|
|
200
|
+
const rank = (label) => {
|
|
201
|
+
const index = order.indexOf(label);
|
|
202
|
+
if (index !== -1) {
|
|
203
|
+
return index;
|
|
204
|
+
}
|
|
205
|
+
return label === BREAKING_SECTION ? -1 : order.length;
|
|
206
|
+
};
|
|
207
|
+
return sections.filter((s) => s.items.length > 0).sort((a, b) => rank(a.label) - rank(b.label));
|
|
208
|
+
}
|
|
209
|
+
var PROJECT_WIDE_HEADING = "Project-wide changes";
|
|
210
|
+
var entryKey = (e) => `${e.type}:${e.description}`;
|
|
211
|
+
function unlistedEntries(entries, listed) {
|
|
212
|
+
const keys = new Set(listed.map(entryKey));
|
|
213
|
+
return entries.filter((e) => !keys.has(entryKey(e)));
|
|
214
|
+
}
|
|
215
|
+
function sharedPackageEntriesFor(shared, own) {
|
|
216
|
+
return unlistedEntries(
|
|
217
|
+
shared.filter((e) => e.sharedPackage),
|
|
218
|
+
own
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
function sharedPackageEntriesOf(changelog, sharedEntries) {
|
|
222
|
+
return changelog.sharedPackageEntries ? [...changelog.sharedPackageEntries] : sharedPackageEntriesFor(sharedEntries, changelog.entries);
|
|
223
|
+
}
|
|
224
|
+
function renderChangelogSections(entries, level, mode, repoUrl) {
|
|
225
|
+
const hashes = "#".repeat(level);
|
|
226
|
+
return groupChangelogSections(entries, (e) => e).map(
|
|
227
|
+
(section) => `${hashes} ${section.label}
|
|
228
|
+
|
|
229
|
+
${section.items.map((e) => renderChangelogEntryLine(e, mode, repoUrl)).join("\n")}`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
function renderChangelogBlock(heading, level, entries, mode, repoUrl) {
|
|
233
|
+
return [`${"#".repeat(level)} ${heading}`, ...renderChangelogSections(entries, level + 1, mode, repoUrl)].join(
|
|
234
|
+
"\n\n"
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
function resolveBundled(bundled, releases) {
|
|
238
|
+
return (bundled ?? []).flatMap(({ packageName, versions }) => {
|
|
239
|
+
const entries = versions.flatMap(
|
|
240
|
+
(version) => (releases.find((r) => r.packageName === packageName && r.version === version)?.entries ?? []).filter(
|
|
241
|
+
(e) => !e.synthetic && e.description !== `Update version to ${version}`
|
|
242
|
+
)
|
|
243
|
+
);
|
|
244
|
+
const first = versions[0];
|
|
245
|
+
const last = versions.at(-1);
|
|
246
|
+
if (last === void 0 || entries.length === 0) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
return [{ packageName, ...versions.length > 1 ? { firstVersion: first } : {}, version: last, entries }];
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function renderBundledBlocks(packages, level, mode, repoUrl) {
|
|
253
|
+
return packages.map(
|
|
254
|
+
(p) => renderChangelogBlock(
|
|
255
|
+
`${p.packageName} ${p.firstVersion ? `${p.firstVersion} \u2192 ` : ""}${p.version}`,
|
|
256
|
+
level,
|
|
257
|
+
p.entries,
|
|
258
|
+
mode,
|
|
259
|
+
repoUrl
|
|
260
|
+
)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
165
263
|
var LOG_LEVELS = {
|
|
166
264
|
error: 0,
|
|
167
265
|
warn: 1,
|
|
@@ -375,103 +473,6 @@ function firstReleaseLine(context, config) {
|
|
|
375
473
|
const template = config?.text ?? DEFAULT_FIRST_RELEASE_TEXT;
|
|
376
474
|
return template.replaceAll("${packageName}", context.packageName).replaceAll("${version}", context.version);
|
|
377
475
|
}
|
|
378
|
-
function escapeCommitText(text) {
|
|
379
|
-
return escapeCommentOpeners(escapeChangelogMentions(text), { keepCodeSpans: true });
|
|
380
|
-
}
|
|
381
|
-
function formatEntry(entry, opts) {
|
|
382
|
-
const refsMode = opts?.refs ?? "link";
|
|
383
|
-
const appendedRefs = [...entry.issueIds ?? [], entry.prNumber];
|
|
384
|
-
const description = neutralizeDescriptionRefs(entry.description, appendedRefs, refsMode, opts?.repoUrl ?? null);
|
|
385
|
-
const { scope, leadIn } = entry;
|
|
386
|
-
let line;
|
|
387
|
-
if (leadIn && entry.breaking) {
|
|
388
|
-
line = `- **BREAKING** **${leadIn}**: ${description}`;
|
|
389
|
-
} else if (leadIn) {
|
|
390
|
-
line = `- **${leadIn}**: ${description}`;
|
|
391
|
-
} else if (entry.breaking && scope && !opts?.hideScope) {
|
|
392
|
-
line = `- **BREAKING** **${scope}**: ${description}`;
|
|
393
|
-
} else if (entry.breaking) {
|
|
394
|
-
line = `- **BREAKING** ${description}`;
|
|
395
|
-
} else if (scope && !opts?.hideScope) {
|
|
396
|
-
line = `- **${scope}**: ${description}`;
|
|
397
|
-
} else {
|
|
398
|
-
line = `- ${description}`;
|
|
399
|
-
}
|
|
400
|
-
const refs = renderIssueRefs(entry.issueIds ?? [], refsMode, opts?.repoUrl ?? null, entry.prNumber);
|
|
401
|
-
if (refs) {
|
|
402
|
-
line += ` ${refs}`;
|
|
403
|
-
}
|
|
404
|
-
return escapeCommitText(line);
|
|
405
|
-
}
|
|
406
|
-
function formatCategorySection(name, entries, refOpts) {
|
|
407
|
-
const blocks = [`### ${name}`];
|
|
408
|
-
const scopeCounts = /* @__PURE__ */ new Map();
|
|
409
|
-
for (const entry of entries) {
|
|
410
|
-
if (entry.scope) {
|
|
411
|
-
scopeCounts.set(entry.scope, (scopeCounts.get(entry.scope) ?? 0) + 1);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
const groupedScopes = /* @__PURE__ */ new Set();
|
|
415
|
-
for (const [scope, count] of scopeCounts) {
|
|
416
|
-
if (count > 1) {
|
|
417
|
-
groupedScopes.add(scope);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
const ungrouped = [];
|
|
421
|
-
const byScope = /* @__PURE__ */ new Map();
|
|
422
|
-
for (const entry of entries) {
|
|
423
|
-
if (entry.scope && groupedScopes.has(entry.scope)) {
|
|
424
|
-
const group = byScope.get(entry.scope) ?? [];
|
|
425
|
-
group.push(entry);
|
|
426
|
-
byScope.set(entry.scope, group);
|
|
427
|
-
} else {
|
|
428
|
-
ungrouped.push(entry);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (ungrouped.length > 0) {
|
|
432
|
-
blocks.push(ungrouped.map((entry) => formatEntry(entry, refOpts)).join("\n"));
|
|
433
|
-
}
|
|
434
|
-
for (const [scope, group] of byScope) {
|
|
435
|
-
blocks.push(
|
|
436
|
-
`**${escapeCommitText(scope)}**:`,
|
|
437
|
-
group.map((entry) => formatEntry(entry, { ...refOpts, hideScope: true })).join("\n")
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
return blocks;
|
|
441
|
-
}
|
|
442
|
-
function rerouteBreakingEntries(categories) {
|
|
443
|
-
const hasBreaking = categories.some((c) => c.entries.some((e) => e.breaking));
|
|
444
|
-
if (!hasBreaking) {
|
|
445
|
-
return categories;
|
|
446
|
-
}
|
|
447
|
-
const breakingEntries = [];
|
|
448
|
-
const stripped = categories.map((c) => ({
|
|
449
|
-
...c,
|
|
450
|
-
entries: c.entries.filter((e) => {
|
|
451
|
-
if (e.breaking) {
|
|
452
|
-
breakingEntries.push(e);
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
return true;
|
|
456
|
-
})
|
|
457
|
-
}));
|
|
458
|
-
const breakingCatIdx = stripped.findIndex((c) => c.name === BREAKING_SECTION);
|
|
459
|
-
if (breakingCatIdx >= 0) {
|
|
460
|
-
return stripped.map((c, i) => i === breakingCatIdx ? { ...c, entries: [...breakingEntries, ...c.entries] } : c);
|
|
461
|
-
}
|
|
462
|
-
return [{ name: BREAKING_SECTION, entries: breakingEntries }, ...stripped.filter((c) => c.entries.length > 0)];
|
|
463
|
-
}
|
|
464
|
-
function applyOrder(categories, order) {
|
|
465
|
-
if (order.length === 0) {
|
|
466
|
-
return categories;
|
|
467
|
-
}
|
|
468
|
-
return [...categories].sort((a, b) => {
|
|
469
|
-
const ai = order.indexOf(a.name);
|
|
470
|
-
const bi = order.indexOf(b.name);
|
|
471
|
-
const rank = (name, idx) => idx === -1 ? name === BREAKING_SECTION ? -1 : order.length : idx;
|
|
472
|
-
return rank(a.name, ai) - rank(b.name, bi);
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
476
|
function parseMdLink(text) {
|
|
476
477
|
let search = 0;
|
|
477
478
|
while (search < text.length) {
|
|
@@ -545,8 +546,19 @@ function resolveLinks(entries, linksConfig) {
|
|
|
545
546
|
}
|
|
546
547
|
return merged;
|
|
547
548
|
}
|
|
549
|
+
function versionSections(context, categoryOrder) {
|
|
550
|
+
const categories = context.enhanced?.categories;
|
|
551
|
+
return groupChangelogSections(
|
|
552
|
+
context.entries,
|
|
553
|
+
(e) => e,
|
|
554
|
+
categories ? { categories, order: categoryOrder } : void 0
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
function sharedPackageBlock(context, refs) {
|
|
558
|
+
return context.sharedEntries?.length ? renderChangelogBlock(PROJECT_WIDE_HEADING, 3, context.sharedEntries, refs, context.repoUrl) : void 0;
|
|
559
|
+
}
|
|
548
560
|
function formatVersion(context, options) {
|
|
549
|
-
const
|
|
561
|
+
const refs = options?.refs ?? "link";
|
|
550
562
|
const versionLabel = options?.includePackageName && context.packageName ? `${context.packageName}@${context.version}` : context.version;
|
|
551
563
|
const versionHeader = context.previousVersion ? `## [${versionLabel}]` : `## ${versionLabel}`;
|
|
552
564
|
const blocks = [`${versionHeader} - ${context.date}`];
|
|
@@ -560,15 +572,14 @@ function formatVersion(context, options) {
|
|
|
560
572
|
if (context.enhanced?.summary) {
|
|
561
573
|
blocks.push(context.enhanced.summary);
|
|
562
574
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
575
|
+
const categories = context.enhanced?.categories;
|
|
576
|
+
for (const section of versionSections(context, options?.categoryOrder)) {
|
|
577
|
+
blocks.push(
|
|
578
|
+
`### ${section.label}`,
|
|
579
|
+
section.items.map((entry) => renderChangelogEntryLine(entry, refs, context.repoUrl)).join("\n")
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
if (categories && categories.length > 0) {
|
|
572
583
|
const links = resolveLinks(context.entries, options?.links);
|
|
573
584
|
if (links.length > 0) {
|
|
574
585
|
blocks.push(
|
|
@@ -576,10 +587,10 @@ function formatVersion(context, options) {
|
|
|
576
587
|
links.map((link) => `- [${link.label}](${link.url})`).join("\n")
|
|
577
588
|
);
|
|
578
589
|
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
590
|
+
}
|
|
591
|
+
const shared = sharedPackageBlock(context, refs);
|
|
592
|
+
if (shared) {
|
|
593
|
+
blocks.push(shared);
|
|
583
594
|
}
|
|
584
595
|
return `${blocks.join("\n\n")}
|
|
585
596
|
`;
|
|
@@ -593,24 +604,48 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
593
604
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
594
605
|
`;
|
|
595
606
|
}
|
|
596
|
-
function renderMarkdown(contexts, options) {
|
|
607
|
+
function renderMarkdown(contexts, options, sharedEntries = []) {
|
|
597
608
|
const sections = [formatHeader()];
|
|
598
609
|
for (const context of contexts) {
|
|
599
610
|
sections.push(formatVersion(context, options));
|
|
600
611
|
}
|
|
612
|
+
const first = contexts[0];
|
|
613
|
+
if (first && sharedEntries.length > 0) {
|
|
614
|
+
const heading = `${PROJECT_WIDE_HEADING} - ${first.date}`;
|
|
615
|
+
sections.push(`${renderChangelogBlock(heading, 2, sharedEntries, options?.refs ?? "link", first.repoUrl)}
|
|
616
|
+
`);
|
|
617
|
+
}
|
|
601
618
|
return sections.join("\n");
|
|
602
619
|
}
|
|
603
|
-
|
|
620
|
+
var HEADING_RE = /^#{1,3} (.*)$/gm;
|
|
621
|
+
var LINK_TARGET_RE = /\]\([^()[\]]*\)/g;
|
|
622
|
+
function versionSectionsStart(markdown) {
|
|
623
|
+
for (const heading of markdown.matchAll(HEADING_RE)) {
|
|
624
|
+
if (/\d\.\d+\.\d/.test((heading[1] ?? "").replace(LINK_TARGET_RE, "]"))) {
|
|
625
|
+
return heading.index;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return -1;
|
|
629
|
+
}
|
|
630
|
+
function prependChangelog(existingPath, rendered) {
|
|
604
631
|
const existing = fs4.existsSync(existingPath) ? fs4.readFileSync(existingPath, "utf-8") : "";
|
|
605
632
|
if (existing.trim() === "") {
|
|
606
|
-
return
|
|
633
|
+
return rendered;
|
|
634
|
+
}
|
|
635
|
+
const sectionsStart = versionSectionsStart(rendered);
|
|
636
|
+
if (sectionsStart === -1) {
|
|
637
|
+
warn(
|
|
638
|
+
`Rendered changelog has no version heading (a "#", "##" or "###" heading with a version); nothing added to ${existingPath}`
|
|
639
|
+
);
|
|
640
|
+
return existing;
|
|
607
641
|
}
|
|
608
|
-
const sections =
|
|
609
|
-
|
|
642
|
+
const sections = `${rendered.slice(sectionsStart).trimEnd()}
|
|
643
|
+
`;
|
|
644
|
+
const headerEnd = versionSectionsStart(existing);
|
|
645
|
+
if (headerEnd === 0) {
|
|
610
646
|
return `${sections}
|
|
611
647
|
${existing}`;
|
|
612
648
|
}
|
|
613
|
-
const headerEnd = existing.indexOf("\n## ");
|
|
614
649
|
if (headerEnd === -1) {
|
|
615
650
|
return `${existing.trimEnd()}
|
|
616
651
|
|
|
@@ -619,32 +654,147 @@ ${sections}`;
|
|
|
619
654
|
return `${existing.slice(0, headerEnd).trimEnd()}
|
|
620
655
|
|
|
621
656
|
${sections}
|
|
622
|
-
${existing.slice(headerEnd
|
|
657
|
+
${existing.slice(headerEnd)}`;
|
|
623
658
|
}
|
|
624
|
-
function
|
|
625
|
-
const content = renderMarkdown(contexts, options);
|
|
626
|
-
const label = /changelog/i.test(outputPath) ? "Changelog" : "Release notes";
|
|
659
|
+
function writeChangelog(outputPath, content, dryRun) {
|
|
627
660
|
if (dryRun) {
|
|
628
|
-
info(`[DRY RUN]
|
|
661
|
+
info(`[DRY RUN] Changelog preview (would write to ${outputPath}):`);
|
|
629
662
|
info(content);
|
|
630
663
|
return;
|
|
631
664
|
}
|
|
665
|
+
if (outputPath === "-") {
|
|
666
|
+
process.stdout.write(content);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
632
669
|
const dir = path5.dirname(outputPath);
|
|
633
670
|
if (!fs4.existsSync(dir)) {
|
|
634
671
|
fs4.mkdirSync(dir, { recursive: true });
|
|
635
672
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
673
|
+
fs4.writeFileSync(outputPath, prependChangelog(outputPath, content), "utf-8");
|
|
674
|
+
success(`Changelog written to ${outputPath}`);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/monorepo/splitter.ts
|
|
678
|
+
function splitByPackage(contexts) {
|
|
679
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
680
|
+
for (const ctx of contexts) {
|
|
681
|
+
byPackage.set(ctx.packageName, ctx);
|
|
682
|
+
}
|
|
683
|
+
return byPackage;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/monorepo/aggregator.ts
|
|
687
|
+
function aggregateToRoot(contexts) {
|
|
688
|
+
const aggregated = {
|
|
689
|
+
packageName: "monorepo",
|
|
690
|
+
version: contexts[0]?.version ?? "0.0.0",
|
|
691
|
+
previousVersion: contexts[0]?.previousVersion ?? null,
|
|
692
|
+
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
|
|
693
|
+
repoUrl: contexts[0]?.repoUrl ?? null,
|
|
694
|
+
entries: []
|
|
695
|
+
};
|
|
696
|
+
for (const ctx of contexts) {
|
|
697
|
+
for (const entry of ctx.entries) {
|
|
698
|
+
aggregated.entries.push({
|
|
699
|
+
...entry,
|
|
700
|
+
scope: entry.scope ? `${ctx.packageName}/${entry.scope}` : ctx.packageName
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return aggregated;
|
|
705
|
+
}
|
|
706
|
+
function writeMonorepoChangelogs(contexts, options, render, dryRun) {
|
|
707
|
+
const files = [];
|
|
708
|
+
const byPackage = splitByPackage(contexts);
|
|
709
|
+
const packageDirMap = buildPackageDirMap(options.rootPath, options.packagesPath);
|
|
710
|
+
for (const [packageName, ctx] of byPackage) {
|
|
711
|
+
const simpleName = packageName.split("/").pop();
|
|
712
|
+
const packageDir = packageDirMap.get(packageName) ?? (simpleName ? packageDirMap.get(simpleName) : void 0) ?? null;
|
|
713
|
+
if (packageDir) {
|
|
714
|
+
const changelogPath = path6.join(packageDir, options.fileName ?? "CHANGELOG.md");
|
|
715
|
+
const content = render([ctx]);
|
|
716
|
+
if (dryRun) {
|
|
717
|
+
info(`Would write changelog for ${packageName} to ${changelogPath}`);
|
|
718
|
+
debug(content);
|
|
719
|
+
} else {
|
|
720
|
+
writeChangelog(changelogPath, content, false);
|
|
721
|
+
files.push(changelogPath);
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
info(`Could not find directory for package ${packageName}, skipping`);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return files;
|
|
728
|
+
}
|
|
729
|
+
function buildPackageDirMap(rootPath, packagesPath) {
|
|
730
|
+
const map = /* @__PURE__ */ new Map();
|
|
731
|
+
const packagesDir = path6.join(rootPath, packagesPath);
|
|
732
|
+
if (!fs5.existsSync(packagesDir)) {
|
|
733
|
+
return map;
|
|
734
|
+
}
|
|
735
|
+
for (const entry of fs5.readdirSync(packagesDir, { withFileTypes: true })) {
|
|
736
|
+
if (!entry.isDirectory()) {
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
const dirPath = path6.join(packagesDir, entry.name);
|
|
740
|
+
map.set(entry.name, dirPath);
|
|
741
|
+
const packageJsonPath = path6.join(dirPath, "package.json");
|
|
742
|
+
if (fs5.existsSync(packageJsonPath)) {
|
|
743
|
+
try {
|
|
744
|
+
const pkg = JSON.parse(fs5.readFileSync(packageJsonPath, "utf-8"));
|
|
745
|
+
if (pkg.name) {
|
|
746
|
+
map.set(pkg.name, dirPath);
|
|
747
|
+
}
|
|
748
|
+
} catch {
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return map;
|
|
753
|
+
}
|
|
754
|
+
function detectMonorepo(cwd) {
|
|
755
|
+
const pnpmWorkspacesPath = path6.join(cwd, "pnpm-workspace.yaml");
|
|
756
|
+
const packageJsonPath = path6.join(cwd, "package.json");
|
|
757
|
+
if (fs5.existsSync(pnpmWorkspacesPath)) {
|
|
758
|
+
const content = fs5.readFileSync(pnpmWorkspacesPath, "utf-8");
|
|
759
|
+
const packagesMatch = content.match(/packages:\s*\n\s*-\s*['"]([^'"]+)['"]/);
|
|
760
|
+
if (packagesMatch?.[1]) {
|
|
761
|
+
const packagesGlob = packagesMatch[1];
|
|
762
|
+
const packagesPath = packagesGlob.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
|
|
763
|
+
return { isMonorepo: true, packagesPath: packagesPath || "packages" };
|
|
764
|
+
}
|
|
765
|
+
return { isMonorepo: true, packagesPath: "packages" };
|
|
766
|
+
}
|
|
767
|
+
if (fs5.existsSync(packageJsonPath)) {
|
|
768
|
+
try {
|
|
769
|
+
const content = fs5.readFileSync(packageJsonPath, "utf-8");
|
|
770
|
+
const pkg = JSON.parse(content);
|
|
771
|
+
if (pkg.workspaces) {
|
|
772
|
+
const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
|
|
773
|
+
if (workspaces?.length) {
|
|
774
|
+
const firstWorkspace = workspaces[0];
|
|
775
|
+
if (firstWorkspace) {
|
|
776
|
+
const packagesPath = firstWorkspace.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
|
|
777
|
+
return { isMonorepo: true, packagesPath: packagesPath || "packages" };
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
} catch {
|
|
782
|
+
return { isMonorepo: false, packagesPath: "" };
|
|
783
|
+
}
|
|
639
784
|
}
|
|
640
|
-
|
|
641
|
-
fs4.writeFileSync(outputPath, updated, "utf-8");
|
|
642
|
-
success(`${label} written to ${outputPath}`);
|
|
785
|
+
return { isMonorepo: false, packagesPath: "" };
|
|
643
786
|
}
|
|
644
787
|
|
|
645
788
|
export {
|
|
646
789
|
parseGitHubOwnerRepo,
|
|
647
790
|
removeDescriptionRefs,
|
|
791
|
+
renderChangelogEntryLine,
|
|
792
|
+
BREAKING_SECTION,
|
|
793
|
+
groupChangelogSections,
|
|
794
|
+
unlistedEntries,
|
|
795
|
+
sharedPackageEntriesOf,
|
|
796
|
+
resolveBundled,
|
|
797
|
+
renderBundledBlocks,
|
|
648
798
|
setLogLevel,
|
|
649
799
|
setQuietMode,
|
|
650
800
|
error,
|
|
@@ -657,8 +807,12 @@ export {
|
|
|
657
807
|
unwrapEnvelope,
|
|
658
808
|
readPackageVersion,
|
|
659
809
|
isPathWithinRoot,
|
|
810
|
+
versionSections,
|
|
811
|
+
sharedPackageBlock,
|
|
660
812
|
formatVersion,
|
|
661
813
|
renderMarkdown,
|
|
662
|
-
|
|
663
|
-
|
|
814
|
+
writeChangelog,
|
|
815
|
+
aggregateToRoot,
|
|
816
|
+
writeMonorepoChangelogs,
|
|
817
|
+
detectMonorepo
|
|
664
818
|
};
|