@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.
Files changed (47) hide show
  1. package/dist/{types-D30QAz2y.d.ts → PluginDriver-BkFepPdm.d.ts} +354 -291
  2. package/dist/hooks.cjs +85 -8
  3. package/dist/hooks.cjs.map +1 -1
  4. package/dist/hooks.d.ts +66 -4
  5. package/dist/hooks.js +83 -8
  6. package/dist/hooks.js.map +1 -1
  7. package/dist/index.cjs +346 -315
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +91 -77
  10. package/dist/index.js +338 -305
  11. package/dist/index.js.map +1 -1
  12. package/package.json +7 -7
  13. package/src/Kubb.ts +27 -55
  14. package/src/{PluginManager.ts → PluginDriver.ts} +69 -82
  15. package/src/build.ts +32 -33
  16. package/src/constants.ts +1 -1
  17. package/src/createAdapter.ts +25 -0
  18. package/src/createPlugin.ts +28 -0
  19. package/src/createStorage.ts +58 -0
  20. package/src/defineGenerator.ts +134 -0
  21. package/src/defineLogger.ts +13 -3
  22. package/src/defineResolver.ts +131 -0
  23. package/src/hooks/index.ts +2 -1
  24. package/src/hooks/useKubb.ts +143 -0
  25. package/src/hooks/useMode.ts +5 -2
  26. package/src/hooks/usePlugin.ts +5 -2
  27. package/src/hooks/usePluginDriver.ts +11 -0
  28. package/src/index.ts +7 -7
  29. package/src/storages/fsStorage.ts +2 -2
  30. package/src/storages/memoryStorage.ts +2 -2
  31. package/src/types.ts +94 -48
  32. package/src/utils/FunctionParams.ts +2 -2
  33. package/src/utils/TreeNode.ts +1 -1
  34. package/src/utils/formatters.ts +1 -1
  35. package/src/utils/getBarrelFiles.ts +73 -11
  36. package/src/utils/getConfigs.ts +3 -21
  37. package/src/utils/linters.ts +1 -1
  38. package/src/utils/packageJSON.ts +61 -0
  39. package/src/BarrelManager.ts +0 -74
  40. package/src/PackageManager.ts +0 -180
  41. package/src/PromiseManager.ts +0 -40
  42. package/src/defineAdapter.ts +0 -22
  43. package/src/definePlugin.ts +0 -12
  44. package/src/defineStorage.ts +0 -56
  45. package/src/errors.ts +0 -1
  46. package/src/hooks/usePluginManager.ts +0 -8
  47. 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 node_module = require("node:module");
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.includes(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
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/PromiseManager.ts
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.default.extname(fileOrFolder) ? "single" : "split";
950
+ return (0, node_path.extname)(fileOrFolder) ? "single" : "split";
963
951
  }
