@kubb/core 4.11.3 → 4.12.0

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.js CHANGED
@@ -1,20 +1,17 @@
1
- import { c as Queue, i as getMode, l as getRelativePath, n as URLPath, r as PluginManager, s as PromiseManager, t as getBarrelFiles } from "./getBarrelFiles-DQ0hksqD.js";
2
- import { a as write, n as createLogger } from "./logger-CQn6sdC0.js";
3
- import "./transformers-CjdbeLAK.js";
1
+ import { a as exists, i as readSync, n as getRelativePath, o as clean, r as read, t as write } from "./fs-ph1OdgEr.js";
2
+ import { a as getMode, c as PromiseManager, i as PluginManager, l as Queue, n as URLPath, r as AsyncEventEmitter, t as getBarrelFiles } from "./getBarrelFiles-ClyWjO0d.js";
3
+ import "./transformers-C481fXH-.js";
4
4
  import mod from "node:module";
5
- import path, { join, relative, resolve } from "node:path";
5
+ import path, { join, resolve } from "node:path";
6
6
  import { performance } from "node:perf_hooks";
7
7
  import { createFabric } from "@kubb/react-fabric";
8
8
  import { typescriptParser } from "@kubb/react-fabric/parsers";
9
9
  import { fsPlugin } from "@kubb/react-fabric/plugins";
10
- import pc from "picocolors";
11
10
  import { isDeepEqual } from "remeda";
12
- import fs from "fs-extra";
13
- import { switcher } from "js-runtime";
14
- import g$1, { version } from "node:process";
11
+ import process$1, { version } from "node:process";
15
12
  import os from "node:os";
16
13
  import { fileURLToPath, pathToFileURL } from "node:url";
17
- import fs$1, { promises } from "node:fs";
14
+ import fs, { promises } from "node:fs";
18
15
  import { coerce, satisfies } from "semver";
19
16
 
20
17
  //#region src/BaseGenerator.ts
@@ -70,62 +67,9 @@ function isInputPath(config) {
70
67
  return typeof config?.input === "object" && config.input !== null && "path" in config.input;
71
68
  }
72
69
 
73
- //#endregion
74
- //#region src/fs/clean.ts
75
- async function clean(path$1) {
76
- return fs.remove(path$1);
77
- }
78
-
79
- //#endregion
80
- //#region src/fs/exists.ts
81
- const reader$1 = switcher({
82
- node: async (path$1) => {
83
- return fs.pathExists(path$1);
84
- },
85
- bun: async (path$1) => {
86
- return Bun.file(path$1).exists();
87
- }
88
- }, "node");
89
- const syncReader$1 = switcher({
90
- node: (path$1) => {
91
- return fs.pathExistsSync(path$1);
92
- },
93
- bun: () => {
94
- throw new Error("Bun cannot read sync");
95
- }
96
- }, "node");
97
- async function exists(path$1) {
98
- return reader$1(path$1);
99
- }
100
-
101
- //#endregion
102
- //#region src/fs/read.ts
103
- const reader = switcher({
104
- node: async (path$1) => {
105
- return fs.readFile(path$1, { encoding: "utf8" });
106
- },
107
- bun: async (path$1) => {
108
- return Bun.file(path$1).text();
109
- }
110
- }, "node");
111
- const syncReader = switcher({
112
- node: (path$1) => {
113
- return fs.readFileSync(path$1, { encoding: "utf8" });
114
- },
115
- bun: () => {
116
- throw new Error("Bun cannot read sync");
117
- }
118
- }, "node");
119
- async function read(path$1) {
120
- return reader(path$1);
121
- }
122
- function readSync(path$1) {
123
- return syncReader(path$1);
124
- }
125
-
126
70
  //#endregion
127
71
  //#region package.json
128
- var version$1 = "4.11.3";
72
+ var version$1 = "4.12.0";
129
73
 
130
74
  //#endregion
131
75
  //#region src/utils/diagnostics.ts
