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
package/dist/index.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { o as somePromise, r as handlePluginError } from "./error-D3dwQnwR.js";
|
|
1
|
+
import { n as generateFromCommits } from "./generate-BfYdNTFi.js";
|
|
2
|
+
import { r as handlePluginError, s as somePromise } from "./error-We7chQVJ.js";
|
|
4
3
|
import { t as PackageGraph } from "./graph-gThXu8Cz.js";
|
|
5
4
|
import { cargo } from "./providers/cargo.js";
|
|
6
|
-
import { n as npm } from "./npm-
|
|
7
|
-
import {
|
|
8
|
-
import fs, { mkdir,
|
|
9
|
-
import path, {
|
|
10
|
-
import * as semver$1 from "semver";
|
|
11
|
-
import z from "zod";
|
|
12
|
-
import { dump, load, visit } from "js-yaml";
|
|
13
|
-
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
14
|
-
import { toMarkdown } from "mdast-util-to-markdown";
|
|
5
|
+
import { n as npm } from "./npm-CMOyacwf.js";
|
|
6
|
+
import { a as parseChangelogFile, i as parsePublishLock, n as createDraft, o as readChangelogEntries, r as packageStoreSchema, t as changelogStoreSchema } from "./draft-DtFyGxe8.js";
|
|
7
|
+
import fs, { mkdir, rm, writeFile } from "node:fs/promises";
|
|
8
|
+
import path, { join } from "node:path";
|
|
15
9
|
//#region src/context.ts
|
|
16
10
|
async function createTegamiContext(options = {}) {
|
|
17
11
|
const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
18
12
|
const changelogDir = path.resolve(cwd, options.changelogDir ?? ".tegami");
|
|
19
|
-
const graph = new PackageGraph();
|
|
20
13
|
const ctx = {
|
|
21
14
|
cwd,
|
|
22
15
|
changelogDir,
|
|
@@ -27,9 +20,13 @@ async function createTegamiContext(options = {}) {
|
|
|
27
20
|
cargo(options.cargo),
|
|
28
21
|
...options.plugins ?? []
|
|
29
22
|
]),
|
|
30
|
-
graph
|
|
23
|
+
graph: new PackageGraph()
|
|
31
24
|
};
|
|
32
25
|
for (const plugin of ctx.plugins) await handlePluginError(plugin, "init", () => plugin.init?.call(ctx));
|
|
26
|
+
return ctx;
|
|
27
|
+
}
|
|
28
|
+
async function resolveGraph(ctx) {
|
|
29
|
+
const { options, graph } = ctx;
|
|
33
30
|
for (const plugin of ctx.plugins) await handlePluginError(plugin, "resolve", () => plugin.resolve?.call(ctx));
|
|
34
31
|
const ignoreMatchers = options.ignore?.map((pattern) => {
|
|
35
32
|
if (pattern instanceof RegExp) return (pkg) => pattern.test(pkg.name) || pattern.test(pkg.id);
|
|
@@ -52,7 +49,6 @@ async function createTegamiContext(options = {}) {
|
|
|
52
49
|
pkg.setPackageOptions(packageOptions);
|
|
53
50
|
if (packageOptions.group) graph.addGroupMember(packageOptions.group, pkg.id);
|
|
54
51
|
}
|
|
55
|
-
return ctx;
|
|
56
52
|
}
|
|
57
53
|
const PLUGIN_ORDER = {
|
|
58
54
|
pre: 0,
|
|
@@ -63,439 +59,6 @@ function resolvePlugins(plugins = []) {
|
|
|
63
59
|
return plugins.flat(Infinity).sort((a, b) => PLUGIN_ORDER[a.enforce ?? "default"] - PLUGIN_ORDER[b.enforce ?? "default"]);
|
|
64
60
|
}
|
|
65
61
|
//#endregion
|
|
66
|
-
//#region src/utils/frontmatter.ts
|
|
67
|
-
/**
|
|
68
|
-
* Inspired by https://github.com/jonschlinkert/gray-matter
|
|
69
|
-
*/
|
|
70
|
-
const regex = /^---\r?\n(.+?)\r?\n---\r?\n?/s;
|
|
71
|
-
/**
|
|
72
|
-
* parse frontmatter, it supports only yaml format
|
|
73
|
-
*/
|
|
74
|
-
function frontmatter(input) {
|
|
75
|
-
const output = {
|
|
76
|
-
matter: "",
|
|
77
|
-
data: {},
|
|
78
|
-
content: input
|
|
79
|
-
};
|
|
80
|
-
const match = regex.exec(input);
|
|
81
|
-
if (!match) return output;
|
|
82
|
-
output.matter = match[0];
|
|
83
|
-
output.content = input.slice(match[0].length);
|
|
84
|
-
output.data = load(match[1]) ?? {};
|
|
85
|
-
return output;
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/changelog/parse.ts
|
|
89
|
-
async function getChangelogFiles(context) {
|
|
90
|
-
return (await readdir(context.changelogDir).catch(() => [])).filter((file) => file.endsWith(".md"));
|
|
91
|
-
}
|
|
92
|
-
async function readChangelogEntries(context) {
|
|
93
|
-
const dir = context.changelogDir;
|
|
94
|
-
const files = await getChangelogFiles(context);
|
|
95
|
-
return (await Promise.all(files.map(async (file) => {
|
|
96
|
-
const filePath = join(dir, file);
|
|
97
|
-
const content = await readFile(filePath, "utf8");
|
|
98
|
-
return parseChangelogFile(basename(filePath), content);
|
|
99
|
-
}))).filter((v) => v !== void 0);
|
|
100
|
-
}
|
|
101
|
-
/** Parse one changelog markdown file into release entries. */
|
|
102
|
-
function parseChangelogFile(filename, content) {
|
|
103
|
-
const parsed = frontmatter(content);
|
|
104
|
-
const { success, data } = changelogFrontmatterSchema.safeParse(parsed.data);
|
|
105
|
-
if (!success || !data.packages) return;
|
|
106
|
-
const tree = fromMarkdown(parsed.content);
|
|
107
|
-
let headingBump;
|
|
108
|
-
const packages = /* @__PURE__ */ new Map();
|
|
109
|
-
const sections = [];
|
|
110
|
-
for (const section of getHeadingSections(tree)) {
|
|
111
|
-
const sectionBumpType = headingToBump(section.heading.depth);
|
|
112
|
-
if (sectionBumpType) headingBump = headingBump ? maxBump(headingBump, sectionBumpType) : sectionBumpType;
|
|
113
|
-
sections.push({
|
|
114
|
-
depth: section.heading.depth,
|
|
115
|
-
title: sectionToMarkdown(section.heading.children),
|
|
116
|
-
content: sectionToMarkdown(section.children)
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
if (sections.length === 0) return;
|
|
120
|
-
if (Array.isArray(data.packages)) {
|
|
121
|
-
if (!headingBump) return;
|
|
122
|
-
for (const pkg of data.packages) packages.set(pkg, { type: headingBump });
|
|
123
|
-
} else for (const [k, v] of Object.entries(data.packages)) {
|
|
124
|
-
let config;
|
|
125
|
-
if (typeof v === "string") config = { type: v };
|
|
126
|
-
else if (v === null) config = { type: headingBump };
|
|
127
|
-
else config = v;
|
|
128
|
-
if (config.type || config.replay?.length) packages.set(k, config);
|
|
129
|
-
}
|
|
130
|
-
if (packages.size === 0) return;
|
|
131
|
-
const entry = {
|
|
132
|
-
id: filename,
|
|
133
|
-
filename,
|
|
134
|
-
subject: data.subject,
|
|
135
|
-
packages,
|
|
136
|
-
sections,
|
|
137
|
-
_raw_body: parsed.content,
|
|
138
|
-
getRawContent() {
|
|
139
|
-
return [
|
|
140
|
-
"---",
|
|
141
|
-
dump({
|
|
142
|
-
subject: this.subject,
|
|
143
|
-
packages: Object.fromEntries(this.packages.entries())
|
|
144
|
-
}).trim(),
|
|
145
|
-
"---",
|
|
146
|
-
"",
|
|
147
|
-
entry._raw_body.trim(),
|
|
148
|
-
""
|
|
149
|
-
].join("\n");
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
return entry;
|
|
153
|
-
}
|
|
154
|
-
function parseReplayCondition(condition) {
|
|
155
|
-
if (condition.startsWith("exit prerelease:")) return {
|
|
156
|
-
type: "on-exit-prerelease",
|
|
157
|
-
name: condition.slice(16).trimStart()
|
|
158
|
-
};
|
|
159
|
-
const idx = condition.lastIndexOf("@");
|
|
160
|
-
if (idx <= 0) return null;
|
|
161
|
-
return {
|
|
162
|
-
type: "on-version",
|
|
163
|
-
name: condition.slice(0, idx),
|
|
164
|
-
version: condition.slice(idx + 1)
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function getHeadingSections(tree) {
|
|
168
|
-
const sections = [];
|
|
169
|
-
let current;
|
|
170
|
-
for (const child of tree.children) {
|
|
171
|
-
if (child.type === "heading") {
|
|
172
|
-
current = {
|
|
173
|
-
heading: child,
|
|
174
|
-
children: []
|
|
175
|
-
};
|
|
176
|
-
sections.push(current);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
current?.children.push(child);
|
|
180
|
-
}
|
|
181
|
-
return sections;
|
|
182
|
-
}
|
|
183
|
-
function sectionToMarkdown(children) {
|
|
184
|
-
if (children.length === 0) return "";
|
|
185
|
-
return toMarkdown({
|
|
186
|
-
type: "root",
|
|
187
|
-
children
|
|
188
|
-
}, {
|
|
189
|
-
bullet: "-",
|
|
190
|
-
fence: "`"
|
|
191
|
-
}).trim();
|
|
192
|
-
}
|
|
193
|
-
function headingToBump(depth) {
|
|
194
|
-
switch (depth) {
|
|
195
|
-
case 1: return "major";
|
|
196
|
-
case 2: return "minor";
|
|
197
|
-
case 3: return "patch";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/plans/lock.ts
|
|
202
|
-
function inlineMultilineScalars(documents) {
|
|
203
|
-
visit(documents, (node) => {
|
|
204
|
-
if (node.kind !== "scalar" || !node.value.includes("\n")) return;
|
|
205
|
-
node.style.doubleQuoted = true;
|
|
206
|
-
node.style.literal = false;
|
|
207
|
-
node.style.folded = false;
|
|
208
|
-
node.style.singleQuoted = false;
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
const lockDumpOptions = {
|
|
212
|
-
sortKeys: true,
|
|
213
|
-
lineWidth: -1,
|
|
214
|
-
transform: inlineMultilineScalars
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* the data structure of `publish-lock.yaml` file.
|
|
218
|
-
*/
|
|
219
|
-
var PublishLock = class {
|
|
220
|
-
data;
|
|
221
|
-
constructor(data = /* @__PURE__ */ new Map()) {
|
|
222
|
-
this.data = data;
|
|
223
|
-
}
|
|
224
|
-
/** write data to namespace, note that the `data` must be serializable in yaml */
|
|
225
|
-
write(namespace, data) {
|
|
226
|
-
let arr = this.data.get(namespace);
|
|
227
|
-
if (!arr) {
|
|
228
|
-
arr = [];
|
|
229
|
-
this.data.set(namespace, arr);
|
|
230
|
-
}
|
|
231
|
-
arr.push(data);
|
|
232
|
-
}
|
|
233
|
-
read(namespace) {
|
|
234
|
-
return this.data.get(namespace)?.shift();
|
|
235
|
-
}
|
|
236
|
-
size(namespace) {
|
|
237
|
-
return this.data.get(namespace)?.length ?? 0;
|
|
238
|
-
}
|
|
239
|
-
serialize() {
|
|
240
|
-
let res = dump(Object.fromEntries(this.data.entries()), lockDumpOptions);
|
|
241
|
-
if (!res.endsWith("\n")) res += "\n";
|
|
242
|
-
return res;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
const baseSchema = z.record(z.string(), z.array(z.unknown()));
|
|
246
|
-
function parsePublishLock(content) {
|
|
247
|
-
const data = baseSchema.parse(load(content));
|
|
248
|
-
return new PublishLock(new Map(Object.entries(data)));
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
//#region src/plans/policy.ts
|
|
252
|
-
function groupPolicy({ graph }) {
|
|
253
|
-
return {
|
|
254
|
-
id: "group",
|
|
255
|
-
onUpdate({ pkg, packageDraft }) {
|
|
256
|
-
if (!packageDraft.type) return;
|
|
257
|
-
const group = graph.getPackageGroup(pkg.id);
|
|
258
|
-
if (!group || !group.options.syncBump) return;
|
|
259
|
-
for (const member of group.packages) {
|
|
260
|
-
if (member === pkg) continue;
|
|
261
|
-
this.bumpPackage(member, {
|
|
262
|
-
type: packageDraft.type,
|
|
263
|
-
reason: `sync "${group.name}" group package versions`
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/plans/draft.ts
|
|
271
|
-
const changelogStoreSchema = z.object({
|
|
272
|
-
v: z.literal("0.0.0"),
|
|
273
|
-
filename: z.string(),
|
|
274
|
-
content: z.string()
|
|
275
|
-
});
|
|
276
|
-
const packageStoreSchema = z.object({
|
|
277
|
-
id: z.string(),
|
|
278
|
-
updated: z.boolean(),
|
|
279
|
-
changelogIds: z.array(z.string()).optional()
|
|
280
|
-
});
|
|
281
|
-
/** a draft describes all operations to perform before the actual publishing, such as version bumps. */
|
|
282
|
-
var Draft = class {
|
|
283
|
-
context;
|
|
284
|
-
#applied = false;
|
|
285
|
-
/** package id -> draft */
|
|
286
|
-
packages = /* @__PURE__ */ new Map();
|
|
287
|
-
/** id -> changelog */
|
|
288
|
-
changelogs = /* @__PURE__ */ new Map();
|
|
289
|
-
policies = [];
|
|
290
|
-
constructor(context) {
|
|
291
|
-
this.context = context;
|
|
292
|
-
this.policies.push(groupPolicy(context));
|
|
293
|
-
}
|
|
294
|
-
getPackageDrafts() {
|
|
295
|
-
return this.packages;
|
|
296
|
-
}
|
|
297
|
-
getPackageDraft(id) {
|
|
298
|
-
return this.packages.get(id);
|
|
299
|
-
}
|
|
300
|
-
bumpPackage(pkg, { type, reason }) {
|
|
301
|
-
return this.dispatchPackage(pkg, (draft) => {
|
|
302
|
-
draft.type = draft.type ? maxBump(draft.type, type) : type;
|
|
303
|
-
if (reason) {
|
|
304
|
-
draft.bumpReasons ??= /* @__PURE__ */ new Set();
|
|
305
|
-
draft.bumpReasons.add(reason);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
dispatchPackage(pkg, dispatch, onUpdate) {
|
|
310
|
-
const packageDraft = this.getOrInitPackage(pkg);
|
|
311
|
-
const prevVersion = packageDraft.bumpVersion(pkg);
|
|
312
|
-
dispatch(packageDraft);
|
|
313
|
-
if (prevVersion !== packageDraft.bumpVersion(pkg)) {
|
|
314
|
-
onUpdate?.(packageDraft);
|
|
315
|
-
for (const policy of this.policies) policy.onUpdate?.call(this, {
|
|
316
|
-
packageDraft,
|
|
317
|
-
pkg
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
return packageDraft;
|
|
321
|
-
}
|
|
322
|
-
getOrInitPackage(pkg) {
|
|
323
|
-
const existing = this.packages.get(pkg.id);
|
|
324
|
-
if (existing) return existing;
|
|
325
|
-
this.packages.set(pkg.id, pkg.initDraft());
|
|
326
|
-
return this.dispatchPackage(pkg, (draft) => pkg.configureDraft(draft, this.context.graph.getPackageGroup(pkg.id)), (draft) => {
|
|
327
|
-
(draft.bumpReasons ??= /* @__PURE__ */ new Set()).add("align with script-level configs");
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
hasPending() {
|
|
331
|
-
const { graph } = this.context;
|
|
332
|
-
for (const [id, draft] of this.packages) {
|
|
333
|
-
const pkg = graph.get(id);
|
|
334
|
-
if (pkg && draft.bumpVersion(pkg) !== pkg.version) return true;
|
|
335
|
-
}
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
/** get all changelogs, note that this includes replay-only changelogs, as long as they are in the `.tegami` folder. */
|
|
339
|
-
getChangelogs() {
|
|
340
|
-
return Array.from(this.changelogs.values());
|
|
341
|
-
}
|
|
342
|
-
getChangelog(id) {
|
|
343
|
-
return this.changelogs.get(id);
|
|
344
|
-
}
|
|
345
|
-
addChangelog(entry) {
|
|
346
|
-
this.changelogs.set(entry.id, entry);
|
|
347
|
-
const { graph } = this.context;
|
|
348
|
-
const groupPackages = /* @__PURE__ */ new Map();
|
|
349
|
-
for (const [name, config] of entry.packages) {
|
|
350
|
-
if (!config.type) continue;
|
|
351
|
-
for (const pkg of graph.getByName(name)) groupPackages.set(pkg, config.type);
|
|
352
|
-
}
|
|
353
|
-
for (const [pkg, bumpType] of groupPackages) attachChangelog(this.bumpPackage(pkg, { type: bumpType }), entry);
|
|
354
|
-
}
|
|
355
|
-
deleteChangelog(id) {
|
|
356
|
-
return this.changelogs.delete(id);
|
|
357
|
-
}
|
|
358
|
-
/** Apply version bumps, lock file, and changelog files. */
|
|
359
|
-
async apply() {
|
|
360
|
-
if (this.#applied) throw new Error("This draft has already been applied.");
|
|
361
|
-
const { graph } = this.context;
|
|
362
|
-
this.#applied = true;
|
|
363
|
-
const snapshots = /* @__PURE__ */ new Map();
|
|
364
|
-
for (const pkg of graph.getPackages()) snapshots.set(pkg.id, { version: pkg.version });
|
|
365
|
-
for (const plugin of this.context.plugins) await handlePluginError(plugin, "applyDraft", () => plugin.applyDraft?.call(this.context, this));
|
|
366
|
-
const updatedChangelogs = this.applyReplays(snapshots);
|
|
367
|
-
const writes = [];
|
|
368
|
-
for (const [id, packageDraft] of this.packages) {
|
|
369
|
-
const pkg = graph.get(id);
|
|
370
|
-
if (!pkg) continue;
|
|
371
|
-
writes.push(this.appendChangelog(pkg, packageDraft));
|
|
372
|
-
}
|
|
373
|
-
for (const entry of this.changelogs.values()) {
|
|
374
|
-
const updated = updatedChangelogs.get(entry.id);
|
|
375
|
-
const filePath = path.join(this.context.changelogDir, entry.filename);
|
|
376
|
-
if (updated) writes.push(mkdir(this.context.changelogDir, { recursive: true }).then(() => writeFile(filePath, updated.getRawContent())));
|
|
377
|
-
else if (!entry.virtual) writes.push(rm(filePath, { force: true }));
|
|
378
|
-
}
|
|
379
|
-
writes.push(this.writeLockFile(snapshots));
|
|
380
|
-
await Promise.all(writes);
|
|
381
|
-
}
|
|
382
|
-
/** write persistent data to publish lock */
|
|
383
|
-
async writeLockFile(snapshots) {
|
|
384
|
-
const lock = new PublishLock();
|
|
385
|
-
const changelogs = /* @__PURE__ */ new Set();
|
|
386
|
-
for (const pkg of this.context.graph.getPackages()) {
|
|
387
|
-
const draft = this.getPackageDraft(pkg.id);
|
|
388
|
-
const snapshot = snapshots.get(pkg.id);
|
|
389
|
-
if (!snapshot) continue;
|
|
390
|
-
for (const entry of draft?.changelogs ?? []) changelogs.add(entry);
|
|
391
|
-
lock.write("core:packages", {
|
|
392
|
-
id: pkg.id,
|
|
393
|
-
updated: draft !== void 0 && snapshot.version !== pkg.version,
|
|
394
|
-
changelogIds: draft?.changelogs?.map((entry) => entry.id)
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
for (const entry of changelogs) lock.write("core:changelogs", {
|
|
398
|
-
v: "0.0.0",
|
|
399
|
-
filename: entry.filename,
|
|
400
|
-
content: entry.getRawContent()
|
|
401
|
-
});
|
|
402
|
-
for (const plugin of this.context.plugins) await handlePluginError(plugin, "initPublishLock", () => plugin.initPublishLock?.call(this.context, {
|
|
403
|
-
lock,
|
|
404
|
-
draft: this
|
|
405
|
-
}));
|
|
406
|
-
await mkdir(dirname(this.context.lockPath), { recursive: true });
|
|
407
|
-
await writeFile(this.context.lockPath, lock.serialize());
|
|
408
|
-
}
|
|
409
|
-
addPolicy(policy) {
|
|
410
|
-
this.policies.push(policy);
|
|
411
|
-
}
|
|
412
|
-
removePolicy(policy) {
|
|
413
|
-
const idx = this.policies.indexOf(policy);
|
|
414
|
-
if (idx !== -1) this.policies.splice(idx, 1);
|
|
415
|
-
}
|
|
416
|
-
canApply() {
|
|
417
|
-
return !this.#applied;
|
|
418
|
-
}
|
|
419
|
-
/** Attach replaying changelog entries to packages (already bumped), and return the updated changelog entries. */
|
|
420
|
-
applyReplays(snapshots) {
|
|
421
|
-
const updated = /* @__PURE__ */ new Map();
|
|
422
|
-
const { graph } = this.context;
|
|
423
|
-
const defaultReplays = (name) => {
|
|
424
|
-
const replay = [];
|
|
425
|
-
for (const pkg of graph.getByName(name)) if (this.packages.get(pkg.id)?.prerelease) replay.push(`exit prerelease: ${pkg.id}`);
|
|
426
|
-
return replay;
|
|
427
|
-
};
|
|
428
|
-
const isMatch = (condition) => {
|
|
429
|
-
if (condition.type === "on-exit-prerelease") return graph.getByName(condition.name).some((pkg) => {
|
|
430
|
-
const previous = snapshots.get(pkg.id);
|
|
431
|
-
return previous?.version && semver$1.inc(previous.version, "release") === pkg.version;
|
|
432
|
-
});
|
|
433
|
-
return graph.getByName(condition.name).some((pkg) => pkg.version === condition.version);
|
|
434
|
-
};
|
|
435
|
-
for (const entry of this.changelogs.values()) {
|
|
436
|
-
const updatedPackages = /* @__PURE__ */ new Map();
|
|
437
|
-
const matchedNames = /* @__PURE__ */ new Set();
|
|
438
|
-
for (const [name, config] of entry.packages) {
|
|
439
|
-
let replay = config.replay;
|
|
440
|
-
if (config.type) replay ??= defaultReplays(name);
|
|
441
|
-
if (!replay || replay.length === 0) continue;
|
|
442
|
-
replay = replay.filter((item) => {
|
|
443
|
-
const condition = parseReplayCondition(item);
|
|
444
|
-
if (condition && isMatch(condition)) {
|
|
445
|
-
matchedNames.add(name);
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
return true;
|
|
449
|
-
});
|
|
450
|
-
if (replay.length === 0) continue;
|
|
451
|
-
const updatedConfig = {
|
|
452
|
-
...config,
|
|
453
|
-
replay
|
|
454
|
-
};
|
|
455
|
-
delete updatedConfig.type;
|
|
456
|
-
updatedPackages.set(name, updatedConfig);
|
|
457
|
-
}
|
|
458
|
-
if (updatedPackages.size > 0) updated.set(entry.id, {
|
|
459
|
-
...entry,
|
|
460
|
-
packages: updatedPackages
|
|
461
|
-
});
|
|
462
|
-
for (const name of matchedNames) for (const pkg of graph.getByName(name)) attachChangelog(this.getOrInitPackage(pkg), entry);
|
|
463
|
-
}
|
|
464
|
-
return updated;
|
|
465
|
-
}
|
|
466
|
-
async appendChangelog(pkg, draft) {
|
|
467
|
-
if (!draft.changelogs || draft.changelogs.length === 0) return;
|
|
468
|
-
const { generator = simpleGenerator() } = this.context.options;
|
|
469
|
-
const generated = await generator.generate.call(this.context, {
|
|
470
|
-
pkg,
|
|
471
|
-
packageDraft: draft,
|
|
472
|
-
draft: this
|
|
473
|
-
});
|
|
474
|
-
const path = join(pkg.path, "CHANGELOG.md");
|
|
475
|
-
const existing = await readFile(path, "utf8").catch(() => "");
|
|
476
|
-
await writeFile(path, `${generated.trim()}\n\n${existing}`.trimEnd() + "\n");
|
|
477
|
-
}
|
|
478
|
-
/** {@link apply} but for `await using` syntax */
|
|
479
|
-
async [Symbol.asyncDispose]() {
|
|
480
|
-
return this.apply();
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
async function createDraft(changelogs, context) {
|
|
484
|
-
let draft = new Draft(context);
|
|
485
|
-
for (const plugin of context.plugins) {
|
|
486
|
-
const result = await handlePluginError(plugin, "initDraft", () => plugin.initDraft?.call(context, draft));
|
|
487
|
-
if (result) draft = result;
|
|
488
|
-
}
|
|
489
|
-
for (const pkg of context.graph.getPackages()) draft.getOrInitPackage(pkg);
|
|
490
|
-
for (const entry of changelogs) draft.addChangelog(entry);
|
|
491
|
-
return draft;
|
|
492
|
-
}
|
|
493
|
-
function attachChangelog(draft, entry) {
|
|
494
|
-
if (draft.changelogs?.some((item) => item.id === entry.id)) return;
|
|
495
|
-
draft.changelogs ??= [];
|
|
496
|
-
draft.changelogs.push(entry);
|
|
497
|
-
}
|
|
498
|
-
//#endregion
|
|
499
62
|
//#region src/plans/publish.ts
|
|
500
63
|
async function initPublishPlan(context, options) {
|
|
501
64
|
let lock;
|
|
@@ -629,14 +192,21 @@ async function publishPlanStatus(plan, context) {
|
|
|
629
192
|
//#region src/index.ts
|
|
630
193
|
/** Create a Tegami project handle. */
|
|
631
194
|
function tegami(options = {}) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
195
|
+
let $context;
|
|
196
|
+
let $contextResolved;
|
|
197
|
+
function getContext() {
|
|
198
|
+
return $context ??= createTegamiContext(options);
|
|
199
|
+
}
|
|
200
|
+
function getContextResolved() {
|
|
201
|
+
return $contextResolved ??= getContext().then(async (ctx) => {
|
|
202
|
+
await resolveGraph(ctx);
|
|
203
|
+
return ctx;
|
|
204
|
+
});
|
|
635
205
|
}
|
|
636
206
|
return {
|
|
637
207
|
async generateChangelog(generateOptions = {}) {
|
|
638
208
|
const { write = true } = generateOptions;
|
|
639
|
-
const context = await
|
|
209
|
+
const context = await getContextResolved();
|
|
640
210
|
const changelogs = await generateFromCommits(context, generateOptions);
|
|
641
211
|
if (write && changelogs.length > 0) {
|
|
642
212
|
await mkdir(context.changelogDir, { recursive: true });
|
|
@@ -646,15 +216,11 @@ function tegami(options = {}) {
|
|
|
646
216
|
},
|
|
647
217
|
_internal: {
|
|
648
218
|
options,
|
|
649
|
-
context
|
|
650
|
-
|
|
651
|
-
},
|
|
652
|
-
async graph() {
|
|
653
|
-
return (await $context).graph;
|
|
654
|
-
}
|
|
219
|
+
context: getContextResolved,
|
|
220
|
+
contextUnresolved: getContext
|
|
655
221
|
},
|
|
656
222
|
async draft() {
|
|
657
|
-
const context = await
|
|
223
|
+
const context = await getContextResolved();
|
|
658
224
|
const changelogs = await readChangelogEntries(context);
|
|
659
225
|
if (context.options.conventionalCommits) {
|
|
660
226
|
const generated = await generateFromCommits(context);
|
|
@@ -668,14 +234,14 @@ function tegami(options = {}) {
|
|
|
668
234
|
return createDraft(changelogs, context);
|
|
669
235
|
},
|
|
670
236
|
async publishStatus() {
|
|
671
|
-
const context = await
|
|
237
|
+
const context = await getContextResolved();
|
|
672
238
|
const plan = await initPublishPlan(context, {});
|
|
673
239
|
if (!plan) return "idle";
|
|
674
240
|
await runPreflights(context, plan);
|
|
675
241
|
return publishPlanStatus(plan, context);
|
|
676
242
|
},
|
|
677
243
|
async publish(publishOptions = {}) {
|
|
678
|
-
const context = await
|
|
244
|
+
const context = await getContextResolved();
|
|
679
245
|
const plan = await initPublishPlan(context, publishOptions);
|
|
680
246
|
if (!plan) return "skipped";
|
|
681
247
|
await runPreflights(context, plan);
|
|
@@ -685,7 +251,7 @@ function tegami(options = {}) {
|
|
|
685
251
|
return plan;
|
|
686
252
|
},
|
|
687
253
|
async cleanup() {
|
|
688
|
-
const context = await
|
|
254
|
+
const context = await getContextResolved();
|
|
689
255
|
const plan = await initPublishPlan(context, {});
|
|
690
256
|
if (!plan) return {
|
|
691
257
|
state: "skipped",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as isNodeError, n as execFailure } from "./error-
|
|
1
|
+
import { i as isNodeError, n as execFailure } from "./error-We7chQVJ.js";
|
|
2
2
|
import { n as WorkspacePackage } from "./graph-gThXu8Cz.js";
|
|
3
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
@@ -198,7 +198,7 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = t
|
|
|
198
198
|
let updatedRange;
|
|
199
199
|
const isPeer = field === "peerDependencies";
|
|
200
200
|
if (isPeer && onBreakPeerDep === "ignore") continue;
|
|
201
|
-
|
|
201
|
+
if (isPeer && onBreakPeerDep === "set") updatedRange = spec.linked.version;
|
|
202
202
|
else if (isPeer && onBreakPeerDep === "error") throw new Error(`[Tegami] the version of "${spec.linked.name}" is beyond its peer dependency constraint "${v}" in package "${pkg.name}", please update the constraint to satisfy.`);
|
|
203
203
|
else if (spec.range.startsWith("^")) updatedRange = `^${spec.linked.version}`;
|
|
204
204
|
else if (spec.range.startsWith("~")) updatedRange = `~${spec.linked.version}`;
|
|
@@ -213,7 +213,7 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = t
|
|
|
213
213
|
}
|
|
214
214
|
await Promise.all(writes);
|
|
215
215
|
},
|
|
216
|
-
|
|
216
|
+
async applyCliDraft() {
|
|
217
217
|
if (!active || !updateLockFile) return;
|
|
218
218
|
let args;
|
|
219
219
|
if (client === "npm") args = ["ci"];
|
|
@@ -222,7 +222,7 @@ function npm({ client: defaultClient, onBreakPeerDep = "set", updateLockFile = t
|
|
|
222
222
|
else args = ["install", "--frozen-lockfile"];
|
|
223
223
|
const result = await x(client, args, { nodeOptions: { cwd: this.cwd } });
|
|
224
224
|
if (result.exitCode !== 0) throw execFailure("Failed to update lockfile.", result);
|
|
225
|
-
}
|
|
225
|
+
}
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
function depsPolicy(context, getBumpDepType) {
|
package/dist/plugins/git.d.ts
CHANGED
package/dist/plugins/git.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as execFailure, o as isCI } from "../error-We7chQVJ.js";
|
|
2
2
|
import { x } from "tinyexec";
|
|
3
3
|
//#region src/plugins/git.ts
|
|
4
4
|
/**
|
|
@@ -23,7 +23,7 @@ function git(options = {}) {
|
|
|
23
23
|
return {
|
|
24
24
|
name: "git",
|
|
25
25
|
enforce: "pre",
|
|
26
|
-
|
|
26
|
+
async initCli() {
|
|
27
27
|
if (!isCI()) return;
|
|
28
28
|
const gitOptions = { nodeOptions: { cwd: this.cwd } };
|
|
29
29
|
for (const args of [[
|
|
@@ -35,10 +35,10 @@ function git(options = {}) {
|
|
|
35
35
|
"user.email",
|
|
36
36
|
"41898282+github-actions[bot]@users.noreply.github.com"
|
|
37
37
|
]]) {
|
|
38
|
-
const result = await x("git",
|
|
38
|
+
const result = await x("git", args, gitOptions);
|
|
39
39
|
if (result.exitCode !== 0) throw execFailure("Failed to configure git user for GitHub Actions.", result);
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
42
|
initPublishPlan({ plan }) {
|
|
43
43
|
const { graph } = this;
|
|
44
44
|
for (const [id, packagePlan] of plan.packages) {
|
package/dist/plugins/github.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as WorkspacePackage, O as Draft, _ as PublishPlan, s as TegamiPlugin, t as Awaitable, w as TegamiContext } from "../types-DKZsadC8.js";
|
|
2
2
|
import { GitPluginOptions } from "./git.js";
|
|
3
3
|
|
|
4
4
|
//#region src/plugins/github.d.ts
|