@kubb/core 3.0.0-alpha.2 → 3.0.0-alpha.20

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