@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/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -216,25 +216,8 @@ async function inParallel({ items, limit, run }) {
|
|
|
216
216
|
};
|
|
217
217
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
218
218
|
}
|
|
219
|
-
// ../../internals/utils/src/time.ts
|
|
220
|
-
/**
|
|
221
|
-
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
222
|
-
* Rounds to 2 decimal places for sub-millisecond precision without noise.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```ts
|
|
226
|
-
* const start = process.hrtime()
|
|
227
|
-
* doWork()
|
|
228
|
-
* getElapsedMs(start) // 42.35
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
function getElapsedMs(hrStart) {
|
|
232
|
-
const [seconds, nanoseconds] = process.hrtime(hrStart);
|
|
233
|
-
const ms = seconds * 1e3 + nanoseconds / 1e6;
|
|
234
|
-
return Math.round(ms * 100) / 100;
|
|
235
|
-
}
|
|
236
219
|
// package.json
|
|
237
|
-
var version = "5.18.
|
|
220
|
+
var version = "5.18.7";
|
|
238
221
|
// ../../internals/shared/src/constants.ts
|
|
239
222
|
/**
|
|
240
223
|
* Extensions `kubb` ships at its own version, so they count as installed without being a direct
|
|
@@ -1388,11 +1371,7 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1388
1371
|
hooks,
|
|
1389
1372
|
signal
|
|
1390
1373
|
});
|
|
1391
|
-
|
|
1392
|
-
const unhook = kubb.hooks.hook("kubb:build:end", (ctx) => {
|
|
1393
|
-
if (ctx.config === kubb.config) input = kubb.driver.inputNode;
|
|
1394
|
-
});
|
|
1395
|
-
const result = await kubb.generate().finally(unhook);
|
|
1374
|
+
const result = await kubb.generate();
|
|
1396
1375
|
if (!result.success) throw generationFailure(result.diagnostics);
|
|
1397
1376
|
const { storage, root } = kubb.config;
|
|
1398
1377
|
return {
|
|
@@ -1402,7 +1381,7 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1402
1381
|
root,
|
|
1403
1382
|
filePath: file.path
|
|
1404
1383
|
}))),
|
|
1405
|
-
input
|
|
1384
|
+
input: result.input
|
|
1406
1385
|
};
|
|
1407
1386
|
}
|
|
1408
1387
|
/**
|
|
@@ -1732,15 +1711,6 @@ function createGenerationStream(hooks, jobId) {
|
|
|
1732
1711
|
root = config.root;
|
|
1733
1712
|
});
|
|
1734
1713
|
for (const type of require_protocol.generationEventTypes) forward(type);
|
|
1735
|
-
on("kubb:generation:end", ({ diagnostics = [], status, hrStart, filesCreated }) => {
|
|
1736
|
-
if (!hrStart) return;
|
|
1737
|
-
emitEvent("kubb:generation:summary", [{
|
|
1738
|
-
duration: Math.round(getElapsedMs(hrStart)),
|
|
1739
|
-
fileCount: filesCreated ?? 0,
|
|
1740
|
-
failedPlugins: _kubb_core.Diagnostics.failedPlugins(diagnostics).length,
|
|
1741
|
-
status: status ?? "success"
|
|
1742
|
-
}]);
|
|
1743
|
-
});
|
|
1744
1714
|
/**
|
|
1745
1715
|
* Takes this generation's listeners off the session emitter. Safe to call twice.
|
|
1746
1716
|
*/
|
|
@@ -3503,25 +3473,50 @@ async function createSnapshotPackage({ files, packageInfo }) {
|
|
|
3503
3473
|
*
|
|
3504
3474
|
* @example
|
|
3505
3475
|
* ```ts
|
|
3506
|
-
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!,
|
|
3476
|
+
* 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' })
|
|
3507
3477
|
* ```
|
|
3508
3478
|
*/
|
|
3509
|
-
async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey,
|
|
3479
|
+
async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, configs, hooks, signal, ...metadata }) {
|
|
3510
3480
|
const url = secureUrl({
|
|
3511
3481
|
studioUrl,
|
|
3512
3482
|
path: "/api/snapshots"
|
|
3513
3483
|
});
|
|
3514
|
-
const
|
|
3515
|
-
config
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3484
|
+
const buildConfigs = configs.map((config) => ({
|
|
3485
|
+
...config,
|
|
3486
|
+
storage: (0, _kubb_core.fsStorage)()
|
|
3487
|
+
}));
|
|
3488
|
+
const failures = [];
|
|
3489
|
+
const sources = /* @__PURE__ */ new Map();
|
|
3490
|
+
for await (const { success, error, diagnostics, files, kubb } of _kubb_core.Kubb.generate(buildConfigs, {
|
|
3519
3491
|
hooks,
|
|
3520
|
-
signal
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3492
|
+
signal
|
|
3493
|
+
})) {
|
|
3494
|
+
if (!success) {
|
|
3495
|
+
failures.push(error ?? generationFailure(diagnostics));
|
|
3496
|
+
continue;
|
|
3497
|
+
}
|
|
3498
|
+
const { root } = kubb.config;
|
|
3499
|
+
for (const file of files) {
|
|
3500
|
+
const path = relativeStoragePath({
|
|
3501
|
+
root,
|
|
3502
|
+
filePath: file.path
|
|
3503
|
+
});
|
|
3504
|
+
const source = (0, node_path.resolve)(root, path);
|
|
3505
|
+
const owner = sources.get(path);
|
|
3506
|
+
if (owner && owner !== source) throw new _kubb_core.Diagnostics.Error({
|
|
3507
|
+
code: _kubb_core.Diagnostics.code.unknown,
|
|
3508
|
+
severity: "error",
|
|
3509
|
+
message: `Snapshot has two generated files at "${path}": "${owner}" and "${source}"`,
|
|
3510
|
+
help: "Give the config entries the same `root`, or output paths that do not overlap."
|
|
3511
|
+
});
|
|
3512
|
+
sources.set(path, source);
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
if (failures.length === 1) throw failures[0];
|
|
3516
|
+
if (failures.length) throw new AggregateError(failures, failures.map(getErrorMessage).join("\n"));
|
|
3517
|
+
const storage = (0, _kubb_core.fsStorage)();
|
|
3518
|
+
const files = Object.fromEntries(await Promise.all([...sources].map(async ([path, source]) => {
|
|
3519
|
+
const content = await storage.readItem(source);
|
|
3525
3520
|
if (content === null) throw new _kubb_core.Diagnostics.Error({
|
|
3526
3521
|
code: _kubb_core.Diagnostics.code.internalError,
|
|
3527
3522
|
severity: "error",
|
|
@@ -3529,12 +3524,13 @@ async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, config, ho
|
|
|
3529
3524
|
});
|
|
3530
3525
|
return [path, content];
|
|
3531
3526
|
})));
|
|
3532
|
-
const pluginNames = config.plugins.map((plugin) => (0, _kubb_core.resolveMeta)(plugin).name);
|
|
3533
|
-
const
|
|
3534
|
-
|
|
3527
|
+
const pluginNames = [...new Set(configs.flatMap((config) => config.plugins.map((plugin) => (0, _kubb_core.resolveMeta)(plugin).name)))];
|
|
3528
|
+
const roots = [...new Set(configs.map((config) => config.root))];
|
|
3529
|
+
const installed = (await Promise.all(roots.map((root) => (0, _kubb_core.readInstalledPackages)({
|
|
3530
|
+
root,
|
|
3535
3531
|
packages: pluginNames.map(toPackageName),
|
|
3536
3532
|
resolveFrom: ["kubb"]
|
|
3537
|
-
});
|
|
3533
|
+
})))).flat();
|
|
3538
3534
|
const packageOf = (name) => installed.find(({ manifest }) => manifest?.kind === "plugin" && manifest.name === name)?.package ?? toPackageName(name);
|
|
3539
3535
|
const names = [...new Set(pluginNames.map(packageOf))];
|
|
3540
3536
|
const peerDependencies = Object.fromEntries(installed.flatMap(({ package: name, version }) => names.includes(name) && version ? [[name, version]] : []));
|