@kubb/core 3.16.2 → 3.16.3

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 (106) hide show
  1. package/dist/FileManager-Dk759iZ3.js +918 -0
  2. package/dist/FileManager-Dk759iZ3.js.map +1 -0
  3. package/dist/FileManager-DsRjYJa_.cjs +1031 -0
  4. package/dist/FileManager-DsRjYJa_.cjs.map +1 -0
  5. package/dist/PluginManager-1jPxuyQK.d.ts +511 -0
  6. package/dist/PluginManager-Cvj5AlsU.d.cts +511 -0
  7. package/dist/chunk-DWy1uDak.cjs +39 -0
  8. package/dist/chunk-DbvY3SJr.js +33 -0
  9. package/dist/fs-BacxV1CO.js +87 -0
  10. package/dist/fs-BacxV1CO.js.map +1 -0
  11. package/dist/fs-BazSaf2y.cjs +129 -0
  12. package/dist/fs-BazSaf2y.cjs.map +1 -0
  13. package/dist/fs.cjs +15 -39
  14. package/dist/fs.d.cts +2 -19
  15. package/dist/fs.d.ts +2 -19
  16. package/dist/fs.js +4 -3
  17. package/dist/index-BKHQGQVq.d.ts +140 -0
  18. package/dist/index-BfD6z1P5.d.cts +141 -0
  19. package/dist/index-Cb4pChs8.d.ts +180 -0
  20. package/dist/index-D2ptHzfn.d.cts +180 -0
  21. package/dist/index.cjs +997 -1077
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +107 -89
  24. package/dist/index.d.ts +107 -89
  25. package/dist/index.js +1020 -864
  26. package/dist/index.js.map +1 -1
  27. package/dist/logger-BxvJpQMX.cjs +1115 -0
  28. package/dist/logger-BxvJpQMX.cjs.map +1 -0
  29. package/dist/logger-Cs45J4yy.js +1085 -0
  30. package/dist/logger-Cs45J4yy.js.map +1 -0
  31. package/dist/logger-OWS6fqk0.d.cts +69 -0
  32. package/dist/logger-xcdTETKy.d.ts +69 -0
  33. package/dist/logger.cjs +6 -24
  34. package/dist/logger.d.cts +2 -3
  35. package/dist/logger.d.ts +2 -3
  36. package/dist/logger.js +4 -4
  37. package/dist/mocks.cjs +49 -65
  38. package/dist/mocks.cjs.map +1 -1
  39. package/dist/mocks.d.cts +6 -6
  40. package/dist/mocks.d.ts +6 -6
  41. package/dist/mocks.js +48 -59
  42. package/dist/mocks.js.map +1 -1
  43. package/dist/prompt-DwEAzq0q.js +853 -0
  44. package/dist/prompt-DwEAzq0q.js.map +1 -0
  45. package/dist/prompt-qiwl6Be9.cjs +855 -0
  46. package/dist/prompt-qiwl6Be9.cjs.map +1 -0
  47. package/dist/transformers-B3CHtwuB.cjs +948 -0
  48. package/dist/transformers-B3CHtwuB.cjs.map +1 -0
  49. package/dist/transformers-CJqBQFIl.js +829 -0
  50. package/dist/transformers-CJqBQFIl.js.map +1 -0
  51. package/dist/transformers.cjs +33 -88
  52. package/dist/transformers.d.cts +75 -54
  53. package/dist/transformers.d.ts +75 -54
  54. package/dist/transformers.js +4 -3
  55. package/dist/utils.cjs +20 -73
  56. package/dist/utils.d.cts +5 -126
  57. package/dist/utils.d.ts +5 -126
  58. package/dist/utils.js +6 -5
  59. package/dist/write-CLTPlucv.js +42 -0
  60. package/dist/write-CLTPlucv.js.map +1 -0
  61. package/dist/write-l_NzIqyy.cjs +48 -0
  62. package/dist/write-l_NzIqyy.cjs.map +1 -0
  63. package/package.json +25 -32
  64. package/src/BarrelManager.ts +1 -0
  65. package/src/PromiseManager.ts +1 -7
  66. package/src/build.ts +9 -11
  67. package/src/index.ts +5 -5
  68. package/src/logger.ts +10 -10
  69. package/src/utils/FunctionParams.ts +3 -1
  70. package/src/utils/TreeNode.ts +3 -1
  71. package/dist/PluginManager-E3SghPP9.d.cts +0 -458
  72. package/dist/PluginManager-PDmRCu9k.d.ts +0 -458
  73. package/dist/chunk-4V7HK7PT.js +0 -1199
  74. package/dist/chunk-4V7HK7PT.js.map +0 -1
  75. package/dist/chunk-BHSTNFNQ.cjs +0 -701
  76. package/dist/chunk-BHSTNFNQ.cjs.map +0 -1
  77. package/dist/chunk-CAZ37TGB.js +0 -918
  78. package/dist/chunk-CAZ37TGB.js.map +0 -1
  79. package/dist/chunk-E4XLCCPK.cjs +0 -170
  80. package/dist/chunk-E4XLCCPK.cjs.map +0 -1
  81. package/dist/chunk-GBYHPDPK.js +0 -595
  82. package/dist/chunk-GBYHPDPK.js.map +0 -1
  83. package/dist/chunk-L3A3DTAX.cjs +0 -1074
  84. package/dist/chunk-L3A3DTAX.cjs.map +0 -1
  85. package/dist/chunk-MCNA6SYG.cjs +0 -1231
  86. package/dist/chunk-MCNA6SYG.cjs.map +0 -1
  87. package/dist/chunk-YRPOID7E.js +0 -157
  88. package/dist/chunk-YRPOID7E.js.map +0 -1
  89. package/dist/fs.cjs.map +0 -1
  90. package/dist/fs.js.map +0 -1
  91. package/dist/logger-BWq-oJU_.d.cts +0 -63
  92. package/dist/logger-BWq-oJU_.d.ts +0 -63
  93. package/dist/logger.cjs.map +0 -1
  94. package/dist/logger.js.map +0 -1
  95. package/dist/parser-C1vOjVEd.d.ts +0 -41
  96. package/dist/parser-D6vU1kA9.d.cts +0 -41
  97. package/dist/prompt-ELTHGQK6.js +0 -753
  98. package/dist/prompt-ELTHGQK6.js.map +0 -1
  99. package/dist/prompt-U7M5G25C.cjs +0 -761
  100. package/dist/prompt-U7M5G25C.cjs.map +0 -1
  101. package/dist/transformers.cjs.map +0 -1
  102. package/dist/transformers.js.map +0 -1
  103. package/dist/types-CA8nQKwM.d.cts +0 -132
  104. package/dist/types-CA8nQKwM.d.ts +0 -132
  105. package/dist/utils.cjs.map +0 -1
  106. package/dist/utils.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,1136 +1,1055 @@
1
- 'use strict';
2
-
3
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
3
+ const require_fs = require('./fs-BazSaf2y.cjs');
4
+ require('./write-l_NzIqyy.cjs');
5
+ const require_logger = require('./logger-BxvJpQMX.cjs');
6
+ const require_transformers = require('./transformers-B3CHtwuB.cjs');
7
+ const require_FileManager = require('./FileManager-DsRjYJa_.cjs');
8
+ const node_path = require_chunk.__toESM(require("node:path"));
9
+ const picocolors = require_chunk.__toESM(require("picocolors"));
10
+ const remeda = require_chunk.__toESM(require("remeda"));
11
+ const node_process = require_chunk.__toESM(require("node:process"));
12
+ const node_module = require_chunk.__toESM(require("node:module"));
13
+ const node_os = require_chunk.__toESM(require("node:os"));
14
+ const node_url = require_chunk.__toESM(require("node:url"));
15
+ const node_fs = require_chunk.__toESM(require("node:fs"));
16
+ const semver = require_chunk.__toESM(require("semver"));
4
17
 
5
- var chunkMCNA6SYG_cjs = require('./chunk-MCNA6SYG.cjs');
6
- var chunkL3A3DTAX_cjs = require('./chunk-L3A3DTAX.cjs');
7
- var chunkBHSTNFNQ_cjs = require('./chunk-BHSTNFNQ.cjs');
8
- var chunkE4XLCCPK_cjs = require('./chunk-E4XLCCPK.cjs');
9
- var path3 = require('path');
10
- var remeda = require('remeda');
11
- var mod = require('module');
12
- var os = require('os');
13
- var url = require('url');
14
- var process2 = require('process');
15
- var fs = require('fs');
16
- var semver = require('semver');
17
-
18
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
+ //#region src/BaseGenerator.ts
19
+ /**
20
+ * Abstract class that contains the building blocks for plugins to create their own Generator
21
+ * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
22
+ */
23
+ var BaseGenerator = class {
24
+ #options = {};
25
+ #context = {};
26
+ constructor(options, context) {
27
+ if (context) this.#context = context;
28
+ if (options) this.#options = options;
29
+ return this;
30
+ }
31
+ get options() {
32
+ return this.#options;
33
+ }
34
+ get context() {
35
+ return this.#context;
36
+ }
37
+ set options(options) {
38
+ this.#options = {
39
+ ...this.#options,
40
+ ...options
41
+ };
42
+ }
43
+ };
19
44
 
20
- var path3__default = /*#__PURE__*/_interopDefault(path3);
21
- var mod__default = /*#__PURE__*/_interopDefault(mod);
22
- var os__default = /*#__PURE__*/_interopDefault(os);
23
- var process2__default = /*#__PURE__*/_interopDefault(process2);
24
- var fs__default = /*#__PURE__*/_interopDefault(fs);
45
+ //#endregion
46
+ //#region src/config.ts
47
+ /**
48
+ * Type helper to make it easier to use vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object.
49
+ */
50
+ function defineConfig(options) {
51
+ return options;
52
+ }
53
+ function isInputPath(result) {
54
+ return !!result && "path" in result?.input;
55
+ }
25
56
 
