tegami 1.0.1 → 1.1.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.
@@ -1,4 +1,4 @@
1
- import { T as Draft, p as Tegami, t as Awaitable, y as PublishPlan } from "../types-DItu_YCc.js";
1
+ import { k as Draft, p as Tegami, t as Awaitable, y as PublishPlan } from "../types-BoQR7Hlg.js";
2
2
 
3
3
  //#region src/cli/index.d.ts
4
4
  interface TegamiCLIOptions {
package/dist/cli/index.js CHANGED
@@ -124,14 +124,11 @@ async function promptPackageSelection(graph, cwd) {
124
124
  groups.push([group, changed]);
125
125
  }
126
126
  groups.sort((a, b) => (a[1] ? 0 : 1) - (b[1] ? 0 : 1));
127
- for (const [group, changed] of groups) {
128
- if (changed) initialValues.add(`group:${group.name}`);
129
- selectOptions.push({
130
- label: `(Group) ${group.name}` + (changed ? "*" : ""),
131
- value: `group:${group.name}`,
132
- hint: group.packages.map(getPackageLabel).join(", ")
133
- });
134
- }
127
+ for (const [group, changed] of groups) selectOptions.push({
128
+ label: `(Group) ${group.name}` + (changed ? "*" : ""),
129
+ value: `group:${group.name}`,
130
+ hint: group.packages.map(getPackageLabel).join(", ")
131
+ });
135
132
  const packages = graph.getPackages().toSorted((a, b) => (changedPackages.has(a) ? 0 : 1) - (changedPackages.has(b) ? 0 : 1));
136
133
  for (const pkg of packages) {
137
134
  const changed = changedPackages.has(pkg);
@@ -87,18 +87,33 @@ function parseChangelogFile(filename, content) {
87
87
  };
88
88
  return entry;
89
89
  }
90
+ function formatReplayCondition(condition) {
91
+ switch (condition.on) {
92
+ case "exit-prerelease": return `exit-prerelease(${condition.name})`;
93
+ case "enter-prerelease": return `prerelease(${condition.name})`;
94
+ case "version": return `${condition.name}@${condition.version}`;
95
+ }
96
+ }
90
97
  function parseReplayCondition(condition) {
91
- if (condition.startsWith("exit prerelease:")) return {
92
- type: "on-exit-prerelease",
93
- name: condition.slice(16).trimStart()
98
+ let match;
99
+ if (match = /^exit-prerelease\((.+)\)$/.exec(condition)) return {
100
+ on: "exit-prerelease",
101
+ name: match[1]
94
102
  };
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)
103
+ if (match = /^prerelease\((.+)\)$/.exec(condition)) return {
104
+ on: "enter-prerelease",
105
+ name: match[1]
106
+ };
107
+ if (match = /^exit prerelease:\s*(.+)$/.exec(condition)) return {
108
+ on: "exit-prerelease",
109
+ name: match[1]
110
+ };
111
+ if (match = /^(.+)@([^@]+)$/.exec(condition)) return {
112
+ on: "version",
113
+ name: match[1],
114
+ version: match[2]
101
115
  };
116
+ return null;
102
117
  }
103
118
  function parseMarkdownSections(markdown) {
104
119
  const sections = [];
@@ -205,12 +220,12 @@ function parsePublishLock(content) {
205
220
  }
206
221
  //#endregion
207
222
  //#region src/plans/policy.ts
208
- function groupPolicy({ graph }) {
223
+ function groupPolicy(_ctx) {
209
224
  return {
210
225
  id: "group",
211
226
  onUpdate({ pkg, packageDraft }) {
212
227
  if (!packageDraft.type) return;
213
- const group = graph.getPackageGroup(pkg.id);
228
+ const group = pkg.group;
214
229
  if (!group || !group.options.syncBump) return;
215
230
  for (const member of group.packages) {
216
231
  if (member === pkg) continue;
@@ -279,7 +294,7 @@ var Draft = class {
279
294
  const existing = this.packages.get(pkg.id);
280
295
  if (existing) return existing;
281
296
  this.packages.set(pkg.id, pkg.initDraft());
282
- return this.dispatchPackage(pkg, (draft) => pkg.configureDraft(draft, this.context.graph.getPackageGroup(pkg.id)), (draft) => {
297
+ return this.dispatchPackage(pkg, (draft) => pkg.configureDraft({ draft }), (draft) => {
283
298
  (draft.bumpReasons ??= /* @__PURE__ */ new Set()).add("align with script-level configs");
284
299
  });
285
300
  }
@@ -387,15 +402,26 @@ var Draft = class {
387
402
  const { graph } = this.context;
388
403
  const defaultReplays = (name) => {
389
404
  const replay = [];
390
- for (const pkg of graph.getByName(name)) if (this.packages.get(pkg.id)?.prerelease) replay.push(`exit prerelease: ${pkg.id}`);
405
+ for (const pkg of graph.getByName(name)) if (this.packages.get(pkg.id)?.prerelease) replay.push(formatReplayCondition({
406
+ on: "exit-prerelease",
407
+ name: pkg.id
408
+ }));
391
409
  return replay;
392
410
  };
393
411
  const isMatch = (condition) => {
394
- if (condition.type === "on-exit-prerelease") return graph.getByName(condition.name).some((pkg) => {
395
- const previous = snapshots.get(pkg.id);
396
- return previous?.version && semver$1.inc(previous.version, "release") === pkg.version;
397
- });
398
- return graph.getByName(condition.name).some((pkg) => pkg.version === condition.version);
412
+ switch (condition.on) {
413
+ case "enter-prerelease": return graph.getByName(condition.name).some((pkg) => {
414
+ const previous = snapshots.get(pkg.id);
415
+ if (!pkg.version || !previous?.version) return false;
416
+ return !semver$1.prerelease(previous.version) && semver$1.prerelease(pkg.version);
417
+ });
418
+ case "exit-prerelease": return graph.getByName(condition.name).some((pkg) => {
419
+ const previous = snapshots.get(pkg.id);
420
+ if (!pkg.version || !previous?.version) return false;
421
+ return semver$1.inc(previous.version, "release") === pkg.version;
422
+ });
423
+ case "version": return graph.getByName(condition.name).some((pkg) => pkg.version === condition.version);
424
+ }
399
425
  };
400
426
  for (const entry of this.changelogs.values()) {
401
427
  const updatedPackages = /* @__PURE__ */ new Map();
@@ -1,4 +1,4 @@
1
- import { r as LogGenerator } from "../types-DItu_YCc.js";
1
+ import { r as LogGenerator } from "../types-BoQR7Hlg.js";
2
2
 
3
3
  //#region src/generators/simple.d.ts
4
4
  declare function simpleGenerator(): LogGenerator;
@@ -2,17 +2,13 @@ import { n as bumpVersion } from "./semver-EKJ8yK5U.js";
2
2
  //#region src/graph.ts
3
3
  /** Package discovered in the workspace. */
4
4
  var WorkspacePackage = class {
5
+ /** note: this will only be available after package graph is resolved */
6
+ group;
7
+ /** note: this will only be available after package graph is resolved */
8
+ options = {};
5
9
  get id() {
6
10
  return `${this.manager}:${this.name}`;
7
11
  }
8
- opts = {};
9
- /** note: this will only be available after package graph is resolved */
10
- getPackageOptions() {
11
- return this.opts;
12
- }
13
- setPackageOptions(options) {
14
- this.opts = options;
15
- }
16
12
  /** create the initial draft. */
17
13
  initDraft() {
18
14
  return { bumpVersion(pkg) {
@@ -21,12 +17,17 @@ var WorkspacePackage = class {
21
17
  } };
22
18
  }
23
19
  /** configure an initial draft to match script-level configs. */
24
- configureDraft(draft, group) {
25
- const { prerelease = group?.options?.prerelease } = this.opts;
20
+ configureDraft({ draft }) {
21
+ const { prerelease = this.group?.options?.prerelease } = this.options;
26
22
  if (prerelease !== void 0) draft.prerelease = prerelease;
27
23
  }
28
24
  };
29
- /** Dependency graph for discovered workspace packages. */
25
+ /**
26
+ * Unified graph for discovered workspace packages.
27
+ *
28
+ * This is only used as a storage for all indexed packages.
29
+ * For registry-specific relationships (e.g. virtual workspaces), they are stored in the provider plugin internally.
30
+ */
30
31
  var PackageGraph = class {
31
32
  packages = /* @__PURE__ */ new Map();
32
33
  groups = /* @__PURE__ */ new Map();
@@ -34,27 +35,25 @@ var PackageGraph = class {
34
35
  for (const pkg of packages) this.add(pkg);
35
36
  }
36
37
  getPackages() {
37
- const out = [];
38
- for (const pkg of this.packages.values()) out.push(pkg.value);
39
- return out;
38
+ return Array.from(this.packages.values());
40
39
  }
41
40
  /** Get a package by exact id. */
42
41
  get(id) {
43
- return this.packages.get(id)?.value;
42
+ return this.packages.get(id);
44
43
  }
45
44
  /** Get packages by id, `group:name`, or every package matching a name. */
46
45
  getByName(nameOrId) {
47
46
  const exact = this.packages.get(nameOrId);
48
- if (exact) return [exact.value];
47
+ if (exact) return [exact];
49
48
  if (nameOrId.startsWith("group:")) return this.getGroup(nameOrId.slice(6))?.packages ?? [];
50
49
  const out = [];
51
- for (const { value } of this.packages.values()) if (value.name === nameOrId) out.push(value);
50
+ for (const value of this.packages.values()) if (value.name === nameOrId) out.push(value);
52
51
  return out;
53
52
  }
54
53
  /** scan package into graph, if the package id already exists, replace the existing one in graph */
55
54
  add(pkg) {
56
55
  this.delete(pkg.id);
57
- this.packages.set(pkg.id, { value: pkg });
56
+ this.packages.set(pkg.id, pkg);
58
57
  }
59
58
  delete(id) {
60
59
  this.packages.delete(id);
@@ -91,7 +90,7 @@ var PackageGraph = class {
91
90
  const pkg = this.packages.get(id);
92
91
  if (!group || !pkg || pkg.group) return;
93
92
  pkg.group = group;
94
- group.packages.push(pkg.value);
93
+ group.packages.push(pkg);
95
94
  }
96
95
  removeGroupMember(group, id) {
97
96
  const entry = this.groups.get(group);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as PackageGroup, D as PackageDraft, E as DraftPolicy, O as BumpType, S as PackageGraph, T as Draft, _ as PackagePublishResult, a as PublishPreflight, b as CommitChangelog, c as TegamiPluginOption, f as GenerateChangelogOptions, g as PackagePublishPlan, h as PublishLock, i as PackageOptions, m as tegami, n as GroupOptions, o as TegamiOptions, p as Tegami, r as LogGenerator, s as TegamiPlugin, v as PublishOptions, w as WorkspacePackage, x as TegamiContext, y as PublishPlan } from "./types-DItu_YCc.js";
1
+ import { A as DraftPolicy, D as PackageGroup, E as PackageGraph, M as BumpType, O as WorkspacePackage, _ as PackagePublishResult, a as PublishPreflight, b as CommitChangelog, c as TegamiPluginOption, f as GenerateChangelogOptions, g as PackagePublishPlan, h as PublishLock, i as PackageOptions, j as PackageDraft, k as Draft, m as tegami, n as GroupOptions, o as TegamiOptions, p as Tegami, r as LogGenerator, s as TegamiPlugin, v as PublishOptions, x as TegamiContext, y as PublishPlan } from "./types-BoQR7Hlg.js";
2
2
  export { type BumpType, type CommitChangelog, type Draft, type DraftPolicy, GenerateChangelogOptions, type GroupOptions, type LogGenerator, type PackageDraft, PackageGraph, type PackageGroup, type PackageOptions, type PackagePublishPlan, type PackagePublishResult, type PublishLock, type PublishOptions, type PublishPlan, type PublishPreflight, Tegami, type TegamiContext, type TegamiOptions, type TegamiPlugin, type TegamiPluginOption, WorkspacePackage, tegami };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { n as generateFromCommits } from "./generate-Rvz4Lu98.js";
2
2
  import { r as handlePluginError } from "./error-BhMYq9iW.js";
3
- import { a as runPreflights, i as publishPlanStatus, n as npm, o as runPublishPlan, r as initPublishPlan } from "./npm-1iEegfHg.js";
4
- import { n as WorkspacePackage, t as PackageGraph } from "./graph-gThXu8Cz.js";
5
- import { a as parseChangelogFile, n as createDraft, o as readChangelogEntries } from "./draft-BqHcSCeX.js";
3
+ import { a as runPreflights, i as publishPlanStatus, n as npm, o as runPublishPlan, r as initPublishPlan } from "./npm-Cj685Ddn.js";
4
+ import { n as WorkspacePackage, t as PackageGraph } from "./graph-BmXTJZxx.js";
5
+ import { a as parseChangelogFile, n as createDraft, o as readChangelogEntries } from "./draft-BLbt4bSG.js";
6
6
  import { mkdir, rm, writeFile } from "node:fs/promises";
7
7
  import path, { join } from "node:path";
8
8
  //#region src/context.ts
@@ -41,7 +41,7 @@ async function resolveGraph(ctx) {
41
41
  }
42
42
  const packageOptions = getPackageOptions?.(pkg);
43
43
  if (!packageOptions) continue;
44
- pkg.setPackageOptions(packageOptions);
44
+ pkg.options = packageOptions;
45
45
  if (packageOptions.group) graph.addGroupMember(packageOptions.group, pkg.id);
46
46
  }
47
47
  }
@@ -1,6 +1,6 @@
1
1
  import { c as somePromise, i as isNodeError, n as execFailure, r as handlePluginError, s as joinPath } from "./error-BhMYq9iW.js";
2
- import { n as WorkspacePackage } from "./graph-gThXu8Cz.js";
3
- import { a as parseChangelogFile, i as parsePublishLock, r as packageStoreSchema, t as changelogStoreSchema } from "./draft-BqHcSCeX.js";
2
+ import { n as WorkspacePackage } from "./graph-BmXTJZxx.js";
3
+ import { a as parseChangelogFile, i as parsePublishLock, r as packageStoreSchema, t as changelogStoreSchema } from "./draft-BLbt4bSG.js";
4
4
  import fs, { readFile, writeFile } from "node:fs/promises";
5
5
  import path, { join } from "node:path";
6
6
  import { x } from "tinyexec";
@@ -133,27 +133,25 @@ async function runPublishPlan(context, plan) {
133
133
  }
134
134
  async function runPreflights(context, plan) {
135
135
  const promises = [];
136
- const runPreflight = async (pkg) => {
137
- for (const plugin of context.plugins) {
138
- const res = await handlePluginError(plugin, "publishPreflight", () => plugin.publishPreflight?.call(context, {
139
- pkg,
140
- plan
141
- }));
142
- if (res) return res;
143
- }
144
- return { shouldPublish: false };
145
- };
146
136
  for (const [id, packagePlan] of plan.packages) {
147
137
  const pkg = context.graph.get(id);
148
- if (!packagePlan.updated) {
149
- packagePlan.preflight = { shouldPublish: false };
150
- continue;
151
- }
152
- promises.push(runPreflight(pkg).then((preflight) => {
153
- packagePlan.preflight = preflight;
154
- }));
138
+ packagePlan.preflight = { shouldPublish: false };
139
+ if (!packagePlan.updated) continue;
140
+ promises.push((async () => {
141
+ for (const plugin of context.plugins) {
142
+ const res = await handlePluginError(plugin, "publishPreflight", () => plugin.publishPreflight?.call(context, {
143
+ pkg,
144
+ plan
145
+ }));
146
+ if (res) {
147
+ packagePlan.preflight = res;
148
+ break;
149
+ }
150
+ }
151
+ })());
155
152
  }
156
153
  await Promise.all(promises);
154
+ for (const plugin of context.plugins) await handlePluginError(plugin, "afterPreflight", () => plugin.afterPreflight?.call(context, { plan }));
157
155
  }
158
156
  async function publishPlanStatus(plan, context) {
159
157
  for (const plugin of context.plugins) {
@@ -329,9 +327,9 @@ var NpmPackage = class extends WorkspacePackage {
329
327
  getRegistry() {
330
328
  return this.manifest.publishConfig?.registry ?? "https://registry.npmjs.org";
331
329
  }
332
- configureDraft(draft, group) {
333
- super.configureDraft(draft, group);
334
- const { distTag = group?.options?.npm?.distTag } = this.getPackageOptions().npm ?? {};
330
+ configureDraft({ draft }) {
331
+ super.configureDraft({ draft });
332
+ const { distTag = this.group?.options?.npm?.distTag } = this.options.npm ?? {};
335
333
  if (distTag) {
336
334
  draft.npm ??= {};
337
335
  draft.npm.distTag = distTag;
@@ -570,11 +568,10 @@ function depsPolicy(context, getBumpDepType) {
570
568
  if (!(pkg instanceof NpmPackage)) return;
571
569
  const deps = dependentMap.get(pkg.id);
572
570
  if (!deps) return;
573
- const group = graph.getPackageGroup(pkg.id);
574
571
  const bumped = plan.bumpVersion(pkg);
575
572
  if (!bumped) return;
576
573
  for (const dep of deps) {
577
- if (group?.options.syncBump && graph.getPackageGroup(dep.dependent.id) === group) continue;
574
+ if (pkg.group?.options.syncBump && dep.dependent.group === pkg.group) continue;
578
575
  if (!needsUpdate(dep.spec, bumped)) continue;
579
576
  const bumpType = getBumpDepType(dep);
580
577
  if (bumpType === false) continue;
@@ -1,97 +1,2 @@
1
- import { O as BumpType, s as TegamiPlugin, w as WorkspacePackage } from "../types-DItu_YCc.js";
2
- import z from "zod";
3
-
4
- //#region src/plugins/cargo/schema.d.ts
5
- declare const cargoManifestSchema: z.ZodObject<{
6
- package: z.ZodObject<{
7
- name: z.ZodString;
8
- version: z.ZodOptional<z.ZodString>;
9
- publish: z.ZodOptional<z.ZodBoolean>;
10
- }, z.core.$strip>;
11
- workspace: z.ZodOptional<z.ZodObject<{
12
- members: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
- exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
- package: z.ZodOptional<z.ZodObject<{
15
- version: z.ZodOptional<z.ZodString>;
16
- }, z.core.$strip>>;
17
- }, z.core.$strip>>;
18
- dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
19
- version: z.ZodString;
20
- package: z.ZodOptional<z.ZodString>;
21
- path: z.ZodOptional<z.ZodString>;
22
- }, z.core.$strip>]>>>;
23
- "dev-dependencies": z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
24
- version: z.ZodString;
25
- package: z.ZodOptional<z.ZodString>;
26
- path: z.ZodOptional<z.ZodString>;
27
- }, z.core.$strip>]>>>;
28
- "build-dependencies": z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
29
- version: z.ZodString;
30
- package: z.ZodOptional<z.ZodString>;
31
- path: z.ZodOptional<z.ZodString>;
32
- }, z.core.$strip>]>>>;
33
- target: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
34
- dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
35
- version: z.ZodString;
36
- package: z.ZodOptional<z.ZodString>;
37
- path: z.ZodOptional<z.ZodString>;
38
- }, z.core.$strip>]>>>;
39
- "dev-dependencies": z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
40
- version: z.ZodString;
41
- package: z.ZodOptional<z.ZodString>;
42
- path: z.ZodOptional<z.ZodString>;
43
- }, z.core.$strip>]>>>;
44
- "build-dependencies": z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
45
- version: z.ZodString;
46
- package: z.ZodOptional<z.ZodString>;
47
- path: z.ZodOptional<z.ZodString>;
48
- }, z.core.$strip>]>>>;
49
- }, z.core.$strip>>>;
50
- }, z.core.$strip>;
51
- type CargoManifest = z.infer<typeof cargoManifestSchema>;
52
- //#endregion
53
- //#region src/plugins/cargo.d.ts
54
- declare const DEP_FIELDS: readonly ["dependencies", "dev-dependencies", "build-dependencies"];
55
- declare class CargoPackage extends WorkspacePackage {
56
- readonly path: string;
57
- readonly manifest: CargoManifest;
58
- private content;
59
- private readonly workspaceManifest?;
60
- readonly manager = "cargo";
61
- constructor(path: string, manifest: CargoManifest, content: string, workspaceManifest?: CargoManifest | undefined);
62
- get name(): string;
63
- get version(): string | undefined;
64
- setVersion(version: string): void;
65
- write(): Promise<void>;
66
- patch(path: string, value: unknown): void;
67
- get packageInfo(): {
68
- name: string;
69
- version?: string | undefined;
70
- publish?: boolean | undefined;
71
- };
72
- private get workspaceVersion();
73
- }
74
- interface DependentRef {
75
- dependent: CargoPackage;
76
- kind: (typeof DEP_FIELDS)[number];
77
- name: string;
78
- version: string;
79
- }
80
- interface CargoPluginOptions {
81
- /**
82
- * Update lock file after versioning.
83
- *
84
- * @default true
85
- */
86
- updateLockFile?: boolean;
87
- /**
88
- * Decide how to bump the dependents of a bumped package.
89
- */
90
- bumpDep?: (opts: DependentRef) => BumpType | false;
91
- }
92
- declare function cargo({
93
- updateLockFile,
94
- bumpDep: getBumpDepType
95
- }?: CargoPluginOptions): TegamiPlugin;
96
- //#endregion
97
- export { CargoPackage, CargoPluginOptions, cargo };
1
+ import { C as CargoPackage, S as CargoGraph, T as cargo, w as CargoPluginOptions } from "../types-BoQR7Hlg.js";
2
+ export { CargoGraph, CargoPackage, CargoPluginOptions, cargo };