@kubb/core 4.11.3 → 4.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/fs-DhLl4-lT.cjs +177 -0
  2. package/dist/fs-DhLl4-lT.cjs.map +1 -0
  3. package/dist/fs-ph1OdgEr.js +108 -0
  4. package/dist/fs-ph1OdgEr.js.map +1 -0
  5. package/dist/fs.cjs +8 -0
  6. package/dist/fs.d.cts +21 -0
  7. package/dist/fs.d.ts +21 -0
  8. package/dist/fs.js +3 -0
  9. package/dist/{getBarrelFiles-ZIHk_1ln.d.ts → getBarrelFiles-BEWbZEZf.d.ts} +3 -6
  10. package/dist/{getBarrelFiles-8VEWWk9Z.cjs → getBarrelFiles-BcgToi50.cjs} +71 -62
  11. package/dist/getBarrelFiles-BcgToi50.cjs.map +1 -0
  12. package/dist/{getBarrelFiles-DQ0hksqD.js → getBarrelFiles-ClyWjO0d.js} +65 -55
  13. package/dist/getBarrelFiles-ClyWjO0d.js.map +1 -0
  14. package/dist/{getBarrelFiles-B_2WDywH.d.cts → getBarrelFiles-LW3anr-E.d.cts} +3 -6
  15. package/dist/hooks.cjs +1 -1
  16. package/dist/hooks.d.cts +1 -1
  17. package/dist/hooks.d.ts +1 -1
  18. package/dist/index.cjs +68 -212
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +8 -9
  21. package/dist/index.d.ts +8 -9
  22. package/dist/index.js +61 -204
  23. package/dist/index.js.map +1 -1
  24. package/dist/{transformers-B-zCAPV-.cjs → transformers-BqQRkrxy.cjs} +2 -2
  25. package/dist/{transformers-B-zCAPV-.cjs.map → transformers-BqQRkrxy.cjs.map} +1 -1
  26. package/dist/{transformers-CjdbeLAK.js → transformers-C481fXH-.js} +1 -1
  27. package/dist/{transformers-CjdbeLAK.js.map → transformers-C481fXH-.js.map} +1 -1
  28. package/dist/transformers.cjs +2 -2
  29. package/dist/transformers.js +1 -1
  30. package/dist/{types-DgfEZ3IN.d.ts → types-DZARm27h.d.ts} +253 -46
  31. package/dist/{types-CCEy_FVr.d.cts → types-icDNKrIP.d.cts} +253 -46
  32. package/dist/utils.cjs +6 -5
  33. package/dist/utils.d.cts +3 -3
  34. package/dist/utils.d.ts +3 -3
  35. package/dist/utils.js +3 -3
  36. package/package.json +10 -17
  37. package/src/BarrelManager.ts +3 -18
  38. package/src/Kubb.ts +249 -0
  39. package/src/PluginManager.ts +42 -73
  40. package/src/build.ts +38 -138
  41. package/src/defineLogger.ts +7 -0
  42. package/src/index.ts +2 -1
  43. package/src/types.ts +35 -2
  44. package/src/utils/getBarrelFiles.ts +7 -10
  45. package/src/utils/index.ts +1 -0
  46. package/dist/EventEmitter-BwU6Ixxt.cjs +0 -31
  47. package/dist/EventEmitter-BwU6Ixxt.cjs.map +0 -1
  48. package/dist/EventEmitter-DlzW04T3.js +0 -25
  49. package/dist/EventEmitter-DlzW04T3.js.map +0 -1
  50. package/dist/chunk-CbDLau6x.cjs +0 -34
  51. package/dist/getBarrelFiles-8VEWWk9Z.cjs.map +0 -1
  52. package/dist/getBarrelFiles-DQ0hksqD.js.map +0 -1
  53. package/dist/logger-CQn6sdC0.js +0 -1152
  54. package/dist/logger-CQn6sdC0.js.map +0 -1
  55. package/dist/logger-US5g7KdM.cjs +0 -1187
  56. package/dist/logger-US5g7KdM.cjs.map +0 -1
  57. package/dist/logger-mq06Cxxv.d.cts +0 -94
  58. package/dist/logger-o16AyvGp.d.ts +0 -94
  59. package/dist/logger.cjs +0 -6
  60. package/dist/logger.d.cts +0 -2
  61. package/dist/logger.d.ts +0 -2
  62. package/dist/logger.js +0 -3
  63. package/dist/prompt-CWSscQpj.cjs +0 -852
  64. package/dist/prompt-CWSscQpj.cjs.map +0 -1
  65. package/dist/prompt-Dt0jyRBe.js +0 -848
  66. package/dist/prompt-Dt0jyRBe.js.map +0 -1
  67. package/src/logger.ts +0 -236
  68. package/src/utils/ciDetection.ts +0 -40