26
- // src/utils/executeStrategies.ts
57
+ //#endregion
58
+ //#region src/utils/executeStrategies.ts
59
+ /**
60
+ * Chains promises
61
+ */
27
62
  function hookSeq(promises) {
28
- return promises.filter(Boolean).reduce(
29
- (promise, func) => {
30
- if (typeof func !== "function") {
31
- throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
32
- }
33
- return promise.then((state) => {
34
- const calledFunc = func(state);
35
- if (calledFunc) {
36
- return calledFunc.then(Array.prototype.concat.bind(state));
37
- }
38
- });
39
- },
40
- Promise.resolve([])
41
- );
63
+ return promises.filter(Boolean).reduce((promise, func) => {
64
+ if (typeof func !== "function") throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
65
+ return promise.then((state) => {
66
+ const calledFunc = func(state);
67
+ if (calledFunc) return calledFunc.then(Array.prototype.concat.bind(state));
68
+ });
69
+ }, Promise.resolve([]));
42
70
  }
71
+ /**
72
+ * Chains promises, first non-null result stops and returns
73
+ */
43
74
  function hookFirst(promises, nullCheck = (state) => state !== null) {
44
- let promise = Promise.resolve(null);
45
- for (const func of promises.filter(Boolean)) {
46
- promise = promise.then((state) => {
47
- if (nullCheck(state)) {
48
- return state;
49
- }
50
- return func(state);
51
- });
52
- }
53
- return promise;
75
+ let promise = Promise.resolve(null);
76
+ for (const func of promises.filter(Boolean)) promise = promise.then((state) => {
77
+ if (nullCheck(state)) return state;
78
+ return func(state);
79
+ });
80
+ return promise;
54
81
  }
82
+ /**
83
+ * Runs an array of promise functions with optional concurrency limit.
84
+ */
55
85
  function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
56
- const limit = chunkL3A3DTAX_cjs.pLimit(concurrency);
57
- const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
58
- return Promise.allSettled(tasks);
86
+ const limit = require_FileManager.pLimit(concurrency);
87
+ const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
88
+ return Promise.allSettled(tasks);
59
89
  }
60
90
 
61
- // src/PromiseManager.ts
91
+ //#endregion
92
+ //#region src/PromiseManager.ts
62
93
  var PromiseManager = class {
63
- #options = {};
64
- constructor(options = {}) {
65
- this.#options = options;
66
- return this;
67
- }
68
- run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
69
- if (strategy === "seq") {
70
- return hookSeq(promises);
71
- }
72
- if (strategy === "first") {
73
- return hookFirst(promises, this.#options.nullCheck);
74
- }
75
- if (strategy === "parallel") {
76
- return hookParallel(promises, concurrency);
77
- }
78
- throw new Error(`${strategy} not implemented`);
79
- }
94
+ #options = {};
95
+ constructor(options = {}) {
96
+ this.#options = options;
97
+ return this;
98
+ }
99
+ run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
100
+ if (strategy === "seq") return hookSeq(promises);
101
+ if (strategy === "first") return hookFirst(promises, this.#options.nullCheck);
102
+ if (strategy === "parallel") return hookParallel(promises, concurrency);
103
+ throw new Error(`${strategy} not implemented`);
104
+ }
80
105
  };
81
106
  function isPromiseRejectedResult(result) {
82
- return result.status === "rejected";
107
+ return result.status === "rejected";
83
108
  }
84
109
 
85
- // src/errors.ts
86
- var ValidationPluginError = class extends Error {
87
- };
110
+ //#endregion
111
+ //#region src/errors.ts
112
+ var ValidationPluginError = class extends Error {};
113
+
114
+ //#endregion
115
+ //#region src/plugin.ts
88
116
  function createPlugin(factory) {
89
- return (options = {}) => {
90
- return factory(options);
91
- };
117
+ return (options = {}) => {
118
+ return factory(options);
119
+ };
92
120
  }
