@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/docs/templates.md CHANGED
@@ -34,7 +34,7 @@ releasekit-notes --template ./my-changelog.liquid
34
34
  }
35
35
  ```
36
36
 
37
- The file receives the full [Document context](#document-context) and must render the complete changelog document.
37
+ The file receives the full [Document context](#document-context) and renders a changelog document, which is [merged into an existing file](#writing-to-an-existing-changelog).
38
38
 
39
39
  ### Composable directory layout
40
40
 
@@ -43,8 +43,8 @@ Pass a directory containing named template files. Each file renders a different
43
43
  ```
44
44
  templates/
45
45
  ├── document.liquid # Outer document wrapper (receives DocumentContext)
46
- ├── version.liquid # One version block (receives TemplateContext)
47
- └── entry.liquid # One changelog entry (receives ChangelogEntry fields directly)
46
+ ├── version.liquid # One version block (receives a Version, as `version` in Liquid)
47
+ └── entry.liquid # One changelog entry (receives an Entry)
48
48
  ```
49
49
 
50
50
  ```bash
@@ -53,7 +53,18 @@ releasekit-notes --template ./templates/
53
53
 
54
54
  All three files are optional — omit any you don't need to customise, and the built-in for that level is used.
55
55
 
56
- The `entry.liquid` template receives the `ChangelogEntry` fields directly as top-level variables: `type`, `description`, `scope`, `breaking`, `issueIds`, `leadIn`.
56
+ An entry template gets one [Entry](#entry). Handlebars and EJS entry templates get its fields directly, as in `{{{line}}}`. A Liquid include shares the caller's variables, so name the `version.liquid` loop variable `entry` and use `{{ entry.line }}`.
57
+
58
+ ### Writing to an existing changelog
59
+
60
+ A changelog template renders only this run's versions, in `versions`. How the output reaches the file:
61
+
62
+ - **New or empty file:** the whole output is written.
63
+ - **Existing file:** the output from its first version heading goes directly under the file's header, which is everything before the file's first version heading. A version heading is a `# `, `## ` or `### ` heading containing a version outside any link target, such as `## [1.2.0]`, `# [1.2.0](…) (2026-01-01)` or `## [@scope/pkg@1.2.0-next.0]`. `# Changelog` and `## [Unreleased]` aren't, so new versions go below an `## [Unreleased]` section. The rest of the file is kept. Anything the template renders before its first version heading, such as its own header, is dropped. Everything from that heading to the end of the output is inserted on every run, so render only version sections after the header: no footer, such as link reference definitions, and no fixed section, such as `## [Unreleased]`.
64
+
65
+ So start each version section with a version heading. If the output has none, an existing file is left unchanged and a warning is logged.
66
+
67
+ In `packages` and `both` modes, each package's changelog is rendered on its own: `versions` holds only that package's version, and `project.name` is the package name.
57
68
 
58
69
  ---
59
70
 
@@ -67,9 +78,10 @@ The outermost template (`document`) receives:
67
78
  |----------|------|-------------|
68
79
  | `project.name` | `string` | Repository/package name |
69
80
  | `project.repoUrl` | `string \| null` | Repository URL |
70
- | `versions` | `TemplateContext[]` | All rendered versions, newest first |
71
- | `unreleased` | `TemplateContext \| undefined` | Unreleased changes, if any |
81
+ | `versions` | `Version[]` | All rendered versions, newest first |
82
+ | `unreleased` | `Version \| undefined` | Unreleased changes, if any |
72
83
  | `compareUrls` | `Record<string, string> \| undefined` | Map of version → compare URL for all versions |
84
+ | `shared` | `Section[]` | A root changelog's [project-wide entries](monorepo.md#project-wide-changes) for the run, which the built-in renderer lists after the versions. Empty otherwise |
73
85
  | `perPackage` | `boolean \| undefined` | `true` when rendered inline for a single package (e.g. GitHub release body). Use this to suppress document-level headings that are redundant when the content is embedded in a release that already shows the package name and version. |
74
86
  | `output` | `'file' \| 'release' \| undefined` | Which release-notes destination this render targets: `'file'` (an in-repo per-version file) or `'release'` (the GitHub release body). Branch on it to emit content that only suits one — most importantly, docs-site **YAML frontmatter**, which would render as literal text in a GitHub release. |
75
87
 
@@ -96,8 +108,32 @@ Each version block (`version`) receives:
96
108
  | `date` | `string` | Release date in `YYYY-MM-DD` format |
97
109
  | `repoUrl` | `string \| null` | Repository URL |
98
110
  | `compareUrl` | `string \| undefined` | Link to diff between previous and current version |
99
- | `entries` | `ChangelogEntry[]` | Raw changelog entries |
100
- | `enhanced` | `EnhancedData \| undefined` | LLM-processed data (see below) |
111
+ | `entries` | `Entry[]` | Changelog entries in commit order. Release-notes templates get the LLM-rewritten entries when `tasks.enhance` is on; changelog templates always get the commit-derived ones |
112
+ | `sections` | `Section[]` | The same entries grouped as the built-in renderer groups them (see below) |
113
+ | `shared` | `Section[]` | [Shared-package entries](monorepo.md#project-wide-changes) in commit-type groups, which the built-in renderer lists under `### Project-wide changes` after the version's own. Empty in a root changelog |
114
+ | `bundled` | `Bundled[]` | A primary's [bundled packages](monorepo.md#bundled-release-notes), each with `packageName`, `version`, `firstVersion` (when it released more than once) and `sections`. Release notes only: empty in a changelog |
115
+ | `enhanced` | `object \| undefined` | LLM-written text (see below) |
116
+
117
+ ### Sections
118
+
119
+ Each section in `sections` has a `label` and its `entries`, in this order:
120
+
121
+ 1. `Breaking`, holding every breaking entry. With LLM categories, `categoryOrder` can place it later.
122
+ 2. With the `categorize` task on a release-notes template, the LLM categories, ordered by `categoryOrder`. Otherwise the commit types, labelled `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed` and `Security`, in that order.
123
+ 3. Without LLM categories, `Dependencies & version bumps`, holding non-breaking `deps` and `deps-dev` entries.
124
+
125
+ Empty sections are left out. To use your own heading, match the label:
126
+
127
+ ```liquid
128
+ {% for section in version.sections %}
129
+ ### {% if section.label == "Added" %}New{% else %}{{ section.label }}{% endif %}
130
+ {% for entry in section.entries %}
131
+ {{ entry.line }}
132
+ {% endfor %}
133
+ {% endfor %}
134
+ ```
135
+
136
+ A breaking entry is marked by its section, not its line. A template that lists the flat `entries` has to check `entry.breaking` itself.
101
137
 
102
138
  ### Entry
103
139
 
@@ -108,39 +144,31 @@ Each entry in `entries` has:
108
144
  | `type` | `ChangelogType` | `"added"`, `"changed"`, `"deprecated"`, `"removed"`, `"fixed"`, `"security"` |
109
145
  | `description` | `string` | Entry description (rewritten by LLM if `tasks.enhance` is on) |
110
146
  | `scope` | `string \| undefined` | Conventional commit scope (may be assigned or validated by LLM) |
111
- | `breaking` | `boolean \| undefined` | `true` for breaking changes |
147
+ | `breaking` | `boolean \| undefined` | `true` for breaking changes. Combined `enhanceAndCategorize` can also set it. |
112
148
  | `issueIds` | `string[] \| undefined` | Referenced issue/PR numbers |
113
149
  | `leadIn` | `string \| undefined` | Short scannable phrase for notable entries (e.g. `"Streaming API"`). Set by the LLM during `enhance` or combined `enhanceAndCategorize`. `undefined` for routine entries. |
150
+ | `line` | `string` | The built-in renderer's Markdown line: `- **scope**: description (refs)`, with the lead-in in the scope's place and refs rendered per `notes.changelog.refs` |
151
+
152
+ `line` has `@` mentions and `<!--` comment openers escaped; the other fields are raw commit or LLM text. Print it without the engine's HTML escaping: `{{{ line }}}` in Handlebars, `<%- line %>` in EJS. Liquid doesn't escape.
114
153
 
115
154
  ### Enhanced data (`enhanced`)
116
155
 
117
- Present when any LLM task ran successfully:
156
+ Present in release-notes templates when the `summarize` or `releaseNotes` task produced text. Changelog templates never get it:
118
157
 
119
158
  | Field | Type | Description |
120
159
  |-------|------|-------------|
121
- | `enhanced.entries` | `ChangelogEntry[]` | Entries with rewritten `description` fields (`enhance` task) |
122
160
  | `enhanced.summary` | `string \| undefined` | 2–3 sentence release summary (`summarize` task) |
123
- | `enhanced.categories` | `Category[] \| undefined` | Grouped entries (`categorize` task) |
124
161
  | `enhanced.releaseNotes` | `string \| undefined` | Full prose release notes (`releaseNotes` task) |
125
162
 
126
- Each `Category` in `enhanced.categories`:
127
-
128
- | Field | Type | Description |
129
- |-------|------|-------------|
130
- | `name` | `string` | Category display name |
131
- | `entries` | `ChangelogEntry[]` | Entries in this category (same type as `entries`; may have `leadIn`, `scope`, `breaking` populated by the LLM) |
132
-
133
- Entries within `enhanced.categories` are the same `ChangelogEntry` objects as in `entries`, with all LLM-assigned fields populated. Custom templates can access `entry.leadIn`, `entry.scope`, and `entry.breaking` directly.
163
+ The `categorize` task's categories come through `sections`.
134
164
 
135
165
  ### Built-in renderer behaviour
136
166
 
137
- When no custom template is configured, the built-in markdown renderer applies the following transformations to LLM-categorised output. Custom templates receive the raw data and must implement these behaviours themselves if desired.
138
-
139
- **Scope grouping:** Within a category, entries sharing the same scope value (two or more) are rendered under a `**scope**:` group header. Entries with a unique scope render with the scope inline (`**scope**: description`). Entries with no scope render as plain bullets.
167
+ When no custom template is configured, the built-in markdown renderer applies the following transformations to LLM-categorised output. Templates get the same grouping in `sections`.
140
168
 
141
- **Breaking change re-routing:** Any entry with `breaking: true` is moved to a `Breaking` category at render time, regardless of which category the LLM assigned it to. If no `Breaking` category exists, one is created and prepended before all other categories. Output without LLM categories gets the same leading `Breaking` section.
169
+ **Breaking change re-routing:** Any entry with `breaking: true` is moved to a `Breaking` category at render time, regardless of which category the LLM assigned it to. See [Sections](#sections) for the order.
142
170
 
143
- **`leadIn` prefix:** Entries with a `leadIn` value render as `**leadIn**: description`. Combined with `breaking: true`, the format is `**BREAKING** **leadIn**: description`.
171
+ **`leadIn` prefix:** Entries with a `leadIn` value render as `**leadIn**: description`, in place of the scope.
144
172
 
145
173
  **Links section:** When `notes.releaseNotes.links` is configured, a links section is appended after all categories. This section is only rendered in the LLM-categorised path.
146
174
 
@@ -156,10 +184,6 @@ When no custom template is configured, the built-in markdown renderer applies th
156
184
  {% for v in versions %}
157
185
  ## [{{ v.version }}] — {{ v.date }}
158
186
 
159
- {% if v.enhanced.summary %}
160
- {{ v.enhanced.summary }}
161
-
162
- {% endif %}
163
187
  {% for entry in v.entries %}
164
188
  - **{{ entry.type }}**: {{ entry.description }}{% if entry.scope %} *({{ entry.scope }})*{% endif %}
165
189
  {% endfor %}
@@ -170,31 +194,13 @@ When no custom template is configured, the built-in markdown renderer applies th
170
194
  ### Liquid (composable — `version.liquid`)
171
195
 
172
196
  ```liquid
173
- ## [{{ version }}]({{ compareUrl }}) — {{ date }}
174
-
175
- {% if enhanced.categories %}
176
- {% for cat in enhanced.categories %}
177
- ### {{ cat.name }}
178
-
179
- {% for entry in cat.entries %}
180
- {% if entry.breaking and entry.leadIn %}
181
- - **BREAKING** **{{ entry.leadIn }}**: {{ entry.description }}
182
- {% elsif entry.breaking %}
183
- - **BREAKING** {{ entry.description }}
184
- {% elsif entry.leadIn %}
185
- - **{{ entry.leadIn }}**: {{ entry.description }}
186
- {% elsif entry.scope %}
187
- - **{{ entry.scope }}**: {{ entry.description }}
188
- {% else %}
189
- - {{ entry.description }}
190
- {% endif %}
191
- {% endfor %}
197
+ ## [{{ version.version }}]({{ version.compareUrl }}) — {{ version.date }}
198
+ {% for section in version.sections %}
199
+ ### {{ section.label }}
200
+ {% for entry in section.entries %}
201
+ {{ entry.line }}
192
202
  {% endfor %}
193
- {% else %}
194
- {% for entry in entries %}
195
- - {{ entry.description }}
196
203
  {% endfor %}
197
- {% endif %}
198
204
  ```
199
205
 
200
206
  ### Handlebars (`version.hbs`)
@@ -203,24 +209,33 @@ When no custom template is configured, the built-in markdown renderer applies th
203
209
  ## [{{version}}] — {{date}}
204
210
 
205
211
  {{#if enhanced.summary}}
206
- > {{enhanced.summary}}
212
+ > {{{enhanced.summary}}}
207
213
 
208
214
  {{/if}}
215
+ {{#each sections}}
216
+ ### {{{label}}}
217
+
209
218
  {{#each entries}}
210
- - **{{type}}**: {{description}}
219
+ {{{line}}}
220
+ {{/each}}
221
+
211
222
  {{/each}}
212
223
  ```
213
224
 
214
- ### EJS (`release.md.ejs`)
225
+ ### EJS (composable — `version.ejs`)
215
226
 
216
227
  ```ejs
217
228
  ## <%= version %> — <%= date %>
218
229
 
219
230
  <% if (enhanced && enhanced.releaseNotes) { %>
220
- <%= enhanced.releaseNotes %>
231
+ <%- enhanced.releaseNotes %>
221
232
  <% } else { %>
222
- <% entries.forEach(entry => { %>
223
- - **<%= entry.type %>**: <%= entry.description %>
233
+ <% sections.forEach(section => { %>
234
+ ### <%- section.label %>
235
+
236
+ <% section.entries.forEach(entry => { %>
237
+ <%- entry.line %>
238
+ <% }) %>
224
239
  <% }) %>
225
240
  <% } %>
226
241
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@releasekit/notes",
3
- "version": "0.44.1",
4
- "description": "Release notes and changelog generation with LLM-powered enhancement and flexible templating",
3
+ "version": "0.46.0",
4
+ "description": "Changelog and release notes generation with flexible templating and optional LLM-enhanced release notes",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -5,3 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  {{#each versions}}
6
6
  {{> version}}
7
7
  {{/each}}
8
+ {{#if shared.length}}
9
+ ## Project-wide changes - {{versions.[0].date}}
10
+
11
+ {{#each shared}}
12
+ ### {{{label}}}
13
+
14
+ {{#each entries}}
15
+ {{{line}}}
16
+ {{/each}}
17
+
18
+ {{/each}}
19
+ {{/if}}
@@ -1,2 +1 @@
1
- - {{#if breaking}}**BREAKING** {{/if}}{{#if scope}}**{{scope}}**: {{/if}}{{description}}{{#if issueIds}} ({{join issueIds ", "}}){{/if}}
2
-
1
+ {{{line}}}
@@ -3,13 +3,23 @@
3
3
  [Full Changelog]({{compareUrl}})
4
4
  {{/if}}
5
5
 
6
+ {{#each sections}}
7
+ ### {{{label}}}
8
+
6
9
  {{#each entries}}
7
- {{#if breaking}}
8
10
  {{> entry}}
9
- {{/if}}
10
11
  {{/each}}
12
+
13
+ {{/each}}
14
+ {{#if shared.length}}
15
+ ### Project-wide changes
16
+
17
+ {{#each shared}}
18
+ #### {{{label}}}
19
+
11
20
  {{#each entries}}
12
- {{#unless breaking}}
13
21
  {{> entry}}
14
- {{/unless}}
15
22
  {{/each}}
23
+
24
+ {{/each}}
25
+ {{/if}}
@@ -1,20 +1,45 @@
1
1
  ## What's Changed
2
+ <% if (versions.length > 0) { -%>
3
+ <% const version = versions[0]; -%>
4
+ <% if (version.enhanced?.releaseNotes) { -%>
2
5
 
3
- <% if (versions.length > 0) { %>
4
- <% const version = versions[0]; %>
6
+ <%- version.enhanced.releaseNotes %>
7
+ <% } else { -%>
8
+ <% version.sections.forEach(function(section) { -%>
5
9
 
6
- <% if (version.enhanced?.releaseNotes) { %>
7
- <%= version.enhanced.releaseNotes %>
8
- <% } else { %>
9
- <% if (version.entries.length > 0) { %>
10
- <% [...version.entries.filter((e) => e.breaking), ...version.entries.filter((e) => !e.breaking)].forEach(function(entry) { %>
11
- - <% if (entry.breaking) { %>**BREAKING** <% } %><% if (entry.scope) { %>**<%= entry.scope %>**: <% } %><%= entry.description %><% if (entry.issueIds) { %> (<%= entry.issueIds.join(', ') %>)<% } %>
10
+ ### <%- section.label %>
12
11
 
13
- <% }); %>
14
- <% } %>
15
- <% } %>
12
+ <% section.entries.forEach(function(entry) { -%>
13
+ <%- entry.line %>
14
+ <% }); -%>
15
+ <% }); -%>
16
+ <% } -%>
17
+ <% if (version.shared.length > 0) { -%>
16
18
 
17
- <% if (version.compareUrl) { %>
18
- **Full Changelog**: <%= version.compareUrl %>
19
- <% } %>
20
- <% } %>
19
+ ### Project-wide changes
20
+ <% version.shared.forEach(function(section) { -%>
21
+
22
+ #### <%- section.label %>
23
+
24
+ <% section.entries.forEach(function(entry) { -%>
25
+ <%- entry.line %>
26
+ <% }); -%>
27
+ <% }); -%>
28
+ <% } -%>
29
+ <% version.bundled.forEach(function(pkg) { -%>
30
+
31
+ ### <%- pkg.packageName %> <% if (pkg.firstVersion) { %><%- pkg.firstVersion %> → <% } %><%- pkg.version %>
32
+ <% pkg.sections.forEach(function(section) { -%>
33
+
34
+ #### <%- section.label %>
35
+
36
+ <% section.entries.forEach(function(entry) { -%>
37
+ <%- entry.line %>
38
+ <% }); -%>
39
+ <% }); -%>
40
+ <% }); -%>
41
+ <% if (version.compareUrl) { -%>
42
+
43
+ **Full Changelog**: <%- version.compareUrl %>
44
+ <% } -%>
45
+ <% } -%>
@@ -8,3 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  {% for version in versions %}
9
9
  {% include "version" %}
10
10
  {% endfor %}
11
+ {%- if shared.size > 0 %}
12
+
13
+ ## Project-wide changes - {{ versions.first.date }}
14
+ {%- for section in shared %}
15
+
16
+ ### {{ section.label }}
17
+ {% for entry in section.entries %}
18
+ {{ entry.line }}
19
+ {%- endfor %}
20
+ {%- endfor %}
21
+ {%- endif %}
@@ -1,2 +1 @@
1
- - {% if entry.breaking %}**BREAKING** {% endif %}{% if entry.scope %}**{{ entry.scope }}**: {% endif %}{{ entry.description }}{% if entry.issueIds %} ({{ entry.issueIds | join: ", " }}){% endif %}
2
-
1
+ {{ entry.line -}}
@@ -1,56 +1,23 @@
1
- ## [{{ version.version }}]{% if version.previousVersion %}{% endif %} - {{ version.date }}
2
- {% if version.compareUrl %}
3
- [Full Changelog]({{ version.compareUrl }})
4
- {% endif %}
1
+ ## [{{ version.version }}] - {{ version.date }}
2
+ {%- if version.compareUrl %}
5
3
 
6
- {% assign breaking = version.entries | where: "breaking" %}
7
- {% assign nonBreaking = version.entries | reject: "breaking" %}
8
- {% assign added = nonBreaking | where: "type", "added" %}
9
- {% assign changed = nonBreaking | where: "type", "changed" %}
10
- {% assign deprecated = nonBreaking | where: "type", "deprecated" %}
11
- {% assign removed = nonBreaking | where: "type", "removed" %}
12
- {% assign fixed = nonBreaking | where: "type", "fixed" %}
13
- {% assign security = nonBreaking | where: "type", "security" %}
4
+ [Full Changelog]({{ version.compareUrl }})
5
+ {%- endif %}
6
+ {%- for section in version.sections %}
14
7
 
15
- {% if breaking.size > 0 %}
16
- ### Breaking
17
- {% for entry in breaking %}
18
- {% include "entry" %}
19
- {% endfor %}
20
- {% endif %}
21
- {% if added.size > 0 %}
22
- ### Added
23
- {% for entry in added %}
24
- {% include "entry" %}
25
- {% endfor %}
26
- {% endif %}
27
- {% if changed.size > 0 %}
28
- ### Changed
29
- {% for entry in changed %}
30
- {% include "entry" %}
31
- {% endfor %}
32
- {% endif %}
33
- {% if deprecated.size > 0 %}
34
- ### Deprecated
35
- {% for entry in deprecated %}
8
+ ### {{ section.label }}
9
+ {% for entry in section.entries %}
36
10
  {% include "entry" %}
37
- {% endfor %}
38
- {% endif %}
39
- {% if removed.size > 0 %}
40
- ### Removed
41
- {% for entry in removed %}
42
- {% include "entry" %}
43
- {% endfor %}
44
- {% endif %}
45
- {% if fixed.size > 0 %}
46
- ### Fixed
47
- {% for entry in fixed %}
48
- {% include "entry" %}
49
- {% endfor %}
50
- {% endif %}
51
- {% if security.size > 0 %}
52
- ### Security
53
- {% for entry in security %}
11
+ {%- endfor %}
12
+ {%- endfor %}
13
+ {%- if version.shared.size > 0 %}
14
+
15
+ ### Project-wide changes
16
+ {%- for section in version.shared %}
17
+
18
+ #### {{ section.label }}
19
+ {% for entry in section.entries %}
54
20
  {% include "entry" %}
55
- {% endfor %}
56
- {% endif %}
21
+ {%- endfor %}
22
+ {%- endfor %}
23
+ {%- endif %}
@@ -1,150 +0,0 @@
1
- import {
2
- debug,
3
- info,
4
- prependVersions,
5
- renderMarkdown,
6
- success
7
- } from "./chunk-VD3TYCTF.js";
8
-
9
- // src/monorepo/aggregator.ts
10
- import * as fs from "fs";
11
- import * as path from "path";
12
-
13
- // src/monorepo/splitter.ts
14
- function splitByPackage(contexts) {
15
- const byPackage = /* @__PURE__ */ new Map();
16
- for (const ctx of contexts) {
17
- byPackage.set(ctx.packageName, ctx);
18
- }
19
- return byPackage;
20
- }
21
-
22
- // src/monorepo/aggregator.ts
23
- function writeFile(outputPath, content, dryRun) {
24
- if (dryRun) {
25
- info(`Would write to ${outputPath}`);
26
- debug(content);
27
- return false;
28
- }
29
- const dir = path.dirname(outputPath);
30
- if (!fs.existsSync(dir)) {
31
- fs.mkdirSync(dir, { recursive: true });
32
- }
33
- fs.writeFileSync(outputPath, content, "utf-8");
34
- success(`Changelog written to ${outputPath}`);
35
- return true;
36
- }
37
- function aggregateToRoot(contexts) {
38
- const aggregated = {
39
- packageName: "monorepo",
40
- version: contexts[0]?.version ?? "0.0.0",
41
- previousVersion: contexts[0]?.previousVersion ?? null,
42
- date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
43
- repoUrl: contexts[0]?.repoUrl ?? null,
44
- entries: []
45
- };
46
- for (const ctx of contexts) {
47
- for (const entry of ctx.entries) {
48
- aggregated.entries.push({
49
- ...entry,
50
- scope: entry.scope ? `${ctx.packageName}/${entry.scope}` : ctx.packageName
51
- });
52
- }
53
- }
54
- return aggregated;
55
- }
56
- function writeMonorepoChangelogs(contexts, options, config, dryRun, refs = "link") {
57
- const files = [];
58
- if (options.mode === "root" || options.mode === "both") {
59
- const rootPath = path.join(options.rootPath, options.fileName ?? "CHANGELOG.md");
60
- const fmtOpts = { includePackageName: true, refs };
61
- info(`Writing root changelog to ${rootPath}`);
62
- const rootContent = config.updateStrategy === "regenerate" ? renderMarkdown(contexts, fmtOpts) : prependVersions(rootPath, contexts, fmtOpts);
63
- if (writeFile(rootPath, rootContent, dryRun)) {
64
- files.push(rootPath);
65
- }
66
- }
67
- if (options.mode === "packages" || options.mode === "both") {
68
- const byPackage = splitByPackage(contexts);
69
- const packageDirMap = buildPackageDirMap(options.rootPath, options.packagesPath);
70
- for (const [packageName, ctx] of byPackage) {
71
- const simpleName = packageName.split("/").pop();
72
- const packageDir = packageDirMap.get(packageName) ?? (simpleName ? packageDirMap.get(simpleName) : void 0) ?? null;
73
- if (packageDir) {
74
- const changelogPath = path.join(packageDir, options.fileName ?? "CHANGELOG.md");
75
- info(`Writing changelog for ${packageName} to ${changelogPath}`);
76
- const pkgContent = config.updateStrategy === "regenerate" ? renderMarkdown([ctx], { refs }) : prependVersions(changelogPath, [ctx], { refs });
77
- if (writeFile(changelogPath, pkgContent, dryRun)) {
78
- files.push(changelogPath);
79
- }
80
- } else {
81
- info(`Could not find directory for package ${packageName}, skipping`);
82
- }
83
- }
84
- }
85
- return files;
86
- }
87
- function buildPackageDirMap(rootPath, packagesPath) {
88
- const map = /* @__PURE__ */ new Map();
89
- const packagesDir = path.join(rootPath, packagesPath);
90
- if (!fs.existsSync(packagesDir)) {
91
- return map;
92
- }
93
- for (const entry of fs.readdirSync(packagesDir, { withFileTypes: true })) {
94
- if (!entry.isDirectory()) {
95
- continue;
96
- }
97
- const dirPath = path.join(packagesDir, entry.name);
98
- map.set(entry.name, dirPath);
99
- const packageJsonPath = path.join(dirPath, "package.json");
100
- if (fs.existsSync(packageJsonPath)) {
101
- try {
102
- const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
103
- if (pkg.name) {
104
- map.set(pkg.name, dirPath);
105
- }
106
- } catch {
107
- }
108
- }
109
- }
110
- return map;
111
- }
112
- function detectMonorepo(cwd) {
113
- const pnpmWorkspacesPath = path.join(cwd, "pnpm-workspace.yaml");
114
- const packageJsonPath = path.join(cwd, "package.json");
115
- if (fs.existsSync(pnpmWorkspacesPath)) {
116
- const content = fs.readFileSync(pnpmWorkspacesPath, "utf-8");
117
- const packagesMatch = content.match(/packages:\s*\n\s*-\s*['"]([^'"]+)['"]/);
118
- if (packagesMatch?.[1]) {
119
- const packagesGlob = packagesMatch[1];
120
- const packagesPath = packagesGlob.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
121
- return { isMonorepo: true, packagesPath: packagesPath || "packages" };
122
- }
123
- return { isMonorepo: true, packagesPath: "packages" };
124
- }
125
- if (fs.existsSync(packageJsonPath)) {
126
- try {
127
- const content = fs.readFileSync(packageJsonPath, "utf-8");
128
- const pkg = JSON.parse(content);
129
- if (pkg.workspaces) {
130
- const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
131
- if (workspaces?.length) {
132
- const firstWorkspace = workspaces[0];
133
- if (firstWorkspace) {
134
- const packagesPath = firstWorkspace.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
135
- return { isMonorepo: true, packagesPath: packagesPath || "packages" };
136
- }
137
- }
138
- }
139
- } catch {
140
- return { isMonorepo: false, packagesPath: "" };
141
- }
142
- }
143
- return { isMonorepo: false, packagesPath: "" };
144
- }
145
-
146
- export {
147
- aggregateToRoot,
148
- writeMonorepoChangelogs,
149
- detectMonorepo
150
- };