tegami 1.0.0-beta.2 → 1.0.0-beta.4
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/cli/index.d.ts +7 -5
- package/dist/cli/index.js +207 -220
- package/dist/draft-DtFyGxe8.js +455 -0
- package/dist/{error-D3dwQnwR.js → error-We7chQVJ.js} +12 -1
- package/dist/{generate-CaCDNfVk.js → generate-BfYdNTFi.js} +1 -1
- package/dist/generators/simple.d.ts +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +28 -462
- package/dist/{npm-B_43doHi.js → npm-CMOyacwf.js} +4 -4
- package/dist/plugins/git.d.ts +1 -1
- package/dist/plugins/git.js +4 -4
- package/dist/plugins/github.d.ts +1 -1
- package/dist/plugins/github.js +388 -126
- package/dist/plugins/gitlab.d.ts +84 -0
- package/dist/plugins/gitlab.js +554 -0
- package/dist/plugins/go.d.ts +1 -1
- package/dist/plugins/go.js +5 -4
- package/dist/providers/cargo.d.ts +1 -1
- package/dist/providers/cargo.js +3 -3
- package/dist/providers/npm.d.ts +1 -1
- package/dist/providers/npm.js +1 -1
- package/dist/{types-DKeF_CDv.d.ts → types-DKZsadC8.d.ts} +128 -14
- package/dist/version-request-cFS0Suzd.js +69 -0
- package/package.json +2 -5
- package/dist/api-D-jf_8xY.js +0 -116
- package/dist/index-CQXmwyLn.d.ts +0 -64
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { a as maxBump } from "./semver-EKJ8yK5U.js";
|
|
2
|
+
import { i as renderChangelog, r as changelogFrontmatterSchema } from "./generate-BfYdNTFi.js";
|
|
3
|
+
import { r as handlePluginError } from "./error-We7chQVJ.js";
|
|
4
|
+
import { simpleGenerator } from "./generators/simple.js";
|
|
5
|
+
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
import path, { basename, dirname, join } from "node:path";
|
|
7
|
+
import * as semver$1 from "semver";
|
|
8
|
+
import z from "zod";
|
|
9
|
+
import { dump, load, visit } from "js-yaml";
|
|
10
|
+
//#region src/utils/frontmatter.ts
|
|
11
|
+
/**
|
|
12
|
+
* Inspired by https://github.com/jonschlinkert/gray-matter
|
|
13
|
+
*/
|
|
14
|
+
const regex = /^---\r?\n(.+?)\r?\n---\r?\n?/s;
|
|
15
|
+
/**
|
|
16
|
+
* parse frontmatter, it supports only yaml format
|
|
17
|
+
*/
|
|
18
|
+
function frontmatter(input) {
|
|
19
|
+
const output = {
|
|
20
|
+
matter: "",
|
|
21
|
+
data: {},
|
|
22
|
+
content: input
|
|
23
|
+
};
|
|
24
|
+
const match = regex.exec(input);
|
|
25
|
+
if (!match) return output;
|
|
26
|
+
output.matter = match[0];
|
|
27
|
+
output.content = input.slice(match[0].length);
|
|
28
|
+
output.data = load(match[1]) ?? {};
|
|
29
|
+
return output;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/changelog/parse.ts
|
|
33
|
+
async function getChangelogFiles(context) {
|
|
34
|
+
return (await readdir(context.changelogDir).catch(() => [])).filter((file) => file.endsWith(".md"));
|
|
35
|
+
}
|
|
36
|
+
async function readChangelogEntries(context) {
|
|
37
|
+
const dir = context.changelogDir;
|
|
38
|
+
const files = await getChangelogFiles(context);
|
|
39
|
+
return (await Promise.all(files.map(async (file) => {
|
|
40
|
+
const filePath = join(dir, file);
|
|
41
|
+
const content = await readFile(filePath, "utf8");
|
|
42
|
+
return parseChangelogFile(basename(filePath), content);
|
|
43
|
+
}))).filter((v) => v !== void 0);
|
|
44
|
+
}
|
|
45
|
+
/** Parse one changelog markdown file into release entries. */
|
|
46
|
+
function parseChangelogFile(filename, content) {
|
|
47
|
+
const parsed = frontmatter(content);
|
|
48
|
+
const { success, data } = changelogFrontmatterSchema.safeParse(parsed.data);
|
|
49
|
+
if (!success || !data.packages) return;
|
|
50
|
+
let headingBump;
|
|
51
|
+
const packages = /* @__PURE__ */ new Map();
|
|
52
|
+
const sections = [];
|
|
53
|
+
for (const section of parseMarkdownSections(parsed.content)) {
|
|
54
|
+
const sectionBumpType = headingToBump(section.depth);
|
|
55
|
+
if (sectionBumpType) headingBump = headingBump ? maxBump(headingBump, sectionBumpType) : sectionBumpType;
|
|
56
|
+
sections.push({
|
|
57
|
+
depth: section.depth,
|
|
58
|
+
title: section.title,
|
|
59
|
+
content: section.content
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (sections.length === 0) return;
|
|
63
|
+
if (Array.isArray(data.packages)) {
|
|
64
|
+
if (!headingBump) return;
|
|
65
|
+
for (const pkg of data.packages) packages.set(pkg, { type: headingBump });
|
|
66
|
+
} else for (const [k, v] of Object.entries(data.packages)) {
|
|
67
|
+
let config;
|
|
68
|
+
if (typeof v === "string") config = { type: v };
|
|
69
|
+
else if (v === null) config = { type: headingBump };
|
|
70
|
+
else config = v;
|
|
71
|
+
if (config.type || config.replay?.length) packages.set(k, config);
|
|
72
|
+
}
|
|
73
|
+
if (packages.size === 0) return;
|
|
74
|
+
const entry = {
|
|
75
|
+
id: filename,
|
|
76
|
+
filename,
|
|
77
|
+
subject: data.subject,
|
|
78
|
+
packages,
|
|
79
|
+
sections,
|
|
80
|
+
_raw_body: parsed.content,
|
|
81
|
+
getRawContent() {
|
|
82
|
+
return renderChangelog({
|
|
83
|
+
subject: this.subject,
|
|
84
|
+
packages: Object.fromEntries(this.packages.entries())
|
|
85
|
+
}, entry._raw_body);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return entry;
|
|
89
|
+
}
|
|
90
|
+
function parseReplayCondition(condition) {
|
|
91
|
+
if (condition.startsWith("exit prerelease:")) return {
|
|
92
|
+
type: "on-exit-prerelease",
|
|
93
|
+
name: condition.slice(16).trimStart()
|
|
94
|
+
};
|
|
95
|
+
const idx = condition.lastIndexOf("@");
|
|
96
|
+
if (idx <= 0) return null;
|
|
97
|
+
return {
|
|
98
|
+
type: "on-version",
|
|
99
|
+
name: condition.slice(0, idx),
|
|
100
|
+
version: condition.slice(idx + 1)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function parseMarkdownSections(markdown) {
|
|
104
|
+
const sections = [];
|
|
105
|
+
const lines = markdown.split(/\r\n|\r|\n/);
|
|
106
|
+
let current;
|
|
107
|
+
let fence;
|
|
108
|
+
for (const line of lines) {
|
|
109
|
+
const fenceMarker = line.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
110
|
+
if (fenceMarker) {
|
|
111
|
+
const marker = fenceMarker[1];
|
|
112
|
+
if (!fence) fence = marker;
|
|
113
|
+
else if (marker[0] === fence[0] && marker.length >= fence.length) fence = void 0;
|
|
114
|
+
}
|
|
115
|
+
if (!fence) {
|
|
116
|
+
const heading = parseHeading(line);
|
|
117
|
+
if (heading) {
|
|
118
|
+
if (current) sections.push(toMarkdownSection(current));
|
|
119
|
+
current = {
|
|
120
|
+
...heading,
|
|
121
|
+
contentLines: []
|
|
122
|
+
};
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
current?.contentLines.push(line);
|
|
127
|
+
}
|
|
128
|
+
if (current) sections.push(toMarkdownSection(current));
|
|
129
|
+
return sections;
|
|
130
|
+
}
|
|
131
|
+
function parseHeading(line) {
|
|
132
|
+
const match = line.match(/^ {0,3}(#{1,6})(?:[ \t]+|$)(.*)$/);
|
|
133
|
+
if (!match) return;
|
|
134
|
+
return {
|
|
135
|
+
depth: match[1].length,
|
|
136
|
+
title: stripClosingHeadingSequence(match[2]).trim()
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function stripClosingHeadingSequence(value) {
|
|
140
|
+
return value.replace(/[ \t]+#{1,}[ \t]*$/, "");
|
|
141
|
+
}
|
|
142
|
+
function toMarkdownSection(section) {
|
|
143
|
+
return {
|
|
144
|
+
depth: section.depth,
|
|
145
|
+
title: section.title,
|
|
146
|
+
content: section.contentLines.join("\n").trim()
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function headingToBump(depth) {
|
|
150
|
+
switch (depth) {
|
|
151
|
+
case 1: return "major";
|
|
152
|
+
case 2: return "minor";
|
|
153
|
+
case 3: return "patch";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/plans/lock.ts
|
|
158
|
+
function inlineMultilineScalars(documents) {
|
|
159
|
+
visit(documents, (node) => {
|
|
160
|
+
if (node.kind !== "scalar" || !node.value.includes("\n")) return;
|
|
161
|
+
node.style.doubleQuoted = true;
|
|
162
|
+
node.style.literal = false;
|
|
163
|
+
node.style.folded = false;
|
|
164
|
+
node.style.singleQuoted = false;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const lockDumpOptions = {
|
|
168
|
+
sortKeys: true,
|
|
169
|
+
lineWidth: -1,
|
|
170
|
+
transform: inlineMultilineScalars
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* the data structure of `publish-lock.yaml` file.
|
|
174
|
+
*/
|
|
175
|
+
var PublishLock = class {
|
|
176
|
+
data;
|
|
177
|
+
constructor(data = /* @__PURE__ */ new Map()) {
|
|
178
|
+
this.data = data;
|
|
179
|
+
}
|
|
180
|
+
/** write data to namespace, note that the `data` must be serializable in yaml */
|
|
181
|
+
write(namespace, data) {
|
|
182
|
+
let arr = this.data.get(namespace);
|
|
183
|
+
if (!arr) {
|
|
184
|
+
arr = [];
|
|
185
|
+
this.data.set(namespace, arr);
|
|
186
|
+
}
|
|
187
|
+
arr.push(data);
|
|
188
|
+
}
|
|
189
|
+
read(namespace) {
|
|
190
|
+
return this.data.get(namespace)?.shift();
|
|
191
|
+
}
|
|
192
|
+
size(namespace) {
|
|
193
|
+
return this.data.get(namespace)?.length ?? 0;
|
|
194
|
+
}
|
|
195
|
+
serialize() {
|
|
196
|
+
let res = dump(Object.fromEntries(this.data.entries()), lockDumpOptions);
|
|
197
|
+
if (!res.endsWith("\n")) res += "\n";
|
|
198
|
+
return res;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const baseSchema = z.record(z.string(), z.array(z.unknown()));
|
|
202
|
+
function parsePublishLock(content) {
|
|
203
|
+
const data = baseSchema.parse(load(content));
|
|
204
|
+
return new PublishLock(new Map(Object.entries(data)));
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/plans/policy.ts
|
|
208
|
+
function groupPolicy({ graph }) {
|
|
209
|
+
return {
|
|
210
|
+
id: "group",
|
|
211
|
+
onUpdate({ pkg, packageDraft }) {
|
|
212
|
+
if (!packageDraft.type) return;
|
|
213
|
+
const group = graph.getPackageGroup(pkg.id);
|
|
214
|
+
if (!group || !group.options.syncBump) return;
|
|
215
|
+
for (const member of group.packages) {
|
|
216
|
+
if (member === pkg) continue;
|
|
217
|
+
this.bumpPackage(member, {
|
|
218
|
+
type: packageDraft.type,
|
|
219
|
+
reason: `sync "${group.name}" group package versions`
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/plans/draft.ts
|
|
227
|
+
const changelogStoreSchema = z.object({
|
|
228
|
+
v: z.literal("0.0.0"),
|
|
229
|
+
filename: z.string(),
|
|
230
|
+
content: z.string()
|
|
231
|
+
});
|
|
232
|
+
const packageStoreSchema = z.object({
|
|
233
|
+
id: z.string(),
|
|
234
|
+
updated: z.boolean(),
|
|
235
|
+
changelogIds: z.array(z.string()).optional()
|
|
236
|
+
});
|
|
237
|
+
/** a draft describes all operations to perform before the actual publishing, such as version bumps. */
|
|
238
|
+
var Draft = class {
|
|
239
|
+
context;
|
|
240
|
+
#applied = false;
|
|
241
|
+
/** package id -> draft */
|
|
242
|
+
packages = /* @__PURE__ */ new Map();
|
|
243
|
+
/** id -> changelog */
|
|
244
|
+
changelogs = /* @__PURE__ */ new Map();
|
|
245
|
+
policies = [];
|
|
246
|
+
constructor(context) {
|
|
247
|
+
this.context = context;
|
|
248
|
+
this.policies.push(groupPolicy(context));
|
|
249
|
+
}
|
|
250
|
+
getPackageDrafts() {
|
|
251
|
+
return this.packages;
|
|
252
|
+
}
|
|
253
|
+
getPackageDraft(id) {
|
|
254
|
+
return this.packages.get(id);
|
|
255
|
+
}
|
|
256
|
+
bumpPackage(pkg, { type, reason }) {
|
|
257
|
+
return this.dispatchPackage(pkg, (draft) => {
|
|
258
|
+
draft.type = draft.type ? maxBump(draft.type, type) : type;
|
|
259
|
+
if (reason) {
|
|
260
|
+
draft.bumpReasons ??= /* @__PURE__ */ new Set();
|
|
261
|
+
draft.bumpReasons.add(reason);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
dispatchPackage(pkg, dispatch, onUpdate) {
|
|
266
|
+
const packageDraft = this.getOrInitPackage(pkg);
|
|
267
|
+
const prevVersion = packageDraft.bumpVersion(pkg);
|
|
268
|
+
dispatch(packageDraft);
|
|
269
|
+
if (prevVersion !== packageDraft.bumpVersion(pkg)) {
|
|
270
|
+
onUpdate?.(packageDraft);
|
|
271
|
+
for (const policy of this.policies) policy.onUpdate?.call(this, {
|
|
272
|
+
packageDraft,
|
|
273
|
+
pkg
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
return packageDraft;
|
|
277
|
+
}
|
|
278
|
+
getOrInitPackage(pkg) {
|
|
279
|
+
const existing = this.packages.get(pkg.id);
|
|
280
|
+
if (existing) return existing;
|
|
281
|
+
this.packages.set(pkg.id, pkg.initDraft());
|
|
282
|
+
return this.dispatchPackage(pkg, (draft) => pkg.configureDraft(draft, this.context.graph.getPackageGroup(pkg.id)), (draft) => {
|
|
283
|
+
(draft.bumpReasons ??= /* @__PURE__ */ new Set()).add("align with script-level configs");
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
hasPending() {
|
|
287
|
+
const { graph } = this.context;
|
|
288
|
+
for (const [id, draft] of this.packages) {
|
|
289
|
+
const pkg = graph.get(id);
|
|
290
|
+
if (pkg && draft.bumpVersion(pkg) !== pkg.version) return true;
|
|
291
|
+
}
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
/** get all changelogs, note that this includes replay-only changelogs, as long as they are in the `.tegami` folder. */
|
|
295
|
+
getChangelogs() {
|
|
296
|
+
return Array.from(this.changelogs.values());
|
|
297
|
+
}
|
|
298
|
+
getChangelog(id) {
|
|
299
|
+
return this.changelogs.get(id);
|
|
300
|
+
}
|
|
301
|
+
addChangelog(entry) {
|
|
302
|
+
this.changelogs.set(entry.id, entry);
|
|
303
|
+
const { graph } = this.context;
|
|
304
|
+
const groupPackages = /* @__PURE__ */ new Map();
|
|
305
|
+
for (const [name, config] of entry.packages) {
|
|
306
|
+
if (!config.type) continue;
|
|
307
|
+
for (const pkg of graph.getByName(name)) groupPackages.set(pkg, config.type);
|
|
308
|
+
}
|
|
309
|
+
for (const [pkg, bumpType] of groupPackages) attachChangelog(this.bumpPackage(pkg, { type: bumpType }), entry);
|
|
310
|
+
}
|
|
311
|
+
deleteChangelog(id) {
|
|
312
|
+
return this.changelogs.delete(id);
|
|
313
|
+
}
|
|
314
|
+
/** Apply version bumps, lock file, and changelog files. */
|
|
315
|
+
async apply() {
|
|
316
|
+
if (this.#applied) throw new Error("This draft has already been applied.");
|
|
317
|
+
const { graph } = this.context;
|
|
318
|
+
this.#applied = true;
|
|
319
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
320
|
+
for (const pkg of graph.getPackages()) snapshots.set(pkg.id, { version: pkg.version });
|
|
321
|
+
for (const plugin of this.context.plugins) await handlePluginError(plugin, "applyDraft", () => plugin.applyDraft?.call(this.context, this));
|
|
322
|
+
const updatedChangelogs = this.applyReplays(snapshots);
|
|
323
|
+
const writes = [];
|
|
324
|
+
for (const [id, packageDraft] of this.packages) {
|
|
325
|
+
const pkg = graph.get(id);
|
|
326
|
+
if (!pkg) continue;
|
|
327
|
+
writes.push(this.appendChangelog(pkg, packageDraft));
|
|
328
|
+
}
|
|
329
|
+
for (const entry of this.changelogs.values()) {
|
|
330
|
+
const updated = updatedChangelogs.get(entry.id);
|
|
331
|
+
const filePath = path.join(this.context.changelogDir, entry.filename);
|
|
332
|
+
if (updated) writes.push(mkdir(this.context.changelogDir, { recursive: true }).then(() => writeFile(filePath, updated.getRawContent())));
|
|
333
|
+
else if (!entry.virtual) writes.push(rm(filePath, { force: true }));
|
|
334
|
+
}
|
|
335
|
+
writes.push(this.writeLockFile(snapshots));
|
|
336
|
+
await Promise.all(writes);
|
|
337
|
+
}
|
|
338
|
+
/** write persistent data to publish lock */
|
|
339
|
+
async writeLockFile(snapshots) {
|
|
340
|
+
const lock = new PublishLock();
|
|
341
|
+
const changelogs = /* @__PURE__ */ new Set();
|
|
342
|
+
for (const pkg of this.context.graph.getPackages()) {
|
|
343
|
+
const draft = this.getPackageDraft(pkg.id);
|
|
344
|
+
const snapshot = snapshots.get(pkg.id);
|
|
345
|
+
if (!snapshot) continue;
|
|
346
|
+
for (const entry of draft?.changelogs ?? []) changelogs.add(entry);
|
|
347
|
+
lock.write("core:packages", {
|
|
348
|
+
id: pkg.id,
|
|
349
|
+
updated: draft !== void 0 && snapshot.version !== pkg.version,
|
|
350
|
+
changelogIds: draft?.changelogs?.map((entry) => entry.id)
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
for (const entry of changelogs) lock.write("core:changelogs", {
|
|
354
|
+
v: "0.0.0",
|
|
355
|
+
filename: entry.filename,
|
|
356
|
+
content: entry.getRawContent()
|
|
357
|
+
});
|
|
358
|
+
for (const plugin of this.context.plugins) await handlePluginError(plugin, "initPublishLock", () => plugin.initPublishLock?.call(this.context, {
|
|
359
|
+
lock,
|
|
360
|
+
draft: this
|
|
361
|
+
}));
|
|
362
|
+
await mkdir(dirname(this.context.lockPath), { recursive: true });
|
|
363
|
+
await writeFile(this.context.lockPath, lock.serialize());
|
|
364
|
+
}
|
|
365
|
+
addPolicy(policy) {
|
|
366
|
+
this.policies.push(policy);
|
|
367
|
+
}
|
|
368
|
+
removePolicy(policy) {
|
|
369
|
+
const idx = this.policies.indexOf(policy);
|
|
370
|
+
if (idx !== -1) this.policies.splice(idx, 1);
|
|
371
|
+
}
|
|
372
|
+
canApply() {
|
|
373
|
+
return !this.#applied;
|
|
374
|
+
}
|
|
375
|
+
/** Attach replaying changelog entries to packages (already bumped), and return the updated changelog entries. */
|
|
376
|
+
applyReplays(snapshots) {
|
|
377
|
+
const updated = /* @__PURE__ */ new Map();
|
|
378
|
+
const { graph } = this.context;
|
|
379
|
+
const defaultReplays = (name) => {
|
|
380
|
+
const replay = [];
|
|
381
|
+
for (const pkg of graph.getByName(name)) if (this.packages.get(pkg.id)?.prerelease) replay.push(`exit prerelease: ${pkg.id}`);
|
|
382
|
+
return replay;
|
|
383
|
+
};
|
|
384
|
+
const isMatch = (condition) => {
|
|
385
|
+
if (condition.type === "on-exit-prerelease") return graph.getByName(condition.name).some((pkg) => {
|
|
386
|
+
const previous = snapshots.get(pkg.id);
|
|
387
|
+
return previous?.version && semver$1.inc(previous.version, "release") === pkg.version;
|
|
388
|
+
});
|
|
389
|
+
return graph.getByName(condition.name).some((pkg) => pkg.version === condition.version);
|
|
390
|
+
};
|
|
391
|
+
for (const entry of this.changelogs.values()) {
|
|
392
|
+
const updatedPackages = /* @__PURE__ */ new Map();
|
|
393
|
+
const matchedNames = /* @__PURE__ */ new Set();
|
|
394
|
+
for (const [name, config] of entry.packages) {
|
|
395
|
+
let replay = config.replay;
|
|
396
|
+
if (config.type) replay ??= defaultReplays(name);
|
|
397
|
+
if (!replay || replay.length === 0) continue;
|
|
398
|
+
replay = replay.filter((item) => {
|
|
399
|
+
const condition = parseReplayCondition(item);
|
|
400
|
+
if (condition && isMatch(condition)) {
|
|
401
|
+
matchedNames.add(name);
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
return true;
|
|
405
|
+
});
|
|
406
|
+
if (replay.length === 0) continue;
|
|
407
|
+
const updatedConfig = {
|
|
408
|
+
...config,
|
|
409
|
+
replay
|
|
410
|
+
};
|
|
411
|
+
delete updatedConfig.type;
|
|
412
|
+
updatedPackages.set(name, updatedConfig);
|
|
413
|
+
}
|
|
414
|
+
if (updatedPackages.size > 0) updated.set(entry.id, {
|
|
415
|
+
...entry,
|
|
416
|
+
packages: updatedPackages
|
|
417
|
+
});
|
|
418
|
+
for (const name of matchedNames) for (const pkg of graph.getByName(name)) attachChangelog(this.getOrInitPackage(pkg), entry);
|
|
419
|
+
}
|
|
420
|
+
return updated;
|
|
421
|
+
}
|
|
422
|
+
async appendChangelog(pkg, draft) {
|
|
423
|
+
if (!draft.changelogs || draft.changelogs.length === 0) return;
|
|
424
|
+
const { generator = simpleGenerator() } = this.context.options;
|
|
425
|
+
const generated = await generator.generate.call(this.context, {
|
|
426
|
+
pkg,
|
|
427
|
+
packageDraft: draft,
|
|
428
|
+
draft: this
|
|
429
|
+
});
|
|
430
|
+
const path = join(pkg.path, "CHANGELOG.md");
|
|
431
|
+
const existing = await readFile(path, "utf8").catch(() => "");
|
|
432
|
+
await writeFile(path, `${generated.trim()}\n\n${existing}`.trimEnd() + "\n");
|
|
433
|
+
}
|
|
434
|
+
/** {@link apply} but for `await using` syntax */
|
|
435
|
+
async [Symbol.asyncDispose]() {
|
|
436
|
+
return this.apply();
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
async function createDraft(changelogs, context) {
|
|
440
|
+
let draft = new Draft(context);
|
|
441
|
+
for (const plugin of context.plugins) {
|
|
442
|
+
const result = await handlePluginError(plugin, "initDraft", () => plugin.initDraft?.call(context, draft));
|
|
443
|
+
if (result) draft = result;
|
|
444
|
+
}
|
|
445
|
+
for (const pkg of context.graph.getPackages()) draft.getOrInitPackage(pkg);
|
|
446
|
+
for (const entry of changelogs) draft.addChangelog(entry);
|
|
447
|
+
return draft;
|
|
448
|
+
}
|
|
449
|
+
function attachChangelog(draft, entry) {
|
|
450
|
+
if (draft.changelogs?.some((item) => item.id === entry.id)) return;
|
|
451
|
+
draft.changelogs ??= [];
|
|
452
|
+
draft.changelogs.push(entry);
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
export { parseChangelogFile as a, parsePublishLock as i, createDraft as n, readChangelogEntries as o, packageStoreSchema as r, changelogStoreSchema as t };
|
|
@@ -20,6 +20,17 @@ async function somePromise(promises, fn) {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
function cached(cacheKey, fn, cacheMap = /* @__PURE__ */ new Map()) {
|
|
24
|
+
return (...args) => {
|
|
25
|
+
const key = cacheKey(...args);
|
|
26
|
+
let out = cacheMap.get(key);
|
|
27
|
+
if (!out) {
|
|
28
|
+
out = fn(...args);
|
|
29
|
+
cacheMap.set(key, out);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
23
34
|
//#endregion
|
|
24
35
|
//#region src/utils/error.ts
|
|
25
36
|
var CancelledError = class extends Error {
|
|
@@ -62,4 +73,4 @@ async function handlePluginError(plugin, hookName, callback) {
|
|
|
62
73
|
}
|
|
63
74
|
}
|
|
64
75
|
//#endregion
|
|
65
|
-
export {
|
|
76
|
+
export { cached as a, isNodeError as i, execFailure as n, isCI as o, handlePluginError as r, somePromise as s, CancelledError as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as maxBump, t as bumpDepth } from "./semver-EKJ8yK5U.js";
|
|
2
|
-
import { n as execFailure } from "./error-
|
|
2
|
+
import { n as execFailure } from "./error-We7chQVJ.js";
|
|
3
3
|
import { x } from "tinyexec";
|
|
4
4
|
import z from "zod";
|
|
5
5
|
import { dump } from "js-yaml";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as CommitChangelog, n as Tegami, r as tegami, t as GenerateChangelogOptions } from "./index-CQXmwyLn.js";
|
|
1
|
+
import { A as PackageDraft, D as WorkspacePackage, E as PackageGroup, O as Draft, T as PackageGraph, _ as PublishPlan, a as PublishPreflight, c as TegamiPluginOption, d as tegami, f as CommitChangelog, g as PublishOptions, h as PackagePublishResult, i as PackageOptions, k as DraftPolicy, l as GenerateChangelogOptions, m as PackagePublishPlan, n as GroupOptions, o as TegamiOptions, p as PublishLock, r as LogGenerator, s as TegamiPlugin, u as Tegami } from "./types-DKZsadC8.js";
|
|
3
2
|
export { type CommitChangelog, type Draft, type DraftPolicy, GenerateChangelogOptions, type GroupOptions, type LogGenerator, type PackageDraft, type PackageGraph, type PackageGroup, type PackageOptions, type PackagePublishPlan, type PackagePublishResult, type PublishLock, type PublishOptions, type PublishPlan, type PublishPreflight, Tegami, type TegamiOptions, type TegamiPlugin, type TegamiPluginOption, type WorkspacePackage, tegami };
|