93
- var pluginCore = createPlugin((options) => {
94
- const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
95
- return {
96
- name: "core",
97
- options,
98
- key: ["core"],
99
- context() {
100
- return {
101
- get config() {
102
- return options.config;
103
- },
104
- get plugins() {
105
- return options.getPlugins();
106
- },
107
- get plugin() {
108
- return options.plugin;
109
- },
110
- logger,
111
- fileManager,
112
- pluginManager,
113
- async addFile(...files) {
114
- const resolvedFiles = await fileManager.add(...files);
115
- if (!Array.isArray(resolvedFiles)) {
116
- return [resolvedFiles];
117
- }
118
- return resolvedFiles;
119
- },
120
- resolvePath,
121
- resolveName
122
- };
123
- },
124
- resolvePath(baseName) {
125
- const root = path3__default.default.resolve(options.config.root, options.config.output.path);
126
- return path3__default.default.resolve(root, baseName);
127
- },
128
- resolveName(name) {
129
- return name;
130
- }
131
- };
121
+ const pluginCore = createPlugin((options) => {
122
+ const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
123
+ return {
124
+ name: "core",
125
+ options,
126
+ key: ["core"],
127
+ context() {
128
+ return {
129
+ get config() {
130
+ return options.config;
131
+ },
132
+ get plugins() {
133
+ return options.getPlugins();
134
+ },
135
+ get plugin() {
136
+ return options.plugin;
137
+ },
138
+ logger,
139
+ fileManager,
140
+ pluginManager,
141
+ async addFile(...files) {
142
+ const resolvedFiles = await fileManager.add(...files);
143
+ if (!Array.isArray(resolvedFiles)) return [resolvedFiles];
144
+ return resolvedFiles;
145
+ },
146
+ resolvePath,
147
+ resolveName
148
+ };
149
+ },
150
+ resolvePath(baseName) {
151
+ const root = node_path.default.resolve(options.config.root, options.config.output.path);
152
+ return node_path.default.resolve(root, baseName);
153
+ },
154
+ resolveName(name) {
155
+ return name;
156
+ }
157
+ };
132
158
  });
133
159
 
134
- // src/PluginManager.ts
160
+ //#endregion
161
+ //#region src/PluginManager.ts
135
162
  var PluginManager = class {
136
- plugins = /* @__PURE__ */ new Set();
137
- fileManager;
138
- events = new chunkMCNA6SYG_cjs.EventEmitter();
139
- config;
140
- executed = [];
141
- logger;
142
- options;
143
- #core;
144
- #usedPluginNames = {};
145
- #promiseManager;
146
- constructor(config, options) {
147
- this.config = config;
148
- this.options = options;
149
- this.logger = options.logger;
150
- this.fileManager = new chunkL3A3DTAX_cjs.FileManager();
151
- this.#promiseManager = new PromiseManager({
152
- nullCheck: (state) => !!state?.result
153
- });
154
- const core = pluginCore({
155
- config,
156
- logger: this.logger,
157
- pluginManager: this,
158
- fileManager: this.fileManager,
159
- resolvePath: this.resolvePath.bind(this),
160
- resolveName: this.resolveName.bind(this),
161
- getPlugins: this.#getSortedPlugins.bind(this)
162
- });
163
- this.#core = this.#parse(core, this, core.context.call(null));
164
- [this.#core, ...config.plugins || []].forEach((plugin) => {
165
- const parsedPlugin = this.#parse(plugin, this, this.#core.context);
166
- this.plugins.add(parsedPlugin);
167
- });
168
- return this;
169
- }
170
- getFile({ name, mode, extname, pluginKey, options }) {
171
- const baseName = `${name}${extname}`;
172
- const path4 = this.resolvePath({ baseName, mode, pluginKey, options });
173
- if (!path4) {
174
- throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
175
- }
176
- return {
177
- path: path4,
178
- baseName,
179
- meta: {
180
- pluginKey
181
- },
182
- sources: []
183
- };
184
- }
185
- resolvePath = (params) => {
186
- if (params.pluginKey) {
187
- const paths = this.hookForPluginSync({
188
- pluginKey: params.pluginKey,
189
- hookName: "resolvePath",
190
- parameters: [params.baseName, params.mode, params.options],
191
- message: `Resolving path '${params.baseName}'`
192
- });
193
- if (paths && paths?.length > 1) {
194
- this.logger.emit("debug", {
195
- date: /* @__PURE__ */ new Date(),
196
- logs: [
197
- `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
198
-
199
- Paths: ${JSON.stringify(paths, void 0, 2)}
200
-
201
- Falling back on the first item.
202
- `
203
- ]
204
- });
205
- }
206
- return paths?.at(0);
207
- }
208
- return this.hookFirstSync({
209
- hookName: "resolvePath",
210
- parameters: [params.baseName, params.mode, params.options],
211
- message: `Resolving path '${params.baseName}'`
212
- }).result;
213
- };
214
- //TODO refactor by using the order of plugins and the cache of the fileManager instead of guessing and recreating the name/path
215
- resolveName = (params) => {
216
- if (params.pluginKey) {
217
- const names = this.hookForPluginSync({
218
- pluginKey: params.pluginKey,
219
- hookName: "resolveName",
220
- parameters: [chunkBHSTNFNQ_cjs.trim(params.name), params.type],
221
- message: `Resolving name '${params.name}' and type '${params.type}'`
222
- });
223
- if (names && names?.length > 1) {
224
- this.logger.emit("debug", {
225
- date: /* @__PURE__ */ new Date(),
226
- logs: [
227
- `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
228
-
229
- Names: ${JSON.stringify(names, void 0, 2)}
230
-
231
- Falling back on the first item.
232
- `
233
- ]
234
- });
235
- }
236
- return chunkBHSTNFNQ_cjs.transformReservedWord(names?.at(0) || params.name);
237
- }
238
- const name = this.hookFirstSync({
239
- hookName: "resolveName",
240
- parameters: [chunkBHSTNFNQ_cjs.trim(params.name), params.type],
241
- message: `Resolving name '${params.name}' and type '${params.type}'`
242
- }).result;
243
- return chunkBHSTNFNQ_cjs.transformReservedWord(name);
244
- };
245
- /**
246
- * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
247
- */
248
- on(eventName, handler) {
249
- this.events.on(eventName, handler);
250
- }
251
- /**
252
- * Run a specific hookName for plugin x.
253
- */
254
- async hookForPlugin({
255
- pluginKey,
256
- hookName,
257
- parameters,
258
- message
259
- }) {
260
- const plugins = this.getPluginsByKey(hookName, pluginKey);
261
- this.logger.emit("progress_start", { id: hookName, size: plugins.length, message: "Running plugins..." });
262
- const items = [];
263
- for (const plugin of plugins) {
264
- const result = await this.#execute({
265
- strategy: "hookFirst",
266
- hookName,
267
- parameters,
268
- plugin,
269
- message
270
- });
271
- if (result !== void 0 && result !== null) {
272
- items.push(result);
273
- }
274
- }
275
- this.logger.emit("progress_stop", { id: hookName });
276
- return items;
277
- }
278
- /**
279
- * Run a specific hookName for plugin x.
280
- */
281
- hookForPluginSync({
282
- pluginKey,
283
- hookName,
284
- parameters,
285
- message
286
- }) {
287
- const plugins = this.getPluginsByKey(hookName, pluginKey);
288
- const result = plugins.map((plugin) => {
289
- return this.#executeSync({
290
- strategy: "hookFirst",
291
- hookName,
292
- parameters,
293
- plugin,
294
- message
295
- });
296
- }).filter(Boolean);
297
- return result;
298
- }
299
- /**
300
- * First non-null result stops and will return it's value.
301
- */
302
- async hookFirst({
303
- hookName,
304
- parameters,
305
- skipped,
306
- message
307
- }) {
308
- const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
309
- return skipped ? skipped.has(plugin) : true;
310
- });
311
- this.logger.emit("progress_start", { id: hookName, size: plugins.length });
312
- const promises = plugins.map((plugin) => {
313
- return async () => {
314
- const value = await this.#execute({
315
- strategy: "hookFirst",
316
- hookName,
317
- parameters,
318
- plugin,
319
- message
320
- });
321
- return Promise.resolve({
322
- plugin,
323
- result: value
324
- });
325
- };
326
- });
327
- const result = await this.#promiseManager.run("first", promises);
328
- this.logger.emit("progress_stop", { id: hookName });
329
- return result;
330
- }
331
- /**
332
- * First non-null result stops and will return it's value.
333
- */
334
- hookFirstSync({
335
- hookName,
336
- parameters,
337
- skipped,
338
- message
339
- }) {
340
- let parseResult = null;
341
- const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
342
- return skipped ? skipped.has(plugin) : true;
343
- });
344
- for (const plugin of plugins) {
345
- parseResult = {
346
- result: this.#executeSync({
347
- strategy: "hookFirst",
348
- hookName,
349
- parameters,
350
- plugin,
351
- message
352
- }),
353
- plugin
354
- };
355
- if (parseResult?.result != null) {
356
- break;
357
- }
358
- }
359
- return parseResult;
360
- }
361
- /**
362
- * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
363
- */
364
- async hookParallel({
365
- hookName,
366
- parameters,
367
- message
368
- }) {
369
- const plugins = this.#getSortedPlugins(hookName);
370
- this.logger.emit("progress_start", { id: hookName, size: plugins.length });
371
- const promises = plugins.map((plugin) => {
372
- return () => this.#execute({
373
- strategy: "hookParallel",
374
- hookName,
375
- parameters,
376
- plugin,
377
- message
378
- });
379
- });
380
- const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
381
- results.forEach((result, index) => {
382
- if (isPromiseRejectedResult(result)) {
383
- const plugin = this.#getSortedPlugins(hookName)[index];
384
- this.#catcher(result.reason, plugin, hookName);
385
- }
386
- });
387
- this.logger.emit("progress_stop", { id: hookName });
388
- return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
389
- }
390
- /**
391
- * Chains plugins
392
- */
393
- async hookSeq({
394
- hookName,
395
- parameters,
396
- message
397
- }) {
398
- const plugins = this.#getSortedPlugins(hookName);
399
- this.logger.emit("progress_start", { id: hookName, size: plugins.length });
400
- const promises = plugins.map((plugin) => {
401
- return () => this.#execute({
402
- strategy: "hookSeq",
403
- hookName,
404
- parameters,
405
- plugin,
406
- message
407
- });
408
- });
409
- await this.#promiseManager.run("seq", promises);
410
- this.logger.emit("progress_stop", { id: hookName });
411
- }
412
- #getSortedPlugins(hookName) {
413
- const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
414
- if (hookName) {
415
- return plugins.filter((plugin) => hookName in plugin);
416
- }
417
- return plugins.map((plugin) => {
418
- if (plugin.pre) {
419
- const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
420
- if (!isValid) {
421
- throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
422
- }
423
- }
424
- return plugin;
425
- }).sort((a, b) => {
426
- if (b.pre?.includes(a.name)) {
427
- return 1;
428
- }
429
- if (b.post?.includes(a.name)) {
430
- return -1;
431
- }
432
- return 0;
433
- });
434
- }
435
- getPluginByKey(pluginKey) {
436
- const plugins = [...this.plugins];
437
- const [searchPluginName] = pluginKey;
438
- return plugins.find((item) => {
439
- const [name] = item.key;
440
- return name === searchPluginName;
441
- });
442
- }
443
- getPluginsByKey(hookName, pluginKey) {
444
- const plugins = [...this.plugins];
445
- const [searchPluginName, searchIdentifier] = pluginKey;
446
- const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
447
- const [name, identifier] = item.key;
448
- const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
449
- const nameCheck = name === searchPluginName;
450
- if (searchIdentifier) {
451
- return identifierCheck && nameCheck;
452
- }
453
- return nameCheck;
454
- });
455
- if (!pluginByPluginName?.length) {
456
- const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
457
- if (corePlugin) {
458
- this.logger.emit("debug", {
459
- date: /* @__PURE__ */ new Date(),
460
- logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
461
- });
462
- } else {
463
- this.logger.emit("debug", {
464
- date: /* @__PURE__ */ new Date(),
465
- logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
466
- });
467
- }
468
- return corePlugin ? [corePlugin] : [];
469
- }
470
- return pluginByPluginName;
471
- }
472
- #addExecutedToCallStack(executer) {
473
- if (executer) {
474
- this.events.emit("executed", executer);
475
- this.executed.push(executer);
476
- this.logger.emit("progressed", { id: executer.hookName, message: `${executer.plugin.name}: ${executer.message}` });
477
- }
478
- }
479
- /**
480
- * Run an async plugin hook and return the result.
481
- * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
482
- * @param args Arguments passed to the plugin hook.
483
- * @param plugin The actual pluginObject to run.
484
- */
485
- // Implementation signature
486
- #execute({
487
- strategy,
488
- hookName,
489
- parameters,
490
- plugin,
491
- message
492
- }) {
493
- const hook = plugin[hookName];
494
- let output;
495
- if (!hook) {
496
- return null;
497
- }
498
- this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
499
- const task = (async () => {
500
- try {
501
- if (typeof hook === "function") {
502
- const result = await Promise.resolve(hook.apply({ ...this.#core.context, plugin }, parameters));
503
- output = result;
504
- this.#addExecutedToCallStack({
505
- parameters,
506
- output,
507
- strategy,
508
- hookName,
509
- plugin,
510
- message
511
- });
512
- return result;
513
- }
514
- output = hook;
515
- this.#addExecutedToCallStack({
516
- parameters,
517
- output,
518
- strategy,
519
- hookName,
520
- plugin,
521
- message
522
- });
523
- return hook;
524
- } catch (e) {
525
- this.#catcher(e, plugin, hookName);
526
- return null;
527
- }
528
- })();
529
- return task;
530
- }
531
- /**
532
- * Run a sync plugin hook and return the result.
533
- * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
534
- * @param args Arguments passed to the plugin hook.
535
- * @param plugin The acutal plugin
536
- * @param replaceContext When passed, the plugin context can be overridden.
537
- */
538
- #executeSync({
539
- strategy,
540
- hookName,
541
- parameters,
542
- plugin,
543
- message
544
- }) {
545
- const hook = plugin[hookName];
546
- let output;
547
- if (!hook) {
548
- return null;
549
- }
550
- this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
551
- try {
552
- if (typeof hook === "function") {
553
- const fn = hook.apply({ ...this.#core.context, plugin }, parameters);
554
- output = fn;
555
- this.#addExecutedToCallStack({
556
- parameters,
557
- output,
558
- strategy,
559
- hookName,
560
- plugin,
561
- message
562
- });
563
- return fn;
564
- }
565
- output = hook;
566
- this.#addExecutedToCallStack({
567
- parameters,
568
- output,
569
- strategy,
570
- hookName,
571
- plugin,
572
- message
573
- });
574
- return hook;
575
- } catch (e) {
576
- this.#catcher(e, plugin, hookName);
577
- return null;
578
- }
579
- }
580
- #catcher(cause, plugin, hookName) {
581
- const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
582
- this.logger.emit("error", text, cause);
583
- this.events.emit("error", cause);
584
- }
585
- #parse(plugin, pluginManager, context) {
586
- const usedPluginNames = pluginManager.#usedPluginNames;
587
- chunkL3A3DTAX_cjs.setUniqueName(plugin.name, usedPluginNames);
588
- const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
589
- if (plugin.context && typeof plugin.context === "function") {
590
- return {
591
- ...plugin,
592
- key,
593
- context: plugin.context.call(context)
594
- };
595
- }
596
- return {
597
- ...plugin,
598
- key
599
- };
600
- }
601
- static getDependedPlugins(plugins, dependedPluginNames) {
602
- let pluginNames = [];
603
- if (typeof dependedPluginNames === "string") {
604
- pluginNames = [dependedPluginNames];
605
- } else {
606
- pluginNames = dependedPluginNames;
607
- }
608
- return pluginNames.map((pluginName) => {
609
- const plugin = plugins.find((plugin2) => plugin2.name === pluginName);
610
- if (!plugin) {
611
- throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
612
- }
613
- return plugin;
614
- });
615
- }
616
- static get hooks() {
617
- return ["buildStart", "resolvePath", "resolveName", "buildEnd"];
618
- }
163
+ plugins = /* @__PURE__ */ new Set();
164
+ fileManager;
165
+ events = new require_logger.EventEmitter();
166
+ config;
167
+ executed = [];
168
+ logger;
169
+ options;
170
+ #core;
171
+ #usedPluginNames = {};
172
+ #promiseManager;
173
+ constructor(config, options) {
174
+ this.config = config;
175
+ this.options = options;
176
+ this.logger = options.logger;
177
+ this.fileManager = new require_FileManager.FileManager();
178
+ this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
179
+ const core = pluginCore({
180
+ config,
181
+ logger: this.logger,
182
+ pluginManager: this,
183
+ fileManager: this.fileManager,
184
+ resolvePath: this.resolvePath.bind(this),
185
+ resolveName: this.resolveName.bind(this),
186
+ getPlugins: this.#getSortedPlugins.bind(this)
187
+ });
188
+ this.#core = this.#parse(core, this, core.context.call(null));
189
+ [this.#core, ...config.plugins || []].forEach((plugin) => {
190
+ const parsedPlugin = this.#parse(plugin, this, this.#core.context);
191
+ this.plugins.add(parsedPlugin);
192
+ });
193
+ return this;
194
+ }
195
+ getFile({ name, mode, extname, pluginKey, options }) {
196
+ const baseName = `${name}${extname}`;
197
+ const path$3 = this.resolvePath({
198
+ baseName,
199
+ mode,
200
+ pluginKey,
201
+ options
202
+ });
203
+ if (!path$3) throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
204
+ return {
205
+ path: path$3,
206
+ baseName,
207
+ meta: { pluginKey },
208
+ sources: []
209
+ };
210
+ }
211
+ resolvePath = (params) => {
212
+ if (params.pluginKey) {
213
+ const paths = this.hookForPluginSync({
214
+ pluginKey: params.pluginKey,
215
+ hookName: "resolvePath",
216
+ parameters: [
217
+ params.baseName,
218
+ params.mode,
219
+ params.options
220
+ ],
221
+ message: `Resolving path '${params.baseName}'`
222
+ });
223
+ if (paths && paths?.length > 1) this.logger.emit("debug", {
224
+ date: /* @__PURE__ */ new Date(),
225
+ logs: [`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nPaths: ${JSON.stringify(paths, void 0, 2)}\n\nFalling back on the first item.\n`]
226
+ });
227
+ return paths?.at(0);
228
+ }
229
+ return this.hookFirstSync({
230
+ hookName: "resolvePath",
231
+ parameters: [
232
+ params.baseName,
233
+ params.mode,
234
+ params.options
235
+ ],
236
+ message: `Resolving path '${params.baseName}'`
237
+ }).result;
238
+ };
239
+ resolveName = (params) => {
240
+ if (params.pluginKey) {
241
+ const names = this.hookForPluginSync({
242
+ pluginKey: params.pluginKey,
243
+ hookName: "resolveName",
244
+ parameters: [require_transformers.trim(params.name), params.type],
245
+ message: `Resolving name '${params.name}' and type '${params.type}'`
246
+ });
247
+ if (names && names?.length > 1) this.logger.emit("debug", {
248
+ date: /* @__PURE__ */ new Date(),
249
+ logs: [`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nNames: ${JSON.stringify(names, void 0, 2)}\n\nFalling back on the first item.\n`]
250
+ });
251
+ return require_transformers.transformReservedWord(names?.at(0) || params.name);
252
+ }
253
+ const name = this.hookFirstSync({
254
+ hookName: "resolveName",
255
+ parameters: [require_transformers.trim(params.name), params.type],
256
+ message: `Resolving name '${params.name}' and type '${params.type}'`
257
+ }).result;
258
+ return require_transformers.transformReservedWord(name);
259
+ };
260
+ /**
261
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
262
+ */
263
+ on(eventName, handler) {
264
+ this.events.on(eventName, handler);
265
+ }
266
+ /**
267
+ * Run a specific hookName for plugin x.
268
+ */
269
+ async hookForPlugin({ pluginKey, hookName, parameters, message }) {
270
+ const plugins = this.getPluginsByKey(hookName, pluginKey);
271
+ this.logger.emit("progress_start", {
272
+ id: hookName,
273
+ size: plugins.length,
274
+ message: "Running plugins..."
275
+ });
276
+ const items = [];
277
+ for (const plugin of plugins) {
278
+ const result = await this.#execute({
279
+ strategy: "hookFirst",
280
+ hookName,
281
+ parameters,
282
+ plugin,
283
+ message
284
+ });
285
+ if (result !== void 0 && result !== null) items.push(result);
286
+ }
287
+ this.logger.emit("progress_stop", { id: hookName });
288
+ return items;
289
+ }
290
+ /**
291
+ * Run a specific hookName for plugin x.
292
+ */
293
+ hookForPluginSync({ pluginKey, hookName, parameters, message }) {
294
+ const plugins = this.getPluginsByKey(hookName, pluginKey);
295
+ const result = plugins.map((plugin) => {
296
+ return this.#executeSync({
297
+ strategy: "hookFirst",
298
+ hookName,
299
+ parameters,
300
+ plugin,
301
+ message
302
+ });
303
+ }).filter(Boolean);
304
+ return result;
305
+ }
306
+ /**
307
+ * First non-null result stops and will return it's value.
308
+ */
309
+ async hookFirst({ hookName, parameters, skipped, message }) {
310
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
311
+ return skipped ? skipped.has(plugin) : true;
312
+ });
313
+ this.logger.emit("progress_start", {
314
+ id: hookName,
315
+ size: plugins.length
316
+ });
317
+ const promises = plugins.map((plugin) => {
318
+ return async () => {
319
+ const value = await this.#execute({
320
+ strategy: "hookFirst",
321
+ hookName,
322
+ parameters,
323
+ plugin,
324
+ message
325
+ });
326
+ return Promise.resolve({
327
+ plugin,
328
+ result: value
329
+ });
330
+ };
331
+ });
332
+ const result = await this.#promiseManager.run("first", promises);
333
+ this.logger.emit("progress_stop", { id: hookName });
334
+ return result;
335
+ }
336
+ /**
337
+ * First non-null result stops and will return it's value.
338
+ */
339
+ hookFirstSync({ hookName, parameters, skipped, message }) {
340
+ let parseResult = null;
341
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
342
+ return skipped ? skipped.has(plugin) : true;
343
+ });
344
+ for (const plugin of plugins) {
345
+ parseResult = {
346
+ result: this.#executeSync({
347
+ strategy: "hookFirst",
348
+ hookName,
349
+ parameters,
350
+ plugin,
351
+ message
352
+ }),
353
+ plugin
354
+ };
355
+ if (parseResult?.result != null) break;
356
+ }
357
+ return parseResult;
358
+ }
359
+ /**
360
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
361
+ */
362
+ async hookParallel({ hookName, parameters, message }) {
363
+ const plugins = this.#getSortedPlugins(hookName);
364
+ this.logger.emit("progress_start", {
365
+ id: hookName,
366
+ size: plugins.length
367
+ });
368
+ const promises = plugins.map((plugin) => {
369
+ return () => this.#execute({
370
+ strategy: "hookParallel",
371
+ hookName,
372
+ parameters,
373
+ plugin,
374
+ message
375
+ });
376
+ });
377
+ const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
378
+ results.forEach((result, index) => {
379
+ if (isPromiseRejectedResult(result)) {
380
+ const plugin = this.#getSortedPlugins(hookName)[index];
381
+ this.#catcher(result.reason, plugin, hookName);
382
+ }
383
+ });
384
+ this.logger.emit("progress_stop", { id: hookName });
385
+ return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
386
+ }
387
+ /**
388
+ * Chains plugins
389
+ */
390
+ async hookSeq({ hookName, parameters, message }) {
391
+ const plugins = this.#getSortedPlugins(hookName);
392
+ this.logger.emit("progress_start", {
393
+ id: hookName,
394
+ size: plugins.length
395
+ });
396
+ const promises = plugins.map((plugin) => {
397
+ return () => this.#execute({
398
+ strategy: "hookSeq",
399
+ hookName,
400
+ parameters,
401
+ plugin,
402
+ message
403
+ });
404
+ });
405
+ await this.#promiseManager.run("seq", promises);
406
+ this.logger.emit("progress_stop", { id: hookName });
407
+ }
408
+ #getSortedPlugins(hookName) {
409
+ const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
410
+ if (hookName) return plugins.filter((plugin) => hookName in plugin);
411
+ return plugins.map((plugin) => {
412
+ if (plugin.pre) {
413
+ const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
414
+ if (!isValid) throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
415
+ }
416
+ return plugin;
417
+ }).sort((a, b) => {
418
+ if (b.pre?.includes(a.name)) return 1;
419
+ if (b.post?.includes(a.name)) return -1;
420
+ return 0;
421
+ });
422
+ }
423
+ getPluginByKey(pluginKey) {
424
+ const plugins = [...this.plugins];
425
+ const [searchPluginName] = pluginKey;
426
+ return plugins.find((item) => {
427
+ const [name] = item.key;
428
+ return name === searchPluginName;
429
+ });
430
+ }
431
+ getPluginsByKey(hookName, pluginKey) {
432
+ const plugins = [...this.plugins];
433
+ const [searchPluginName, searchIdentifier] = pluginKey;
434
+ const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
435
+ const [name, identifier] = item.key;
436
+ const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
437
+ const nameCheck = name === searchPluginName;
438
+ if (searchIdentifier) return identifierCheck && nameCheck;
439
+ return nameCheck;
440
+ });
441
+ if (!pluginByPluginName?.length) {
442
+ const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
443
+ if (corePlugin) this.logger.emit("debug", {
444
+ date: /* @__PURE__ */ new Date(),
445
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
446
+ });
447
+ else this.logger.emit("debug", {
448
+ date: /* @__PURE__ */ new Date(),
449
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
450
+ });
451
+ return corePlugin ? [corePlugin] : [];
452
+ }
453
+ return pluginByPluginName;
454
+ }
455
+ #addExecutedToCallStack(executer) {
456
+ if (executer) {
457
+ this.events.emit("executed", executer);
458
+ this.executed.push(executer);
459
+ this.logger.emit("progressed", {
460
+ id: executer.hookName,
461
+ message: `${executer.plugin.name}: ${executer.message}`
462
+ });
463
+ }
464
+ }
465
+ /**
466
+ * Run an async plugin hook and return the result.
467
+ * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
468
+ * @param args Arguments passed to the plugin hook.
469
+ * @param plugin The actual pluginObject to run.
470
+ */
471
+ #execute({ strategy, hookName, parameters, plugin, message }) {
472
+ const hook = plugin[hookName];
473
+ let output;
474
+ if (!hook) return null;
475
+ this.events.emit("executing", {
476
+ strategy,
477
+ hookName,
478
+ parameters,
479
+ plugin,
480
+ message
481
+ });
482
+ const task = (async () => {
483
+ try {
484
+ if (typeof hook === "function") {
485
+ const result = await Promise.resolve(hook.apply({
486
+ ...this.#core.context,
487
+ plugin
488
+ }, parameters));
489
+ output = result;
490
+ this.#addExecutedToCallStack({
491
+ parameters,
492
+ output,
493
+ strategy,
494
+ hookName,
495
+ plugin,
496
+ message
497
+ });
498
+ return result;
499
+ }
500
+ output = hook;
501
+ this.#addExecutedToCallStack({
502
+ parameters,
503
+ output,
504
+ strategy,
505
+ hookName,
506
+ plugin,
507
+ message
508
+ });
509
+ return hook;
510
+ } catch (e) {
511
+ this.#catcher(e, plugin, hookName);
512
+ return null;
513
+ }
514
+ })();
515
+ return task;
516
+ }
517
+ /**
518
+ * Run a sync plugin hook and return the result.
519
+ * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
520
+ * @param args Arguments passed to the plugin hook.
521
+ * @param plugin The acutal plugin
522
+ * @param replaceContext When passed, the plugin context can be overridden.
523
+ */
524
+ #executeSync({ strategy, hookName, parameters, plugin, message }) {
525
+ const hook = plugin[hookName];
526
+ let output;
527
+ if (!hook) return null;
528
+ this.events.emit("executing", {
529
+ strategy,
530
+ hookName,
531
+ parameters,
532
+ plugin,
533
+ message
534
+ });
535
+ try {
536
+ if (typeof hook === "function") {
537
+ const fn = hook.apply({
538
+ ...this.#core.context,
539
+ plugin
540
+ }, parameters);
541
+ output = fn;
542
+ this.#addExecutedToCallStack({
543
+ parameters,
544
+ output,
545
+ strategy,
546
+ hookName,
547
+ plugin,
548
+ message
549
+ });
550
+ return fn;
551
+ }
552
+ output = hook;
553
+ this.#addExecutedToCallStack({
554
+ parameters,
555
+ output,
556
+ strategy,
557
+ hookName,
558
+ plugin,
559
+ message
560
+ });
561
+ return hook;
562
+ } catch (e) {
563
+ this.#catcher(e, plugin, hookName);
564
+ return null;
565
+ }
566
+ }
567
+ #catcher(cause, plugin, hookName) {
568
+ const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
569
+ this.logger.emit("error", text, cause);
570
+ this.events.emit("error", cause);
571
+ }
572
+ #parse(plugin, pluginManager, context) {
573
+ const usedPluginNames = pluginManager.#usedPluginNames;
574
+ require_FileManager.setUniqueName(plugin.name, usedPluginNames);
575
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
576
+ if (plugin.context && typeof plugin.context === "function") return {
577
+ ...plugin,
578
+ key,
579
+ context: plugin.context.call(context)
580
+ };
581
+ return {
582
+ ...plugin,
583
+ key
584
+ };
585
+ }
586
+ static getDependedPlugins(plugins, dependedPluginNames) {
587
+ let pluginNames = [];
588
+ if (typeof dependedPluginNames === "string") pluginNames = [dependedPluginNames];
589
+ else pluginNames = dependedPluginNames;
590
+ return pluginNames.map((pluginName) => {
591
+ const plugin = plugins.find((plugin$1) => plugin$1.name === pluginName);
592
+ if (!plugin) throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
593
+ return plugin;
594
+ });
595
+ }
596
+ static get hooks() {
597
+ return [
598
+ "buildStart",
599
+ "resolvePath",
600
+ "resolveName",
601
+ "buildEnd"
602
+ ];
603
+ }
619
604
  };
