@releasekit/notes 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @releasekit/notes
2
2
 
3
- Changelog generation from conventional commits with LLM-powered enhancement and flexible templating
3
+ Release notes and changelog generation from conventional commits with LLM-powered enhancement and flexible templating
4
4
 
5
5
  ## Features
6
6
 
@@ -19,6 +19,8 @@ npm install -g @releasekit/notes
19
19
  pnpm add -g @releasekit/notes
20
20
  ```
21
21
 
22
+ > **Note:** This package is ESM only and requires Node.js 20+.
23
+
22
24
  ## Quick Start
23
25
 
24
26
  ```bash
@@ -0,0 +1,13 @@
1
+ import {
2
+ aggregateToRoot,
3
+ detectMonorepo,
4
+ splitByPackage,
5
+ writeMonorepoChangelogs
6
+ } from "./chunk-ATNNRK62.js";
7
+ import "./chunk-SAUES3BF.js";
8
+ export {
9
+ aggregateToRoot,
10
+ detectMonorepo,
11
+ splitByPackage,
12
+ writeMonorepoChangelogs
13
+ };
@@ -0,0 +1,165 @@
1
+ import {
2
+ debug,
3
+ formatVersion,
4
+ info,
5
+ prependVersion,
6
+ renderMarkdown,
7
+ success
8
+ } from "./chunk-SAUES3BF.js";
9
+
10
+ // src/monorepo/aggregator.ts
11
+ import * as fs from "fs";
12
+ import * as path from "path";
13
+
14
+ // src/monorepo/splitter.ts
15
+ function splitByPackage(contexts) {
16
+ const byPackage = /* @__PURE__ */ new Map();
17
+ for (const ctx of contexts) {
18
+ byPackage.set(ctx.packageName, ctx);
19
+ }
20
+ return byPackage;
21
+ }
22
+
23
+ // src/monorepo/aggregator.ts
24
+ function writeFile(outputPath, content, dryRun) {
25
+ if (dryRun) {
26
+ info(`Would write to ${outputPath}`);
27
+ debug(content);
28
+ return false;
29
+ }
30
+ const dir = path.dirname(outputPath);
31
+ if (!fs.existsSync(dir)) {
32
+ fs.mkdirSync(dir, { recursive: true });
33
+ }
34
+ fs.writeFileSync(outputPath, content, "utf-8");
35
+ success(`Changelog written to ${outputPath}`);
36
+ return true;
37
+ }
38
+ function aggregateToRoot(contexts) {
39
+ const aggregated = {
40
+ packageName: "monorepo",
41
+ version: contexts[0]?.version ?? "0.0.0",
42
+ previousVersion: contexts[0]?.previousVersion ?? null,
43
+ date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
44
+ repoUrl: contexts[0]?.repoUrl ?? null,
45
+ entries: []
46
+ };
47
+ for (const ctx of contexts) {
48
+ for (const entry of ctx.entries) {
49
+ aggregated.entries.push({
50
+ ...entry,
51
+ scope: entry.scope ? `${ctx.packageName}/${entry.scope}` : ctx.packageName
52
+ });
53
+ }
54
+ }
55
+ return aggregated;
56
+ }
57
+ function writeMonorepoChangelogs(contexts, options, config, dryRun) {
58
+ const files = [];
59
+ if (options.mode === "root" || options.mode === "both") {
60
+ const rootPath = path.join(options.rootPath, "CHANGELOG.md");
61
+ const fmtOpts = { includePackageName: true };
62
+ info(`Writing root changelog to ${rootPath}`);
63
+ let rootContent;
64
+ if (config.updateStrategy === "prepend" && fs.existsSync(rootPath)) {
65
+ const newSections = contexts.map((ctx) => formatVersion(ctx, fmtOpts)).join("\n");
66
+ const existing = fs.readFileSync(rootPath, "utf-8");
67
+ const headerEnd = existing.indexOf("\n## ");
68
+ if (headerEnd >= 0) {
69
+ rootContent = `${existing.slice(0, headerEnd)}
70
+
71
+ ${newSections}
72
+ ${existing.slice(headerEnd + 1)}`;
73
+ } else {
74
+ rootContent = renderMarkdown(contexts, fmtOpts);
75
+ }
76
+ } else {
77
+ rootContent = renderMarkdown(contexts, fmtOpts);
78
+ }
79
+ if (writeFile(rootPath, rootContent, dryRun)) {
80
+ files.push(rootPath);
81
+ }
82
+ }
83
+ if (options.mode === "packages" || options.mode === "both") {
84
+ const byPackage = splitByPackage(contexts);
85
+ const packageDirMap = buildPackageDirMap(options.rootPath, options.packagesPath);
86
+ for (const [packageName, ctx] of byPackage) {
87
+ const simpleName = packageName.split("/").pop();
88
+ const packageDir = packageDirMap.get(packageName) ?? (simpleName ? packageDirMap.get(simpleName) : void 0) ?? null;
89
+ if (packageDir) {
90
+ const changelogPath = path.join(packageDir, "CHANGELOG.md");
91
+ info(`Writing changelog for ${packageName} to ${changelogPath}`);
92
+ const pkgContent = config.updateStrategy === "prepend" && fs.existsSync(changelogPath) ? prependVersion(changelogPath, ctx) : renderMarkdown([ctx]);
93
+ if (writeFile(changelogPath, pkgContent, dryRun)) {
94
+ files.push(changelogPath);
95
+ }
96
+ } else {
97
+ info(`Could not find directory for package ${packageName}, skipping`);
98
+ }
99
+ }
100
+ }
101
+ return files;
102
+ }
103
+ function buildPackageDirMap(rootPath, packagesPath) {
104
+ const map = /* @__PURE__ */ new Map();
105
+ const packagesDir = path.join(rootPath, packagesPath);
106
+ if (!fs.existsSync(packagesDir)) {
107
+ return map;
108
+ }
109
+ for (const entry of fs.readdirSync(packagesDir, { withFileTypes: true })) {
110
+ if (!entry.isDirectory()) continue;
111
+ const dirPath = path.join(packagesDir, entry.name);
112
+ map.set(entry.name, dirPath);
113
+ const packageJsonPath = path.join(dirPath, "package.json");
114
+ if (fs.existsSync(packageJsonPath)) {
115
+ try {
116
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
117
+ if (pkg.name) {
118
+ map.set(pkg.name, dirPath);
119
+ }
120
+ } catch {
121
+ }
122
+ }
123
+ }
124
+ return map;
125
+ }
126
+ function detectMonorepo(cwd) {
127
+ const pnpmWorkspacesPath = path.join(cwd, "pnpm-workspace.yaml");
128
+ const packageJsonPath = path.join(cwd, "package.json");
129
+ if (fs.existsSync(pnpmWorkspacesPath)) {
130
+ const content = fs.readFileSync(pnpmWorkspacesPath, "utf-8");
131
+ const packagesMatch = content.match(/packages:\s*\n\s*-\s*['"]([^'"]+)['"]/);
132
+ if (packagesMatch?.[1]) {
133
+ const packagesGlob = packagesMatch[1];
134
+ const packagesPath = packagesGlob.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
135
+ return { isMonorepo: true, packagesPath: packagesPath || "packages" };
136
+ }
137
+ return { isMonorepo: true, packagesPath: "packages" };
138
+ }
139
+ if (fs.existsSync(packageJsonPath)) {
140
+ try {
141
+ const content = fs.readFileSync(packageJsonPath, "utf-8");
142
+ const pkg = JSON.parse(content);
143
+ if (pkg.workspaces) {
144
+ const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
145
+ if (workspaces?.length) {
146
+ const firstWorkspace = workspaces[0];
147
+ if (firstWorkspace) {
148
+ const packagesPath = firstWorkspace.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
149
+ return { isMonorepo: true, packagesPath: packagesPath || "packages" };
150
+ }
151
+ }
152
+ }
153
+ } catch {
154
+ return { isMonorepo: false, packagesPath: "" };
155
+ }
156
+ }
157
+ return { isMonorepo: false, packagesPath: "" };
158
+ }
159
+
160
+ export {
161
+ splitByPackage,
162
+ aggregateToRoot,
163
+ writeMonorepoChangelogs,
164
+ detectMonorepo
165
+ };