964
- var PluginManager = class {
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 pluginManager = this;
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
- pluginManager: this,
997
- mode: getMode(node_path.default.resolve(this.config.root, this.config.output.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 pluginManager.rootNode;
993
+ return driver.rootNode;
994
+ },
995
+ get adapter() {
996
+ return driver.adapter;
1006
997
  },
1007
998
  openInStudio(options) {
1008
- if (typeof pluginManager.config.devtools !== "object") throw new Error("Devtools must be an object");
1009
- if (!pluginManager.rootNode) throw new Error("RootNode is not defined, make sure you have set the parser in kubb.config.ts");
1010
- if (pluginManager.#studioIsOpen) return;
1011
- pluginManager.#studioIsOpen = true;
1012
- const studioUrl = pluginManager.config.devtools?.studioUrl ?? "https://studio.kubb.dev";
1013
- return openInStudio(pluginManager.rootNode, studioUrl, options);
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, pluginKey, options }) {
1030
- const baseName = `${name}${extname}`;
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
- pluginKey,
1029
+ pluginName,
1035
1030
  options
1036
1031
  });
1037
- if (!path) throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
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: { pluginKey },
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 root = node_path.default.resolve(this.config.root, this.config.output.path);
1049
- const defaultPath = node_path.default.resolve(root, params.baseName);
1050
- if (params.pluginKey) return this.hookForPluginSync({
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.pluginKey) {
1063
+ if (params.pluginName) {
1070
1064
  const names = this.hookForPluginSync({
1071
- pluginKey: params.pluginKey,
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({ pluginKey, hookName, parameters }) {
1087
- const plugins = this.getPluginsByKey(hookName, pluginKey);
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({ pluginKey, hookName, parameters }) {
1109
- return this.getPluginsByKey(hookName, pluginKey).map((plugin) => {
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 promises = plugins.map((plugin) => {
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 promises = plugins.map((plugin) => {
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
- const promises = plugins.map((plugin) => {
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
- const missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
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
- getPluginByKey(pluginKey) {
1248
- const plugins = [...this.#plugins];
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
- getPluginsByKey(hookName, pluginKey) {
1242
+ getPluginsByName(hookName, pluginName) {
1256
1243
  const plugins = [...this.plugins];
1257
- const [searchPluginName, searchIdentifier] = pluginKey;
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) this.events.emit("warn", `Multiple instances of plugin "${plugin.name}" detected. This behavior is deprecated and will be removed in v5.`, `Plugin key: [${plugin.name}, ${usageCount}]`);
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/defineStorage.ts
1349
+ //#region src/createStorage.ts
1371
1350
  /**
1372
- * Wraps a storage builder so the `options` argument is optional, following the
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
- * ```ts
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() { return [...store.keys()] },
1391
- * async clear() { store.clear() },
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 defineStorage(build) {
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 = defineStorage(() => ({
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 = "4.36.1";
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 pluginManager = new PluginManager(definedConfig, {
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
- pluginManager.rootNode = await definedConfig.adapter.parse(source);
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: ${pluginManager.rootNode.schemas.length}`,
1603
- ` • Operations: ${pluginManager.rootNode.operations.length}`
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
- pluginManager,
1585
+ driver: pluginDriver,
1611
1586
  sources
1612
1587
  };
1613
1588
  }
1614
1589
  async function build(options, overrides) {
1615
- const { fabric, files, pluginManager, failedPlugins, pluginTimings, error, sources } = await safeBuild(options, overrides);
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
- pluginManager,
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, pluginManager, events, sources } = overrides ? overrides : await setup(options);
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 = pluginManager.config;
1610
+ const config = driver.config;
1636
1611
  try {
1637
- for (const plugin of pluginManager.plugins) {
1638
- const context = pluginManager.getContext(plugin);
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 Key: [${plugin.key.join(", ")}]`]
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 Key: ${JSON.stringify(plugin.key)}`,
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
- pluginManager
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
- pluginManager,
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
- pluginManager,
1713
+ driver,
1739
1714
  pluginTimings,
1740
1715
  error,
1741
1716
  sources
1742
1717
  };
1743
1718
  }
1744
1719
  }
1745
- function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }) {
1746
- const pluginKeyMap = /* @__PURE__ */ new Map();
1747
- for (const plugin of pluginManager.plugins) pluginKeyMap.set(JSON.stringify(plugin.key), plugin);
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?.pluginKey ? pluginKeyMap.get(JSON.stringify(meta.pluginKey)) : void 0)?.options;
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/defineAdapter.ts
1759
+ //#region src/createAdapter.ts
1785
1760
  /**
1786
- * Wraps an adapter builder to make the options parameter optional.
1761
+ * Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
1787
1762
  *
1788
1763
  * @example
1789
- * ```ts
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: adapterOasName,
1794
- * options: { validate, dateType, ... },
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 defineAdapter(build) {
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 { ...logger };
1844
+ return logger;
1807
1845
  }
1808
1846
  //#endregion
1809
- //#region src/definePlugin.ts
1847
+ //#region src/defineResolver.ts
1810
1848
  /**
1811
- * Wraps a plugin builder to make the options parameter optional.
1849
+ * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).
1812
1850
  */
1813
- function definePlugin(build) {
1814
- return (options) => build(options ?? {});
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
- //#endregion
1817
- //#region src/PackageManager.ts
1818
- var PackageManager = class PackageManager {
1819
- static #cache = {};
1820
- #cwd;
1821
- constructor(workspace) {
1822
- if (workspace) this.#cwd = workspace;
1823
- }
1824
- set workspace(workspace) {
1825
- this.#cwd = workspace;
1826
- }
1827
- get workspace() {
1828
- return this.#cwd;
1829
- }
1830
- normalizeDirectory(directory) {
1831
- const lastChar = directory[directory.length - 1];
1832
- if (lastChar && !PATH_SEPARATORS.includes(lastChar)) return `${directory}/`;
1833
- return directory;
1834
- }
1835
- getLocation(path) {
1836
- let location = path;
1837
- if (this.#cwd) location = node_module.default.createRequire(this.normalizeDirectory(this.#cwd)).resolve(path);
1838
- return location;
1839
- }
1840
- async import(path) {
1841
- let location = this.getLocation(path);
1842
- if (node_os.default.platform() === "win32") location = (0, node_url.pathToFileURL)(location).href;
1843
- const module = await import(location);
1844
- return module?.default ?? module;
1845
- }
1846
- async getPackageJSON() {
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 = defineStorage(() => {
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
- for (const formatter of [
2096
+ const formatterNames = new Set([
2065
2097
  "biome",
2066
2098
  "oxfmt",
2067
2099
  "prettier"
2068
- ]) if (await isFormatterAvailable(formatter)) return formatter;
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/BarrelManager.ts
2224
+ //#region src/utils/getBarrelFiles.ts
2192
2225
  /** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
2193
- var BarrelManager = class {
2194
- getFiles({ files: generatedFiles, root }) {
2195
- const cachedFiles = /* @__PURE__ */ new Map();
2196
- TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
2197
- if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
2198
- const barrelFile = {
2199
- path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
2200
- baseName: "index.ts",
2201
- exports: [],
2202
- imports: [],
2203
- sources: []
2204
- };
2205
- const previousBarrelFile = cachedFiles.get(barrelFile.path);
2206
- treeNode.leaves.forEach((item) => {
2207
- if (!item.data.name) return;
2208
- (item.data.file?.sources || []).forEach((source) => {
2209
- if (!item.data.file?.path || !source.isIndexable || !source.name) return;
2210
- if (previousBarrelFile?.sources.some((item) => item.name === source.name && item.isTypeOnly === source.isTypeOnly)) return;
2211
- barrelFile.exports.push({
2212
- name: [source.name],
2213
- path: getRelativePath(treeNode.parent?.data.path, item.data.path),
2214
- isTypeOnly: source.isTypeOnly
2215
- });
2216
- barrelFile.sources.push({
2217
- name: source.name,
2218
- isTypeOnly: source.isTypeOnly,
2219
- value: "",
2220
- isExportable: false,
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
- return [...cachedFiles.values()];
2231
- }
2232
- };
2233
- //#endregion
2234
- //#region src/utils/getBarrelFiles.ts
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 = barrelManager.getFiles({
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
- let userConfigs = await (typeof config === "function" ? Promise.resolve(config(args)) : Promise.resolve(config));
2288
- if (!Array.isArray(userConfigs)) userConfigs = [userConfigs];
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
- for (const linter of [
2312
+ const linterNames = new Set([
2311
2313
  "biome",
2312
2314
  "oxlint",
2313
2315
  "eslint"
2314
- ]) if (await isLinterAvailable(linter)) return linter;
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.PackageManager = PackageManager;
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.defineAdapter = defineAdapter;
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.defineStorage = defineStorage;
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