620
605
 
621
- // src/config.ts
622
- function defineConfig(options) {
623
- return options;
624
- }
625
- function isInputPath(result) {
626
- return !!result && "path" in result?.input;
627
- }
606
+ //#endregion
607
+ //#region src/build.ts
628
608
  async function setup(options) {
629
- if (options.pluginManager) {
630
- return options.pluginManager;
631
- }
632
- const { config: userConfig, logger = chunkMCNA6SYG_cjs.createLogger() } = options;
633
- if (Array.isArray(userConfig.input)) {
634
- chunkMCNA6SYG_cjs.consola.warn(chunkMCNA6SYG_cjs.colors.yellow("This feature is still under development \u2014 use with caution"));
635
- }
636
- try {
637
- if (isInputPath(userConfig) && !new chunkL3A3DTAX_cjs.URLPath(userConfig.input.path).isURL) {
638
- await chunkE4XLCCPK_cjs.exists(userConfig.input.path);
639
- }
640
- } catch (e) {
641
- if (isInputPath(userConfig)) {
642
- throw new Error(
643
- `Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`,
644
- {
645
- cause: e
646
- }
647
- );
648
- }
649
- }
650
- const definedConfig = {
651
- root: userConfig.root || process.cwd(),
652
- ...userConfig,
653
- output: {
654
- write: true,
655
- barrelType: "named",
656
- extension: {
657
- ".ts": ".ts"
658
- },
659
- defaultBanner: "simple",
660
- ...userConfig.output
661
- },
662
- plugins: userConfig.plugins
663
- };
664
- if (definedConfig.output.clean) {
665
- await chunkE4XLCCPK_cjs.clean(definedConfig.output.path);
666
- await chunkE4XLCCPK_cjs.clean(path3.join(definedConfig.root, ".kubb"));
667
- }
668
- return new PluginManager(definedConfig, { logger, concurrency: 5 });
609
+ if (options.pluginManager) return options.pluginManager;
610
+ const { config: userConfig, logger = require_logger.createLogger() } = options;
611
+ if (Array.isArray(userConfig.input)) console.warn(picocolors.default.yellow("This feature is still under development — use with caution"));
612
+ try {
613
+ if (isInputPath(userConfig) && !new require_FileManager.URLPath(userConfig.input.path).isURL) await require_fs.exists(userConfig.input.path);
614
+ } catch (e) {
615
+ if (isInputPath(userConfig)) throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: e });
616
+ }
617
+ const definedConfig = {
618
+ root: userConfig.root || process.cwd(),
619
+ ...userConfig,
620
+ output: {
621
+ write: true,
622
+ barrelType: "named",
623
+ extension: { ".ts": ".ts" },
624
+ defaultBanner: "simple",
625
+ ...userConfig.output
626
+ },
627
+ plugins: userConfig.plugins
628
+ };
629
+ if (definedConfig.output.clean) {
630
+ await require_fs.clean(definedConfig.output.path);
631
+ await require_fs.clean((0, node_path.join)(definedConfig.root, ".kubb"));
632
+ }
633
+ return new PluginManager(definedConfig, {
634
+ logger,
635
+ concurrency: 5
636
+ });
669
637
  }
