tegami 0.0.1 → 0.1.0-beta.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/dist/checks-CKBRRjgQ.js +100 -0
- package/dist/cli/{index.d.mts → index.d.ts} +2 -2
- package/dist/cli/{index.mjs → index.js} +78 -55
- package/dist/error-DBK-9uBa.js +23 -0
- package/dist/generators/{simple.d.mts → simple.d.ts} +1 -1
- package/dist/generators/{simple.mjs → simple.js} +3 -3
- package/dist/graph-CUgwuRW5.js +107 -0
- package/dist/index-Da6P6gSc.d.ts +467 -0
- package/dist/index.d.ts +2 -0
- package/dist/{index.mjs → index.js} +182 -194
- package/dist/plugins/{git.d.mts → git.d.ts} +1 -1
- package/dist/plugins/git.js +84 -0
- package/dist/plugins/{github.d.mts → github.d.ts} +23 -9
- package/dist/plugins/github.js +187 -0
- package/dist/providers/cargo.d.ts +2 -0
- package/dist/providers/{cargo.mjs → cargo.js} +110 -52
- package/dist/providers/npm.d.ts +2 -0
- package/dist/providers/npm.js +288 -0
- package/dist/schemas-Cc4h6bq5.js +41 -0
- package/dist/semver-mWK2Khi2.js +33 -0
- package/package.json +22 -22
- package/dist/context-CC36jtz1.d.mts +0 -297
- package/dist/exec-hOS852t5.mjs +0 -12
- package/dist/index-DJ7YxxdM.d.mts +0 -35
- package/dist/index.d.mts +0 -3
- package/dist/npm-BpFlXy8I.mjs +0 -281
- package/dist/plugins/git.mjs +0 -99
- package/dist/plugins/github.mjs +0 -146
- package/dist/providers/cargo.d.mts +0 -32
- package/dist/providers/npm.d.mts +0 -2
- package/dist/providers/npm.mjs +0 -2
- package/dist/semver-FSWx3_34.mjs +0 -35
- package/dist/workspace-B5_i21S0.mjs +0 -63
- /package/dist/{constants-B9qjNfvr.mjs → constants-B9qjNfvr.js} +0 -0
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import * as semver from "semver";
|
|
2
|
-
import { SemVer } from "semver";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/semver.d.ts
|
|
6
|
-
type BumpType = "major" | "minor" | "patch";
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/changelog/parse.d.ts
|
|
9
|
-
interface ChangelogEntry {
|
|
10
|
-
id: string;
|
|
11
|
-
/** file name like `my-change.md` */
|
|
12
|
-
filename: string;
|
|
13
|
-
subject?: string;
|
|
14
|
-
packages: Set<string>;
|
|
15
|
-
type: BumpType;
|
|
16
|
-
title: string;
|
|
17
|
-
content: string;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/draft.d.ts
|
|
21
|
-
/** Per-package options applied when creating publish plans. */
|
|
22
|
-
interface PackageOptions {
|
|
23
|
-
/** npm dist-tag used when publishing. */
|
|
24
|
-
distTag?: string;
|
|
25
|
-
/** Set to false to keep this package out of npm publishing. */
|
|
26
|
-
publish?: boolean;
|
|
27
|
-
}
|
|
28
|
-
interface PackagePlan {
|
|
29
|
-
type: BumpType;
|
|
30
|
-
changelogIds: Set<string>;
|
|
31
|
-
distTag?: string;
|
|
32
|
-
publish: boolean;
|
|
33
|
-
}
|
|
34
|
-
declare class DraftPlan {
|
|
35
|
-
#private;
|
|
36
|
-
private readonly changelogs;
|
|
37
|
-
private readonly packages;
|
|
38
|
-
private readonly context;
|
|
39
|
-
constructor(changelogs: Map<string, ChangelogEntry>, packages: Map<string, PackagePlan>, context: TegamiContext);
|
|
40
|
-
getPackageIds(): string[];
|
|
41
|
-
getPackage(id: string): PackagePlan | undefined;
|
|
42
|
-
setPackage(id: string, plan?: Partial<PackagePlan>): void;
|
|
43
|
-
deletePackage(id: string): boolean;
|
|
44
|
-
getChangelogIds(): string[];
|
|
45
|
-
getChangelog(id: string): ChangelogEntry | undefined;
|
|
46
|
-
setChangelog(id: string, entry: ChangelogEntry): void;
|
|
47
|
-
deleteChangelog(id: string): boolean;
|
|
48
|
-
/** Write the publish plan, update package versions, and consume changelog files. */
|
|
49
|
-
createPublishPlan(): Promise<void>;
|
|
50
|
-
editable(): boolean;
|
|
51
|
-
private assertPublishPlanFinished;
|
|
52
|
-
private applyVersionChanges;
|
|
53
|
-
private removeConsumedChangelogs;
|
|
54
|
-
private assertEditable;
|
|
55
|
-
private appendChangelog;
|
|
56
|
-
/** {@link createPublishPlan} but for `await using` syntax */
|
|
57
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/schemas.d.ts
|
|
61
|
-
declare const packageManifestSchema: z.ZodObject<{
|
|
62
|
-
name: z.ZodOptional<z.ZodString>;
|
|
63
|
-
version: z.ZodOptional<z.ZodString>;
|
|
64
|
-
private: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
-
publishConfig: z.ZodOptional<z.ZodObject<{
|
|
66
|
-
access: z.ZodOptional<z.ZodEnum<{
|
|
67
|
-
public: "public";
|
|
68
|
-
restricted: "restricted";
|
|
69
|
-
}>>;
|
|
70
|
-
registry: z.ZodOptional<z.ZodString>;
|
|
71
|
-
tag: z.ZodOptional<z.ZodString>;
|
|
72
|
-
}, z.core.$loose>>;
|
|
73
|
-
workspaces: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodPipe<z.ZodObject<{
|
|
74
|
-
packages: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
75
|
-
}, z.core.$loose>, z.ZodTransform<string[], {
|
|
76
|
-
[x: string]: unknown;
|
|
77
|
-
packages?: string[] | undefined;
|
|
78
|
-
}>>]>, z.ZodArray<z.ZodString>>>;
|
|
79
|
-
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
80
|
-
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
81
|
-
peerDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
82
|
-
optionalDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
83
|
-
}, z.core.$loose>;
|
|
84
|
-
type PackageManifest = z.infer<typeof packageManifestSchema>;
|
|
85
|
-
/** the persisted plan data for actual publishing */
|
|
86
|
-
declare const planStoreSchema: z.ZodCodec<z.ZodString, z.ZodObject<{
|
|
87
|
-
id: z.ZodString;
|
|
88
|
-
createdAt: z.ZodISODateTime;
|
|
89
|
-
changelogs: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
90
|
-
filename: z.ZodString;
|
|
91
|
-
subject: z.ZodOptional<z.ZodString>;
|
|
92
|
-
packages: z.ZodArray<z.ZodString>;
|
|
93
|
-
type: z.ZodEnum<{
|
|
94
|
-
major: "major";
|
|
95
|
-
minor: "minor";
|
|
96
|
-
patch: "patch";
|
|
97
|
-
}>;
|
|
98
|
-
title: z.ZodString;
|
|
99
|
-
content: z.ZodString;
|
|
100
|
-
}, z.core.$strip>>;
|
|
101
|
-
packages: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
102
|
-
type: z.ZodEnum<{
|
|
103
|
-
major: "major";
|
|
104
|
-
minor: "minor";
|
|
105
|
-
patch: "patch";
|
|
106
|
-
}>;
|
|
107
|
-
changelogIds: z.ZodCodec<z.ZodArray<z.ZodString>, z.ZodSet<z.ZodString>>;
|
|
108
|
-
distTag: z.ZodOptional<z.ZodString>;
|
|
109
|
-
publish: z.ZodBoolean;
|
|
110
|
-
}, z.core.$strip>>;
|
|
111
|
-
}, z.core.$strip>>;
|
|
112
|
-
type PlanStore = z.output<typeof planStoreSchema>;
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/publish.d.ts
|
|
115
|
-
interface PublishOptions {
|
|
116
|
-
/** Validate the publish plan without publishing packages, creating tags, or running release plugins. */
|
|
117
|
-
dryRun?: boolean;
|
|
118
|
-
}
|
|
119
|
-
type PublishResult = {
|
|
120
|
-
state: "created";
|
|
121
|
-
packages: PackagePublishResult[]; /** Path to the publish plan that was executed. */
|
|
122
|
-
planPath: string; /** the persisted plan object. This is not a public API, can be changed without notice */
|
|
123
|
-
_rawPlan: PlanStore;
|
|
124
|
-
} | {
|
|
125
|
-
state: "failed";
|
|
126
|
-
error?: string;
|
|
127
|
-
packages: PackagePublishResult[]; /** Path to the publish plan that was executed. */
|
|
128
|
-
planPath: string; /** the persisted plan object. This is not a public API, can be changed without notice */
|
|
129
|
-
_rawPlan: PlanStore;
|
|
130
|
-
} | {
|
|
131
|
-
state: "skipped"; /** Path to the publish plan that was executed or missing. */
|
|
132
|
-
planPath: string;
|
|
133
|
-
};
|
|
134
|
-
type PackagePublishResult = ({
|
|
135
|
-
state: "failed";
|
|
136
|
-
error?: string;
|
|
137
|
-
} | {
|
|
138
|
-
state: "success";
|
|
139
|
-
}) & {
|
|
140
|
-
id: string;
|
|
141
|
-
name: string;
|
|
142
|
-
version: string;
|
|
143
|
-
distTag: string | undefined; /** added by the `git` plugin */
|
|
144
|
-
gitTag?: string;
|
|
145
|
-
changelogs: ChangelogEntry[];
|
|
146
|
-
};
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/workspace.d.ts
|
|
149
|
-
/** Package discovered in the workspace. */
|
|
150
|
-
declare abstract class WorkspacePackage {
|
|
151
|
-
abstract readonly name: string;
|
|
152
|
-
abstract readonly path: string;
|
|
153
|
-
abstract readonly manager: string;
|
|
154
|
-
abstract readonly version: string;
|
|
155
|
-
abstract readonly publish: boolean;
|
|
156
|
-
get distTag(): string | undefined;
|
|
157
|
-
get id(): string;
|
|
158
|
-
setVersion?(version: string): void;
|
|
159
|
-
updateDependency?(target: WorkspacePackage, version: string, context: TegamiContext): Awaitable<void>;
|
|
160
|
-
write?(): Awaitable<void>;
|
|
161
|
-
protected updateRange(context: TegamiContext, spec: DependencySpec, next: semver.SemVer): Promise<DependencySpec>;
|
|
162
|
-
}
|
|
163
|
-
/** Dependency graph for discovered workspace packages. */
|
|
164
|
-
declare class PackageGraph {
|
|
165
|
-
private readonly byId;
|
|
166
|
-
private readonly byName;
|
|
167
|
-
constructor(packages?: WorkspacePackage[]);
|
|
168
|
-
getPackages(): WorkspacePackage[];
|
|
169
|
-
/** Get a package by exact id. */
|
|
170
|
-
get(id: string): WorkspacePackage | undefined;
|
|
171
|
-
/** Get packages by id, or every package matching a name. */
|
|
172
|
-
getByName(nameOrId: string): WorkspacePackage[];
|
|
173
|
-
/** scan package into graph, if the package id already exists, replace the existing one in graph */
|
|
174
|
-
add(pkg: WorkspacePackage): void;
|
|
175
|
-
delete(pkg: WorkspacePackage): void;
|
|
176
|
-
}
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/providers/npm.d.ts
|
|
179
|
-
declare class NpmPackage extends WorkspacePackage {
|
|
180
|
-
readonly path: string;
|
|
181
|
-
readonly manifest: PackageManifest;
|
|
182
|
-
readonly manager = "npm";
|
|
183
|
-
constructor(path: string, manifest: PackageManifest);
|
|
184
|
-
get name(): string;
|
|
185
|
-
get version(): string;
|
|
186
|
-
get publish(): boolean;
|
|
187
|
-
get distTag(): string | undefined;
|
|
188
|
-
setVersion(version: string): void;
|
|
189
|
-
updateDependency(target: WorkspacePackage, version: string, context: TegamiContext): Promise<void>;
|
|
190
|
-
write(): Promise<void>;
|
|
191
|
-
}
|
|
192
|
-
type NpmClient = "npm" | "pnpm";
|
|
193
|
-
declare class NpmRegistryClient implements RegistryClient {
|
|
194
|
-
#private;
|
|
195
|
-
private readonly cwd;
|
|
196
|
-
private readonly npmClient;
|
|
197
|
-
private readonly graph;
|
|
198
|
-
readonly id = "npm";
|
|
199
|
-
constructor(cwd: string, npmClient: NpmClient | undefined, graph: {
|
|
200
|
-
get(id: string): WorkspacePackage | undefined;
|
|
201
|
-
});
|
|
202
|
-
supports(pkg: WorkspacePackage): boolean;
|
|
203
|
-
packageVersionExists(pkg: WorkspacePackage, version: string): Promise<boolean>;
|
|
204
|
-
publish(pkg: WorkspacePackage, options?: {
|
|
205
|
-
distTag?: string;
|
|
206
|
-
}): Promise<void>;
|
|
207
|
-
publishPlanStatus(plan: PlanStore): Promise<PublishPlanStatus>;
|
|
208
|
-
private resolveClient;
|
|
209
|
-
}
|
|
210
|
-
declare function npm(client?: NpmClient): TegamiPlugin;
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region src/types.d.ts
|
|
213
|
-
/** Generates changelog content for a package release. */
|
|
214
|
-
interface LogGenerator {
|
|
215
|
-
generate(this: TegamiContext, opts: {
|
|
216
|
-
packageName: string;
|
|
217
|
-
version: string;
|
|
218
|
-
distTag?: string;
|
|
219
|
-
changelogs: ChangelogEntry[];
|
|
220
|
-
}): string | Promise<string>;
|
|
221
|
-
}
|
|
222
|
-
interface TegamiOptions {
|
|
223
|
-
/** Workspace root. Defaults to the current working directory. */
|
|
224
|
-
cwd?: string;
|
|
225
|
-
/** Directory containing pending changelog markdown files. */
|
|
226
|
-
changelogDir?: string;
|
|
227
|
-
/** Path to the publish plan file. */
|
|
228
|
-
planPath?: string;
|
|
229
|
-
/** Changelog generator used when creating a publish plan. */
|
|
230
|
-
generator?: LogGenerator;
|
|
231
|
-
/** Per-package release and publish options keyed by package name. */
|
|
232
|
-
packages?: Record<string, PackageOptions>;
|
|
233
|
-
plugins?: TegamiPluginOption[];
|
|
234
|
-
/** Package manager command used for npm registry operations. */
|
|
235
|
-
npmClient?: NpmClient;
|
|
236
|
-
}
|
|
237
|
-
type TegamiPluginOption = TegamiPlugin | TegamiPluginOption[];
|
|
238
|
-
interface TegamiPlugin {
|
|
239
|
-
name: string;
|
|
240
|
-
enforce?: "pre" | "default" | "post";
|
|
241
|
-
/** when Tegami initializes */
|
|
242
|
-
init?(this: TegamiContext): Awaitable<void>;
|
|
243
|
-
/** Resolve workspace packages and dependency metadata into the shared graph. */
|
|
244
|
-
resolve?(this: TegamiContext): Awaitable<void>;
|
|
245
|
-
/** Register registry clients used to handle packages for different package managers. */
|
|
246
|
-
createRegistryClient?(this: TegamiContext): Awaitable<RegistryClient | RegistryClient[] | void | undefined>;
|
|
247
|
-
/** Called after Tegami builds the initial draft plan and before it is returned. */
|
|
248
|
-
initPlan?(this: TegamiContext, plan: DraftPlan): Awaitable<DraftPlan | void | undefined>;
|
|
249
|
-
/** Called after publishing finishes. */
|
|
250
|
-
afterPublish?(this: TegamiContext & {
|
|
251
|
-
publishOptions: PublishOptions;
|
|
252
|
-
}, result: PublishResult): Awaitable<PublishResult | void | undefined>;
|
|
253
|
-
/** CLI lifecycle hooks. */
|
|
254
|
-
cli?: {
|
|
255
|
-
/** Called once before a CLI command runs. */init?(this: TegamiContext): Awaitable<void>; /** Called after `tegami version` creates a publish plan. */
|
|
256
|
-
afterVersion?(this: TegamiContext, draft: DraftPlan): Awaitable<void>;
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* @param pkg - the package that referenced the dependency
|
|
260
|
-
* @param spec - the referenced dependency & its range
|
|
261
|
-
* @param target - the target version to update to
|
|
262
|
-
* @returns fallback to the default behaviour if `undefined`, otherwise replace with updated spec (can reuse the same instance, as long as a value is returned).
|
|
263
|
-
*/
|
|
264
|
-
onUpdateRange?(this: TegamiContext, pkg: WorkspacePackage, spec: DependencySpec, target: SemVer): Awaitable<DependencySpec | void | undefined>;
|
|
265
|
-
}
|
|
266
|
-
type Awaitable<T> = T | Promise<T>;
|
|
267
|
-
interface PublishPlanStatus {
|
|
268
|
-
state: "pending" | "success";
|
|
269
|
-
error?: string;
|
|
270
|
-
}
|
|
271
|
-
interface RegistryClient {
|
|
272
|
-
id: string;
|
|
273
|
-
supports?(pkg: WorkspacePackage): boolean;
|
|
274
|
-
packageVersionExists(pkg: WorkspacePackage, version: string): Promise<boolean>;
|
|
275
|
-
publish(pkg: WorkspacePackage, options?: {
|
|
276
|
-
distTag?: string;
|
|
277
|
-
}): Promise<void>;
|
|
278
|
-
publishPlanStatus(plan: PlanStore): Promise<PublishPlanStatus>;
|
|
279
|
-
}
|
|
280
|
-
interface DependencySpec {
|
|
281
|
-
name: string;
|
|
282
|
-
range: string;
|
|
283
|
-
}
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/context.d.ts
|
|
286
|
-
interface TegamiContext {
|
|
287
|
-
cwd: string;
|
|
288
|
-
changelogDir: string;
|
|
289
|
-
planPath: string;
|
|
290
|
-
options: TegamiOptions;
|
|
291
|
-
plugins: TegamiPlugin[];
|
|
292
|
-
graph: PackageGraph;
|
|
293
|
-
/** error if doesn't exist */
|
|
294
|
-
getRegistryClient(pkgOrId: WorkspacePackage | string): RegistryClient;
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
|
-
export { PublishResult as _, RegistryClient as a, PackageOptions as b, TegamiPluginOption as c, NpmRegistryClient as d, npm as f, PublishOptions as g, PackagePublishResult as h, PublishPlanStatus as i, NpmClient as l, WorkspacePackage as m, Awaitable as n, TegamiOptions as o, PackageGraph as p, LogGenerator as r, TegamiPlugin as s, TegamiContext as t, NpmPackage as u, PlanStore as v, PackagePlan as x, DraftPlan as y };
|
package/dist/exec-hOS852t5.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/utils/exec.ts
|
|
2
|
-
function commandOutput(result) {
|
|
3
|
-
return [result.stdout, result.stderr].filter(Boolean).join("\n").trim();
|
|
4
|
-
}
|
|
5
|
-
function execFailure(context, result) {
|
|
6
|
-
const lines = [context, `(exit ${result.exitCode})`];
|
|
7
|
-
const output = commandOutput(result);
|
|
8
|
-
if (output) lines.push(output);
|
|
9
|
-
return lines.join("\n");
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { execFailure as t };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { _ as PublishResult, g as PublishOptions, o as TegamiOptions, p as PackageGraph, t as TegamiContext, y as DraftPlan } from "./context-CC36jtz1.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/changelog/create.d.ts
|
|
4
|
-
interface CreateChangelogOptions {
|
|
5
|
-
/** Start revision. Defaults to the latest reachable git tag, or all history if none exists. */
|
|
6
|
-
from?: string;
|
|
7
|
-
/** End revision. Defaults to HEAD. */
|
|
8
|
-
to?: string;
|
|
9
|
-
}
|
|
10
|
-
interface CreatedChangelog {
|
|
11
|
-
filename: string;
|
|
12
|
-
path: string;
|
|
13
|
-
packages: string[];
|
|
14
|
-
changes: number;
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/index.d.ts
|
|
18
|
-
interface Tegami {
|
|
19
|
-
/** Create pending changelog files from git commit history. */
|
|
20
|
-
generateChangelog(options?: CreateChangelogOptions): Promise<CreatedChangelog[]>;
|
|
21
|
-
/** Build an editable draft from pending changelog files. */
|
|
22
|
-
draft(): Promise<DraftPlan>;
|
|
23
|
-
/** Publish the current publish plan. */
|
|
24
|
-
publish(options?: PublishOptions): Promise<PublishResult>;
|
|
25
|
-
/** Internal APIs, do not use it unless you know what you are doing */
|
|
26
|
-
_internal: {
|
|
27
|
-
context(): Promise<TegamiContext>;
|
|
28
|
-
graph(): Promise<PackageGraph>;
|
|
29
|
-
options: TegamiOptions;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/** Create a Tegami project handle. */
|
|
33
|
-
declare function tegami(options?: TegamiOptions): Tegami;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { CreatedChangelog as i, tegami as n, CreateChangelogOptions as r, Tegami as t };
|
package/dist/index.d.mts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { _ as PublishResult, a as RegistryClient, b as PackageOptions, c as TegamiPluginOption, g as PublishOptions, h as PackagePublishResult, m as WorkspacePackage, o as TegamiOptions, p as PackageGraph, r as LogGenerator, s as TegamiPlugin, x as PackagePlan, y as DraftPlan } from "./context-CC36jtz1.mjs";
|
|
2
|
-
import { i as CreatedChangelog, n as tegami, r as CreateChangelogOptions, t as Tegami } from "./index-DJ7YxxdM.mjs";
|
|
3
|
-
export { type CreateChangelogOptions, type CreatedChangelog, type DraftPlan, type LogGenerator, type PackageGraph, type PackageOptions, type PackagePlan, type PackagePublishResult, type PublishOptions, type PublishResult, type RegistryClient, Tegami, type TegamiOptions, type TegamiPlugin, type TegamiPluginOption, type WorkspacePackage, tegami };
|
package/dist/npm-BpFlXy8I.mjs
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { n as WorkspacePackage, r as isNodeError } from "./workspace-B5_i21S0.mjs";
|
|
2
|
-
import { t as execFailure } from "./exec-hOS852t5.mjs";
|
|
3
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join, normalize } from "node:path";
|
|
5
|
-
import { x } from "tinyexec";
|
|
6
|
-
import * as semver from "semver";
|
|
7
|
-
import { glob } from "tinyglobby";
|
|
8
|
-
import { load } from "js-yaml";
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import { detect } from "package-manager-detector";
|
|
11
|
-
//#region src/schemas.ts
|
|
12
|
-
const changelogFrontmatterSchema = z.object({
|
|
13
|
-
subject: z.string().optional(),
|
|
14
|
-
packages: z.array(z.string()).default([])
|
|
15
|
-
});
|
|
16
|
-
const stringRecordSchema = z.record(z.string(), z.string());
|
|
17
|
-
const jsonCodec = (schema) => z.codec(z.string(), schema, {
|
|
18
|
-
decode: (jsonString, ctx) => {
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(jsonString);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
ctx.issues.push({
|
|
23
|
-
code: "invalid_format",
|
|
24
|
-
format: "json",
|
|
25
|
-
input: jsonString,
|
|
26
|
-
message: err.message
|
|
27
|
-
});
|
|
28
|
-
return z.NEVER;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
encode: (value) => JSON.stringify(value)
|
|
32
|
-
});
|
|
33
|
-
const workspacePatternsSchema = z.union([z.array(z.string()), z.looseObject({ packages: z.array(z.string()).optional() }).transform((workspaces) => workspaces.packages ?? ["."])]).pipe(z.array(z.string()));
|
|
34
|
-
const packageManifestSchema = z.looseObject({
|
|
35
|
-
name: z.string().optional(),
|
|
36
|
-
version: z.string().optional(),
|
|
37
|
-
private: z.boolean().optional(),
|
|
38
|
-
publishConfig: z.looseObject({
|
|
39
|
-
access: z.enum(["public", "restricted"]).optional(),
|
|
40
|
-
registry: z.string().optional(),
|
|
41
|
-
tag: z.string().optional()
|
|
42
|
-
}).optional(),
|
|
43
|
-
workspaces: workspacePatternsSchema.optional(),
|
|
44
|
-
dependencies: stringRecordSchema.optional(),
|
|
45
|
-
devDependencies: stringRecordSchema.optional(),
|
|
46
|
-
peerDependencies: stringRecordSchema.optional(),
|
|
47
|
-
optionalDependencies: stringRecordSchema.optional()
|
|
48
|
-
});
|
|
49
|
-
/** the persisted plan data for actual publishing */
|
|
50
|
-
const planStoreSchema = jsonCodec(z.object({
|
|
51
|
-
id: z.string(),
|
|
52
|
-
createdAt: z.iso.datetime(),
|
|
53
|
-
/** release note entries */
|
|
54
|
-
changelogs: z.record(z.string(), z.object({
|
|
55
|
-
filename: z.string(),
|
|
56
|
-
subject: z.string().optional(),
|
|
57
|
-
packages: z.array(z.string()),
|
|
58
|
-
type: z.enum([
|
|
59
|
-
"major",
|
|
60
|
-
"minor",
|
|
61
|
-
"patch"
|
|
62
|
-
]),
|
|
63
|
-
title: z.string(),
|
|
64
|
-
content: z.string()
|
|
65
|
-
})),
|
|
66
|
-
/** package id -> package info */
|
|
67
|
-
packages: z.record(z.string(), z.object({
|
|
68
|
-
type: z.enum([
|
|
69
|
-
"major",
|
|
70
|
-
"minor",
|
|
71
|
-
"patch"
|
|
72
|
-
]),
|
|
73
|
-
changelogIds: z.codec(z.array(z.string()), z.set(z.string()), {
|
|
74
|
-
encode: (v) => Array.from(v),
|
|
75
|
-
decode: (v) => new Set(v)
|
|
76
|
-
}),
|
|
77
|
-
distTag: z.string().optional(),
|
|
78
|
-
publish: z.boolean()
|
|
79
|
-
}))
|
|
80
|
-
}));
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/providers/npm.ts
|
|
83
|
-
const DEP_FIELDS = [
|
|
84
|
-
"dependencies",
|
|
85
|
-
"devDependencies",
|
|
86
|
-
"peerDependencies",
|
|
87
|
-
"optionalDependencies"
|
|
88
|
-
];
|
|
89
|
-
var NpmPackage = class NpmPackage extends WorkspacePackage {
|
|
90
|
-
path;
|
|
91
|
-
manifest;
|
|
92
|
-
manager = "npm";
|
|
93
|
-
constructor(path, manifest) {
|
|
94
|
-
super();
|
|
95
|
-
this.path = path;
|
|
96
|
-
this.manifest = manifest;
|
|
97
|
-
}
|
|
98
|
-
get name() {
|
|
99
|
-
return this.manifest.name;
|
|
100
|
-
}
|
|
101
|
-
get version() {
|
|
102
|
-
return this.manifest.version ?? "0.0.0";
|
|
103
|
-
}
|
|
104
|
-
get publish() {
|
|
105
|
-
return this.manifest.private !== true;
|
|
106
|
-
}
|
|
107
|
-
get distTag() {
|
|
108
|
-
return this.manifest.publishConfig?.tag;
|
|
109
|
-
}
|
|
110
|
-
setVersion(version) {
|
|
111
|
-
this.manifest.version = version;
|
|
112
|
-
}
|
|
113
|
-
async updateDependency(target, version, context) {
|
|
114
|
-
if (!(target instanceof NpmPackage)) return;
|
|
115
|
-
const next = semver.parse(version);
|
|
116
|
-
if (!next) return;
|
|
117
|
-
for (const field of DEP_FIELDS) {
|
|
118
|
-
const dependencies = this.manifest[field];
|
|
119
|
-
if (!dependencies) continue;
|
|
120
|
-
for (const [rawName, rawRange] of Object.entries(dependencies)) {
|
|
121
|
-
const spec = parseNpmDependency(rawName, rawRange);
|
|
122
|
-
if (!spec || spec.name !== target.name) continue;
|
|
123
|
-
dependencies[rawName] = formatNpmDependency(await this.updateRange(context, spec, next));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async write() {
|
|
128
|
-
await writeFile(join(this.path, "package.json"), `${JSON.stringify(this.manifest, null, 2)}\n`);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
var NpmRegistryClient = class {
|
|
132
|
-
cwd;
|
|
133
|
-
npmClient;
|
|
134
|
-
graph;
|
|
135
|
-
id = "npm";
|
|
136
|
-
#versionMap = /* @__PURE__ */ new Map();
|
|
137
|
-
#resolvedClient;
|
|
138
|
-
constructor(cwd, npmClient = void 0, graph) {
|
|
139
|
-
this.cwd = cwd;
|
|
140
|
-
this.npmClient = npmClient;
|
|
141
|
-
this.graph = graph;
|
|
142
|
-
}
|
|
143
|
-
supports(pkg) {
|
|
144
|
-
return pkg instanceof NpmPackage;
|
|
145
|
-
}
|
|
146
|
-
async packageVersionExists(pkg, version) {
|
|
147
|
-
const cacheKey = `${pkg.id}@${version}`;
|
|
148
|
-
let info = this.#versionMap.get(cacheKey);
|
|
149
|
-
if (!info) {
|
|
150
|
-
const run = async () => {
|
|
151
|
-
if (!(pkg instanceof NpmPackage)) return false;
|
|
152
|
-
const registry = pkg.manifest.publishConfig?.registry;
|
|
153
|
-
const args = [
|
|
154
|
-
"view",
|
|
155
|
-
`${pkg.name}@${version}`,
|
|
156
|
-
"version",
|
|
157
|
-
"--json"
|
|
158
|
-
];
|
|
159
|
-
if (registry) args.push("--registry", registry);
|
|
160
|
-
const result = await x(await this.resolveClient(), args, { nodeOptions: { cwd: this.cwd } });
|
|
161
|
-
if (result.exitCode === 0) return true;
|
|
162
|
-
const output = commandOutput(result);
|
|
163
|
-
if (isMissingRegistryEntry(output)) return false;
|
|
164
|
-
throw new Error(`Unable to validate ${pkg.name}@${version} against the npm registry${registry ? ` "${registry}"` : ""}: ${output.trim() || `command exited with code ${result.exitCode}`}`);
|
|
165
|
-
};
|
|
166
|
-
info = run();
|
|
167
|
-
this.#versionMap.set(cacheKey, info);
|
|
168
|
-
}
|
|
169
|
-
return info;
|
|
170
|
-
}
|
|
171
|
-
async publish(pkg, options = {}) {
|
|
172
|
-
const client = await this.resolveClient();
|
|
173
|
-
const args = ["publish"];
|
|
174
|
-
const distTag = options.distTag ?? pkg.distTag;
|
|
175
|
-
if (distTag) args.push("--tag", distTag);
|
|
176
|
-
if (client === "pnpm") args.push("--no-git-checks");
|
|
177
|
-
const result = await x(client, args, { nodeOptions: { cwd: pkg.path } });
|
|
178
|
-
if (result.exitCode !== 0) throw new Error(execFailure(`Failed to publish ${pkg.name}@${pkg.version}${distTag ? ` with dist-tag "${distTag}"` : ""}.`, result));
|
|
179
|
-
}
|
|
180
|
-
async publishPlanStatus(plan) {
|
|
181
|
-
for (const [name, pkgPlan] of Object.entries(plan.packages)) {
|
|
182
|
-
const pkg = this.graph.get(name);
|
|
183
|
-
if (!(pkg instanceof NpmPackage) || !pkgPlan.publish) continue;
|
|
184
|
-
if (!await this.packageVersionExists(pkg, pkg.version)) return { state: "pending" };
|
|
185
|
-
}
|
|
186
|
-
return { state: "success" };
|
|
187
|
-
}
|
|
188
|
-
resolveClient() {
|
|
189
|
-
if (!this.#resolvedClient) this.#resolvedClient = this.npmClient ?? detect({ cwd: this.cwd }).then((result) => {
|
|
190
|
-
if (result?.name === "pnpm") return "pnpm";
|
|
191
|
-
return "npm";
|
|
192
|
-
});
|
|
193
|
-
return this.#resolvedClient;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
function commandOutput(result) {
|
|
197
|
-
return [result.stdout, result.stderr].filter(Boolean).join("\n");
|
|
198
|
-
}
|
|
199
|
-
function isMissingRegistryEntry(output) {
|
|
200
|
-
const normalized = output.toLowerCase();
|
|
201
|
-
return normalized.includes("e404") || normalized.includes("404") || normalized.includes("no match") || normalized.includes("no matching version") || normalized.includes("not found");
|
|
202
|
-
}
|
|
203
|
-
function parseNpmDependency(rawName, rawRange) {
|
|
204
|
-
if (rawRange.startsWith("workspace:")) return {
|
|
205
|
-
name: rawName,
|
|
206
|
-
range: rawRange.slice(10),
|
|
207
|
-
protocol: "workspace"
|
|
208
|
-
};
|
|
209
|
-
if (rawRange.startsWith("npm:")) {
|
|
210
|
-
const spec = rawRange.slice(4);
|
|
211
|
-
const separator = spec.lastIndexOf("@");
|
|
212
|
-
if (separator <= 0) return void 0;
|
|
213
|
-
return {
|
|
214
|
-
name: spec.slice(0, separator),
|
|
215
|
-
range: spec.slice(separator + 1),
|
|
216
|
-
protocol: "npm"
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
name: rawName,
|
|
221
|
-
range: rawRange
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function formatNpmDependency(spec) {
|
|
225
|
-
const npmSpec = spec;
|
|
226
|
-
if (npmSpec.protocol === "workspace") return `workspace:${spec.range}`;
|
|
227
|
-
if (npmSpec.protocol === "npm") return `npm:${spec.name}@${spec.range}`;
|
|
228
|
-
return spec.range;
|
|
229
|
-
}
|
|
230
|
-
function npm(client) {
|
|
231
|
-
return {
|
|
232
|
-
name: "npm",
|
|
233
|
-
enforce: "pre",
|
|
234
|
-
async resolve() {
|
|
235
|
-
await discoverNpmPackages(this.cwd, (pkg) => this.graph.add(pkg));
|
|
236
|
-
},
|
|
237
|
-
createRegistryClient() {
|
|
238
|
-
return new NpmRegistryClient(this.cwd, client, this.graph);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
async function discoverNpmPackages(cwd, add) {
|
|
243
|
-
const candidatePaths = await expandWorkspacePatterns(cwd, await readWorkspacePatterns(cwd));
|
|
244
|
-
const rootManifestPromise = readManifest(cwd).catch(() => void 0);
|
|
245
|
-
const manifests = await Promise.all(candidatePaths.map((path) => readManifest(path).then((manifest) => ({
|
|
246
|
-
path,
|
|
247
|
-
manifest
|
|
248
|
-
})).catch(() => void 0)));
|
|
249
|
-
const rootManifest = await rootManifestPromise;
|
|
250
|
-
if (rootManifest?.name && rootManifest.version && rootManifest.private !== true) add(new NpmPackage(cwd, rootManifest));
|
|
251
|
-
for (const entry of manifests) {
|
|
252
|
-
if (!entry?.manifest.name || !entry.manifest.version) continue;
|
|
253
|
-
add(new NpmPackage(entry.path, entry.manifest));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
async function readWorkspacePatterns(cwd) {
|
|
257
|
-
const pnpmPatterns = await readFile(join(cwd, "pnpm-workspace.yaml"), "utf8").then((content) => workspacePatternsSchema.parse(load(content) ?? {})).catch((error) => {
|
|
258
|
-
if (isNodeError(error) && error.code === "ENOENT") return void 0;
|
|
259
|
-
throw error;
|
|
260
|
-
});
|
|
261
|
-
if (pnpmPatterns) return pnpmPatterns;
|
|
262
|
-
return (await readManifest(cwd).catch(() => void 0))?.workspaces ?? ["."];
|
|
263
|
-
}
|
|
264
|
-
async function expandWorkspacePatterns(cwd, patterns) {
|
|
265
|
-
const paths = patterns.includes(".") ? [cwd] : [];
|
|
266
|
-
const globPatterns = patterns.filter((pattern) => pattern !== ".");
|
|
267
|
-
if (globPatterns.length > 0) paths.push(...await glob(globPatterns, {
|
|
268
|
-
absolute: true,
|
|
269
|
-
cwd,
|
|
270
|
-
ignore: ["**/node_modules/**"],
|
|
271
|
-
onlyDirectories: true,
|
|
272
|
-
onlyFiles: false
|
|
273
|
-
}));
|
|
274
|
-
return paths.map(normalize);
|
|
275
|
-
}
|
|
276
|
-
async function readManifest(packagePath) {
|
|
277
|
-
const content = await readFile(join(packagePath, "package.json"), "utf8");
|
|
278
|
-
return packageManifestSchema.parse(JSON.parse(content));
|
|
279
|
-
}
|
|
280
|
-
//#endregion
|
|
281
|
-
export { planStoreSchema as a, changelogFrontmatterSchema as i, NpmRegistryClient as n, npm as r, NpmPackage as t };
|