@kubb/studio 5.18.6 → 5.18.7
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/README.md +1 -1
- package/dist/index.cjs +45 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +48 -52
- package/dist/index.js.map +1 -1
- package/dist/protocol-f2YAAGLi.d.cts +1 -2
- package/dist/protocol-f2YAAGLi.d.ts +1 -2
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -225,9 +225,10 @@ type CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDepend
|
|
|
225
225
|
*/
|
|
226
226
|
apiKey: string;
|
|
227
227
|
/**
|
|
228
|
-
*
|
|
228
|
+
* Every entry of the project's Kubb config, generated like `kubb generate`: formatter, linter, and `output.postGenerate` included.
|
|
229
|
+
* One package holds the output of them all.
|
|
229
230
|
*/
|
|
230
|
-
|
|
231
|
+
configs: Array<Config>;
|
|
231
232
|
hooks?: Hookable<KubbHooks>;
|
|
232
233
|
signal?: AbortSignal;
|
|
233
234
|
};
|
|
@@ -236,13 +237,12 @@ type CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDepend
|
|
|
236
237
|
*
|
|
237
238
|
* @example
|
|
238
239
|
* ```ts
|
|
239
|
-
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!,
|
|
240
|
+
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!, configs, id: 'gh:123:pr-4', name: 'acme/api#4', packageName: '@acme/api', version: '1.0.0' })
|
|
240
241
|
* ```
|
|
241
242
|
*/
|
|
242
|
-
export declare function createSnapshot({ studioUrl, apiKey,
|
|
243
|
+
export declare function createSnapshot({ studioUrl, apiKey, configs, hooks, signal, ...metadata }: CreateSnapshotOptions): Promise<PublishedSnapshot>;
|
|
243
244
|
/**
|
|
244
245
|
* Hosted Kubb Studio URL, used when a host passes none.
|
|
245
246
|
*/
|
|
246
247
|
export declare const defaultStudioUrl = "https://kubb.studio";
|
|
247
|
-
export { type ConnectAgentOptions, type StudioConnectedContext, editConfig, editConfigFile };
|
|
248
|
-
//# sourceMappingURL=index.d.cts.map
|
|
248
|
+
export { type ConnectAgentOptions, type StudioConnectedContext, editConfig, editConfigFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -225,9 +225,10 @@ type CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDepend
|
|
|
225
225
|
*/
|
|
226
226
|
apiKey: string;
|
|
227
227
|
/**
|
|
228
|
-
*
|
|
228
|
+
* Every entry of the project's Kubb config, generated like `kubb generate`: formatter, linter, and `output.postGenerate` included.
|
|
229
|
+
* One package holds the output of them all.
|
|
229
230
|
*/
|
|
230
|
-
|
|
231
|
+
configs: Array<Config>;
|
|
231
232
|
hooks?: Hookable<KubbHooks>;
|
|
232
233
|
signal?: AbortSignal;
|
|
233
234
|
};
|
|
@@ -236,13 +237,12 @@ type CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDepend
|
|
|
236
237
|
*
|
|
237
238
|
* @example
|
|
238
239
|
* ```ts
|
|
239
|
-
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!,
|
|
240
|
+
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!, configs, id: 'gh:123:pr-4', name: 'acme/api#4', packageName: '@acme/api', version: '1.0.0' })
|
|
240
241
|
* ```
|
|
241
242
|
*/
|
|
242
|
-
export declare function createSnapshot({ studioUrl, apiKey,
|
|
243
|
+
export declare function createSnapshot({ studioUrl, apiKey, configs, hooks, signal, ...metadata }: CreateSnapshotOptions): Promise<PublishedSnapshot>;
|
|
243
244
|
/**
|
|
244
245
|
* Hosted Kubb Studio URL, used when a host passes none.
|
|
245
246
|
*/
|
|
246
247
|
export declare const defaultStudioUrl = "https://kubb.studio";
|
|
247
|
-
export { type ConnectAgentOptions, type StudioConnectedContext, editConfig, editConfigFile };
|
|
248
|
-
//# sourceMappingURL=index.d.ts.map
|
|
248
|
+
export { type ConnectAgentOptions, type StudioConnectedContext, editConfig, editConfigFile };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import path, { dirname, isAbsolute, join, relative, resolve, sep } from "node:pa
|
|
|
8
8
|
import process$1 from "node:process";
|
|
9
9
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
10
10
|
import { x } from "tinyexec";
|
|
11
|
-
import { Diagnostics, Hookable, cacheStorage, checkoutGitInput, createKubb, fsStorage, getInputKind, isPackageName, isPublicAddress, readInstalledPackages, resolveCacheDir, resolveMeta } from "@kubb/core";
|
|
11
|
+
import { Diagnostics, Hookable, Kubb, cacheStorage, checkoutGitInput, createKubb, fsStorage, getInputKind, isPackageName, isPublicAddress, readInstalledPackages, resolveCacheDir, resolveMeta } from "@kubb/core";
|
|
12
12
|
import { RpcTarget, newWebSocketRpcSession } from "capnweb";
|
|
13
13
|
import { pathToFileURL } from "node:url";
|
|
14
14
|
import { stripVTControlCharacters } from "node:util";
|
|
@@ -146,7 +146,7 @@ async function writeRaw(path, content) {
|
|
|
146
146
|
await writeFile(resolved, content, { encoding: "utf-8" });
|
|
147
147
|
} catch (error) {
|
|
148
148
|
if (error.code !== "ENOENT") throw error;
|
|
149
|
-
await mkdir(dirname(resolved), { recursive: true });
|
|
149
|
+
await mkdir$1(dirname(resolved), { recursive: true });
|
|
150
150
|
await writeFile(resolved, content, { encoding: "utf-8" });
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -188,25 +188,8 @@ async function inParallel({ items, limit, run }) {
|
|
|
188
188
|
};
|
|
189
189
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
190
190
|
}
|
|
191
|
-
// ../../internals/utils/src/time.ts
|
|
192
|
-
/**
|
|
193
|
-
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
194
|
-
* Rounds to 2 decimal places for sub-millisecond precision without noise.
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* const start = process.hrtime()
|
|
199
|
-
* doWork()
|
|
200
|
-
* getElapsedMs(start) // 42.35
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
function getElapsedMs(hrStart) {
|
|
204
|
-
const [seconds, nanoseconds] = process.hrtime(hrStart);
|
|
205
|
-
const ms = seconds * 1e3 + nanoseconds / 1e6;
|
|
206
|
-
return Math.round(ms * 100) / 100;
|
|
207
|
-
}
|
|
208
191
|
// package.json
|
|
209
|
-
var version = "5.18.
|
|
192
|
+
var version = "5.18.7";
|
|
210
193
|
// ../../internals/shared/src/constants.ts
|
|
211
194
|
/**
|
|
212
195
|
* Extensions `kubb` ships at its own version, so they count as installed without being a direct
|
|
@@ -1360,11 +1343,7 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1360
1343
|
hooks,
|
|
1361
1344
|
signal
|
|
1362
1345
|
});
|
|
1363
|
-
|
|
1364
|
-
const unhook = kubb.hooks.hook("kubb:build:end", (ctx) => {
|
|
1365
|
-
if (ctx.config === kubb.config) input = kubb.driver.inputNode;
|
|
1366
|
-
});
|
|
1367
|
-
const result = await kubb.generate().finally(unhook);
|
|
1346
|
+
const result = await kubb.generate();
|
|
1368
1347
|
if (!result.success) throw generationFailure(result.diagnostics);
|
|
1369
1348
|
const { storage, root } = kubb.config;
|
|
1370
1349
|
return {
|
|
@@ -1374,7 +1353,7 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1374
1353
|
root,
|
|
1375
1354
|
filePath: file.path
|
|
1376
1355
|
}))),
|
|
1377
|
-
input
|
|
1356
|
+
input: result.input
|
|
1378
1357
|
};
|
|
1379
1358
|
}
|
|
1380
1359
|
/**
|
|
@@ -1704,15 +1683,6 @@ function createGenerationStream(hooks, jobId) {
|
|
|
1704
1683
|
root = config.root;
|
|
1705
1684
|
});
|
|
1706
1685
|
for (const type of generationEventTypes) forward(type);
|
|
1707
|
-
on("kubb:generation:end", ({ diagnostics = [], status, hrStart, filesCreated }) => {
|
|
1708
|
-
if (!hrStart) return;
|
|
1709
|
-
emitEvent("kubb:generation:summary", [{
|
|
1710
|
-
duration: Math.round(getElapsedMs(hrStart)),
|
|
1711
|
-
fileCount: filesCreated ?? 0,
|
|
1712
|
-
failedPlugins: Diagnostics.failedPlugins(diagnostics).length,
|
|
1713
|
-
status: status ?? "success"
|
|
1714
|
-
}]);
|
|
1715
|
-
});
|
|
1716
1686
|
/**
|
|
1717
1687
|
* Takes this generation's listeners off the session emitter. Safe to call twice.
|
|
1718
1688
|
*/
|
|
@@ -3411,7 +3381,7 @@ async function createSnapshotPackage({ files, packageInfo }) {
|
|
|
3411
3381
|
const root = await mkdtemp(join(tmpdir(), "kubb-snapshot-"));
|
|
3412
3382
|
const dist = join(root, "dist");
|
|
3413
3383
|
try {
|
|
3414
|
-
await mkdir
|
|
3384
|
+
await mkdir(dist);
|
|
3415
3385
|
await Promise.all([...sources].map(async ([path, { content }]) => {
|
|
3416
3386
|
await writeRaw(join(root, path), content);
|
|
3417
3387
|
}));
|
|
@@ -3475,25 +3445,50 @@ async function createSnapshotPackage({ files, packageInfo }) {
|
|
|
3475
3445
|
*
|
|
3476
3446
|
* @example
|
|
3477
3447
|
* ```ts
|
|
3478
|
-
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!,
|
|
3448
|
+
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!, configs, id: 'gh:123:pr-4', name: 'acme/api#4', packageName: '@acme/api', version: '1.0.0' })
|
|
3479
3449
|
* ```
|
|
3480
3450
|
*/
|
|
3481
|
-
async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey,
|
|
3451
|
+
async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, configs, hooks, signal, ...metadata }) {
|
|
3482
3452
|
const url = secureUrl({
|
|
3483
3453
|
studioUrl,
|
|
3484
3454
|
path: "/api/snapshots"
|
|
3485
3455
|
});
|
|
3486
|
-
const
|
|
3487
|
-
config
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3456
|
+
const buildConfigs = configs.map((config) => ({
|
|
3457
|
+
...config,
|
|
3458
|
+
storage: fsStorage()
|
|
3459
|
+
}));
|
|
3460
|
+
const failures = [];
|
|
3461
|
+
const sources = /* @__PURE__ */ new Map();
|
|
3462
|
+
for await (const { success, error, diagnostics, files, kubb } of Kubb.generate(buildConfigs, {
|
|
3491
3463
|
hooks,
|
|
3492
|
-
signal
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3464
|
+
signal
|
|
3465
|
+
})) {
|
|
3466
|
+
if (!success) {
|
|
3467
|
+
failures.push(error ?? generationFailure(diagnostics));
|
|
3468
|
+
continue;
|
|
3469
|
+
}
|
|
3470
|
+
const { root } = kubb.config;
|
|
3471
|
+
for (const file of files) {
|
|
3472
|
+
const path = relativeStoragePath({
|
|
3473
|
+
root,
|
|
3474
|
+
filePath: file.path
|
|
3475
|
+
});
|
|
3476
|
+
const source = resolve(root, path);
|
|
3477
|
+
const owner = sources.get(path);
|
|
3478
|
+
if (owner && owner !== source) throw new Diagnostics.Error({
|
|
3479
|
+
code: Diagnostics.code.unknown,
|
|
3480
|
+
severity: "error",
|
|
3481
|
+
message: `Snapshot has two generated files at "${path}": "${owner}" and "${source}"`,
|
|
3482
|
+
help: "Give the config entries the same `root`, or output paths that do not overlap."
|
|
3483
|
+
});
|
|
3484
|
+
sources.set(path, source);
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
if (failures.length === 1) throw failures[0];
|
|
3488
|
+
if (failures.length) throw new AggregateError(failures, failures.map(getErrorMessage).join("\n"));
|
|
3489
|
+
const storage = fsStorage();
|
|
3490
|
+
const files = Object.fromEntries(await Promise.all([...sources].map(async ([path, source]) => {
|
|
3491
|
+
const content = await storage.readItem(source);
|
|
3497
3492
|
if (content === null) throw new Diagnostics.Error({
|
|
3498
3493
|
code: Diagnostics.code.internalError,
|
|
3499
3494
|
severity: "error",
|
|
@@ -3501,12 +3496,13 @@ async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, config, ho
|
|
|
3501
3496
|
});
|
|
3502
3497
|
return [path, content];
|
|
3503
3498
|
})));
|
|
3504
|
-
const pluginNames = config.plugins.map((plugin) => resolveMeta(plugin).name);
|
|
3505
|
-
const
|
|
3506
|
-
|
|
3499
|
+
const pluginNames = [...new Set(configs.flatMap((config) => config.plugins.map((plugin) => resolveMeta(plugin).name)))];
|
|
3500
|
+
const roots = [...new Set(configs.map((config) => config.root))];
|
|
3501
|
+
const installed = (await Promise.all(roots.map((root) => readInstalledPackages({
|
|
3502
|
+
root,
|
|
3507
3503
|
packages: pluginNames.map(toPackageName),
|
|
3508
3504
|
resolveFrom: ["kubb"]
|
|
3509
|
-
});
|
|
3505
|
+
})))).flat();
|
|
3510
3506
|
const packageOf = (name) => installed.find(({ manifest }) => manifest?.kind === "plugin" && manifest.name === name)?.package ?? toPackageName(name);
|
|
3511
3507
|
const names = [...new Set(pluginNames.map(packageOf))];
|
|
3512
3508
|
const peerDependencies = Object.fromEntries(installed.flatMap(({ package: name, version }) => names.includes(name) && version ? [[name, version]] : []));
|