@kubb/core 5.0.0-alpha.43 → 5.0.0-alpha.44
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/{PluginDriver-CgXFtmNP.js → PluginDriver-Bt_UCn7-.js} +88 -739
- package/dist/PluginDriver-Bt_UCn7-.js.map +1 -0
- package/dist/{PluginDriver-BQwm8hDd.cjs → PluginDriver-rVSfG8tW.cjs} +91 -751
- package/dist/PluginDriver-rVSfG8tW.cjs.map +1 -0
- package/dist/index.cjs +185 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +186 -14
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +5 -33
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +5 -5
- package/dist/mocks.js +5 -33
- package/dist/mocks.js.map +1 -1
- package/dist/{types-BJX_uR-y.d.ts → types-BUgxQiWY.d.ts} +72 -500
- package/package.json +4 -4
- package/src/FileManager.ts +20 -21
- package/src/FileProcessor.ts +2 -0
- package/src/Kubb.ts +3 -47
- package/src/PluginDriver.ts +53 -578
- package/src/constants.ts +9 -1
- package/src/createKubb.ts +6 -16
- package/src/definePlugin.ts +12 -34
- package/src/defineResolver.ts +23 -8
- package/src/mocks.ts +10 -84
- package/src/types.ts +40 -342
- package/src/utils/getBarrelFiles.ts +9 -3
- package/dist/PluginDriver-BQwm8hDd.cjs.map +0 -1
- package/dist/PluginDriver-CgXFtmNP.js.map +0 -1
- package/src/createPlugin.ts +0 -31
- package/src/utils/executeStrategies.ts +0 -84
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { c as DEFAULT_EXTENSION, d as camelCase, i as defineResolver, l as DEFAULT_STUDIO_URL, n as applyHookResult, o as BARREL_FILENAME, r as FileManager, s as DEFAULT_BANNER, t as PluginDriver, u as logLevel } from "./PluginDriver-Bt_UCn7-.js";
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
4
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import path, { dirname, join, posix, resolve } from "node:path";
|
|
@@ -268,6 +268,26 @@ async function clean(path) {
|
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
//#endregion
|
|
271
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
272
|
+
/**
|
|
273
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* isValidVarName('status') // true
|
|
278
|
+
* isValidVarName('class') // false (reserved word)
|
|
279
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
function isValidVarName(name) {
|
|
283
|
+
try {
|
|
284
|
+
new Function(`var ${name}`);
|
|
285
|
+
} catch {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
271
291
|
//#region ../../internals/utils/src/urlPath.ts
|
|
272
292
|
/**
|
|
273
293
|
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
@@ -434,6 +454,136 @@ function createAdapter(build) {
|
|
|
434
454
|
return (options) => build(options ?? {});
|
|
435
455
|
}
|
|
436
456
|
//#endregion
|
|
457
|
+
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
458
|
+
var Node$1 = class {
|
|
459
|
+
static {
|
|
460
|
+
__name(this, "Node");
|
|
461
|
+
}
|
|
462
|
+
value;
|
|
463
|
+
next;
|
|
464
|
+
constructor(value) {
|
|
465
|
+
this.value = value;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
var Queue = class {
|
|
469
|
+
#head;
|
|
470
|
+
#tail;
|
|
471
|
+
#size;
|
|
472
|
+
constructor() {
|
|
473
|
+
this.clear();
|
|
474
|
+
}
|
|
475
|
+
enqueue(value) {
|
|
476
|
+
const node = new Node$1(value);
|
|
477
|
+
if (this.#head) {
|
|
478
|
+
this.#tail.next = node;
|
|
479
|
+
this.#tail = node;
|
|
480
|
+
} else {
|
|
481
|
+
this.#head = node;
|
|
482
|
+
this.#tail = node;
|
|
483
|
+
}
|
|
484
|
+
this.#size++;
|
|
485
|
+
}
|
|
486
|
+
dequeue() {
|
|
487
|
+
const current = this.#head;
|
|
488
|
+
if (!current) return;
|
|
489
|
+
this.#head = this.#head.next;
|
|
490
|
+
this.#size--;
|
|
491
|
+
if (!this.#head) this.#tail = void 0;
|
|
492
|
+
return current.value;
|
|
493
|
+
}
|
|
494
|
+
peek() {
|
|
495
|
+
if (!this.#head) return;
|
|
496
|
+
return this.#head.value;
|
|
497
|
+
}
|
|
498
|
+
clear() {
|
|
499
|
+
this.#head = void 0;
|
|
500
|
+
this.#tail = void 0;
|
|
501
|
+
this.#size = 0;
|
|
502
|
+
}
|
|
503
|
+
get size() {
|
|
504
|
+
return this.#size;
|
|
505
|
+
}
|
|
506
|
+
*[Symbol.iterator]() {
|
|
507
|
+
let current = this.#head;
|
|
508
|
+
while (current) {
|
|
509
|
+
yield current.value;
|
|
510
|
+
current = current.next;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
*drain() {
|
|
514
|
+
while (this.#head) yield this.dequeue();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region ../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js
|
|
519
|
+
function pLimit(concurrency) {
|
|
520
|
+
let rejectOnClear = false;
|
|
521
|
+
if (typeof concurrency === "object") ({concurrency, rejectOnClear = false} = concurrency);
|
|
522
|
+
validateConcurrency(concurrency);
|
|
523
|
+
if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
|
|
524
|
+
const queue = new Queue();
|
|
525
|
+
let activeCount = 0;
|
|
526
|
+
const resumeNext = () => {
|
|
527
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
528
|
+
activeCount++;
|
|
529
|
+
queue.dequeue().run();
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
const next = () => {
|
|
533
|
+
activeCount--;
|
|
534
|
+
resumeNext();
|
|
535
|
+
};
|
|
536
|
+
const run = async (function_, resolve, arguments_) => {
|
|
537
|
+
const result = (async () => function_(...arguments_))();
|
|
538
|
+
resolve(result);
|
|
539
|
+
try {
|
|
540
|
+
await result;
|
|
541
|
+
} catch {}
|
|
542
|
+
next();
|
|
543
|
+
};
|
|
544
|
+
const enqueue = (function_, resolve, reject, arguments_) => {
|
|
545
|
+
const queueItem = { reject };
|
|
546
|
+
new Promise((internalResolve) => {
|
|
547
|
+
queueItem.run = internalResolve;
|
|
548
|
+
queue.enqueue(queueItem);
|
|
549
|
+
}).then(run.bind(void 0, function_, resolve, arguments_));
|
|
550
|
+
if (activeCount < concurrency) resumeNext();
|
|
551
|
+
};
|
|
552
|
+
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
|
553
|
+
enqueue(function_, resolve, reject, arguments_);
|
|
554
|
+
});
|
|
555
|
+
Object.defineProperties(generator, {
|
|
556
|
+
activeCount: { get: () => activeCount },
|
|
557
|
+
pendingCount: { get: () => queue.size },
|
|
558
|
+
clearQueue: { value() {
|
|
559
|
+
if (!rejectOnClear) {
|
|
560
|
+
queue.clear();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const abortError = AbortSignal.abort().reason;
|
|
564
|
+
while (queue.size > 0) queue.dequeue().reject(abortError);
|
|
565
|
+
} },
|
|
566
|
+
concurrency: {
|
|
567
|
+
get: () => concurrency,
|
|
568
|
+
set(newConcurrency) {
|
|
569
|
+
validateConcurrency(newConcurrency);
|
|
570
|
+
concurrency = newConcurrency;
|
|
571
|
+
queueMicrotask(() => {
|
|
572
|
+
while (activeCount < concurrency && queue.size > 0) resumeNext();
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
map: { async value(iterable, function_) {
|
|
577
|
+
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
578
|
+
return Promise.all(promises);
|
|
579
|
+
} }
|
|
580
|
+
});
|
|
581
|
+
return generator;
|
|
582
|
+
}
|
|
583
|
+
function validateConcurrency(concurrency) {
|
|
584
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
585
|
+
}
|
|
586
|
+
//#endregion
|
|
437
587
|
//#region src/FileProcessor.ts
|
|
438
588
|
function joinSources(file) {
|
|
439
589
|
return file.sources.map((item) => extractStringsFromNodes(item.nodes)).filter(Boolean).join("\n\n");
|
|
@@ -441,6 +591,8 @@ function joinSources(file) {
|
|
|
441
591
|
/**
|
|
442
592
|
* Converts a single file to a string using the registered parsers.
|
|
443
593
|
* Falls back to joining source values when no matching parser is found.
|
|
594
|
+
*
|
|
595
|
+
* @internal
|
|
444
596
|
*/
|
|
445
597
|
var FileProcessor = class {
|
|
446
598
|
#limit = pLimit(100);
|
|
@@ -585,7 +737,7 @@ const fsStorage = createStorage(() => ({
|
|
|
585
737
|
}));
|
|
586
738
|
//#endregion
|
|
587
739
|
//#region package.json
|
|
588
|
-
var version$1 = "5.0.0-alpha.
|
|
740
|
+
var version$1 = "5.0.0-alpha.44";
|
|
589
741
|
//#endregion
|
|
590
742
|
//#region src/utils/diagnostics.ts
|
|
591
743
|
/**
|
|
@@ -769,8 +921,8 @@ function getBarrelFilesByRoot(root, files) {
|
|
|
769
921
|
TreeNode.build(files, root)?.forEach((treeNode) => {
|
|
770
922
|
if (!treeNode?.children || !treeNode.parent?.data.path) return;
|
|
771
923
|
const barrelFile = createFile({
|
|
772
|
-
path: join(treeNode.parent?.data.path,
|
|
773
|
-
baseName:
|
|
924
|
+
path: join(treeNode.parent?.data.path, BARREL_FILENAME),
|
|
925
|
+
baseName: BARREL_FILENAME,
|
|
774
926
|
exports: [],
|
|
775
927
|
imports: [],
|
|
776
928
|
sources: []
|
|
@@ -906,10 +1058,7 @@ async function setup(userConfig, options = {}) {
|
|
|
906
1058
|
});
|
|
907
1059
|
await storage?.clear(resolve(config.root, config.output.path));
|
|
908
1060
|
}
|
|
909
|
-
const driver = new PluginDriver(config, {
|
|
910
|
-
hooks,
|
|
911
|
-
concurrency: 15
|
|
912
|
-
});
|
|
1061
|
+
const driver = new PluginDriver(config, { hooks });
|
|
913
1062
|
const adapter = config.adapter;
|
|
914
1063
|
if (!adapter) throw new Error("No adapter configured. Please provide an adapter in your kubb.config.ts.");
|
|
915
1064
|
const source = inputToAdapterSource(config);
|
|
@@ -1032,7 +1181,6 @@ async function safeBuild(setupResult) {
|
|
|
1032
1181
|
date: timestamp,
|
|
1033
1182
|
logs: ["Starting plugin...", ` • Plugin Name: ${plugin.name}`]
|
|
1034
1183
|
});
|
|
1035
|
-
await plugin.buildStart.call(context);
|
|
1036
1184
|
if (plugin.generators?.length || driver.hasRegisteredGenerators(plugin.name)) await runPluginAstHooks(plugin, context);
|
|
1037
1185
|
if (output) {
|
|
1038
1186
|
const barrelFiles = await getBarrelFiles(driver.fileManager.files, {
|
|
@@ -1153,10 +1301,6 @@ async function safeBuild(setupResult) {
|
|
|
1153
1301
|
});
|
|
1154
1302
|
}
|
|
1155
1303
|
});
|
|
1156
|
-
for (const plugin of driver.plugins.values()) if (plugin.buildEnd) {
|
|
1157
|
-
const context = driver.getContext(plugin);
|
|
1158
|
-
await plugin.buildEnd.call(context);
|
|
1159
|
-
}
|
|
1160
1304
|
await hooks.emit("kubb:build:end", {
|
|
1161
1305
|
files,
|
|
1162
1306
|
config,
|
|
@@ -1371,6 +1515,34 @@ function defineParser(parser) {
|
|
|
1371
1515
|
return parser;
|
|
1372
1516
|
}
|
|
1373
1517
|
//#endregion
|
|
1518
|
+
//#region src/definePlugin.ts
|
|
1519
|
+
/**
|
|
1520
|
+
* Creates a plugin factory using the hook-style (`hooks:`) API.
|
|
1521
|
+
*
|
|
1522
|
+
* The returned factory is called with optional options and produces a `Plugin`
|
|
1523
|
+
* that coexists with plugins created via the legacy `createPlugin` API in the same
|
|
1524
|
+
* `kubb.config.ts`.
|
|
1525
|
+
*
|
|
1526
|
+
* Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
|
|
1527
|
+
* both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
|
|
1528
|
+
*
|
|
1529
|
+
* @example
|
|
1530
|
+
* ```ts
|
|
1531
|
+
* // With PluginFactoryOptions (recommended for real plugins)
|
|
1532
|
+
* export const pluginTs = definePlugin<PluginTs>((options) => ({
|
|
1533
|
+
* name: 'plugin-ts',
|
|
1534
|
+
* hooks: {
|
|
1535
|
+
* 'kubb:plugin:setup'(ctx) {
|
|
1536
|
+
* ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
|
|
1537
|
+
* },
|
|
1538
|
+
* },
|
|
1539
|
+
* }))
|
|
1540
|
+
* ```
|
|
1541
|
+
*/
|
|
1542
|
+
function definePlugin(factory) {
|
|
1543
|
+
return (options) => factory(options ?? {});
|
|
1544
|
+
}
|
|
1545
|
+
//#endregion
|
|
1374
1546
|
//#region src/storages/memoryStorage.ts
|
|
1375
1547
|
/**
|
|
1376
1548
|
* In-memory storage driver. Useful for testing and dry-run scenarios where
|