@kubb/core 2.0.0-canary.20231030T124958 → 2.0.1

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 (100) hide show
  1. package/README.md +1 -1
  2. package/dist/chunk-4A7WG6IA.js +128 -0
  3. package/dist/chunk-4A7WG6IA.js.map +1 -0
  4. package/dist/chunk-54P4AWHI.js +71 -0
  5. package/dist/chunk-54P4AWHI.js.map +1 -0
  6. package/dist/chunk-5TK7TMV6.cjs +131 -0
  7. package/dist/chunk-5TK7TMV6.cjs.map +1 -0
  8. package/dist/chunk-7S67BJXQ.js +85 -0
  9. package/dist/chunk-7S67BJXQ.js.map +1 -0
  10. package/dist/chunk-E3ANGQ5N.cjs +2290 -0
  11. package/dist/chunk-E3ANGQ5N.cjs.map +1 -0
  12. package/dist/chunk-H47IKRXJ.cjs +129 -0
  13. package/dist/chunk-H47IKRXJ.cjs.map +1 -0
  14. package/dist/chunk-HIE46T3F.js +129 -0
  15. package/dist/chunk-HIE46T3F.js.map +1 -0
  16. package/dist/chunk-K2H7BYQB.js +155 -0
  17. package/dist/chunk-K2H7BYQB.js.map +1 -0
  18. package/dist/chunk-NAWI7UXW.js +67 -0
  19. package/dist/chunk-NAWI7UXW.js.map +1 -0
  20. package/dist/chunk-PLVKILIY.cjs +162 -0
  21. package/dist/chunk-PLVKILIY.cjs.map +1 -0
  22. package/dist/chunk-W2FP7ZWW.cjs +71 -0
  23. package/dist/chunk-W2FP7ZWW.cjs.map +1 -0
  24. package/dist/chunk-WZQO3EPM.cjs +91 -0
  25. package/dist/chunk-WZQO3EPM.cjs.map +1 -0
  26. package/dist/chunk-XDHI63G7.cjs +104 -0
  27. package/dist/chunk-XDHI63G7.cjs.map +1 -0
  28. package/dist/chunk-XPOF4D5N.js +18 -0
  29. package/dist/chunk-XPOF4D5N.js.map +1 -0
  30. package/dist/fs.cjs +31 -0
  31. package/dist/fs.cjs.map +1 -0
  32. package/dist/fs.d.cts +5 -0
  33. package/dist/fs.d.ts +5 -0
  34. package/dist/fs.js +11 -0
  35. package/dist/fs.js.map +1 -0
  36. package/dist/index.cjs +1866 -977
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +302 -319
  39. package/dist/index.d.ts +302 -319
  40. package/dist/index.js +1071 -846
  41. package/dist/index.js.map +1 -1
  42. package/dist/logger.cjs +26 -0
  43. package/dist/logger.cjs.map +1 -0
  44. package/dist/logger.d.cts +32 -0
  45. package/dist/logger.d.ts +32 -0
  46. package/dist/logger.js +8 -0
  47. package/dist/logger.js.map +1 -0
  48. package/dist/transformers.cjs +124 -0
  49. package/dist/transformers.cjs.map +1 -0
  50. package/dist/transformers.d.cts +55 -0
  51. package/dist/transformers.d.ts +55 -0
  52. package/dist/transformers.js +95 -0
  53. package/dist/transformers.js.map +1 -0
  54. package/dist/utils.cjs +23 -1163
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +2 -143
  57. package/dist/utils.d.ts +2 -143
  58. package/dist/utils.js +15 -1118
  59. package/dist/utils.js.map +1 -1
  60. package/dist/write-A6VgHkYA.d.cts +10 -0
  61. package/dist/write-A6VgHkYA.d.ts +10 -0
  62. package/package.json +40 -23
  63. package/src/BarrelManager.ts +113 -0
  64. package/src/FileManager.ts +581 -0
  65. package/src/Generator.ts +34 -0
  66. package/src/PackageManager.ts +178 -0
  67. package/src/PluginManager.ts +645 -0
  68. package/src/PromiseManager.ts +51 -0
  69. package/src/build.ts +221 -0
  70. package/src/config.ts +22 -0
  71. package/src/errors.ts +12 -0
  72. package/src/fs/clean.ts +5 -0
  73. package/src/fs/index.ts +3 -0
  74. package/src/fs/read.ts +68 -0
  75. package/src/fs/write.ts +79 -0
  76. package/src/index.ts +27 -0
  77. package/src/logger.ts +121 -0
  78. package/src/plugin.ts +80 -0
  79. package/src/transformers/casing.ts +9 -0
  80. package/src/transformers/combineCodes.ts +3 -0
  81. package/src/transformers/createJSDocBlockText.ts +9 -0
  82. package/src/transformers/escape.ts +31 -0
  83. package/src/transformers/indent.ts +3 -0
  84. package/src/transformers/index.ts +36 -0
  85. package/src/transformers/nameSorter.ts +9 -0
  86. package/src/transformers/searchAndReplace.ts +25 -0
  87. package/src/transformers/transformReservedWord.ts +97 -0
  88. package/src/transformers/trim.ts +7 -0
  89. package/src/types.ts +334 -0
  90. package/src/utils/EventEmitter.ts +24 -0
  91. package/src/utils/FunctionParams.ts +86 -0
  92. package/src/utils/TreeNode.ts +125 -0
  93. package/src/utils/URLPath.ts +133 -0
  94. package/src/utils/cache.ts +35 -0
  95. package/src/utils/executeStrategies.ts +83 -0
  96. package/src/utils/index.ts +8 -0
  97. package/src/utils/promise.ts +13 -0
  98. package/src/utils/renderTemplate.ts +31 -0
  99. package/src/utils/timeout.ts +7 -0
  100. package/src/utils/uniqueName.ts +20 -0
package/dist/index.js CHANGED
@@ -1,253 +1,736 @@
1
1
  import mod, { createRequire } from 'module';
2
- import pc3 from 'picocolors';
3
- import fs2, { remove } from 'fs-extra';
4
- import seedrandom from 'seedrandom';
5
- import { switcher } from 'js-runtime';
6
- import { camelCase, camelCaseTransformMerge } from 'change-case';
7
- import crypto2 from 'crypto';
8
- import path, { resolve, dirname, extname } from 'path';
2
+ import { transformReservedWord, trimExtName, searchAndReplace } from './chunk-HIE46T3F.js';
3
+ import { setUniqueName, URLPath } from './chunk-4A7WG6IA.js';
4
+ import './chunk-XPOF4D5N.js';
5
+ import { LogLevel, createLogger, p, randomCliColour } from './chunk-K2H7BYQB.js';
6
+ import { read, getRelativePath, clean } from './chunk-NAWI7UXW.js';
7
+ import { write } from './chunk-7S67BJXQ.js';
8
+ import { __commonJS, init_esm_shims, __toESM, __privateAdd, __privateSet, __privateGet, __privateMethod, __require } from './chunk-54P4AWHI.js';
9
+ import crypto from 'crypto';
10
+ import path, { resolve, extname } from 'path';
9
11
  import { print } from '@kubb/parser';
10
12
  import * as factory from '@kubb/parser/factory';
11
- import isEqual from 'lodash.isequal';
12
13
  import { orderBy } from 'natural-orderby';
14
+ import PQueue from 'p-queue';
13
15
  import dirTree from 'directory-tree';
14
16
  import { EventEmitter as EventEmitter$1 } from 'events';
15
- import { performance } from 'perf_hooks';
16
17
  import os from 'os';
17
18
  import { pathToFileURL } from 'url';
18
19
  import { findUp, findUpSync } from 'find-up';
19
20
  import { coerce, satisfies } from 'semver';
20
21
 
