@kubb/core 4.36.1 → 5.0.0-alpha.10
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/{types-D30QAz2y.d.ts → PluginDriver-BkFepPdm.d.ts} +354 -291
- package/dist/hooks.cjs +85 -8
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +66 -4
- package/dist/hooks.js +83 -8
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +346 -315
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +91 -77
- package/dist/index.js +338 -305
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/Kubb.ts +27 -55
- package/src/{PluginManager.ts → PluginDriver.ts} +69 -82
- package/src/build.ts +32 -33
- package/src/constants.ts +1 -1
- package/src/createAdapter.ts +25 -0
- package/src/createPlugin.ts +28 -0
- package/src/createStorage.ts +58 -0
- package/src/defineGenerator.ts +134 -0
- package/src/defineLogger.ts +13 -3
- package/src/defineResolver.ts +131 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useKubb.ts +143 -0
- package/src/hooks/useMode.ts +5 -2
- package/src/hooks/usePlugin.ts +5 -2
- package/src/hooks/usePluginDriver.ts +11 -0
- package/src/index.ts +7 -7
- package/src/storages/fsStorage.ts +2 -2
- package/src/storages/memoryStorage.ts +2 -2
- package/src/types.ts +94 -48
- package/src/utils/FunctionParams.ts +2 -2
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/formatters.ts +1 -1
- package/src/utils/getBarrelFiles.ts +73 -11
- package/src/utils/getConfigs.ts +3 -21
- package/src/utils/linters.ts +1 -1
- package/src/utils/packageJSON.ts +61 -0
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PromiseManager.ts +0 -40
- package/src/defineAdapter.ts +0 -22
- package/src/definePlugin.ts +0 -12
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/usePluginManager.ts +0 -8
- package/src/utils/getPlugins.ts +0 -23
package/dist/index.cjs
CHANGED
|
@@ -3,13 +3,13 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
6
|
+
let _kubb_ast = require("@kubb/ast");
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
node_path = require_chunk.__toESM(node_path);
|
|
6
9
|
let node_events = require("node:events");
|
|
7
10
|
let node_util = require("node:util");
|
|
8
11
|
let node_fs = require("node:fs");
|
|
9
12
|
let node_fs_promises = require("node:fs/promises");
|
|
10
|
-
let node_path = require("node:path");
|
|
11
|
-
node_path = require_chunk.__toESM(node_path);
|
|
12
|
-
let _kubb_ast = require("@kubb/ast");
|
|
13
13
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
14
14
|
let _kubb_react_fabric_parsers = require("@kubb/react-fabric/parsers");
|
|
15
15
|
let _kubb_react_fabric_plugins = require("@kubb/react-fabric/plugins");
|
|
@@ -17,15 +17,10 @@ let node_perf_hooks = require("node:perf_hooks");
|
|
|
17
17
|
let fflate = require("fflate");
|
|
18
18
|
let tinyexec = require("tinyexec");
|
|
19
19
|
let node_process = require("node:process");
|
|
20
|
-
let
|
|
21
|
-
node_module = require_chunk.__toESM(node_module);
|
|
22
|
-
let node_os = require("node:os");
|
|
23
|
-
node_os = require_chunk.__toESM(node_os);
|
|
24
|
-
let node_url = require("node:url");
|
|
20
|
+
let remeda = require("remeda");
|
|
25
21
|
let empathic_package = require("empathic/package");
|
|
26
22
|
empathic_package = require_chunk.__toESM(empathic_package);
|
|
27
23
|
let semver = require("semver");
|
|
28
|
-
let remeda = require("remeda");
|
|
29
24
|
//#region ../../internals/utils/dist/index.js
|
|
30
25
|
/** Thrown when a plugin's configuration or input fails validation. */
|
|
31
26
|
var ValidationPluginError = class extends Error {};
|
|
@@ -142,6 +137,21 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
142
137
|
} : {}));
|
|
143
138
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
144
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Converts `text` to PascalCase.
|
|
142
|
+
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* pascalCase('hello-world') // 'HelloWorld'
|
|
146
|
+
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
147
|
+
*/
|
|
148
|
+
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
149
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
150
|
+
prefix,
|
|
151
|
+
suffix
|
|
152
|
+
}) : camelCase(part));
|
|
153
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
154
|
+
}
|
|
145
155
|
/** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
|
|
146
156
|
function defineCLIAdapter(adapter) {
|
|
147
157
|
return adapter;
|
|
@@ -391,14 +401,6 @@ async function exists(path) {
|
|
|
391
401
|
if (typeof Bun !== "undefined") return Bun.file(path).exists();
|
|
392
402
|
return (0, node_fs_promises.access)(path).then(() => true, () => false);
|
|
393
403
|
}
|
|
394
|
-
/**
|
|
395
|
-
* Reads the file at `path` as a UTF-8 string.
|
|
396
|
-
* Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
|
|
397
|
-
*/
|
|
398
|
-
async function read(path) {
|
|
399
|
-
if (typeof Bun !== "undefined") return Bun.file(path).text();
|
|
400
|
-
return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
|
|
401
|
-
}
|
|
402
404
|
/** Synchronous counterpart of `read`. */
|
|
403
405
|
function readSync(path) {
|
|
404
406
|
return (0, node_fs.readFileSync)(path, { encoding: "utf8" });
|
|
@@ -453,11 +455,15 @@ function setUniqueName(originalName, data) {
|
|
|
453
455
|
data[originalName] = 1;
|
|
454
456
|
return originalName;
|
|
455
457
|
}
|
|
458
|
+
/** Type guard for a rejected `Promise.allSettled` result with a typed `reason`. */
|
|
459
|
+
function isPromiseRejectedResult(result) {
|
|
460
|
+
return result.status === "rejected";
|
|
461
|
+
}
|
|
456
462
|
/**
|
|
457
463
|
* JavaScript and Java reserved words.
|
|
458
464
|
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
459
465
|
*/
|
|
460
|
-
const reservedWords = [
|
|
466
|
+
const reservedWords = new Set([
|
|
461
467
|
"abstract",
|
|
462
468
|
"arguments",
|
|
463
469
|
"boolean",
|
|
@@ -539,14 +545,14 @@ const reservedWords = [
|
|
|
539
545
|
"toString",
|
|
540
546
|
"undefined",
|
|
541
547
|
"valueOf"
|
|
542
|
-
];
|
|
548
|
+
]);
|
|
543
549
|
/**
|
|
544
550
|
* Prefixes a word with `_` when it is a reserved JavaScript/Java identifier
|
|
545
551
|
* or starts with a digit.
|
|
546
552
|
*/
|
|
547
553
|
function transformReservedWord(word) {
|
|
548
554
|
const firstChar = word.charCodeAt(0);
|
|
549
|
-
if (word && (reservedWords.
|
|
555
|
+
if (word && (reservedWords.has(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
|
|
550
556
|
return word;
|
|
551
557
|
}
|
|
552
558
|
/**
|
|
@@ -678,7 +684,6 @@ const DEFAULT_STUDIO_URL = "https://studio.kubb.dev";
|
|
|
678
684
|
const BARREL_FILENAME = "index.ts";
|
|
679
685
|
const DEFAULT_BANNER = "simple";
|
|
680
686
|
const DEFAULT_EXTENSION = { ".ts": ".ts" };
|
|
681
|
-
const PATH_SEPARATORS = ["/", "\\"];
|
|
682
687
|
const logLevel = {
|
|
683
688
|
silent: Number.NEGATIVE_INFINITY,
|
|
684
689
|
error: 0,
|
|
@@ -939,29 +944,13 @@ function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
|
939
944
|
return Promise.allSettled(tasks);
|
|
940
945
|
}
|
|
941
946
|
//#endregion
|
|
942
|
-
//#region src/
|
|
943
|
-
var PromiseManager = class {
|
|
944
|
-
#options = {};
|
|
945
|
-
constructor(options = {}) {
|
|
946
|
-
this.#options = options;
|
|
947
|
-
}
|
|
948
|
-
run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
|
|
949
|
-
if (strategy === "seq") return hookSeq(promises);
|
|
950
|
-
if (strategy === "first") return hookFirst(promises, this.#options.nullCheck);
|
|
951
|
-
if (strategy === "parallel") return hookParallel(promises, concurrency);
|
|
952
|
-
throw new Error(`${strategy} not implemented`);
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
function isPromiseRejectedResult(result) {
|
|
956
|
-
return result.status === "rejected";
|
|
957
|
-
}
|
|
958
|
-
//#endregion
|
|
959
|
-
//#region src/PluginManager.ts
|
|
947
|
+
//#region src/PluginDriver.ts
|
|
960
948
|
function getMode(fileOrFolder) {
|
|
961
949
|
if (!fileOrFolder) return "split";
|
|
962
|
-
return node_path.
|
|
950
|
+
return (0, node_path.extname)(fileOrFolder) ? "single" : "split";
|
|
963
951
|
}
|
|
964
|
-
|
|
952
|
+
const hookFirstNullCheck = (state) => !!state?.result;
|
|
953
|
+
var PluginDriver = class {
|
|
965
954
|
config;
|
|
966
955
|
options;
|
|
967
956
|
/**
|
|
@@ -969,14 +958,13 @@ var PluginManager = class {
|
|
|
969
958
|
* the build pipeline after the adapter's `parse()` resolves.
|
|
970
959
|
*/
|
|
971
960
|
rootNode = void 0;
|
|
961
|
+
adapter = void 0;
|
|
972
962
|
#studioIsOpen = false;
|
|
973
963
|
#plugins = /* @__PURE__ */ new Set();
|
|
974
964
|
#usedPluginNames = {};
|
|
975
|
-
#promiseManager;
|
|
976
965
|
constructor(config, options) {
|
|
977
966
|
this.config = config;
|
|
978
967
|
this.options = options;
|
|
979
|
-
this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
|
|
980
968
|
[...config.plugins || []].forEach((plugin) => {
|
|
981
969
|
const parsedPlugin = this.#parse(plugin);
|
|
982
970
|
this.#plugins.add(parsedPlugin);
|
|
@@ -987,14 +975,14 @@ var PluginManager = class {
|
|
|
987
975
|
}
|
|
988
976
|
getContext(plugin) {
|
|
989
977
|
const plugins = [...this.#plugins];
|
|
990
|
-
const
|
|
978
|
+
const driver = this;
|
|
991
979
|
const baseContext = {
|
|
992
980
|
fabric: this.options.fabric,
|
|
993
981
|
config: this.config,
|
|
994
982
|
plugin,
|
|
995
983
|
events: this.options.events,
|
|
996
|
-
|
|
997
|
-
mode: getMode(node_path.
|
|
984
|
+
driver: this,
|
|
985
|
+
mode: getMode((0, node_path.resolve)(this.config.root, this.config.output.path)),
|
|
998
986
|
addFile: async (...files) => {
|
|
999
987
|
await this.options.fabric.addFile(...files);
|
|
1000
988
|
},
|
|
@@ -1002,15 +990,18 @@ var PluginManager = class {
|
|
|
1002
990
|
await this.options.fabric.upsertFile(...files);
|
|
1003
991
|
},
|
|
1004
992
|
get rootNode() {
|
|
1005
|
-
return
|
|
993
|
+
return driver.rootNode;
|
|
994
|
+
},
|
|
995
|
+
get adapter() {
|
|
996
|
+
return driver.adapter;
|
|
1006
997
|
},
|
|
1007
998
|
openInStudio(options) {
|
|
1008
|
-
if (
|
|
1009
|
-
if (
|
|
1010
|
-
if (
|
|
1011
|
-
|
|
1012
|
-
const studioUrl =
|
|
1013
|
-
return openInStudio(
|
|
999
|
+
if (!driver.config.devtools || driver.#studioIsOpen) return;
|
|
1000
|
+
if (typeof driver.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
1001
|
+
if (!driver.rootNode || !driver.adapter) throw new Error("adapter is not defined, make sure you have set the parser in kubb.config.ts");
|
|
1002
|
+
driver.#studioIsOpen = true;
|
|
1003
|
+
const studioUrl = driver.config.devtools?.studioUrl ?? "https://studio.kubb.dev";
|
|
1004
|
+
return openInStudio(driver.rootNode, studioUrl, options);
|
|
1014
1005
|
}
|
|
1015
1006
|
};
|
|
1016
1007
|
const mergedExtras = {};
|
|
@@ -1026,29 +1017,32 @@ var PluginManager = class {
|
|
|
1026
1017
|
get plugins() {
|
|
1027
1018
|
return this.#getSortedPlugins();
|
|
1028
1019
|
}
|
|
1029
|
-
getFile({ name, mode, extname,
|
|
1030
|
-
const
|
|
1020
|
+
getFile({ name, mode, extname, pluginName, options }) {
|
|
1021
|
+
const resolvedName = mode ? mode === "single" ? "" : this.resolveName({
|
|
1022
|
+
name,
|
|
1023
|
+
pluginName,
|
|
1024
|
+
type: "file"
|
|
1025
|
+
}) : name;
|
|
1031
1026
|
const path = this.resolvePath({
|
|
1032
|
-
baseName
|
|
1027
|
+
baseName: `${resolvedName}${extname}`,
|
|
1033
1028
|
mode,
|
|
1034
|
-
|
|
1029
|
+
pluginName,
|
|
1035
1030
|
options
|
|
1036
1031
|
});
|
|
1037
|
-
if (!path) throw new Error(`Filepath should be defined for resolvedName "${
|
|
1032
|
+
if (!path) throw new Error(`Filepath should be defined for resolvedName "${resolvedName}" and pluginName "${pluginName}"`);
|
|
1038
1033
|
return {
|
|
1039
1034
|
path,
|
|
1040
|
-
baseName,
|
|
1041
|
-
meta: {
|
|
1035
|
+
baseName: (0, node_path.basename)(path),
|
|
1036
|
+
meta: { pluginName },
|
|
1042
1037
|
sources: [],
|
|
1043
1038
|
imports: [],
|
|
1044
1039
|
exports: []
|
|
1045
1040
|
};
|
|
1046
1041
|
}
|
|
1047
1042
|
resolvePath = (params) => {
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
pluginKey: params.pluginKey,
|
|
1043
|
+
const defaultPath = (0, node_path.resolve)((0, node_path.resolve)(this.config.root, this.config.output.path), params.baseName);
|
|
1044
|
+
if (params.pluginName) return this.hookForPluginSync({
|
|
1045
|
+
pluginName: params.pluginName,
|
|
1052
1046
|
hookName: "resolvePath",
|
|
1053
1047
|
parameters: [
|
|
1054
1048
|
params.baseName,
|
|
@@ -1066,9 +1060,9 @@ var PluginManager = class {
|
|
|
1066
1060
|
})?.result || defaultPath;
|
|
1067
1061
|
};
|
|
1068
1062
|
resolveName = (params) => {
|
|
1069
|
-
if (params.
|
|
1063
|
+
if (params.pluginName) {
|
|
1070
1064
|
const names = this.hookForPluginSync({
|
|
1071
|
-
|
|
1065
|
+
pluginName: params.pluginName,
|
|
1072
1066
|
hookName: "resolveName",
|
|
1073
1067
|
parameters: [params.name.trim(), params.type]
|
|
1074
1068
|
});
|
|
@@ -1083,8 +1077,8 @@ var PluginManager = class {
|
|
|
1083
1077
|
/**
|
|
1084
1078
|
* Run a specific hookName for plugin x.
|
|
1085
1079
|
*/
|
|
1086
|
-
async hookForPlugin({
|
|
1087
|
-
const plugins = this.
|
|
1080
|
+
async hookForPlugin({ pluginName, hookName, parameters }) {
|
|
1081
|
+
const plugins = this.getPluginsByName(hookName, pluginName);
|
|
1088
1082
|
this.events.emit("plugins:hook:progress:start", {
|
|
1089
1083
|
hookName,
|
|
1090
1084
|
plugins
|
|
@@ -1105,8 +1099,8 @@ var PluginManager = class {
|
|
|
1105
1099
|
/**
|
|
1106
1100
|
* Run a specific hookName for plugin x.
|
|
1107
1101
|
*/
|
|
1108
|
-
hookForPluginSync({
|
|
1109
|
-
return this.
|
|
1102
|
+
hookForPluginSync({ pluginName, hookName, parameters }) {
|
|
1103
|
+
return this.getPluginsByName(hookName, pluginName).map((plugin) => {
|
|
1110
1104
|
return this.#executeSync({
|
|
1111
1105
|
strategy: "hookFirst",
|
|
1112
1106
|
hookName,
|
|
@@ -1126,7 +1120,7 @@ var PluginManager = class {
|
|
|
1126
1120
|
hookName,
|
|
1127
1121
|
plugins
|
|
1128
1122
|
});
|
|
1129
|
-
const
|
|
1123
|
+
const result = await hookFirst(plugins.map((plugin) => {
|
|
1130
1124
|
return async () => {
|
|
1131
1125
|
const value = await this.#execute({
|
|
1132
1126
|
strategy: "hookFirst",
|
|
@@ -1139,8 +1133,7 @@ var PluginManager = class {
|
|
|
1139
1133
|
result: value
|
|
1140
1134
|
});
|
|
1141
1135
|
};
|
|
1142
|
-
});
|
|
1143
|
-
const result = await this.#promiseManager.run("first", promises);
|
|
1136
|
+
}), hookFirstNullCheck);
|
|
1144
1137
|
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1145
1138
|
return result;
|
|
1146
1139
|
}
|
|
@@ -1176,7 +1169,7 @@ var PluginManager = class {
|
|
|
1176
1169
|
plugins
|
|
1177
1170
|
});
|
|
1178
1171
|
const pluginStartTimes = /* @__PURE__ */ new Map();
|
|
1179
|
-
const
|
|
1172
|
+
const results = await hookParallel(plugins.map((plugin) => {
|
|
1180
1173
|
return () => {
|
|
1181
1174
|
pluginStartTimes.set(plugin, node_perf_hooks.performance.now());
|
|
1182
1175
|
return this.#execute({
|
|
@@ -1186,8 +1179,7 @@ var PluginManager = class {
|
|
|
1186
1179
|
plugin
|
|
1187
1180
|
});
|
|
1188
1181
|
};
|
|
1189
|
-
});
|
|
1190
|
-
const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
|
|
1182
|
+
}), this.options.concurrency);
|
|
1191
1183
|
results.forEach((result, index) => {
|
|
1192
1184
|
if (isPromiseRejectedResult(result)) {
|
|
1193
1185
|
const plugin = this.#getSortedPlugins(hookName)[index];
|
|
@@ -1218,15 +1210,14 @@ var PluginManager = class {
|
|
|
1218
1210
|
hookName,
|
|
1219
1211
|
plugins
|
|
1220
1212
|
});
|
|
1221
|
-
|
|
1213
|
+
await hookSeq(plugins.map((plugin) => {
|
|
1222
1214
|
return () => this.#execute({
|
|
1223
1215
|
strategy: "hookSeq",
|
|
1224
1216
|
hookName,
|
|
1225
1217
|
parameters,
|
|
1226
1218
|
plugin
|
|
1227
1219
|
});
|
|
1228
|
-
});
|
|
1229
|
-
await this.#promiseManager.run("seq", promises);
|
|
1220
|
+
}));
|
|
1230
1221
|
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1231
1222
|
}
|
|
1232
1223
|
#getSortedPlugins(hookName) {
|
|
@@ -1234,7 +1225,8 @@ var PluginManager = class {
|
|
|
1234
1225
|
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
1235
1226
|
return plugins.map((plugin) => {
|
|
1236
1227
|
if (plugin.pre) {
|
|
1237
|
-
|
|
1228
|
+
let missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1229
|
+
if (missingPlugins.includes("plugin-oas") && this.adapter) missingPlugins = missingPlugins.filter((pluginName) => pluginName !== "plugin-oas");
|
|
1238
1230
|
if (missingPlugins.length > 0) throw new ValidationPluginError(`The plugin '${plugin.name}' has a pre set that references missing plugins for '${missingPlugins.join(", ")}'`);
|
|
1239
1231
|
}
|
|
1240
1232
|
return plugin;
|
|
@@ -1244,24 +1236,12 @@ var PluginManager = class {
|
|
|
1244
1236
|
return 0;
|
|
1245
1237
|
});
|
|
1246
1238
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
const [searchPluginName] = pluginKey;
|
|
1250
|
-
return plugins.find((item) => {
|
|
1251
|
-
const [name] = item.key;
|
|
1252
|
-
return name === searchPluginName;
|
|
1253
|
-
});
|
|
1239
|
+
getPluginByName(pluginName) {
|
|
1240
|
+
return [...this.#plugins].find((item) => item.name === pluginName);
|
|
1254
1241
|
}
|
|
1255
|
-
|
|
1242
|
+
getPluginsByName(hookName, pluginName) {
|
|
1256
1243
|
const plugins = [...this.plugins];
|
|
1257
|
-
const
|
|
1258
|
-
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
|
|
1259
|
-
const [name, identifier] = item.key;
|
|
1260
|
-
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1261
|
-
const nameCheck = name === searchPluginName;
|
|
1262
|
-
if (searchIdentifier) return identifierCheck && nameCheck;
|
|
1263
|
-
return nameCheck;
|
|
1264
|
-
});
|
|
1244
|
+
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => item.name === pluginName);
|
|
1265
1245
|
if (!pluginByPluginName?.length) {
|
|
1266
1246
|
const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
|
|
1267
1247
|
return corePlugin ? [corePlugin] : [];
|
|
@@ -1358,28 +1338,20 @@ var PluginManager = class {
|
|
|
1358
1338
|
const usedPluginNames = this.#usedPluginNames;
|
|
1359
1339
|
setUniqueName(plugin.name, usedPluginNames);
|
|
1360
1340
|
const usageCount = usedPluginNames[plugin.name];
|
|
1361
|
-
if (usageCount && usageCount > 1)
|
|
1341
|
+
if (usageCount && usageCount > 1) throw new ValidationPluginError(`Duplicate plugin "${plugin.name}" detected. Each plugin can only be used once. Use a different configuration instead of adding multiple instances of the same plugin.`);
|
|
1362
1342
|
return {
|
|
1363
1343
|
install() {},
|
|
1364
|
-
...plugin
|
|
1365
|
-
key: [plugin.name, usedPluginNames[plugin.name]].filter(Boolean)
|
|
1344
|
+
...plugin
|
|
1366
1345
|
};
|
|
1367
1346
|
}
|
|
1368
1347
|
};
|
|
1369
1348
|
//#endregion
|
|
1370
|
-
//#region src/
|
|
1349
|
+
//#region src/createStorage.ts
|
|
1371
1350
|
/**
|
|
1372
|
-
*
|
|
1373
|
-
* same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`.
|
|
1374
|
-
*
|
|
1375
|
-
* The builder receives the resolved options object and must return a
|
|
1376
|
-
* `DefineStorage`-compatible object that includes a `name` string.
|
|
1351
|
+
* Creates a storage factory. Call the returned function with optional options to get the storage instance.
|
|
1377
1352
|
*
|
|
1378
1353
|
* @example
|
|
1379
|
-
*
|
|
1380
|
-
* import { defineStorage } from '@kubb/core'
|
|
1381
|
-
*
|
|
1382
|
-
* export const memoryStorage = defineStorage((_options) => {
|
|
1354
|
+
* export const memoryStorage = createStorage(() => {
|
|
1383
1355
|
* const store = new Map<string, string>()
|
|
1384
1356
|
* return {
|
|
1385
1357
|
* name: 'memory',
|
|
@@ -1387,13 +1359,15 @@ var PluginManager = class {
|
|
|
1387
1359
|
* async getItem(key) { return store.get(key) ?? null },
|
|
1388
1360
|
* async setItem(key, value) { store.set(key, value) },
|
|
1389
1361
|
* async removeItem(key) { store.delete(key) },
|
|
1390
|
-
* async getKeys() {
|
|
1391
|
-
*
|
|
1362
|
+
* async getKeys(base) {
|
|
1363
|
+
* const keys = [...store.keys()]
|
|
1364
|
+
* return base ? keys.filter((k) => k.startsWith(base)) : keys
|
|
1365
|
+
* },
|
|
1366
|
+
* async clear(base) { if (!base) store.clear() },
|
|
1392
1367
|
* }
|
|
1393
1368
|
* })
|
|
1394
|
-
* ```
|
|
1395
1369
|
*/
|
|
1396
|
-
function
|
|
1370
|
+
function createStorage(build) {
|
|
1397
1371
|
return (options) => build(options ?? {});
|
|
1398
1372
|
}
|
|
1399
1373
|
//#endregion
|
|
@@ -1421,7 +1395,7 @@ function defineStorage(build) {
|
|
|
1421
1395
|
* })
|
|
1422
1396
|
* ```
|
|
1423
1397
|
*/
|
|
1424
|
-
const fsStorage =
|
|
1398
|
+
const fsStorage = createStorage(() => ({
|
|
1425
1399
|
name: "fs",
|
|
1426
1400
|
async hasItem(key) {
|
|
1427
1401
|
try {
|
|
@@ -1469,7 +1443,7 @@ const fsStorage = defineStorage(() => ({
|
|
|
1469
1443
|
}));
|
|
1470
1444
|
//#endregion
|
|
1471
1445
|
//#region package.json
|
|
1472
|
-
var version = "
|
|
1446
|
+
var version = "5.0.0-alpha.10";
|
|
1473
1447
|
//#endregion
|
|
1474
1448
|
//#region src/utils/diagnostics.ts
|
|
1475
1449
|
/**
|
|
@@ -1583,7 +1557,7 @@ async function setup(options) {
|
|
|
1583
1557
|
` • Barrel type: ${definedConfig.output.barrelType || "none"}`
|
|
1584
1558
|
]
|
|
1585
1559
|
});
|
|
1586
|
-
const
|
|
1560
|
+
const pluginDriver = new PluginDriver(definedConfig, {
|
|
1587
1561
|
fabric,
|
|
1588
1562
|
events,
|
|
1589
1563
|
concurrency: 15
|
|
@@ -1594,25 +1568,26 @@ async function setup(options) {
|
|
|
1594
1568
|
date: /* @__PURE__ */ new Date(),
|
|
1595
1569
|
logs: [`Running adapter: ${definedConfig.adapter.name}`]
|
|
1596
1570
|
});
|
|
1597
|
-
|
|
1571
|
+
pluginDriver.adapter = definedConfig.adapter;
|
|
1572
|
+
pluginDriver.rootNode = await definedConfig.adapter.parse(source);
|
|
1598
1573
|
await events.emit("debug", {
|
|
1599
1574
|
date: /* @__PURE__ */ new Date(),
|
|
1600
1575
|
logs: [
|
|
1601
1576
|
`✓ Adapter '${definedConfig.adapter.name}' resolved RootNode`,
|
|
1602
|
-
` • Schemas: ${
|
|
1603
|
-
` • Operations: ${
|
|
1577
|
+
` • Schemas: ${pluginDriver.rootNode.schemas.length}`,
|
|
1578
|
+
` • Operations: ${pluginDriver.rootNode.operations.length}`
|
|
1604
1579
|
]
|
|
1605
1580
|
});
|
|
1606
1581
|
}
|
|
1607
1582
|
return {
|
|
1608
1583
|
events,
|
|
1609
1584
|
fabric,
|
|
1610
|
-
|
|
1585
|
+
driver: pluginDriver,
|
|
1611
1586
|
sources
|
|
1612
1587
|
};
|
|
1613
1588
|
}
|
|
1614
1589
|
async function build(options, overrides) {
|
|
1615
|
-
const { fabric, files,
|
|
1590
|
+
const { fabric, files, driver, failedPlugins, pluginTimings, error, sources } = await safeBuild(options, overrides);
|
|
1616
1591
|
if (error) throw error;
|
|
1617
1592
|
if (failedPlugins.size > 0) {
|
|
1618
1593
|
const errors = [...failedPlugins].map(({ error }) => error);
|
|
@@ -1622,20 +1597,20 @@ async function build(options, overrides) {
|
|
|
1622
1597
|
failedPlugins,
|
|
1623
1598
|
fabric,
|
|
1624
1599
|
files,
|
|
1625
|
-
|
|
1600
|
+
driver,
|
|
1626
1601
|
pluginTimings,
|
|
1627
1602
|
error: void 0,
|
|
1628
1603
|
sources
|
|
1629
1604
|
};
|
|
1630
1605
|
}
|
|
1631
1606
|
async function safeBuild(options, overrides) {
|
|
1632
|
-
const { fabric,
|
|
1607
|
+
const { fabric, driver, events, sources } = overrides ? overrides : await setup(options);
|
|
1633
1608
|
const failedPlugins = /* @__PURE__ */ new Set();
|
|
1634
1609
|
const pluginTimings = /* @__PURE__ */ new Map();
|
|
1635
|
-
const config =
|
|
1610
|
+
const config = driver.config;
|
|
1636
1611
|
try {
|
|
1637
|
-
for (const plugin of
|
|
1638
|
-
const context =
|
|
1612
|
+
for (const plugin of driver.plugins) {
|
|
1613
|
+
const context = driver.getContext(plugin);
|
|
1639
1614
|
const hrStart = process.hrtime();
|
|
1640
1615
|
const installer = plugin.install.bind(context);
|
|
1641
1616
|
try {
|
|
@@ -1643,7 +1618,7 @@ async function safeBuild(options, overrides) {
|
|
|
1643
1618
|
await events.emit("plugin:start", plugin);
|
|
1644
1619
|
await events.emit("debug", {
|
|
1645
1620
|
date: timestamp,
|
|
1646
|
-
logs: ["Installing plugin...", ` • Plugin
|
|
1621
|
+
logs: ["Installing plugin...", ` • Plugin Name: ${plugin.name}`]
|
|
1647
1622
|
});
|
|
1648
1623
|
await installer(context);
|
|
1649
1624
|
const duration = getElapsedMs(hrStart);
|
|
@@ -1669,7 +1644,7 @@ async function safeBuild(options, overrides) {
|
|
|
1669
1644
|
date: errorTimestamp,
|
|
1670
1645
|
logs: [
|
|
1671
1646
|
"✗ Plugin installation failed",
|
|
1672
|
-
` • Plugin
|
|
1647
|
+
` • Plugin Name: ${plugin.name}`,
|
|
1673
1648
|
` • Error: ${error.constructor.name} - ${error.message}`,
|
|
1674
1649
|
" • Stack Trace:",
|
|
1675
1650
|
error.stack || "No stack trace available"
|
|
@@ -1708,7 +1683,7 @@ async function safeBuild(options, overrides) {
|
|
|
1708
1683
|
rootDir,
|
|
1709
1684
|
existingExports: new Set(existingBarrel?.exports?.flatMap((e) => Array.isArray(e.name) ? e.name : [e.name]).filter((n) => Boolean(n)) ?? []),
|
|
1710
1685
|
config,
|
|
1711
|
-
|
|
1686
|
+
driver
|
|
1712
1687
|
}),
|
|
1713
1688
|
sources: [],
|
|
1714
1689
|
imports: [],
|
|
@@ -1726,7 +1701,7 @@ async function safeBuild(options, overrides) {
|
|
|
1726
1701
|
failedPlugins,
|
|
1727
1702
|
fabric,
|
|
1728
1703
|
files,
|
|
1729
|
-
|
|
1704
|
+
driver,
|
|
1730
1705
|
pluginTimings,
|
|
1731
1706
|
sources
|
|
1732
1707
|
};
|
|
@@ -1735,22 +1710,22 @@ async function safeBuild(options, overrides) {
|
|
|
1735
1710
|
failedPlugins,
|
|
1736
1711
|
fabric,
|
|
1737
1712
|
files: [],
|
|
1738
|
-
|
|
1713
|
+
driver,
|
|
1739
1714
|
pluginTimings,
|
|
1740
1715
|
error,
|
|
1741
1716
|
sources
|
|
1742
1717
|
};
|
|
1743
1718
|
}
|
|
1744
1719
|
}
|
|
1745
|
-
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config,
|
|
1746
|
-
const
|
|
1747
|
-
for (const plugin of
|
|
1720
|
+
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, driver }) {
|
|
1721
|
+
const pluginNameMap = /* @__PURE__ */ new Map();
|
|
1722
|
+
for (const plugin of driver.plugins) pluginNameMap.set(plugin.name, plugin);
|
|
1748
1723
|
return barrelFiles.flatMap((file) => {
|
|
1749
1724
|
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
|
|
1750
1725
|
return (file.sources ?? []).flatMap((source) => {
|
|
1751
1726
|
if (!file.path || !source.isIndexable) return [];
|
|
1752
1727
|
const meta = file.meta;
|
|
1753
|
-
const pluginOptions = (meta?.
|
|
1728
|
+
const pluginOptions = (meta?.pluginName ? pluginNameMap.get(meta.pluginName) : void 0)?.options;
|
|
1754
1729
|
if (!pluginOptions || pluginOptions.output?.barrelType === false) return [];
|
|
1755
1730
|
const exportName = config.output.barrelType === "all" ? void 0 : source.name ? [source.name] : void 0;
|
|
1756
1731
|
if (exportName?.some((n) => existingExports.has(n))) return [];
|
|
@@ -1781,121 +1756,178 @@ function inputToAdapterSource(config) {
|
|
|
1781
1756
|
};
|
|
1782
1757
|
}
|
|
1783
1758
|
//#endregion
|
|
1784
|
-
//#region src/
|
|
1759
|
+
//#region src/createAdapter.ts
|
|
1785
1760
|
/**
|
|
1786
|
-
*
|
|
1761
|
+
* Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
|
|
1787
1762
|
*
|
|
1788
1763
|
* @example
|
|
1789
|
-
*
|
|
1790
|
-
* export const adapterOas = defineAdapter<OasAdapter>((options) => {
|
|
1791
|
-
* const { validate = true, dateType = 'string' } = options
|
|
1764
|
+
* export const myAdapter = createAdapter<MyAdapter>((options) => {
|
|
1792
1765
|
* return {
|
|
1793
|
-
* name:
|
|
1794
|
-
* options
|
|
1795
|
-
* parse(source) { ... },
|
|
1766
|
+
* name: 'my-adapter',
|
|
1767
|
+
* options,
|
|
1768
|
+
* async parse(source) { ... },
|
|
1796
1769
|
* }
|
|
1797
1770
|
* })
|
|
1798
|
-
*
|
|
1771
|
+
*
|
|
1772
|
+
* // instantiate
|
|
1773
|
+
* const adapter = myAdapter({ validate: true })
|
|
1774
|
+
*/
|
|
1775
|
+
function createAdapter(build) {
|
|
1776
|
+
return (options) => build(options ?? {});
|
|
1777
|
+
}
|
|
1778
|
+
//#endregion
|
|
1779
|
+
//#region src/createPlugin.ts
|
|
1780
|
+
/**
|
|
1781
|
+
* Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
|
|
1782
|
+
*
|
|
1783
|
+
* @example
|
|
1784
|
+
* export const myPlugin = createPlugin<MyPlugin>((options) => {
|
|
1785
|
+
* return {
|
|
1786
|
+
* name: 'my-plugin',
|
|
1787
|
+
* options,
|
|
1788
|
+
* resolvePath(baseName) { ... },
|
|
1789
|
+
* resolveName(name, type) { ... },
|
|
1790
|
+
* }
|
|
1791
|
+
* })
|
|
1792
|
+
*
|
|
1793
|
+
* // instantiate
|
|
1794
|
+
* const plugin = myPlugin({ output: { path: 'src/gen' } })
|
|
1799
1795
|
*/
|
|
1800
|
-
function
|
|
1796
|
+
function createPlugin(build) {
|
|
1801
1797
|
return (options) => build(options ?? {});
|
|
1802
1798
|
}
|
|
1803
1799
|
//#endregion
|
|
1800
|
+
//#region src/defineGenerator.ts
|
|
1801
|
+
function defineGenerator(generator) {
|
|
1802
|
+
if (generator.type === "react") return {
|
|
1803
|
+
version: "2",
|
|
1804
|
+
Operations() {
|
|
1805
|
+
return null;
|
|
1806
|
+
},
|
|
1807
|
+
Operation() {
|
|
1808
|
+
return null;
|
|
1809
|
+
},
|
|
1810
|
+
Schema() {
|
|
1811
|
+
return null;
|
|
1812
|
+
},
|
|
1813
|
+
...generator
|
|
1814
|
+
};
|
|
1815
|
+
return {
|
|
1816
|
+
version: "2",
|
|
1817
|
+
async operations() {
|
|
1818
|
+
return [];
|
|
1819
|
+
},
|
|
1820
|
+
async operation() {
|
|
1821
|
+
return [];
|
|
1822
|
+
},
|
|
1823
|
+
async schema() {
|
|
1824
|
+
return [];
|
|
1825
|
+
},
|
|
1826
|
+
...generator
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
//#endregion
|
|
1804
1830
|
//#region src/defineLogger.ts
|
|
1831
|
+
/**
|
|
1832
|
+
* Wraps a logger definition into a typed {@link Logger}.
|
|
1833
|
+
*
|
|
1834
|
+
* @example
|
|
1835
|
+
* export const myLogger = defineLogger({
|
|
1836
|
+
* name: 'my-logger',
|
|
1837
|
+
* install(context, options) {
|
|
1838
|
+
* context.on('info', (message) => console.log('ℹ', message))
|
|
1839
|
+
* context.on('error', (error) => console.error('✗', error.message))
|
|
1840
|
+
* },
|
|
1841
|
+
* })
|
|
1842
|
+
*/
|
|
1805
1843
|
function defineLogger(logger) {
|
|
1806
|
-
return
|
|
1844
|
+
return logger;
|
|
1807
1845
|
}
|
|
1808
1846
|
//#endregion
|
|
1809
|
-
//#region src/
|
|
1847
|
+
//#region src/defineResolver.ts
|
|
1810
1848
|
/**
|
|
1811
|
-
*
|
|
1849
|
+
* Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).
|
|
1812
1850
|
*/
|
|
1813
|
-
function
|
|
1814
|
-
|
|
1851
|
+
function matchesOperationPattern(node, type, pattern) {
|
|
1852
|
+
switch (type) {
|
|
1853
|
+
case "tag": return node.tags.some((tag) => !!tag.match(pattern));
|
|
1854
|
+
case "operationId": return !!node.operationId.match(pattern);
|
|
1855
|
+
case "path": return !!node.path.match(pattern);
|
|
1856
|
+
case "method": return !!node.method.toLowerCase().match(pattern);
|
|
1857
|
+
default: return false;
|
|
1858
|
+
}
|
|
1815
1859
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
if (
|
|
1843
|
-
const
|
|
1844
|
-
return
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
const pkgPath = empathic_package.up({ cwd: this.#cwd });
|
|
1848
|
-
if (!pkgPath) return;
|
|
1849
|
-
const json = await read(pkgPath);
|
|
1850
|
-
return JSON.parse(json);
|
|
1851
|
-
}
|
|
1852
|
-
getPackageJSONSync() {
|
|
1853
|
-
const pkgPath = empathic_package.up({ cwd: this.#cwd });
|
|
1854
|
-
if (!pkgPath) return;
|
|
1855
|
-
const json = readSync(pkgPath);
|
|
1856
|
-
return JSON.parse(json);
|
|
1857
|
-
}
|
|
1858
|
-
static setVersion(dependency, version) {
|
|
1859
|
-
PackageManager.#cache[dependency] = version;
|
|
1860
|
-
}
|
|
1861
|
-
#match(packageJSON, dependency) {
|
|
1862
|
-
const dependencies = {
|
|
1863
|
-
...packageJSON.dependencies || {},
|
|
1864
|
-
...packageJSON.devDependencies || {}
|
|
1860
|
+
/**
|
|
1861
|
+
* Checks if a schema matches a pattern for a given filter type (`schemaName`).
|
|
1862
|
+
* Returns `null` when the filter type doesn't apply to schemas.
|
|
1863
|
+
*/
|
|
1864
|
+
function matchesSchemaPattern(node, type, pattern) {
|
|
1865
|
+
switch (type) {
|
|
1866
|
+
case "schemaName": return node.name ? !!node.name.match(pattern) : false;
|
|
1867
|
+
default: return null;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Default name resolver — `camelCase` for most types, `PascalCase` for `type`.
|
|
1872
|
+
*/
|
|
1873
|
+
function defaultResolver(name, type) {
|
|
1874
|
+
let resolvedName = camelCase(name);
|
|
1875
|
+
if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
|
|
1876
|
+
if (type === "type") resolvedName = pascalCase(name);
|
|
1877
|
+
return resolvedName;
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Default option resolver — applies include/exclude filters and merges any matching override options.
|
|
1881
|
+
* Returns `null` when the node is filtered out.
|
|
1882
|
+
*/
|
|
1883
|
+
function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
|
|
1884
|
+
if ((0, _kubb_ast.isOperationNode)(node)) {
|
|
1885
|
+
if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
1886
|
+
if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
1887
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
|
|
1888
|
+
return {
|
|
1889
|
+
...options,
|
|
1890
|
+
...overrideOptions
|
|
1865
1891
|
};
|
|
1866
|
-
if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
|
|
1867
|
-
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
1868
|
-
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
1869
|
-
}
|
|
1870
|
-
async getVersion(dependency) {
|
|
1871
|
-
if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
|
|
1872
|
-
const packageJSON = await this.getPackageJSON();
|
|
1873
|
-
if (!packageJSON) return;
|
|
1874
|
-
return this.#match(packageJSON, dependency);
|
|
1875
|
-
}
|
|
1876
|
-
getVersionSync(dependency) {
|
|
1877
|
-
if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
|
|
1878
|
-
const packageJSON = this.getPackageJSONSync();
|
|
1879
|
-
if (!packageJSON) return;
|
|
1880
|
-
return this.#match(packageJSON, dependency);
|
|
1881
|
-
}
|
|
1882
|
-
async isValid(dependency, version) {
|
|
1883
|
-
const packageVersion = await this.getVersion(dependency);
|
|
1884
|
-
if (!packageVersion) return false;
|
|
1885
|
-
if (packageVersion === version) return true;
|
|
1886
|
-
const semVer = (0, semver.coerce)(packageVersion);
|
|
1887
|
-
if (!semVer) return false;
|
|
1888
|
-
return (0, semver.satisfies)(semVer, version);
|
|
1889
|
-
}
|
|
1890
|
-
isValidSync(dependency, version) {
|
|
1891
|
-
const packageVersion = this.getVersionSync(dependency);
|
|
1892
|
-
if (!packageVersion) return false;
|
|
1893
|
-
if (packageVersion === version) return true;
|
|
1894
|
-
const semVer = (0, semver.coerce)(packageVersion);
|
|
1895
|
-
if (!semVer) return false;
|
|
1896
|
-
return (0, semver.satisfies)(semVer, version);
|
|
1897
1892
|
}
|
|
1898
|
-
|
|
1893
|
+
if ((0, _kubb_ast.isSchemaNode)(node)) {
|
|
1894
|
+
if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
|
|
1895
|
+
if (include) {
|
|
1896
|
+
const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
|
|
1897
|
+
if (applicable.length > 0 && !applicable.includes(true)) return null;
|
|
1898
|
+
}
|
|
1899
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
|
|
1900
|
+
return {
|
|
1901
|
+
...options,
|
|
1902
|
+
...overrideOptions
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
return options;
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Defines a resolver for a plugin, with built-in defaults for name casing and include/exclude/override filtering.
|
|
1909
|
+
* Override `default` or `resolveOptions` in the builder to customize the behavior.
|
|
1910
|
+
*
|
|
1911
|
+
* @example
|
|
1912
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
1913
|
+
* resolveName(name) {
|
|
1914
|
+
* return this.default(name, 'function')
|
|
1915
|
+
* },
|
|
1916
|
+
* resolveTypedName(name) {
|
|
1917
|
+
* return this.default(name, 'type')
|
|
1918
|
+
* },
|
|
1919
|
+
* resolveParamName(node, param) {
|
|
1920
|
+
* return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
|
|
1921
|
+
* },
|
|
1922
|
+
* }))
|
|
1923
|
+
*/
|
|
1924
|
+
function defineResolver(build) {
|
|
1925
|
+
return {
|
|
1926
|
+
default: defaultResolver,
|
|
1927
|
+
resolveOptions: defaultResolveOptions,
|
|
1928
|
+
...build()
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1899
1931
|
//#endregion
|
|
1900
1932
|
//#region src/storages/memoryStorage.ts
|
|
1901
1933
|
/**
|
|
@@ -1915,7 +1947,7 @@ var PackageManager = class PackageManager {
|
|
|
1915
1947
|
* })
|
|
1916
1948
|
* ```
|
|
1917
1949
|
*/
|
|
1918
|
-
const memoryStorage =
|
|
1950
|
+
const memoryStorage = createStorage(() => {
|
|
1919
1951
|
const store = /* @__PURE__ */ new Map();
|
|
1920
1952
|
return {
|
|
1921
1953
|
name: "memory",
|
|
@@ -1947,7 +1979,7 @@ const memoryStorage = defineStorage(() => {
|
|
|
1947
1979
|
//#endregion
|
|
1948
1980
|
//#region src/utils/FunctionParams.ts
|
|
1949
1981
|
/**
|
|
1950
|
-
* @deprecated
|
|
1982
|
+
* @deprecated use ast package instead
|
|
1951
1983
|
*/
|
|
1952
1984
|
var FunctionParams = class FunctionParams {
|
|
1953
1985
|
#items = [];
|
|
@@ -2061,11 +2093,12 @@ async function isFormatterAvailable(formatter) {
|
|
|
2061
2093
|
* ```
|
|
2062
2094
|
*/
|
|
2063
2095
|
async function detectFormatter() {
|
|
2064
|
-
|
|
2096
|
+
const formatterNames = new Set([
|
|
2065
2097
|
"biome",
|
|
2066
2098
|
"oxfmt",
|
|
2067
2099
|
"prettier"
|
|
2068
|
-
])
|
|
2100
|
+
]);
|
|
2101
|
+
for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
|
|
2069
2102
|
}
|
|
2070
2103
|
//#endregion
|
|
2071
2104
|
//#region src/utils/TreeNode.ts
|
|
@@ -2188,50 +2221,46 @@ function buildDirectoryTree(files, rootFolder = "") {
|
|
|
2188
2221
|
return root;
|
|
2189
2222
|
}
|
|
2190
2223
|
//#endregion
|
|
2191
|
-
//#region src/
|
|
2224
|
+
//#region src/utils/getBarrelFiles.ts
|
|
2192
2225
|
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
(item.data.file?.
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
isIndexable: false
|
|
2222
|
-
});
|
|
2226
|
+
function getBarrelFilesByRoot(root, files) {
|
|
2227
|
+
const cachedFiles = /* @__PURE__ */ new Map();
|
|
2228
|
+
TreeNode.build(files, root)?.forEach((treeNode) => {
|
|
2229
|
+
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
|
|
2230
|
+
const barrelFile = {
|
|
2231
|
+
path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
|
|
2232
|
+
baseName: "index.ts",
|
|
2233
|
+
exports: [],
|
|
2234
|
+
imports: [],
|
|
2235
|
+
sources: []
|
|
2236
|
+
};
|
|
2237
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path);
|
|
2238
|
+
treeNode.leaves.forEach((item) => {
|
|
2239
|
+
if (!item.data.name) return;
|
|
2240
|
+
(item.data.file?.sources || []).forEach((source) => {
|
|
2241
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) return;
|
|
2242
|
+
if (previousBarrelFile?.sources.some((item) => item.name === source.name && item.isTypeOnly === source.isTypeOnly)) return;
|
|
2243
|
+
barrelFile.exports.push({
|
|
2244
|
+
name: [source.name],
|
|
2245
|
+
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
2246
|
+
isTypeOnly: source.isTypeOnly
|
|
2247
|
+
});
|
|
2248
|
+
barrelFile.sources.push({
|
|
2249
|
+
name: source.name,
|
|
2250
|
+
isTypeOnly: source.isTypeOnly,
|
|
2251
|
+
value: "",
|
|
2252
|
+
isExportable: false,
|
|
2253
|
+
isIndexable: false
|
|
2223
2254
|
});
|
|
2224
2255
|
});
|
|
2225
|
-
if (previousBarrelFile) {
|
|
2226
|
-
previousBarrelFile.sources.push(...barrelFile.sources);
|
|
2227
|
-
previousBarrelFile.exports?.push(...barrelFile.exports || []);
|
|
2228
|
-
} else cachedFiles.set(barrelFile.path, barrelFile);
|
|
2229
2256
|
});
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2257
|
+
if (previousBarrelFile) {
|
|
2258
|
+
previousBarrelFile.sources.push(...barrelFile.sources);
|
|
2259
|
+
previousBarrelFile.exports?.push(...barrelFile.exports || []);
|
|
2260
|
+
} else cachedFiles.set(barrelFile.path, barrelFile);
|
|
2261
|
+
});
|
|
2262
|
+
return [...cachedFiles.values()];
|
|
2263
|
+
}
|
|
2235
2264
|
function trimExtName(text) {
|
|
2236
2265
|
const dotIndex = text.lastIndexOf(".");
|
|
2237
2266
|
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
@@ -2239,14 +2268,9 @@ function trimExtName(text) {
|
|
|
2239
2268
|
}
|
|
2240
2269
|
async function getBarrelFiles(files, { type, meta = {}, root, output }) {
|
|
2241
2270
|
if (!type || type === "propagate") return [];
|
|
2242
|
-
const barrelManager = new BarrelManager();
|
|
2243
2271
|
const pathToBuildFrom = (0, node_path.join)(root, output.path);
|
|
2244
2272
|
if (trimExtName(pathToBuildFrom).endsWith("index")) return [];
|
|
2245
|
-
const barrelFiles =
|
|
2246
|
-
files,
|
|
2247
|
-
root: pathToBuildFrom,
|
|
2248
|
-
meta
|
|
2249
|
-
});
|
|
2273
|
+
const barrelFiles = getBarrelFilesByRoot(pathToBuildFrom, files);
|
|
2250
2274
|
if (type === "all") return barrelFiles.map((file) => {
|
|
2251
2275
|
return {
|
|
2252
2276
|
...file,
|
|
@@ -2266,35 +2290,13 @@ async function getBarrelFiles(files, { type, meta = {}, root, output }) {
|
|
|
2266
2290
|
});
|
|
2267
2291
|
}
|
|
2268
2292
|
//#endregion
|
|
2269
|
-
//#region src/utils/getPlugins.ts
|
|
2270
|
-
function isJSONPlugins(plugins) {
|
|
2271
|
-
return Array.isArray(plugins) && plugins.some((plugin) => Array.isArray(plugin) && typeof plugin[0] === "string");
|
|
2272
|
-
}
|
|
2273
|
-
function isObjectPlugins(plugins) {
|
|
2274
|
-
return plugins instanceof Object && !Array.isArray(plugins);
|
|
2275
|
-
}
|
|
2276
|
-
function getPlugins(plugins) {
|
|
2277
|
-
if (isObjectPlugins(plugins)) throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
2278
|
-
if (isJSONPlugins(plugins)) throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
2279
|
-
return Promise.resolve(plugins);
|
|
2280
|
-
}
|
|
2281
|
-
//#endregion
|
|
2282
2293
|
//#region src/utils/getConfigs.ts
|
|
2283
2294
|
/**
|
|
2284
2295
|
* Converting UserConfig to Config Array without a change in the object beside the JSON convert.
|
|
2285
2296
|
*/
|
|
2286
2297
|
async function getConfigs(config, args) {
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
const results = [];
|
|
2290
|
-
for (const item of userConfigs) {
|
|
2291
|
-
const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
|
|
2292
|
-
results.push({
|
|
2293
|
-
...item,
|
|
2294
|
-
plugins
|
|
2295
|
-
});
|
|
2296
|
-
}
|
|
2297
|
-
return results;
|
|
2298
|
+
const resolved = await (typeof config === "function" ? config(args) : config);
|
|
2299
|
+
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({ ...item }));
|
|
2298
2300
|
}
|
|
2299
2301
|
//#endregion
|
|
2300
2302
|
//#region src/utils/linters.ts
|
|
@@ -2307,32 +2309,60 @@ async function isLinterAvailable(linter) {
|
|
|
2307
2309
|
}
|
|
2308
2310
|
}
|
|
2309
2311
|
async function detectLinter() {
|
|
2310
|
-
|
|
2312
|
+
const linterNames = new Set([
|
|
2311
2313
|
"biome",
|
|
2312
2314
|
"oxlint",
|
|
2313
2315
|
"eslint"
|
|
2314
|
-
])
|
|
2316
|
+
]);
|
|
2317
|
+
for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
|
|
2318
|
+
}
|
|
2319
|
+
//#endregion
|
|
2320
|
+
//#region src/utils/packageJSON.ts
|
|
2321
|
+
function getPackageJSONSync(cwd) {
|
|
2322
|
+
const pkgPath = empathic_package.up({ cwd });
|
|
2323
|
+
if (!pkgPath) return;
|
|
2324
|
+
return JSON.parse(readSync(pkgPath));
|
|
2325
|
+
}
|
|
2326
|
+
function match(packageJSON, dependency) {
|
|
2327
|
+
const dependencies = {
|
|
2328
|
+
...packageJSON.dependencies || {},
|
|
2329
|
+
...packageJSON.devDependencies || {}
|
|
2330
|
+
};
|
|
2331
|
+
if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
|
|
2332
|
+
const matched = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
2333
|
+
return matched ? dependencies[matched] : void 0;
|
|
2334
|
+
}
|
|
2335
|
+
function getVersionSync(dependency, cwd) {
|
|
2336
|
+
const packageJSON = getPackageJSONSync(cwd);
|
|
2337
|
+
return packageJSON ? match(packageJSON, dependency) : void 0;
|
|
2338
|
+
}
|
|
2339
|
+
function satisfiesDependency(dependency, version, cwd) {
|
|
2340
|
+
const packageVersion = getVersionSync(dependency, cwd);
|
|
2341
|
+
if (!packageVersion) return false;
|
|
2342
|
+
if (packageVersion === version) return true;
|
|
2343
|
+
const semVer = (0, semver.coerce)(packageVersion);
|
|
2344
|
+
if (!semVer) return false;
|
|
2345
|
+
return (0, semver.satisfies)(semVer, version);
|
|
2315
2346
|
}
|
|
2316
2347
|
//#endregion
|
|
2317
|
-
exports.AsyncEventEmitter = AsyncEventEmitter;
|
|
2318
2348
|
exports.FunctionParams = FunctionParams;
|
|
2319
|
-
exports.
|
|
2320
|
-
exports.PluginManager = PluginManager;
|
|
2321
|
-
exports.PromiseManager = PromiseManager;
|
|
2322
|
-
exports.URLPath = URLPath;
|
|
2349
|
+
exports.PluginDriver = PluginDriver;
|
|
2323
2350
|
exports.build = build;
|
|
2351
|
+
exports.createAdapter = createAdapter;
|
|
2352
|
+
exports.createPlugin = createPlugin;
|
|
2353
|
+
exports.createStorage = createStorage;
|
|
2324
2354
|
exports.default = build;
|
|
2325
|
-
exports.
|
|
2355
|
+
exports.defaultResolveOptions = defaultResolveOptions;
|
|
2326
2356
|
exports.defineConfig = defineConfig;
|
|
2357
|
+
exports.defineGenerator = defineGenerator;
|
|
2327
2358
|
exports.defineLogger = defineLogger;
|
|
2328
|
-
exports.definePlugin = definePlugin;
|
|
2329
2359
|
Object.defineProperty(exports, "definePrinter", {
|
|
2330
2360
|
enumerable: true,
|
|
2331
2361
|
get: function() {
|
|
2332
2362
|
return _kubb_ast.definePrinter;
|
|
2333
2363
|
}
|
|
2334
2364
|
});
|
|
2335
|
-
exports.
|
|
2365
|
+
exports.defineResolver = defineResolver;
|
|
2336
2366
|
exports.detectFormatter = detectFormatter;
|
|
2337
2367
|
exports.detectLinter = detectLinter;
|
|
2338
2368
|
exports.formatters = formatters;
|
|
@@ -2345,6 +2375,7 @@ exports.linters = linters;
|
|
|
2345
2375
|
exports.logLevel = logLevel;
|
|
2346
2376
|
exports.memoryStorage = memoryStorage;
|
|
2347
2377
|
exports.safeBuild = safeBuild;
|
|
2378
|
+
exports.satisfiesDependency = satisfiesDependency;
|
|
2348
2379
|
exports.setup = setup;
|
|
2349
2380
|
|
|
2350
2381
|
//# sourceMappingURL=index.cjs.map
|