@kubb/core 5.0.0-alpha.35 → 5.0.0-alpha.36
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-B_65W4fv.js +1677 -0
- package/dist/PluginDriver-B_65W4fv.js.map +1 -0
- package/dist/{PluginDriver-D8lWvtUg.d.ts → PluginDriver-C9iBgYbk.d.ts} +3 -4
- package/dist/PluginDriver-CCdkwR14.cjs +1806 -0
- package/dist/PluginDriver-CCdkwR14.cjs.map +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +31 -1696
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -2
- package/dist/index.js +6 -1676
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +165 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +11 -4
- package/src/index.ts +2 -0
- package/src/mocks.ts +234 -0
- package/src/types.ts +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
3
|
+
const require_PluginDriver = require("./PluginDriver-CCdkwR14.cjs");
|
|
3
4
|
let node_events = require("node:events");
|
|
4
5
|
let node_fs = require("node:fs");
|
|
5
6
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -7,8 +8,6 @@ let node_path = require("node:path");
|
|
|
7
8
|
node_path = require_chunk.__toESM(node_path, 1);
|
|
8
9
|
let _kubb_ast = require("@kubb/ast");
|
|
9
10
|
_kubb_ast = require_chunk.__toESM(_kubb_ast, 1);
|
|
10
|
-
let node_perf_hooks = require("node:perf_hooks");
|
|
11
|
-
let fflate = require("fflate");
|
|
12
11
|
let tinyexec = require("tinyexec");
|
|
13
12
|
let node_process = require("node:process");
|
|
14
13
|
let remeda = require("remeda");
|
|
@@ -153,64 +152,6 @@ var AsyncEventEmitter = class {
|
|
|
153
152
|
}
|
|
154
153
|
};
|
|
155
154
|
//#endregion
|
|
156
|
-
//#region ../../internals/utils/src/casing.ts
|
|
157
|
-
/**
|
|
158
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
159
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
160
|
-
* and capitalizes each word according to `pascal`.
|
|
161
|
-
*
|
|
162
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
163
|
-
*/
|
|
164
|
-
function toCamelOrPascal(text, pascal) {
|
|
165
|
-
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
166
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
167
|
-
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
168
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
169
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
173
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
174
|
-
* Segments are joined with `/` to form a file path.
|
|
175
|
-
*
|
|
176
|
-
* Only splits on dots followed by a letter so that version numbers
|
|
177
|
-
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
178
|
-
*/
|
|
179
|
-
function applyToFileParts(text, transformPart) {
|
|
180
|
-
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
181
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Converts `text` to camelCase.
|
|
185
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* camelCase('hello-world') // 'helloWorld'
|
|
189
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
190
|
-
*/
|
|
191
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
192
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
193
|
-
prefix,
|
|
194
|
-
suffix
|
|
195
|
-
} : {}));
|
|
196
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Converts `text` to PascalCase.
|
|
200
|
-
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* pascalCase('hello-world') // 'HelloWorld'
|
|
204
|
-
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
205
|
-
*/
|
|
206
|
-
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
207
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
208
|
-
prefix,
|
|
209
|
-
suffix
|
|
210
|
-
}) : camelCase(part));
|
|
211
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
212
|
-
}
|
|
213
|
-
//#endregion
|
|
214
155
|
//#region ../../internals/utils/src/time.ts
|
|
215
156
|
/**
|
|
216
157
|
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
@@ -364,159 +305,6 @@ async function clean(path) {
|
|
|
364
305
|
});
|
|
365
306
|
}
|
|
366
307
|
//#endregion
|
|
367
|
-
//#region ../../internals/utils/src/string.ts
|
|
368
|
-
/**
|
|
369
|
-
* Strips the file extension from a path or file name.
|
|
370
|
-
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
371
|
-
*
|
|
372
|
-
* @example
|
|
373
|
-
* trimExtName('petStore.ts') // 'petStore'
|
|
374
|
-
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
375
|
-
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
376
|
-
* trimExtName('noExtension') // 'noExtension'
|
|
377
|
-
*/
|
|
378
|
-
function trimExtName$1(text) {
|
|
379
|
-
const dotIndex = text.lastIndexOf(".");
|
|
380
|
-
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
381
|
-
return text;
|
|
382
|
-
}
|
|
383
|
-
require_chunk.__name(trimExtName$1, "trimExtName");
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region ../../internals/utils/src/promise.ts
|
|
386
|
-
/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* ```ts
|
|
390
|
-
* const results = await Promise.allSettled([p1, p2])
|
|
391
|
-
* results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)
|
|
392
|
-
* ```
|
|
393
|
-
*/
|
|
394
|
-
function isPromiseRejectedResult(result) {
|
|
395
|
-
return result.status === "rejected";
|
|
396
|
-
}
|
|
397
|
-
//#endregion
|
|
398
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
399
|
-
/**
|
|
400
|
-
* JavaScript and Java reserved words.
|
|
401
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
402
|
-
*/
|
|
403
|
-
const reservedWords = new Set([
|
|
404
|
-
"abstract",
|
|
405
|
-
"arguments",
|
|
406
|
-
"boolean",
|
|
407
|
-
"break",
|
|
408
|
-
"byte",
|
|
409
|
-
"case",
|
|
410
|
-
"catch",
|
|
411
|
-
"char",
|
|
412
|
-
"class",
|
|
413
|
-
"const",
|
|
414
|
-
"continue",
|
|
415
|
-
"debugger",
|
|
416
|
-
"default",
|
|
417
|
-
"delete",
|
|
418
|
-
"do",
|
|
419
|
-
"double",
|
|
420
|
-
"else",
|
|
421
|
-
"enum",
|
|
422
|
-
"eval",
|
|
423
|
-
"export",
|
|
424
|
-
"extends",
|
|
425
|
-
"false",
|
|
426
|
-
"final",
|
|
427
|
-
"finally",
|
|
428
|
-
"float",
|
|
429
|
-
"for",
|
|
430
|
-
"function",
|
|
431
|
-
"goto",
|
|
432
|
-
"if",
|
|
433
|
-
"implements",
|
|
434
|
-
"import",
|
|
435
|
-
"in",
|
|
436
|
-
"instanceof",
|
|
437
|
-
"int",
|
|
438
|
-
"interface",
|
|
439
|
-
"let",
|
|
440
|
-
"long",
|
|
441
|
-
"native",
|
|
442
|
-
"new",
|
|
443
|
-
"null",
|
|
444
|
-
"package",
|
|
445
|
-
"private",
|
|
446
|
-
"protected",
|
|
447
|
-
"public",
|
|
448
|
-
"return",
|
|
449
|
-
"short",
|
|
450
|
-
"static",
|
|
451
|
-
"super",
|
|
452
|
-
"switch",
|
|
453
|
-
"synchronized",
|
|
454
|
-
"this",
|
|
455
|
-
"throw",
|
|
456
|
-
"throws",
|
|
457
|
-
"transient",
|
|
458
|
-
"true",
|
|
459
|
-
"try",
|
|
460
|
-
"typeof",
|
|
461
|
-
"var",
|
|
462
|
-
"void",
|
|
463
|
-
"volatile",
|
|
464
|
-
"while",
|
|
465
|
-
"with",
|
|
466
|
-
"yield",
|
|
467
|
-
"Array",
|
|
468
|
-
"Date",
|
|
469
|
-
"hasOwnProperty",
|
|
470
|
-
"Infinity",
|
|
471
|
-
"isFinite",
|
|
472
|
-
"isNaN",
|
|
473
|
-
"isPrototypeOf",
|
|
474
|
-
"length",
|
|
475
|
-
"Math",
|
|
476
|
-
"name",
|
|
477
|
-
"NaN",
|
|
478
|
-
"Number",
|
|
479
|
-
"Object",
|
|
480
|
-
"prototype",
|
|
481
|
-
"String",
|
|
482
|
-
"toString",
|
|
483
|
-
"undefined",
|
|
484
|
-
"valueOf"
|
|
485
|
-
]);
|
|
486
|
-
/**
|
|
487
|
-
* Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```ts
|
|
491
|
-
* transformReservedWord('class') // '_class'
|
|
492
|
-
* transformReservedWord('42foo') // '_42foo'
|
|
493
|
-
* transformReservedWord('status') // 'status'
|
|
494
|
-
* ```
|
|
495
|
-
*/
|
|
496
|
-
function transformReservedWord(word) {
|
|
497
|
-
const firstChar = word.charCodeAt(0);
|
|
498
|
-
if (word && (reservedWords.has(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
|
|
499
|
-
return word;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
503
|
-
*
|
|
504
|
-
* @example
|
|
505
|
-
* ```ts
|
|
506
|
-
* isValidVarName('status') // true
|
|
507
|
-
* isValidVarName('class') // false (reserved word)
|
|
508
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
509
|
-
* ```
|
|
510
|
-
*/
|
|
511
|
-
function isValidVarName(name) {
|
|
512
|
-
try {
|
|
513
|
-
new Function(`var ${name}`);
|
|
514
|
-
} catch {
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
//#endregion
|
|
520
308
|
//#region ../../internals/utils/src/urlPath.ts
|
|
521
309
|
/**
|
|
522
310
|
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
@@ -594,8 +382,8 @@ var URLPath = class {
|
|
|
594
382
|
return this.getParams();
|
|
595
383
|
}
|
|
596
384
|
#transformParam(raw) {
|
|
597
|
-
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
598
|
-
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
385
|
+
const param = require_PluginDriver.isValidVarName(raw) ? raw : require_PluginDriver.camelCase(raw);
|
|
386
|
+
return this.#options.casing === "camelcase" ? require_PluginDriver.camelCase(param) : param;
|
|
599
387
|
}
|
|
600
388
|
/**
|
|
601
389
|
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
@@ -663,97 +451,6 @@ var URLPath = class {
|
|
|
663
451
|
}
|
|
664
452
|
};
|
|
665
453
|
//#endregion
|
|
666
|
-
//#region src/constants.ts
|
|
667
|
-
/**
|
|
668
|
-
* Base URL for the Kubb Studio web app.
|
|
669
|
-
*/
|
|
670
|
-
const DEFAULT_STUDIO_URL = "https://studio.kubb.dev";
|
|
671
|
-
/**
|
|
672
|
-
* File name used for generated barrel (index) files.
|
|
673
|
-
*/
|
|
674
|
-
const BARREL_FILENAME = "index.ts";
|
|
675
|
-
/**
|
|
676
|
-
* Default banner style written at the top of every generated file.
|
|
677
|
-
*/
|
|
678
|
-
const DEFAULT_BANNER = "simple";
|
|
679
|
-
/**
|
|
680
|
-
* Default file-extension mapping used when no explicit mapping is configured.
|
|
681
|
-
*/
|
|
682
|
-
const DEFAULT_EXTENSION = { ".ts": ".ts" };
|
|
683
|
-
/**
|
|
684
|
-
* Numeric log-level thresholds used internally to compare verbosity.
|
|
685
|
-
*
|
|
686
|
-
* Higher numbers are more verbose.
|
|
687
|
-
*/
|
|
688
|
-
const logLevel = {
|
|
689
|
-
silent: Number.NEGATIVE_INFINITY,
|
|
690
|
-
error: 0,
|
|
691
|
-
warn: 1,
|
|
692
|
-
info: 3,
|
|
693
|
-
verbose: 4,
|
|
694
|
-
debug: 5
|
|
695
|
-
};
|
|
696
|
-
/**
|
|
697
|
-
* CLI command descriptors for each supported linter.
|
|
698
|
-
*
|
|
699
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
700
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
701
|
-
* the linter is not found.
|
|
702
|
-
*/
|
|
703
|
-
const linters = {
|
|
704
|
-
eslint: {
|
|
705
|
-
command: "eslint",
|
|
706
|
-
args: (outputPath) => [outputPath, "--fix"],
|
|
707
|
-
errorMessage: "Eslint not found"
|
|
708
|
-
},
|
|
709
|
-
biome: {
|
|
710
|
-
command: "biome",
|
|
711
|
-
args: (outputPath) => [
|
|
712
|
-
"lint",
|
|
713
|
-
"--fix",
|
|
714
|
-
outputPath
|
|
715
|
-
],
|
|
716
|
-
errorMessage: "Biome not found"
|
|
717
|
-
},
|
|
718
|
-
oxlint: {
|
|
719
|
-
command: "oxlint",
|
|
720
|
-
args: (outputPath) => ["--fix", outputPath],
|
|
721
|
-
errorMessage: "Oxlint not found"
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
/**
|
|
725
|
-
* CLI command descriptors for each supported code formatter.
|
|
726
|
-
*
|
|
727
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
728
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
729
|
-
* the formatter is not found.
|
|
730
|
-
*/
|
|
731
|
-
const formatters = {
|
|
732
|
-
prettier: {
|
|
733
|
-
command: "prettier",
|
|
734
|
-
args: (outputPath) => [
|
|
735
|
-
"--ignore-unknown",
|
|
736
|
-
"--write",
|
|
737
|
-
outputPath
|
|
738
|
-
],
|
|
739
|
-
errorMessage: "Prettier not found"
|
|
740
|
-
},
|
|
741
|
-
biome: {
|
|
742
|
-
command: "biome",
|
|
743
|
-
args: (outputPath) => [
|
|
744
|
-
"format",
|
|
745
|
-
"--write",
|
|
746
|
-
outputPath
|
|
747
|
-
],
|
|
748
|
-
errorMessage: "Biome not found"
|
|
749
|
-
},
|
|
750
|
-
oxfmt: {
|
|
751
|
-
command: "oxfmt",
|
|
752
|
-
args: (outputPath) => [outputPath],
|
|
753
|
-
errorMessage: "Oxfmt not found"
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
//#endregion
|
|
757
454
|
//#region src/createAdapter.ts
|
|
758
455
|
/**
|
|
759
456
|
* Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
|
|
@@ -774,133 +471,6 @@ function createAdapter(build) {
|
|
|
774
471
|
return (options) => build(options ?? {});
|
|
775
472
|
}
|
|
776
473
|
//#endregion
|
|
777
|
-
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
778
|
-
var Node = class {
|
|
779
|
-
value;
|
|
780
|
-
next;
|
|
781
|
-
constructor(value) {
|
|
782
|
-
this.value = value;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
var Queue = class {
|
|
786
|
-
#head;
|
|
787
|
-
#tail;
|
|
788
|
-
#size;
|
|
789
|
-
constructor() {
|
|
790
|
-
this.clear();
|
|
791
|
-
}
|
|
792
|
-
enqueue(value) {
|
|
793
|
-
const node = new Node(value);
|
|
794
|
-
if (this.#head) {
|
|
795
|
-
this.#tail.next = node;
|
|
796
|
-
this.#tail = node;
|
|
797
|
-
} else {
|
|
798
|
-
this.#head = node;
|
|
799
|
-
this.#tail = node;
|
|
800
|
-
}
|
|
801
|
-
this.#size++;
|
|
802
|
-
}
|
|
803
|
-
dequeue() {
|
|
804
|
-
const current = this.#head;
|
|
805
|
-
if (!current) return;
|
|
806
|
-
this.#head = this.#head.next;
|
|
807
|
-
this.#size--;
|
|
808
|
-
if (!this.#head) this.#tail = void 0;
|
|
809
|
-
return current.value;
|
|
810
|
-
}
|
|
811
|
-
peek() {
|
|
812
|
-
if (!this.#head) return;
|
|
813
|
-
return this.#head.value;
|
|
814
|
-
}
|
|
815
|
-
clear() {
|
|
816
|
-
this.#head = void 0;
|
|
817
|
-
this.#tail = void 0;
|
|
818
|
-
this.#size = 0;
|
|
819
|
-
}
|
|
820
|
-
get size() {
|
|
821
|
-
return this.#size;
|
|
822
|
-
}
|
|
823
|
-
*[Symbol.iterator]() {
|
|
824
|
-
let current = this.#head;
|
|
825
|
-
while (current) {
|
|
826
|
-
yield current.value;
|
|
827
|
-
current = current.next;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
*drain() {
|
|
831
|
-
while (this.#head) yield this.dequeue();
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
//#endregion
|
|
835
|
-
//#region ../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js
|
|
836
|
-
function pLimit(concurrency) {
|
|
837
|
-
let rejectOnClear = false;
|
|
838
|
-
if (typeof concurrency === "object") ({concurrency, rejectOnClear = false} = concurrency);
|
|
839
|
-
validateConcurrency(concurrency);
|
|
840
|
-
if (typeof rejectOnClear !== "boolean") throw new TypeError("Expected `rejectOnClear` to be a boolean");
|
|
841
|
-
const queue = new Queue();
|
|
842
|
-
let activeCount = 0;
|
|
843
|
-
const resumeNext = () => {
|
|
844
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
845
|
-
activeCount++;
|
|
846
|
-
queue.dequeue().run();
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
const next = () => {
|
|
850
|
-
activeCount--;
|
|
851
|
-
resumeNext();
|
|
852
|
-
};
|
|
853
|
-
const run = async (function_, resolve, arguments_) => {
|
|
854
|
-
const result = (async () => function_(...arguments_))();
|
|
855
|
-
resolve(result);
|
|
856
|
-
try {
|
|
857
|
-
await result;
|
|
858
|
-
} catch {}
|
|
859
|
-
next();
|
|
860
|
-
};
|
|
861
|
-
const enqueue = (function_, resolve, reject, arguments_) => {
|
|
862
|
-
const queueItem = { reject };
|
|
863
|
-
new Promise((internalResolve) => {
|
|
864
|
-
queueItem.run = internalResolve;
|
|
865
|
-
queue.enqueue(queueItem);
|
|
866
|
-
}).then(run.bind(void 0, function_, resolve, arguments_));
|
|
867
|
-
if (activeCount < concurrency) resumeNext();
|
|
868
|
-
};
|
|
869
|
-
const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
|
|
870
|
-
enqueue(function_, resolve, reject, arguments_);
|
|
871
|
-
});
|
|
872
|
-
Object.defineProperties(generator, {
|
|
873
|
-
activeCount: { get: () => activeCount },
|
|
874
|
-
pendingCount: { get: () => queue.size },
|
|
875
|
-
clearQueue: { value() {
|
|
876
|
-
if (!rejectOnClear) {
|
|
877
|
-
queue.clear();
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
const abortError = AbortSignal.abort().reason;
|
|
881
|
-
while (queue.size > 0) queue.dequeue().reject(abortError);
|
|
882
|
-
} },
|
|
883
|
-
concurrency: {
|
|
884
|
-
get: () => concurrency,
|
|
885
|
-
set(newConcurrency) {
|
|
886
|
-
validateConcurrency(newConcurrency);
|
|
887
|
-
concurrency = newConcurrency;
|
|
888
|
-
queueMicrotask(() => {
|
|
889
|
-
while (activeCount < concurrency && queue.size > 0) resumeNext();
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
},
|
|
893
|
-
map: { async value(iterable, function_) {
|
|
894
|
-
const promises = Array.from(iterable, (value, index) => this(function_, value, index));
|
|
895
|
-
return Promise.all(promises);
|
|
896
|
-
} }
|
|
897
|
-
});
|
|
898
|
-
return generator;
|
|
899
|
-
}
|
|
900
|
-
function validateConcurrency(concurrency) {
|
|
901
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
902
|
-
}
|
|
903
|
-
//#endregion
|
|
904
474
|
//#region src/FileProcessor.ts
|
|
905
475
|
function joinSources(file) {
|
|
906
476
|
return file.sources.map((item) => (0, _kubb_ast.extractStringsFromNodes)(item.nodes)).filter(Boolean).join("\n\n");
|
|
@@ -910,7 +480,7 @@ function joinSources(file) {
|
|
|
910
480
|
* Falls back to joining source values when no matching parser is found.
|
|
911
481
|
*/
|
|
912
482
|
var FileProcessor = class {
|
|
913
|
-
#limit = pLimit(100);
|
|
483
|
+
#limit = require_PluginDriver.pLimit(100);
|
|
914
484
|
async parse(file, { parsers, extension } = {}) {
|
|
915
485
|
const parseExtName = extension?.[file.extname] || void 0;
|
|
916
486
|
if (!parsers || !file.extname) return joinSources(file);
|
|
@@ -944,1243 +514,6 @@ var FileProcessor = class {
|
|
|
944
514
|
}
|
|
945
515
|
};
|
|
946
516
|
//#endregion
|
|
947
|
-
//#region src/definePlugin.ts
|
|
948
|
-
/**
|
|
949
|
-
* Returns `true` when `plugin` is a hook-style plugin created with `definePlugin`.
|
|
950
|
-
*
|
|
951
|
-
* Used by `PluginDriver` to distinguish hook-style plugins from legacy `createPlugin` plugins
|
|
952
|
-
* so it can normalize them and register their handlers on the `AsyncEventEmitter`.
|
|
953
|
-
*/
|
|
954
|
-
function isHookStylePlugin(plugin) {
|
|
955
|
-
return typeof plugin === "object" && plugin !== null && "hooks" in plugin;
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Creates a plugin factory using the new hook-style (`hooks:`) API.
|
|
959
|
-
*
|
|
960
|
-
* The returned factory is called with optional options and produces a `HookStylePlugin`
|
|
961
|
-
* that coexists with plugins created via the legacy `createPlugin` API in the same
|
|
962
|
-
* `kubb.config.ts`.
|
|
963
|
-
*
|
|
964
|
-
* Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
|
|
965
|
-
* both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
|
|
966
|
-
*
|
|
967
|
-
* @example
|
|
968
|
-
* ```ts
|
|
969
|
-
* // With PluginFactoryOptions (recommended for real plugins)
|
|
970
|
-
* export const pluginTs = definePlugin<PluginTs>((options) => ({
|
|
971
|
-
* name: 'plugin-ts',
|
|
972
|
-
* hooks: {
|
|
973
|
-
* 'kubb:plugin:setup'(ctx) {
|
|
974
|
-
* ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
|
|
975
|
-
* },
|
|
976
|
-
* },
|
|
977
|
-
* }))
|
|
978
|
-
* ```
|
|
979
|
-
*/
|
|
980
|
-
function definePlugin(factory) {
|
|
981
|
-
return (options) => factory(options ?? {});
|
|
982
|
-
}
|
|
983
|
-
//#endregion
|
|
984
|
-
//#region src/defineResolver.ts
|
|
985
|
-
/**
|
|
986
|
-
* Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).
|
|
987
|
-
*/
|
|
988
|
-
function matchesOperationPattern(node, type, pattern) {
|
|
989
|
-
switch (type) {
|
|
990
|
-
case "tag": return node.tags.some((tag) => !!tag.match(pattern));
|
|
991
|
-
case "operationId": return !!node.operationId.match(pattern);
|
|
992
|
-
case "path": return !!node.path.match(pattern);
|
|
993
|
-
case "method": return !!node.method.toLowerCase().match(pattern);
|
|
994
|
-
case "contentType": return !!node.requestBody?.contentType?.match(pattern);
|
|
995
|
-
default: return false;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* Checks if a schema matches a pattern for a given filter type (`schemaName`).
|
|
1000
|
-
*
|
|
1001
|
-
* Returns `null` when the filter type doesn't apply to schemas.
|
|
1002
|
-
*/
|
|
1003
|
-
function matchesSchemaPattern(node, type, pattern) {
|
|
1004
|
-
switch (type) {
|
|
1005
|
-
case "schemaName": return node.name ? !!node.name.match(pattern) : false;
|
|
1006
|
-
default: return null;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Default name resolver used by `defineResolver`.
|
|
1011
|
-
*
|
|
1012
|
-
* - `camelCase` for `function` and `file` types.
|
|
1013
|
-
* - `PascalCase` for `type`.
|
|
1014
|
-
* - `camelCase` for everything else.
|
|
1015
|
-
*/
|
|
1016
|
-
function defaultResolver(name, type) {
|
|
1017
|
-
let resolvedName = camelCase(name);
|
|
1018
|
-
if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
|
|
1019
|
-
if (type === "type") resolvedName = pascalCase(name);
|
|
1020
|
-
return resolvedName;
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Default option resolver — applies include/exclude filters and merges matching override options.
|
|
1024
|
-
*
|
|
1025
|
-
* Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.
|
|
1026
|
-
*
|
|
1027
|
-
* @example Include/exclude filtering
|
|
1028
|
-
* ```ts
|
|
1029
|
-
* const options = defaultResolveOptions(operationNode, {
|
|
1030
|
-
* options: { output: 'types' },
|
|
1031
|
-
* exclude: [{ type: 'tag', pattern: 'internal' }],
|
|
1032
|
-
* })
|
|
1033
|
-
* // → null when node has tag 'internal'
|
|
1034
|
-
* ```
|
|
1035
|
-
*
|
|
1036
|
-
* @example Override merging
|
|
1037
|
-
* ```ts
|
|
1038
|
-
* const options = defaultResolveOptions(operationNode, {
|
|
1039
|
-
* options: { enumType: 'asConst' },
|
|
1040
|
-
* override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],
|
|
1041
|
-
* })
|
|
1042
|
-
* // → { enumType: 'enum' } when operationId matches
|
|
1043
|
-
* ```
|
|
1044
|
-
*/
|
|
1045
|
-
function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
|
|
1046
|
-
if ((0, _kubb_ast.isOperationNode)(node)) {
|
|
1047
|
-
if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
1048
|
-
if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
1049
|
-
const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
|
|
1050
|
-
return {
|
|
1051
|
-
...options,
|
|
1052
|
-
...overrideOptions
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
|
-
if ((0, _kubb_ast.isSchemaNode)(node)) {
|
|
1056
|
-
if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
|
|
1057
|
-
if (include) {
|
|
1058
|
-
const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
|
|
1059
|
-
if (applicable.length > 0 && !applicable.includes(true)) return null;
|
|
1060
|
-
}
|
|
1061
|
-
const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
|
|
1062
|
-
return {
|
|
1063
|
-
...options,
|
|
1064
|
-
...overrideOptions
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
return options;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Default path resolver used by `defineResolver`.
|
|
1071
|
-
*
|
|
1072
|
-
* - Returns the output directory in `single` mode.
|
|
1073
|
-
* - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.
|
|
1074
|
-
* - Falls back to a flat `output/baseName` path otherwise.
|
|
1075
|
-
*
|
|
1076
|
-
* A custom `group.name` function overrides the default subdirectory naming.
|
|
1077
|
-
* For `tag` groups the default is `${camelCase(tag)}Controller`.
|
|
1078
|
-
* For `path` groups the default is the first path segment after `/`.
|
|
1079
|
-
*
|
|
1080
|
-
* @example Flat output
|
|
1081
|
-
* ```ts
|
|
1082
|
-
* defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })
|
|
1083
|
-
* // → '/src/types/petTypes.ts'
|
|
1084
|
-
* ```
|
|
1085
|
-
*
|
|
1086
|
-
* @example Tag-based grouping
|
|
1087
|
-
* ```ts
|
|
1088
|
-
* defaultResolvePath(
|
|
1089
|
-
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
1090
|
-
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1091
|
-
* )
|
|
1092
|
-
* // → '/src/types/petsController/petTypes.ts'
|
|
1093
|
-
* ```
|
|
1094
|
-
*
|
|
1095
|
-
* @example Path-based grouping
|
|
1096
|
-
* ```ts
|
|
1097
|
-
* defaultResolvePath(
|
|
1098
|
-
* { baseName: 'petTypes.ts', path: '/pets/list' },
|
|
1099
|
-
* { root: '/src', output: { path: 'types' }, group: { type: 'path' } },
|
|
1100
|
-
* )
|
|
1101
|
-
* // → '/src/types/pets/petTypes.ts'
|
|
1102
|
-
* ```
|
|
1103
|
-
*
|
|
1104
|
-
* @example Single-file mode
|
|
1105
|
-
* ```ts
|
|
1106
|
-
* defaultResolvePath(
|
|
1107
|
-
* { baseName: 'petTypes.ts', pathMode: 'single' },
|
|
1108
|
-
* { root: '/src', output: { path: 'types' } },
|
|
1109
|
-
* )
|
|
1110
|
-
* // → '/src/types'
|
|
1111
|
-
* ```
|
|
1112
|
-
*/
|
|
1113
|
-
function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
|
|
1114
|
-
if ((pathMode ?? getMode(node_path.default.resolve(root, output.path))) === "single") return node_path.default.resolve(root, output.path);
|
|
1115
|
-
if (group && (groupPath || tag)) return node_path.default.resolve(root, output.path, group.name({ group: group.type === "path" ? groupPath : tag }), baseName);
|
|
1116
|
-
return node_path.default.resolve(root, output.path, baseName);
|
|
1117
|
-
}
|
|
1118
|
-
/**
|
|
1119
|
-
* Default file resolver used by `defineResolver`.
|
|
1120
|
-
*
|
|
1121
|
-
* Resolves a `FileNode` by combining name resolution (`resolver.default`) with
|
|
1122
|
-
* path resolution (`resolver.resolvePath`). The resolved file always has empty
|
|
1123
|
-
* `sources`, `imports`, and `exports` arrays — consumers populate those separately.
|
|
1124
|
-
*
|
|
1125
|
-
* In `single` mode the name is omitted and the file sits directly in the output directory.
|
|
1126
|
-
*
|
|
1127
|
-
* @example Resolve a schema file
|
|
1128
|
-
* ```ts
|
|
1129
|
-
* const file = defaultResolveFile.call(resolver,
|
|
1130
|
-
* { name: 'pet', extname: '.ts' },
|
|
1131
|
-
* { root: '/src', output: { path: 'types' } },
|
|
1132
|
-
* )
|
|
1133
|
-
* // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
|
|
1134
|
-
* ```
|
|
1135
|
-
*
|
|
1136
|
-
* @example Resolve an operation file with tag grouping
|
|
1137
|
-
* ```ts
|
|
1138
|
-
* const file = defaultResolveFile.call(resolver,
|
|
1139
|
-
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
1140
|
-
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1141
|
-
* )
|
|
1142
|
-
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
1143
|
-
* ```
|
|
1144
|
-
*/
|
|
1145
|
-
function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
1146
|
-
const pathMode = getMode(node_path.default.resolve(context.root, context.output.path));
|
|
1147
|
-
const baseName = `${pathMode === "single" ? "" : this.default(name, "file")}${extname}`;
|
|
1148
|
-
const filePath = this.resolvePath({
|
|
1149
|
-
baseName,
|
|
1150
|
-
pathMode,
|
|
1151
|
-
tag,
|
|
1152
|
-
path: groupPath
|
|
1153
|
-
}, context);
|
|
1154
|
-
return (0, _kubb_ast.createFile)({
|
|
1155
|
-
path: filePath,
|
|
1156
|
-
baseName: node_path.default.basename(filePath),
|
|
1157
|
-
meta: { pluginName: this.pluginName },
|
|
1158
|
-
sources: [],
|
|
1159
|
-
imports: [],
|
|
1160
|
-
exports: []
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Generates the default "Generated by Kubb" banner from config and optional node metadata.
|
|
1165
|
-
*/
|
|
1166
|
-
function buildDefaultBanner({ title, description, version, config }) {
|
|
1167
|
-
try {
|
|
1168
|
-
let source = "";
|
|
1169
|
-
if (Array.isArray(config.input)) {
|
|
1170
|
-
const first = config.input[0];
|
|
1171
|
-
if (first && "path" in first) source = node_path.default.basename(first.path);
|
|
1172
|
-
} else if ("path" in config.input) source = node_path.default.basename(config.input.path);
|
|
1173
|
-
else if ("data" in config.input) source = "text content";
|
|
1174
|
-
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
1175
|
-
if (config.output.defaultBanner === "simple") {
|
|
1176
|
-
banner += "*/\n";
|
|
1177
|
-
return banner;
|
|
1178
|
-
}
|
|
1179
|
-
if (source) banner += `* Source: ${source}\n`;
|
|
1180
|
-
if (title) banner += `* Title: ${title}\n`;
|
|
1181
|
-
if (description) {
|
|
1182
|
-
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
1183
|
-
banner += `* Description: ${formattedDescription}\n`;
|
|
1184
|
-
}
|
|
1185
|
-
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
1186
|
-
banner += "*/\n";
|
|
1187
|
-
return banner;
|
|
1188
|
-
} catch (_error) {
|
|
1189
|
-
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
/**
|
|
1193
|
-
* Default banner resolver — returns the banner string for a generated file.
|
|
1194
|
-
*
|
|
1195
|
-
* A user-supplied `output.banner` overrides the default Kubb "Generated by Kubb" notice.
|
|
1196
|
-
* When no `output.banner` is set, the Kubb notice is used (including `title` and `version`
|
|
1197
|
-
* from the OAS spec when a `node` is provided).
|
|
1198
|
-
*
|
|
1199
|
-
* - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.
|
|
1200
|
-
* - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.
|
|
1201
|
-
* - When `output.banner` is a string, returns it directly.
|
|
1202
|
-
* - When `config.output.defaultBanner` is `false`, returns `undefined`.
|
|
1203
|
-
* - Otherwise returns the Kubb "Generated by Kubb" notice.
|
|
1204
|
-
*
|
|
1205
|
-
* @example String banner overrides default
|
|
1206
|
-
* ```ts
|
|
1207
|
-
* defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })
|
|
1208
|
-
* // → '// my banner'
|
|
1209
|
-
* ```
|
|
1210
|
-
*
|
|
1211
|
-
* @example Function banner with node
|
|
1212
|
-
* ```ts
|
|
1213
|
-
* defaultResolveBanner(inputNode, { output: { banner: (node) => `// v${node.version}` }, config })
|
|
1214
|
-
* // → '// v3.0.0'
|
|
1215
|
-
* ```
|
|
1216
|
-
*
|
|
1217
|
-
* @example No user banner — Kubb notice with OAS metadata
|
|
1218
|
-
* ```ts
|
|
1219
|
-
* defaultResolveBanner(inputNode, { config })
|
|
1220
|
-
* // → '/** Generated by Kubb ... Title: Pet Store ... *\/'
|
|
1221
|
-
* ```
|
|
1222
|
-
*
|
|
1223
|
-
* @example Disabled default banner
|
|
1224
|
-
* ```ts
|
|
1225
|
-
* defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })
|
|
1226
|
-
* // → undefined
|
|
1227
|
-
* ```
|
|
1228
|
-
*/
|
|
1229
|
-
function defaultResolveBanner(node, { output, config }) {
|
|
1230
|
-
if (typeof output?.banner === "function") return output.banner(node);
|
|
1231
|
-
if (typeof output?.banner === "string") return output.banner;
|
|
1232
|
-
if (config.output.defaultBanner === false) return;
|
|
1233
|
-
return buildDefaultBanner({
|
|
1234
|
-
title: node?.meta?.title,
|
|
1235
|
-
version: node?.meta?.version,
|
|
1236
|
-
config
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Default footer resolver — returns the footer string for a generated file.
|
|
1241
|
-
*
|
|
1242
|
-
* - When `output.footer` is a function and `node` is provided, calls it with the node.
|
|
1243
|
-
* - When `output.footer` is a function and `node` is absent, returns `undefined`.
|
|
1244
|
-
* - When `output.footer` is a string, returns it directly.
|
|
1245
|
-
* - Otherwise returns `undefined`.
|
|
1246
|
-
*
|
|
1247
|
-
* @example String footer
|
|
1248
|
-
* ```ts
|
|
1249
|
-
* defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })
|
|
1250
|
-
* // → '// end of file'
|
|
1251
|
-
* ```
|
|
1252
|
-
*
|
|
1253
|
-
* @example Function footer with node
|
|
1254
|
-
* ```ts
|
|
1255
|
-
* defaultResolveFooter(inputNode, { output: { footer: (node) => `// ${node.title}` }, config })
|
|
1256
|
-
* // → '// Pet Store'
|
|
1257
|
-
* ```
|
|
1258
|
-
*/
|
|
1259
|
-
function defaultResolveFooter(node, { output }) {
|
|
1260
|
-
if (typeof output?.footer === "function") return node ? output.footer(node) : void 0;
|
|
1261
|
-
if (typeof output?.footer === "string") return output.footer;
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Defines a resolver for a plugin, injecting built-in defaults for name casing,
|
|
1265
|
-
* include/exclude/override filtering, path resolution, and file construction.
|
|
1266
|
-
*
|
|
1267
|
-
* All four defaults can be overridden by providing them in the builder function:
|
|
1268
|
-
* - `default` — name casing strategy (camelCase / PascalCase)
|
|
1269
|
-
* - `resolveOptions` — include/exclude/override filtering
|
|
1270
|
-
* - `resolvePath` — output path computation
|
|
1271
|
-
* - `resolveFile` — full `FileNode` construction
|
|
1272
|
-
*
|
|
1273
|
-
* Methods in the builder have access to `this` (the full resolver object), so they
|
|
1274
|
-
* can call other resolver methods without circular imports.
|
|
1275
|
-
*
|
|
1276
|
-
* @example Basic resolver with naming helpers
|
|
1277
|
-
* ```ts
|
|
1278
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
1279
|
-
* name: 'default',
|
|
1280
|
-
* resolveName(node) {
|
|
1281
|
-
* return this.default(node.name, 'function')
|
|
1282
|
-
* },
|
|
1283
|
-
* resolveTypedName(node) {
|
|
1284
|
-
* return this.default(node.name, 'type')
|
|
1285
|
-
* },
|
|
1286
|
-
* }))
|
|
1287
|
-
* ```
|
|
1288
|
-
*
|
|
1289
|
-
* @example Override resolvePath for a custom output structure
|
|
1290
|
-
* ```ts
|
|
1291
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
1292
|
-
* name: 'custom',
|
|
1293
|
-
* resolvePath({ baseName }, { root, output }) {
|
|
1294
|
-
* return path.resolve(root, output.path, 'generated', baseName)
|
|
1295
|
-
* },
|
|
1296
|
-
* }))
|
|
1297
|
-
* ```
|
|
1298
|
-
*
|
|
1299
|
-
* @example Use this.default inside a helper
|
|
1300
|
-
* ```ts
|
|
1301
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
1302
|
-
* name: 'default',
|
|
1303
|
-
* resolveParamName(node, param) {
|
|
1304
|
-
* return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
|
|
1305
|
-
* },
|
|
1306
|
-
* }))
|
|
1307
|
-
* ```
|
|
1308
|
-
*/
|
|
1309
|
-
function defineResolver(build) {
|
|
1310
|
-
return {
|
|
1311
|
-
default: defaultResolver,
|
|
1312
|
-
resolveOptions: defaultResolveOptions,
|
|
1313
|
-
resolvePath: defaultResolvePath,
|
|
1314
|
-
resolveFile: defaultResolveFile,
|
|
1315
|
-
resolveBanner: defaultResolveBanner,
|
|
1316
|
-
resolveFooter: defaultResolveFooter,
|
|
1317
|
-
...build()
|
|
1318
|
-
};
|
|
1319
|
-
}
|
|
1320
|
-
//#endregion
|
|
1321
|
-
//#region src/devtools.ts
|
|
1322
|
-
/**
|
|
1323
|
-
* Encodes an `InputNode` as a compressed, URL-safe string.
|
|
1324
|
-
*
|
|
1325
|
-
* The JSON representation is deflate-compressed with {@link deflateSync} before
|
|
1326
|
-
* base64url encoding, which typically reduces payload size by 70–80 % and
|
|
1327
|
-
* keeps URLs well within browser and server path-length limits.
|
|
1328
|
-
*
|
|
1329
|
-
* Use {@link decodeAst} to reverse.
|
|
1330
|
-
*/
|
|
1331
|
-
function encodeAst(input) {
|
|
1332
|
-
const compressed = (0, fflate.deflateSync)(new TextEncoder().encode(JSON.stringify(input)));
|
|
1333
|
-
return Buffer.from(compressed).toString("base64url");
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* Constructs the Kubb Studio URL for the given `InputNode`.
|
|
1337
|
-
* When `options.ast` is `true`, navigates to the AST inspector (`/ast`).
|
|
1338
|
-
* The `input` is encoded and attached as the `?root=` query parameter so Studio
|
|
1339
|
-
* can decode and render it without a round-trip to any server.
|
|
1340
|
-
*/
|
|
1341
|
-
function getStudioUrl(input, studioUrl, options = {}) {
|
|
1342
|
-
return `${studioUrl.replace(/\/$/, "")}${options.ast ? "/ast" : ""}?root=${encodeAst(input)}`;
|
|
1343
|
-
}
|
|
1344
|
-
/**
|
|
1345
|
-
* Opens the Kubb Studio URL for the given `InputNode` in the default browser —
|
|
1346
|
-
*
|
|
1347
|
-
* Falls back to printing the URL if the browser cannot be launched.
|
|
1348
|
-
*/
|
|
1349
|
-
async function openInStudio(input, studioUrl, options = {}) {
|
|
1350
|
-
const url = getStudioUrl(input, studioUrl, options);
|
|
1351
|
-
const cmd = process.platform === "win32" ? "cmd" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
1352
|
-
const args = process.platform === "win32" ? [
|
|
1353
|
-
"/c",
|
|
1354
|
-
"start",
|
|
1355
|
-
"",
|
|
1356
|
-
url
|
|
1357
|
-
] : [url];
|
|
1358
|
-
try {
|
|
1359
|
-
await (0, tinyexec.x)(cmd, args);
|
|
1360
|
-
} catch {
|
|
1361
|
-
console.log(`\n ${url}\n`);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
//#endregion
|
|
1365
|
-
//#region src/FileManager.ts
|
|
1366
|
-
function mergeFile(a, b) {
|
|
1367
|
-
return {
|
|
1368
|
-
...a,
|
|
1369
|
-
sources: [...a.sources || [], ...b.sources || []],
|
|
1370
|
-
imports: [...a.imports || [], ...b.imports || []],
|
|
1371
|
-
exports: [...a.exports || [], ...b.exports || []]
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* In-memory file store for generated files.
|
|
1376
|
-
*
|
|
1377
|
-
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
1378
|
-
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
1379
|
-
*
|
|
1380
|
-
* @example
|
|
1381
|
-
* ```ts
|
|
1382
|
-
* import { FileManager } from '@kubb/core'
|
|
1383
|
-
*
|
|
1384
|
-
* const manager = new FileManager()
|
|
1385
|
-
* manager.upsert(myFile)
|
|
1386
|
-
* console.log(manager.files) // all stored files
|
|
1387
|
-
* ```
|
|
1388
|
-
*/
|
|
1389
|
-
var FileManager = class {
|
|
1390
|
-
#cache = /* @__PURE__ */ new Map();
|
|
1391
|
-
#filesCache = null;
|
|
1392
|
-
/**
|
|
1393
|
-
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
1394
|
-
* and exports from all calls with the same path are concatenated together.
|
|
1395
|
-
*/
|
|
1396
|
-
add(...files) {
|
|
1397
|
-
const resolvedFiles = [];
|
|
1398
|
-
const mergedFiles = /* @__PURE__ */ new Map();
|
|
1399
|
-
files.forEach((file) => {
|
|
1400
|
-
const existing = mergedFiles.get(file.path);
|
|
1401
|
-
if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
|
|
1402
|
-
else mergedFiles.set(file.path, file);
|
|
1403
|
-
});
|
|
1404
|
-
for (const file of mergedFiles.values()) {
|
|
1405
|
-
const resolvedFile = (0, _kubb_ast.createFile)(file);
|
|
1406
|
-
this.#cache.set(resolvedFile.path, resolvedFile);
|
|
1407
|
-
this.#filesCache = null;
|
|
1408
|
-
resolvedFiles.push(resolvedFile);
|
|
1409
|
-
}
|
|
1410
|
-
return resolvedFiles;
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Adds or merges one or more files.
|
|
1414
|
-
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
1415
|
-
*/
|
|
1416
|
-
upsert(...files) {
|
|
1417
|
-
const resolvedFiles = [];
|
|
1418
|
-
const mergedFiles = /* @__PURE__ */ new Map();
|
|
1419
|
-
files.forEach((file) => {
|
|
1420
|
-
const existing = mergedFiles.get(file.path);
|
|
1421
|
-
if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
|
|
1422
|
-
else mergedFiles.set(file.path, file);
|
|
1423
|
-
});
|
|
1424
|
-
for (const file of mergedFiles.values()) {
|
|
1425
|
-
const existing = this.#cache.get(file.path);
|
|
1426
|
-
const resolvedFile = (0, _kubb_ast.createFile)(existing ? mergeFile(existing, file) : file);
|
|
1427
|
-
this.#cache.set(resolvedFile.path, resolvedFile);
|
|
1428
|
-
this.#filesCache = null;
|
|
1429
|
-
resolvedFiles.push(resolvedFile);
|
|
1430
|
-
}
|
|
1431
|
-
return resolvedFiles;
|
|
1432
|
-
}
|
|
1433
|
-
getByPath(path) {
|
|
1434
|
-
return this.#cache.get(path) ?? null;
|
|
1435
|
-
}
|
|
1436
|
-
deleteByPath(path) {
|
|
1437
|
-
this.#cache.delete(path);
|
|
1438
|
-
this.#filesCache = null;
|
|
1439
|
-
}
|
|
1440
|
-
clear() {
|
|
1441
|
-
this.#cache.clear();
|
|
1442
|
-
this.#filesCache = null;
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* All stored files, sorted by path length (shorter paths first).
|
|
1446
|
-
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
1447
|
-
*/
|
|
1448
|
-
get files() {
|
|
1449
|
-
if (this.#filesCache) return this.#filesCache;
|
|
1450
|
-
const keys = [...this.#cache.keys()].sort((a, b) => {
|
|
1451
|
-
if (a.length !== b.length) return a.length - b.length;
|
|
1452
|
-
const aIsIndex = trimExtName$1(a).endsWith("index");
|
|
1453
|
-
if (aIsIndex !== trimExtName$1(b).endsWith("index")) return aIsIndex ? 1 : -1;
|
|
1454
|
-
return 0;
|
|
1455
|
-
});
|
|
1456
|
-
const files = [];
|
|
1457
|
-
for (const key of keys) {
|
|
1458
|
-
const file = this.#cache.get(key);
|
|
1459
|
-
if (file) files.push(file);
|
|
1460
|
-
}
|
|
1461
|
-
this.#filesCache = files;
|
|
1462
|
-
return files;
|
|
1463
|
-
}
|
|
1464
|
-
};
|
|
1465
|
-
//#endregion
|
|
1466
|
-
//#region src/renderNode.ts
|
|
1467
|
-
/**
|
|
1468
|
-
* Handles the return value of a plugin AST hook or generator method.
|
|
1469
|
-
*
|
|
1470
|
-
* - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`
|
|
1471
|
-
* - `Array<FileNode>` → added directly into `driver.fileManager`
|
|
1472
|
-
* - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)
|
|
1473
|
-
*
|
|
1474
|
-
* Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result
|
|
1475
|
-
* may be a renderer element. Generators that only return `Array<FileNode>` do not need one.
|
|
1476
|
-
*/
|
|
1477
|
-
async function applyHookResult(result, driver, rendererFactory) {
|
|
1478
|
-
if (!result) return;
|
|
1479
|
-
if (Array.isArray(result)) {
|
|
1480
|
-
driver.fileManager.upsert(...result);
|
|
1481
|
-
return;
|
|
1482
|
-
}
|
|
1483
|
-
if (!rendererFactory) return;
|
|
1484
|
-
const renderer = rendererFactory();
|
|
1485
|
-
await renderer.render(result);
|
|
1486
|
-
driver.fileManager.upsert(...renderer.files);
|
|
1487
|
-
renderer.unmount();
|
|
1488
|
-
}
|
|
1489
|
-
//#endregion
|
|
1490
|
-
//#region src/utils/executeStrategies.ts
|
|
1491
|
-
/**
|
|
1492
|
-
* Runs promise functions in sequence, threading each result into the next call.
|
|
1493
|
-
*
|
|
1494
|
-
* - Each function receives the accumulated state from the previous call.
|
|
1495
|
-
* - Skips functions that return a falsy value (acts as a no-op for that step).
|
|
1496
|
-
* - Returns an array of all individual results.
|
|
1497
|
-
* @deprecated
|
|
1498
|
-
*/
|
|
1499
|
-
function hookSeq(promises) {
|
|
1500
|
-
return promises.filter(Boolean).reduce((promise, func) => {
|
|
1501
|
-
if (typeof func !== "function") throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1502
|
-
return promise.then((state) => {
|
|
1503
|
-
const calledFunc = func(state);
|
|
1504
|
-
if (calledFunc) return calledFunc.then(Array.prototype.concat.bind(state));
|
|
1505
|
-
return state;
|
|
1506
|
-
});
|
|
1507
|
-
}, Promise.resolve([]));
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Runs promise functions in sequence and returns the first non-null result.
|
|
1511
|
-
*
|
|
1512
|
-
* - Stops as soon as `nullCheck` passes for a result (default: `!== null`).
|
|
1513
|
-
* - Subsequent functions are skipped once a match is found.
|
|
1514
|
-
* @deprecated
|
|
1515
|
-
*/
|
|
1516
|
-
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
1517
|
-
let promise = Promise.resolve(null);
|
|
1518
|
-
for (const func of promises.filter(Boolean)) promise = promise.then((state) => {
|
|
1519
|
-
if (nullCheck(state)) return state;
|
|
1520
|
-
return func(state);
|
|
1521
|
-
});
|
|
1522
|
-
return promise;
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Runs promise functions concurrently and returns all settled results.
|
|
1526
|
-
*
|
|
1527
|
-
* - Limits simultaneous executions to `concurrency` (default: unlimited).
|
|
1528
|
-
* - Uses `Promise.allSettled` so individual failures do not cancel other tasks.
|
|
1529
|
-
* @deprecated
|
|
1530
|
-
*/
|
|
1531
|
-
function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
1532
|
-
const limit = pLimit(concurrency);
|
|
1533
|
-
const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
|
|
1534
|
-
return Promise.allSettled(tasks);
|
|
1535
|
-
}
|
|
1536
|
-
//#endregion
|
|
1537
|
-
//#region src/PluginDriver.ts
|
|
1538
|
-
/**
|
|
1539
|
-
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
1540
|
-
*
|
|
1541
|
-
* @example
|
|
1542
|
-
* ```ts
|
|
1543
|
-
* getMode('src/gen/types.ts') // 'single'
|
|
1544
|
-
* getMode('src/gen/types') // 'split'
|
|
1545
|
-
* ```
|
|
1546
|
-
*/
|
|
1547
|
-
function getMode(fileOrFolder) {
|
|
1548
|
-
if (!fileOrFolder) return "split";
|
|
1549
|
-
return (0, node_path.extname)(fileOrFolder) ? "single" : "split";
|
|
1550
|
-
}
|
|
1551
|
-
const hookFirstNullCheck = (state) => !!state?.result;
|
|
1552
|
-
var PluginDriver = class {
|
|
1553
|
-
config;
|
|
1554
|
-
options;
|
|
1555
|
-
/**
|
|
1556
|
-
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
1557
|
-
* the build pipeline after the adapter's `parse()` resolves.
|
|
1558
|
-
*/
|
|
1559
|
-
inputNode = void 0;
|
|
1560
|
-
adapter = void 0;
|
|
1561
|
-
#studioIsOpen = false;
|
|
1562
|
-
/**
|
|
1563
|
-
* Central file store for all generated files.
|
|
1564
|
-
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
1565
|
-
* add files; this property gives direct read/write access when needed.
|
|
1566
|
-
*/
|
|
1567
|
-
fileManager = new FileManager();
|
|
1568
|
-
plugins = /* @__PURE__ */ new Map();
|
|
1569
|
-
/**
|
|
1570
|
-
* Tracks which plugins have generators registered via `addGenerator()` (event-based path).
|
|
1571
|
-
* Used by the build loop to decide whether to emit generator events for a given plugin.
|
|
1572
|
-
*/
|
|
1573
|
-
#pluginsWithEventGenerators = /* @__PURE__ */ new Set();
|
|
1574
|
-
#resolvers = /* @__PURE__ */ new Map();
|
|
1575
|
-
#defaultResolvers = /* @__PURE__ */ new Map();
|
|
1576
|
-
#hookListeners = /* @__PURE__ */ new Map();
|
|
1577
|
-
constructor(config, options) {
|
|
1578
|
-
this.config = config;
|
|
1579
|
-
this.options = {
|
|
1580
|
-
...options,
|
|
1581
|
-
hooks: options.hooks
|
|
1582
|
-
};
|
|
1583
|
-
config.plugins.map((rawPlugin) => {
|
|
1584
|
-
if (isHookStylePlugin(rawPlugin)) return this.#normalizeHookStylePlugin(rawPlugin);
|
|
1585
|
-
return {
|
|
1586
|
-
...rawPlugin,
|
|
1587
|
-
buildStart: rawPlugin.buildStart ?? (() => {}),
|
|
1588
|
-
buildEnd: rawPlugin.buildEnd ?? (() => {})
|
|
1589
|
-
};
|
|
1590
|
-
}).filter((plugin) => {
|
|
1591
|
-
if (typeof plugin.apply === "function") return plugin.apply(config);
|
|
1592
|
-
return true;
|
|
1593
|
-
}).sort((a, b) => {
|
|
1594
|
-
if (b.dependencies?.includes(a.name)) return -1;
|
|
1595
|
-
if (a.dependencies?.includes(b.name)) return 1;
|
|
1596
|
-
return 0;
|
|
1597
|
-
}).forEach((plugin) => {
|
|
1598
|
-
this.plugins.set(plugin.name, plugin);
|
|
1599
|
-
});
|
|
1600
|
-
}
|
|
1601
|
-
get hooks() {
|
|
1602
|
-
if (!this.options.hooks) throw new Error("hooks are not defined");
|
|
1603
|
-
return this.options.hooks;
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* Creates a `Plugin`-compatible object from a hook-style plugin and registers
|
|
1607
|
-
* its lifecycle handlers on the `AsyncEventEmitter`.
|
|
1608
|
-
*
|
|
1609
|
-
* The normalized plugin has an empty `buildStart` — generators registered via
|
|
1610
|
-
* `addGenerator()` in `kubb:plugin:setup` are stored on `normalizedPlugin.generators`
|
|
1611
|
-
* and used by `runPluginAstHooks` during the build.
|
|
1612
|
-
*/
|
|
1613
|
-
#normalizeHookStylePlugin(hookPlugin) {
|
|
1614
|
-
const generators = [];
|
|
1615
|
-
const driver = this;
|
|
1616
|
-
const normalizedPlugin = {
|
|
1617
|
-
name: hookPlugin.name,
|
|
1618
|
-
dependencies: hookPlugin.dependencies,
|
|
1619
|
-
options: {
|
|
1620
|
-
output: { path: "." },
|
|
1621
|
-
exclude: [],
|
|
1622
|
-
override: []
|
|
1623
|
-
},
|
|
1624
|
-
generators,
|
|
1625
|
-
inject: () => void 0,
|
|
1626
|
-
resolveName(name, type) {
|
|
1627
|
-
return driver.getResolver(hookPlugin.name).default(name, type);
|
|
1628
|
-
},
|
|
1629
|
-
resolvePath(baseName, pathMode, resolveOptions) {
|
|
1630
|
-
const resolver = driver.getResolver(hookPlugin.name);
|
|
1631
|
-
const opts = normalizedPlugin.options;
|
|
1632
|
-
const group = resolveOptions?.group;
|
|
1633
|
-
return resolver.resolvePath({
|
|
1634
|
-
baseName,
|
|
1635
|
-
pathMode,
|
|
1636
|
-
tag: group?.tag,
|
|
1637
|
-
path: group?.path
|
|
1638
|
-
}, {
|
|
1639
|
-
root: (0, node_path.resolve)(driver.config.root, driver.config.output.path),
|
|
1640
|
-
output: opts.output,
|
|
1641
|
-
group: opts.group
|
|
1642
|
-
});
|
|
1643
|
-
},
|
|
1644
|
-
buildStart() {},
|
|
1645
|
-
buildEnd() {}
|
|
1646
|
-
};
|
|
1647
|
-
this.registerPluginHooks(hookPlugin, normalizedPlugin);
|
|
1648
|
-
return normalizedPlugin;
|
|
1649
|
-
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
1652
|
-
*
|
|
1653
|
-
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
1654
|
-
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
1655
|
-
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
1656
|
-
*
|
|
1657
|
-
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
1658
|
-
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
1659
|
-
*
|
|
1660
|
-
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
1661
|
-
* the plugin lifecycle without modifying plugin behavior.
|
|
1662
|
-
*/
|
|
1663
|
-
registerPluginHooks(hookPlugin, normalizedPlugin) {
|
|
1664
|
-
const { hooks } = hookPlugin;
|
|
1665
|
-
if (hooks["kubb:plugin:setup"]) {
|
|
1666
|
-
const setupHandler = (globalCtx) => {
|
|
1667
|
-
const pluginCtx = {
|
|
1668
|
-
...globalCtx,
|
|
1669
|
-
options: hookPlugin.options ?? {},
|
|
1670
|
-
addGenerator: (gen) => {
|
|
1671
|
-
this.registerGenerator(normalizedPlugin.name, gen);
|
|
1672
|
-
},
|
|
1673
|
-
setResolver: (resolver) => {
|
|
1674
|
-
this.setPluginResolver(normalizedPlugin.name, resolver);
|
|
1675
|
-
},
|
|
1676
|
-
setTransformer: (visitor) => {
|
|
1677
|
-
normalizedPlugin.transformer = visitor;
|
|
1678
|
-
},
|
|
1679
|
-
setRenderer: (renderer) => {
|
|
1680
|
-
normalizedPlugin.renderer = renderer;
|
|
1681
|
-
},
|
|
1682
|
-
setOptions: (opts) => {
|
|
1683
|
-
normalizedPlugin.options = {
|
|
1684
|
-
...normalizedPlugin.options,
|
|
1685
|
-
...opts
|
|
1686
|
-
};
|
|
1687
|
-
},
|
|
1688
|
-
injectFile: (file) => {
|
|
1689
|
-
const fileNode = (0, _kubb_ast.createFile)({
|
|
1690
|
-
baseName: file.baseName,
|
|
1691
|
-
path: file.path,
|
|
1692
|
-
sources: file.sources ?? [],
|
|
1693
|
-
imports: [],
|
|
1694
|
-
exports: []
|
|
1695
|
-
});
|
|
1696
|
-
this.fileManager.add(fileNode);
|
|
1697
|
-
}
|
|
1698
|
-
};
|
|
1699
|
-
return hooks["kubb:plugin:setup"](pluginCtx);
|
|
1700
|
-
};
|
|
1701
|
-
this.hooks.on("kubb:plugin:setup", setupHandler);
|
|
1702
|
-
this.#trackHookListener("kubb:plugin:setup", setupHandler);
|
|
1703
|
-
}
|
|
1704
|
-
for (const [event, handler] of Object.entries(hooks)) {
|
|
1705
|
-
if (event === "kubb:plugin:setup" || !handler) continue;
|
|
1706
|
-
this.hooks.on(event, handler);
|
|
1707
|
-
this.#trackHookListener(event, handler);
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
1712
|
-
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
1713
|
-
*
|
|
1714
|
-
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
1715
|
-
*/
|
|
1716
|
-
async emitSetupHooks() {
|
|
1717
|
-
await this.hooks.emit("kubb:plugin:setup", {
|
|
1718
|
-
config: this.config,
|
|
1719
|
-
addGenerator: () => {},
|
|
1720
|
-
setResolver: () => {},
|
|
1721
|
-
setTransformer: () => {},
|
|
1722
|
-
setRenderer: () => {},
|
|
1723
|
-
setOptions: () => {},
|
|
1724
|
-
injectFile: () => {},
|
|
1725
|
-
updateConfig: () => {},
|
|
1726
|
-
options: {}
|
|
1727
|
-
});
|
|
1728
|
-
}
|
|
1729
|
-
/**
|
|
1730
|
-
* Registers a generator for the given plugin on the shared event emitter.
|
|
1731
|
-
*
|
|
1732
|
-
* The generator's `schema`, `operation`, and `operations` methods are registered as
|
|
1733
|
-
* listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
|
|
1734
|
-
* respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
|
|
1735
|
-
* so that generators from different plugins do not cross-fire.
|
|
1736
|
-
*
|
|
1737
|
-
* The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
|
|
1738
|
-
* Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
|
|
1739
|
-
* declares a renderer.
|
|
1740
|
-
*
|
|
1741
|
-
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
1742
|
-
*/
|
|
1743
|
-
registerGenerator(pluginName, gen) {
|
|
1744
|
-
const resolveRenderer = () => {
|
|
1745
|
-
const plugin = this.plugins.get(pluginName);
|
|
1746
|
-
return gen.renderer === null ? void 0 : gen.renderer ?? plugin?.renderer ?? this.config.renderer;
|
|
1747
|
-
};
|
|
1748
|
-
if (gen.schema) {
|
|
1749
|
-
const schemaHandler = async (node, ctx) => {
|
|
1750
|
-
if (ctx.plugin.name !== pluginName) return;
|
|
1751
|
-
await applyHookResult(await gen.schema(node, ctx), this, resolveRenderer());
|
|
1752
|
-
};
|
|
1753
|
-
this.hooks.on("kubb:generate:schema", schemaHandler);
|
|
1754
|
-
this.#trackHookListener("kubb:generate:schema", schemaHandler);
|
|
1755
|
-
}
|
|
1756
|
-
if (gen.operation) {
|
|
1757
|
-
const operationHandler = async (node, ctx) => {
|
|
1758
|
-
if (ctx.plugin.name !== pluginName) return;
|
|
1759
|
-
await applyHookResult(await gen.operation(node, ctx), this, resolveRenderer());
|
|
1760
|
-
};
|
|
1761
|
-
this.hooks.on("kubb:generate:operation", operationHandler);
|
|
1762
|
-
this.#trackHookListener("kubb:generate:operation", operationHandler);
|
|
1763
|
-
}
|
|
1764
|
-
if (gen.operations) {
|
|
1765
|
-
const operationsHandler = async (nodes, ctx) => {
|
|
1766
|
-
if (ctx.plugin.name !== pluginName) return;
|
|
1767
|
-
await applyHookResult(await gen.operations(nodes, ctx), this, resolveRenderer());
|
|
1768
|
-
};
|
|
1769
|
-
this.hooks.on("kubb:generate:operations", operationsHandler);
|
|
1770
|
-
this.#trackHookListener("kubb:generate:operations", operationsHandler);
|
|
1771
|
-
}
|
|
1772
|
-
this.#pluginsWithEventGenerators.add(pluginName);
|
|
1773
|
-
}
|
|
1774
|
-
/**
|
|
1775
|
-
* Returns `true` when at least one generator was registered for the given plugin
|
|
1776
|
-
* via `addGenerator()` in `kubb:plugin:setup` (event-based path).
|
|
1777
|
-
*
|
|
1778
|
-
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
1779
|
-
* for a plugin that has no static `plugin.generators`.
|
|
1780
|
-
*/
|
|
1781
|
-
hasRegisteredGenerators(pluginName) {
|
|
1782
|
-
return this.#pluginsWithEventGenerators.has(pluginName);
|
|
1783
|
-
}
|
|
1784
|
-
dispose() {
|
|
1785
|
-
for (const [event, handlers] of this.#hookListeners) for (const handler of handlers) this.hooks.off(event, handler);
|
|
1786
|
-
this.#hookListeners.clear();
|
|
1787
|
-
this.#pluginsWithEventGenerators.clear();
|
|
1788
|
-
}
|
|
1789
|
-
#trackHookListener(event, handler) {
|
|
1790
|
-
let handlers = this.#hookListeners.get(event);
|
|
1791
|
-
if (!handlers) {
|
|
1792
|
-
handlers = /* @__PURE__ */ new Set();
|
|
1793
|
-
this.#hookListeners.set(event, handlers);
|
|
1794
|
-
}
|
|
1795
|
-
handlers.add(handler);
|
|
1796
|
-
}
|
|
1797
|
-
#createDefaultResolver(pluginName) {
|
|
1798
|
-
const existingResolver = this.#defaultResolvers.get(pluginName);
|
|
1799
|
-
if (existingResolver) return existingResolver;
|
|
1800
|
-
const resolver = defineResolver(() => ({
|
|
1801
|
-
name: "default",
|
|
1802
|
-
pluginName
|
|
1803
|
-
}));
|
|
1804
|
-
this.#defaultResolvers.set(pluginName, resolver);
|
|
1805
|
-
return resolver;
|
|
1806
|
-
}
|
|
1807
|
-
setPluginResolver(pluginName, partial) {
|
|
1808
|
-
const merged = {
|
|
1809
|
-
...this.#createDefaultResolver(pluginName),
|
|
1810
|
-
...partial
|
|
1811
|
-
};
|
|
1812
|
-
this.#resolvers.set(pluginName, merged);
|
|
1813
|
-
const plugin = this.plugins.get(pluginName);
|
|
1814
|
-
if (plugin) plugin.resolver = merged;
|
|
1815
|
-
}
|
|
1816
|
-
getResolver(pluginName) {
|
|
1817
|
-
const dynamicResolver = this.#resolvers.get(pluginName);
|
|
1818
|
-
if (dynamicResolver) return dynamicResolver;
|
|
1819
|
-
const pluginResolver = this.plugins.get(pluginName)?.resolver;
|
|
1820
|
-
if (pluginResolver) return pluginResolver;
|
|
1821
|
-
return this.#createDefaultResolver(pluginName);
|
|
1822
|
-
}
|
|
1823
|
-
getContext(plugin) {
|
|
1824
|
-
const driver = this;
|
|
1825
|
-
const baseContext = {
|
|
1826
|
-
config: driver.config,
|
|
1827
|
-
get root() {
|
|
1828
|
-
return (0, node_path.resolve)(driver.config.root, driver.config.output.path);
|
|
1829
|
-
},
|
|
1830
|
-
getMode(output) {
|
|
1831
|
-
return getMode((0, node_path.resolve)(driver.config.root, driver.config.output.path, output.path));
|
|
1832
|
-
},
|
|
1833
|
-
hooks: driver.hooks,
|
|
1834
|
-
plugin,
|
|
1835
|
-
getPlugin: driver.getPlugin.bind(driver),
|
|
1836
|
-
requirePlugin: driver.requirePlugin.bind(driver),
|
|
1837
|
-
driver,
|
|
1838
|
-
addFile: async (...files) => {
|
|
1839
|
-
driver.fileManager.add(...files);
|
|
1840
|
-
},
|
|
1841
|
-
upsertFile: async (...files) => {
|
|
1842
|
-
driver.fileManager.upsert(...files);
|
|
1843
|
-
},
|
|
1844
|
-
get inputNode() {
|
|
1845
|
-
return driver.inputNode;
|
|
1846
|
-
},
|
|
1847
|
-
get adapter() {
|
|
1848
|
-
return driver.adapter;
|
|
1849
|
-
},
|
|
1850
|
-
get resolver() {
|
|
1851
|
-
return driver.getResolver(plugin.name);
|
|
1852
|
-
},
|
|
1853
|
-
get transformer() {
|
|
1854
|
-
return plugin.transformer;
|
|
1855
|
-
},
|
|
1856
|
-
warn(message) {
|
|
1857
|
-
driver.hooks.emit("kubb:warn", message);
|
|
1858
|
-
},
|
|
1859
|
-
error(error) {
|
|
1860
|
-
driver.hooks.emit("kubb:error", typeof error === "string" ? new Error(error) : error);
|
|
1861
|
-
},
|
|
1862
|
-
info(message) {
|
|
1863
|
-
driver.hooks.emit("kubb:info", message);
|
|
1864
|
-
},
|
|
1865
|
-
openInStudio(options) {
|
|
1866
|
-
if (!driver.config.devtools || driver.#studioIsOpen) return;
|
|
1867
|
-
if (typeof driver.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
1868
|
-
if (!driver.inputNode || !driver.adapter) throw new Error("adapter is not defined, make sure you have set the parser in kubb.config.ts");
|
|
1869
|
-
driver.#studioIsOpen = true;
|
|
1870
|
-
const studioUrl = driver.config.devtools?.studioUrl ?? "https://studio.kubb.dev";
|
|
1871
|
-
return openInStudio(driver.inputNode, studioUrl, options);
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
let mergedExtras = {};
|
|
1875
|
-
for (const p of this.plugins.values()) if (typeof p.inject === "function") {
|
|
1876
|
-
const result = p.inject.call(baseContext);
|
|
1877
|
-
if (result !== null && typeof result === "object") mergedExtras = {
|
|
1878
|
-
...mergedExtras,
|
|
1879
|
-
...result
|
|
1880
|
-
};
|
|
1881
|
-
}
|
|
1882
|
-
return {
|
|
1883
|
-
...baseContext,
|
|
1884
|
-
...mergedExtras
|
|
1885
|
-
};
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* @deprecated use resolvers context instead
|
|
1889
|
-
*/
|
|
1890
|
-
getFile({ name, mode, extname, pluginName, options }) {
|
|
1891
|
-
const resolvedName = mode ? mode === "single" ? "" : this.resolveName({
|
|
1892
|
-
name,
|
|
1893
|
-
pluginName,
|
|
1894
|
-
type: "file"
|
|
1895
|
-
}) : name;
|
|
1896
|
-
const path = this.resolvePath({
|
|
1897
|
-
baseName: `${resolvedName}${extname}`,
|
|
1898
|
-
mode,
|
|
1899
|
-
pluginName,
|
|
1900
|
-
options
|
|
1901
|
-
});
|
|
1902
|
-
if (!path) throw new Error(`Filepath should be defined for resolvedName "${resolvedName}" and pluginName "${pluginName}"`);
|
|
1903
|
-
return (0, _kubb_ast.createFile)({
|
|
1904
|
-
path,
|
|
1905
|
-
baseName: (0, node_path.basename)(path),
|
|
1906
|
-
meta: { pluginName },
|
|
1907
|
-
sources: [],
|
|
1908
|
-
imports: [],
|
|
1909
|
-
exports: []
|
|
1910
|
-
});
|
|
1911
|
-
}
|
|
1912
|
-
/**
|
|
1913
|
-
* @deprecated use resolvers context instead
|
|
1914
|
-
*/
|
|
1915
|
-
resolvePath = (params) => {
|
|
1916
|
-
const defaultPath = (0, node_path.resolve)((0, node_path.resolve)(this.config.root, this.config.output.path), params.baseName);
|
|
1917
|
-
if (params.pluginName) return this.hookForPluginSync({
|
|
1918
|
-
pluginName: params.pluginName,
|
|
1919
|
-
hookName: "resolvePath",
|
|
1920
|
-
parameters: [
|
|
1921
|
-
params.baseName,
|
|
1922
|
-
params.mode,
|
|
1923
|
-
params.options
|
|
1924
|
-
]
|
|
1925
|
-
})?.at(0) || defaultPath;
|
|
1926
|
-
return this.hookFirstSync({
|
|
1927
|
-
hookName: "resolvePath",
|
|
1928
|
-
parameters: [
|
|
1929
|
-
params.baseName,
|
|
1930
|
-
params.mode,
|
|
1931
|
-
params.options
|
|
1932
|
-
]
|
|
1933
|
-
})?.result || defaultPath;
|
|
1934
|
-
};
|
|
1935
|
-
/**
|
|
1936
|
-
* @deprecated use resolvers context instead
|
|
1937
|
-
*/
|
|
1938
|
-
resolveName = (params) => {
|
|
1939
|
-
if (params.pluginName) return transformReservedWord(this.hookForPluginSync({
|
|
1940
|
-
pluginName: params.pluginName,
|
|
1941
|
-
hookName: "resolveName",
|
|
1942
|
-
parameters: [params.name.trim(), params.type]
|
|
1943
|
-
})?.at(0) ?? params.name);
|
|
1944
|
-
const name = this.hookFirstSync({
|
|
1945
|
-
hookName: "resolveName",
|
|
1946
|
-
parameters: [params.name.trim(), params.type]
|
|
1947
|
-
})?.result;
|
|
1948
|
-
return transformReservedWord(name ?? params.name);
|
|
1949
|
-
};
|
|
1950
|
-
/**
|
|
1951
|
-
* Run a specific hookName for plugin x.
|
|
1952
|
-
*/
|
|
1953
|
-
async hookForPlugin({ pluginName, hookName, parameters }) {
|
|
1954
|
-
const plugin = this.plugins.get(pluginName);
|
|
1955
|
-
if (!plugin) return [null];
|
|
1956
|
-
this.hooks.emit("kubb:plugins:hook:progress:start", {
|
|
1957
|
-
hookName,
|
|
1958
|
-
plugins: [plugin]
|
|
1959
|
-
});
|
|
1960
|
-
const result = await this.#execute({
|
|
1961
|
-
strategy: "hookFirst",
|
|
1962
|
-
hookName,
|
|
1963
|
-
parameters,
|
|
1964
|
-
plugin
|
|
1965
|
-
});
|
|
1966
|
-
this.hooks.emit("kubb:plugins:hook:progress:end", { hookName });
|
|
1967
|
-
return [result];
|
|
1968
|
-
}
|
|
1969
|
-
/**
|
|
1970
|
-
* Run a specific hookName for plugin x.
|
|
1971
|
-
*/
|
|
1972
|
-
hookForPluginSync({ pluginName, hookName, parameters }) {
|
|
1973
|
-
const plugin = this.plugins.get(pluginName);
|
|
1974
|
-
if (!plugin) return null;
|
|
1975
|
-
const result = this.#executeSync({
|
|
1976
|
-
strategy: "hookFirst",
|
|
1977
|
-
hookName,
|
|
1978
|
-
parameters,
|
|
1979
|
-
plugin
|
|
1980
|
-
});
|
|
1981
|
-
return result !== null ? [result] : [];
|
|
1982
|
-
}
|
|
1983
|
-
/**
|
|
1984
|
-
* Returns the first non-null result.
|
|
1985
|
-
*/
|
|
1986
|
-
async hookFirst({ hookName, parameters, skipped }) {
|
|
1987
|
-
const plugins = [];
|
|
1988
|
-
for (const plugin of this.plugins.values()) if (hookName in plugin && (skipped ? !skipped.has(plugin) : true)) plugins.push(plugin);
|
|
1989
|
-
this.hooks.emit("kubb:plugins:hook:progress:start", {
|
|
1990
|
-
hookName,
|
|
1991
|
-
plugins
|
|
1992
|
-
});
|
|
1993
|
-
const result = await hookFirst(plugins.map((plugin) => {
|
|
1994
|
-
return async () => {
|
|
1995
|
-
const value = await this.#execute({
|
|
1996
|
-
strategy: "hookFirst",
|
|
1997
|
-
hookName,
|
|
1998
|
-
parameters,
|
|
1999
|
-
plugin
|
|
2000
|
-
});
|
|
2001
|
-
return Promise.resolve({
|
|
2002
|
-
plugin,
|
|
2003
|
-
result: value
|
|
2004
|
-
});
|
|
2005
|
-
};
|
|
2006
|
-
}), hookFirstNullCheck);
|
|
2007
|
-
this.hooks.emit("kubb:plugins:hook:progress:end", { hookName });
|
|
2008
|
-
return result;
|
|
2009
|
-
}
|
|
2010
|
-
/**
|
|
2011
|
-
* Returns the first non-null result.
|
|
2012
|
-
*/
|
|
2013
|
-
hookFirstSync({ hookName, parameters, skipped }) {
|
|
2014
|
-
let parseResult = null;
|
|
2015
|
-
for (const plugin of this.plugins.values()) {
|
|
2016
|
-
if (!(hookName in plugin)) continue;
|
|
2017
|
-
if (skipped?.has(plugin)) continue;
|
|
2018
|
-
parseResult = {
|
|
2019
|
-
result: this.#executeSync({
|
|
2020
|
-
strategy: "hookFirst",
|
|
2021
|
-
hookName,
|
|
2022
|
-
parameters,
|
|
2023
|
-
plugin
|
|
2024
|
-
}),
|
|
2025
|
-
plugin
|
|
2026
|
-
};
|
|
2027
|
-
if (parseResult.result != null) break;
|
|
2028
|
-
}
|
|
2029
|
-
return parseResult;
|
|
2030
|
-
}
|
|
2031
|
-
/**
|
|
2032
|
-
* Runs all plugins in parallel based on `this.plugin` order and `dependencies` settings.
|
|
2033
|
-
*/
|
|
2034
|
-
async hookParallel({ hookName, parameters }) {
|
|
2035
|
-
const plugins = [];
|
|
2036
|
-
for (const plugin of this.plugins.values()) if (hookName in plugin) plugins.push(plugin);
|
|
2037
|
-
this.hooks.emit("kubb:plugins:hook:progress:start", {
|
|
2038
|
-
hookName,
|
|
2039
|
-
plugins
|
|
2040
|
-
});
|
|
2041
|
-
const pluginStartTimes = /* @__PURE__ */ new Map();
|
|
2042
|
-
const results = await hookParallel(plugins.map((plugin) => {
|
|
2043
|
-
return () => {
|
|
2044
|
-
pluginStartTimes.set(plugin, node_perf_hooks.performance.now());
|
|
2045
|
-
return this.#execute({
|
|
2046
|
-
strategy: "hookParallel",
|
|
2047
|
-
hookName,
|
|
2048
|
-
parameters,
|
|
2049
|
-
plugin
|
|
2050
|
-
});
|
|
2051
|
-
};
|
|
2052
|
-
}), this.options.concurrency);
|
|
2053
|
-
results.forEach((result, index) => {
|
|
2054
|
-
if (isPromiseRejectedResult(result)) {
|
|
2055
|
-
const plugin = plugins[index];
|
|
2056
|
-
if (plugin) {
|
|
2057
|
-
const startTime = pluginStartTimes.get(plugin) ?? node_perf_hooks.performance.now();
|
|
2058
|
-
this.hooks.emit("kubb:error", result.reason, {
|
|
2059
|
-
plugin,
|
|
2060
|
-
hookName,
|
|
2061
|
-
strategy: "hookParallel",
|
|
2062
|
-
duration: Math.round(node_perf_hooks.performance.now() - startTime),
|
|
2063
|
-
parameters
|
|
2064
|
-
});
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
});
|
|
2068
|
-
this.hooks.emit("kubb:plugins:hook:progress:end", { hookName });
|
|
2069
|
-
return results.reduce((acc, result) => {
|
|
2070
|
-
if (result.status === "fulfilled") acc.push(result.value);
|
|
2071
|
-
return acc;
|
|
2072
|
-
}, []);
|
|
2073
|
-
}
|
|
2074
|
-
/**
|
|
2075
|
-
* Execute a lifecycle hook sequentially for all plugins that implement it.
|
|
2076
|
-
*/
|
|
2077
|
-
async hookSeq({ hookName, parameters }) {
|
|
2078
|
-
const plugins = [];
|
|
2079
|
-
for (const plugin of this.plugins.values()) if (hookName in plugin) plugins.push(plugin);
|
|
2080
|
-
this.hooks.emit("kubb:plugins:hook:progress:start", {
|
|
2081
|
-
hookName,
|
|
2082
|
-
plugins
|
|
2083
|
-
});
|
|
2084
|
-
await hookSeq(plugins.map((plugin) => {
|
|
2085
|
-
return () => this.#execute({
|
|
2086
|
-
strategy: "hookSeq",
|
|
2087
|
-
hookName,
|
|
2088
|
-
parameters,
|
|
2089
|
-
plugin
|
|
2090
|
-
});
|
|
2091
|
-
}));
|
|
2092
|
-
this.hooks.emit("kubb:plugins:hook:progress:end", { hookName });
|
|
2093
|
-
}
|
|
2094
|
-
getPlugin(pluginName) {
|
|
2095
|
-
return this.plugins.get(pluginName);
|
|
2096
|
-
}
|
|
2097
|
-
requirePlugin(pluginName) {
|
|
2098
|
-
const plugin = this.plugins.get(pluginName);
|
|
2099
|
-
if (!plugin) throw new Error(`[kubb] Plugin "${pluginName}" is required but not found. Make sure it is included in your Kubb config.`);
|
|
2100
|
-
return plugin;
|
|
2101
|
-
}
|
|
2102
|
-
/**
|
|
2103
|
-
* Emit hook-processing completion metadata after a plugin hook resolves.
|
|
2104
|
-
*/
|
|
2105
|
-
#emitProcessingEnd({ startTime, output, strategy, hookName, plugin, parameters }) {
|
|
2106
|
-
this.hooks.emit("kubb:plugins:hook:processing:end", {
|
|
2107
|
-
duration: Math.round(node_perf_hooks.performance.now() - startTime),
|
|
2108
|
-
parameters,
|
|
2109
|
-
output,
|
|
2110
|
-
strategy,
|
|
2111
|
-
hookName,
|
|
2112
|
-
plugin
|
|
2113
|
-
});
|
|
2114
|
-
}
|
|
2115
|
-
#execute({ strategy, hookName, parameters, plugin }) {
|
|
2116
|
-
const hook = plugin[hookName];
|
|
2117
|
-
if (!hook) return null;
|
|
2118
|
-
this.hooks.emit("kubb:plugins:hook:processing:start", {
|
|
2119
|
-
strategy,
|
|
2120
|
-
hookName,
|
|
2121
|
-
parameters,
|
|
2122
|
-
plugin
|
|
2123
|
-
});
|
|
2124
|
-
const startTime = node_perf_hooks.performance.now();
|
|
2125
|
-
return (async () => {
|
|
2126
|
-
try {
|
|
2127
|
-
const output = typeof hook === "function" ? await Promise.resolve(hook.apply(this.getContext(plugin), parameters ?? [])) : hook;
|
|
2128
|
-
this.#emitProcessingEnd({
|
|
2129
|
-
startTime,
|
|
2130
|
-
output,
|
|
2131
|
-
strategy,
|
|
2132
|
-
hookName,
|
|
2133
|
-
plugin,
|
|
2134
|
-
parameters
|
|
2135
|
-
});
|
|
2136
|
-
return output;
|
|
2137
|
-
} catch (error) {
|
|
2138
|
-
this.hooks.emit("kubb:error", error, {
|
|
2139
|
-
plugin,
|
|
2140
|
-
hookName,
|
|
2141
|
-
strategy,
|
|
2142
|
-
duration: Math.round(node_perf_hooks.performance.now() - startTime)
|
|
2143
|
-
});
|
|
2144
|
-
return null;
|
|
2145
|
-
}
|
|
2146
|
-
})();
|
|
2147
|
-
}
|
|
2148
|
-
/**
|
|
2149
|
-
* Execute a plugin lifecycle hook synchronously and return its output.
|
|
2150
|
-
*/
|
|
2151
|
-
#executeSync({ strategy, hookName, parameters, plugin }) {
|
|
2152
|
-
const hook = plugin[hookName];
|
|
2153
|
-
if (!hook) return null;
|
|
2154
|
-
this.hooks.emit("kubb:plugins:hook:processing:start", {
|
|
2155
|
-
strategy,
|
|
2156
|
-
hookName,
|
|
2157
|
-
parameters,
|
|
2158
|
-
plugin
|
|
2159
|
-
});
|
|
2160
|
-
const startTime = node_perf_hooks.performance.now();
|
|
2161
|
-
try {
|
|
2162
|
-
const output = typeof hook === "function" ? hook.apply(this.getContext(plugin), parameters) : hook;
|
|
2163
|
-
this.#emitProcessingEnd({
|
|
2164
|
-
startTime,
|
|
2165
|
-
output,
|
|
2166
|
-
strategy,
|
|
2167
|
-
hookName,
|
|
2168
|
-
plugin,
|
|
2169
|
-
parameters
|
|
2170
|
-
});
|
|
2171
|
-
return output;
|
|
2172
|
-
} catch (error) {
|
|
2173
|
-
this.hooks.emit("kubb:error", error, {
|
|
2174
|
-
plugin,
|
|
2175
|
-
hookName,
|
|
2176
|
-
strategy,
|
|
2177
|
-
duration: Math.round(node_perf_hooks.performance.now() - startTime)
|
|
2178
|
-
});
|
|
2179
|
-
return null;
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
};
|
|
2183
|
-
//#endregion
|
|
2184
517
|
//#region src/createStorage.ts
|
|
2185
518
|
/**
|
|
2186
519
|
* Creates a storage factory. Call the returned function with optional options to get the storage instance.
|
|
@@ -2278,7 +611,7 @@ const fsStorage = createStorage(() => ({
|
|
|
2278
611
|
}));
|
|
2279
612
|
//#endregion
|
|
2280
613
|
//#region package.json
|
|
2281
|
-
var version = "5.0.0-alpha.
|
|
614
|
+
var version = "5.0.0-alpha.36";
|
|
2282
615
|
//#endregion
|
|
2283
616
|
//#region src/utils/diagnostics.ts
|
|
2284
617
|
/**
|
|
@@ -2393,14 +726,14 @@ var TreeNode = class TreeNode {
|
|
|
2393
726
|
name: filteredTree.name,
|
|
2394
727
|
path: filteredTree.path,
|
|
2395
728
|
file: filteredTree.file,
|
|
2396
|
-
type: getMode(filteredTree.path)
|
|
729
|
+
type: require_PluginDriver.getMode(filteredTree.path)
|
|
2397
730
|
});
|
|
2398
731
|
const recurse = (node, item) => {
|
|
2399
732
|
const subNode = node.addChild({
|
|
2400
733
|
name: item.name,
|
|
2401
734
|
path: item.path,
|
|
2402
735
|
file: item.file,
|
|
2403
|
-
type: getMode(item.path)
|
|
736
|
+
type: require_PluginDriver.getMode(item.path)
|
|
2404
737
|
});
|
|
2405
738
|
if (item.children?.length) item.children?.forEach((child) => {
|
|
2406
739
|
recurse(subNode, child);
|
|
@@ -2585,12 +918,12 @@ async function setup(options) {
|
|
|
2585
918
|
output: {
|
|
2586
919
|
write: true,
|
|
2587
920
|
barrelType: "named",
|
|
2588
|
-
extension: DEFAULT_EXTENSION,
|
|
2589
|
-
defaultBanner: DEFAULT_BANNER,
|
|
921
|
+
extension: require_PluginDriver.DEFAULT_EXTENSION,
|
|
922
|
+
defaultBanner: require_PluginDriver.DEFAULT_BANNER,
|
|
2590
923
|
...userConfig.output
|
|
2591
924
|
},
|
|
2592
925
|
devtools: userConfig.devtools ? {
|
|
2593
|
-
studioUrl: DEFAULT_STUDIO_URL,
|
|
926
|
+
studioUrl: require_PluginDriver.DEFAULT_STUDIO_URL,
|
|
2594
927
|
...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
|
|
2595
928
|
} : void 0,
|
|
2596
929
|
plugins: userConfig.plugins
|
|
@@ -2603,7 +936,7 @@ async function setup(options) {
|
|
|
2603
936
|
});
|
|
2604
937
|
await storage?.clear((0, node_path.resolve)(config.root, config.output.path));
|
|
2605
938
|
}
|
|
2606
|
-
const driver = new PluginDriver(config, {
|
|
939
|
+
const driver = new require_PluginDriver.PluginDriver(config, {
|
|
2607
940
|
hooks,
|
|
2608
941
|
concurrency: 15
|
|
2609
942
|
});
|
|
@@ -2666,7 +999,7 @@ async function runPluginAstHooks(plugin, context) {
|
|
|
2666
999
|
};
|
|
2667
1000
|
for (const gen of generators) {
|
|
2668
1001
|
if (!gen.schema) continue;
|
|
2669
|
-
await applyHookResult(await gen.schema(transformedNode, ctx), driver, resolveRenderer(gen));
|
|
1002
|
+
await require_PluginDriver.applyHookResult(await gen.schema(transformedNode, ctx), driver, resolveRenderer(gen));
|
|
2670
1003
|
}
|
|
2671
1004
|
await driver.hooks.emit("kubb:generate:schema", transformedNode, ctx);
|
|
2672
1005
|
},
|
|
@@ -2686,7 +1019,7 @@ async function runPluginAstHooks(plugin, context) {
|
|
|
2686
1019
|
};
|
|
2687
1020
|
for (const gen of generators) {
|
|
2688
1021
|
if (!gen.operation) continue;
|
|
2689
|
-
await applyHookResult(await gen.operation(transformedNode, ctx), driver, resolveRenderer(gen));
|
|
1022
|
+
await require_PluginDriver.applyHookResult(await gen.operation(transformedNode, ctx), driver, resolveRenderer(gen));
|
|
2690
1023
|
}
|
|
2691
1024
|
await driver.hooks.emit("kubb:generate:operation", transformedNode, ctx);
|
|
2692
1025
|
}
|
|
@@ -2699,7 +1032,7 @@ async function runPluginAstHooks(plugin, context) {
|
|
|
2699
1032
|
};
|
|
2700
1033
|
for (const gen of generators) {
|
|
2701
1034
|
if (!gen.operations) continue;
|
|
2702
|
-
await applyHookResult(await gen.operations(collectedOperations, ctx), driver, resolveRenderer(gen));
|
|
1035
|
+
await require_PluginDriver.applyHookResult(await gen.operations(collectedOperations, ctx), driver, resolveRenderer(gen));
|
|
2703
1036
|
}
|
|
2704
1037
|
await driver.hooks.emit("kubb:generate:operations", collectedOperations, ctx);
|
|
2705
1038
|
}
|
|
@@ -2776,7 +1109,7 @@ async function safeBuild(setupResult) {
|
|
|
2776
1109
|
}
|
|
2777
1110
|
}
|
|
2778
1111
|
if (config.output.barrelType) {
|
|
2779
|
-
const rootPath = (0, node_path.resolve)((0, node_path.resolve)(config.root), config.output.path, BARREL_FILENAME);
|
|
1112
|
+
const rootPath = (0, node_path.resolve)((0, node_path.resolve)(config.root), config.output.path, require_PluginDriver.BARREL_FILENAME);
|
|
2780
1113
|
const rootDir = (0, node_path.dirname)(rootPath);
|
|
2781
1114
|
await hooks.emit("kubb:debug", {
|
|
2782
1115
|
date: /* @__PURE__ */ new Date(),
|
|
@@ -2796,7 +1129,7 @@ async function safeBuild(setupResult) {
|
|
|
2796
1129
|
const existingBarrel = driver.fileManager.files.find((f) => f.path === rootPath);
|
|
2797
1130
|
const rootFile = (0, _kubb_ast.createFile)({
|
|
2798
1131
|
path: rootPath,
|
|
2799
|
-
baseName: BARREL_FILENAME,
|
|
1132
|
+
baseName: require_PluginDriver.BARREL_FILENAME,
|
|
2800
1133
|
exports: buildBarrelExports({
|
|
2801
1134
|
barrelFiles,
|
|
2802
1135
|
rootDir,
|
|
@@ -3382,8 +1715,10 @@ function satisfiesDependency(dependency, version, cwd) {
|
|
|
3382
1715
|
}
|
|
3383
1716
|
//#endregion
|
|
3384
1717
|
exports.AsyncEventEmitter = AsyncEventEmitter;
|
|
1718
|
+
exports.FileManager = require_PluginDriver.FileManager;
|
|
1719
|
+
exports.FileProcessor = FileProcessor;
|
|
3385
1720
|
exports.FunctionParams = FunctionParams;
|
|
3386
|
-
exports.PluginDriver = PluginDriver;
|
|
1721
|
+
exports.PluginDriver = require_PluginDriver.PluginDriver;
|
|
3387
1722
|
exports.URLPath = URLPath;
|
|
3388
1723
|
Object.defineProperty(exports, "ast", {
|
|
3389
1724
|
enumerable: true,
|
|
@@ -3391,7 +1726,7 @@ Object.defineProperty(exports, "ast", {
|
|
|
3391
1726
|
return _kubb_ast;
|
|
3392
1727
|
}
|
|
3393
1728
|
});
|
|
3394
|
-
exports.buildDefaultBanner = buildDefaultBanner;
|
|
1729
|
+
exports.buildDefaultBanner = require_PluginDriver.buildDefaultBanner;
|
|
3395
1730
|
Object.defineProperty(exports, "composeTransformers", {
|
|
3396
1731
|
enumerable: true,
|
|
3397
1732
|
get: function() {
|
|
@@ -3404,32 +1739,32 @@ exports.createKubb = createKubb;
|
|
|
3404
1739
|
exports.createPlugin = createPlugin;
|
|
3405
1740
|
exports.createRenderer = createRenderer;
|
|
3406
1741
|
exports.createStorage = createStorage;
|
|
3407
|
-
exports.defaultResolveBanner = defaultResolveBanner;
|
|
3408
|
-
exports.defaultResolveFile = defaultResolveFile;
|
|
3409
|
-
exports.defaultResolveFooter = defaultResolveFooter;
|
|
3410
|
-
exports.defaultResolveOptions = defaultResolveOptions;
|
|
3411
|
-
exports.defaultResolvePath = defaultResolvePath;
|
|
1742
|
+
exports.defaultResolveBanner = require_PluginDriver.defaultResolveBanner;
|
|
1743
|
+
exports.defaultResolveFile = require_PluginDriver.defaultResolveFile;
|
|
1744
|
+
exports.defaultResolveFooter = require_PluginDriver.defaultResolveFooter;
|
|
1745
|
+
exports.defaultResolveOptions = require_PluginDriver.defaultResolveOptions;
|
|
1746
|
+
exports.defaultResolvePath = require_PluginDriver.defaultResolvePath;
|
|
3412
1747
|
exports.defineGenerator = defineGenerator;
|
|
3413
1748
|
exports.defineLogger = defineLogger;
|
|
3414
1749
|
exports.defineParser = defineParser;
|
|
3415
|
-
exports.definePlugin = definePlugin;
|
|
1750
|
+
exports.definePlugin = require_PluginDriver.definePlugin;
|
|
3416
1751
|
Object.defineProperty(exports, "definePrinter", {
|
|
3417
1752
|
enumerable: true,
|
|
3418
1753
|
get: function() {
|
|
3419
1754
|
return _kubb_ast.definePrinter;
|
|
3420
1755
|
}
|
|
3421
1756
|
});
|
|
3422
|
-
exports.defineResolver = defineResolver;
|
|
1757
|
+
exports.defineResolver = require_PluginDriver.defineResolver;
|
|
3423
1758
|
exports.detectFormatter = detectFormatter;
|
|
3424
1759
|
exports.detectLinter = detectLinter;
|
|
3425
|
-
exports.formatters = formatters;
|
|
1760
|
+
exports.formatters = require_PluginDriver.formatters;
|
|
3426
1761
|
exports.fsStorage = fsStorage;
|
|
3427
1762
|
exports.getBarrelFiles = getBarrelFiles;
|
|
3428
1763
|
exports.getFunctionParams = getFunctionParams;
|
|
3429
|
-
exports.getMode = getMode;
|
|
1764
|
+
exports.getMode = require_PluginDriver.getMode;
|
|
3430
1765
|
exports.isInputPath = isInputPath;
|
|
3431
|
-
exports.linters = linters;
|
|
3432
|
-
exports.logLevel = logLevel;
|
|
1766
|
+
exports.linters = require_PluginDriver.linters;
|
|
1767
|
+
exports.logLevel = require_PluginDriver.logLevel;
|
|
3433
1768
|
exports.memoryStorage = memoryStorage;
|
|
3434
1769
|
exports.satisfiesDependency = satisfiesDependency;
|
|
3435
1770
|
|