@kubb/core 5.0.0-alpha.21 → 5.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PluginDriver-CEQPafXV.d.ts → PluginDriver-P920mak9.d.ts} +135 -54
- package/dist/hooks.cjs +3 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +6 -3
- package/dist/hooks.js +3 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +135 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -69
- package/dist/index.js +136 -227
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Kubb.ts +5 -5
- package/src/PluginDriver.ts +110 -154
- package/src/build.ts +11 -11
- package/src/constants.ts +2 -12
- package/src/defineGenerator.ts +29 -7
- package/src/defineResolver.ts +13 -19
- package/src/hooks/useDriver.ts +3 -0
- package/src/hooks/useMode.ts +3 -3
- package/src/index.ts +0 -2
- package/src/renderNode.tsx +9 -6
- package/src/types.ts +67 -35
- package/src/utils/TreeNode.ts +22 -7
- package/src/utils/getBarrelFiles.ts +9 -6
- package/src/utils/getConfigs.ts +1 -1
- package/src/utils/getPreset.ts +3 -3
- package/src/utils/mergeResolvers.ts +9 -1
- package/src/defineBuilder.ts +0 -26
- package/src/definePreset.ts +0 -27
package/dist/index.cjs
CHANGED
|
@@ -22,14 +22,6 @@ let empathic_package = require("empathic/package");
|
|
|
22
22
|
empathic_package = require_chunk.__toESM(empathic_package);
|
|
23
23
|
let semver = require("semver");
|
|
24
24
|
//#region ../../internals/utils/src/errors.ts
|
|
25
|
-
/** Thrown when a plugin's configuration or input fails validation.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* throw new ValidationPluginError('Invalid config: "output.path" is required')
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
var ValidationPluginError = class extends Error {};
|
|
33
25
|
/**
|
|
34
26
|
* Thrown when one or more errors occur during a Kubb build.
|
|
35
27
|
* Carries the full list of underlying errors on `errors`.
|
|
@@ -350,28 +342,6 @@ async function clean(path) {
|
|
|
350
342
|
});
|
|
351
343
|
}
|
|
352
344
|
//#endregion
|
|
353
|
-
//#region ../../internals/utils/src/names.ts
|
|
354
|
-
/**
|
|
355
|
-
* Registers `originalName` in `data` without altering the returned name.
|
|
356
|
-
* Use when you need to track usage frequency but always emit the original identifier.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```ts
|
|
360
|
-
* const seen: Record<string, number> = {}
|
|
361
|
-
* setUniqueName('Foo', seen) // 'Foo' (seen = { Foo: 1 })
|
|
362
|
-
* setUniqueName('Foo', seen) // 'Foo' (seen = { Foo: 2 })
|
|
363
|
-
* ```
|
|
364
|
-
*/
|
|
365
|
-
function setUniqueName(originalName, data) {
|
|
366
|
-
let used = data[originalName] || 0;
|
|
367
|
-
if (used) {
|
|
368
|
-
data[originalName] = ++used;
|
|
369
|
-
return originalName;
|
|
370
|
-
}
|
|
371
|
-
data[originalName] = 1;
|
|
372
|
-
return originalName;
|
|
373
|
-
}
|
|
374
|
-
//#endregion
|
|
375
345
|
//#region ../../internals/utils/src/promise.ts
|
|
376
346
|
/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.
|
|
377
347
|
*
|
|
@@ -971,6 +941,15 @@ function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
|
971
941
|
}
|
|
972
942
|
//#endregion
|
|
973
943
|
//#region src/PluginDriver.ts
|
|
944
|
+
/**
|
|
945
|
+
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* getMode('src/gen/types.ts') // 'single'
|
|
950
|
+
* getMode('src/gen/types') // 'split'
|
|
951
|
+
* ```
|
|
952
|
+
*/
|
|
974
953
|
function getMode(fileOrFolder) {
|
|
975
954
|
if (!fileOrFolder) return "split";
|
|
976
955
|
return (0, node_path.extname)(fileOrFolder) ? "single" : "split";
|
|
@@ -986,29 +965,30 @@ var PluginDriver = class {
|
|
|
986
965
|
rootNode = void 0;
|
|
987
966
|
adapter = void 0;
|
|
988
967
|
#studioIsOpen = false;
|
|
989
|
-
|
|
990
|
-
#usedPluginNames = {};
|
|
968
|
+
plugins = /* @__PURE__ */ new Map();
|
|
991
969
|
constructor(config, options) {
|
|
992
970
|
this.config = config;
|
|
993
971
|
this.options = options;
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
972
|
+
config.plugins.map((plugin) => Object.assign({ install() {} }, plugin)).sort((a, b) => {
|
|
973
|
+
if (b.pre?.includes(a.name)) return 1;
|
|
974
|
+
if (b.post?.includes(a.name)) return -1;
|
|
975
|
+
return 0;
|
|
976
|
+
}).forEach((plugin) => {
|
|
977
|
+
this.plugins.set(plugin.name, plugin);
|
|
997
978
|
});
|
|
998
979
|
}
|
|
999
980
|
get events() {
|
|
1000
981
|
return this.options.events;
|
|
1001
982
|
}
|
|
1002
983
|
getContext(plugin) {
|
|
1003
|
-
const plugins = [...this.#plugins];
|
|
1004
984
|
const driver = this;
|
|
1005
985
|
const baseContext = {
|
|
1006
|
-
fabric:
|
|
1007
|
-
config:
|
|
986
|
+
fabric: driver.options.fabric,
|
|
987
|
+
config: driver.config,
|
|
1008
988
|
plugin,
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
989
|
+
getPlugin: driver.getPlugin.bind(driver),
|
|
990
|
+
events: driver.options.events,
|
|
991
|
+
driver,
|
|
1012
992
|
addFile: async (...files) => {
|
|
1013
993
|
await this.options.fabric.addFile(...files);
|
|
1014
994
|
},
|
|
@@ -1021,6 +1001,9 @@ var PluginDriver = class {
|
|
|
1021
1001
|
get adapter() {
|
|
1022
1002
|
return driver.adapter;
|
|
1023
1003
|
},
|
|
1004
|
+
get resolver() {
|
|
1005
|
+
return plugin.resolver;
|
|
1006
|
+
},
|
|
1024
1007
|
openInStudio(options) {
|
|
1025
1008
|
if (!driver.config.devtools || driver.#studioIsOpen) return;
|
|
1026
1009
|
if (typeof driver.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
@@ -1031,8 +1014,8 @@ var PluginDriver = class {
|
|
|
1031
1014
|
}
|
|
1032
1015
|
};
|
|
1033
1016
|
const mergedExtras = {};
|
|
1034
|
-
for (const
|
|
1035
|
-
const result =
|
|
1017
|
+
for (const plugin of this.plugins.values()) if (typeof plugin.inject === "function") {
|
|
1018
|
+
const result = plugin.inject.call(baseContext, baseContext);
|
|
1036
1019
|
if (result !== null && typeof result === "object") Object.assign(mergedExtras, result);
|
|
1037
1020
|
}
|
|
1038
1021
|
return {
|
|
@@ -1040,9 +1023,9 @@ var PluginDriver = class {
|
|
|
1040
1023
|
...mergedExtras
|
|
1041
1024
|
};
|
|
1042
1025
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1026
|
+
/**
|
|
1027
|
+
* @deprecated use resolvers context instead
|
|
1028
|
+
*/
|
|
1046
1029
|
getFile({ name, mode, extname, pluginName, options }) {
|
|
1047
1030
|
const resolvedName = mode ? mode === "single" ? "" : this.resolveName({
|
|
1048
1031
|
name,
|
|
@@ -1065,6 +1048,9 @@ var PluginDriver = class {
|
|
|
1065
1048
|
exports: []
|
|
1066
1049
|
};
|
|
1067
1050
|
}
|
|
1051
|
+
/**
|
|
1052
|
+
* @deprecated use resolvers context instead
|
|
1053
|
+
*/
|
|
1068
1054
|
resolvePath = (params) => {
|
|
1069
1055
|
const defaultPath = (0, node_path.resolve)((0, node_path.resolve)(this.config.root, this.config.output.path), params.baseName);
|
|
1070
1056
|
if (params.pluginName) return this.hookForPluginSync({
|
|
@@ -1085,15 +1071,15 @@ var PluginDriver = class {
|
|
|
1085
1071
|
]
|
|
1086
1072
|
})?.result || defaultPath;
|
|
1087
1073
|
};
|
|
1074
|
+
/**
|
|
1075
|
+
* @deprecated use resolvers context instead
|
|
1076
|
+
*/
|
|
1088
1077
|
resolveName = (params) => {
|
|
1089
|
-
if (params.pluginName) {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
});
|
|
1095
|
-
return transformReservedWord([...new Set(names)].at(0) || params.name);
|
|
1096
|
-
}
|
|
1078
|
+
if (params.pluginName) return transformReservedWord(this.hookForPluginSync({
|
|
1079
|
+
pluginName: params.pluginName,
|
|
1080
|
+
hookName: "resolveName",
|
|
1081
|
+
parameters: [params.name.trim(), params.type]
|
|
1082
|
+
})?.at(0) ?? params.name);
|
|
1097
1083
|
const name = this.hookFirstSync({
|
|
1098
1084
|
hookName: "resolveName",
|
|
1099
1085
|
parameters: [params.name.trim(), params.type]
|
|
@@ -1104,44 +1090,41 @@ var PluginDriver = class {
|
|
|
1104
1090
|
* Run a specific hookName for plugin x.
|
|
1105
1091
|
*/
|
|
1106
1092
|
async hookForPlugin({ pluginName, hookName, parameters }) {
|
|
1107
|
-
const
|
|
1093
|
+
const plugin = this.plugins.get(pluginName);
|
|
1094
|
+
if (!plugin) return [null];
|
|
1108
1095
|
this.events.emit("plugins:hook:progress:start", {
|
|
1109
1096
|
hookName,
|
|
1110
|
-
plugins
|
|
1097
|
+
plugins: [plugin]
|
|
1098
|
+
});
|
|
1099
|
+
const result = await this.#execute({
|
|
1100
|
+
strategy: "hookFirst",
|
|
1101
|
+
hookName,
|
|
1102
|
+
parameters,
|
|
1103
|
+
plugin
|
|
1111
1104
|
});
|
|
1112
|
-
const items = [];
|
|
1113
|
-
for (const plugin of plugins) {
|
|
1114
|
-
const result = await this.#execute({
|
|
1115
|
-
strategy: "hookFirst",
|
|
1116
|
-
hookName,
|
|
1117
|
-
parameters,
|
|
1118
|
-
plugin
|
|
1119
|
-
});
|
|
1120
|
-
if (result !== void 0 && result !== null) items.push(result);
|
|
1121
|
-
}
|
|
1122
1105
|
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1123
|
-
return
|
|
1106
|
+
return [result];
|
|
1124
1107
|
}
|
|
1125
1108
|
/**
|
|
1126
1109
|
* Run a specific hookName for plugin x.
|
|
1127
1110
|
*/
|
|
1128
1111
|
hookForPluginSync({ pluginName, hookName, parameters }) {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
})
|
|
1112
|
+
const plugin = this.plugins.get(pluginName);
|
|
1113
|
+
if (!plugin) return null;
|
|
1114
|
+
const result = this.#executeSync({
|
|
1115
|
+
strategy: "hookFirst",
|
|
1116
|
+
hookName,
|
|
1117
|
+
parameters,
|
|
1118
|
+
plugin
|
|
1119
|
+
});
|
|
1120
|
+
return result !== null ? [result] : [];
|
|
1137
1121
|
}
|
|
1138
1122
|
/**
|
|
1139
1123
|
* Returns the first non-null result.
|
|
1140
1124
|
*/
|
|
1141
1125
|
async hookFirst({ hookName, parameters, skipped }) {
|
|
1142
|
-
const plugins =
|
|
1143
|
-
|
|
1144
|
-
});
|
|
1126
|
+
const plugins = [];
|
|
1127
|
+
for (const plugin of this.plugins.values()) if (hookName in plugin && (skipped ? !skipped.has(plugin) : true)) plugins.push(plugin);
|
|
1145
1128
|
this.events.emit("plugins:hook:progress:start", {
|
|
1146
1129
|
hookName,
|
|
1147
1130
|
plugins
|
|
@@ -1168,10 +1151,9 @@ var PluginDriver = class {
|
|
|
1168
1151
|
*/
|
|
1169
1152
|
hookFirstSync({ hookName, parameters, skipped }) {
|
|
1170
1153
|
let parseResult = null;
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
for (const plugin of plugins) {
|
|
1154
|
+
for (const plugin of this.plugins.values()) {
|
|
1155
|
+
if (!(hookName in plugin)) continue;
|
|
1156
|
+
if (skipped?.has(plugin)) continue;
|
|
1175
1157
|
parseResult = {
|
|
1176
1158
|
result: this.#executeSync({
|
|
1177
1159
|
strategy: "hookFirst",
|
|
@@ -1181,7 +1163,7 @@ var PluginDriver = class {
|
|
|
1181
1163
|
}),
|
|
1182
1164
|
plugin
|
|
1183
1165
|
};
|
|
1184
|
-
if (parseResult
|
|
1166
|
+
if (parseResult.result != null) break;
|
|
1185
1167
|
}
|
|
1186
1168
|
return parseResult;
|
|
1187
1169
|
}
|
|
@@ -1189,7 +1171,8 @@ var PluginDriver = class {
|
|
|
1189
1171
|
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
1190
1172
|
*/
|
|
1191
1173
|
async hookParallel({ hookName, parameters }) {
|
|
1192
|
-
const plugins =
|
|
1174
|
+
const plugins = [];
|
|
1175
|
+
for (const plugin of this.plugins.values()) if (hookName in plugin) plugins.push(plugin);
|
|
1193
1176
|
this.events.emit("plugins:hook:progress:start", {
|
|
1194
1177
|
hookName,
|
|
1195
1178
|
plugins
|
|
@@ -1208,7 +1191,7 @@ var PluginDriver = class {
|
|
|
1208
1191
|
}), this.options.concurrency);
|
|
1209
1192
|
results.forEach((result, index) => {
|
|
1210
1193
|
if (isPromiseRejectedResult(result)) {
|
|
1211
|
-
const plugin =
|
|
1194
|
+
const plugin = plugins[index];
|
|
1212
1195
|
if (plugin) {
|
|
1213
1196
|
const startTime = pluginStartTimes.get(plugin) ?? node_perf_hooks.performance.now();
|
|
1214
1197
|
this.events.emit("error", result.reason, {
|
|
@@ -1231,7 +1214,8 @@ var PluginDriver = class {
|
|
|
1231
1214
|
* Chains plugins
|
|
1232
1215
|
*/
|
|
1233
1216
|
async hookSeq({ hookName, parameters }) {
|
|
1234
|
-
const plugins =
|
|
1217
|
+
const plugins = [];
|
|
1218
|
+
for (const plugin of this.plugins.values()) if (hookName in plugin) plugins.push(plugin);
|
|
1235
1219
|
this.events.emit("plugins:hook:progress:start", {
|
|
1236
1220
|
hookName,
|
|
1237
1221
|
plugins
|
|
@@ -1246,33 +1230,8 @@ var PluginDriver = class {
|
|
|
1246
1230
|
}));
|
|
1247
1231
|
this.events.emit("plugins:hook:progress:end", { hookName });
|
|
1248
1232
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
1252
|
-
return plugins.map((plugin) => {
|
|
1253
|
-
if (plugin.pre) {
|
|
1254
|
-
let missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1255
|
-
if (missingPlugins.includes("plugin-oas") && this.adapter) missingPlugins = missingPlugins.filter((pluginName) => pluginName !== "plugin-oas");
|
|
1256
|
-
if (missingPlugins.length > 0) throw new ValidationPluginError(`The plugin '${plugin.name}' has a pre set that references missing plugins for '${missingPlugins.join(", ")}'`);
|
|
1257
|
-
}
|
|
1258
|
-
return plugin;
|
|
1259
|
-
}).sort((a, b) => {
|
|
1260
|
-
if (b.pre?.includes(a.name)) return 1;
|
|
1261
|
-
if (b.post?.includes(a.name)) return -1;
|
|
1262
|
-
return 0;
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
getPluginByName(pluginName) {
|
|
1266
|
-
return [...this.#plugins].find((item) => item.name === pluginName);
|
|
1267
|
-
}
|
|
1268
|
-
getPluginsByName(hookName, pluginName) {
|
|
1269
|
-
const plugins = [...this.plugins];
|
|
1270
|
-
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => item.name === pluginName);
|
|
1271
|
-
if (!pluginByPluginName?.length) {
|
|
1272
|
-
const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
|
|
1273
|
-
return corePlugin ? [corePlugin] : [];
|
|
1274
|
-
}
|
|
1275
|
-
return pluginByPluginName;
|
|
1233
|
+
getPlugin(pluginName) {
|
|
1234
|
+
return this.plugins.get(pluginName);
|
|
1276
1235
|
}
|
|
1277
1236
|
/**
|
|
1278
1237
|
* Run an async plugin hook and return the result.
|
|
@@ -1360,16 +1319,6 @@ var PluginDriver = class {
|
|
|
1360
1319
|
return null;
|
|
1361
1320
|
}
|
|
1362
1321
|
}
|
|
1363
|
-
#parse(plugin) {
|
|
1364
|
-
const usedPluginNames = this.#usedPluginNames;
|
|
1365
|
-
setUniqueName(plugin.name, usedPluginNames);
|
|
1366
|
-
const usageCount = usedPluginNames[plugin.name];
|
|
1367
|
-
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.`);
|
|
1368
|
-
return {
|
|
1369
|
-
install() {},
|
|
1370
|
-
...plugin
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1373
1322
|
};
|
|
1374
1323
|
//#endregion
|
|
1375
1324
|
//#region src/createStorage.ts
|
|
@@ -1469,7 +1418,7 @@ const fsStorage = createStorage(() => ({
|
|
|
1469
1418
|
}));
|
|
1470
1419
|
//#endregion
|
|
1471
1420
|
//#region package.json
|
|
1472
|
-
var version = "5.0.0-alpha.
|
|
1421
|
+
var version = "5.0.0-alpha.23";
|
|
1473
1422
|
//#endregion
|
|
1474
1423
|
//#region src/utils/diagnostics.ts
|
|
1475
1424
|
/**
|
|
@@ -1665,7 +1614,7 @@ async function safeBuild(options, overrides) {
|
|
|
1665
1614
|
const pluginTimings = /* @__PURE__ */ new Map();
|
|
1666
1615
|
const config = driver.config;
|
|
1667
1616
|
try {
|
|
1668
|
-
for (const plugin of driver.plugins) {
|
|
1617
|
+
for (const plugin of driver.plugins.values()) {
|
|
1669
1618
|
const context = driver.getContext(plugin);
|
|
1670
1619
|
const hrStart = process.hrtime();
|
|
1671
1620
|
const installer = plugin.install.bind(context);
|
|
@@ -1775,7 +1724,7 @@ async function safeBuild(options, overrides) {
|
|
|
1775
1724
|
}
|
|
1776
1725
|
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, driver }) {
|
|
1777
1726
|
const pluginNameMap = /* @__PURE__ */ new Map();
|
|
1778
|
-
for (const plugin of driver.plugins) pluginNameMap.set(plugin.name, plugin);
|
|
1727
|
+
for (const plugin of driver.plugins.values()) pluginNameMap.set(plugin.name, plugin);
|
|
1779
1728
|
return barrelFiles.flatMap((file) => {
|
|
1780
1729
|
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
|
|
1781
1730
|
return (file.sources ?? []).flatMap((source) => {
|
|
@@ -1857,26 +1806,6 @@ function createPlugin(build) {
|
|
|
1857
1806
|
return (options) => build(options ?? {});
|
|
1858
1807
|
}
|
|
1859
1808
|
//#endregion
|
|
1860
|
-
//#region src/defineBuilder.ts
|
|
1861
|
-
/**
|
|
1862
|
-
* Defines a builder for a plugin — a named collection of schema-building helpers that
|
|
1863
|
-
* can be exported alongside the plugin and imported by other plugins or generators.
|
|
1864
|
-
*
|
|
1865
|
-
* @example
|
|
1866
|
-
* export const builder = defineBuilder<PluginTs>(() => ({
|
|
1867
|
-
* name: 'default',
|
|
1868
|
-
* buildParamsSchema({ params, node, resolver }) {
|
|
1869
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
1870
|
-
* },
|
|
1871
|
-
* buildDataSchemaNode({ node, resolver }) {
|
|
1872
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
1873
|
-
* },
|
|
1874
|
-
* }))
|
|
1875
|
-
*/
|
|
1876
|
-
function defineBuilder(build) {
|
|
1877
|
-
return build();
|
|
1878
|
-
}
|
|
1879
|
-
//#endregion
|
|
1880
1809
|
//#region src/defineGenerator.ts
|
|
1881
1810
|
function defineGenerator(generator) {
|
|
1882
1811
|
if (generator.type === "react") return {
|
|
@@ -1924,34 +1853,6 @@ function defineLogger(logger) {
|
|
|
1924
1853
|
return logger;
|
|
1925
1854
|
}
|
|
1926
1855
|
//#endregion
|
|
1927
|
-
//#region src/definePreset.ts
|
|
1928
|
-
/**
|
|
1929
|
-
* Creates a typed preset object that bundles a name, resolvers, optional
|
|
1930
|
-
* transformers, and optional generators — the building block for composable plugin presets.
|
|
1931
|
-
*
|
|
1932
|
-
* @example
|
|
1933
|
-
* import { definePreset } from '@kubb/core'
|
|
1934
|
-
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
1935
|
-
*
|
|
1936
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy] })
|
|
1937
|
-
*
|
|
1938
|
-
* @example
|
|
1939
|
-
* // With custom transformers
|
|
1940
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], transformers: [myTransformer] })
|
|
1941
|
-
*
|
|
1942
|
-
* @example
|
|
1943
|
-
* // With generators
|
|
1944
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], generators: [typeGeneratorLegacy] })
|
|
1945
|
-
*/
|
|
1946
|
-
function definePreset(name, { resolvers, transformers, generators }) {
|
|
1947
|
-
return {
|
|
1948
|
-
name,
|
|
1949
|
-
resolvers,
|
|
1950
|
-
transformers,
|
|
1951
|
-
generators
|
|
1952
|
-
};
|
|
1953
|
-
}
|
|
1954
|
-
//#endregion
|
|
1955
1856
|
//#region src/definePresets.ts
|
|
1956
1857
|
/**
|
|
1957
1858
|
* Creates a typed presets registry object — a named collection of {@link Preset} entries.
|
|
@@ -2098,19 +1999,13 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
|
|
|
2098
1999
|
*/
|
|
2099
2000
|
function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
|
|
2100
2001
|
if ((pathMode ?? getMode(node_path.default.resolve(root, output.path))) === "single") return node_path.default.resolve(root, output.path);
|
|
2101
|
-
if (group && (groupPath || tag)) {
|
|
2102
|
-
const groupName = group.name ? group.name : (ctx) => {
|
|
2103
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
2104
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
2105
|
-
};
|
|
2106
|
-
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? groupPath : tag }), baseName);
|
|
2107
|
-
}
|
|
2002
|
+
if (group && (groupPath || tag)) return node_path.default.resolve(root, output.path, group.name({ group: group.type === "path" ? groupPath : tag }), baseName);
|
|
2108
2003
|
return node_path.default.resolve(root, output.path, baseName);
|
|
2109
2004
|
}
|
|
2110
2005
|
/**
|
|
2111
2006
|
* Default file resolver used by `defineResolver`.
|
|
2112
2007
|
*
|
|
2113
|
-
* Resolves a `
|
|
2008
|
+
* Resolves a `FabricFile.File` by combining name resolution (`resolver.default`) with
|
|
2114
2009
|
* path resolution (`resolver.resolvePath`). The resolved file always has empty
|
|
2115
2010
|
* `sources`, `imports`, and `exports` arrays — consumers populate those separately.
|
|
2116
2011
|
*
|
|
@@ -2246,7 +2141,7 @@ function defaultResolveFooter(node, { output }) {
|
|
|
2246
2141
|
* - `default` — name casing strategy (camelCase / PascalCase)
|
|
2247
2142
|
* - `resolveOptions` — include/exclude/override filtering
|
|
2248
2143
|
* - `resolvePath` — output path computation
|
|
2249
|
-
* - `resolveFile` — full `
|
|
2144
|
+
* - `resolveFile` — full `FabricFile.File` construction
|
|
2250
2145
|
*
|
|
2251
2146
|
* Methods in the builder have access to `this` (the full resolver object), so they
|
|
2252
2147
|
* can call other resolver methods without circular imports.
|
|
@@ -2304,19 +2199,15 @@ async function renderOperations(nodes, options) {
|
|
|
2304
2199
|
const { config, fabric, plugin, Component, driver, adapter } = options;
|
|
2305
2200
|
if (!Component) return;
|
|
2306
2201
|
const fabricChild = (0, _kubb_react_fabric.createReactFabric)();
|
|
2307
|
-
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, {
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
nodes,
|
|
2317
|
-
options: options.options
|
|
2318
|
-
})
|
|
2319
|
-
}));
|
|
2202
|
+
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, { children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Component, {
|
|
2203
|
+
config,
|
|
2204
|
+
plugin,
|
|
2205
|
+
driver,
|
|
2206
|
+
adapter,
|
|
2207
|
+
nodes,
|
|
2208
|
+
options: options.options,
|
|
2209
|
+
resolver: options.resolver
|
|
2210
|
+
}) }));
|
|
2320
2211
|
fabric.context.fileManager.upsert(...fabricChild.files);
|
|
2321
2212
|
fabricChild.unmount();
|
|
2322
2213
|
}
|
|
@@ -2327,19 +2218,15 @@ async function renderOperation(node, options) {
|
|
|
2327
2218
|
const { config, fabric, plugin, Component, adapter, driver } = options;
|
|
2328
2219
|
if (!Component) return;
|
|
2329
2220
|
const fabricChild = (0, _kubb_react_fabric.createReactFabric)();
|
|
2330
|
-
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, {
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
node,
|
|
2340
|
-
options: options.options
|
|
2341
|
-
})
|
|
2342
|
-
}));
|
|
2221
|
+
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, { children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Component, {
|
|
2222
|
+
config,
|
|
2223
|
+
plugin,
|
|
2224
|
+
driver,
|
|
2225
|
+
adapter,
|
|
2226
|
+
node,
|
|
2227
|
+
options: options.options,
|
|
2228
|
+
resolver: options.resolver
|
|
2229
|
+
}) }));
|
|
2343
2230
|
fabric.context.fileManager.upsert(...fabricChild.files);
|
|
2344
2231
|
fabricChild.unmount();
|
|
2345
2232
|
}
|
|
@@ -2350,19 +2237,15 @@ async function renderSchema(node, options) {
|
|
|
2350
2237
|
const { config, fabric, plugin, Component, adapter, driver } = options;
|
|
2351
2238
|
if (!Component) return;
|
|
2352
2239
|
const fabricChild = (0, _kubb_react_fabric.createReactFabric)();
|
|
2353
|
-
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, {
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
node,
|
|
2363
|
-
options: options.options
|
|
2364
|
-
})
|
|
2365
|
-
}));
|
|
2240
|
+
await fabricChild.render(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Fabric, { children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Component, {
|
|
2241
|
+
config,
|
|
2242
|
+
plugin,
|
|
2243
|
+
driver,
|
|
2244
|
+
adapter,
|
|
2245
|
+
node,
|
|
2246
|
+
options: options.options,
|
|
2247
|
+
resolver: options.resolver
|
|
2248
|
+
}) }));
|
|
2366
2249
|
fabric.context.fileManager.upsert(...fabricChild.files);
|
|
2367
2250
|
fabricChild.unmount();
|
|
2368
2251
|
}
|
|
@@ -2533,7 +2416,7 @@ async function detectFormatter() {
|
|
|
2533
2416
|
//#region src/utils/TreeNode.ts
|
|
2534
2417
|
/**
|
|
2535
2418
|
* Tree structure used to build per-directory barrel (`index.ts`) files from a
|
|
2536
|
-
* flat list of generated {@link
|
|
2419
|
+
* flat list of generated {@link FabricFile.File} entries.
|
|
2537
2420
|
*
|
|
2538
2421
|
* Each node represents either a directory or a file within the output tree.
|
|
2539
2422
|
* Use {@link TreeNode.build} to construct a root node from a file list, then
|
|
@@ -2575,24 +2458,39 @@ var TreeNode = class TreeNode {
|
|
|
2575
2458
|
this.#cachedLeaves = leaves;
|
|
2576
2459
|
return leaves;
|
|
2577
2460
|
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Visits this node and every descendant in depth-first order.
|
|
2463
|
+
*/
|
|
2578
2464
|
forEach(callback) {
|
|
2579
2465
|
if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
|
|
2580
2466
|
callback(this);
|
|
2581
2467
|
for (const child of this.children) child.forEach(callback);
|
|
2582
2468
|
return this;
|
|
2583
2469
|
}
|
|
2470
|
+
/**
|
|
2471
|
+
* Finds the first leaf that satisfies `predicate`, or `undefined` when none match.
|
|
2472
|
+
*/
|
|
2584
2473
|
findDeep(predicate) {
|
|
2585
2474
|
if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
|
|
2586
2475
|
return this.leaves.find(predicate);
|
|
2587
2476
|
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Calls `callback` for every leaf of this node.
|
|
2479
|
+
*/
|
|
2588
2480
|
forEachDeep(callback) {
|
|
2589
2481
|
if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
|
|
2590
2482
|
this.leaves.forEach(callback);
|
|
2591
2483
|
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Returns all leaves that satisfy `callback`.
|
|
2486
|
+
*/
|
|
2592
2487
|
filterDeep(callback) {
|
|
2593
2488
|
if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
|
|
2594
2489
|
return this.leaves.filter(callback);
|
|
2595
2490
|
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Maps every leaf through `callback` and returns the resulting array.
|
|
2493
|
+
*/
|
|
2596
2494
|
mapDeep(callback) {
|
|
2597
2495
|
if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
|
|
2598
2496
|
return this.leaves.map(callback);
|
|
@@ -2760,12 +2658,23 @@ async function getBarrelFiles(files, { type, meta = {}, root, output }) {
|
|
|
2760
2658
|
*/
|
|
2761
2659
|
async function getConfigs(config, args) {
|
|
2762
2660
|
const resolved = await (typeof config === "function" ? config(args) : config);
|
|
2763
|
-
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
2661
|
+
return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
2662
|
+
plugins: [],
|
|
2663
|
+
...item
|
|
2664
|
+
}));
|
|
2764
2665
|
}
|
|
2765
2666
|
//#endregion
|
|
2766
2667
|
//#region src/utils/mergeResolvers.ts
|
|
2767
2668
|
/**
|
|
2768
|
-
* Merges an
|
|
2669
|
+
* Merges an ordered list of resolvers into a single resolver by shallow-merging each entry left to right.
|
|
2670
|
+
*
|
|
2671
|
+
* Later entries win when keys conflict, so the last resolver in the list takes highest precedence.
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* ```ts
|
|
2675
|
+
* const resolver = mergeResolvers(resolverTs, resolverTsLegacy)
|
|
2676
|
+
* // resolverTsLegacy methods override resolverTs where they overlap
|
|
2677
|
+
* ```
|
|
2769
2678
|
*/
|
|
2770
2679
|
function mergeResolvers(...resolvers) {
|
|
2771
2680
|
return resolvers.reduce((acc, curr) => ({
|
|
@@ -2784,7 +2693,7 @@ function mergeResolvers(...resolvers) {
|
|
|
2784
2693
|
* - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
|
|
2785
2694
|
*/
|
|
2786
2695
|
function getPreset(params) {
|
|
2787
|
-
const { preset: presetName, presets, resolvers, transformers: userTransformers, generators: userGenerators } = params;
|
|
2696
|
+
const { preset: presetName, presets, resolvers = [], transformers: userTransformers = [], generators: userGenerators = [] } = params;
|
|
2788
2697
|
const [defaultResolver, ...userResolvers] = resolvers;
|
|
2789
2698
|
const preset = presets[presetName];
|
|
2790
2699
|
const resolver = mergeResolvers(mergeResolvers(defaultResolver, ...preset?.resolvers ?? []), ...userResolvers ?? []);
|
|
@@ -2896,11 +2805,9 @@ exports.defaultResolveFile = defaultResolveFile;
|
|
|
2896
2805
|
exports.defaultResolveFooter = defaultResolveFooter;
|
|
2897
2806
|
exports.defaultResolveOptions = defaultResolveOptions;
|
|
2898
2807
|
exports.defaultResolvePath = defaultResolvePath;
|
|
2899
|
-
exports.defineBuilder = defineBuilder;
|
|
2900
2808
|
exports.defineConfig = defineConfig;
|
|
2901
2809
|
exports.defineGenerator = defineGenerator;
|
|
2902
2810
|
exports.defineLogger = defineLogger;
|
|
2903
|
-
exports.definePreset = definePreset;
|
|
2904
2811
|
exports.definePresets = definePresets;
|
|
2905
2812
|
Object.defineProperty(exports, "definePrinter", {
|
|
2906
2813
|
enumerable: true,
|