@kubb/core 3.0.0-alpha.0 → 3.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/FileManager-BbUCeEyv.d.cts +469 -0
  2. package/dist/FileManager-CpuFz6eH.d.ts +469 -0
  3. package/dist/chunk-2EU7DMPM.js +97 -0
  4. package/dist/chunk-2EU7DMPM.js.map +1 -0
  5. package/dist/chunk-5E2I6KH4.cjs +1071 -0
  6. package/dist/chunk-5E2I6KH4.cjs.map +1 -0
  7. package/dist/{chunk-XRC6KXC3.cjs → chunk-A6PCLWEY.cjs} +5 -5
  8. package/dist/{chunk-XRC6KXC3.cjs.map → chunk-A6PCLWEY.cjs.map} +1 -1
  9. package/dist/chunk-DID47EQD.cjs +102 -0
  10. package/dist/chunk-DID47EQD.cjs.map +1 -0
  11. package/dist/chunk-HBQM723K.js +1063 -0
  12. package/dist/chunk-HBQM723K.js.map +1 -0
  13. package/dist/chunk-L6YLVCKM.js +929 -0
  14. package/dist/chunk-L6YLVCKM.js.map +1 -0
  15. package/dist/{chunk-XRUOSVKX.cjs → chunk-M7NLNCSM.cjs} +71 -38
  16. package/dist/chunk-M7NLNCSM.cjs.map +1 -0
  17. package/dist/{chunk-3OXCZ5DJ.js → chunk-MU3CBCQT.js} +59 -35
  18. package/dist/chunk-MU3CBCQT.js.map +1 -0
  19. package/dist/chunk-NB4JMN75.cjs +1548 -0
  20. package/dist/chunk-NB4JMN75.cjs.map +1 -0
  21. package/dist/chunk-SEH6NUCX.cjs +42 -0
  22. package/dist/chunk-SEH6NUCX.cjs.map +1 -0
  23. package/dist/index.cjs +496 -552
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +9 -477
  26. package/dist/index.d.ts +9 -477
  27. package/dist/index.js +438 -492
  28. package/dist/index.js.map +1 -1
  29. package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
  30. package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
  31. package/dist/logger.cjs +4 -5
  32. package/dist/logger.cjs.map +1 -1
  33. package/dist/logger.d.cts +1 -2
  34. package/dist/logger.d.ts +1 -2
  35. package/dist/logger.js +2 -4
  36. package/dist/mocks.cjs +25 -19
  37. package/dist/mocks.cjs.map +1 -1
  38. package/dist/mocks.d.cts +6 -9
  39. package/dist/mocks.d.ts +6 -9
  40. package/dist/mocks.js +21 -16
  41. package/dist/mocks.js.map +1 -1
  42. package/dist/prompt-DVQN7JTN.cjs +760 -0
  43. package/dist/prompt-DVQN7JTN.cjs.map +1 -0
  44. package/dist/prompt-WQQUN22Z.js +754 -0
  45. package/dist/prompt-WQQUN22Z.js.map +1 -0
  46. package/dist/transformers.cjs +198 -42
  47. package/dist/transformers.cjs.map +1 -1
  48. package/dist/transformers.d.cts +1 -3
  49. package/dist/transformers.d.ts +1 -3
  50. package/dist/transformers.js +155 -14
  51. package/dist/transformers.js.map +1 -1
  52. package/dist/utils.cjs +12 -4
  53. package/dist/utils.cjs.map +1 -1
  54. package/dist/utils.d.cts +31 -3
  55. package/dist/utils.d.ts +31 -3
  56. package/dist/utils.js +11 -4
  57. package/package.json +11 -14
  58. package/src/BarrelManager.ts +93 -107
  59. package/src/{Generator.ts → BaseGenerator.ts} +1 -1
  60. package/src/FileManager.ts +198 -297
  61. package/src/PackageManager.ts +1 -1
  62. package/src/PluginManager.ts +152 -101
  63. package/src/__snapshots__/barrel.json +91 -0
  64. package/src/__snapshots__/grouped.json +114 -0
  65. package/src/__snapshots__/ordered.json +62 -0
  66. package/src/build.ts +86 -171
  67. package/src/errors.ts +0 -11
  68. package/src/index.ts +1 -5
  69. package/src/logger.ts +76 -34
  70. package/src/plugin.ts +3 -3
  71. package/src/transformers/index.ts +2 -3
  72. package/src/transformers/trim.ts +0 -4
  73. package/src/types.ts +35 -40
  74. package/src/utils/TreeNode.ts +132 -50
  75. package/src/utils/executeStrategies.ts +1 -1
  76. package/src/utils/index.ts +2 -1
  77. package/src/utils/parser.ts +157 -0
  78. package/dist/chunk-3OXCZ5DJ.js.map +0 -1
  79. package/dist/chunk-5JZNFPUP.js +0 -309
  80. package/dist/chunk-5JZNFPUP.js.map +0 -1
  81. package/dist/chunk-DKW7IBJV.cjs +0 -299
  82. package/dist/chunk-DKW7IBJV.cjs.map +0 -1
  83. package/dist/chunk-HMLY7DHA.js +0 -16
  84. package/dist/chunk-HMLY7DHA.js.map +0 -1
  85. package/dist/chunk-JKZG2IJR.js +0 -283
  86. package/dist/chunk-JKZG2IJR.js.map +0 -1
  87. package/dist/chunk-LKXUCYWU.cjs +0 -66
  88. package/dist/chunk-LKXUCYWU.cjs.map +0 -1
  89. package/dist/chunk-OPOT6TCT.cjs +0 -320
  90. package/dist/chunk-OPOT6TCT.cjs.map +0 -1
  91. package/dist/chunk-SA2GZKXS.js +0 -596
  92. package/dist/chunk-SA2GZKXS.js.map +0 -1
  93. package/dist/chunk-XRUOSVKX.cjs.map +0 -1
  94. package/dist/chunk-Y3LLJA4H.cjs +0 -1227
  95. package/dist/chunk-Y3LLJA4H.cjs.map +0 -1
  96. package/globals.d.ts +0 -49
  97. package/schema.json +0 -86
  98. package/src/kubb.ts +0 -11
  99. package/src/utils/getParser.ts +0 -17
