@kubb/fabric-core 0.2.16 → 0.2.17

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 (33) hide show
  1. package/dist/{Fabric-CBrTERuf.d.cts → Fabric-BezqNTQ9.d.cts} +12 -7
  2. package/dist/{Fabric-AmREkq58.d.ts → Fabric-CVe8cc8b.d.ts} +12 -7
  3. package/dist/{defineProperty-Dlhh3lSJ.cjs → defineProperty-DZi5DvrW.cjs} +13 -1
  4. package/dist/{defineProperty-Dlhh3lSJ.cjs.map → defineProperty-DZi5DvrW.cjs.map} +1 -1
  5. package/dist/{defineProperty-_FBdEen_.js → defineProperty-DcP1vZ2K.js} +2 -2
  6. package/dist/{defineProperty-_FBdEen_.js.map → defineProperty-DcP1vZ2K.js.map} +1 -1
  7. package/dist/index.cjs +28 -11
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +28 -11
  12. package/dist/index.js.map +1 -1
  13. package/dist/parsers/typescript.d.cts +2 -2
  14. package/dist/parsers/typescript.d.ts +2 -2
  15. package/dist/parsers.d.cts +2 -2
  16. package/dist/parsers.d.ts +2 -2
  17. package/dist/plugins.cjs +3 -5
  18. package/dist/plugins.cjs.map +1 -1
  19. package/dist/plugins.d.cts +7 -1
  20. package/dist/plugins.d.ts +7 -1
  21. package/dist/plugins.js +3 -5
  22. package/dist/plugins.js.map +1 -1
  23. package/dist/types.d.cts +1 -1
  24. package/dist/types.d.ts +1 -1
  25. package/dist/{typescriptParser-DaOfAlmM.d.ts → typescriptParser-B5SxjtvV.d.ts} +2 -2
  26. package/dist/{typescriptParser-C3B3dzh_.d.cts → typescriptParser-PfAO0SSm.d.cts} +2 -2
  27. package/package.json +1 -1
  28. package/src/Fabric.ts +7 -8
  29. package/src/FileManager.ts +16 -12
  30. package/src/defineFabric.ts +1 -1
  31. package/src/plugins/barrelPlugin.ts +7 -1
  32. package/src/plugins/fsPlugin.ts +1 -1
  33. package/src/utils/AsyncEventEmitter.ts +14 -2
@@ -33,23 +33,27 @@ export class FileManager {
33
33
  return this
34
34
  }
35
35
 
36
- async add(...files: Array<KubbFile.File>) {
37
- const resolvedFiles: Array<KubbFile.ResolvedFile> = []
36
+ async #resolvePath(file: KubbFile.File): Promise<KubbFile.File> {
37
+ await this.events.emit('file:resolve:path', { file })
38
38
 
39
- const mergedFiles = new Map<string, KubbFile.File>()
39
+ return file
40
+ }
40
41
 
41
- files.forEach((file) => {
42
- const existing = mergedFiles.get(file.path)
43
- if (existing) {
44
- mergedFiles.set(file.path, mergeFile(existing, file))
45
- } else {
46
- mergedFiles.set(file.path, file)
47
- }
48
- })
42
+ async #resolveName(file: KubbFile.File): Promise<KubbFile.File> {
43
+ await this.events.emit('file:resolve:name', { file })
44
+
45
+ return file
46
+ }
49
47
 
50
- for (const file of mergedFiles.values()) {
48
+ async add(...files: Array<KubbFile.File>) {
49
+ const resolvedFiles: Array<KubbFile.ResolvedFile> = []
50
+
51
+ for (let file of files) {
51
52
  const existing = this.#cache.get(file.path)
52
53
 
54
+ file = await this.#resolveName(file)
55
+ file = await this.#resolvePath(file)
56
+
53
57
  const merged = existing ? mergeFile(existing, file) : file
54
58
  const resolvedFile = createFile(merged)
55
59
 
@@ -27,7 +27,7 @@ export type CreateFabric<T extends FabricOptions> = (config?: FabricConfig<T>) =
27
27
  * })
28
28
  */
29
29
  export function defineFabric<T extends FabricOptions>(init?: FabricInitializer<T>): CreateFabric<T> {
30
- function create(config?: FabricConfig<T>): Fabric<T> {
30
+ function create(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {
31
31
  const events = new AsyncEventEmitter<FabricEvents>()
32
32
  const installedPlugins = new Set<Plugin<any>>()
33
33
  const installedParsers = new Set<Parser<any>>()
@@ -21,12 +21,18 @@ type WriteEntryOptions = {
21
21
  }
22
22
 
23
23
  type ExtendOptions = {
24
+ /**
25
+ * `fabric.writeEntry` should be called before `fabric.write`
26
+ */
24
27
  writeEntry(options: WriteEntryOptions): Promise<void>
25
28
  }
26
29
 
27
30
  declare global {
28
31
  namespace Kubb {
29
32
  interface Fabric {
33
+ /**
34
+ * `fabric.writeEntry` should be called before `fabric.write`
35
+ */
30
36
  writeEntry(options: WriteEntryOptions): Promise<void>
31
37
  }
32
38
  }
@@ -188,7 +194,7 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
188
194
  await ctx.addFile(entryFile)
189
195
 
190
196
  await ctx.fileManager.write({
191
- mode: ctx.config?.options?.mode,
197
+ mode: ctx.config.mode,
192
198
  dryRun: options.dryRun,
193
199
  parsers: ctx.installedParsers,
194
200
  })
@@ -107,7 +107,7 @@ export const fsPlugin = createPlugin<Options, ExtendOptions>({
107
107
  },
108
108
  ) {
109
109
  await ctx.fileManager.write({
110
- mode: ctx.config?.options?.mode,
110
+ mode: ctx.config.mode,
111
111
  extension: options.extension,
112
112
  dryRun,
113
113
  parsers: ctx.installedParsers,
@@ -22,13 +22,16 @@ export class AsyncEventEmitter<TEvents extends Record<string, any>> {
22
22
  return
23
23
  }
24
24
 
25
+ const errors: Error[] = []
26
+
25
27
  if (this.#mode === 'sequential') {
26
28
  // Run listeners one by one, in order
27
29
  for (const listener of listeners) {
28
30
  try {
29
31
  await listener(...eventArgs)
30
32
  } catch (err) {
31
- console.error(`Error in listener for "${eventName}":`, err)
33
+ const error = err instanceof Error ? err : new Error(String(err))
34
+ errors.push(error)
32
35
  }
33
36
  }
34
37
  } else {
@@ -37,11 +40,20 @@ export class AsyncEventEmitter<TEvents extends Record<string, any>> {
37
40
  try {
38
41
  await listener(...eventArgs)
39
42
  } catch (err) {
40
- console.error(`Error in listener for "${eventName}":`, err)
43
+ const error = err instanceof Error ? err : new Error(String(err))
44
+ errors.push(error)
41
45
  }
42
46
  })
43
47
  await Promise.all(promises)
44
48
  }
49
+
50
+ if (errors.length === 1) {
51
+ throw errors[0]
52
+ }
53
+
54
+ if (errors.length > 1) {
55
+ throw new AggregateError(errors, `Errors in async listeners for "${eventName}"`)
56
+ }
45
57
  }
46
58
 
47
59
  on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {