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