@kizunajs/cli 2.0.0-beta.3 → 2.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.cjs +27 -7
- package/dist/cli.mjs +27 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +67 -19
- package/dist/index.d.mts +67 -19
- package/dist/index.mjs +1 -1
- package/dist/{route-map-BZVDVH7m.mjs → route-map-CRWVBQGf.mjs} +217 -134
- package/dist/{route-map-BUq6Iw3_.cjs → route-map-yRIISgnC.cjs} +239 -132
- package/package.json +5 -4
|
@@ -23,9 +23,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
let jiti = require("jiti");
|
|
24
24
|
let kizunajs = require("kizunajs");
|
|
25
25
|
let kizunajs_generator = require("kizunajs/generator");
|
|
26
|
+
let node_path = require("node:path");
|
|
27
|
+
let yaml = require("yaml");
|
|
26
28
|
let kizunajs_adapter = require("kizunajs/adapter");
|
|
27
29
|
let node_fs = require("node:fs");
|
|
28
|
-
let node_path = require("node:path");
|
|
29
30
|
let typescript = require("typescript");
|
|
30
31
|
typescript = __toESM(typescript, 1);
|
|
31
32
|
let node_child_process = require("node:child_process");
|
|
@@ -47,49 +48,22 @@ const loadConfig = async (configPath) => {
|
|
|
47
48
|
name,
|
|
48
49
|
api: entry.api,
|
|
49
50
|
clients: entry.clients ?? [],
|
|
50
|
-
typesOutput: entry.typescript?.outputFile
|
|
51
|
+
typesOutput: entry.typescript?.outputFile,
|
|
52
|
+
diff: entry.diff ?? {}
|
|
51
53
|
}));
|
|
52
54
|
};
|
|
53
55
|
//#endregion
|
|
54
56
|
//#region src/diff-schemas.ts
|
|
55
|
-
const shapeOf = (schema) => {
|
|
56
|
-
const { inner } = (0, kizunajs_generator.unwrapOptionalWrappers)(schema);
|
|
57
|
-
const raw = (0, kizunajs_generator.readObjectShape)(inner);
|
|
58
|
-
if (!raw) return void 0;
|
|
59
|
-
const fields = /* @__PURE__ */ new Map();
|
|
60
|
-
for (const [key, field] of Object.entries(raw)) fields.set(key, {
|
|
61
|
-
schema: field,
|
|
62
|
-
optional: (0, kizunajs_generator.unwrapOptionalWrappers)(field).optional
|
|
63
|
-
});
|
|
64
|
-
return { fields };
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* What a schema accepts, flattened enough to compare: its kind, and its values
|
|
68
|
-
* when it is closed.
|
|
69
|
-
*/
|
|
70
|
-
const describe = (schema) => {
|
|
71
|
-
const { inner } = (0, kizunajs_generator.unwrapOptionalWrappers)(schema);
|
|
72
|
-
const def = (0, kizunajs_generator.readDef)(inner);
|
|
73
|
-
if (def.type === "enum") return {
|
|
74
|
-
kind: "enum",
|
|
75
|
-
values: Object.values(def.entries ?? {}).map(String).sort()
|
|
76
|
-
};
|
|
77
|
-
if (def.type === "literal") return {
|
|
78
|
-
kind: "enum",
|
|
79
|
-
values: (def.values ?? []).map(String).sort()
|
|
80
|
-
};
|
|
81
|
-
if (def.type === "array" && def.element) return { kind: `array<${describe(def.element).kind}>` };
|
|
82
|
-
return { kind: def.type ?? "unknown" };
|
|
83
|
-
};
|
|
84
57
|
const joinPath = (parent, key) => parent === "" ? key : `${parent}.${key}`;
|
|
58
|
+
const fieldsOf = (schema) => schema.kind === "object" ? schema.fields : void 0;
|
|
59
|
+
const elementOf = (schema) => schema.kind === "array" ? schema.element : void 0;
|
|
60
|
+
const valuesOf = (schema) => schema.kind === "enum" ? schema.values : void 0;
|
|
85
61
|
/**
|
|
86
|
-
*
|
|
87
|
-
* rather than as the whole array changing shape.
|
|
62
|
+
* What a reader sees when the kinds differ, so `array` reads as `array<string>`.
|
|
88
63
|
*/
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
return def.type === "array" ? def.element : void 0;
|
|
64
|
+
const describeKind = (schema) => {
|
|
65
|
+
const element = elementOf(schema);
|
|
66
|
+
return element ? `array<${describeKind(element)}>` : schema.kind;
|
|
93
67
|
};
|
|
94
68
|
/**
|
|
95
69
|
* What changed between two versions of one schema, and whether it breaks the
|
|
@@ -111,11 +85,11 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
111
85
|
const beforeElement = elementOf(before);
|
|
112
86
|
const afterElement = elementOf(after);
|
|
113
87
|
if (beforeElement && afterElement) return diffSchemas(beforeElement, afterElement, direction, `${path}[]`);
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
for (const [key, field] of
|
|
118
|
-
const existing =
|
|
88
|
+
const beforeFields = fieldsOf(before);
|
|
89
|
+
const afterFields = fieldsOf(after);
|
|
90
|
+
if (beforeFields && afterFields) {
|
|
91
|
+
for (const [key, field] of Object.entries(afterFields)) {
|
|
92
|
+
const existing = beforeFields[key];
|
|
119
93
|
const here = joinPath(path, key);
|
|
120
94
|
if (!existing) {
|
|
121
95
|
if (!field.optional) changes.push({
|
|
@@ -132,8 +106,8 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
132
106
|
});
|
|
133
107
|
changes.push(...diffSchemas(existing.schema, field.schema, direction, here));
|
|
134
108
|
}
|
|
135
|
-
for (const
|
|
136
|
-
if (
|
|
109
|
+
for (const key of Object.keys(beforeFields)) {
|
|
110
|
+
if (afterFields[key]) continue;
|
|
137
111
|
const here = joinPath(path, key);
|
|
138
112
|
changes.push({
|
|
139
113
|
breaking: direction === "response",
|
|
@@ -143,19 +117,16 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
143
117
|
}
|
|
144
118
|
return changes;
|
|
145
119
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (was.values && now.values) {
|
|
157
|
-
const removed = was.values.filter((value) => !now.values?.includes(value));
|
|
158
|
-
const added = now.values.filter((value) => !was.values?.includes(value));
|
|
120
|
+
if (before.kind !== after.kind) return [{
|
|
121
|
+
breaking: true,
|
|
122
|
+
path,
|
|
123
|
+
summary: `${path || "the body"} is ${describeKind(after)} instead of ${describeKind(before)}`
|
|
124
|
+
}];
|
|
125
|
+
const was = valuesOf(before);
|
|
126
|
+
const now = valuesOf(after);
|
|
127
|
+
if (was && now) {
|
|
128
|
+
const removed = was.filter((value) => !now.includes(value));
|
|
129
|
+
const added = now.filter((value) => !was.includes(value));
|
|
159
130
|
if (removed.length > 0) changes.push({
|
|
160
131
|
breaking: true,
|
|
161
132
|
path,
|
|
@@ -167,53 +138,145 @@ const diffSchemas = (before, after, direction, path = "") => {
|
|
|
167
138
|
summary: direction === "response" ? `${path || "the body"} can now be ${added.join(", ")}` : `${path || "the body"} also accepts ${added.join(", ")}`
|
|
168
139
|
});
|
|
169
140
|
}
|
|
141
|
+
const wasRefined = before.refinements ?? 0;
|
|
142
|
+
const isRefined = after.refinements ?? 0;
|
|
143
|
+
if (wasRefined !== isRefined) changes.push({
|
|
144
|
+
breaking: direction === "request" && isRefined > wasRefined,
|
|
145
|
+
path,
|
|
146
|
+
summary: isRefined > wasRefined ? `${path || "the body"} is validated more tightly` : `${path || "the body"} is validated less tightly`
|
|
147
|
+
});
|
|
170
148
|
return changes;
|
|
171
149
|
};
|
|
172
150
|
//#endregion
|
|
173
|
-
//#region src/
|
|
174
|
-
|
|
175
|
-
|
|
151
|
+
//#region src/snapshot.ts
|
|
152
|
+
/**
|
|
153
|
+
* How many `.refine()` or `.superRefine()` calls a schema carries. The
|
|
154
|
+
* predicate itself cannot be compared across two files, but its arrival or
|
|
155
|
+
* departure can.
|
|
156
|
+
*/
|
|
157
|
+
const refinementCount = (schema) => {
|
|
158
|
+
const checks = (0, kizunajs_generator.readDef)(schema).checks;
|
|
159
|
+
if (!checks) return void 0;
|
|
160
|
+
const custom = checks.filter((check) => check._zod?.def?.check === "custom").length;
|
|
161
|
+
return custom === 0 ? void 0 : custom;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* A Zod schema reduced to the shape a comparison reads.
|
|
165
|
+
*/
|
|
166
|
+
const toSchemaNode = (schema) => {
|
|
167
|
+
const { inner } = (0, kizunajs_generator.unwrapOptionalWrappers)(schema);
|
|
168
|
+
const def = (0, kizunajs_generator.readDef)(inner);
|
|
169
|
+
const refinements = refinementCount(inner);
|
|
170
|
+
const carry = refinements === void 0 ? {} : { refinements };
|
|
171
|
+
const shape = (0, kizunajs_generator.readObjectShape)(inner);
|
|
172
|
+
if (shape) {
|
|
173
|
+
const fields = {};
|
|
174
|
+
for (const [key, field] of Object.entries(shape)) fields[key] = {
|
|
175
|
+
optional: (0, kizunajs_generator.unwrapOptionalWrappers)(field).optional,
|
|
176
|
+
schema: toSchemaNode(field)
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
kind: "object",
|
|
180
|
+
fields,
|
|
181
|
+
...carry
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (def.type === "array" && def.element) return {
|
|
185
|
+
kind: "array",
|
|
186
|
+
element: toSchemaNode(def.element),
|
|
187
|
+
...carry
|
|
188
|
+
};
|
|
189
|
+
if (def.type === "enum") return {
|
|
190
|
+
kind: "enum",
|
|
191
|
+
values: Object.values(def.entries ?? {}).map(String).sort(),
|
|
192
|
+
...carry
|
|
193
|
+
};
|
|
194
|
+
if (def.type === "literal") return {
|
|
195
|
+
kind: "enum",
|
|
196
|
+
values: (def.values ?? []).map(String).sort(),
|
|
197
|
+
...carry
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
kind: def.type ?? "unknown",
|
|
201
|
+
...carry
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
const sunsetOf = (route) => {
|
|
205
|
+
const declared = route.sunset;
|
|
206
|
+
if (declared === void 0) return void 0;
|
|
207
|
+
return typeof declared === "string" ? declared : declared.date;
|
|
208
|
+
};
|
|
209
|
+
const routeSnapshots = (0, kizunajs_generator.createGenerator)(() => {
|
|
210
|
+
const routes = {};
|
|
176
211
|
return {
|
|
177
212
|
processRoute({ routeKey, route, deprecated }) {
|
|
178
|
-
|
|
213
|
+
const sunset = sunsetOf(route);
|
|
214
|
+
const responses = {};
|
|
215
|
+
for (const [status, response] of Object.entries(route.responses)) {
|
|
216
|
+
const body = (0, kizunajs_generator.resolveResponseBody)(response);
|
|
217
|
+
responses[status] = body === void 0 ? null : toSchemaNode(body);
|
|
218
|
+
}
|
|
219
|
+
routes[routeKey] = {
|
|
179
220
|
method: route.method,
|
|
180
221
|
path: route.path,
|
|
181
|
-
statuses: Object.keys(route.responses).map(Number).sort(),
|
|
222
|
+
statuses: Object.keys(route.responses).map(Number).sort((a, b) => a - b),
|
|
182
223
|
deprecated,
|
|
183
|
-
...
|
|
184
|
-
...route.body ? { body: route.body } : {},
|
|
185
|
-
...route.query ? { query: route.query } : {},
|
|
186
|
-
...route.headers ? { headers: route.headers } : {},
|
|
187
|
-
responses
|
|
188
|
-
}
|
|
224
|
+
...sunset === void 0 ? {} : { sunset },
|
|
225
|
+
...route.body ? { body: toSchemaNode(route.body) } : {},
|
|
226
|
+
...route.query ? { query: toSchemaNode(route.query) } : {},
|
|
227
|
+
...route.headers ? { headers: toSchemaNode(route.headers) } : {},
|
|
228
|
+
responses
|
|
229
|
+
};
|
|
189
230
|
},
|
|
190
|
-
finalize: () =>
|
|
231
|
+
finalize: () => routes
|
|
191
232
|
};
|
|
192
233
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Everything `kizuna diff` compares, as plain data.
|
|
236
|
+
*
|
|
237
|
+
* Writing this at each commit is what lets a comparison read the other side
|
|
238
|
+
* out of git rather than checking it out and running it.
|
|
239
|
+
*/
|
|
240
|
+
const toSnapshot = (api) => {
|
|
241
|
+
const declared = api.jobs;
|
|
242
|
+
const jobs = declared ? (0, kizunajs_generator.flattenJobs)(declared).map((job) => job.jobKey).sort() : [];
|
|
243
|
+
const tools = Object.fromEntries((0, kizunajs_adapter.flattenRoutes)(api.routes).filter(({ route }) => route.tool !== void 0 && route.tool !== false).map(({ routeKey }) => [routeKey, (0, kizunajs_generator.toToolName)(routeKey)]));
|
|
244
|
+
return {
|
|
245
|
+
routes: routeSnapshots(api, {}),
|
|
246
|
+
jobs,
|
|
247
|
+
tools
|
|
248
|
+
};
|
|
202
249
|
};
|
|
203
250
|
/**
|
|
204
|
-
*
|
|
251
|
+
* YAML rather than JSON, so the file a reviewer opens in a pull request reads
|
|
252
|
+
* as the API rather than as punctuation.
|
|
205
253
|
*/
|
|
206
|
-
const
|
|
254
|
+
const renderSnapshot = (api) => (0, yaml.stringify)(toSnapshot(api), { lineWidth: 0 });
|
|
207
255
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
|
|
256
|
+
* Where a config's snapshot lives. `.kizuna/` sits beside the config, so CI
|
|
257
|
+
* always knows where to look without being told, and a repository holding
|
|
258
|
+
* several configs keeps one snapshot per config.
|
|
259
|
+
*/
|
|
260
|
+
const snapshotPathFor = (configPath) => {
|
|
261
|
+
const declared = (0, node_path.basename)(configPath).replace(/\.config\.[cm]?[jt]s$/, "").replace(/^kizuna\./, "");
|
|
262
|
+
const name = declared === "" || declared === "kizuna" ? "diff" : `${declared}.diff`;
|
|
263
|
+
return (0, node_path.join)((0, node_path.dirname)(configPath), ".kizuna", `${name}.yaml`);
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* The snapshot as a client target, so `kizuna generate` writes it and
|
|
267
|
+
* `kizuna generate --check` refuses to let it go stale.
|
|
212
268
|
*/
|
|
213
|
-
const
|
|
269
|
+
const snapshotTarget = (configPath) => ({
|
|
270
|
+
kind: "diff",
|
|
271
|
+
output: snapshotPathFor(configPath),
|
|
272
|
+
generate: renderSnapshot
|
|
273
|
+
});
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/diff-apis.ts
|
|
276
|
+
const diffSnapshots = (before, after, options = {}) => {
|
|
214
277
|
const changes = [];
|
|
215
|
-
const beforeRoutes =
|
|
216
|
-
const afterRoutes =
|
|
278
|
+
const beforeRoutes = new Map(Object.entries(before.routes));
|
|
279
|
+
const afterRoutes = new Map(Object.entries(after.routes));
|
|
217
280
|
const removed = [...beforeRoutes.keys()].filter((key) => !afterRoutes.has(key));
|
|
218
281
|
const added = [...afterRoutes.keys()].filter((key) => !beforeRoutes.has(key));
|
|
219
282
|
const renames = /* @__PURE__ */ new Map();
|
|
@@ -230,10 +293,10 @@ const diffApis = (before, after) => {
|
|
|
230
293
|
if (match) renames.set(match, goneKey);
|
|
231
294
|
}
|
|
232
295
|
for (const [toKey, fromKey] of renames) changes.push({
|
|
233
|
-
level: "breaking",
|
|
296
|
+
level: options.dottedKeys ? "breaking" : "changed",
|
|
234
297
|
key: fromKey,
|
|
235
298
|
summary: `${fromKey} renamed to ${toKey}`,
|
|
236
|
-
detail: "
|
|
299
|
+
detail: "the generated client method changes name, the HTTP surface does not"
|
|
237
300
|
});
|
|
238
301
|
for (const key of removed) {
|
|
239
302
|
if ([...renames.values()].includes(key)) continue;
|
|
@@ -306,10 +369,10 @@ const diffApis = (before, after) => {
|
|
|
306
369
|
key,
|
|
307
370
|
summary: `${httpLabel(arrived, key)} ${change.summary}`
|
|
308
371
|
});
|
|
309
|
-
for (const [status, was] of gone.responses) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
for (const change of diffSchemas(was, now, "response",
|
|
372
|
+
for (const [status, was] of Object.entries(gone.responses)) {
|
|
373
|
+
if (!(status in arrived.responses)) continue;
|
|
374
|
+
const now = arrived.responses[status];
|
|
375
|
+
for (const change of diffSchemas(was ?? void 0, now ?? void 0, "response", status)) changes.push({
|
|
313
376
|
level: change.breaking ? "breaking" : "changed",
|
|
314
377
|
key,
|
|
315
378
|
summary: `${httpLabel(arrived, key)} ${change.summary}`
|
|
@@ -326,8 +389,8 @@ const diffApis = (before, after) => {
|
|
|
326
389
|
summary: `${httpLabel(arrived, key)} sunsets on ${arrived.sunset}`
|
|
327
390
|
});
|
|
328
391
|
}
|
|
329
|
-
for (const key of
|
|
330
|
-
if (
|
|
392
|
+
for (const key of options.jobs ? before.jobs : []) {
|
|
393
|
+
if (after.jobs.includes(key)) continue;
|
|
331
394
|
changes.push({
|
|
332
395
|
level: "breaking",
|
|
333
396
|
key,
|
|
@@ -335,10 +398,8 @@ const diffApis = (before, after) => {
|
|
|
335
398
|
detail: "whatever calls POST /jobs/run with that key stops working"
|
|
336
399
|
});
|
|
337
400
|
}
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
for (const [key, name] of beforeTools) {
|
|
341
|
-
const arrived = afterTools.get(key);
|
|
401
|
+
for (const [key, name] of options.tools ? Object.entries(before.tools) : []) {
|
|
402
|
+
const arrived = after.tools[key];
|
|
342
403
|
if (arrived === void 0) {
|
|
343
404
|
changes.push({
|
|
344
405
|
level: "breaking",
|
|
@@ -363,6 +424,13 @@ const diffApis = (before, after) => {
|
|
|
363
424
|
return changes.sort((left, right) => order[left.level] - order[right.level] || left.key.localeCompare(right.key));
|
|
364
425
|
};
|
|
365
426
|
/**
|
|
427
|
+
* What changed between two apis, for a caller holding both in memory.
|
|
428
|
+
*
|
|
429
|
+
* `kizuna diff` reads snapshots instead, so it never has to load the other
|
|
430
|
+
* side's code.
|
|
431
|
+
*/
|
|
432
|
+
const diffApis = (before, after, options = {}) => diffSnapshots(toSnapshot(before), toSnapshot(after), options);
|
|
433
|
+
/**
|
|
366
434
|
* One block per change, ready to print: the level, the summary, and the
|
|
367
435
|
* detail indented beneath it.
|
|
368
436
|
*/
|
|
@@ -431,7 +499,7 @@ const formatStale = (stale, command = "kizuna generate") => {
|
|
|
431
499
|
return client.reason === "missing" ? ` ${where} has not been generated` : ` ${where} is behind the config`;
|
|
432
500
|
});
|
|
433
501
|
return [
|
|
434
|
-
stale.length === 1 ? "A generated
|
|
502
|
+
stale.length === 1 ? "A generated file is out of date:" : `${stale.length} generated files are out of date:`,
|
|
435
503
|
...lines,
|
|
436
504
|
"",
|
|
437
505
|
`Run \`${command}\` and commit the result.`
|
|
@@ -670,44 +738,59 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", output
|
|
|
670
738
|
//#region src/diff-against.ts
|
|
671
739
|
const git = (cwd, ...args) => (0, node_child_process.execFileSync)("git", args, {
|
|
672
740
|
cwd,
|
|
673
|
-
encoding: "utf8"
|
|
741
|
+
encoding: "utf8",
|
|
742
|
+
stdio: [
|
|
743
|
+
"ignore",
|
|
744
|
+
"pipe",
|
|
745
|
+
"ignore"
|
|
746
|
+
]
|
|
674
747
|
}).trim();
|
|
675
748
|
/**
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
* The ref is checked out into a worktree inside the repository, which costs a
|
|
679
|
-
* few files rather than a clone. Nothing is installed there: module resolution
|
|
680
|
-
* walks up to the repository's own `node_modules`, so the base tree needs only
|
|
681
|
-
* its source.
|
|
682
|
-
*
|
|
683
|
-
* @example
|
|
684
|
-
* const changes = await diffAgainst('main', './src/contract.ts');
|
|
749
|
+
* The repository holding the snapshot, falling back to the one the caller ran in.
|
|
685
750
|
*/
|
|
686
|
-
const
|
|
687
|
-
const { cwd = process.cwd() } = options;
|
|
688
|
-
const root = git(cwd, "rev-parse", "--show-toplevel");
|
|
689
|
-
const absolute = (0, node_path.isAbsolute)(configPath) ? configPath : (0, node_path.resolve)(cwd, configPath);
|
|
690
|
-
const fromRoot = (0, node_path.relative)(root, absolute);
|
|
691
|
-
if (fromRoot.startsWith("..")) throw new Error(`${configPath} is outside the repository at ${root}`);
|
|
692
|
-
const worktree = (0, node_fs.mkdtempSync)((0, node_path.join)(root, ".kizuna-diff-"));
|
|
751
|
+
const repositoryFor = (directory, cwd) => {
|
|
693
752
|
try {
|
|
694
|
-
git(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
const [after] = await loadConfig(absolute);
|
|
698
|
-
if (after === void 0) throw new Error(`No config found in ${configPath}`);
|
|
699
|
-
return diffApis(before.api, after.api);
|
|
700
|
-
} finally {
|
|
701
|
-
try {
|
|
702
|
-
git(root, "worktree", "remove", "--force", worktree);
|
|
703
|
-
} catch {
|
|
704
|
-
(0, node_fs.rmSync)(worktree, {
|
|
705
|
-
recursive: true,
|
|
706
|
-
force: true
|
|
707
|
-
});
|
|
708
|
-
}
|
|
753
|
+
return git(directory, "rev-parse", "--show-toplevel");
|
|
754
|
+
} catch {
|
|
755
|
+
return git(cwd, "rev-parse", "--show-toplevel");
|
|
709
756
|
}
|
|
710
757
|
};
|
|
758
|
+
const parseSnapshot = (contents, source) => {
|
|
759
|
+
try {
|
|
760
|
+
return (0, yaml.parse)(contents);
|
|
761
|
+
} catch {
|
|
762
|
+
throw new Error(`${source} is not a Kizuna diff file. Run \`kizuna generate\` to write one.`);
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
/**
|
|
766
|
+
* Reads a path out of a ref without checking anything out.
|
|
767
|
+
*/
|
|
768
|
+
const showAtRef = (root, ref, path) => {
|
|
769
|
+
try {
|
|
770
|
+
return git(root, "show", `${ref}:${path}`);
|
|
771
|
+
} catch {
|
|
772
|
+
throw new Error(`${path} does not exist at ${ref}. It was added or renamed since, so there is nothing to compare against.`);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
const readSnapshot = (path) => {
|
|
776
|
+
if (!(0, node_fs.existsSync)(path)) throw new Error(`No snapshot at ${path}. Run \`kizuna generate\` to write one.`);
|
|
777
|
+
return parseSnapshot((0, node_fs.readFileSync)(path, "utf8"), path);
|
|
778
|
+
};
|
|
779
|
+
/**
|
|
780
|
+
* Compares a snapshot against the same file at a git ref.
|
|
781
|
+
*
|
|
782
|
+
* The ref is read with `git show`, so nothing is checked out, installed or
|
|
783
|
+
* executed for the other side. A snapshot written a year ago compares fine
|
|
784
|
+
* against one written today.
|
|
785
|
+
*/
|
|
786
|
+
const diffAgainst = (ref, snapshotPath, options = {}) => {
|
|
787
|
+
const { cwd = process.cwd(), ...diff } = options;
|
|
788
|
+
const absolute = (0, node_path.isAbsolute)(snapshotPath) ? snapshotPath : (0, node_path.resolve)(cwd, snapshotPath);
|
|
789
|
+
const root = repositoryFor((0, node_path.dirname)(absolute), cwd);
|
|
790
|
+
const fromRoot = (0, node_path.relative)(root, absolute);
|
|
791
|
+
if (fromRoot.startsWith("..")) throw new Error(`${snapshotPath} is outside the repository at ${root}`);
|
|
792
|
+
return diffSnapshots(parseSnapshot(showAtRef(root, ref, fromRoot.split("\\").join("/")), `${fromRoot} at ${ref}`), readSnapshot(absolute), diff);
|
|
793
|
+
};
|
|
711
794
|
//#endregion
|
|
712
795
|
//#region src/route-map.ts
|
|
713
796
|
const permissionList = (requires) => {
|
|
@@ -822,6 +905,12 @@ Object.defineProperty(exports, "diffSchemas", {
|
|
|
822
905
|
return diffSchemas;
|
|
823
906
|
}
|
|
824
907
|
});
|
|
908
|
+
Object.defineProperty(exports, "diffSnapshots", {
|
|
909
|
+
enumerable: true,
|
|
910
|
+
get: function() {
|
|
911
|
+
return diffSnapshots;
|
|
912
|
+
}
|
|
913
|
+
});
|
|
825
914
|
Object.defineProperty(exports, "formatChange", {
|
|
826
915
|
enumerable: true,
|
|
827
916
|
get: function() {
|
|
@@ -858,12 +947,30 @@ Object.defineProperty(exports, "loadConfig", {
|
|
|
858
947
|
return loadConfig;
|
|
859
948
|
}
|
|
860
949
|
});
|
|
950
|
+
Object.defineProperty(exports, "readSnapshot", {
|
|
951
|
+
enumerable: true,
|
|
952
|
+
get: function() {
|
|
953
|
+
return readSnapshot;
|
|
954
|
+
}
|
|
955
|
+
});
|
|
861
956
|
Object.defineProperty(exports, "routeMap", {
|
|
862
957
|
enumerable: true,
|
|
863
958
|
get: function() {
|
|
864
959
|
return routeMap;
|
|
865
960
|
}
|
|
866
961
|
});
|
|
962
|
+
Object.defineProperty(exports, "snapshotPathFor", {
|
|
963
|
+
enumerable: true,
|
|
964
|
+
get: function() {
|
|
965
|
+
return snapshotPathFor;
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
Object.defineProperty(exports, "snapshotTarget", {
|
|
969
|
+
enumerable: true,
|
|
970
|
+
get: function() {
|
|
971
|
+
return snapshotTarget;
|
|
972
|
+
}
|
|
973
|
+
});
|
|
867
974
|
Object.defineProperty(exports, "writeClients", {
|
|
868
975
|
enumerable: true,
|
|
869
976
|
get: function() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/cli",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.4",
|
|
4
4
|
"description": "Command line tooling for Kizuna.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -57,18 +57,19 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"jiti": "^2.7.0",
|
|
60
|
-
"typescript": "^6.0.3"
|
|
60
|
+
"typescript": "^6.0.3",
|
|
61
|
+
"yaml": "^2.8.4"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
64
|
"zod": "^4.0.0",
|
|
64
|
-
"kizunajs": "2.0.0-beta.
|
|
65
|
+
"kizunajs": "2.0.0-beta.4"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"@types/node": "^24",
|
|
68
69
|
"@types/react": "^19.2.18",
|
|
69
70
|
"tsdown": "^0.21.0",
|
|
70
71
|
"zod": "^4.0.0",
|
|
71
|
-
"kizunajs": "2.0.0-beta.
|
|
72
|
+
"kizunajs": "2.0.0-beta.4"
|
|
72
73
|
},
|
|
73
74
|
"scripts": {
|
|
74
75
|
"build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external zod --external jiti --external typescript",
|