670
638
  async function build(options) {
671
- const { files, pluginManager, error } = await safeBuild(options);
672
- if (error) throw error;
673
- return {
674
- files,
675
- pluginManager,
676
- error
677
- };
639
+ const { files, pluginManager, error } = await safeBuild(options);
640
+ if (error) throw error;
641
+ return {
642
+ files,
643
+ pluginManager,
644
+ error
645
+ };
678
646
  }
679
647
  async function safeBuild(options) {
680
- const pluginManager = await setup(options);
681
- const config = pluginManager.config;
682
- try {
683
- pluginManager.events.on("executing", ({ plugin, message }) => {
684
- pluginManager.logger.emit("debug", { date: /* @__PURE__ */ new Date(), logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`] });
685
- });
686
- pluginManager.events.on("executed", ({ plugin, message, output }) => {
687
- pluginManager.logger.emit("debug", {
688
- date: /* @__PURE__ */ new Date(),
689
- logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
690
- });
691
- });
692
- await pluginManager.hookParallel({
693
- hookName: "buildStart",
694
- parameters: [config],
695
- message: "buildStart"
696
- });
697
- if (config.output.barrelType) {
698
- const root = path3.resolve(config.root);
699
- const rootPath = path3.resolve(root, config.output.path, "index.ts");
700
- const files2 = await pluginManager.fileManager.getFiles();
701
- const barrelFiles = files2.filter((file) => {
702
- return file.sources.some((source) => source.isIndexable);
703
- });
704
- const rootFile = {
705
- path: rootPath,
706
- baseName: "index.ts",
707
- exports: barrelFiles.flatMap((file) => {
708
- const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
709
- return file.sources?.map((source) => {
710
- if (!file.path || !source.isIndexable) {
711
- return void 0;
712
- }
713
- const plugin = [...pluginManager.plugins].find((item) => {
714
- const meta = file.meta;
715
- return remeda.isDeepEqual(item.key, meta?.pluginKey);
716
- });
717
- const pluginOptions = plugin?.options;
718
- if (!pluginOptions || pluginOptions?.output?.barrelType === false) {
719
- return void 0;
720
- }
721
- return {
722
- name: config.output.barrelType === "all" ? void 0 : [source.name],
723
- path: chunkE4XLCCPK_cjs.getRelativePath(rootPath, file.path),
724
- isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
725
- };
726
- }).filter(Boolean);
727
- }).filter(Boolean),
728
- sources: [],
729
- meta: {}
730
- };
731
- await pluginManager.fileManager.add(rootFile);
732
- }
733
- const files = await pluginManager.fileManager.processFiles({
734
- root: config.root,
735
- extension: config.output.extension,
736
- dryRun: !config.output.write,
737
- logger: pluginManager.logger
738
- });
739
- await pluginManager.hookParallel({ hookName: "buildEnd", message: `Build stopped for ${config.name}` });
740
- await pluginManager.fileManager.clear();
741
- return {
742
- files,
743
- pluginManager
744
- };
745
- } catch (e) {
746
- return {
747
- files: [],
748
- pluginManager,
749
- error: e
750
- };
751
- }
648
+ const pluginManager = await setup(options);
649
+ const config = pluginManager.config;
650
+ try {
651
+ pluginManager.events.on("executing", ({ plugin, message }) => {
652
+ pluginManager.logger.emit("debug", {
653
+ date: /* @__PURE__ */ new Date(),
654
+ logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`]
655
+ });
656
+ });
657
+ pluginManager.events.on("executed", ({ plugin, message, output }) => {
658
+ pluginManager.logger.emit("debug", {
659
+ date: /* @__PURE__ */ new Date(),
660
+ logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
661
+ });
662
+ });
663
+ await pluginManager.hookParallel({
664
+ hookName: "buildStart",
665
+ parameters: [config],
666
+ message: "buildStart"
667
+ });
668
+ if (config.output.barrelType) {
669
+ const root = (0, node_path.resolve)(config.root);
670
+ const rootPath = (0, node_path.resolve)(root, config.output.path, "index.ts");
671
+ const files$1 = await pluginManager.fileManager.getFiles();
672
+ const barrelFiles = files$1.filter((file) => {
673
+ return file.sources.some((source) => source.isIndexable);
674
+ });
675
+ const rootFile = {
676
+ path: rootPath,
677
+ baseName: "index.ts",
678
+ exports: barrelFiles.flatMap((file) => {
679
+ const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
680
+ return file.sources?.map((source) => {
681
+ if (!file.path || !source.isIndexable) return void 0;
682
+ const plugin = [...pluginManager.plugins].find((item) => {
683
+ const meta = file.meta;
684
+ return (0, remeda.isDeepEqual)(item.key, meta?.pluginKey);
685
+ });
686
+ const pluginOptions = plugin?.options;
687
+ if (!pluginOptions || pluginOptions?.output?.barrelType === false) return void 0;
688
+ return {
689
+ name: config.output.barrelType === "all" ? void 0 : [source.name],
690
+ path: require_fs.getRelativePath(rootPath, file.path),
691
+ isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
692
+ };
693
+ }).filter(Boolean);
694
+ }).filter(Boolean),
695
+ sources: [],
696
+ meta: {}
697
+ };
698
+ await pluginManager.fileManager.add(rootFile);
699
+ }
700
+ const files = await pluginManager.fileManager.processFiles({
701
+ root: config.root,
702
+ extension: config.output.extension,
703
+ dryRun: !config.output.write,
704
+ logger: pluginManager.logger
705
+ });
706
+ await pluginManager.hookParallel({
707
+ hookName: "buildEnd",
708
+ message: `Build stopped for ${config.name}`
709
+ });
710
+ await pluginManager.fileManager.clear();
711
+ return {
712
+ files,
713
+ pluginManager
714
+ };
715
+ } catch (e) {
716
+ return {
717
+ files: [],
718
+ pluginManager,
719
+ error: e
720
+ };
721
+ }
752
722
  }
