@kubb/studio 5.18.6 → 5.18.8
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 +83 -52
- 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 +89 -58
- 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
|
@@ -155,7 +155,7 @@ function detect() {
|
|
|
155
155
|
*/
|
|
156
156
|
async function read(path) {
|
|
157
157
|
if (runtime.isBun) return Bun.file(path).text();
|
|
158
|
-
return (0,
|
|
158
|
+
return new Promise((resolvePromise, reject) => (0, node_fs.readFile)(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Writes UTF-8 content verbatim, including empty files and surrounding whitespace.
|
|
@@ -171,11 +171,11 @@ async function writeRaw(path, content) {
|
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
try {
|
|
174
|
-
await (0,
|
|
174
|
+
await new Promise((resolvePromise, reject) => (0, node_fs.writeFile)(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
|
|
175
175
|
} catch (error) {
|
|
176
176
|
if (error.code !== "ENOENT") throw error;
|
|
177
177
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
|
|
178
|
-
await (0,
|
|
178
|
+
await new Promise((resolvePromise, reject) => (0, node_fs.writeFile)(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
@@ -201,6 +201,41 @@ function isPathInside(path, parent) {
|
|
|
201
201
|
}
|
|
202
202
|
// ../../internals/utils/src/promise.ts
|
|
203
203
|
/**
|
|
204
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
205
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
206
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
210
|
+
*/
|
|
211
|
+
function memo(store, key, compute) {
|
|
212
|
+
const cached = store.get(key);
|
|
213
|
+
if (cached !== void 0 || store.has(key)) return cached;
|
|
214
|
+
const value = compute();
|
|
215
|
+
store.set(key, value);
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
function createStore({ type }) {
|
|
219
|
+
if (type === "weak") return /* @__PURE__ */ new WeakMap();
|
|
220
|
+
const entry = /* @__PURE__ */ new Map();
|
|
221
|
+
if (type === "map") return entry;
|
|
222
|
+
const set = (key, value) => {
|
|
223
|
+
entry.clear();
|
|
224
|
+
entry.set(key, value);
|
|
225
|
+
};
|
|
226
|
+
const touch = (key) => {
|
|
227
|
+
if (!entry.has(key)) return false;
|
|
228
|
+
set(key, entry.get(key));
|
|
229
|
+
return true;
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
has: touch,
|
|
233
|
+
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
234
|
+
set
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
memo.create = createStore;
|
|
238
|
+
/**
|
|
204
239
|
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
205
240
|
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
206
241
|
*
|
|
@@ -216,25 +251,8 @@ async function inParallel({ items, limit, run }) {
|
|
|
216
251
|
};
|
|
217
252
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
218
253
|
}
|
|
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
254
|
// package.json
|
|
237
|
-
var version = "5.18.
|
|
255
|
+
var version = "5.18.8";
|
|
238
256
|
// ../../internals/shared/src/constants.ts
|
|
239
257
|
/**
|
|
240
258
|
* Extensions `kubb` ships at its own version, so they count as installed without being a direct
|
|
@@ -1388,11 +1406,7 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1388
1406
|
hooks,
|
|
1389
1407
|
signal
|
|
1390
1408
|
});
|
|
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);
|
|
1409
|
+
const result = await kubb.generate();
|
|
1396
1410
|
if (!result.success) throw generationFailure(result.diagnostics);
|
|
1397
1411
|
const { storage, root } = kubb.config;
|
|
1398
1412
|
return {
|
|
@@ -1402,7 +1416,7 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1402
1416
|
root,
|
|
1403
1417
|
filePath: file.path
|
|
1404
1418
|
}))),
|
|
1405
|
-
input
|
|
1419
|
+
input: result.input
|
|
1406
1420
|
};
|
|
1407
1421
|
}
|
|
1408
1422
|
/**
|
|
@@ -1732,15 +1746,6 @@ function createGenerationStream(hooks, jobId) {
|
|
|
1732
1746
|
root = config.root;
|
|
1733
1747
|
});
|
|
1734
1748
|
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
1749
|
/**
|
|
1745
1750
|
* Takes this generation's listeners off the session emitter. Safe to call twice.
|
|
1746
1751
|
*/
|
|
@@ -3503,25 +3508,50 @@ async function createSnapshotPackage({ files, packageInfo }) {
|
|
|
3503
3508
|
*
|
|
3504
3509
|
* @example
|
|
3505
3510
|
* ```ts
|
|
3506
|
-
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!,
|
|
3511
|
+
* 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
3512
|
* ```
|
|
3508
3513
|
*/
|
|
3509
|
-
async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey,
|
|
3514
|
+
async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, configs, hooks, signal, ...metadata }) {
|
|
3510
3515
|
const url = secureUrl({
|
|
3511
3516
|
studioUrl,
|
|
3512
3517
|
path: "/api/snapshots"
|
|
3513
3518
|
});
|
|
3514
|
-
const
|
|
3515
|
-
config
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
+
const buildConfigs = configs.map((config) => ({
|
|
3520
|
+
...config,
|
|
3521
|
+
storage: (0, _kubb_core.fsStorage)()
|
|
3522
|
+
}));
|
|
3523
|
+
const failures = [];
|
|
3524
|
+
const sources = /* @__PURE__ */ new Map();
|
|
3525
|
+
for await (const { success, error, diagnostics, files, kubb } of _kubb_core.Kubb.generate(buildConfigs, {
|
|
3519
3526
|
hooks,
|
|
3520
|
-
signal
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3527
|
+
signal
|
|
3528
|
+
})) {
|
|
3529
|
+
if (!success) {
|
|
3530
|
+
failures.push(error ?? generationFailure(diagnostics));
|
|
3531
|
+
continue;
|
|
3532
|
+
}
|
|
3533
|
+
const { root } = kubb.config;
|
|
3534
|
+
for (const file of files) {
|
|
3535
|
+
const path = relativeStoragePath({
|
|
3536
|
+
root,
|
|
3537
|
+
filePath: file.path
|
|
3538
|
+
});
|
|
3539
|
+
const source = (0, node_path.resolve)(root, path);
|
|
3540
|
+
const owner = sources.get(path);
|
|
3541
|
+
if (owner && owner !== source) throw new _kubb_core.Diagnostics.Error({
|
|
3542
|
+
code: _kubb_core.Diagnostics.code.unknown,
|
|
3543
|
+
severity: "error",
|
|
3544
|
+
message: `Snapshot has two generated files at "${path}": "${owner}" and "${source}"`,
|
|
3545
|
+
help: "Give the config entries the same `root`, or output paths that do not overlap."
|
|
3546
|
+
});
|
|
3547
|
+
sources.set(path, source);
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
if (failures.length === 1) throw failures[0];
|
|
3551
|
+
if (failures.length) throw new AggregateError(failures, failures.map(getErrorMessage).join("\n"));
|
|
3552
|
+
const storage = (0, _kubb_core.fsStorage)();
|
|
3553
|
+
const files = Object.fromEntries(await Promise.all([...sources].map(async ([path, source]) => {
|
|
3554
|
+
const content = await storage.readItem(source);
|
|
3525
3555
|
if (content === null) throw new _kubb_core.Diagnostics.Error({
|
|
3526
3556
|
code: _kubb_core.Diagnostics.code.internalError,
|
|
3527
3557
|
severity: "error",
|
|
@@ -3529,12 +3559,13 @@ async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, config, ho
|
|
|
3529
3559
|
});
|
|
3530
3560
|
return [path, content];
|
|
3531
3561
|
})));
|
|
3532
|
-
const pluginNames = config.plugins.map((plugin) => (0, _kubb_core.resolveMeta)(plugin).name);
|
|
3533
|
-
const
|
|
3534
|
-
|
|
3562
|
+
const pluginNames = [...new Set(configs.flatMap((config) => config.plugins.map((plugin) => (0, _kubb_core.resolveMeta)(plugin).name)))];
|
|
3563
|
+
const roots = [...new Set(configs.map((config) => config.root))];
|
|
3564
|
+
const installed = (await Promise.all(roots.map((root) => (0, _kubb_core.readInstalledPackages)({
|
|
3565
|
+
root,
|
|
3535
3566
|
packages: pluginNames.map(toPackageName),
|
|
3536
3567
|
resolveFrom: ["kubb"]
|
|
3537
|
-
});
|
|
3568
|
+
})))).flat();
|
|
3538
3569
|
const packageOf = (name) => installed.find(({ manifest }) => manifest?.kind === "plugin" && manifest.name === name)?.package ?? toPackageName(name);
|
|
3539
3570
|
const names = [...new Set(pluginNames.map(packageOf))];
|
|
3540
3571
|
const peerDependencies = Object.fromEntries(installed.flatMap(({ package: name, version }) => names.includes(name) && version ? [[name, version]] : []));
|