tegami 0.0.0 → 0.1.0-beta.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.
@@ -0,0 +1,460 @@
1
+ import { TomlTable } from "smol-toml";
2
+ import z$1, { z } from "zod";
3
+
4
+ //#region src/utils/semver.d.ts
5
+ type BumpType = "major" | "minor" | "patch";
6
+ //#endregion
7
+ //#region src/graph.d.ts
8
+ /** Package discovered in the workspace. */
9
+ declare abstract class WorkspacePackage {
10
+ abstract readonly name: string;
11
+ abstract readonly path: string;
12
+ abstract readonly manager: string;
13
+ abstract readonly version: string;
14
+ get id(): string;
15
+ private opts;
16
+ /** note: this will only be available after package graph is resolved */
17
+ getPackageOptions(): PackageOptions;
18
+ setPackageOptions(options: PackageOptions): void;
19
+ /** create an empty draft plan. */
20
+ onPlan(_context: TegamiContext): PackagePlan;
21
+ }
22
+ interface PackageGroup {
23
+ name: string;
24
+ options: GroupOptions;
25
+ packages: WorkspacePackage[];
26
+ }
27
+ /** Dependency graph for discovered workspace packages. */
28
+ declare class PackageGraph {
29
+ private readonly packages;
30
+ private readonly groups;
31
+ constructor(packages?: WorkspacePackage[]);
32
+ getPackages(): WorkspacePackage[];
33
+ /** Get a package by exact id. */
34
+ get(id: string): WorkspacePackage | undefined;
35
+ /** Get packages by id, `group:name`, or every package matching a name. */
36
+ getByName(nameOrId: string): WorkspacePackage[];
37
+ /** scan package into graph, if the package id already exists, replace the existing one in graph */
38
+ add(pkg: WorkspacePackage): void;
39
+ delete(id: string): void;
40
+ getPackageGroup(pkgId: string): PackageGroup | undefined;
41
+ getGroups(): PackageGroup[];
42
+ getGroup(name: string): PackageGroup | undefined;
43
+ registerGroup(name: string, options: GroupOptions): PackageGroup;
44
+ addGroupMember(groupId: string, id: string): void;
45
+ removeGroupMember(group: string, id: string): void;
46
+ unregisterGroup(name: string): void;
47
+ }
48
+ //#endregion
49
+ //#region src/changelog/parse.d.ts
50
+ interface ChangelogEntry {
51
+ id: string;
52
+ /** file name like `my-change.md` */
53
+ filename: string;
54
+ subject?: string;
55
+ packages: Set<string>;
56
+ type: BumpType;
57
+ title: string;
58
+ content: string;
59
+ }
60
+ //#endregion
61
+ //#region src/plans/draft.d.ts
62
+ interface PackagePlan {
63
+ type?: BumpType;
64
+ bumpReasons?: Set<string>;
65
+ changelogs?: ChangelogEntry[];
66
+ prerelease?: string;
67
+ publish?: boolean;
68
+ npm?: {
69
+ /** npm dist-tag used when publishing. */distTag?: string;
70
+ };
71
+ /** get the bumped version of a package */
72
+ bumpVersion: (pkg: WorkspacePackage) => string;
73
+ }
74
+ declare class DraftPlan {
75
+ #private;
76
+ private readonly context;
77
+ private readonly packages;
78
+ private readonly changelogs;
79
+ private readonly policies;
80
+ constructor(context: TegamiContext);
81
+ getPackagePlans(): Map<string, PackagePlan>;
82
+ getPackagePlan(id: string): PackagePlan | undefined;
83
+ bumpPackage(pkg: WorkspacePackage, {
84
+ type,
85
+ reason
86
+ }: {
87
+ type: BumpType;
88
+ reason?: string;
89
+ }): PackagePlan;
90
+ hasPending(): boolean;
91
+ getChangelogs(): ChangelogEntry[];
92
+ getChangelog(id: string): ChangelogEntry | undefined;
93
+ addChangelog(entry: ChangelogEntry): void;
94
+ deleteChangelog(id: string): boolean;
95
+ private initPackagePlan;
96
+ /** Apply the publish plan: update package versions, write the plan file, and consume changelog files. */
97
+ applyPlan(): Promise<void>;
98
+ addPolicy(policy: PlanPolicy): void;
99
+ removePolicy(policy: PlanPolicy): void;
100
+ canApply(): boolean;
101
+ private appendChangelog;
102
+ /** {@link applyPlan} but for `await using` syntax */
103
+ [Symbol.asyncDispose](): Promise<void>;
104
+ }
105
+ interface PlanPolicy {
106
+ id: string;
107
+ onUpdate?: (this: DraftPlan, opts: {
108
+ plan: PackagePlan;
109
+ pkg: WorkspacePackage;
110
+ }) => void;
111
+ }
112
+ type CleanupResult = {
113
+ state: "removed";
114
+ } | {
115
+ state: "skipped";
116
+ reason: "missing" | "pending";
117
+ };
118
+ //#endregion
119
+ //#region src/plans/store.d.ts
120
+ declare const packagePlanStoreSchema: z$1.ZodObject<{
121
+ type: z$1.ZodOptional<z$1.ZodEnum<{
122
+ major: "major";
123
+ minor: "minor";
124
+ patch: "patch";
125
+ }>>;
126
+ changelogIds: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
127
+ bumpReasons: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
128
+ npm: z$1.ZodOptional<z$1.ZodObject<{
129
+ distTag: z$1.ZodOptional<z$1.ZodString>;
130
+ }, z$1.core.$strip>>;
131
+ publish: z$1.ZodBoolean;
132
+ }, z$1.core.$strip>;
133
+ /** the persisted plan data for actual publishing */
134
+ declare const planStoreSchema: z$1.ZodCodec<z$1.ZodString, z$1.ZodObject<{
135
+ id: z$1.ZodString;
136
+ createdAt: z$1.ZodISODateTime;
137
+ version: z$1.ZodDefault<z$1.ZodLiteral<"0.0.0">>;
138
+ changelogs: z$1.ZodRecord<z$1.ZodString, z$1.ZodObject<{
139
+ filename: z$1.ZodString;
140
+ subject: z$1.ZodOptional<z$1.ZodString>;
141
+ packages: z$1.ZodArray<z$1.ZodString>;
142
+ type: z$1.ZodEnum<{
143
+ major: "major";
144
+ minor: "minor";
145
+ patch: "patch";
146
+ }>;
147
+ title: z$1.ZodString;
148
+ content: z$1.ZodString;
149
+ }, z$1.core.$strip>>;
150
+ packages: z$1.ZodRecord<z$1.ZodString, z$1.ZodObject<{
151
+ type: z$1.ZodOptional<z$1.ZodEnum<{
152
+ major: "major";
153
+ minor: "minor";
154
+ patch: "patch";
155
+ }>>;
156
+ changelogIds: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
157
+ bumpReasons: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
158
+ npm: z$1.ZodOptional<z$1.ZodObject<{
159
+ distTag: z$1.ZodOptional<z$1.ZodString>;
160
+ }, z$1.core.$strip>>;
161
+ publish: z$1.ZodBoolean;
162
+ }, z$1.core.$strip>>;
163
+ }, z$1.core.$strip>>;
164
+ type PlanStore = z$1.output<typeof planStoreSchema>;
165
+ type PackagePlanStore = z$1.output<typeof packagePlanStoreSchema>;
166
+ //#endregion
167
+ //#region src/publish.d.ts
168
+ interface PublishOptions {
169
+ /** Validate the publish plan without publishing packages, creating tags, or running release plugins. */
170
+ dryRun?: boolean;
171
+ }
172
+ type PublishResult = {
173
+ state: "created";
174
+ packages: PackagePublishResult[]; /** the persisted plan object. This is not a public API, can be changed without notice */
175
+ _rawPlan: PlanStore;
176
+ } | {
177
+ state: "failed";
178
+ error?: string;
179
+ packages: PackagePublishResult[]; /** the persisted plan object. This is not a public API, can be changed without notice */
180
+ _rawPlan: PlanStore;
181
+ } | {
182
+ state: "skipped";
183
+ };
184
+ type PackagePublishResult = ({
185
+ state: "failed";
186
+ error?: string;
187
+ } | {
188
+ state: "success";
189
+ }) & {
190
+ id: string;
191
+ name: string;
192
+ version: string;
193
+ npm?: {
194
+ distTag?: string;
195
+ }; /** added by the `git` plugin */
196
+ gitTag?: string;
197
+ changelogs: ChangelogEntry[];
198
+ };
199
+ //#endregion
200
+ //#region src/schemas.d.ts
201
+ declare const packageManifestSchema: z.ZodObject<{
202
+ name: z.ZodString;
203
+ version: z.ZodOptional<z.ZodString>;
204
+ private: z.ZodOptional<z.ZodBoolean>;
205
+ publishConfig: z.ZodOptional<z.ZodObject<{
206
+ access: z.ZodOptional<z.ZodEnum<{
207
+ public: "public";
208
+ restricted: "restricted";
209
+ }>>;
210
+ registry: z.ZodOptional<z.ZodString>;
211
+ tag: z.ZodOptional<z.ZodString>;
212
+ }, z.core.$loose>>;
213
+ workspaces: z.ZodOptional<z.ZodArray<z.ZodString>>;
214
+ dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
215
+ devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
216
+ peerDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
217
+ optionalDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
218
+ }, z.core.$loose>;
219
+ type PackageManifest = z.infer<typeof packageManifestSchema>;
220
+ //#endregion
221
+ //#region src/providers/npm.d.ts
222
+ declare const DEP_FIELDS$1: readonly ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
223
+ declare class NpmPackage extends WorkspacePackage {
224
+ readonly path: string;
225
+ readonly manifest: PackageManifest;
226
+ readonly manager = "npm";
227
+ constructor(path: string, manifest: PackageManifest);
228
+ get name(): string;
229
+ get version(): string;
230
+ write(): Promise<void>;
231
+ onPlan(context: TegamiContext): PackagePlan;
232
+ }
233
+ type NpmClient = "npm" | "pnpm";
234
+ declare class NpmRegistryClient implements RegistryClient {
235
+ #private;
236
+ private readonly cwd;
237
+ private readonly client;
238
+ readonly id = "npm";
239
+ constructor(cwd: string, client: NpmClient, _graph: PackageGraph);
240
+ supports(pkg: WorkspacePackage): boolean;
241
+ isPackagePublished(pkg: NpmPackage): Promise<boolean>;
242
+ publish(pkg: NpmPackage, {
243
+ packageStore
244
+ }: {
245
+ store: PlanStore;
246
+ packageStore: PackagePlanStore;
247
+ }): Promise<void>;
248
+ }
249
+ type DependencySpec = {
250
+ protocol: "npm";
251
+ alias: string;
252
+ range: string;
253
+ linked?: WorkspacePackage;
254
+ } | {
255
+ protocol?: "workspace";
256
+ range: string;
257
+ linked?: WorkspacePackage;
258
+ };
259
+ interface NpmPluginOptions {
260
+ /** Package manager command used for npm registry operations. */
261
+ client?: NpmClient;
262
+ /**
263
+ * Decide how to bump the dependents of a bumped package.
264
+ */
265
+ bumpDep?: (opts: {
266
+ kind: (typeof DEP_FIELDS$1)[number];
267
+ name: string;
268
+ spec: DependencySpec;
269
+ }) => BumpType | false;
270
+ /**
271
+ * What to do when a workspace dependency's version has gone beyond peer dependency constraints:
272
+ *
273
+ * - `set` (default): set to the current version (won't preserve prefix).
274
+ * - `error`: throw error.
275
+ * - `ignore`: do nothing.
276
+ *
277
+ * Note: `workspace:` protocols are not included.
278
+ */
279
+ onBreakPeerDep?: "set" | "error" | "ignore";
280
+ }
281
+ declare function npm({
282
+ client: defaultClient,
283
+ onBreakPeerDep,
284
+ bumpDep: getBumpDepType
285
+ }?: NpmPluginOptions): TegamiPlugin;
286
+ //#endregion
287
+ //#region src/providers/cargo.d.ts
288
+ declare const DEP_FIELDS: readonly ["dependencies", "dev-dependencies", "build-dependencies"];
289
+ declare class CargoPackage extends WorkspacePackage {
290
+ readonly path: string;
291
+ readonly manifest: TomlTable;
292
+ private readonly workspaceManifest?;
293
+ readonly manager = "cargo";
294
+ constructor(path: string, manifest: TomlTable, workspaceManifest?: TomlTable | undefined);
295
+ get name(): string;
296
+ get version(): string;
297
+ onPlan(context: TegamiContext): PackagePlan;
298
+ write(): Promise<void>;
299
+ get packageInfo(): TomlTable;
300
+ private get workspaceVersion();
301
+ }
302
+ declare class CargoRegistryClient implements RegistryClient {
303
+ #private;
304
+ readonly id = "cargo";
305
+ constructor(_graph: PackageGraph);
306
+ supports(pkg: WorkspacePackage): boolean;
307
+ isPackagePublished(pkg: CargoPackage): Promise<boolean>;
308
+ publish(pkg: CargoPackage): Promise<void>;
309
+ }
310
+ interface CargoPluginOptions {
311
+ bumpDep?: (opts: {
312
+ kind: (typeof DEP_FIELDS)[number];
313
+ name: string;
314
+ version: string;
315
+ }) => BumpType | false;
316
+ }
317
+ declare function cargo({
318
+ bumpDep: getBumpDepType
319
+ }?: CargoPluginOptions): TegamiPlugin;
320
+ //#endregion
321
+ //#region src/types.d.ts
322
+ /** Generates changelog content for a package release. */
323
+ interface LogGenerator {
324
+ generate(this: TegamiContext, opts: {
325
+ packageId: string;
326
+ packageName: string;
327
+ version: string;
328
+ changelogs: ChangelogEntry[];
329
+ plan: PackagePlan;
330
+ _draft: DraftPlan;
331
+ }): string | Promise<string>;
332
+ }
333
+ interface TegamiOptions<Groups extends string = string> {
334
+ /** Workspace root. Defaults to the current working directory. */
335
+ cwd?: string;
336
+ /** Directory containing pending changelog markdown files. */
337
+ changelogDir?: string;
338
+ /** Path to the publish plan file. */
339
+ planPath?: string;
340
+ /** Changelog generator used when applying a publish plan. */
341
+ generator?: LogGenerator;
342
+ /** Per-package release and publish options keyed by package name. */
343
+ packages?: Record<string, PackageOptions<NoInfer<Groups>>>;
344
+ plugins?: TegamiPluginOption[];
345
+ groups?: Record<Groups, GroupOptions>;
346
+ /** Package names, ids, or regex patterns to exclude from the dependency graph. */
347
+ ignore?: (string | RegExp)[];
348
+ npm?: NpmPluginOptions;
349
+ cargo?: CargoPluginOptions;
350
+ }
351
+ interface GroupOptions {
352
+ /** Prerelease identifier appended to bumped versions (e.g. `alpha` → `1.1.0-alpha.0`). */
353
+ prerelease?: string;
354
+ /** all member packages will share the same type of version bump (e.g. when one package is bumped by a minor, other member packages will also be bumped by a minor) */
355
+ syncBump?: boolean;
356
+ /** when multiple packages in the group are published, only one git tag will be created (as well as GitHub release) */
357
+ syncGitTag?: boolean;
358
+ }
359
+ interface PackageOptions<Group extends string = string> {
360
+ /** Prerelease identifier appended to bumped versions (e.g. `alpha` → `1.1.0-alpha.0`). */
361
+ prerelease?: string;
362
+ /** Set to false to keep this package out of npm publishing. */
363
+ publish?: boolean;
364
+ /** the group of this package, ignored if the group doesn't exist */
365
+ group?: Group;
366
+ /** npm-specific options. */
367
+ npm?: {
368
+ /** npm dist-tag used when publishing. */distTag?: string;
369
+ };
370
+ }
371
+ type TegamiPluginOption = TegamiPlugin | TegamiPluginOption[];
372
+ interface TegamiPlugin {
373
+ name: string;
374
+ enforce?: "pre" | "default" | "post";
375
+ /** when Tegami initializes */
376
+ init?(this: TegamiContext): Awaitable<void>;
377
+ /** Resolve workspace packages and dependency metadata into the shared graph. */
378
+ resolve?(this: TegamiContext): Awaitable<void>;
379
+ /** Register registry clients used to handle packages for different package managers. */
380
+ createRegistryClient?(this: TegamiContext): Awaitable<RegistryClient | RegistryClient[] | void | undefined>;
381
+ /** Called when Tegami creates an empty draft plan. */
382
+ initPlan?(this: TegamiContext, plan: DraftPlan): Awaitable<DraftPlan | void | undefined>;
383
+ /** Called when Tegami applies the draft plan. */
384
+ applyPlan?(this: TegamiContext, draft: DraftPlan): Awaitable<void>;
385
+ /** resolve the plan status, crucial to check if the plan is finished successfully, or needs retries */
386
+ resolvePlanStatus?(this: TegamiContext, status: PublishPlanStatus, env: {
387
+ plan: PlanStore;
388
+ }): Awaitable<PublishPlanStatus>;
389
+ /** Called after publishing finishes. */
390
+ afterPublish?(this: TegamiContext & {
391
+ publishOptions: PublishOptions;
392
+ }, result: PublishResult): Awaitable<PublishResult | void | undefined>;
393
+ /** CLI lifecycle hooks. */
394
+ cli?: {
395
+ /** Called once before a CLI command runs. */init?(this: TegamiContext): Awaitable<void>; /** Called after `tegami version` returns a draft plan. */
396
+ publishPlanCreated?(this: TegamiContext, draft: DraftPlan): Awaitable<void>; /** Called after `tegami version` applies a publish plan. */
397
+ publishPlanApplied?(this: TegamiContext, draft: DraftPlan): Awaitable<void>;
398
+ };
399
+ }
400
+ type Awaitable<T> = T | Promise<T>;
401
+ interface PublishPlanStatus {
402
+ state: "pending" | "success" | "missing";
403
+ }
404
+ interface RegistryClient {
405
+ id: string;
406
+ supports(pkg: WorkspacePackage): boolean;
407
+ isPackagePublished(pkg: WorkspacePackage): Promise<boolean>;
408
+ publish(pkg: WorkspacePackage, env: {
409
+ store: PlanStore;
410
+ packageStore: PackagePlanStore;
411
+ }): Promise<void>;
412
+ }
413
+ //#endregion
414
+ //#region src/context.d.ts
415
+ interface TegamiContext {
416
+ cwd: string;
417
+ changelogDir: string;
418
+ planPath: string;
419
+ options: TegamiOptions;
420
+ plugins: TegamiPlugin[];
421
+ graph: PackageGraph;
422
+ /** error if doesn't exist */
423
+ getRegistryClient(pkgOrId: WorkspacePackage | string): RegistryClient;
424
+ }
425
+ //#endregion
426
+ //#region src/changelog/create.d.ts
427
+ interface CreateChangelogOptions {
428
+ /** Start revision. Defaults to the latest reachable git tag, or all history if none exists. */
429
+ from?: string;
430
+ /** End revision. Defaults to HEAD. */
431
+ to?: string;
432
+ }
433
+ interface CreatedChangelog {
434
+ filename: string;
435
+ path: string;
436
+ packages: string[];
437
+ changes: number;
438
+ }
439
+ //#endregion
440
+ //#region src/index.d.ts
441
+ interface Tegami {
442
+ /** Create pending changelog files from git commit history. */
443
+ generateChangelog(options?: CreateChangelogOptions): Promise<CreatedChangelog[]>;
444
+ /** Build a draft from pending changelog files. */
445
+ draft(): Promise<DraftPlan>;
446
+ /** Publish the current publish plan. */
447
+ publish(options?: PublishOptions): Promise<PublishResult>;
448
+ /** Remove the publish plan file after it has finished successfully. */
449
+ cleanup(): Promise<CleanupResult>;
450
+ /** Internal APIs, do not use it unless you know what you are doing */
451
+ _internal: {
452
+ context(): Promise<TegamiContext>;
453
+ graph(): Promise<PackageGraph>;
454
+ options: TegamiOptions;
455
+ };
456
+ }
457
+ /** Create a Tegami project handle. */
458
+ declare function tegami<const Groups extends string = string>(options?: TegamiOptions<Groups>): Tegami;
459
+ //#endregion
460
+ export { PublishResult as C, PackageGroup as D, PackageGraph as E, WorkspacePackage as O, PublishOptions as S, PackagePlan as T, NpmPackage as _, Awaitable as a, npm as b, PackageOptions as c, TegamiPlugin as d, TegamiPluginOption as f, cargo as g, CargoRegistryClient as h, CreatedChangelog as i, RegistryClient as l, CargoPluginOptions as m, tegami as n, GroupOptions as o, CargoPackage as p, CreateChangelogOptions as r, LogGenerator as s, Tegami as t, TegamiOptions as u, NpmPluginOptions as v, DraftPlan as w, PackagePublishResult as x, NpmRegistryClient as y };
@@ -0,0 +1,2 @@
1
+ import { C as PublishResult, D as PackageGroup, E as PackageGraph, O as WorkspacePackage, S as PublishOptions, T as PackagePlan, c as PackageOptions, d as TegamiPlugin, f as TegamiPluginOption, i as CreatedChangelog, l as RegistryClient, n as tegami, o as GroupOptions, r as CreateChangelogOptions, s as LogGenerator, t as Tegami, u as TegamiOptions, w as DraftPlan, x as PackagePublishResult } from "./index-Bhh2dJZp.js";
2
+ export { type CreateChangelogOptions, type CreatedChangelog, type DraftPlan, type GroupOptions, type LogGenerator, type PackageGraph, type PackageGroup, type PackageOptions, type PackagePlan, type PackagePublishResult, type PublishOptions, type PublishResult, type RegistryClient, Tegami, type TegamiOptions, type TegamiPlugin, type TegamiPluginOption, type WorkspacePackage, tegami };