package/dist/index.js CHANGED
@@ -1,35 +1,22 @@
1
- import {
2
- EventEmitter,
3
- LogLevel,
4
- createLogger,
5
- p,
6
- randomCliColour
7
- } from "./chunk-3OXCZ5DJ.js";
8
- import {
9
- FileManager
10
- } from "./chunk-SA2GZKXS.js";
11
1
  import {
12
2
  transformReservedWord
13
- } from "./chunk-JKZG2IJR.js";
3
+ } from "./chunk-2EU7DMPM.js";
14
4
  import {
5
+ EventEmitter,
6
+ createLogger
7
+ } from "./chunk-MU3CBCQT.js";
8
+ import {
9
+ FileManager,
15
10
  URLPath,
11
+ processFiles,
16
12
  setUniqueName
17
- } from "./chunk-5JZNFPUP.js";
13
+ } from "./chunk-L6YLVCKM.js";
18
14
  import "./chunk-4X5FFJPJ.js";
19
- import {
20
- __privateAdd,
21
- __privateGet,
22
- __privateMethod,
23
- __privateSet
24
- } from "./chunk-HMLY7DHA.js";
15
+ import "./chunk-HBQM723K.js";
25
16
 
26
17
  // src/build.ts
27
18
  import { clean, read } from "@kubb/fs";
28
19
 
29
- // src/PluginManager.ts
30
- import PQueue from "p-queue";
31
- import { readSync } from "@kubb/fs";
32
-
33
20
  // src/utils/executeStrategies.ts
34
21
  function hookSeq(promises) {
35
22
  return promises.filter(Boolean).reduce(
@@ -65,11 +52,10 @@ function hookParallel(promises) {
65
52
  }
66
53
 
67
54
  // src/PromiseManager.ts
68
- var _options;
69
55
  var PromiseManager = class {
56
+ #options = {};
70
57
  constructor(options = {}) {
71
- __privateAdd(this, _options, {});
72
- __privateSet(this, _options, options);
58
+ this.#options = options;
73
59
  return this;
74
60
  }
75
61
  run(strategy, promises) {
@@ -77,7 +63,7 @@ var PromiseManager = class {
77
63
  return hookSeq(promises);
78
64
  }
79
65
  if (strategy === "first") {
80
- return hookFirst(promises, __privateGet(this, _options).nullCheck);
66
+ return hookFirst(promises, this.#options.nullCheck);
81
67
  }
82
68
  if (strategy === "parallel") {
83
69
  return hookParallel(promises);
@@ -85,7 +71,6 @@ var PromiseManager = class {
85
71
  throw new Error(`${strategy} not implemented`);
86
72
  }
87
73
  };
88
- _options = new WeakMap();
89
74
  function isPromise(result) {
90
75
  return !!result && typeof result?.then === "function";
91
76
  }
@@ -94,17 +79,11 @@ function isPromiseRejectedResult(result) {
94
79
  }
95
80
 
96
81
  // src/errors.ts
97
- var Warning = class extends Error {
98
- constructor(message, options) {
99
- super(message, { cause: options?.cause });
100
- this.name = "Warning";
101
- }
102
- };
103
82
  var ValidationPluginError = class extends Error {
104
83
  };
105
84
 
106
85
  // src/plugin.ts
107
- import path from "path";
86
+ import path from "node:path";
108
87
 
109
88
  // src/utils/cache.ts
110
89
  function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
@@ -146,7 +125,7 @@ var pluginCore = createPlugin((options) => {
146
125
  name: "core",
147
126
  options,
148
127
  key: ["core"],
149
- api() {
128
+ context() {
150
129
  return {
151
130
  get config() {
152
131
  return options.config;
@@ -173,7 +152,7 @@ var pluginCore = createPlugin((options) => {
173
152
  };
174
153
  },
175
154
  resolvePath(baseName) {
176
- const root = path.resolve(this.config.root, this.config.output.path);
155
+ const root = path.resolve(options.config.root, options.config.output.path);
177
156
  return path.resolve(root, baseName);
178
157
  },
179
158
  resolveName(name) {
@@ -183,74 +162,25 @@ var pluginCore = createPlugin((options) => {
183
162
  });
184
163
 
185
164
  // src/PluginManager.ts
186
- var _core, _usedPluginNames, _promiseManager, _PluginManager_instances, getSortedPlugins_fn, addExecutedToCallStack_fn, execute_fn, executeSync_fn, catcher_fn, parse_fn;
187
165
  var PluginManager = class {
166
+ plugins;
167
+ fileManager;
168
+ events = new EventEmitter();
169
+ config;
170
+ executed = [];
171
+ logger;
172
+ options;
173
+ #core;
174
+ #usedPluginNames = {};
175
+ #promiseManager;
188
176
  constructor(config, options) {
189
- __privateAdd(this, _PluginManager_instances);
190
- this.events = new EventEmitter();
191
- this.executed = [];
192
- __privateAdd(this, _core);
193
- __privateAdd(this, _usedPluginNames, {});
194
- __privateAdd(this, _promiseManager);
195
- this.resolvePath = (params) => {
196
- if (params.pluginKey) {
197
- const paths = this.hookForPluginSync({
198
- pluginKey: params.pluginKey,
199
- hookName: "resolvePath",
200
- parameters: [params.baseName, params.mode, params.options]
201
- });
202
- if (paths && paths?.length > 1) {
203
- this.logger.emit("debug", [
204
- `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
205
-
206
- Paths: ${JSON.stringify(paths, void 0, 2)}
207
-
208
- Falling back on the first item.
209
- `
210
- ]);
211
- }
212
- return paths?.at(0);
213
- }
214
- return this.hookFirstSync({
215
- hookName: "resolvePath",
216
- parameters: [params.baseName, params.mode, params.options]
217
- }).result;
218
- };
219
- this.resolveName = (params) => {
220
- if (params.pluginKey) {
221
- const names = this.hookForPluginSync({
222
- pluginKey: params.pluginKey,
223
- hookName: "resolveName",
224
- parameters: [params.name, params.type]
225
- });
226
- if (names && names?.length > 1) {
227
- this.logger.emit("debug", [
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
- return transformReservedWord(names?.at(0) || params.name);
237
- }
238
- const name = this.hookFirstSync({
239
- hookName: "resolveName",
240
- parameters: [params.name, params.type]
241
- }).result;
242
- return transformReservedWord(name);
243
- };
244
177
  this.config = config;
178
+ this.options = options;
245
179
  this.logger = options.logger;
246
- this.queue = new PQueue({ concurrency: 1 });
247
- this.fileManager = new FileManager({
248
- task: options.task,
249
- queue: this.queue
250
- });
251
- __privateSet(this, _promiseManager, new PromiseManager({
180
+ this.fileManager = new FileManager();
181
+ this.#promiseManager = new PromiseManager({
252
182
  nullCheck: (state) => !!state?.result
253
- }));
183
+ });
254
184
  const plugins = config.plugins || [];
255
185
  const core = pluginCore({
256
186
  config,
@@ -259,34 +189,89 @@ Falling back on the first item.
259
189
  fileManager: this.fileManager,
260
190
  resolvePath: this.resolvePath.bind(this),
261
191
  resolveName: this.resolveName.bind(this),
262
- getPlugins: __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).bind(this)
192
+ getPlugins: this.#getSortedPlugins.bind(this)
263
193
  });
264
- __privateSet(this, _core, __privateMethod(this, _PluginManager_instances, parse_fn).call(this, core, this, core.api.call(null)));
265
- this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
266
- return __privateMethod(this, _PluginManager_instances, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
194
+ this.#core = this.#parse(core, this, core.context.call(null));
195
+ this.plugins = [this.#core, ...plugins].map((plugin) => {
196
+ return this.#parse(plugin, this, this.#core.context);
267
197
  });
268
198
  return this;
269
199
  }
270
200
  getFile({ name, mode, extName, pluginKey, options }) {
271
- let source = "";
272
201
  const baseName = `${name}${extName}`;
273
202
  const path2 = this.resolvePath({ baseName, mode, pluginKey, options });
274
203
  if (!path2) {
275
204
  throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
276
205
  }
277
- try {
278
- source = readSync(path2);
279
- } catch (_e) {
280
- }
281
206
  return {
282
207
  path: path2,
283
208
  baseName,
284
209
  meta: {
285
210
  pluginKey
286
211
  },
287
- source
212
+ sources: []
288
213
  };
289
214
  }
215
+ resolvePath = (params) => {
216
+ if (params.pluginKey) {
217
+ const paths = this.hookForPluginSync({
218
+ pluginKey: params.pluginKey,
219
+ hookName: "resolvePath",
220
+ parameters: [params.baseName, params.mode, params.options],
221
+ message: `Resolving path '${params.baseName}'`
222
+ });
223
+ if (paths && paths?.length > 1) {
224
+ this.logger.emit("debug", {
225
+ date: /* @__PURE__ */ new Date(),
226
+ logs: [
227
+ `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
228
+
229
+ Paths: ${JSON.stringify(paths, void 0, 2)}
230
+
231
+ Falling back on the first item.
232
+ `
233
+ ]
234
+ });
235
+ }
236
+ return paths?.at(0);
237
+ }
238
+ return this.hookFirstSync({
239
+ hookName: "resolvePath",
240
+ parameters: [params.baseName, params.mode, params.options],
241
+ message: `Resolving path '${params.baseName}'`
242
+ }).result;
243
+ };
244
+ //TODO refactor by using the order of plugins and the cache of the fileManager instead of guessing and recreating the name/path
245
+ resolveName = (params) => {
246
+ if (params.pluginKey) {
247
+ const names = this.hookForPluginSync({
248
+ pluginKey: params.pluginKey,
249
+ hookName: "resolveName",
250
+ parameters: [params.name, params.type],
251
+ message: `Resolving name '${params.name}' and type '${params.type}'`
252
+ });
253
+ if (names && names?.length > 1) {
254
+ this.logger.emit("debug", {
255
+ date: /* @__PURE__ */ new Date(),
256
+ logs: [
257
+ `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
258
+
259
+ Names: ${JSON.stringify(names, void 0, 2)}
260
+
261
+ Falling back on the first item.
262
+ `
263
+ ]
264
+ });
265
+ }
266
+ return transformReservedWord(names?.at(0) || params.name);
267
+ }
268
+ const name = this.hookFirstSync({
269
+ hookName: "resolveName",
270
+ parameters: [params.name, params.type],
271
+ message: `Resolving name '${params.name}' and type '${params.type}'`
272
+ }).result;
273
+ return transformReservedWord(name);
274
+ };
290
275
  /**
291
276
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
292
277
  */
@@ -296,21 +281,26 @@ Falling back on the first item.
296
281
  /**
297
282
  * Run a specific hookName for plugin x.
298
283
  */
299
- hookForPlugin({
284
+ async hookForPlugin({
300
285
  pluginKey,
301
286
  hookName,
302
- parameters
287
+ parameters,
288
+ message
303
289
  }) {
304
290
  const plugins = this.getPluginsByKey(hookName, pluginKey);
291
+ this.logger.emit("progress_start", { id: hookName, size: plugins.length, message: "Running plugins..." });
305
292
  const promises = plugins.map((plugin) => {
306
- return __privateMethod(this, _PluginManager_instances, execute_fn).call(this, {
293
+ return this.#execute({
307
294
  strategy: "hookFirst",
308
295
  hookName,
309
296
  parameters,
310
- plugin
297
+ plugin,
298
+ message
311
299
  });
312
300
  }).filter(Boolean);
313
- return Promise.all(promises);
301
+ const items = await Promise.all(promises);
302
+ this.logger.emit("progress_stop", { id: hookName });
303
+ return items;
314
304
  }
315
305
  /**
316
306
  * Run a specific hookName for plugin x.
@@ -318,17 +308,20 @@ Falling back on the first item.
318
308
  hookForPluginSync({
319
309
  pluginKey,
320
310
  hookName,
321
- parameters
311
+ parameters,
312
+ message
322
313
  }) {
323
314
  const plugins = this.getPluginsByKey(hookName, pluginKey);
324
- return plugins.map((plugin) => {
325
- return __privateMethod(this, _PluginManager_instances, executeSync_fn).call(this, {
315
+ const result = plugins.map((plugin) => {
316
+ return this.#executeSync({
326
317
  strategy: "hookFirst",
327
318
  hookName,
328
319
  parameters,
329
- plugin
320
+ plugin,
321
+ message
330
322
  });
331
323
  }).filter(Boolean);
324
+ return result;
332
325
  }
333
326
  /**
334
327
  * First non-null result stops and will return it's value.
@@ -336,17 +329,21 @@ Falling back on the first item.
336
329
  async hookFirst({
337
330
  hookName,
338
331
  parameters,
339
- skipped
332
+ skipped,
333
+ message
340
334
  }) {
341
- const promises = __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).call(this).filter((plugin) => {
335
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
342
336
  return skipped ? skipped.has(plugin) : true;
343
- }).map((plugin) => {
337
+ });
338
+ this.logger.emit("progress_start", { id: hookName, size: plugins.length });
339
+ const promises = plugins.map((plugin) => {
344
340
  return async () => {
345
- const value = await __privateMethod(this, _PluginManager_instances, execute_fn).call(this, {
341
+ const value = await this.#execute({
346
342
  strategy: "hookFirst",
347
343
  hookName,
348
344
  parameters,
349
- plugin
345
+ plugin,
346
+ message
350
347
  });
351
348
  return Promise.resolve({
352
349
  plugin,
@@ -354,7 +351,9 @@ Falling back on the first item.
354
351
  });
355
352
  };
356
353
  });
357
- return __privateGet(this, _promiseManager).run("first", promises);
354
+ const result = await this.#promiseManager.run("first", promises);
355
+ this.logger.emit("progress_stop", { id: hookName });
356
+ return result;
358
357
  }
359
358
  /**
360
359
  * First non-null result stops and will return it's value.
@@ -362,19 +361,21 @@ Falling back on the first item.
362
361
  hookFirstSync({
363
362
  hookName,
364
363
  parameters,
365
- skipped
364
+ skipped,
365
+ message
366
366
  }) {
367
367
  let parseResult = null;
368
- for (const plugin of __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).call(this)) {
369
- if (skipped?.has(plugin)) {
370
- continue;
371
- }
368
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
369
+ return skipped ? skipped.has(plugin) : true;
370
+ });
371
+ for (const plugin of plugins) {
372
372
  parseResult = {
373
- result: __privateMethod(this, _PluginManager_instances, executeSync_fn).call(this, {
373
+ result: this.#executeSync({
374
374
  strategy: "hookFirst",
375
375
  hookName,
376
376
  parameters,
377
- plugin
377
+ plugin,
378
+ message
378
379
  }),
379
380
  plugin
380
381
  };
@@ -389,23 +390,28 @@ Falling back on the first item.
389
390
  */
390
391
  async hookParallel({
391
392
  hookName,
392
- parameters
393
+ parameters,
394
+ message
393
395
  }) {
394
- const promises = __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).call(this).map((plugin) => {
395
- return () => __privateMethod(this, _PluginManager_instances, execute_fn).call(this, {
396
+ const plugins = this.#getSortedPlugins(hookName);
397
+ this.logger.emit("progress_start", { id: hookName, size: plugins.length });
398
+ const promises = plugins.map((plugin) => {
399
+ return () => this.#execute({
396
400
  strategy: "hookParallel",
397
401
  hookName,
398
402
  parameters,
399
- plugin
403
+ plugin,
404
+ message
400
405
  });
401
406
  });
402
- const results = await __privateGet(this, _promiseManager).run("parallel", promises);
407
+ const results = await this.#promiseManager.run("parallel", promises);
403
408
  results.forEach((result, index) => {
404
409
  if (isPromiseRejectedResult(result)) {
405
- const plugin = __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).call(this)[index];
406
- __privateMethod(this, _PluginManager_instances, catcher_fn).call(this, result.reason, plugin, hookName);
410
+ const plugin = this.#getSortedPlugins(hookName)[index];
411
+ this.#catcher(result.reason, plugin, hookName);
407
412
  }
408
413
  });
414
+ this.logger.emit("progress_stop", { id: hookName });
409
415
  return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
410
416
  }
411
417
  /**
@@ -414,36 +420,70 @@ Falling back on the first item.
414
420
  hookReduceArg0({
415
421
  hookName,
416
422
  parameters,
417
- reduce
423
+ reduce,
424
+ message
418
425
  }) {
419
426
  const [argument0, ...rest] = parameters;
427
+ const plugins = this.#getSortedPlugins(hookName);
420
428
  let promise = Promise.resolve(argument0);
421
- for (const plugin of __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).call(this)) {
429
+ for (const plugin of plugins) {
422
430
  promise = promise.then((arg0) => {
423
- const value = __privateMethod(this, _PluginManager_instances, execute_fn).call(this, {
431
+ const value = this.#execute({
424
432
  strategy: "hookReduceArg0",
425
433
  hookName,
426
434
  parameters: [arg0, ...rest],
427
- plugin
435
+ plugin,
436
+ message
428
437
  });
429
438
  return value;
430
- }).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
439
+ }).then((result) => reduce.call(this.#core.context, argument0, result, plugin));
431
440
  }
432
441
  return promise;
433
442
  }
434
443
  /**
435
444
  * Chains plugins
436
445
  */
437
- async hookSeq({ hookName, parameters }) {
438
- const promises = __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).call(this).map((plugin) => {
439
- return () => __privateMethod(this, _PluginManager_instances, execute_fn).call(this, {
446
+ async hookSeq({
447
+ hookName,
448
+ parameters,
449
+ message
450
+ }) {
451
+ const plugins = this.#getSortedPlugins(hookName);
452
+ this.logger.emit("progress_start", { id: hookName, size: plugins.length });
453
+ const promises = plugins.map((plugin) => {
454
+ return () => this.#execute({
440
455
  strategy: "hookSeq",
441
456
  hookName,
442
457
  parameters,
443
- plugin
458
+ plugin,
459
+ message
444
460
  });
445
461
  });
446
- return __privateGet(this, _promiseManager).run("seq", promises);
462
+ await this.#promiseManager.run("seq", promises);
463
+ this.logger.emit("progress_stop", { id: hookName });
464
+ }
465
+ #getSortedPlugins(hookName) {
466
+ const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
467
+ if (hookName) {
468
+ return plugins.filter((item) => item[hookName]);
469
+ }
470
+ return plugins.map((plugin) => {
471
+ if (plugin.pre) {
472
+ const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
473
+ if (!isValid) {
474
+ throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
475
+ }
476
+ }
477
+ return plugin;
478
+ }).sort((a, b) => {
479
+ if (b.pre?.includes(a.name)) {
480
+ return 1;
481
+ }
482
+ if (b.post?.includes(a.name)) {
483
+ return -1;
484
+ }
485
+ return 0;
486
+ });
447
487
  }
448
488
  getPluginsByKey(hookName, pluginKey) {
449
489
  const plugins = [...this.plugins];
@@ -460,14 +500,146 @@ Falling back on the first item.
460
500
  if (!pluginByPluginName?.length) {
461
501
  const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
462
502
  if (corePlugin) {
463
- this.logger.emit("debug", [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]);
503
+ this.logger.emit("debug", {
504
+ date: /* @__PURE__ */ new Date(),
505
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
506
+ });
464
507
  } else {
465
- this.logger.emit("debug", [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]);
508
+ this.logger.emit("debug", {
509
+ date: /* @__PURE__ */ new Date(),
510
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
511
+ });
466
512
  }
467
513
  return corePlugin ? [corePlugin] : [];
468
514
  }
469
515
  return pluginByPluginName;
470
516
  }
517
+ #addExecutedToCallStack(executer) {
518
+ if (executer) {
519
+ this.events.emit("executed", executer);
520
+ this.executed.push(executer);
521
+ this.logger.emit("progressed", { id: executer.hookName, message: `${executer.plugin.name}: ${executer.message}` });
522
+ }
523
+ }
524
+ /**
525
+ * Run an async plugin hook and return the result.
526
+ * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
527
+ * @param args Arguments passed to the plugin hook.
528
+ * @param plugin The actual pluginObject to run.
529
+ */
530
+ // Implementation signature
531
+ #execute({
532
+ strategy,
533
+ hookName,
534
+ parameters,
535
+ plugin,
536
+ message
537
+ }) {
538
+ const hook = plugin[hookName];
539
+ let output;
540
+ if (!hook) {
541
+ return null;
542
+ }
543
+ this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
544
+ const promise = new Promise((resolve2) => {
545
+ resolve2(void 0);
546
+ });
547
+ const task = promise.then(() => {
548
+ if (typeof hook === "function") {
549
+ const possiblePromiseResult = hook.apply({ ...this.#core.context, plugin }, parameters);
550
+ if (isPromise(possiblePromiseResult)) {
551
+ return Promise.resolve(possiblePromiseResult);
552
+ }
553
+ return possiblePromiseResult;
554
+ }
555
+ return hook;
556
+ }).then((result) => {
557
+ output = result;
558
+ this.#addExecutedToCallStack({
559
+ parameters,
560
+ output,
561
+ strategy,
562
+ hookName,
563
+ plugin,
564
+ message
565
+ });
566
+ return result;
567
+ }).catch((e) => {
568
+ this.#catcher(e, plugin, hookName);
569
+ return null;
570
+ });
571
+ return task;
572
+ }
573
+ /**
574
+ * Run a sync plugin hook and return the result.
575
+ * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
576
+ * @param args Arguments passed to the plugin hook.
577
+ * @param plugin The acutal plugin
578
+ * @param replaceContext When passed, the plugin context can be overridden.
579
+ */
580
+ #executeSync({
581
+ strategy,
582
+ hookName,
583
+ parameters,
584
+ plugin,
585
+ message
586
+ }) {
587
+ const hook = plugin[hookName];
588
+ let output;
589
+ if (!hook) {
590
+ return null;
591
+ }
592
+ this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
593
+ try {
594
+ if (typeof hook === "function") {
595
+ const fn = hook.apply({ ...this.#core.context, plugin }, parameters);
596
+ output = fn;
597
+ this.#addExecutedToCallStack({
598
+ parameters,
599
+ output,
600
+ strategy,
601
+ hookName,
602
+ plugin,
603
+ message
604
+ });
605
+ return fn;
606
+ }
607
+ output = hook;
608
+ this.#addExecutedToCallStack({
609
+ parameters,
610
+ output,
611
+ strategy,
612
+ hookName,
613
+ plugin,
614
+ message
615
+ });
616
+ return hook;
617
+ } catch (e) {
618
+ this.#catcher(e, plugin, hookName);
619
+ return null;
620
+ }
621
+ }
622
+ #catcher(cause, plugin, hookName) {
623
+ const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
624
+ this.logger.emit("error", text, cause);
625
+ this.events.emit("error", cause);
626
+ }
627
+ #parse(plugin, pluginManager, context) {
628
+ const usedPluginNames = pluginManager.#usedPluginNames;
629
+ setUniqueName(plugin.name, usedPluginNames);
630
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
631
+ if (plugin.context && typeof plugin.context === "function") {
632
+ return {
633
+ ...plugin,
634
+ key,
635
+ context: plugin.context.call(context)
636
+ };
637
+ }
638
+ return {
639
+ ...plugin,
640
+ key
641
+ };
642
+ }
471
643
  static getDependedPlugins(plugins, dependedPluginNames) {
472
644
  let pluginNames = [];
473
645
  if (typeof dependedPluginNames === "string") {
@@ -484,157 +656,8 @@ Falling back on the first item.
484
656
  });
485
657
  }
486
658
  static get hooks() {
487
- return ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
488
- }
489
- };
490
- _core = new WeakMap();
491
- _usedPluginNames = new WeakMap();
492
- _promiseManager = new WeakMap();
493
- _PluginManager_instances = new WeakSet();
494
- getSortedPlugins_fn = function(hookName) {
495
- const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
496
- if (hookName) {
497
- if (this.logger.logLevel === LogLevel.info) {
498
- const containsHookName = plugins.some((item) => item[hookName]);
499
- if (!containsHookName) {
500
- this.logger.emit("warning", `No hook ${hookName} found`);
501
- }
502
- }
503
- return plugins.filter((item) => item[hookName]);
504
- }
505
- return plugins.map((plugin) => {
506
- if (plugin.pre) {
507
- const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
508
- if (!isValid) {
509
- throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
510
- }
511
- }
512
- return plugin;
513
- }).sort((a, b) => {
514
- if (b.pre?.includes(a.name)) {
515
- return 1;
516
- }
517
- if (b.post?.includes(a.name)) {
518
- return -1;
519
- }
520
- return 0;
521
- });
522
- };
523
- addExecutedToCallStack_fn = function(executer) {
524
- if (executer) {
525
- this.events.emit("executed", executer);
526
- this.executed.push(executer);
527
- }
528
- };
529
- /**
530
- * Run an async plugin hook and return the result.
531
- * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
532
- * @param args Arguments passed to the plugin hook.
533
- * @param plugin The actual pluginObject to run.
534
- */
535
- // Implementation signature
536
- execute_fn = function({
537
- strategy,
538
- hookName,
539
- parameters,
540
- plugin
541
- }) {
542
- const hook = plugin[hookName];
543
- let output;
544
- if (!hook) {
545
- return null;
546
- }
547
- this.events.emit("execute", { strategy, hookName, parameters, plugin });
548
- const task = Promise.resolve().then(() => {
549
- if (typeof hook === "function") {
550
- const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
551
- if (isPromise(possiblePromiseResult)) {
552
- return Promise.resolve(possiblePromiseResult);
553
- }
554
- return possiblePromiseResult;
555
- }
556
- return hook;
557
- }).then((result) => {
558
- output = result;
559
- __privateMethod(this, _PluginManager_instances, addExecutedToCallStack_fn).call(this, {
560
- parameters,
561
- output,
562
- strategy,
563
- hookName,
564
- plugin
565
- });
566
- return result;
567
- }).catch((e) => {
568
- __privateMethod(this, _PluginManager_instances, catcher_fn).call(this, e, plugin, hookName);
569
- return null;
570
- });
571
- return task;
572
- };
573
- /**
574
- * Run a sync plugin hook and return the result.
575
- * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
576
- * @param args Arguments passed to the plugin hook.
577
- * @param plugin The acutal plugin
578
- * @param replaceContext When passed, the plugin context can be overridden.
579
- */
580
- executeSync_fn = function({
581
- strategy,
582
- hookName,
583
- parameters,
584
- plugin
585
- }) {
586
- const hook = plugin[hookName];
587
- let output;
588
- if (!hook) {
589
- return null;
590
- }
591
- this.events.emit("execute", { strategy, hookName, parameters, plugin });
592
- try {
593
- if (typeof hook === "function") {
594
- const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
595
- output = fn;
596
- return fn;
597
- }
598
- output = hook;
599
- __privateMethod(this, _PluginManager_instances, addExecutedToCallStack_fn).call(this, {
600
- parameters,
601
- output,
602
- strategy,
603
- hookName,
604
- plugin
605
- });
606
- return hook;
607
- } catch (e) {
608
- __privateMethod(this, _PluginManager_instances, catcher_fn).call(this, e, plugin, hookName);
609
- return null;
610
- }
611
- };
612
- catcher_fn = function(cause, plugin, hookName) {
613
- const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
614
- this.logger.emit("error", text, cause);
615
- this.events.emit("error", cause);
616
- };
617
- parse_fn = function(plugin, pluginManager, context) {
618
- const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
619
- setUniqueName(plugin.name, usedPluginNames);
620
- const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
621
- if (!plugin.transform) {
622
- plugin.transform = function transform(_path, code) {
623
- return code;
624
- };
659
+ return ["buildStart", "resolvePath", "resolveName", "buildEnd"];
625
660
  }
626
- if (plugin.api && typeof plugin.api === "function") {
627
- const api = plugin.api.call(context);
628
- return {
629
- ...plugin,
630
- key,
631
- api
632
- };
633
- }
634
- return {
635
- ...plugin,
636
- key
637
- };
638
661
  };
639
662
 
640
663
  // src/config.ts
@@ -646,238 +669,168 @@ function isInputPath(result) {
646
669
  }
647
670
 
648
671
  // src/build.ts
649
- async function transformReducer(_previousCode, result, _plugin) {
650
- return result;
651
- }
672
+ import { join, resolve } from "node:path";
673
+ import { getRelativePath } from "@kubb/fs";
652
674
  async function setup(options) {
653
- const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
654
- let count = 0;
675
+ const { config, logger = createLogger() } = options;
655
676
  try {
656
677
  if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
657
678
  await read(config.input.path);
658
679
  }
659
680
  } catch (e) {
660
681
  if (isInputPath(config)) {
661
- throw new Error(
662
- `Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${p.dim(config.input.path)}`,
663
- {
664
- cause: e
665
- }
666
- );
682
+ throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${config.input.path}`, {
683
+ cause: e
684
+ });
667
685
  }
668
686
  }
669
687
  if (config.output.clean) {
670
688
  await clean(config.output.path);
689
+ await clean(join(config.root, ".kubb"));
671
690
  }
672
- const task = async (file) => {
673
- const { path: path2 } = file;
674
- let source = await FileManager.getSource(file);
675
- const { result: loadedResult } = await pluginManager.hookFirst({
676
- hookName: "load",
677
- parameters: [path2]
678
- });
679
- if (loadedResult && isPromise(loadedResult)) {
680
- source = await loadedResult;
681
- }
682
- if (loadedResult && !isPromise(loadedResult)) {
683
- source = loadedResult;
684
- }
685
- if (source) {
686
- source = await pluginManager.hookReduceArg0({
687
- hookName: "transform",
688
- parameters: [path2, source],
689
- reduce: transformReducer
690
- });
691
- if (config.output.write || config.output.write === void 0) {
692
- if (file.meta?.pluginKey) {
693
- await pluginManager.hookForPlugin({
694
- pluginKey: file.meta?.pluginKey,
695
- hookName: "writeFile",
696
- parameters: [path2, source]
697
- });
698
- }
699
- await pluginManager.hookFirst({
700
- hookName: "writeFile",
701
- parameters: [path2, source]
702
- });
703
- }
704
- }
705
- return {
706
- ...file,
707
- source: source || ""
708
- };
709
- };
710
- const pluginManager = new PluginManager(config, { logger, task });
711
- pluginManager.on("execute", (executer) => {
712
- const { hookName, parameters, plugin } = executer;
713
- if (hookName === "writeFile") {
714
- const [code] = parameters;
715
- logger.emit("debug", [`PluginKey ${p.dim(JSON.stringify(plugin.key))}
716
- with source
717
-
718
- ${code}`]);
719
- }
720
- });
721
- pluginManager.queue.on("add", () => {
722
- if (logger.logLevel !== LogLevel.info) {
723
- return;
724
- }
725
- if (count === 0) {
726
- logger.emit("start", "\u{1F4BE} Writing");
727
- }
728
- });
729
- pluginManager.queue.on("active", () => {
730
- if (logger.logLevel !== LogLevel.info) {
731
- return;
732
- }
733
- if (logger.spinner && pluginManager.queue.size > 0) {
734
- const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
735
- logger.spinner.suffixText = p.dim(text);
736
- }
737
- ++count;
738
- });
739
- pluginManager.queue.on("completed", () => {
740
- if (logger.logLevel !== LogLevel.info) {
741
- return;
742
- }
743
- if (logger.spinner) {
744
- const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
745
- logger.spinner.suffixText = p.dim(text);
746
- }
747
- });
748
- pluginManager.on("executed", (executer) => {
749
- const { hookName, plugin, output, parameters } = executer;
750
- const logs = [
751
- `${randomCliColour(plugin.name)} Executing ${hookName}`,
752
- parameters && `${p.bgWhite("Parameters")} ${randomCliColour(plugin.name)} ${hookName}`,
753
- JSON.stringify(parameters, void 0, 2),
754
- output && `${p.bgWhite("Output")} ${randomCliColour(plugin.name)} ${hookName}`,
755
- output
756
- ].filter(Boolean);
757
- logger.emit("debug", logs);
758
- });
759
- return pluginManager;
691
+ return new PluginManager(config, { logger });
760
692
  }
761
693
  async function build(options) {
762
- const pluginManager = await setup(options);
763
- const { fileManager, logger } = pluginManager;
764
- await pluginManager.hookParallel({
765
- hookName: "buildStart",
766
- parameters: [options.config]
767
- });
768
- await pluginManager.hookParallel({ hookName: "buildEnd" });
769
- if (logger.logLevel === LogLevel.info) {
770
- logger.emit("end", "\u{1F4BE} Writing completed");
771
- }
772
- const files = await Promise.all(
773
- fileManager.files.map(async (file) => ({
774
- ...file,
775
- source: await FileManager.getSource(file)
776
- }))
777
- );
694
+ const { files, pluginManager, error } = await safeBuild(options);
695
+ if (error) throw error;
778
696
  return {
779
697
  files,
780
- pluginManager
698
+ pluginManager,
699
+ error
781
700
  };
782
701
  }
783
702
  async function safeBuild(options) {
703
+ let files = [];
784
704
  const pluginManager = await setup(options);
785
- const { fileManager, logger } = pluginManager;
786
705
  try {
706
+ pluginManager.events.on("executing", ({ plugin, message }) => {
707
+ pluginManager.logger.emit("debug", { date: /* @__PURE__ */ new Date(), logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`] });
708
+ });
709
+ pluginManager.events.on("executed", ({ plugin, message, output }) => {
710
+ pluginManager.logger.emit("debug", {
711
+ date: /* @__PURE__ */ new Date(),
712
+ logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
713
+ });
714
+ });
787
715
  await pluginManager.hookParallel({
788
716
  hookName: "buildStart",
789
- parameters: [options.config]
717
+ parameters: [options.config],
718
+ message: "buildStart"
790
719
  });
791
- await pluginManager.hookParallel({ hookName: "buildEnd" });
792
- if (logger.logLevel === LogLevel.info) {
793
- logger.emit("end", "\u{1F4BE} Writing completed");
794
- }
720
+ const root = resolve(options.config.root);
721
+ const rootPath = resolve(root, options.config.output.path, "index.ts");
722
+ const barrelFiles = pluginManager.fileManager.files.filter((file) => {
723
+ return file.sources.some((source) => source.isIndexable);
724
+ });
725
+ const rootFile = {
726
+ path: rootPath,
727
+ baseName: "index.ts",
728
+ exports: barrelFiles.flatMap((file) => {
729
+ return file.sources?.map((source) => {
730
+ if (!file.path || !source.isIndexable) {
731
+ return void 0;
732
+ }
733
+ const plugin = pluginManager.plugins.find((item) => {
734
+ const meta = file.meta;
735
+ return item.name === meta?.pluginKey?.[0];
736
+ });
737
+ if (plugin?.output?.exportType === false) {
738
+ return void 0;
739
+ }
740
+ if (FileManager.getMode(plugin?.output?.path) === "single") {
741
+ return void 0;
742
+ }
743
+ return {
744
+ name: options.config.output.exportType === "barrel" ? void 0 : [source.name],
745
+ path: getRelativePath(rootPath, file.path),
746
+ isTypeOnly: source.isTypeOnly
747
+ };
748
+ }).filter(Boolean);
749
+ }).filter(Boolean),
750
+ sources: [],
751
+ meta: {}
752
+ };
753
+ if (options.config.output.exportType) {
754
+ await pluginManager.fileManager.add(rootFile);
755
+ }
756
+ files = await processFiles({
757
+ config: options.config,
758
+ dryRun: !options.config.output.write,
759
+ files: pluginManager.fileManager.files,
760
+ logger: pluginManager.logger
761
+ });
762
+ await pluginManager.hookParallel({ hookName: "buildEnd", message: `Build stopped for ${options.config.name}` });
763
+ pluginManager.fileManager.clear();
795
764
  } catch (e) {
796
- const files2 = await Promise.all(
797
- fileManager.files.map(async (file) => ({
798
- ...file,
799
- source: await FileManager.getSource(file)
800
- }))
801
- );
802
765
  return {
803
- files: files2,
766
+ files: [],
804
767
  pluginManager,
805
768
  error: e
806
769
  };
807
770
  }
808
- const files = await Promise.all(
809
- fileManager.files.map(async (file) => ({
810
- ...file,
811
- source: await FileManager.getSource(file)
812
- }))
813
- );
814
771
  return {
815
772
  files,
816
773
  pluginManager
817
774
  };
818
775
  }
819
776
 
820
- // src/Generator.ts
821
- var _options2, _context;
822
- var Generator = class {
777
+ // src/BaseGenerator.ts
778
+ var BaseGenerator = class {
779
+ #options = {};
780
+ #context = {};
823
781
  constructor(options, context) {
824
- __privateAdd(this, _options2, {});
825
- __privateAdd(this, _context, {});
826
782
  if (context) {
827
- __privateSet(this, _context, context);
783
+ this.#context = context;
828
784
  }
829
785
  if (options) {
830
- __privateSet(this, _options2, options);
786
+ this.#options = options;
831
787
  }
832
788
  return this;
833
789
  }
834
790
  get options() {
835
- return __privateGet(this, _options2);
791
+ return this.#options;
836
792
  }
837
793
  get context() {
838
- return __privateGet(this, _context);
794
+ return this.#context;
839
795
  }
840
796
  set options(options) {
841
- __privateSet(this, _options2, { ...__privateGet(this, _options2), ...options });
797
+ this.#options = { ...this.#options, ...options };
842
798
  }
843
799
  };
844
- _options2 = new WeakMap();
845
- _context = new WeakMap();
846
800
 
847
801
  // src/PackageManager.ts
848
- import mod from "module";
849
- import os from "os";
850
- import { pathToFileURL } from "url";
802
+ import mod from "node:module";
803
+ import os from "node:os";
804
+ import { pathToFileURL } from "node:url";
851
805
  import { findUp, findUpSync } from "find-up";
852
806
  import { coerce, satisfies } from "semver";
853
- import { read as read2, readSync as readSync2 } from "@kubb/fs";
854
- var _cache, _cwd, _SLASHES, _PackageManager_instances, match_fn;
855
- var _PackageManager = class _PackageManager {
807
+ import { read as read2, readSync } from "@kubb/fs";
808
+ var PackageManager = class _PackageManager {
809
+ static #cache = {};
810
+ #cwd;
811
+ #SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
856
812
  constructor(workspace) {
857
- __privateAdd(this, _PackageManager_instances);
858
- __privateAdd(this, _cwd);
859
- __privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
860
813
  if (workspace) {
861
- __privateSet(this, _cwd, workspace);
814
+ this.#cwd = workspace;
862
815
  }
863
816
  return this;
864
817
  }
865
818
  set workspace(workspace) {
866
- __privateSet(this, _cwd, workspace);
819
+ this.#cwd = workspace;
867
820
  }
868
821
  get workspace() {
869
- return __privateGet(this, _cwd);
822
+ return this.#cwd;
870
823
  }
871
824
  normalizeDirectory(directory) {
872
- if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
825
+ if (!this.#SLASHES.has(directory[directory.length - 1])) {
873
826
  return `${directory}/`;
874
827
  }
875
828
  return directory;
876
829
  }
877
830
  getLocation(path2) {
878
831
  let location = path2;
879
- if (__privateGet(this, _cwd)) {
880
- const require2 = mod.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
832
+ if (this.#cwd) {
833
+ const require2 = mod.createRequire(this.normalizeDirectory(this.#cwd));
881
834
  location = require2.resolve(path2);
882
835
  }
883
836
  return location;
@@ -891,13 +844,13 @@ var _PackageManager = class _PackageManager {
891
844
  const module = await import(location);
892
845
  return module?.default ?? module;
893
846
  } catch (e) {
894
- console.log(e);
847
+ console.error(e);
895
848
  return void 0;
896
849
  }
897
850
  }
898
851
  async getPackageJSON() {
899
852
  const pkgPath = await findUp(["package.json"], {
900
- cwd: __privateGet(this, _cwd)
853
+ cwd: this.#cwd
901
854
  });
902
855
  if (!pkgPath) {
903
856
  return void 0;
@@ -907,36 +860,47 @@ var _PackageManager = class _PackageManager {
907
860
  }
908
861
  getPackageJSONSync() {
909
862
  const pkgPath = findUpSync(["package.json"], {
910
- cwd: __privateGet(this, _cwd)
863
+ cwd: this.#cwd
911
864
  });
912
865
  if (!pkgPath) {
913
866
  return void 0;
914
867
  }
915
- const json = readSync2(pkgPath);
868
+ const json = readSync(pkgPath);
916
869
  return JSON.parse(json);
917
870
  }
918
871
  static setVersion(dependency, version) {
919
- __privateGet(_PackageManager, _cache)[dependency] = version;
872
+ _PackageManager.#cache[dependency] = version;
873
+ }
874
+ #match(packageJSON, dependency) {
875
+ const dependencies = {
876
+ ...packageJSON["dependencies"] || {},
877
+ ...packageJSON["devDependencies"] || {}
878
+ };
879
+ if (typeof dependency === "string" && dependencies[dependency]) {
880
+ return dependencies[dependency];
881
+ }
882
+ const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
883
+ return matchedDependency ? dependencies[matchedDependency] : void 0;
920
884
  }
921
885
  async getVersion(dependency) {
922
- if (typeof dependency === "string" && __privateGet(_PackageManager, _cache)[dependency]) {
923
- return __privateGet(_PackageManager, _cache)[dependency];
886
+ if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
887
+ return _PackageManager.#cache[dependency];
924
888
  }
925
889
  const packageJSON = await this.getPackageJSON();
926
890
  if (!packageJSON) {
927
891
  return void 0;
928
892
  }
929
- return __privateMethod(this, _PackageManager_instances, match_fn).call(this, packageJSON, dependency);
893
+ return this.#match(packageJSON, dependency);
930
894
  }
931
895
  getVersionSync(dependency) {
932
- if (typeof dependency === "string" && __privateGet(_PackageManager, _cache)[dependency]) {
933
- return __privateGet(_PackageManager, _cache)[dependency];
896
+ if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
897
+ return _PackageManager.#cache[dependency];
934
898
  }
935
899
  const packageJSON = this.getPackageJSONSync();
936
900
  if (!packageJSON) {
937
901
  return void 0;
938
902
  }
939
- return __privateMethod(this, _PackageManager_instances, match_fn).call(this, packageJSON, dependency);
903
+ return this.#match(packageJSON, dependency);
940
904
  }
941
905
  async isValid(dependency, version) {
942
906
  const packageVersion = await this.getVersion(dependency);
@@ -964,30 +928,12 @@ var _PackageManager = class _PackageManager {
964
928
  return satisfies(semVer, version);
965
929
  }
966
930
  };
967
- _cache = new WeakMap();
968
- _cwd = new WeakMap();
969
- _SLASHES = new WeakMap();
970
- _PackageManager_instances = new WeakSet();
971
- match_fn = function(packageJSON, dependency) {
972
- const dependencies = {
973
- ...packageJSON["dependencies"] || {},
974
- ...packageJSON["devDependencies"] || {}
975
- };
976
- if (typeof dependency === "string" && dependencies[dependency]) {
977
- return dependencies[dependency];
978
- }
979
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
980
- return matchedDependency ? dependencies[matchedDependency] : void 0;
981
- };
982
- __privateAdd(_PackageManager, _cache, {});
983
- var PackageManager = _PackageManager;
984
931
  export {
932
+ BaseGenerator,
985
933
  FileManager,
986
- Generator,
987
934
  PackageManager,
988
935
  PluginManager,
989
936
  PromiseManager,
990
- Warning,
991
937
  build,
992
938
  createPlugin,
993
939
  build as default,