753
723
 
754
- // src/BaseGenerator.ts
755
- var BaseGenerator = class {
756
- #options = {};
757
- #context = {};
758
- constructor(options, context) {
759
- if (context) {
760
- this.#context = context;
761
- }
762
- if (options) {
763
- this.#options = options;
764
- }
765
- return this;
766
- }
767
- get options() {
768
- return this.#options;
769
- }
770
- get context() {
771
- return this.#context;
772
- }
773
- set options(options) {
774
- this.#options = { ...this.#options, ...options };
775
- }
724
+ //#endregion
725
+ //#region ../../node_modules/.pnpm/yocto-queue@1.1.1/node_modules/yocto-queue/index.js
726
+ var Node = class {
727
+ value;
728
+ next;
729
+ constructor(value) {
730
+ this.value = value;
731
+ }
732
+ };
733
+ var Queue = class {
734
+ #head;
735
+ #tail;
736
+ #size;
737
+ constructor() {
738
+ this.clear();
739
+ }
740
+ enqueue(value) {
741
+ const node = new Node(value);
742
+ if (this.#head) {
743
+ this.#tail.next = node;
744
+ this.#tail = node;
745
+ } else {
746
+ this.#head = node;
747
+ this.#tail = node;
748
+ }
749
+ this.#size++;
750
+ }
751
+ dequeue() {
752
+ const current = this.#head;
753
+ if (!current) return;
754
+ this.#head = this.#head.next;
755
+ this.#size--;
756
+ return current.value;
757
+ }
758
+ peek() {
759
+ if (!this.#head) return;
760
+ return this.#head.value;
761
+ }
762
+ clear() {
763
+ this.#head = void 0;
764
+ this.#tail = void 0;
765
+ this.#size = 0;
766
+ }
767
+ get size() {
768
+ return this.#size;
769
+ }
770
+ *[Symbol.iterator]() {
771
+ let current = this.#head;
772
+ while (current) {
773
+ yield current.value;
774
+ current = current.next;
775
+ }
776
+ }
776
777
  };
777
778
 
778
- // ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
779
- function pLimit2(concurrency) {
780
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
781
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
782
- }
783
- const queue = new chunkL3A3DTAX_cjs.Queue();
784
- let activeCount = 0;
785
- const next = () => {
786
- activeCount--;
787
- if (queue.size > 0) {
788
- queue.dequeue()();
789
- }
790
- };
791
- const run = async (fn, resolve2, args) => {
792
- activeCount++;
793
- const result = (async () => fn(...args))();
794
- resolve2(result);
795
- try {
796
- await result;
797
- } catch {
798
- }
799
- next();
800
- };
801
- const enqueue = (fn, resolve2, args) => {
802
- queue.enqueue(run.bind(void 0, fn, resolve2, args));
803
- (async () => {
804
- await Promise.resolve();
805
- if (activeCount < concurrency && queue.size > 0) {
806
- queue.dequeue()();
807
- }
808
- })();
809
- };
810
- const generator = (fn, ...args) => new Promise((resolve2) => {
811
- enqueue(fn, resolve2, args);
812
- });
813
- Object.defineProperties(generator, {
814
- activeCount: {
815
- get: () => activeCount
816
- },
817
- pendingCount: {
818
- get: () => queue.size
819
- },
820
- clearQueue: {
821
- value: () => {
822
- queue.clear();
823
- }
824
- }
825
- });
826
- return generator;
779
+ //#endregion
780
+ //#region ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
781
+ function pLimit$1(concurrency) {
782
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
783
+ const queue = new Queue();
784
+ let activeCount = 0;
785
+ const next = () => {
786
+ activeCount--;
787
+ if (queue.size > 0) queue.dequeue()();
788
+ };
789
+ const run = async (fn, resolve$1, args) => {
790
+ activeCount++;
791
+ const result = (async () => fn(...args))();
792
+ resolve$1(result);
793
+ try {
794
+ await result;
795
+ } catch {}
796
+ next();
797
+ };
798
+ const enqueue = (fn, resolve$1, args) => {
799
+ queue.enqueue(run.bind(void 0, fn, resolve$1, args));
800
+ (async () => {
801
+ await Promise.resolve();
802
+ if (activeCount < concurrency && queue.size > 0) queue.dequeue()();
803
+ })();
804
+ };
805
+ const generator = (fn, ...args) => new Promise((resolve$1) => {
806
+ enqueue(fn, resolve$1, args);
807
+ });
808
+ Object.defineProperties(generator, {
809
+ activeCount: { get: () => activeCount },
810
+ pendingCount: { get: () => queue.size },
811
+ clearQueue: { value: () => {
812
+ queue.clear();
813
+ } }
814
+ });
815
+ return generator;
827
816
  }
828
817
 
829
- // ../../node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
818
+ //#endregion
819
+ //#region ../../node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
830
820
  var EndError = class extends Error {
831
- constructor(value) {
832
- super();
833
- this.value = value;
834
- }
821
+ constructor(value) {
822
+ super();
823
+ this.value = value;
824
+ }
835
825
  };
836
- var testElement = async (element, tester) => tester(await element);
837
- var finder = async (element) => {
838
- const values = await Promise.all(element);
839
- if (values[1] === true) {
840
- throw new EndError(values[0]);
841
- }
842
- return false;
826
+ const testElement = async (element, tester) => tester(await element);
827
+ const finder = async (element) => {
828
+ const values = await Promise.all(element);
829
+ if (values[1] === true) throw new EndError(values[0]);
830
+ return false;
843
831
  };
844
- async function pLocate(iterable, tester, {
845
- concurrency = Number.POSITIVE_INFINITY,
846
- preserveOrder = true
847
- } = {}) {
848
- const limit = pLimit2(concurrency);
849
- const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
850
- const checkLimit = pLimit2(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
851
- try {
852
- await Promise.all(items.map((element) => checkLimit(finder, element)));
853
- } catch (error) {
854
- if (error instanceof EndError) {
855
- return error.value;
856
- }
857
- throw error;
858
- }
832
+ async function pLocate(iterable, tester, { concurrency = Number.POSITIVE_INFINITY, preserveOrder = true } = {}) {
833
+ const limit = pLimit$1(concurrency);
834
+ const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
835
+ const checkLimit = pLimit$1(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
836
+ try {
837
+ await Promise.all(items.map((element) => checkLimit(finder, element)));
838
+ } catch (error) {
839
+ if (error instanceof EndError) return error.value;
840
+ throw error;
841
+ }
859
842
  }
860
843
 
861
- // ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
862
- var typeMappings = {
863
- directory: "isDirectory",
864
- file: "isFile"
844
+ //#endregion
845
+ //#region ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
846
+ const typeMappings = {
847
+ directory: "isDirectory",
848
+ file: "isFile"
865
849
  };
866
850
  function checkType(type) {
867
- if (Object.hasOwnProperty.call(typeMappings, type)) {
868
- return;
869
- }
870
- throw new Error(`Invalid type specified: ${type}`);
851
+ if (Object.hasOwnProperty.call(typeMappings, type)) return;
852
+ throw new Error(`Invalid type specified: ${type}`);
871
853
  }
872
- var matchType = (type, stat) => stat[typeMappings[type]]();
873
- var toPath = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
874
- async function locatePath(paths, {
875
- cwd = process2__default.default.cwd(),
876
- type = "file",
877
- allowSymlinks = true,
878
- concurrency,
879
- preserveOrder
880
- } = {}) {
881
- checkType(type);
882
- cwd = toPath(cwd);
883
- const statFunction = allowSymlinks ? fs.promises.stat : fs.promises.lstat;
884
- return pLocate(paths, async (path_) => {
885
- try {
886
- const stat = await statFunction(path3__default.default.resolve(cwd, path_));
887
- return matchType(type, stat);
888
- } catch {
889
- return false;
890
- }
891
- }, { concurrency, preserveOrder });
854
+ const matchType = (type, stat) => stat[typeMappings[type]]();
855
+ const toPath$1 = (urlOrPath) => urlOrPath instanceof URL ? (0, node_url.fileURLToPath)(urlOrPath) : urlOrPath;
856
+ async function locatePath(paths, { cwd = node_process.default.cwd(), type = "file", allowSymlinks = true, concurrency, preserveOrder } = {}) {
857
+ checkType(type);
858
+ cwd = toPath$1(cwd);
859
+ const statFunction = allowSymlinks ? node_fs.promises.stat : node_fs.promises.lstat;
860
+ return pLocate(paths, async (path_) => {
861
+ try {
862
+ const stat = await statFunction(node_path.default.resolve(cwd, path_));
863
+ return matchType(type, stat);
864
+ } catch {
865
+ return false;
866
+ }
867
+ }, {
868
+ concurrency,
869
+ preserveOrder
870
+ });
892
871
  }
893
- function locatePathSync(paths, {
894
- cwd = process2__default.default.cwd(),
895
- type = "file",
896
- allowSymlinks = true
897
- } = {}) {
898
- checkType(type);
899
- cwd = toPath(cwd);
900
- const statFunction = allowSymlinks ? fs__default.default.statSync : fs__default.default.lstatSync;
901
- for (const path_ of paths) {
902
- try {
903
- const stat = statFunction(path3__default.default.resolve(cwd, path_), {
904
- throwIfNoEntry: false
905
- });
906
- if (!stat) {
907
- continue;
908
- }
909
- if (matchType(type, stat)) {
910
- return path_;
911
- }
912
- } catch {
913
- }
914
- }
872
+ function locatePathSync(paths, { cwd = node_process.default.cwd(), type = "file", allowSymlinks = true } = {}) {
873
+ checkType(type);
874
+ cwd = toPath$1(cwd);
875
+ const statFunction = allowSymlinks ? node_fs.default.statSync : node_fs.default.lstatSync;
876
+ for (const path_ of paths) try {
877
+ const stat = statFunction(node_path.default.resolve(cwd, path_), { throwIfNoEntry: false });
878
+ if (!stat) continue;
879
+ if (matchType(type, stat)) return path_;
880
+ } catch {}
915
881
  }
916
- function toPath2(urlOrPath) {
917
- return urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
882
+
883
+ //#endregion
884
+ //#region ../../node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/node.js
885
+ function toPath(urlOrPath) {
886
+ return urlOrPath instanceof URL ? (0, node_url.fileURLToPath)(urlOrPath) : urlOrPath;
918
887
  }
919
888
 
920
- // ../../node_modules/.pnpm/find-up@7.0.0/node_modules/find-up/index.js
921
- var findUpStop = Symbol("findUpStop");
889
+ //#endregion
890
+ //#region ../../node_modules/.pnpm/find-up@7.0.0/node_modules/find-up/index.js
891
+ const findUpStop = Symbol("findUpStop");
922
892
  async function findUpMultiple(name, options = {}) {
923
- let directory = path3__default.default.resolve(toPath2(options.cwd) ?? "");
924
- const { root } = path3__default.default.parse(directory);
925
- const stopAt = path3__default.default.resolve(directory, toPath2(options.stopAt ?? root));
926
- const limit = options.limit ?? Number.POSITIVE_INFINITY;
927
- const paths = [name].flat();
928
- const runMatcher = async (locateOptions) => {
929
- if (typeof name !== "function") {
930
- return locatePath(paths, locateOptions);
931
- }
932
- const foundPath = await name(locateOptions.cwd);
933
- if (typeof foundPath === "string") {
934
- return locatePath([foundPath], locateOptions);
935
- }
936
- return foundPath;
937
- };
938
- const matches = [];
939
- while (true) {
940
- const foundPath = await runMatcher({ ...options, cwd: directory });
941
- if (foundPath === findUpStop) {
942
- break;
943
- }
944
- if (foundPath) {
945
- matches.push(path3__default.default.resolve(directory, foundPath));
946
- }
947
- if (directory === stopAt || matches.length >= limit) {
948
- break;
949
- }
950
- directory = path3__default.default.dirname(directory);
951
- }
952
- return matches;
893
+ let directory = node_path.default.resolve(toPath(options.cwd) ?? "");
894
+ const { root } = node_path.default.parse(directory);
895
+ const stopAt = node_path.default.resolve(directory, toPath(options.stopAt ?? root));
896
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
897
+ const paths = [name].flat();
898
+ const runMatcher = async (locateOptions) => {
899
+ if (typeof name !== "function") return locatePath(paths, locateOptions);
900
+ const foundPath = await name(locateOptions.cwd);
901
+ if (typeof foundPath === "string") return locatePath([foundPath], locateOptions);
902
+ return foundPath;
903
+ };
904
+ const matches = [];
905
+ while (true) {
906
+ const foundPath = await runMatcher({
907
+ ...options,
908
+ cwd: directory
909
+ });
910
+ if (foundPath === findUpStop) break;
911
+ if (foundPath) matches.push(node_path.default.resolve(directory, foundPath));
912
+ if (directory === stopAt || matches.length >= limit) break;
913
+ directory = node_path.default.dirname(directory);
914
+ }
915
+ return matches;
953
916
  }
954
917
  function findUpMultipleSync(name, options = {}) {
955
- let directory = path3__default.default.resolve(toPath2(options.cwd) ?? "");
956
- const { root } = path3__default.default.parse(directory);
957
- const stopAt = path3__default.default.resolve(directory, toPath2(options.stopAt) ?? root);
958
- const limit = options.limit ?? Number.POSITIVE_INFINITY;
959
- const paths = [name].flat();
960
- const runMatcher = (locateOptions) => {
961
- if (typeof name !== "function") {
962
- return locatePathSync(paths, locateOptions);
963
- }
964
- const foundPath = name(locateOptions.cwd);
965
- if (typeof foundPath === "string") {
966
- return locatePathSync([foundPath], locateOptions);
967
- }
968
- return foundPath;
969
- };
970
- const matches = [];
971
- while (true) {
972
- const foundPath = runMatcher({ ...options, cwd: directory });
973
- if (foundPath === findUpStop) {
974
- break;
975
- }
976
- if (foundPath) {
977
- matches.push(path3__default.default.resolve(directory, foundPath));
978
- }
979
- if (directory === stopAt || matches.length >= limit) {
980
- break;
981
- }
982
- directory = path3__default.default.dirname(directory);
983
- }
984
- return matches;
918
+ let directory = node_path.default.resolve(toPath(options.cwd) ?? "");
919
+ const { root } = node_path.default.parse(directory);
920
+ const stopAt = node_path.default.resolve(directory, toPath(options.stopAt) ?? root);
921
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
922
+ const paths = [name].flat();
923
+ const runMatcher = (locateOptions) => {
924
+ if (typeof name !== "function") return locatePathSync(paths, locateOptions);
925
+ const foundPath = name(locateOptions.cwd);
926
+ if (typeof foundPath === "string") return locatePathSync([foundPath], locateOptions);
927
+ return foundPath;
928
+ };
929
+ const matches = [];
930
+ while (true) {
931
+ const foundPath = runMatcher({
932
+ ...options,
933
+ cwd: directory
934
+ });
935
+ if (foundPath === findUpStop) break;
936
+ if (foundPath) matches.push(node_path.default.resolve(directory, foundPath));
937
+ if (directory === stopAt || matches.length >= limit) break;
938
+ directory = node_path.default.dirname(directory);
939
+ }
940
+ return matches;
985
941
  }
986
942
  async function findUp(name, options = {}) {
987
- const matches = await findUpMultiple(name, { ...options, limit: 1 });
988
- return matches[0];
943
+ const matches = await findUpMultiple(name, {
944
+ ...options,
945
+ limit: 1
946
+ });
947
+ return matches[0];
989
948
  }
990
949
  function findUpSync(name, options = {}) {
991
- const matches = findUpMultipleSync(name, { ...options, limit: 1 });
992
- return matches[0];
950
+ const matches = findUpMultipleSync(name, {
951
+ ...options,
952
+ limit: 1
953
+ });
954
+ return matches[0];
993
955
  }
994
- var PackageManager = class _PackageManager {
995
- static #cache = {};
996
- #cwd;
997
- #SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
998
- constructor(workspace) {
999
- if (workspace) {
1000
- this.#cwd = workspace;
1001
- }
1002
- return this;
1003
- }
1004
- set workspace(workspace) {
1005
- this.#cwd = workspace;
1006
- }
1007
- get workspace() {
1008
- return this.#cwd;
1009
- }
1010
- normalizeDirectory(directory) {
1011
- if (!this.#SLASHES.has(directory[directory.length - 1])) {
1012
- return `${directory}/`;
1013
- }
1014
- return directory;
1015
- }
1016
- getLocation(path4) {
1017
- let location = path4;
1018
- if (this.#cwd) {
1019
- const require2 = mod__default.default.createRequire(this.normalizeDirectory(this.#cwd));
1020
- location = require2.resolve(path4);
1021
- }
1022
- return location;
1023
- }
1024
- async import(path4) {
1025
- try {
1026
- let location = this.getLocation(path4);
1027
- if (os__default.default.platform() === "win32") {
1028
- location = url.pathToFileURL(location).href;
1029
- }
1030
- const module = await import(location);
1031
- return module?.default ?? module;
1032
- } catch (e) {
1033
- console.error(e);
1034
- return void 0;
1035
- }
1036
- }
1037
- async getPackageJSON() {
1038
- const pkgPath = await findUp(["package.json"], {
1039
- cwd: this.#cwd
1040
- });
1041
- if (!pkgPath) {
1042
- return void 0;
1043
- }
1044
- const json = await chunkE4XLCCPK_cjs.read(pkgPath);
1045
- return JSON.parse(json);
1046
- }
1047
- getPackageJSONSync() {
1048
- const pkgPath = findUpSync(["package.json"], {
1049
- cwd: this.#cwd
1050
- });
1051
- if (!pkgPath) {
1052
- return void 0;
1053
- }
1054
- const json = chunkE4XLCCPK_cjs.readSync(pkgPath);
1055
- return JSON.parse(json);
1056
- }
1057
- static setVersion(dependency, version) {
1058
- _PackageManager.#cache[dependency] = version;
1059
- }
1060
- #match(packageJSON, dependency) {
1061
- const dependencies = {
1062
- ...packageJSON["dependencies"] || {},
1063
- ...packageJSON["devDependencies"] || {}
1064
- };
1065
- if (typeof dependency === "string" && dependencies[dependency]) {
1066
- return dependencies[dependency];
1067
- }
1068
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
1069
- return matchedDependency ? dependencies[matchedDependency] : void 0;
1070
- }
1071
- async getVersion(dependency) {
1072
- if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
1073
- return _PackageManager.#cache[dependency];
1074
- }
1075
- const packageJSON = await this.getPackageJSON();
1076
- if (!packageJSON) {
1077
- return void 0;
1078
- }
1079
- return this.#match(packageJSON, dependency);
1080
- }
1081
- getVersionSync(dependency) {
1082
- if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
1083
- return _PackageManager.#cache[dependency];
1084
- }
1085
- const packageJSON = this.getPackageJSONSync();
1086
- if (!packageJSON) {
1087
- return void 0;
1088
- }
1089
- return this.#match(packageJSON, dependency);
1090
- }
1091
- async isValid(dependency, version) {
1092
- const packageVersion = await this.getVersion(dependency);
1093
- if (!packageVersion) {
1094
- return false;
1095
- }
1096
- if (packageVersion === version) {
1097
- return true;
1098
- }
1099
- const semVer = semver.coerce(packageVersion);
1100
- if (!semVer) {
1101
- throw new Error(`${packageVersion} is not valid`);
1102
- }
1103
- return semver.satisfies(semVer, version);
1104
- }
1105
- isValidSync(dependency, version) {
1106
- const packageVersion = this.getVersionSync(dependency);
1107
- if (!packageVersion) {
1108
- return false;
1109
- }
1110
- if (version === "next" && packageVersion === version) {
1111
- return true;
1112
- }
1113
- const semVer = semver.coerce(packageVersion);
1114
- if (!semVer) {
1115
- return false;
1116
- }
1117
- return semver.satisfies(semVer, version);
1118
- }
956
+
957
+ //#endregion
958
+ //#region src/PackageManager.ts
959
+ var PackageManager = class PackageManager {
960
+ static #cache = {};
961
+ #cwd;
962
+ #SLASHES = new Set(["/", "\\"]);
963
+ constructor(workspace) {
964
+ if (workspace) this.#cwd = workspace;
965
+ return this;
966
+ }
967
+ set workspace(workspace) {
968
+ this.#cwd = workspace;
969
+ }
970
+ get workspace() {
971
+ return this.#cwd;
972
+ }
973
+ normalizeDirectory(directory) {
974
+ if (!this.#SLASHES.has(directory[directory.length - 1])) return `${directory}/`;
975
+ return directory;
976
+ }
977
+ getLocation(path$3) {
978
+ let location = path$3;
979
+ if (this.#cwd) {
980
+ const require$1 = node_module.default.createRequire(this.normalizeDirectory(this.#cwd));
981
+ location = require$1.resolve(path$3);
982
+ }
983
+ return location;
984
+ }
985
+ async import(path$3) {
986
+ try {
987
+ let location = this.getLocation(path$3);
988
+ if (node_os.default.platform() === "win32") location = (0, node_url.pathToFileURL)(location).href;
989
+ const module$1 = await import(location);
990
+ return module$1?.default ?? module$1;
991
+ } catch (e) {
992
+ console.error(e);
993
+ return void 0;
994
+ }
995
+ }
996
+ async getPackageJSON() {
997
+ const pkgPath = await findUp(["package.json"], { cwd: this.#cwd });
998
+ if (!pkgPath) return void 0;
999
+ const json = await require_fs.read(pkgPath);
1000
+ return JSON.parse(json);
1001
+ }
1002
+ getPackageJSONSync() {
1003
+ const pkgPath = findUpSync(["package.json"], { cwd: this.#cwd });
1004
+ if (!pkgPath) return void 0;
1005
+ const json = require_fs.readSync(pkgPath);
1006
+ return JSON.parse(json);
1007
+ }
1008
+ static setVersion(dependency, version) {
1009
+ PackageManager.#cache[dependency] = version;
1010
+ }
1011
+ #match(packageJSON, dependency) {
1012
+ const dependencies = {
1013
+ ...packageJSON["dependencies"] || {},
1014
+ ...packageJSON["devDependencies"] || {}
1015
+ };
1016
+ if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
1017
+ const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
1018
+ return matchedDependency ? dependencies[matchedDependency] : void 0;
1019
+ }
1020
+ async getVersion(dependency) {
1021
+ if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1022
+ const packageJSON = await this.getPackageJSON();
1023
+ if (!packageJSON) return void 0;
1024
+ return this.#match(packageJSON, dependency);
1025
+ }
1026
+ getVersionSync(dependency) {
1027
+ if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1028
+ const packageJSON = this.getPackageJSONSync();
1029
+ if (!packageJSON) return void 0;
1030
+ return this.#match(packageJSON, dependency);
1031
+ }
1032
+ async isValid(dependency, version) {
1033
+ const packageVersion = await this.getVersion(dependency);
1034
+ if (!packageVersion) return false;
1035
+ if (packageVersion === version) return true;
1036
+ const semVer = (0, semver.coerce)(packageVersion);
1037
+ if (!semVer) throw new Error(`${packageVersion} is not valid`);
1038
+ return (0, semver.satisfies)(semVer, version);
1039
+ }
1040
+ isValidSync(dependency, version) {
1041
+ const packageVersion = this.getVersionSync(dependency);
1042
+ if (!packageVersion) return false;
1043
+ if (version === "next" && packageVersion === version) return true;
1044
+ const semVer = (0, semver.coerce)(packageVersion);
1045
+ if (!semVer) return false;
1046
+ return (0, semver.satisfies)(semVer, version);
1047
+ }
1119
1048
  };
1120
1049
 
1121
- Object.defineProperty(exports, "FileManager", {
1122
- enumerable: true,
1123
- get: function () { return chunkL3A3DTAX_cjs.FileManager; }
1124
- });
1125
- Object.defineProperty(exports, "getDefaultBanner", {
1126
- enumerable: true,
1127
- get: function () { return chunkL3A3DTAX_cjs.getDefaultBanner; }
1128
- });
1129
- Object.defineProperty(exports, "getSource", {
1130
- enumerable: true,
1131
- get: function () { return chunkL3A3DTAX_cjs.getSource; }
1132
- });
1050
+ //#endregion
1133
1051
  exports.BaseGenerator = BaseGenerator;
1052
+ exports.FileManager = require_FileManager.FileManager;
1134
1053
  exports.PackageManager = PackageManager;
1135
1054
  exports.PluginManager = PluginManager;
1136
1055
  exports.PromiseManager = PromiseManager;
@@ -1138,8 +1057,9 @@ exports.build = build;
1138
1057
  exports.createPlugin = createPlugin;
1139
1058
  exports.default = build;
1140
1059
  exports.defineConfig = defineConfig;
1060
+ exports.getDefaultBanner = require_FileManager.getDefaultBanner;
1061
+ exports.getSource = require_FileManager.getSource;
1141
1062
  exports.isInputPath = isInputPath;
1142
1063
  exports.safeBuild = safeBuild;
1143
1064
  exports.setup = setup;
1144
- //# sourceMappingURL=index.cjs.map
1145
1065
  //# sourceMappingURL=index.cjs.map