@@ -145,12 +89,11 @@ function getDiagnosticInfo() {
145
89
  //#endregion
146
90
  //#region src/build.ts
147
91
  async function setup(options) {
148
- const { config: userConfig, logger = createLogger() } = options;
92
+ const { config: userConfig, events = new AsyncEventEmitter() } = options;
149
93
  const diagnosticInfo = getDiagnosticInfo();
150
- if (Array.isArray(userConfig.input)) console.warn(pc.yellow("This feature is still under development — use with caution"));
151
- logger.emit("debug", {
94
+ if (Array.isArray(userConfig.input)) await events.emit("warn", "This feature is still under development — use with caution");
95
+ await events.emit("debug", {
152
96
  date: /* @__PURE__ */ new Date(),
153
- category: "setup",
154
97
  logs: [
155
98
  "Configuration:",
156
99
  ` • Name: ${userConfig.name || "unnamed"}`,
@@ -168,9 +111,8 @@ async function setup(options) {
168
111
  try {
169
112
  if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) {
170
113
  await exists(userConfig.input.path);
171
- logger.emit("debug", {
114
+ await events.emit("debug", {
172
115
  date: /* @__PURE__ */ new Date(),
173
- category: "setup",
174
116
  logs: [`✓ Input file validated: ${userConfig.input.path}`]
175
117
  });
176
118
  }
@@ -193,9 +135,8 @@ async function setup(options) {
193
135
  plugins: userConfig.plugins
194
136
  };
195
137
  if (definedConfig.output.clean) {
196
- logger.emit("debug", {
138
+ await events.emit("debug", {
197
139
  date: /* @__PURE__ */ new Date(),
198
- category: "setup",
199
140
  logs: [
200
141
  "Cleaning output directories",
201
142
  ` • Output: ${definedConfig.output.path}`,
@@ -208,123 +149,45 @@ async function setup(options) {
208
149
  const fabric = createFabric();
209
150
  fabric.use(fsPlugin, { dryRun: !definedConfig.output.write });
210
151
  fabric.use(typescriptParser);
211
- fabric.context.on("process:start", ({ files }) => {
212
- logger.emit("progress_start", {
213
- id: "files",
214
- size: files.length,
215
- message: "Writing files ..."
216
- });
217
- logger.emit("debug", {
152
+ fabric.context.on("files:processing:start", (files) => {
153
+ events.emit("files:processing:start", files);
154
+ events.emit("debug", {
218
155
  date: /* @__PURE__ */ new Date(),
219
- category: "file",
220
156
  logs: [`Writing ${files.length} files...`]
221
157
  });
222
158
  });
223
- fabric.context.on("process:progress", async ({ file, source }) => {
224
- const message = file ? `Writing ${relative(definedConfig.root, file.path)}` : "";
225
- logger.emit("progressed", {
226
- id: "files",
227
- message
159
+ fabric.context.on("file:processing:update", async (params) => {
160
+ const { file, source } = params;
161
+ await events.emit("file:processing:update", {
162
+ ...params,
163
+ config: definedConfig,
164
+ source
228
165
  });
229
166
  if (source) await write(file.path, source, { sanity: false });
230
167
  });
231
- fabric.context.on("process:end", () => {
232
- logger.emit("progress_stop", { id: "files" });
233
- logger.emit("debug", {
168
+ fabric.context.on("files:processing:end", async (files) => {
169
+ await events.emit("files:processing:end", files);
170
+ await events.emit("debug", {
234
171
  date: /* @__PURE__ */ new Date(),
235
- category: "file",
236
172
  logs: ["✓ File write process completed"]
237
173
  });
238
174
  });
239
- logger.emit("debug", {
175
+ await events.emit("debug", {
240
176
  date: /* @__PURE__ */ new Date(),
241
- category: "setup",
242
177
  logs: [
243
178
  "✓ Fabric initialized",
244
179
  ` • File writing: ${definedConfig.output.write ? "enabled" : "disabled (dry-run)"}`,
245
180
  ` • Barrel type: ${definedConfig.output.barrelType || "none"}`
246
181
  ]
247
182
  });
248
- const pluginManager = new PluginManager(definedConfig, {
249
- fabric,
250
- logger,
251
- concurrency: 5
252
- });
253
- pluginManager.on("executing", ({ plugin, hookName, strategy, parameters }) => {
254
- logger.emit("debug", {
255
- date: /* @__PURE__ */ new Date(),
256
- category: "hook",
257
- pluginName: plugin.name,
258
- logs: [
259
- `Executing hook: ${hookName}`,
260
- ` • Strategy: ${strategy}`,
261
- " • Parameters:",
262
- JSON.stringify(parameters, null, 2)
263
- ]
264
- });
265
- });
266
- pluginManager.on("executed", ({ plugin, hookName, duration, parameters }) => {
267
- let message = "";
268
- if (hookName === "resolvePath") {
269
- const [path$1] = parameters || [];
270
- message = `Resolving path '${path$1}'`;
271
- }
272
- if (hookName === "resolveName") {
273
- const [name, type] = parameters || [];
274
- message = `Resolving name '${name}' and type '${type}'`;
275
- }
276
- logger.emit("progressed", {
277
- id: hookName,
278
- message: `${plugin.name}: ${message}`
279
- });
280
- logger.emit("debug", {
281
- date: /* @__PURE__ */ new Date(),
282
- category: "hook",
283
- pluginName: plugin.name,
284
- logs: [`✓ Completed in ${duration}ms`]
285
- });
286
- });
287
- pluginManager.on("progress_start", ({ hookName, plugins }) => {
288
- logger.emit("progress_start", {
289
- id: hookName,
290
- size: plugins.length,
291
- message: "Running plugins..."
292
- });
293
- });
294
- pluginManager.on("progress_stop", ({ hookName }) => {
295
- logger.emit("progress_stop", { id: hookName });
296
- });
297
- pluginManager.on("error", (error, { plugin, strategy, duration, parameters, hookName }) => {
298
- const text = `${error.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
299
- logger.emit("error", text, error);
300
- logger.emit("debug", {
301
- date: /* @__PURE__ */ new Date(),
302
- category: "error",
303
- pluginName: plugin.name,
304
- logs: [
305
- `✗ Hook '${hookName}' failed after ${duration}ms`,
306
- ` • Strategy: ${strategy}`,
307
- ` • Error: ${error.constructor.name} - ${error.message}`,
308
- " • Stack Trace:",
309
- error.stack || "No stack trace available",
310
- " • Parameters:",
311
- JSON.stringify(parameters, null, 2)
312
- ]
313
- });
314
- });
315
- logger.emit("debug", {
316
- date: /* @__PURE__ */ new Date(),
317
- category: "setup",
318
- logs: [
319
- "✓ PluginManager initialized",
320
- " • Concurrency: 5",
321
- ` • Total plugins: ${pluginManager.plugins.length}`
322
- ]
323
- });
324
183
  return {
325
- logger,
184
+ events,
326
185
  fabric,
327
- pluginManager
186
+ pluginManager: new PluginManager(definedConfig, {
187
+ fabric,
188
+ events,
189
+ concurrency: 5
190
+ })
328
191
  };
329
192
  }
330
193
  async function build(options, overrides) {
@@ -340,7 +203,7 @@ async function build(options, overrides) {
340
203
  };
341
204
  }
342
205
  async function safeBuild(options, overrides) {
343
- const { fabric, pluginManager, logger } = overrides ? overrides : await setup(options);
206
+ const { fabric, pluginManager, events } = overrides ? overrides : await setup(options);
344
207
  const failedPlugins = /* @__PURE__ */ new Set();
345
208
  const pluginTimings = /* @__PURE__ */ new Map();
346
209
  const config = pluginManager.config;
@@ -351,40 +214,24 @@ async function safeBuild(options, overrides) {
351
214
  try {
352
215
  const startTime = performance.now();
353
216
  const timestamp = /* @__PURE__ */ new Date();
354
- logger.emit("debug", {
355
- date: timestamp,
356
- pluginGroupMarker: "start",
357
- pluginName: plugin.name,
358
- logs: []
359
- });
360
- logger.emit("debug", {
217
+ await events.emit("plugin:start", plugin);
218
+ await events.emit("debug", {
361
219
  date: timestamp,
362
- category: "plugin",
363
- pluginName: plugin.name,
364
220
  logs: ["Installing plugin...", ` • Plugin Key: ${JSON.stringify(plugin.key)}`]
365
221
  });
366
222
  await installer(context);
367
223
  const duration = Math.round(performance.now() - startTime);
368
224
  pluginTimings.set(plugin.name, duration);
369
- logger.emit("debug", {
225
+ await events.emit("plugin:end", plugin, duration);
226
+ await events.emit("debug", {
370
227
  date: /* @__PURE__ */ new Date(),
371
- category: "plugin",
372
- pluginName: plugin.name,
373
228
  logs: [`✓ Plugin installed successfully (${duration}ms)`]
374
229
  });
375
- logger.emit("debug", {
376
- date: /* @__PURE__ */ new Date(),
377
- pluginGroupMarker: "end",
378
- pluginName: plugin.name,
379
- logs: []
380
- });
381
230
  } catch (e) {
382
231
  const error = e;
383
232
  const errorTimestamp = /* @__PURE__ */ new Date();
384
- logger.emit("debug", {
233
+ await events.emit("debug", {
385
234
  date: errorTimestamp,
386
- category: "error",
387
- pluginName: plugin.name,
388
235
  logs: [
389
236
  "✗ Plugin installation failed",
390
237
  ` • Plugin Key: ${JSON.stringify(plugin.key)}`,
@@ -393,12 +240,6 @@ async function safeBuild(options, overrides) {
393
240
  error.stack || "No stack trace available"
394
241
  ]
395
242
  });
396
- logger.emit("debug", {
397
- date: errorTimestamp,
398
- pluginGroupMarker: "end",
399
- pluginName: plugin.name,
400
- logs: []
401
- });
402
243
  failedPlugins.add({
403
244
  plugin,
404
245
  error
@@ -407,7 +248,7 @@ async function safeBuild(options, overrides) {
407
248
  }
408
249
  if (config.output.barrelType) {
409
250
  const rootPath = resolve(resolve(config.root), config.output.path, "index.ts");
410
- logger.emit("debug", {
251
+ await events.emit("debug", {
411
252
  date: /* @__PURE__ */ new Date(),
412
253
  logs: [
413
254
  "Generating barrel file",
@@ -418,7 +259,7 @@ async function safeBuild(options, overrides) {
418
259
  const barrelFiles = fabric.files.filter((file) => {
419
260
  return file.sources.some((source) => source.isIndexable);
420
261
  });
421
- logger.emit("debug", {
262
+ await events.emit("debug", {
422
263
  date: /* @__PURE__ */ new Date(),
423
264
  logs: [`Found ${barrelFiles.length} indexable files for barrel export`]
424
265
  });
@@ -445,9 +286,8 @@ async function safeBuild(options, overrides) {
445
286
  meta: {}
446
287
  };
447
288
  await fabric.upsertFile(rootFile);
448
- logger.emit("debug", {
289
+ await events.emit("debug", {
449
290
  date: /* @__PURE__ */ new Date(),
450
- category: "file",
451
291
  logs: [`✓ Generated barrel file (${rootFile.exports?.length || 0} exports)`]
452
292
  });
453
293
  }
@@ -472,6 +312,12 @@ async function safeBuild(options, overrides) {
472
312
  }
473
313
  }
474
314
 
315
+ //#endregion
316
+ //#region src/defineLogger.ts
317
+ function defineLogger(logger) {
318
+ return { ...logger };
319
+ }
320
+
475
321
  //#endregion
476
322
  //#region src/definePlugin.ts
477
323
  /**
@@ -558,7 +404,7 @@ function checkType(type) {
558
404
  }
559
405
  const matchType = (type, stat) => stat[typeMappings[type]]();
560
406
  const toPath$1 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
561
- async function locatePath(paths, { cwd = g$1.cwd(), type = "file", allowSymlinks = true, concurrency, preserveOrder } = {}) {
407
+ async function locatePath(paths, { cwd = process$1.cwd(), type = "file", allowSymlinks = true, concurrency, preserveOrder } = {}) {
562
408
  checkType(type);
563
409
  cwd = toPath$1(cwd);
564
410
  const statFunction = allowSymlinks ? promises.stat : promises.lstat;
@@ -573,10 +419,10 @@ async function locatePath(paths, { cwd = g$1.cwd(), type = "file", allowSymlinks
573
419
  preserveOrder
574
420
  });
575
421
  }
576
- function locatePathSync(paths, { cwd = g$1.cwd(), type = "file", allowSymlinks = true } = {}) {
422
+ function locatePathSync(paths, { cwd = process$1.cwd(), type = "file", allowSymlinks = true } = {}) {
577
423
  checkType(type);
578
424
  cwd = toPath$1(cwd);
579
- const statFunction = allowSymlinks ? fs$1.statSync : fs$1.lstatSync;
425
+ const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
580
426
  for (const path_ of paths) try {
581
427
  const stat = statFunction(path.resolve(cwd, path_), { throwIfNoEntry: false });
582
428
  if (!stat) continue;
@@ -747,5 +593,16 @@ var PackageManager = class PackageManager {
747
593
  };
748
594
 
749
595
  //#endregion
750
- export { BaseGenerator, PackageManager, PluginManager, PromiseManager, build, build as default, defineConfig, definePlugin, getBarrelFiles, getMode, isInputPath, safeBuild, setup };
596
+ //#region src/types.ts
597
+ const LogLevel = {
598
+ silent: Number.NEGATIVE_INFINITY,
599
+ error: 0,
600
+ warn: 1,
601
+ info: 3,
602
+ verbose: 4,
603
+ debug: 5
604
+ };
605
+
606
+ //#endregion
607
+ export { BaseGenerator, LogLevel, PackageManager, PluginManager, PromiseManager, build, build as default, defineConfig, defineLogger, definePlugin, getBarrelFiles, getMode, isInputPath, safeBuild, setup };
751
608
  //# sourceMappingURL=index.js.map