package/dist/index.cjs CHANGED
@@ -1,29 +1,23 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- const require_chunk = require('./chunk-CbDLau6x.cjs');
3
- const require_getBarrelFiles = require('./getBarrelFiles-8VEWWk9Z.cjs');
4
- const require_logger = require('./logger-US5g7KdM.cjs');
5
- require('./transformers-B-zCAPV-.cjs');
2
+ const require_fs = require('./fs-DhLl4-lT.cjs');
3
+ const require_getBarrelFiles = require('./getBarrelFiles-BcgToi50.cjs');
4
+ require('./transformers-BqQRkrxy.cjs');
6
5
  let node_path = require("node:path");
7
- node_path = require_chunk.__toESM(node_path);
6
+ node_path = require_fs.__toESM(node_path);
8
7
  let node_perf_hooks = require("node:perf_hooks");
9
8
  let __kubb_react_fabric = require("@kubb/react-fabric");
10
9
  let __kubb_react_fabric_parsers = require("@kubb/react-fabric/parsers");
11
10
  let __kubb_react_fabric_plugins = require("@kubb/react-fabric/plugins");
12
- let picocolors = require("picocolors");
13
- picocolors = require_chunk.__toESM(picocolors);
14
11
  let remeda = require("remeda");
15
- let fs_extra = require("fs-extra");
16
- fs_extra = require_chunk.__toESM(fs_extra);
17
- let js_runtime = require("js-runtime");
18
12
  let node_process = require("node:process");
19
- node_process = require_chunk.__toESM(node_process);
13
+ node_process = require_fs.__toESM(node_process);
20
14
  let node_module = require("node:module");
21
- node_module = require_chunk.__toESM(node_module);
15
+ node_module = require_fs.__toESM(node_module);
22
16
  let node_os = require("node:os");
23
- node_os = require_chunk.__toESM(node_os);
17
+ node_os = require_fs.__toESM(node_os);
24
18
  let node_url = require("node:url");
25
19
  let node_fs = require("node:fs");
26
- node_fs = require_chunk.__toESM(node_fs);
20
+ node_fs = require_fs.__toESM(node_fs);
27
21
  let semver = require("semver");
28
22
 
29
23
  //#region src/BaseGenerator.ts
@@ -79,62 +73,9 @@ function isInputPath(config) {
79
73
  return typeof config?.input === "object" && config.input !== null && "path" in config.input;
80
74
  }
81
75
 
82
- //#endregion
83
- //#region src/fs/clean.ts
84
- async function clean(path$2) {
85
- return fs_extra.default.remove(path$2);
86
- }
87
-
88
- //#endregion
89
- //#region src/fs/exists.ts
90
- const reader$1 = (0, js_runtime.switcher)({
91
- node: async (path$2) => {
92
- return fs_extra.default.pathExists(path$2);
93
- },
94
- bun: async (path$2) => {
95
- return Bun.file(path$2).exists();
96
- }
97
- }, "node");
98
- const syncReader$1 = (0, js_runtime.switcher)({
99
- node: (path$2) => {
100
- return fs_extra.default.pathExistsSync(path$2);
101
- },
102
- bun: () => {
103
- throw new Error("Bun cannot read sync");
104
- }
105
- }, "node");
106
- async function exists(path$2) {
107
- return reader$1(path$2);
108
- }
109
-
110
- //#endregion
111
- //#region src/fs/read.ts
112
- const reader = (0, js_runtime.switcher)({
113
- node: async (path$2) => {
114
- return fs_extra.default.readFile(path$2, { encoding: "utf8" });
115
- },
116
- bun: async (path$2) => {
117
- return Bun.file(path$2).text();
118
- }
119
- }, "node");
120
- const syncReader = (0, js_runtime.switcher)({
121
- node: (path$2) => {
122
- return fs_extra.default.readFileSync(path$2, { encoding: "utf8" });
123
- },
124
- bun: () => {
125
- throw new Error("Bun cannot read sync");
126
- }
127
- }, "node");
128
- async function read(path$2) {
129
- return reader(path$2);
130
- }
131
- function readSync(path$2) {
132
- return syncReader(path$2);
133
- }
134
-
135
76
  //#endregion