21
- const require = createRequire(import.meta.url);
22
-
23
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
24
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
25
- }) : x)(function(x) {
26
- if (typeof require !== "undefined")
27
- return require.apply(this, arguments);
28
- throw Error('Dynamic require of "' + x + '" is not supported');
29
- });
30
- var __accessCheck = (obj, member, msg) => {
31
- if (!member.has(obj))
32
- throw TypeError("Cannot " + msg);
33
- };
34
- var __privateGet = (obj, member, getter) => {
35
- __accessCheck(obj, member, "read from private field");
36
- return getter ? getter.call(obj) : member.get(obj);
37
- };
38
- var __privateAdd = (obj, member, value) => {
39
- if (member.has(obj))
40
- throw TypeError("Cannot add the same private member more than once");
41
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
- };
43
- var __privateSet = (obj, member, value, setter) => {
44
- __accessCheck(obj, member, "write to private field");
45
- setter ? setter.call(obj, value) : member.set(obj, value);
46
- return value;
47
- };
48
- var __privateWrapper = (obj, member, setter, getter) => ({
49
- set _(value) {
50
- __privateSet(obj, member, value, setter);
51
- },
52
- get _() {
53
- return __privateGet(obj, member, getter);
54
- }
55
- });
56
- var __privateMethod = (obj, member, method) => {
57
- __accessCheck(obj, member, "access private method");
58
- return method;
59
- };
60
- async function clean(path3) {
61
- return remove(path3);
62
- }
63
- var LogLevel = {
64
- silent: "silent",
65
- info: "info",
66
- debug: "debug"
67
- };
68
- function createLogger({ logLevel, name, spinner }) {
69
- const logs = [];
70
- const log = (message) => {
71
- if (message && spinner) {
72
- spinner.text = message;
73
- logs.push(message);
22
+ createRequire(import.meta.url);
23
+
24
+ // ../../node_modules/.pnpm/lodash.isequal@4.5.0/node_modules/lodash.isequal/index.js
25
+ var require_lodash = __commonJS({
26
+ "../../node_modules/.pnpm/lodash.isequal@4.5.0/node_modules/lodash.isequal/index.js"(exports, module) {
27
+ init_esm_shims();
28
+ var LARGE_ARRAY_SIZE = 200;
29
+ var HASH_UNDEFINED = "__lodash_hash_undefined__";
30
+ var COMPARE_PARTIAL_FLAG = 1;
31
+ var COMPARE_UNORDERED_FLAG = 2;
32
+ var MAX_SAFE_INTEGER = 9007199254740991;
33
+ var argsTag = "[object Arguments]";
34
+ var arrayTag = "[object Array]";
35
+ var asyncTag = "[object AsyncFunction]";
36
+ var boolTag = "[object Boolean]";
37
+ var dateTag = "[object Date]";
38
+ var errorTag = "[object Error]";
39
+ var funcTag = "[object Function]";
40
+ var genTag = "[object GeneratorFunction]";
41
+ var mapTag = "[object Map]";
42
+ var numberTag = "[object Number]";
43
+ var nullTag = "[object Null]";
44
+ var objectTag = "[object Object]";
45
+ var promiseTag = "[object Promise]";
46
+ var proxyTag = "[object Proxy]";
47
+ var regexpTag = "[object RegExp]";
48
+ var setTag = "[object Set]";
49
+ var stringTag = "[object String]";
50
+ var symbolTag = "[object Symbol]";
51
+ var undefinedTag = "[object Undefined]";
52
+ var weakMapTag = "[object WeakMap]";
53
+ var arrayBufferTag = "[object ArrayBuffer]";
54
+ var dataViewTag = "[object DataView]";
55
+ var float32Tag = "[object Float32Array]";
56
+ var float64Tag = "[object Float64Array]";
57
+ var int8Tag = "[object Int8Array]";
58
+ var int16Tag = "[object Int16Array]";
59
+ var int32Tag = "[object Int32Array]";
60
+ var uint8Tag = "[object Uint8Array]";
61
+ var uint8ClampedTag = "[object Uint8ClampedArray]";
62
+ var uint16Tag = "[object Uint16Array]";
63
+ var uint32Tag = "[object Uint32Array]";
64
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
65
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
66
+ var reIsUint = /^(?:0|[1-9]\d*)$/;
67
+ var typedArrayTags = {};
68
+ typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
69
+ typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
70
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
71
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
72
+ var root = freeGlobal || freeSelf || Function("return this")();
73
+ var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports;
74
+ var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module;
75
+ var moduleExports = freeModule && freeModule.exports === freeExports;
76
+ var freeProcess = moduleExports && freeGlobal.process;
77
+ var nodeUtil = function() {
78
+ try {
79
+ return freeProcess && freeProcess.binding && freeProcess.binding("util");
80
+ } catch (e) {
81
+ }
82
+ }();
83
+ var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
84
+ function arrayFilter(array, predicate) {
85
+ var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = [];
86
+ while (++index < length) {
87
+ var value = array[index];
88
+ if (predicate(value, index, array)) {
89
+ result[resIndex++] = value;
90
+ }
91
+ }
92
+ return result;
74
93
  }
75
- };
76
- const error = (message) => {
77
- if (message) {
78
- throw new Error(message || "Something went wrong");
94
+ function arrayPush(array, values) {
95
+ var index = -1, length = values.length, offset = array.length;
96
+ while (++index < length) {
97
+ array[offset + index] = values[index];
98
+ }
99
+ return array;
79
100
  }
80
- };
81
- const warn = (message) => {
82
- if (message && spinner) {
83
- spinner.warn(pc3.yellow(message));
84
- logs.push(message);
101
+ function arraySome(array, predicate) {
102
+ var index = -1, length = array == null ? 0 : array.length;
103
+ while (++index < length) {
104
+ if (predicate(array[index], index, array)) {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
85
109
  }
86
- };
87
- const info = (message) => {
88
- if (message && spinner) {
89
- spinner.info(message);
90
- logs.push(message);
110
+ function baseTimes(n, iteratee) {
111
+ var index = -1, result = Array(n);
112
+ while (++index < n) {
113
+ result[index] = iteratee(index);
114
+ }
115
+ return result;
91
116
  }
92
- };
93
- const logger = {
94
- name,
95
- logLevel,
96
- log,
97
- error,
98
- warn,
99
- info,
100
- spinner,
101
- logs
102
- };
103
- return logger;
104
- }
105
- var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
106
- function randomColour(text, colours = defaultColours) {
107
- if (!text) {
108
- return "white";
109
- }
110
- const random = seedrandom(text);
111
- const colour = colours.at(Math.floor(random() * colours.length)) || "white";
112
- return colour;
113
- }
114
- function randomPicoColour(text, colors = defaultColours) {
115
- const colours = pc3.createColors(true);
116
- if (!text) {
117
- return colours.white(text);
118
- }
119
- const colour = randomColour(text, colors);
120
- const isDark = colour.includes("dark");
121
- const key = colour.replace("dark", "").toLowerCase();
122
- const formatter = colours[key];
123
- if (isDark) {
124
- return pc3.bold(formatter(text));
125
- }
126
- if (typeof formatter !== "function") {
127
- throw new Error("Formatter for picoColor is not of type function/Formatter");
128
- }
129
- return formatter(text);
130
- }
131
- var reader = switcher(
132
- {
133
- node: async (path3) => {
134
- return fs2.readFile(path3, { encoding: "utf8" });
135
- },
136
- bun: async (path3) => {
137
- const file = Bun.file(path3);
138
- return file.text();
139
- }
140
- },
141
- "node"
142
- );
143
- switcher(
144
- {
145
- node: (path3) => {
146
- return fs2.readFileSync(path3, { encoding: "utf8" });
147
- },
148
- bun: () => {
149
- throw new Error("Bun cannot read sync");
150
- }
151
- },
152
- "node"
153
- );
154
- async function read(path3) {
155
- return reader(path3);
156
- }
157
- var URLPath = class {
158
- constructor(path3) {
159
- this.path = path3;
160
- return this;
161
- }
162
- /**
163
- * Convert Swagger path to URLPath(syntax of Express)
164
- * @example /pet/{petId} => /pet/:petId
165
- */
166
- get URL() {
167
- return this.toURLPath();
168
- }
169
- get isURL() {
170
- try {
171
- const url = new URL(this.path);
172
- if (url?.href) {
117
+ function baseUnary(func) {
118
+ return function(value) {
119
+ return func(value);
120
+ };
121
+ }
122
+ function cacheHas(cache, key) {
123
+ return cache.has(key);
124
+ }
125
+ function getValue(object, key) {
126
+ return object == null ? void 0 : object[key];
127
+ }
128
+ function mapToArray(map) {
129
+ var index = -1, result = Array(map.size);
130
+ map.forEach(function(value, key) {
131
+ result[++index] = [key, value];
132
+ });
133
+ return result;
134
+ }
135
+ function overArg(func, transform) {
136
+ return function(arg) {
137
+ return func(transform(arg));
138
+ };
139
+ }
140
+ function setToArray(set) {
141
+ var index = -1, result = Array(set.size);
142
+ set.forEach(function(value) {
143
+ result[++index] = value;
144
+ });
145
+ return result;
146
+ }
147
+ var arrayProto = Array.prototype;
148
+ var funcProto = Function.prototype;
149
+ var objectProto = Object.prototype;
150
+ var coreJsData = root["__core-js_shared__"];
151
+ var funcToString = funcProto.toString;
152
+ var hasOwnProperty = objectProto.hasOwnProperty;
153
+ var maskSrcKey = function() {
154
+ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
155
+ return uid ? "Symbol(src)_1." + uid : "";
156
+ }();
157
+ var nativeObjectToString = objectProto.toString;
158
+ var reIsNative = RegExp(
159
+ "^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
160
+ );
161
+ var Buffer = moduleExports ? root.Buffer : void 0;
162
+ var Symbol = root.Symbol;
163
+ var Uint8Array = root.Uint8Array;
164
+ var propertyIsEnumerable = objectProto.propertyIsEnumerable;
165
+ var splice = arrayProto.splice;
166
+ var symToStringTag = Symbol ? Symbol.toStringTag : void 0;
167
+ var nativeGetSymbols = Object.getOwnPropertySymbols;
168
+ var nativeIsBuffer = Buffer ? Buffer.isBuffer : void 0;
169
+ var nativeKeys = overArg(Object.keys, Object);
170
+ var DataView = getNative(root, "DataView");
171
+ var Map2 = getNative(root, "Map");
172
+ var Promise2 = getNative(root, "Promise");
173
+ var Set2 = getNative(root, "Set");
174
+ var WeakMap2 = getNative(root, "WeakMap");
175
+ var nativeCreate = getNative(Object, "create");
176
+ var dataViewCtorString = toSource(DataView);
177
+ var mapCtorString = toSource(Map2);
178
+ var promiseCtorString = toSource(Promise2);
179
+ var setCtorString = toSource(Set2);
180
+ var weakMapCtorString = toSource(WeakMap2);
181
+ var symbolProto = Symbol ? Symbol.prototype : void 0;
182
+ var symbolValueOf = symbolProto ? symbolProto.valueOf : void 0;
183
+ function Hash(entries) {
184
+ var index = -1, length = entries == null ? 0 : entries.length;
185
+ this.clear();
186
+ while (++index < length) {
187
+ var entry = entries[index];
188
+ this.set(entry[0], entry[1]);
189
+ }
190
+ }
191
+ function hashClear() {
192
+ this.__data__ = nativeCreate ? nativeCreate(null) : {};
193
+ this.size = 0;
194
+ }
195
+ function hashDelete(key) {
196
+ var result = this.has(key) && delete this.__data__[key];
197
+ this.size -= result ? 1 : 0;
198
+ return result;
199
+ }
200
+ function hashGet(key) {
201
+ var data = this.__data__;
202
+ if (nativeCreate) {
203
+ var result = data[key];
204
+ return result === HASH_UNDEFINED ? void 0 : result;
205
+ }
206
+ return hasOwnProperty.call(data, key) ? data[key] : void 0;
207
+ }
208
+ function hashHas(key) {
209
+ var data = this.__data__;
210
+ return nativeCreate ? data[key] !== void 0 : hasOwnProperty.call(data, key);
211
+ }
212
+ function hashSet(key, value) {
213
+ var data = this.__data__;
214
+ this.size += this.has(key) ? 0 : 1;
215
+ data[key] = nativeCreate && value === void 0 ? HASH_UNDEFINED : value;
216
+ return this;
217
+ }
218
+ Hash.prototype.clear = hashClear;
219
+ Hash.prototype["delete"] = hashDelete;
220
+ Hash.prototype.get = hashGet;
221
+ Hash.prototype.has = hashHas;
222
+ Hash.prototype.set = hashSet;
223
+ function ListCache(entries) {
224
+ var index = -1, length = entries == null ? 0 : entries.length;
225
+ this.clear();
226
+ while (++index < length) {
227
+ var entry = entries[index];
228
+ this.set(entry[0], entry[1]);
229
+ }
230
+ }
231
+ function listCacheClear() {
232
+ this.__data__ = [];
233
+ this.size = 0;
234
+ }
235
+ function listCacheDelete(key) {
236
+ var data = this.__data__, index = assocIndexOf(data, key);
237
+ if (index < 0) {
238
+ return false;
239
+ }
240
+ var lastIndex = data.length - 1;
241
+ if (index == lastIndex) {
242
+ data.pop();
243
+ } else {
244
+ splice.call(data, index, 1);
245
+ }
246
+ --this.size;
247
+ return true;
248
+ }
249
+ function listCacheGet(key) {
250
+ var data = this.__data__, index = assocIndexOf(data, key);
251
+ return index < 0 ? void 0 : data[index][1];
252
+ }
253
+ function listCacheHas(key) {
254
+ return assocIndexOf(this.__data__, key) > -1;
255
+ }
256
+ function listCacheSet(key, value) {
257
+ var data = this.__data__, index = assocIndexOf(data, key);
258
+ if (index < 0) {
259
+ ++this.size;
260
+ data.push([key, value]);
261
+ } else {
262
+ data[index][1] = value;
263
+ }
264
+ return this;
265
+ }
266
+ ListCache.prototype.clear = listCacheClear;
267
+ ListCache.prototype["delete"] = listCacheDelete;
268
+ ListCache.prototype.get = listCacheGet;
269
+ ListCache.prototype.has = listCacheHas;
270
+ ListCache.prototype.set = listCacheSet;
271
+ function MapCache(entries) {
272
+ var index = -1, length = entries == null ? 0 : entries.length;
273
+ this.clear();
274
+ while (++index < length) {
275
+ var entry = entries[index];
276
+ this.set(entry[0], entry[1]);
277
+ }
278
+ }
279
+ function mapCacheClear() {
280
+ this.size = 0;
281
+ this.__data__ = {
282
+ "hash": new Hash(),
283
+ "map": new (Map2 || ListCache)(),
284
+ "string": new Hash()
285
+ };
286
+ }
287
+ function mapCacheDelete(key) {
288
+ var result = getMapData(this, key)["delete"](key);
289
+ this.size -= result ? 1 : 0;
290
+ return result;
291
+ }
292
+ function mapCacheGet(key) {
293
+ return getMapData(this, key).get(key);
294
+ }
295
+ function mapCacheHas(key) {
296
+ return getMapData(this, key).has(key);
297
+ }
298
+ function mapCacheSet(key, value) {
299
+ var data = getMapData(this, key), size = data.size;
300
+ data.set(key, value);
301
+ this.size += data.size == size ? 0 : 1;
302
+ return this;
303
+ }
304
+ MapCache.prototype.clear = mapCacheClear;
305
+ MapCache.prototype["delete"] = mapCacheDelete;
306
+ MapCache.prototype.get = mapCacheGet;
307
+ MapCache.prototype.has = mapCacheHas;
308
+ MapCache.prototype.set = mapCacheSet;
309
+ function SetCache(values) {
310
+ var index = -1, length = values == null ? 0 : values.length;
311
+ this.__data__ = new MapCache();
312
+ while (++index < length) {
313
+ this.add(values[index]);
314
+ }
315
+ }
316
+ function setCacheAdd(value) {
317
+ this.__data__.set(value, HASH_UNDEFINED);
318
+ return this;
319
+ }
320
+ function setCacheHas(value) {
321
+ return this.__data__.has(value);
322
+ }
323
+ SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
324
+ SetCache.prototype.has = setCacheHas;
325
+ function Stack(entries) {
326
+ var data = this.__data__ = new ListCache(entries);
327
+ this.size = data.size;
328
+ }
329
+ function stackClear() {
330
+ this.__data__ = new ListCache();
331
+ this.size = 0;
332
+ }
333
+ function stackDelete(key) {
334
+ var data = this.__data__, result = data["delete"](key);
335
+ this.size = data.size;
336
+ return result;
337
+ }
338
+ function stackGet(key) {
339
+ return this.__data__.get(key);
340
+ }
341
+ function stackHas(key) {
342
+ return this.__data__.has(key);
343
+ }
344
+ function stackSet(key, value) {
345
+ var data = this.__data__;
346
+ if (data instanceof ListCache) {
347
+ var pairs = data.__data__;
348
+ if (!Map2 || pairs.length < LARGE_ARRAY_SIZE - 1) {
349
+ pairs.push([key, value]);
350
+ this.size = ++data.size;
351
+ return this;
352
+ }
353
+ data = this.__data__ = new MapCache(pairs);
354
+ }
355
+ data.set(key, value);
356
+ this.size = data.size;
357
+ return this;
358
+ }
359
+ Stack.prototype.clear = stackClear;
360
+ Stack.prototype["delete"] = stackDelete;
361
+ Stack.prototype.get = stackGet;
362
+ Stack.prototype.has = stackHas;
363
+ Stack.prototype.set = stackSet;
364
+ function arrayLikeKeys(value, inherited) {
365
+ var isArr = isArray(value), isArg = !isArr && isArguments(value), isBuff = !isArr && !isArg && isBuffer(value), isType = !isArr && !isArg && !isBuff && isTypedArray(value), skipIndexes = isArr || isArg || isBuff || isType, result = skipIndexes ? baseTimes(value.length, String) : [], length = result.length;
366
+ for (var key in value) {
367
+ if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && // Safari 9 has enumerable `arguments.length` in strict mode.
368
+ (key == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
369
+ isBuff && (key == "offset" || key == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays.
370
+ isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || // Skip index properties.
371
+ isIndex(key, length)))) {
372
+ result.push(key);
373
+ }
374
+ }
375
+ return result;
376
+ }
377
+ function assocIndexOf(array, key) {
378
+ var length = array.length;
379
+ while (length--) {
380
+ if (eq(array[length][0], key)) {
381
+ return length;
382
+ }
383
+ }
384
+ return -1;
385
+ }
386
+ function baseGetAllKeys(object, keysFunc, symbolsFunc) {
387
+ var result = keysFunc(object);
388
+ return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
389
+ }
390
+ function baseGetTag(value) {
391
+ if (value == null) {
392
+ return value === void 0 ? undefinedTag : nullTag;
393
+ }
394
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
395
+ }
396
+ function baseIsArguments(value) {
397
+ return isObjectLike(value) && baseGetTag(value) == argsTag;
398
+ }
399
+ function baseIsEqual(value, other, bitmask, customizer, stack) {
400
+ if (value === other) {
173
401
  return true;
174
402
  }
175
- } catch (error) {
403
+ if (value == null || other == null || !isObjectLike(value) && !isObjectLike(other)) {
404
+ return value !== value && other !== other;
405
+ }
406
+ return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
407
+ }
408
+ function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
409
+ var objIsArr = isArray(object), othIsArr = isArray(other), objTag = objIsArr ? arrayTag : getTag(object), othTag = othIsArr ? arrayTag : getTag(other);
410
+ objTag = objTag == argsTag ? objectTag : objTag;
411
+ othTag = othTag == argsTag ? objectTag : othTag;
412
+ var objIsObj = objTag == objectTag, othIsObj = othTag == objectTag, isSameTag = objTag == othTag;
413
+ if (isSameTag && isBuffer(object)) {
414
+ if (!isBuffer(other)) {
415
+ return false;
416
+ }
417
+ objIsArr = true;
418
+ objIsObj = false;
419
+ }
420
+ if (isSameTag && !objIsObj) {
421
+ stack || (stack = new Stack());
422
+ return objIsArr || isTypedArray(object) ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
423
+ }
424
+ if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
425
+ var objIsWrapped = objIsObj && hasOwnProperty.call(object, "__wrapped__"), othIsWrapped = othIsObj && hasOwnProperty.call(other, "__wrapped__");
426
+ if (objIsWrapped || othIsWrapped) {
427
+ var objUnwrapped = objIsWrapped ? object.value() : object, othUnwrapped = othIsWrapped ? other.value() : other;
428
+ stack || (stack = new Stack());
429
+ return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
430
+ }
431
+ }
432
+ if (!isSameTag) {
433
+ return false;
434
+ }
435
+ stack || (stack = new Stack());
436
+ return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
437
+ }
438
+ function baseIsNative(value) {
439
+ if (!isObject(value) || isMasked(value)) {
440
+ return false;
441
+ }
442
+ var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
443
+ return pattern.test(toSource(value));
444
+ }
445
+ function baseIsTypedArray(value) {
446
+ return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
447
+ }
448
+ function baseKeys(object) {
449
+ if (!isPrototype(object)) {
450
+ return nativeKeys(object);
451
+ }
452
+ var result = [];
453
+ for (var key in Object(object)) {
454
+ if (hasOwnProperty.call(object, key) && key != "constructor") {
455
+ result.push(key);
456
+ }
457
+ }
458
+ return result;
459
+ }
460
+ function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
461
+ var isPartial = bitmask & COMPARE_PARTIAL_FLAG, arrLength = array.length, othLength = other.length;
462
+ if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
463
+ return false;
464
+ }
465
+ var stacked = stack.get(array);
466
+ if (stacked && stack.get(other)) {
467
+ return stacked == other;
468
+ }
469
+ var index = -1, result = true, seen = bitmask & COMPARE_UNORDERED_FLAG ? new SetCache() : void 0;
470
+ stack.set(array, other);
471
+ stack.set(other, array);
472
+ while (++index < arrLength) {
473
+ var arrValue = array[index], othValue = other[index];
474
+ if (customizer) {
475
+ var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
476
+ }
477
+ if (compared !== void 0) {
478
+ if (compared) {
479
+ continue;
480
+ }
481
+ result = false;
482
+ break;
483
+ }
484
+ if (seen) {
485
+ if (!arraySome(other, function(othValue2, othIndex) {
486
+ if (!cacheHas(seen, othIndex) && (arrValue === othValue2 || equalFunc(arrValue, othValue2, bitmask, customizer, stack))) {
487
+ return seen.push(othIndex);
488
+ }
489
+ })) {
490
+ result = false;
491
+ break;
492
+ }
493
+ } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
494
+ result = false;
495
+ break;
496
+ }
497
+ }
498
+ stack["delete"](array);
499
+ stack["delete"](other);
500
+ return result;
501
+ }
502
+ function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
503
+ switch (tag) {
504
+ case dataViewTag:
505
+ if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
506
+ return false;
507
+ }
508
+ object = object.buffer;
509
+ other = other.buffer;
510
+ case arrayBufferTag:
511
+ if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
512
+ return false;
513
+ }
514
+ return true;
515
+ case boolTag:
516
+ case dateTag:
517
+ case numberTag:
518
+ return eq(+object, +other);
519
+ case errorTag:
520
+ return object.name == other.name && object.message == other.message;
521
+ case regexpTag:
522
+ case stringTag:
523
+ return object == other + "";
524
+ case mapTag:
525
+ var convert = mapToArray;
526
+ case setTag:
527
+ var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
528
+ convert || (convert = setToArray);
529
+ if (object.size != other.size && !isPartial) {
530
+ return false;
531
+ }
532
+ var stacked = stack.get(object);
533
+ if (stacked) {
534
+ return stacked == other;
535
+ }
536
+ bitmask |= COMPARE_UNORDERED_FLAG;
537
+ stack.set(object, other);
538
+ var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
539
+ stack["delete"](object);
540
+ return result;
541
+ case symbolTag:
542
+ if (symbolValueOf) {
543
+ return symbolValueOf.call(object) == symbolValueOf.call(other);
544
+ }
545
+ }
176
546
  return false;
177
547
  }
178
- return false;
179
- }
180
- /**
181
- * Convert Swagger path to template literals/ template strings(camelcase)
182
- * @example /pet/{petId} => `/pet/${petId}`
183
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
184
- * @example /account/userID => `/account/${userId}`
185
- */
186
- get template() {
187
- return this.toTemplateString();
188
- }
189
- get object() {
190
- return this.toObject();
191
- }
192
- get params() {
193
- return this.getParams();
194
- }
195
- toObject({ type = "path", replacer, stringify } = {}) {
196
- const object = {
197
- url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
198
- params: this.getParams()
548
+ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
549
+ var isPartial = bitmask & COMPARE_PARTIAL_FLAG, objProps = getAllKeys(object), objLength = objProps.length, othProps = getAllKeys(other), othLength = othProps.length;
550
+ if (objLength != othLength && !isPartial) {
551
+ return false;
552
+ }
553
+ var index = objLength;
554
+ while (index--) {
555
+ var key = objProps[index];
556
+ if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
557
+ return false;
558
+ }
559
+ }
560
+ var stacked = stack.get(object);
561
+ if (stacked && stack.get(other)) {
562
+ return stacked == other;
563
+ }
564
+ var result = true;
565
+ stack.set(object, other);
566
+ stack.set(other, object);
567
+ var skipCtor = isPartial;
568
+ while (++index < objLength) {
569
+ key = objProps[index];
570
+ var objValue = object[key], othValue = other[key];
571
+ if (customizer) {
572
+ var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
573
+ }
574
+ if (!(compared === void 0 ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
575
+ result = false;
576
+ break;
577
+ }
578
+ skipCtor || (skipCtor = key == "constructor");
579
+ }
580
+ if (result && !skipCtor) {
581
+ var objCtor = object.constructor, othCtor = other.constructor;
582
+ if (objCtor != othCtor && ("constructor" in object && "constructor" in other) && !(typeof objCtor == "function" && objCtor instanceof objCtor && typeof othCtor == "function" && othCtor instanceof othCtor)) {
583
+ result = false;
584
+ }
585
+ }
586
+ stack["delete"](object);
587
+ stack["delete"](other);
588
+ return result;
589
+ }
590
+ function getAllKeys(object) {
591
+ return baseGetAllKeys(object, keys, getSymbols);
592
+ }
593
+ function getMapData(map, key) {
594
+ var data = map.__data__;
595
+ return isKeyable(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
596
+ }
597
+ function getNative(object, key) {
598
+ var value = getValue(object, key);
599
+ return baseIsNative(value) ? value : void 0;
600
+ }
601
+ function getRawTag(value) {
602
+ var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
603
+ try {
604
+ value[symToStringTag] = void 0;
605
+ var unmasked = true;
606
+ } catch (e) {
607
+ }
608
+ var result = nativeObjectToString.call(value);
609
+ if (unmasked) {
610
+ if (isOwn) {
611
+ value[symToStringTag] = tag;
612
+ } else {
613
+ delete value[symToStringTag];
614
+ }
615
+ }
616
+ return result;
617
+ }
618
+ var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
619
+ if (object == null) {
620
+ return [];
621
+ }
622
+ object = Object(object);
623
+ return arrayFilter(nativeGetSymbols(object), function(symbol) {
624
+ return propertyIsEnumerable.call(object, symbol);
625
+ });
199
626
  };
200
- if (stringify) {
201
- if (type !== "template") {
202
- throw new Error("Type should be `template` when using stringiyf");
627
+ var getTag = baseGetTag;
628
+ if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map2 && getTag(new Map2()) != mapTag || Promise2 && getTag(Promise2.resolve()) != promiseTag || Set2 && getTag(new Set2()) != setTag || WeakMap2 && getTag(new WeakMap2()) != weakMapTag) {
629
+ getTag = function(value) {
630
+ var result = baseGetTag(value), Ctor = result == objectTag ? value.constructor : void 0, ctorString = Ctor ? toSource(Ctor) : "";
631
+ if (ctorString) {
632
+ switch (ctorString) {
633
+ case dataViewCtorString:
634
+ return dataViewTag;
635
+ case mapCtorString:
636
+ return mapTag;
637
+ case promiseCtorString:
638
+ return promiseTag;
639
+ case setCtorString:
640
+ return setTag;
641
+ case weakMapCtorString:
642
+ return weakMapTag;
643
+ }
644
+ }
645
+ return result;
646
+ };
647
+ }
648
+ function isIndex(value, length) {
649
+ length = length == null ? MAX_SAFE_INTEGER : length;
650
+ return !!length && (typeof value == "number" || reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
651
+ }
652
+ function isKeyable(value) {
653
+ var type = typeof value;
654
+ return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
655
+ }
656
+ function isMasked(func) {
657
+ return !!maskSrcKey && maskSrcKey in func;
658
+ }
659
+ function isPrototype(value) {
660
+ var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto;
661
+ return value === proto;
662
+ }
663
+ function objectToString(value) {
664
+ return nativeObjectToString.call(value);
665
+ }
666
+ function toSource(func) {
667
+ if (func != null) {
668
+ try {
669
+ return funcToString.call(func);
670
+ } catch (e) {
671
+ }
672
+ try {
673
+ return func + "";
674
+ } catch (e) {
675
+ }
203
676
  }
204
- return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
677
+ return "";
205
678
  }
206
- return object;
207
- }
208
- /**
209
- * Convert Swagger path to template literals/ template strings(camelcase)
210
- * @example /pet/{petId} => `/pet/${petId}`
211
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
212
- * @example /account/userID => `/account/${userId}`
213
- */
214
- toTemplateString(replacer) {
215
- const regex = /{(\w|-)*}/g;
216
- const found = this.path.match(regex);
217
- let newPath = this.path.replaceAll("{", "${");
218
- if (found) {
219
- newPath = found.reduce((prev, curr) => {
220
- const pathParam = replacer ? replacer(camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge });
221
- const replacement = `\${${pathParam}}`;
222
- return prev.replace(curr, replacement);
223
- }, this.path);
224
- }
225
- return `\`${newPath}\``;
226
- }
227
- getParams(replacer) {
228
- const regex = /{(\w|-)*}/g;
229
- const found = this.path.match(regex);
230
- if (!found) {
231
- return void 0;
679
+ function eq(value, other) {
680
+ return value === other || value !== value && other !== other;
232
681
  }
233
- const params = {};
234
- found.forEach((item) => {
235
- item = item.replaceAll("{", "").replaceAll("}", "");
236
- const pathParam = replacer ? replacer(camelCase(item, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(item, { delimiter: "", transform: camelCaseTransformMerge });
237
- params[pathParam] = pathParam;
238
- }, this.path);
239
- return params;
240
- }
241
- /**
242
- * Convert Swagger path to URLPath(syntax of Express)
243
- * @example /pet/{petId} => /pet/:petId
244
- */
245
- toURLPath() {
246
- return this.path.replaceAll("{", ":").replaceAll("}", "");
682
+ var isArguments = baseIsArguments(/* @__PURE__ */ function() {
683
+ return arguments;
684
+ }()) ? baseIsArguments : function(value) {
685
+ return isObjectLike(value) && hasOwnProperty.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
686
+ };
687
+ var isArray = Array.isArray;
688
+ function isArrayLike(value) {
689
+ return value != null && isLength(value.length) && !isFunction(value);
690
+ }
691
+ var isBuffer = nativeIsBuffer || stubFalse;
692
+ function isEqual2(value, other) {
693
+ return baseIsEqual(value, other);
694
+ }
695
+ function isFunction(value) {
696
+ if (!isObject(value)) {
697
+ return false;
698
+ }
699
+ var tag = baseGetTag(value);
700
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
701
+ }
702
+ function isLength(value) {
703
+ return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
704
+ }
705
+ function isObject(value) {
706
+ var type = typeof value;
707
+ return value != null && (type == "object" || type == "function");
708
+ }
709
+ function isObjectLike(value) {
710
+ return value != null && typeof value == "object";
711
+ }
712
+ var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
713
+ function keys(object) {
714
+ return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
715
+ }
716
+ function stubArray() {
717
+ return [];
718
+ }
719
+ function stubFalse() {
720
+ return false;
721
+ }
722
+ module.exports = isEqual2;
247
723
  }
248
- };
724
+ });
725
+
726
+ // src/index.ts
727
+ init_esm_shims();
728
+
729
+ // src/build.ts
730
+ init_esm_shims();
249
731
 
250
732
  // src/config.ts
733
+ init_esm_shims();
251
734
  function defineConfig(options) {
252
735
  return options;
253
736
  }
@@ -255,255 +738,15 @@ function isInputPath(result) {
255
738
  return !!result && "path" in result;
256
739
  }
257
740
 
258
- // src/utils/timeout.ts
259
- async function timeout(ms) {
260
- return new Promise((resolve2) => {
261
- setTimeout(() => {
262
- resolve2(true);
263
- }, ms);
264
- });
265
- }
266
-
267
- // src/utils/transformers/combineCodes.ts
268
- function combineCodes(codes) {
269
- return codes.join("\n");
270
- }
271
-
272
- // src/utils/transformers/createJSDocBlockText.ts
273
- function createJSDocBlockText({ comments }) {
274
- const filteredComments = comments.filter(Boolean);
275
- if (!filteredComments.length) {
276
- return "";
277
- }
278
- return `/**
279
- * ${filteredComments.join("\n * ")}
280
- */`;
281
- }
282
-
283
- // src/utils/transformers/escape.ts
284
- function escape(text) {
285
- return text ? text.replaceAll("`", "\\`") : "";
286
- }
287
- function jsStringEscape(input) {
288
- return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
289
- switch (character) {
290
- case '"':
291
- case "'":
292
- case "\\":
293
- return "\\" + character;
294
- case "\n":
295
- return "\\n";
296
- case "\r":
297
- return "\\r";
298
- case "\u2028":
299
- return "\\u2028";
300
- case "\u2029":
301
- return "\\u2029";
302
- default:
303
- return "";
304
- }
305
- });
306
- }
307
-
308
- // src/utils/transformers/indent.ts
309
- function createIndent(size) {
310
- return Array.from({ length: size + 1 }).join(" ");
311
- }
312
-
313
- // src/utils/transformers/nameSorter.ts
314
- function nameSorter(a, b) {
315
- if (a.name < b.name) {
316
- return -1;
317
- }
318
- if (a.name > b.name) {
319
- return 1;
320
- }
321
- return 0;
322
- }
323
-
324
- // src/utils/transformers/searchAndReplace.ts
325
- function searchAndReplace(options) {
326
- const { text, replaceBy, prefix = "", key } = options;
327
- const searchValues = options.searchValues?.(prefix, key) || [
328
- `${prefix}["${key}"]`,
329
- `${prefix}['${key}']`,
330
- `${prefix}[\`${key}\`]`,
331
- `${prefix}"${key}"`,
332
- `${prefix}'${key}'`,
333
- `${prefix}\`${key}\``,
334
- new RegExp(`${prefix}${key}`, "g")
335
- ];
336
- return searchValues.reduce((prev, searchValue) => {
337
- return prev.toString().replaceAll(searchValue, replaceBy);
338
- }, text);
339
- }
340
-
341
- // src/utils/transformers/transformReservedWord.ts
342
- var reservedWords = [
343
- "abstract",
344
- "arguments",
345
- "boolean",
346
- "break",
347
- "byte",
348
- "case",
349
- "catch",
350
- "char",
351
- "class",
352
- "const",
353
- "continue",
354
- "debugger",
355
- "default",
356
- "delete",
357
- "do",
358
- "double",
359
- "else",
360
- "enum",
361
- "eval",
362
- "export",
363
- "extends",
364
- "false",
365
- "final",
366
- "finally",
367
- "float",
368
- "for",
369
- "function",
370
- "goto",
371
- "if",
372
- "implements",
373
- "import",
374
- "in",
375
- "instanceof",
376
- "int",
377
- "interface",
378
- "let",
379
- "long",
380
- "native",
381
- "new",
382
- "null",
383
- "package",
384
- "private",
385
- "protected",
386
- "public",
387
- "return",
388
- "short",
389
- "static",
390
- "super",
391
- "switch",
392
- "synchronized",
393
- "this",
394
- "throw",
395
- "throws",
396
- "transient",
397
- "true",
398
- "try",
399
- "typeof",
400
- "var",
401
- "void",
402
- "volatile",
403
- "while",
404
- "with",
405
- "yield",
406
- "Array",
407
- "Date",
408
- "eval",
409
- "function",
410
- "hasOwnProperty",
411
- "Infinity",
412
- "isFinite",
413
- "isNaN",
414
- "isPrototypeOf",
415
- "length",
416
- "Math",
417
- "name",
418
- "NaN",
419
- "Number",
420
- "Object",
421
- "prototype",
422
- "String",
423
- "toString",
424
- "undefined",
425
- "valueOf"
426
- ];
427
- function transformReservedWord(word) {
428
- if (word && reservedWords.includes(word) || word?.match(/^\d/)) {
429
- return `_${word}`;
430
- }
431
- return word;
432
- }
433
-
434
- // src/utils/transformers/index.ts
435
- var transformers = {
436
- combineCodes,
437
- escape,
438
- jsStringEscape,
439
- createIndent,
440
- transformReservedWord,
441
- nameSorter,
442
- searchAndReplace,
443
- JSDoc: {
444
- createJSDocBlockText
445
- }
446
- };
447
- async function saveCreateDirectory(path3) {
448
- const passedPath = dirname(resolve(path3));
449
- await fs2.mkdir(passedPath, { recursive: true });
450
- }
451
- var writer = switcher(
452
- {
453
- node: async (path3, data) => {
454
- try {
455
- await fs2.stat(resolve(path3));
456
- const oldContent = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
457
- if (oldContent?.toString() === data?.toString()) {
458
- return;
459
- }
460
- } catch (_err) {
461
- }
462
- await saveCreateDirectory(path3);
463
- await fs2.writeFile(resolve(path3), data, { encoding: "utf-8" });
464
- const savedData = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
465
- if (savedData?.toString() !== data?.toString()) {
466
- throw new Error(`Sanity check failed for ${path3}
467
-
468
- Data[${data.length}]:
469
- ${data}
470
-
471
- Saved[${savedData.length}]:
472
- ${savedData}
473
- `);
474
- }
475
- return savedData;
476
- },
477
- bun: async (path3, data) => {
478
- try {
479
- await saveCreateDirectory(path3);
480
- await Bun.write(resolve(path3), data);
481
- const file = Bun.file(resolve(path3));
482
- const savedData = await file.text();
483
- if (savedData?.toString() !== data?.toString()) {
484
- throw new Error(`Sanity check failed for ${path3}
741
+ // src/FileManager.ts
742
+ init_esm_shims();
743
+ var import_lodash = __toESM(require_lodash(), 1);
485
744
 
486
- Data[${data.length}]:
487
- ${data}
745
+ // src/BarrelManager.ts
746
+ init_esm_shims();
488
747
 
489
- Saved[${savedData.length}]:
490
- ${savedData}
491
- `);
492
- }
493
- return savedData;
494
- } catch (e) {
495
- console.log(e, resolve(path3));
496
- }
497
- }
498
- },
499
- "node"
500
- );
501
- async function write(data, path3) {
502
- if (data.trim() === "") {
503
- return void 0;
504
- }
505
- return writer(path3, data.trim());
506
- }
748
+ // src/utils/TreeNode.ts
749
+ init_esm_shims();
507
750
  var TreeNode = class _TreeNode {
508
751
  constructor(data, parent) {
509
752
  this.children = [];
@@ -594,78 +837,67 @@ var TreeNode = class _TreeNode {
594
837
  var _options;
595
838
  var BarrelManager = class {
596
839
  constructor(options = {}) {
597
- __privateAdd(this, _options, {});
840
+ __privateAdd(this, _options, void 0);
598
841
  __privateSet(this, _options, options);
599
842
  return this;
600
843
  }
601
- getIndexes(root, extName) {
602
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
603
- const extMapper = {
604
- ".ts": {
605
- extensions: /\.ts/,
606
- exclude: [/schemas/, /json/]
607
- },
608
- ".json": {
609
- extensions: /\.json/,
610
- exclude: []
611
- }
612
- };
613
- const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
844
+ getIndexes(pathToBuild) {
845
+ const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
846
+ const tree = TreeNode.build(pathToBuild, treeNode);
614
847
  if (!tree) {
615
848
  return null;
616
849
  }
617
- const fileReducer = (files2, currentTree) => {
618
- if (!currentTree.children) {
850
+ const fileReducer = (files, treeNode2) => {
851
+ if (!treeNode2.children) {
619
852
  return [];
620
853
  }
621
- if (currentTree.children?.length > 1) {
622
- const indexPath = path.resolve(currentTree.data.path, "index.ts");
623
- const exports = currentTree.children.filter(Boolean).map((file) => {
624
- const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
625
- if (importPath.includes("index") && indexPath.includes("index")) {
854
+ if (treeNode2.children.length > 1) {
855
+ const indexPath = path.resolve(treeNode2.data.path, "index.ts");
856
+ const exports = treeNode2.children.filter(Boolean).map((file) => {
857
+ const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`;
858
+ if (importPath.endsWith("index") && file.data.type === "file") {
626
859
  return void 0;
627
860
  }
628
861
  return {
629
- path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
862
+ path: extName ? `${importPath}${extName}` : importPath,
630
863
  isTypeOnly
631
864
  };
632
865
  }).filter(Boolean);
633
- files2.push({
866
+ files.push({
634
867
  path: indexPath,
635
868
  baseName: "index.ts",
636
869
  source: "",
637
- exports: output ? exports?.filter((item) => {
638
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
639
- }) : exports
870
+ exports,
871
+ meta: {
872
+ treeNode: treeNode2
873
+ }
640
874
  });
641
- } else {
642
- currentTree.children?.forEach((child) => {
643
- const indexPath = path.resolve(currentTree.data.path, "index.ts");
644
- const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
645
- const exports = [
646
- {
647
- path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
648
- isTypeOnly
649
- }
650
- ];
651
- files2.push({
652
- path: indexPath,
653
- baseName: "index.ts",
654
- source: "",
655
- exports: output ? exports?.filter((item) => {
656
- return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
657
- }) : exports
658
- });
875
+ } else if (treeNode2.children.length === 1) {
876
+ const [treeNodeChild] = treeNode2.children;
877
+ const indexPath = path.resolve(treeNode2.data.path, "index.ts");
878
+ const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${trimExtName(treeNodeChild.data.name)}`;
879
+ const exports = [
880
+ {
881
+ path: extName ? `${importPath}${extName}` : importPath,
882
+ isTypeOnly
883
+ }
884
+ ];
885
+ files.push({
886
+ path: indexPath,
887
+ baseName: "index.ts",
888
+ source: "",
889
+ exports,
890
+ meta: {
891
+ treeNode: treeNode2
892
+ }
659
893
  });
660
894
  }
661
- currentTree.children.forEach((childItem) => {
662
- fileReducer(files2, childItem);
895
+ treeNode2.children.forEach((childItem) => {
896
+ fileReducer(files, childItem);
663
897
  });
664
- return files2;
898
+ return files;
665
899
  };
666
- const files = fileReducer([], tree).reverse();
667
- const filteredFiles = filter ? files.filter(filter) : files;
668
- return map ? filteredFiles.map(map) : filteredFiles;
900
+ return fileReducer([], tree).reverse();
669
901
  }
670
902
  };
671
903
  _options = new WeakMap();
@@ -674,25 +906,16 @@ _options = new WeakMap();
674
906
  var KubbFile;
675
907
  ((KubbFile2) => {
676
908
  })(KubbFile || (KubbFile = {}));
677
- var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
909
+ var _cache, _task, _queue, _add, add_fn, _addOrAppend, addOrAppend_fn;
678
910
  var _FileManager = class _FileManager {
679
- constructor(options) {
680
- __privateAdd(this, _validate);
911
+ constructor({ task = async (file) => file, queue = new PQueue() } = {}) {
681
912
  __privateAdd(this, _add);
682
913
  __privateAdd(this, _addOrAppend);
683
914
  __privateAdd(this, _cache, /* @__PURE__ */ new Map());
684
915
  __privateAdd(this, _task, void 0);
685
- __privateAdd(this, _isWriting, false);
686
- /**
687
- * Timeout between writes
688
- */
689
- __privateAdd(this, _timeout, 0);
690
916
  __privateAdd(this, _queue, void 0);
691
- if (options) {
692
- __privateSet(this, _task, options.task);
693
- __privateSet(this, _queue, options.queue);
694
- __privateSet(this, _timeout, options.timeout || 0);
695
- }
917
+ __privateSet(this, _task, task);
918
+ __privateSet(this, _queue, queue);
696
919
  return this;
697
920
  }
698
921
  get files() {
@@ -703,11 +926,10 @@ var _FileManager = class _FileManager {
703
926
  return files;
704
927
  }
705
928
  get isExecuting() {
706
- return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
929
+ return __privateGet(this, _queue).size !== 0 && __privateGet(this, _queue).pending !== 0;
707
930
  }
708
931
  async add(...files) {
709
- const promises = files.map((file) => {
710
- __privateMethod(this, _validate, validate_fn).call(this, file);
932
+ const promises = combineFiles(files).map((file) => {
711
933
  if (file.override) {
712
934
  return __privateMethod(this, _add, add_fn).call(this, file);
713
935
  }
@@ -719,12 +941,47 @@ var _FileManager = class _FileManager {
719
941
  }
720
942
  return resolvedFiles[0];
721
943
  }
722
- async addIndexes({ root, extName = ".ts", meta, options = {} }) {
723
- const barrelManager = new BarrelManager(options);
724
- const files = barrelManager.getIndexes(root, extName);
944
+ async addIndexes({ root, output, meta, options = {} }) {
945
+ const { exportType = "barrel" } = output;
946
+ if (!exportType) {
947
+ return void 0;
948
+ }
949
+ const exportPath = output.path.startsWith("./") ? trimExtName(output.path) : `./${trimExtName(output.path)}`;
950
+ const mode = _FileManager.getMode(output.path);
951
+ const barrelManager = new BarrelManager({ extName: output.extName, ...options });
952
+ const files = barrelManager.getIndexes(resolve(root, output.path));
953
+ function getPath() {
954
+ if (output.extName) {
955
+ if (mode === "directory") {
956
+ return `${exportPath}/index${output.extName}`;
957
+ }
958
+ return `${exportPath}${output.extName}`;
959
+ }
960
+ return exportPath;
961
+ }
725
962
  if (!files) {
726
963
  return void 0;
727
964
  }
965
+ const rootFile = {
966
+ path: resolve(root, "index.ts"),
967
+ baseName: "index.ts",
968
+ source: "",
969
+ exports: [
970
+ output.exportAs ? {
971
+ name: output.exportAs,
972
+ asAlias: true,
973
+ path: getPath(),
974
+ isTypeOnly: options.isTypeOnly
975
+ } : {
976
+ path: getPath(),
977
+ isTypeOnly: options.isTypeOnly
978
+ }
979
+ ]
980
+ };
981
+ await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
982
+ ...rootFile,
983
+ meta: meta ? meta : rootFile.meta
984
+ });
728
985
  return await Promise.all(
729
986
  files.map((file) => {
730
987
  return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
@@ -752,58 +1009,17 @@ var _FileManager = class _FileManager {
752
1009
  __privateGet(this, _cache).delete(path3);
753
1010
  }
754
1011
  async write(...params) {
755
- if (!__privateGet(this, _isWriting)) {
756
- __privateSet(this, _isWriting, true);
757
- const text = await write(...params);
758
- __privateSet(this, _isWriting, false);
759
- return text;
760
- }
761
- await timeout(__privateGet(this, _timeout));
762
- return this.write(...params);
1012
+ return write(...params);
763
1013
  }
764
1014
  async read(...params) {
765
1015
  return read(...params);
766
1016
  }
767
1017
  // statics
768
1018
  static getSource(file) {
769
- if (!_FileManager.isExtensionAllowed(file.baseName)) {
770
- return file.source;
771
- }
772
- const exports = file.exports ? combineExports(file.exports) : [];
773
- const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
774
- const importNodes = imports.map((item) => factory.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
775
- const exportNodes = exports.map(
776
- (item) => factory.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
777
- );
778
- return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
1019
+ return getSource(file);
779
1020
  }
780
1021
  static combineFiles(files) {
781
- return files.filter(Boolean).reduce((acc, file) => {
782
- const prevIndex = acc.findIndex((item) => item.path === file.path);
783
- if (prevIndex === -1) {
784
- return [...acc, file];
785
- }
786
- const prev = acc[prevIndex];
787
- if (prev && file.override) {
788
- acc[prevIndex] = {
789
- imports: [],
790
- exports: [],
791
- ...file
792
- };
793
- return acc;
794
- }
795
- if (prev) {
796
- acc[prevIndex] = {
797
- ...file,
798
- source: prev.source && file.source ? `${prev.source}
799
- ${file.source}` : "",
800
- imports: [...prev.imports || [], ...file.imports || []],
801
- exports: [...prev.exports || [], ...file.exports || []],
802
- env: { ...prev.env || {}, ...file.env || {} }
803
- };
804
- }
805
- return acc;
806
- }, []);
1022
+ return combineFiles(files);
807
1023
  }
808
1024
  static getMode(path3) {
809
1025
  if (!path3) {
@@ -820,33 +1036,19 @@ ${file.source}` : "",
820
1036
  };
821
1037
  _cache = new WeakMap();
822
1038
  _task = new WeakMap();
823
- _isWriting = new WeakMap();
824
- _timeout = new WeakMap();
825
1039
  _queue = new WeakMap();
826
- _validate = new WeakSet();
827
- validate_fn = function(file) {
828
- if (!file.validate) {
829
- return;
830
- }
831
- if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
832
- throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
833
- }
834
- };
835
1040
  _add = new WeakSet();
836
1041
  add_fn = async function(file) {
837
1042
  const controller = new AbortController();
838
- const resolvedFile = { id: crypto2.randomUUID(), ...file };
1043
+ const resolvedFile = { id: crypto.randomUUID(), name: trimExtName(file.baseName), ...file };
839
1044
  __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
840
- if (__privateGet(this, _queue)) {
841
- await __privateGet(this, _queue).run(
842
- async () => {
843
- var _a;
844
- return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
845
- },
846
- { controller }
847
- );
848
- }
849
- return resolvedFile;
1045
+ return __privateGet(this, _queue).add(
1046
+ async () => {
1047
+ var _a;
1048
+ return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
1049
+ },
1050
+ { signal: controller.signal }
1051
+ );
850
1052
  };
851
1053
  _addOrAppend = new WeakSet();
852
1054
  addOrAppend_fn = async function(file) {
@@ -866,16 +1068,69 @@ ${file.source}` : "",
866
1068
  return __privateMethod(this, _add, add_fn).call(this, file);
867
1069
  };
868
1070
  var FileManager = _FileManager;
1071
+ function combineFiles(files) {
1072
+ return files.filter(Boolean).reduce((acc, file) => {
1073
+ const prevIndex = acc.findIndex((item) => item.path === file.path);
1074
+ if (prevIndex === -1) {
1075
+ return [...acc, file];
1076
+ }
1077
+ const prev = acc[prevIndex];
1078
+ if (prev && file.override) {
1079
+ acc[prevIndex] = {
1080
+ imports: [],
1081
+ exports: [],
1082
+ ...file
1083
+ };
1084
+ return acc;
1085
+ }
1086
+ if (prev) {
1087
+ acc[prevIndex] = {
1088
+ ...file,
1089
+ source: prev.source && file.source ? `${prev.source}
1090
+ ${file.source}` : "",
1091
+ imports: [...prev.imports || [], ...file.imports || []],
1092
+ exports: [...prev.exports || [], ...file.exports || []],
1093
+ env: { ...prev.env || {}, ...file.env || {} }
1094
+ };
1095
+ }
1096
+ return acc;
1097
+ }, []);
1098
+ }
1099
+ function getSource(file) {
1100
+ if (!FileManager.isExtensionAllowed(file.baseName)) {
1101
+ return file.source;
1102
+ }
1103
+ const exports = file.exports ? combineExports(file.exports) : [];
1104
+ const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
1105
+ const importNodes = imports.filter((item) => {
1106
+ return item.path !== trimExtName(file.path);
1107
+ }).map((item) => {
1108
+ return factory.createImportDeclaration({
1109
+ name: item.name,
1110
+ path: item.root ? getRelativePath(item.root, item.path) : item.path,
1111
+ isTypeOnly: item.isTypeOnly
1112
+ });
1113
+ });
1114
+ const exportNodes = exports.map(
1115
+ (item) => factory.createExportDeclaration({
1116
+ name: item.name,
1117
+ path: item.path,
1118
+ isTypeOnly: item.isTypeOnly,
1119
+ asAlias: item.asAlias
1120
+ })
1121
+ );
1122
+ return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
1123
+ }
869
1124
  function combineExports(exports) {
870
1125
  const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
871
1126
  const name = curr.name;
872
1127
  const prevByPath = prev.findLast((imp) => imp.path === curr.path);
873
- const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
1128
+ const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && (0, import_lodash.default)(imp.name, name) && imp.isTypeOnly);
874
1129
  if (prevByPathAndIsTypeOnly) {
875
1130
  return prev;
876
1131
  }
877
1132
  const uniquePrev = prev.findLast(
878
- (imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
1133
+ (imp) => imp.path === curr.path && (0, import_lodash.default)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
879
1134
  );
880
1135
  if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
881
1136
  return prev;
@@ -908,11 +1163,11 @@ function combineImports(imports, exports, source) {
908
1163
  return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
909
1164
  };
910
1165
  if (Array.isArray(name)) {
911
- name = name.filter((item) => hasImportInSource(item));
1166
+ name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
912
1167
  }
913
1168
  const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
914
- const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
915
- const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
1169
+ const uniquePrev = prev.findLast((imp) => imp.path === curr.path && (0, import_lodash.default)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
1170
+ const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && (0, import_lodash.default)(imp.name, name) && imp.isTypeOnly);
916
1171
  if (prevByPathNameAndIsTypeOnly) {
917
1172
  return prev;
918
1173
  }
@@ -954,13 +1209,19 @@ function getEnvSource(source, env) {
954
1209
  throw new TypeError(`Environment should be in upperCase for ${key}`);
955
1210
  }
956
1211
  if (typeof replaceBy === "string") {
957
- prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
958
- prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
1212
+ prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
1213
+ prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
959
1214
  `, "ig"), ""), replaceBy, key });
960
1215
  }
961
1216
  return prev;
962
1217
  }, source);
963
1218
  }
1219
+
1220
+ // src/PluginManager.ts
1221
+ init_esm_shims();
1222
+
1223
+ // src/utils/EventEmitter.ts
1224
+ init_esm_shims();
964
1225
  var _emitter;
965
1226
  var EventEmitter = class {
966
1227
  constructor() {
@@ -981,127 +1242,9 @@ var EventEmitter = class {
981
1242
  }
982
1243
  };
983
1244
  _emitter = new WeakMap();
984
- var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
985
- var Queue = class {
986
- constructor(maxParallel, debug = false) {
987
- __privateAdd(this, _work);
988
- __privateAdd(this, _queue2, []);
989
- this.eventEmitter = new EventEmitter();
990
- __privateAdd(this, _workerCount, 0);
991
- __privateAdd(this, _maxParallel, void 0);
992
- __privateAdd(this, _debug, false);
993
- __privateSet(this, _maxParallel, maxParallel);
994
- __privateSet(this, _debug, debug);
995
- }
996
- run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
997
- return new Promise((resolve2, reject) => {
998
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
999
- options.controller?.signal.addEventListener("abort", () => {
1000
- __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1001
- reject("Aborted");
1002
- });
1003
- __privateGet(this, _queue2).push(item);
1004
- __privateMethod(this, _work, work_fn).call(this);
1005
- });
1006
- }
1007
- runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
1008
- new Promise((resolve2, reject) => {
1009
- const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
1010
- options.controller?.signal.addEventListener("abort", () => {
1011
- __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
1012
- });
1013
- __privateGet(this, _queue2).push(item);
1014
- __privateMethod(this, _work, work_fn).call(this);
1015
- });
1016
- }
1017
- get hasJobs() {
1018
- return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
1019
- }
1020
- get count() {
1021
- return __privateGet(this, _workerCount);
1022
- }
1023
- };
1024
- _queue2 = new WeakMap();
1025
- _workerCount = new WeakMap();
1026
- _maxParallel = new WeakMap();
1027
- _debug = new WeakMap();
1028
- _work = new WeakSet();
1029
- work_fn = function() {
1030
- if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
1031
- return;
1032
- }
1033
- __privateWrapper(this, _workerCount)._++;
1034
- let entry;
1035
- while (entry = __privateGet(this, _queue2).shift()) {
1036
- const { reject, resolve: resolve2, job, name, description } = entry;
1037
- if (__privateGet(this, _debug)) {
1038
- performance.mark(name + "_start");
1039
- }
1040
- job().then((result) => {
1041
- this.eventEmitter.emit("jobDone", result);
1042
- resolve2(result);
1043
- if (__privateGet(this, _debug)) {
1044
- performance.mark(name + "_stop");
1045
- performance.measure(description, name + "_start", name + "_stop");
1046
- }
1047
- }).catch((err) => {
1048
- this.eventEmitter.emit("jobFailed", err);
1049
- reject(err);
1050
- });
1051
- }
1052
- __privateWrapper(this, _workerCount)._--;
1053
- };
1054
-
1055
- // src/utils/uniqueName.ts
1056
- function setUniqueName(originalName, data) {
1057
- let used = data[originalName] || 0;
1058
- if (used) {
1059
- data[originalName] = ++used;
1060
- return originalName;
1061
- }
1062
- data[originalName] = 1;
1063
- return originalName;
1064
- }
1065
1245
 
1066
1246
  // src/errors.ts
1067
- var PluginError = class extends Error {
1068
- constructor(message, options) {
1069
- super(message, { cause: options.cause });
1070
- this.name = "PluginError";
1071
- this.cause = options.cause;
1072
- this.pluginManager = options.pluginManager;
1073
- }
1074
- };
1075
- var ParallelPluginError = class extends Error {
1076
- constructor(message, options) {
1077
- super(message, { cause: options.cause });
1078
- this.errors = [];
1079
- this.name = "ParallelPluginError";
1080
- this.errors = options.errors;
1081
- this.pluginManager = options.pluginManager;
1082
- }
1083
- findError(searchError) {
1084
- if (!searchError) {
1085
- return void 0;
1086
- }
1087
- return this.errors.find((error) => {
1088
- if (error.cause) {
1089
- if (error.cause.name == searchError.name) {
1090
- return true;
1091
- }
1092
- return !!this.findError(error.cause);
1093
- }
1094
- return error.name === searchError.name;
1095
- })?.cause;
1096
- }
1097
- };
1098
- var SummaryError = class extends Error {
1099
- constructor(message, options) {
1100
- super(message, { cause: options.cause });
1101
- this.name = "SummaryError";
1102
- this.summary = options.summary || [];
1103
- }
1104
- };
1247
+ init_esm_shims();
1105
1248
  var Warning = class extends Error {
1106
1249
  constructor(message, options) {
1107
1250
  super(message, { cause: options?.cause });
@@ -1111,7 +1254,11 @@ var Warning = class extends Error {
1111
1254
  var ValidationPluginError = class extends Error {
1112
1255
  };
1113
1256
 
1257
+ // src/plugin.ts
1258
+ init_esm_shims();
1259
+
1114
1260
  // src/utils/cache.ts
1261
+ init_esm_shims();
1115
1262
  function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
1116
1263
  return {
1117
1264
  set(id, value) {
@@ -1151,8 +1298,7 @@ var definePlugin = createPlugin((options) => {
1151
1298
  return {
1152
1299
  name: pluginName,
1153
1300
  options,
1154
- key: ["controller", "core"],
1155
- kind: "controller",
1301
+ key: ["core"],
1156
1302
  api() {
1157
1303
  return {
1158
1304
  get config() {
@@ -1189,7 +1335,11 @@ var definePlugin = createPlugin((options) => {
1189
1335
  };
1190
1336
  });
1191
1337
 
1338
+ // src/PromiseManager.ts
1339
+ init_esm_shims();
1340
+
1192
1341
  // src/utils/executeStrategies.ts
1342
+ init_esm_shims();
1193
1343
  function hookSeq(promises) {
1194
1344
  return promises.filter(Boolean).reduce(
1195
1345
  (promise, func) => {
@@ -1219,6 +1369,9 @@ function hookFirst(promises, nullCheck = (state) => state !== null) {
1219
1369
  }
1220
1370
  return promise;
1221
1371
  }
1372
+ function hookParallel(promises) {
1373
+ return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
1374
+ }
1222
1375
 
1223
1376
  // src/PromiseManager.ts
1224
1377
  var _options2;
@@ -1235,6 +1388,9 @@ var PromiseManager = class {
1235
1388
  if (strategy === "first") {
1236
1389
  return hookFirst(promises, __privateGet(this, _options2).nullCheck);
1237
1390
  }
1391
+ if (strategy === "parallel") {
1392
+ return hookParallel(promises);
1393
+ }
1238
1394
  throw new Error(`${strategy} not implemented`);
1239
1395
  }
1240
1396
  };
@@ -1270,7 +1426,7 @@ var PluginManager = class {
1270
1426
  __privateAdd(this, _executeSync);
1271
1427
  __privateAdd(this, _catcher);
1272
1428
  __privateAdd(this, _parse);
1273
- this.eventEmitter = new EventEmitter();
1429
+ this.events = new EventEmitter();
1274
1430
  this.executed = [];
1275
1431
  __privateAdd(this, _core, void 0);
1276
1432
  __privateAdd(this, _usedPluginNames, {});
@@ -1282,11 +1438,14 @@ var PluginManager = class {
1282
1438
  hookName: "resolvePath",
1283
1439
  parameters: [params.baseName, params.directory, params.options]
1284
1440
  });
1285
- if (paths && paths?.length > 1) {
1286
- throw new Error(
1441
+ if (paths && paths?.length > 1 && this.logger.logLevel === LogLevel.debug) {
1442
+ this.logger.debug(
1287
1443
  `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1288
1444
 
1289
- Paths: ${JSON.stringify(paths, void 0, 2)}`
1445
+ Paths: ${JSON.stringify(paths, void 0, 2)}
1446
+
1447
+ Falling back on the first item.
1448
+ `
1290
1449
  );
1291
1450
  }
1292
1451
  return paths?.at(0);
@@ -1303,11 +1462,14 @@ Paths: ${JSON.stringify(paths, void 0, 2)}`
1303
1462
  hookName: "resolveName",
1304
1463
  parameters: [params.name, params.type]
1305
1464
  });
1306
- if (names && names?.length > 1) {
1307
- throw new Error(
1465
+ if (names && names?.length > 1 && this.logger.logLevel === LogLevel.debug) {
1466
+ this.logger.debug(
1308
1467
  `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1309
1468
 
1310
- Names: ${JSON.stringify(names, void 0, 2)}`
1469
+ Names: ${JSON.stringify(names, void 0, 2)}
1470
+
1471
+ Falling back on the first item.
1472
+ `
1311
1473
  );
1312
1474
  }
1313
1475
  return transformReservedWord(names?.at(0) || params.name);
@@ -1318,9 +1480,10 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1318
1480
  }).result;
1319
1481
  return transformReservedWord(name);
1320
1482
  };
1483
+ this.config = config;
1321
1484
  this.logger = options.logger;
1322
- this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1323
- this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1485
+ this.queue = new PQueue({ concurrency: 1 });
1486
+ this.fileManager = new FileManager({ task: options.task, queue: this.queue });
1324
1487
  __privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
1325
1488
  const plugins = config.plugins || [];
1326
1489
  const core = definePlugin({
@@ -1338,11 +1501,14 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1338
1501
  });
1339
1502
  return this;
1340
1503
  }
1504
+ /**
1505
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
1506
+ */
1341
1507
  on(eventName, handler) {
1342
- this.eventEmitter.on(eventName, handler);
1508
+ this.events.on(eventName, handler);
1343
1509
  }
1344
1510
  /**
1345
- * Run only hook for a specific plugin name
1511
+ * Run a specific hookName for plugin x.
1346
1512
  */
1347
1513
  hookForPlugin({
1348
1514
  pluginKey,
@@ -1360,6 +1526,9 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1360
1526
  }).filter(Boolean);
1361
1527
  return Promise.all(promises);
1362
1528
  }
1529
+ /**
1530
+ * Run a specific hookName for plugin x.
1531
+ */
1363
1532
  hookForPluginSync({
1364
1533
  pluginKey,
1365
1534
  hookName,
@@ -1376,7 +1545,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1376
1545
  }).filter(Boolean);
1377
1546
  }
1378
1547
  /**
1379
- * Chains, first non-null result stops and returns
1548
+ * First non-null result stops and will return it's value.
1380
1549
  */
1381
1550
  async hookFirst({
1382
1551
  hookName,
@@ -1404,7 +1573,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1404
1573
  return __privateGet(this, _promiseManager).run("first", promises);
1405
1574
  }
1406
1575
  /**
1407
- * Chains, first non-null result stops and returns
1576
+ * First non-null result stops and will return it's value.
1408
1577
  */
1409
1578
  hookFirstSync({
1410
1579
  hookName,
@@ -1432,33 +1601,26 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1432
1601
  return parseResult;
1433
1602
  }
1434
1603
  /**
1435
- * Parallel, runs all plugins
1604
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
1436
1605
  */
1437
1606
  async hookParallel({
1438
1607
  hookName,
1439
1608
  parameters
1440
1609
  }) {
1441
- const parallelPromises = [];
1442
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1443
- const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
1444
- if (promise) {
1445
- parallelPromises.push(promise);
1446
- }
1447
- }
1448
- const results = await Promise.allSettled(parallelPromises);
1449
- const errors = results.map((result) => {
1450
- if (isPromiseRejectedResult(result) && result.reason instanceof PluginError) {
1451
- return result.reason;
1610
+ const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
1611
+ return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
1612
+ });
1613
+ const results = await __privateGet(this, _promiseManager).run("parallel", promises);
1614
+ results.forEach((result, index) => {
1615
+ if (isPromiseRejectedResult(result)) {
1616
+ const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
1617
+ __privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
1452
1618
  }
1453
- return void 0;
1454
- }).filter(Boolean);
1455
- if (errors.length) {
1456
- throw new ParallelPluginError("Error", { errors, pluginManager: this });
1457
- }
1619
+ });
1458
1620
  return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
1459
1621
  }
1460
1622
  /**
1461
- * Chains, reduces returned value, handling the reduced value as the first hook argument
1623
+ * Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
1462
1624
  */
1463
1625
  hookReduceArg0({
1464
1626
  hookName,
@@ -1496,24 +1658,23 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1496
1658
  }
1497
1659
  getPluginsByKey(hookName, pluginKey) {
1498
1660
  const plugins = [...this.plugins];
1499
- const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
1661
+ const [searchPluginName, searchIdentifier] = pluginKey;
1500
1662
  const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
1501
- const [kind, name, identifier] = item.key;
1663
+ const [name, identifier] = item.key;
1502
1664
  const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
1503
- const kindCheck = kind === searchKind;
1504
1665
  const nameCheck = name === searchPluginName;
1505
1666
  if (searchIdentifier) {
1506
- return identifierCheck && kindCheck && nameCheck;
1667
+ return identifierCheck && nameCheck;
1507
1668
  }
1508
- return kindCheck && nameCheck;
1669
+ return nameCheck;
1509
1670
  });
1510
1671
  if (!pluginByPluginName?.length) {
1511
1672
  const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
1512
- if (this.logger.logLevel === "info") {
1673
+ if (this.logger.logLevel === LogLevel.debug) {
1513
1674
  if (corePlugin) {
1514
- this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1675
+ this.logger.debug(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
1515
1676
  } else {
1516
- this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
1677
+ this.logger.debug(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
1517
1678
  }
1518
1679
  }
1519
1680
  return corePlugin ? [corePlugin] : [];
@@ -1537,7 +1698,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1537
1698
  }
1538
1699
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1539
1700
  static get hooks() {
1540
- return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1701
+ return ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1541
1702
  }
1542
1703
  };
1543
1704
  _core = new WeakMap();
@@ -1547,7 +1708,7 @@ _getSortedPlugins = new WeakSet();
1547
1708
  getSortedPlugins_fn = function(hookName) {
1548
1709
  const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1549
1710
  if (hookName) {
1550
- if (this.logger.logLevel === "info") {
1711
+ if (this.logger.logLevel === LogLevel.info) {
1551
1712
  const containsHookName = plugins.some((item) => item[hookName]);
1552
1713
  if (!containsHookName) {
1553
1714
  this.logger.warn(`No hook ${hookName} found`);
@@ -1555,12 +1716,28 @@ getSortedPlugins_fn = function(hookName) {
1555
1716
  }
1556
1717
  return plugins.filter((item) => item[hookName]);
1557
1718
  }
1558
- return plugins;
1719
+ return plugins.map((plugin) => {
1720
+ if (plugin.pre) {
1721
+ const isValid = plugin.pre.every((pluginName2) => plugins.find((pluginToFind) => pluginToFind.name === pluginName2));
1722
+ if (!isValid) {
1723
+ throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
1724
+ }
1725
+ }
1726
+ return plugin;
1727
+ }).sort((a, b) => {
1728
+ if (b.pre?.includes(a.name)) {
1729
+ return 1;
1730
+ }
1731
+ if (b.post?.includes(a.name)) {
1732
+ return -1;
1733
+ }
1734
+ return 0;
1735
+ });
1559
1736
  };
1560
1737
  _addExecutedToCallStack = new WeakSet();
1561
1738
  addExecutedToCallStack_fn = function(executer) {
1562
1739
  if (executer) {
1563
- this.eventEmitter.emit("executed", executer);
1740
+ this.events.emit("executed", executer);
1564
1741
  this.executed.push(executer);
1565
1742
  }
1566
1743
  };
@@ -1576,7 +1753,7 @@ execute_fn = function({
1576
1753
  if (!hook) {
1577
1754
  return null;
1578
1755
  }
1579
- this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1756
+ this.events.emit("execute", { strategy, hookName, parameters, plugin });
1580
1757
  const task = Promise.resolve().then(() => {
1581
1758
  if (typeof hook === "function") {
1582
1759
  const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
@@ -1588,11 +1765,6 @@ execute_fn = function({
1588
1765
  return hook;
1589
1766
  }).then((result) => {
1590
1767
  output = result;
1591
- return result;
1592
- }).catch((e) => {
1593
- __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1594
- return null;
1595
- }).finally(() => {
1596
1768
  __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1597
1769
  parameters,
1598
1770
  output,
@@ -1600,6 +1772,10 @@ execute_fn = function({
1600
1772
  hookName,
1601
1773
  plugin
1602
1774
  });
1775
+ return result;
1776
+ }).catch((e) => {
1777
+ __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1778
+ return null;
1603
1779
  });
1604
1780
  return task;
1605
1781
  };
@@ -1615,7 +1791,7 @@ executeSync_fn = function({
1615
1791
  if (!hook) {
1616
1792
  return null;
1617
1793
  }
1618
- this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1794
+ this.events.emit("execute", { strategy, hookName, parameters, plugin });
1619
1795
  try {
1620
1796
  if (typeof hook === "function") {
1621
1797
  const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
@@ -1623,11 +1799,6 @@ executeSync_fn = function({
1623
1799
  return fn;
1624
1800
  }
1625
1801
  output = hook;
1626
- return hook;
1627
- } catch (e) {
1628
- __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1629
- return null;
1630
- } finally {
1631
1802
  __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1632
1803
  parameters,
1633
1804
  output,
@@ -1635,24 +1806,24 @@ executeSync_fn = function({
1635
1806
  hookName,
1636
1807
  plugin
1637
1808
  });
1809
+ return hook;
1810
+ } catch (e) {
1811
+ __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1812
+ return null;
1638
1813
  }
1639
1814
  };
1640
1815
  _catcher = new WeakSet();
1641
1816
  catcher_fn = function(e, plugin, hookName) {
1642
- const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1817
+ const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
1643
1818
  `;
1644
- const pluginError = new PluginError(text, { cause: e, pluginManager: this });
1645
- this.eventEmitter.emit("error", pluginError);
1646
- throw pluginError;
1819
+ this.logger.error(text);
1820
+ this.events.emit("error", e);
1647
1821
  };
1648
1822
  _parse = new WeakSet();
1649
1823
  parse_fn = function(plugin, pluginManager, context) {
1650
1824
  const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
1651
1825
  setUniqueName(plugin.name, usedPluginNames);
1652
- const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1653
- if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1654
- pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1655
- }
1826
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1656
1827
  if (!plugin.transform) {
1657
1828
  plugin.transform = function transform(code) {
1658
1829
  return code;
@@ -1676,8 +1847,9 @@ parse_fn = function(plugin, pluginManager, context) {
1676
1847
  async function transformReducer(_previousCode, result, _plugin) {
1677
1848
  return result;
1678
1849
  }
1679
- async function build(options) {
1850
+ async function setup(options) {
1680
1851
  const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
1852
+ let count = 0;
1681
1853
  try {
1682
1854
  if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
1683
1855
  await read(config.input.path);
@@ -1685,7 +1857,7 @@ async function build(options) {
1685
1857
  } catch (e) {
1686
1858
  if (isInputPath(config)) {
1687
1859
  throw new Error(
1688
- "Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3.dim(config.input.path),
1860
+ "Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + p.dim(config.input.path),
1689
1861
  {
1690
1862
  cause: e
1691
1863
  }
@@ -1695,96 +1867,134 @@ async function build(options) {
1695
1867
  if (config.output.clean) {
1696
1868
  await clean(config.output.path);
1697
1869
  }
1698
- const queueTask = async (file) => {
1870
+ const task = async (file) => {
1699
1871
  const { path: path3 } = file;
1700
- let code = FileManager.getSource(file);
1872
+ let source = FileManager.getSource(file);
1701
1873
  const { result: loadedResult } = await pluginManager.hookFirst({
1702
1874
  hookName: "load",
1703
1875
  parameters: [path3]
1704
1876
  });
1705
1877
  if (loadedResult && isPromise(loadedResult)) {
1706
- code = await loadedResult;
1878
+ source = await loadedResult;
1707
1879
  }
1708
1880
  if (loadedResult && !isPromise(loadedResult)) {
1709
- code = loadedResult;
1881
+ source = loadedResult;
1710
1882
  }
1711
- if (code) {
1712
- const transformedCode = await pluginManager.hookReduceArg0({
1883
+ if (source) {
1884
+ source = await pluginManager.hookReduceArg0({
1713
1885
  hookName: "transform",
1714
- parameters: [code, path3],
1886
+ parameters: [source, path3],
1715
1887
  reduce: transformReducer
1716
1888
  });
1717
1889
  if (config.output.write || config.output.write === void 0) {
1718
1890
  if (file.meta?.pluginKey) {
1719
- return pluginManager.hookForPlugin({
1891
+ await pluginManager.hookForPlugin({
1720
1892
  pluginKey: file.meta?.pluginKey,
1721
1893
  hookName: "writeFile",
1722
- parameters: [transformedCode, path3]
1894
+ parameters: [source, path3]
1723
1895
  });
1724
1896
  }
1725
- return pluginManager.hookFirst({
1897
+ await pluginManager.hookFirst({
1726
1898
  hookName: "writeFile",
1727
- parameters: [transformedCode, path3]
1899
+ parameters: [source, path3]
1728
1900
  });
1729
1901
  }
1730
1902
  }
1903
+ return {
1904
+ ...file,
1905
+ source: source || ""
1906
+ };
1731
1907
  };
1732
- const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
1733
- const { plugins, fileManager } = pluginManager;
1908
+ const pluginManager = new PluginManager(config, { logger, task });
1734
1909
  pluginManager.on("execute", (executer) => {
1735
1910
  const { hookName, parameters, plugin } = executer;
1736
1911
  if (hookName === "writeFile" && logger.spinner) {
1737
1912
  const [code] = parameters;
1738
- if (logger.logLevel === LogLevel.info) {
1739
- logger.spinner.start(`\u{1F4BE} Writing`);
1740
- }
1741
- if (logger.logLevel === "debug") {
1742
- logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
1913
+ if (logger.logLevel === LogLevel.debug) {
1914
+ logger.debug(`PluginKey ${p.dim(JSON.stringify(plugin.key))}
1743
1915
  with source
1744
1916
 
1745
1917
  ${code}`);
1746
1918
  }
1747
1919
  }
1748
1920
  });
1921
+ pluginManager.queue.on("add", () => {
1922
+ if (logger.logLevel !== LogLevel.info) {
1923
+ return;
1924
+ }
1925
+ if (logger.spinner && count === 0) {
1926
+ logger.spinner?.start(`\u{1F4BE} Writing`);
1927
+ }
1928
+ });
1929
+ pluginManager.queue.on("active", () => {
1930
+ if (logger.logLevel !== LogLevel.info) {
1931
+ return;
1932
+ }
1933
+ if (logger.spinner && pluginManager.queue.size > 0) {
1934
+ const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
1935
+ logger.spinner.suffixText = p.dim(text);
1936
+ }
1937
+ ++count;
1938
+ });
1939
+ pluginManager.queue.on("completed", () => {
1940
+ if (logger.logLevel !== LogLevel.info) {
1941
+ return;
1942
+ }
1943
+ if (logger.spinner) {
1944
+ const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
1945
+ logger.spinner.suffixText = p.dim(text);
1946
+ }
1947
+ });
1749
1948
  pluginManager.on("executed", (executer) => {
1750
1949
  const { hookName, plugin, output, parameters } = executer;
1751
- const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
1752
- if (logger.logLevel === LogLevel.info && logger.spinner) {
1753
- if (hookName === "writeFile") {
1754
- const [_code, path3] = parameters;
1755
- logger.spinner.suffixText = pc3.dim(path3);
1756
- } else {
1757
- logger.spinner.suffixText = messsage;
1758
- }
1759
- }
1760
1950
  if (logger.logLevel === LogLevel.debug) {
1761
- logger.info(messsage);
1762
1951
  const logs = [
1763
- parameters && `${pc3.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
1952
+ `${randomCliColour(plugin.name)} Executing ${hookName}`,
1953
+ parameters && `${p.bgWhite(`Parameters`)} ${randomCliColour(plugin.name)} ${hookName}`,
1764
1954
  JSON.stringify(parameters, void 0, 2),
1765
- output && `${pc3.bgWhite("Output")} ${randomPicoColour(plugin.name)} ${hookName}`,
1955
+ output && `${p.bgWhite("Output")} ${randomCliColour(plugin.name)} ${hookName}`,
1766
1956
  output
1767
1957
  ].filter(Boolean);
1768
- console.log(logs.join("\n"));
1958
+ logger.debug(logs.join("\n"));
1769
1959
  }
1770
1960
  });
1771
- await pluginManager.hookParallel({
1772
- hookName: "validate",
1773
- parameters: [plugins]
1774
- });
1961
+ return pluginManager;
1962
+ }
1963
+ async function build(options) {
1964
+ const pluginManager = await setup(options);
1965
+ const { fileManager, logger } = pluginManager;
1775
1966
  await pluginManager.hookParallel({
1776
1967
  hookName: "buildStart",
1777
- parameters: [config]
1968
+ parameters: [options.config]
1778
1969
  });
1779
1970
  await pluginManager.hookParallel({ hookName: "buildEnd" });
1780
- if (!fileManager.isExecuting && logger.spinner) {
1971
+ if (logger.logLevel === LogLevel.info && logger.spinner) {
1781
1972
  logger.spinner.suffixText = "";
1782
1973
  logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1783
1974
  }
1784
1975
  return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
1785
1976
  }
1977
+ async function safeBuild(options) {
1978
+ const pluginManager = await setup(options);
1979
+ const { fileManager, logger } = pluginManager;
1980
+ try {
1981
+ await pluginManager.hookParallel({
1982
+ hookName: "buildStart",
1983
+ parameters: [options.config]
1984
+ });
1985
+ await pluginManager.hookParallel({ hookName: "buildEnd" });
1986
+ if (logger.logLevel === LogLevel.info && logger.spinner) {
1987
+ logger.spinner.suffixText = "";
1988
+ logger.spinner.succeed(`\u{1F4BE} Writing completed`);
1989
+ }
1990
+ } catch (e) {
1991
+ return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
1992
+ }
1993
+ return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
1994
+ }
1786
1995
 
1787
1996
  // src/Generator.ts
1997
+ init_esm_shims();
1788
1998
  var _options3, _context;
1789
1999
  var Generator = class {
1790
2000
  constructor(options, context) {
@@ -1810,9 +2020,13 @@ var Generator = class {
1810
2020
  };
1811
2021
  _options3 = new WeakMap();
1812
2022
  _context = new WeakMap();
1813
- var _cache2, _cwd, _SLASHES;
2023
+
2024
+ // src/PackageManager.ts
2025
+ init_esm_shims();
2026
+ var _cache2, _cwd, _SLASHES, _match, match_fn;
1814
2027
  var _PackageManager = class _PackageManager {
1815
2028
  constructor(workspace) {
2029
+ __privateAdd(this, _match);
1816
2030
  __privateAdd(this, _cwd, void 0);
1817
2031
  __privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
1818
2032
  if (workspace) {
@@ -1875,30 +2089,33 @@ var _PackageManager = class _PackageManager {
1875
2089
  __privateGet(_PackageManager, _cache2)[dependency] = version;
1876
2090
  }
1877
2091
  async getVersion(dependency) {
1878
- if (__privateGet(_PackageManager, _cache2)[dependency]) {
2092
+ if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
1879
2093
  return __privateGet(_PackageManager, _cache2)[dependency];
1880
2094
  }
1881
2095
  const packageJSON = await this.getPackageJSON();
1882
2096
  if (!packageJSON) {
1883
2097
  return void 0;
1884
2098
  }
1885
- return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
2099
+ return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
1886
2100
  }
1887
2101
  getVersionSync(dependency) {
1888
- if (__privateGet(_PackageManager, _cache2)[dependency]) {
2102
+ if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
1889
2103
  return __privateGet(_PackageManager, _cache2)[dependency];
1890
2104
  }
1891
2105
  const packageJSON = this.getPackageJSONSync();
1892
2106
  if (!packageJSON) {
1893
2107
  return void 0;
1894
2108
  }
1895
- return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
2109
+ return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
1896
2110
  }
1897
2111
  async isValid(dependency, version) {
1898
2112
  const packageVersion = await this.getVersion(dependency);
1899
2113
  if (!packageVersion) {
1900
2114
  return false;
1901
2115
  }
2116
+ if (packageVersion === version) {
2117
+ return true;
2118
+ }
1902
2119
  const semVer = coerce(packageVersion);
1903
2120
  if (!semVer) {
1904
2121
  throw new Error(`${packageVersion} is not valid`);
@@ -1920,16 +2137,24 @@ var _PackageManager = class _PackageManager {
1920
2137
  _cache2 = new WeakMap();
1921
2138
  _cwd = new WeakMap();
1922
2139
  _SLASHES = new WeakMap();
2140
+ _match = new WeakSet();
2141
+ match_fn = function(packageJSON, dependency) {
2142
+ const dependencies = {
2143
+ ...packageJSON["dependencies"] || {},
2144
+ ...packageJSON["devDependencies"] || {}
2145
+ };
2146
+ if (typeof dependency === "string" && dependencies[dependency]) {
2147
+ return dependencies[dependency];
2148
+ }
2149
+ const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
2150
+ return matchedDependency ? dependencies[matchedDependency] : void 0;
2151
+ };
1923
2152
  __privateAdd(_PackageManager, _cache2, {});
1924
2153
  var PackageManager = _PackageManager;
1925
2154
 
1926
- // src/SchemaGenerator.ts
1927
- var SchemaGenerator = class extends Generator {
1928
- };
1929
-
1930
2155
  // src/index.ts
1931
2156
  var src_default = build;
1932
2157
 
1933
- export { FileManager, Generator, KubbFile, PackageManager, ParallelPluginError, PluginError, PluginManager, PromiseManager, SchemaGenerator, SummaryError, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName };
2158
+ export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager, Warning, build, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
1934
2159
  //# sourceMappingURL=out.js.map
1935
2160
  //# sourceMappingURL=index.js.map