136
77
  //#region package.json
137
- var version = "4.11.3";
78
+ var version = "4.12.1";
138
79
 
139
80
  //#endregion
140
81
  //#region src/utils/diagnostics.ts
@@ -154,12 +95,11 @@ function getDiagnosticInfo() {
154
95
  //#endregion
155
96
  //#region src/build.ts
156
97
  async function setup(options) {
157
- const { config: userConfig, logger = require_logger.createLogger() } = options;
98
+ const { config: userConfig, events = new require_getBarrelFiles.AsyncEventEmitter() } = options;
158
99
  const diagnosticInfo = getDiagnosticInfo();
159
- if (Array.isArray(userConfig.input)) console.warn(picocolors.default.yellow("This feature is still under development — use with caution"));
160
- logger.emit("debug", {
100
+ if (Array.isArray(userConfig.input)) await events.emit("warn", "This feature is still under development — use with caution");
101
+ await events.emit("debug", {
161
102
  date: /* @__PURE__ */ new Date(),
162
- category: "setup",
163
103
  logs: [
164
104
  "Configuration:",
165
105
  ` • Name: ${userConfig.name || "unnamed"}`,
@@ -176,10 +116,9 @@ async function setup(options) {
176
116
  });
177
117
  try {
178
118
  if (isInputPath(userConfig) && !new require_getBarrelFiles.URLPath(userConfig.input.path).isURL) {
179
- await exists(userConfig.input.path);
180
- logger.emit("debug", {
119
+ await require_fs.exists(userConfig.input.path);
120
+ await events.emit("debug", {
181
121
  date: /* @__PURE__ */ new Date(),
182
- category: "setup",
183
122
  logs: [`✓ Input file validated: ${userConfig.input.path}`]
184
123
  });
185
124
  }
@@ -202,138 +141,59 @@ async function setup(options) {
202
141
  plugins: userConfig.plugins
203
142
  };
204
143
  if (definedConfig.output.clean) {
205
- logger.emit("debug", {
144
+ await events.emit("debug", {
206
145
  date: /* @__PURE__ */ new Date(),
207
- category: "setup",
208
146
  logs: [
209
147
  "Cleaning output directories",
210
148
  ` • Output: ${definedConfig.output.path}`,
211
149
  " • Cache: .kubb"
212
150
  ]
213
151
  });
214
- await clean(definedConfig.output.path);
215
- await clean((0, node_path.join)(definedConfig.root, ".kubb"));
152
+ await require_fs.clean(definedConfig.output.path);
153
+ await require_fs.clean((0, node_path.join)(definedConfig.root, ".kubb"));
216
154
  }
217
155
  const fabric = (0, __kubb_react_fabric.createFabric)();
218
156
  fabric.use(__kubb_react_fabric_plugins.fsPlugin, { dryRun: !definedConfig.output.write });
219
157
  fabric.use(__kubb_react_fabric_parsers.typescriptParser);
220
- fabric.context.on("process:start", ({ files }) => {
221
- logger.emit("progress_start", {
222
- id: "files",
223
- size: files.length,
224
- message: "Writing files ..."
225
- });
226
- logger.emit("debug", {
158
+ fabric.context.on("files:processing:start", (files) => {
159
+ events.emit("files:processing:start", files);
160
+ events.emit("debug", {
227
161
  date: /* @__PURE__ */ new Date(),
228
- category: "file",
229
162
  logs: [`Writing ${files.length} files...`]
230
163
  });
231
164
  });
232
- fabric.context.on("process:progress", async ({ file, source }) => {
233
- const message = file ? `Writing ${(0, node_path.relative)(definedConfig.root, file.path)}` : "";
234
- logger.emit("progressed", {
235
- id: "files",
236
- message
165
+ fabric.context.on("file:processing:update", async (params) => {
166
+ const { file, source } = params;
167
+ await events.emit("file:processing:update", {
168
+ ...params,
169
+ config: definedConfig,
170
+ source
237
171
  });
238
- if (source) await require_logger.write(file.path, source, { sanity: false });
172
+ if (source) await require_fs.write(file.path, source, { sanity: false });
239
173
  });
240
- fabric.context.on("process:end", () => {
241
- logger.emit("progress_stop", { id: "files" });
242
- logger.emit("debug", {
174
+ fabric.context.on("files:processing:end", async (files) => {
175
+ await events.emit("files:processing:end", files);
176
+ await events.emit("debug", {
243
177
  date: /* @__PURE__ */ new Date(),
244
- category: "file",
245
178
  logs: ["✓ File write process completed"]
246
179
  });
247
180
  });
248
- logger.emit("debug", {
181
+ await events.emit("debug", {
249
182
  date: /* @__PURE__ */ new Date(),
250
- category: "setup",
251
183
  logs: [
252
184
  "✓ Fabric initialized",
253
185
  ` • File writing: ${definedConfig.output.write ? "enabled" : "disabled (dry-run)"}`,
254
186
  ` • Barrel type: ${definedConfig.output.barrelType || "none"}`
255
187
  ]
256
188
  });
257
- const pluginManager = new require_getBarrelFiles.PluginManager(definedConfig, {
258
- fabric,
259
- logger,
260
- concurrency: 5
261
- });
262
- pluginManager.on("executing", ({ plugin, hookName, strategy, parameters }) => {
263
- logger.emit("debug", {
264
- date: /* @__PURE__ */ new Date(),
265
- category: "hook",
266
- pluginName: plugin.name,
267
- logs: [
268
- `Executing hook: ${hookName}`,
269
- ` • Strategy: ${strategy}`,
270
- " • Parameters:",
271
- JSON.stringify(parameters, null, 2)
272
- ]
273
- });
274
- });
275
- pluginManager.on("executed", ({ plugin, hookName, duration, parameters }) => {
276
- let message = "";
277
- if (hookName === "resolvePath") {
278
- const [path$2] = parameters || [];
279
- message = `Resolving path '${path$2}'`;
280
- }
281
- if (hookName === "resolveName") {
282
- const [name, type] = parameters || [];
283
- message = `Resolving name '${name}' and type '${type}'`;
284
- }
285
- logger.emit("progressed", {
286
- id: hookName,
287
- message: `${plugin.name}: ${message}`
288
- });
289
- logger.emit("debug", {
290
- date: /* @__PURE__ */ new Date(),
291
- category: "hook",
292
- pluginName: plugin.name,
293
- logs: [`✓ Completed in ${duration}ms`]
294
- });
295
- });
296
- pluginManager.on("progress_start", ({ hookName, plugins }) => {
297
- logger.emit("progress_start", {
298
- id: hookName,
299
- size: plugins.length,
300
- message: "Running plugins..."
301
- });
302
- });
303
- pluginManager.on("progress_stop", ({ hookName }) => {
304
- logger.emit("progress_stop", { id: hookName });
305
- });
306
- pluginManager.on("error", (error, { plugin, strategy, duration, parameters, hookName }) => {
307
- const text = `${error.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
308
- logger.emit("error", text, error);
309
- logger.emit("debug", {
310
- date: /* @__PURE__ */ new Date(),
311
- category: "error",
312
- pluginName: plugin.name,
313
- logs: [
314
- `✗ Hook '${hookName}' failed after ${duration}ms`,
315
- ` • Strategy: ${strategy}`,
316
- ` • Error: ${error.constructor.name} - ${error.message}`,
317
- " • Stack Trace:",
318
- error.stack || "No stack trace available",
319
- " • Parameters:",
320
- JSON.stringify(parameters, null, 2)
321
- ]
322
- });
323
- });
324
- logger.emit("debug", {
325
- date: /* @__PURE__ */ new Date(),
326
- category: "setup",
327
- logs: [
328
- "✓ PluginManager initialized",
329
- " • Concurrency: 5",
330
- ` • Total plugins: ${pluginManager.plugins.length}`
331
- ]
332
- });
333
189
  return {
334
- logger,
190
+ events,
335
191
  fabric,
336
- pluginManager
192
+ pluginManager: new require_getBarrelFiles.PluginManager(definedConfig, {
193
+ fabric,
194
+ events,
195
+ concurrency: 5
196
+ })
337
197
  };
338
198
  }
339
199
  async function build(options, overrides) {
@@ -349,7 +209,7 @@ async function build(options, overrides) {
349
209
  };
350
210
  }
351
211
  async function safeBuild(options, overrides) {
352
- const { fabric, pluginManager, logger } = overrides ? overrides : await setup(options);
212
+ const { fabric, pluginManager, events } = overrides ? overrides : await setup(options);
353
213
  const failedPlugins = /* @__PURE__ */ new Set();
354
214
  const pluginTimings = /* @__PURE__ */ new Map();
355
215
  const config = pluginManager.config;
@@ -360,40 +220,24 @@ async function safeBuild(options, overrides) {
360
220
  try {
361
221
  const startTime = node_perf_hooks.performance.now();
362
222
  const timestamp = /* @__PURE__ */ new Date();
363
- logger.emit("debug", {
364
- date: timestamp,
365
- pluginGroupMarker: "start",
366
- pluginName: plugin.name,
367
- logs: []
368
- });
369
- logger.emit("debug", {
223
+ await events.emit("plugin:start", plugin);
224
+ await events.emit("debug", {
370
225
  date: timestamp,
371
- category: "plugin",
372
- pluginName: plugin.name,
373
226
  logs: ["Installing plugin...", ` • Plugin Key: ${JSON.stringify(plugin.key)}`]
374
227
  });
375
228
  await installer(context);
376
229
  const duration = Math.round(node_perf_hooks.performance.now() - startTime);
377
230
  pluginTimings.set(plugin.name, duration);
378
- logger.emit("debug", {
231
+ await events.emit("plugin:end", plugin, duration);
232
+ await events.emit("debug", {
379
233
  date: /* @__PURE__ */ new Date(),
380
- category: "plugin",
381
- pluginName: plugin.name,
382
234
  logs: [`✓ Plugin installed successfully (${duration}ms)`]
383
235
  });
384
- logger.emit("debug", {
385
- date: /* @__PURE__ */ new Date(),
386
- pluginGroupMarker: "end",
387
- pluginName: plugin.name,
388
- logs: []
389
- });
390
236
  } catch (e) {
391
237
  const error = e;
392
238
  const errorTimestamp = /* @__PURE__ */ new Date();
393
- logger.emit("debug", {
239
+ await events.emit("debug", {
394
240
  date: errorTimestamp,
395
- category: "error",
396
- pluginName: plugin.name,
397
241
  logs: [
398
242
  "✗ Plugin installation failed",
399
243
  ` • Plugin Key: ${JSON.stringify(plugin.key)}`,
@@ -402,12 +246,6 @@ async function safeBuild(options, overrides) {
402
246
  error.stack || "No stack trace available"
403
247
  ]
404
248
  });
405
- logger.emit("debug", {
406
- date: errorTimestamp,
407
- pluginGroupMarker: "end",
408
- pluginName: plugin.name,
409
- logs: []
410
- });
411
249
  failedPlugins.add({
412
250
  plugin,
413
251
  error
@@ -416,7 +254,7 @@ async function safeBuild(options, overrides) {
416
254
  }
417
255
  if (config.output.barrelType) {
418
256
  const rootPath = (0, node_path.resolve)((0, node_path.resolve)(config.root), config.output.path, "index.ts");
419
- logger.emit("debug", {
257
+ await events.emit("debug", {
420
258
  date: /* @__PURE__ */ new Date(),
421
259
  logs: [
422
260
  "Generating barrel file",
@@ -427,7 +265,7 @@ async function safeBuild(options, overrides) {
427
265
  const barrelFiles = fabric.files.filter((file) => {
428
266
  return file.sources.some((source) => source.isIndexable);
429
267
  });
430
- logger.emit("debug", {
268
+ await events.emit("debug", {
431
269
  date: /* @__PURE__ */ new Date(),
432
270
  logs: [`Found ${barrelFiles.length} indexable files for barrel export`]
433
271
  });
@@ -445,7 +283,7 @@ async function safeBuild(options, overrides) {
445
283
  if (!pluginOptions || pluginOptions?.output?.barrelType === false) return;
446
284
  return {
447
285
  name: config.output.barrelType === "all" ? void 0 : [source.name],
448
- path: require_getBarrelFiles.getRelativePath(rootPath, file.path),
286
+ path: require_fs.getRelativePath(rootPath, file.path),
449
287
  isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
450
288
  };
451
289
  }).filter(Boolean);
@@ -454,9 +292,8 @@ async function safeBuild(options, overrides) {
454
292
  meta: {}
455
293
  };
456
294
  await fabric.upsertFile(rootFile);
457
- logger.emit("debug", {
295
+ await events.emit("debug", {
458
296
  date: /* @__PURE__ */ new Date(),
459
- category: "file",
460
297
  logs: [`✓ Generated barrel file (${rootFile.exports?.length || 0} exports)`]
461
298
  });
462
299
  }
@@ -481,6 +318,12 @@ async function safeBuild(options, overrides) {
481
318
  }
482
319
  }
483
320
 
321
+ //#endregion
322
+ //#region src/defineLogger.ts
323
+ function defineLogger(logger) {
324
+ return { ...logger };
325
+ }
326
+
484
327
  //#endregion
485
328
  //#region src/definePlugin.ts
486
329
  /**
@@ -704,13 +547,13 @@ var PackageManager = class PackageManager {
704
547
  async getPackageJSON() {
705
548
  const pkgPath = await findUp(["package.json"], { cwd: this.#cwd });
706
549
  if (!pkgPath) return;
707
- const json = await read(pkgPath);
550
+ const json = await require_fs.read(pkgPath);
708
551
  return JSON.parse(json);
709
552
  }
710
553
  getPackageJSONSync() {
711
554
  const pkgPath = findUpSync(["package.json"], { cwd: this.#cwd });
712
555
  if (!pkgPath) return;
713
- const json = readSync(pkgPath);
556
+ const json = require_fs.readSync(pkgPath);
714
557
  return JSON.parse(json);
715
558
  }
716
559
  static setVersion(dependency, version$1) {
@@ -755,14 +598,27 @@ var PackageManager = class PackageManager {
755
598
  }
756
599
  };
757
600
 
601
+ //#endregion
602
+ //#region src/types.ts
603
+ const LogLevel = {
604
+ silent: Number.NEGATIVE_INFINITY,
605
+ error: 0,
606
+ warn: 1,
607
+ info: 3,
608
+ verbose: 4,
609
+ debug: 5
610
+ };
611
+
758
612
  //#endregion
759
613
  exports.BaseGenerator = BaseGenerator;
614
+ exports.LogLevel = LogLevel;
760
615
  exports.PackageManager = PackageManager;
761
616
  exports.PluginManager = require_getBarrelFiles.PluginManager;
762
617
  exports.PromiseManager = require_getBarrelFiles.PromiseManager;
763
618
  exports.build = build;
764
619
  exports.default = build;
765
620
  exports.defineConfig = defineConfig;
621
+ exports.defineLogger = defineLogger;
766
622
  exports.definePlugin = definePlugin;
767
623
  exports.getBarrelFiles = require_getBarrelFiles.getBarrelFiles;
768
624
  exports.getMode = require_getBarrelFiles.getMode;