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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/{FileManager-EVJig-LT.d.ts → FileManager-BbUCeEyv.d.cts} +108 -94
  2. package/dist/{FileManager-DSLZ6ps7.d.cts → FileManager-CpuFz6eH.d.ts} +108 -94
  3. package/dist/chunk-2EU7DMPM.js +97 -0
  4. package/dist/chunk-2EU7DMPM.js.map +1 -0
  5. package/dist/chunk-5E2I6KH4.cjs +1071 -0
  6. package/dist/chunk-5E2I6KH4.cjs.map +1 -0
  7. package/dist/{chunk-67C6RBGQ.cjs → chunk-A6PCLWEY.cjs} +5 -5
  8. package/dist/{chunk-67C6RBGQ.cjs.map → chunk-A6PCLWEY.cjs.map} +1 -1
  9. package/dist/chunk-DID47EQD.cjs +102 -0
  10. package/dist/chunk-DID47EQD.cjs.map +1 -0
  11. package/dist/chunk-HBQM723K.js +1063 -0
  12. package/dist/chunk-HBQM723K.js.map +1 -0
  13. package/dist/chunk-L6YLVCKM.js +929 -0
  14. package/dist/chunk-L6YLVCKM.js.map +1 -0
  15. package/dist/{chunk-LM2YQC3T.cjs → chunk-M7NLNCSM.cjs} +71 -38
  16. package/dist/chunk-M7NLNCSM.cjs.map +1 -0
  17. package/dist/{chunk-3OXCZ5DJ.js → chunk-MU3CBCQT.js} +59 -35
  18. package/dist/chunk-MU3CBCQT.js.map +1 -0
  19. package/dist/chunk-NB4JMN75.cjs +1548 -0
  20. package/dist/chunk-NB4JMN75.cjs.map +1 -0
  21. package/dist/{chunk-XCPFG6DO.cjs → chunk-SEH6NUCX.cjs} +4 -28
  22. package/dist/chunk-SEH6NUCX.cjs.map +1 -0
  23. package/dist/index.cjs +496 -552
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +6 -19
  26. package/dist/index.d.ts +6 -19
  27. package/dist/index.js +438 -492
  28. package/dist/index.js.map +1 -1
  29. package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
  30. package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
  31. package/dist/logger.cjs +4 -5
  32. package/dist/logger.cjs.map +1 -1
  33. package/dist/logger.d.cts +1 -2
  34. package/dist/logger.d.ts +1 -2
  35. package/dist/logger.js +2 -4
  36. package/dist/mocks.cjs +25 -19
  37. package/dist/mocks.cjs.map +1 -1
  38. package/dist/mocks.d.cts +6 -9
  39. package/dist/mocks.d.ts +6 -9
  40. package/dist/mocks.js +21 -16
  41. package/dist/mocks.js.map +1 -1
  42. package/dist/prompt-DVQN7JTN.cjs +760 -0
  43. package/dist/prompt-DVQN7JTN.cjs.map +1 -0
  44. package/dist/prompt-WQQUN22Z.js +754 -0
  45. package/dist/prompt-WQQUN22Z.js.map +1 -0
  46. package/dist/transformers.cjs +198 -42
  47. package/dist/transformers.cjs.map +1 -1
  48. package/dist/transformers.d.cts +1 -3
  49. package/dist/transformers.d.ts +1 -3
  50. package/dist/transformers.js +155 -14
  51. package/dist/transformers.js.map +1 -1
  52. package/dist/utils.cjs +12 -4
  53. package/dist/utils.cjs.map +1 -1
  54. package/dist/utils.d.cts +31 -3
  55. package/dist/utils.d.ts +31 -3
  56. package/dist/utils.js +11 -4
  57. package/package.json +10 -10
  58. package/src/BarrelManager.ts +93 -107
  59. package/src/{Generator.ts → BaseGenerator.ts} +1 -1
  60. package/src/FileManager.ts +198 -297
  61. package/src/PackageManager.ts +1 -1
  62. package/src/PluginManager.ts +152 -101
  63. package/src/__snapshots__/barrel.json +91 -0
  64. package/src/__snapshots__/grouped.json +114 -0
  65. package/src/__snapshots__/ordered.json +62 -0
  66. package/src/build.ts +86 -171
  67. package/src/errors.ts +0 -11
  68. package/src/index.ts +1 -2
  69. package/src/logger.ts +76 -34
  70. package/src/plugin.ts +3 -3
  71. package/src/transformers/index.ts +2 -3
  72. package/src/transformers/trim.ts +0 -4
  73. package/src/types.ts +35 -35
  74. package/src/utils/TreeNode.ts +132 -50
  75. package/src/utils/executeStrategies.ts +1 -1
  76. package/src/utils/index.ts +2 -1
  77. package/src/utils/parser.ts +157 -0
  78. package/dist/chunk-3OXCZ5DJ.js.map +0 -1
  79. package/dist/chunk-5JZNFPUP.js +0 -309
  80. package/dist/chunk-5JZNFPUP.js.map +0 -1
  81. package/dist/chunk-ADC5UNZ5.cjs +0 -1227
  82. package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
  83. package/dist/chunk-HMLY7DHA.js +0 -16
  84. package/dist/chunk-HMLY7DHA.js.map +0 -1
  85. package/dist/chunk-JKZG2IJR.js +0 -283
  86. package/dist/chunk-JKZG2IJR.js.map +0 -1
  87. package/dist/chunk-LM2YQC3T.cjs.map +0 -1
  88. package/dist/chunk-PZT4CTBV.cjs +0 -299
  89. package/dist/chunk-PZT4CTBV.cjs.map +0 -1
  90. package/dist/chunk-SA2GZKXS.js +0 -596
  91. package/dist/chunk-SA2GZKXS.js.map +0 -1
  92. package/dist/chunk-XCPFG6DO.cjs.map +0 -1
  93. package/dist/chunk-YTSNYMHW.cjs +0 -320
  94. package/dist/chunk-YTSNYMHW.cjs.map +0 -1
  95. package/schema.json +0 -86
  96. package/src/utils/getParser.ts +0 -17
@@ -1,11 +1,7 @@
1
- import PQueue from 'p-queue'
2
-
3
- import { readSync } from '@kubb/fs'
4
- import { FileManager, type ResolvedFile } from './FileManager.ts'
1
+ import { FileManager } from './FileManager.ts'
5
2
  import { isPromise, isPromiseRejectedResult } from './PromiseManager.ts'
6
3
  import { PromiseManager } from './PromiseManager.ts'
7
4
  import { ValidationPluginError } from './errors.ts'
8
- import { LogLevel } from './logger.ts'
9
5
  import { pluginCore } from './plugin.ts'
10
6
  import { transformReservedWord } from './transformers/transformReservedWord.ts'
11
7
  import { EventEmitter } from './utils/EventEmitter.ts'
@@ -41,6 +37,7 @@ type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifec
41
37
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq'
42
38
 
43
39
  type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
40
+ message: string
44
41
  strategy: Strategy
45
42
  hookName: H
46
43
  plugin: Plugin
@@ -59,15 +56,10 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
59
56
 
60
57
  type Options = {
61
58
  logger: Logger
62
-
63
- /**
64
- * Task for the FileManager
65
- */
66
- task: (file: ResolvedFile) => Promise<ResolvedFile>
67
59
  }
68
60
 
69
61
  type Events = {
70
- execute: [executer: Executer]
62
+ executing: [executer: Executer]
71
63
  executed: [executer: Executer]
72
64
  error: [error: Error]
73
65
  }
@@ -89,21 +81,17 @@ export class PluginManager {
89
81
 
90
82
  readonly executed: Array<Executer> = []
91
83
  readonly logger: Logger
84
+ readonly options: Options
92
85
  readonly #core: Plugin<PluginCore>
93
86
 
94
87
  readonly #usedPluginNames: Record<string, number> = {}
95
88
  readonly #promiseManager: PromiseManager
96
89
 
97
- readonly queue: PQueue
98
-
99
90
  constructor(config: Config, options: Options) {
100
91
  this.config = config
92
+ this.options = options
101
93
  this.logger = options.logger
102
- this.queue = new PQueue({ concurrency: 1 })
103
- this.fileManager = new FileManager({
104
- task: options.task,
105
- queue: this.queue,
106
- })
94
+ this.fileManager = new FileManager()
107
95
  this.#promiseManager = new PromiseManager({
108
96
  nullCheck: (state: SafeParseResult<'resolveName'> | null) => !!state?.result,
109
97
  })
@@ -120,18 +108,17 @@ export class PluginManager {
120
108
  getPlugins: this.#getSortedPlugins.bind(this),
121
109
  })
122
110
 
123
- // call core.api.call with empty context so we can transform `api()` to `api: {}`
124
- this.#core = this.#parse(core as unknown as UserPlugin, this as any, core.api.call(null as any)) as Plugin<PluginCore>
111
+ // call core.context.call with empty context so we can transform `context()` to `context: {}`
112
+ this.#core = this.#parse(core as unknown as UserPlugin, this as any, core.context.call(null as any)) as Plugin<PluginCore>
125
113
 
126
114
  this.plugins = [this.#core, ...plugins].map((plugin) => {
127
- return this.#parse(plugin as UserPlugin, this, this.#core.api)
115
+ return this.#parse(plugin as UserPlugin, this, this.#core.context)
128
116
  })
129
117
 
130
118
  return this
131
119
  }
132
120
 
133
121
  getFile<TOptions = object>({ name, mode, extName, pluginKey, options }: GetFileProps<TOptions>): KubbFile.File<{ pluginKey: Plugin['key'] }> {
134
- let source = ''
135
122
  const baseName = `${name}${extName}` as const
136
123
  const path = this.resolvePath({ baseName, mode, pluginKey, options })
137
124
 
@@ -139,19 +126,13 @@ export class PluginManager {
139
126
  throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`)
140
127
  }
141
128
 
142
- try {
143
- source = readSync(path)
144
- } catch (_e) {
145
- //
146
- }
147
-
148
129
  return {
149
130
  path,
150
131
  baseName,
151
132
  meta: {
152
133
  pluginKey,
153
134
  },
154
- source,
135
+ sources: [],
155
136
  }
156
137
  }
157
138
 
@@ -161,14 +142,18 @@ export class PluginManager {
161
142
  pluginKey: params.pluginKey,
162
143
  hookName: 'resolvePath',
163
144
  parameters: [params.baseName, params.mode, params.options as object],
145
+ message: `Resolving path '${params.baseName}'`,
164
146
  })
165
147
 
166
148
  if (paths && paths?.length > 1) {
167
- this.logger.emit('debug', [
168
- `Cannot return a path where the 'pluginKey' ${
169
- params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
170
- } is not unique enough\n\nPaths: ${JSON.stringify(paths, undefined, 2)}\n\nFalling back on the first item.\n`,
171
- ])
149
+ this.logger.emit('debug', {
150
+ date: new Date(),
151
+ logs: [
152
+ `Cannot return a path where the 'pluginKey' ${
153
+ params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
154
+ } is not unique enough\n\nPaths: ${JSON.stringify(paths, undefined, 2)}\n\nFalling back on the first item.\n`,
155
+ ],
156
+ })
172
157
  }
173
158
 
174
159
  return paths?.at(0)
@@ -176,22 +161,28 @@ export class PluginManager {
176
161
  return this.hookFirstSync({
177
162
  hookName: 'resolvePath',
178
163
  parameters: [params.baseName, params.mode, params.options as object],
164
+ message: `Resolving path '${params.baseName}'`,
179
165
  }).result
180
166
  }
167
+ //TODO refactor by using the order of plugins and the cache of the fileManager instead of guessing and recreating the name/path
181
168
  resolveName = (params: ResolveNameParams): string => {
182
169
  if (params.pluginKey) {
183
170
  const names = this.hookForPluginSync({
184
171
  pluginKey: params.pluginKey,
185
172
  hookName: 'resolveName',
186
173
  parameters: [params.name, params.type],
174
+ message: `Resolving name '${params.name}' and type '${params.type}'`,
187
175
  })
188
176
 
189
177
  if (names && names?.length > 1) {
190
- this.logger.emit('debug', [
191
- `Cannot return a name where the 'pluginKey' ${
192
- params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
193
- } is not unique enough\n\nNames: ${JSON.stringify(names, undefined, 2)}\n\nFalling back on the first item.\n`,
194
- ])
178
+ this.logger.emit('debug', {
179
+ date: new Date(),
180
+ logs: [
181
+ `Cannot return a name where the 'pluginKey' ${
182
+ params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
183
+ } is not unique enough\n\nNames: ${JSON.stringify(names, undefined, 2)}\n\nFalling back on the first item.\n`,
184
+ ],
185
+ })
195
186
  }
196
187
 
197
188
  return transformReservedWord(names?.at(0) || params.name)
@@ -200,6 +191,7 @@ export class PluginManager {
200
191
  const name = this.hookFirstSync({
201
192
  hookName: 'resolveName',
202
193
  parameters: [params.name, params.type],
194
+ message: `Resolving name '${params.name}' and type '${params.type}'`,
203
195
  }).result
204
196
 
205
197
  return transformReservedWord(name)
@@ -215,17 +207,21 @@ export class PluginManager {
215
207
  /**
216
208
  * Run a specific hookName for plugin x.
217
209
  */
218
- hookForPlugin<H extends PluginLifecycleHooks>({
210
+ async hookForPlugin<H extends PluginLifecycleHooks>({
219
211
  pluginKey,
220
212
  hookName,
221
213
  parameters,
214
+ message,
222
215
  }: {
223
216
  pluginKey: Plugin['key']
224
217
  hookName: H
225
218
  parameters: PluginParameter<H>
226
- }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null {
219
+ message: string
220
+ }): Promise<Array<ReturnType<ParseResult<H>> | null>> {
227
221
  const plugins = this.getPluginsByKey(hookName, pluginKey)
228
222
 
223
+ this.logger.emit('progress_start', { id: hookName, size: plugins.length, message: 'Running plugins...' })
224
+
229
225
  const promises = plugins
230
226
  .map((plugin) => {
231
227
  return this.#execute<H>({
@@ -233,11 +229,16 @@ export class PluginManager {
233
229
  hookName,
234
230
  parameters,
235
231
  plugin,
232
+ message,
236
233
  })
237
234
  })
238
235
  .filter(Boolean)
239
236
 
240
- return Promise.all(promises)
237
+ const items = await Promise.all(promises)
238
+
239
+ this.logger.emit('progress_stop', { id: hookName })
240
+
241
+ return items
241
242
  }
242
243
  /**
243
244
  * Run a specific hookName for plugin x.
@@ -247,23 +248,28 @@ export class PluginManager {
247
248
  pluginKey,
248
249
  hookName,
249
250
  parameters,
251
+ message,
250
252
  }: {
251
253
  pluginKey: Plugin['key']
252
254
  hookName: H
253
255
  parameters: PluginParameter<H>
256
+ message: string
254
257
  }): Array<ReturnType<ParseResult<H>>> | null {
255
258
  const plugins = this.getPluginsByKey(hookName, pluginKey)
256
259
 
257
- return plugins
260
+ const result = plugins
258
261
  .map((plugin) => {
259
262
  return this.#executeSync<H>({
260
263
  strategy: 'hookFirst',
261
264
  hookName,
262
265
  parameters,
263
266
  plugin,
267
+ message,
264
268
  })
265
269
  })
266
270
  .filter(Boolean)
271
+
272
+ return result
267
273
  }
268
274
 
269
275
  /**
@@ -273,32 +279,41 @@ export class PluginManager {
273
279
  hookName,
274
280
  parameters,
275
281
  skipped,
282
+ message,
276
283
  }: {
277
284
  hookName: H
278
285
  parameters: PluginParameter<H>
279
286
  skipped?: ReadonlySet<Plugin> | null
287
+ message: string
280
288
  }): Promise<SafeParseResult<H>> {
281
- const promises = this.#getSortedPlugins()
282
- .filter((plugin) => {
283
- return skipped ? skipped.has(plugin) : true
284
- })
285
- .map((plugin) => {
286
- return async () => {
287
- const value = await this.#execute<H>({
288
- strategy: 'hookFirst',
289
- hookName,
290
- parameters,
291
- plugin,
292
- })
289
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
290
+ return skipped ? skipped.has(plugin) : true
291
+ })
293
292
 
294
- return Promise.resolve({
295
- plugin,
296
- result: value,
297
- } as SafeParseResult<H>)
298
- }
299
- })
293
+ this.logger.emit('progress_start', { id: hookName, size: plugins.length })
300
294
 
301
- return this.#promiseManager.run('first', promises)
295
+ const promises = plugins.map((plugin) => {
296
+ return async () => {
297
+ const value = await this.#execute<H>({
298
+ strategy: 'hookFirst',
299
+ hookName,
300
+ parameters,
301
+ plugin,
302
+ message,
303
+ })
304
+
305
+ return Promise.resolve({
306
+ plugin,
307
+ result: value,
308
+ } as SafeParseResult<H>)
309
+ }
310
+ })
311
+
312
+ const result = await this.#promiseManager.run('first', promises)
313
+
314
+ this.logger.emit('progress_stop', { id: hookName })
315
+
316
+ return result
302
317
  }
303
318
 
304
319
  /**
@@ -308,24 +323,26 @@ export class PluginManager {
308
323
  hookName,
309
324
  parameters,
310
325
  skipped,
326
+ message,
311
327
  }: {
312
328
  hookName: H
313
329
  parameters: PluginParameter<H>
314
330
  skipped?: ReadonlySet<Plugin> | null
331
+ message: string
315
332
  }): SafeParseResult<H> {
316
333
  let parseResult: SafeParseResult<H> = null as unknown as SafeParseResult<H>
334
+ const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
335
+ return skipped ? skipped.has(plugin) : true
336
+ })
317
337
 
318
- for (const plugin of this.#getSortedPlugins()) {
319
- if (skipped?.has(plugin)) {
320
- continue
321
- }
322
-
338
+ for (const plugin of plugins) {
323
339
  parseResult = {
324
340
  result: this.#executeSync<H>({
325
341
  strategy: 'hookFirst',
326
342
  hookName,
327
343
  parameters,
328
344
  plugin,
345
+ message,
329
346
  }),
330
347
  plugin,
331
348
  } as SafeParseResult<H>
@@ -334,6 +351,7 @@ export class PluginManager {
334
351
  break
335
352
  }
336
353
  }
354
+
337
355
  return parseResult
338
356
  }
339
357
 
@@ -343,17 +361,23 @@ export class PluginManager {
343
361
  async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
344
362
  hookName,
345
363
  parameters,
364
+ message,
346
365
  }: {
347
366
  hookName: H
348
367
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined
368
+ message: string
349
369
  }): Promise<Awaited<TOuput>[]> {
350
- const promises = this.#getSortedPlugins().map((plugin) => {
370
+ const plugins = this.#getSortedPlugins(hookName)
371
+ this.logger.emit('progress_start', { id: hookName, size: plugins.length })
372
+
373
+ const promises = plugins.map((plugin) => {
351
374
  return () =>
352
375
  this.#execute({
353
376
  strategy: 'hookParallel',
354
377
  hookName,
355
378
  parameters,
356
379
  plugin,
380
+ message,
357
381
  }) as Promise<TOuput>
358
382
  })
359
383
 
@@ -361,12 +385,14 @@ export class PluginManager {
361
385
 
362
386
  results.forEach((result, index) => {
363
387
  if (isPromiseRejectedResult<Error>(result)) {
364
- const plugin = this.#getSortedPlugins()[index]
388
+ const plugin = this.#getSortedPlugins(hookName)[index]
365
389
 
366
390
  this.#catcher<H>(result.reason, plugin, hookName)
367
391
  }
368
392
  })
369
393
 
394
+ this.logger.emit('progress_stop', { id: hookName })
395
+
370
396
  return results.filter((result) => result.status === 'fulfilled').map((result) => (result as PromiseFulfilledResult<Awaited<TOuput>>).value)
371
397
  }
372
398
 
@@ -377,15 +403,18 @@ export class PluginManager {
377
403
  hookName,
378
404
  parameters,
379
405
  reduce,
406
+ message,
380
407
  }: {
381
408
  hookName: H
382
409
  parameters: PluginParameter<H>
383
410
  reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: Plugin) => PossiblePromise<Argument0<H> | null>
411
+ message: string
384
412
  }): Promise<Argument0<H>> {
385
413
  const [argument0, ...rest] = parameters
414
+ const plugins = this.#getSortedPlugins(hookName)
386
415
 
387
416
  let promise: Promise<Argument0<H>> = Promise.resolve(argument0)
388
- for (const plugin of this.#getSortedPlugins()) {
417
+ for (const plugin of plugins) {
389
418
  promise = promise
390
419
  .then((arg0) => {
391
420
  const value = this.#execute({
@@ -393,10 +422,11 @@ export class PluginManager {
393
422
  hookName,
394
423
  parameters: [arg0, ...rest] as PluginParameter<H>,
395
424
  plugin,
425
+ message,
396
426
  })
397
427
  return value
398
428
  })
399
- .then((result) => reduce.call(this.#core.api, argument0, result as ReturnType<ParseResult<H>>, plugin)) as Promise<Argument0<H>>
429
+ .then((result) => reduce.call(this.#core.context, argument0, result as ReturnType<ParseResult<H>>, plugin)) as Promise<Argument0<H>>
400
430
  }
401
431
 
402
432
  return promise
@@ -405,31 +435,34 @@ export class PluginManager {
405
435
  /**
406
436
  * Chains plugins
407
437
  */
408
- async hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: PluginParameter<H> }): Promise<void> {
409
- const promises = this.#getSortedPlugins().map((plugin) => {
438
+ async hookSeq<H extends PluginLifecycleHooks>({
439
+ hookName,
440
+ parameters,
441
+ message,
442
+ }: { hookName: H; parameters?: PluginParameter<H>; message: string }): Promise<void> {
443
+ const plugins = this.#getSortedPlugins(hookName)
444
+ this.logger.emit('progress_start', { id: hookName, size: plugins.length })
445
+
446
+ const promises = plugins.map((plugin) => {
410
447
  return () =>
411
448
  this.#execute({
412
449
  strategy: 'hookSeq',
413
450
  hookName,
414
451
  parameters,
415
452
  plugin,
453
+ message,
416
454
  })
417
455
  })
418
456
 
419
- return this.#promiseManager.run('seq', promises)
457
+ await this.#promiseManager.run('seq', promises)
458
+
459
+ this.logger.emit('progress_stop', { id: hookName })
420
460
  }
421
461
 
422
462
  #getSortedPlugins(hookName?: keyof PluginLifecycle): Plugin[] {
423
463
  const plugins = [...this.plugins].filter((plugin) => plugin.name !== 'core')
424
464
 
425
465
  if (hookName) {
426
- if (this.logger.logLevel === LogLevel.info) {
427
- const containsHookName = plugins.some((item) => item[hookName])
428
- if (!containsHookName) {
429
- this.logger.emit('warning', `No hook ${hookName} found`)
430
- }
431
- }
432
-
433
466
  return plugins.filter((item) => item[hookName])
434
467
  }
435
468
  // TODO add test case for sorting with pre/post
@@ -482,9 +515,15 @@ export class PluginManager {
482
515
  const corePlugin = plugins.find((plugin) => plugin.name === 'core' && plugin[hookName])
483
516
 
484
517
  if (corePlugin) {
485
- this.logger.emit('debug', [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`])
518
+ this.logger.emit('debug', {
519
+ date: new Date(),
520
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`],
521
+ })
486
522
  } else {
487
- this.logger.emit('debug', [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`])
523
+ this.logger.emit('debug', {
524
+ date: new Date(),
525
+ logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`],
526
+ })
488
527
  }
489
528
  return corePlugin ? [corePlugin] : []
490
529
  }
@@ -496,6 +535,8 @@ export class PluginManager {
496
535
  if (executer) {
497
536
  this.events.emit('executed', executer)
498
537
  this.executed.push(executer)
538
+
539
+ this.logger.emit('progressed', { id: executer.hookName, message: `${executer.plugin.name}: ${executer.message}` })
499
540
  }
500
541
  }
501
542
 
@@ -511,11 +552,13 @@ export class PluginManager {
511
552
  hookName,
512
553
  parameters,
513
554
  plugin,
555
+ message,
514
556
  }: {
515
557
  strategy: Strategy
516
558
  hookName: H
517
559
  parameters: unknown[] | undefined
518
560
  plugin: PluginWithLifeCycle
561
+ message: string
519
562
  }): Promise<ReturnType<ParseResult<H>> | null> | null {
520
563
  const hook = plugin[hookName]
521
564
  let output: unknown
@@ -524,12 +567,15 @@ export class PluginManager {
524
567
  return null
525
568
  }
526
569
 
527
- this.events.emit('execute', { strategy, hookName, parameters, plugin })
570
+ this.events.emit('executing', { strategy, hookName, parameters, plugin, message })
571
+ const promise = new Promise((resolve) => {
572
+ resolve(undefined)
573
+ })
528
574
 
529
- const task = Promise.resolve()
575
+ const task = promise
530
576
  .then(() => {
531
577
  if (typeof hook === 'function') {
532
- const possiblePromiseResult = (hook as Function).apply({ ...this.#core.api, plugin }, parameters) as Promise<ReturnType<ParseResult<H>>>
578
+ const possiblePromiseResult = (hook as Function).apply({ ...this.#core.context, plugin }, parameters) as Promise<ReturnType<ParseResult<H>>>
533
579
 
534
580
  if (isPromise(possiblePromiseResult)) {
535
581
  return Promise.resolve(possiblePromiseResult)
@@ -548,6 +594,7 @@ export class PluginManager {
548
594
  strategy,
549
595
  hookName,
550
596
  plugin,
597
+ message,
551
598
  })
552
599
 
553
600
  return result
@@ -573,11 +620,13 @@ export class PluginManager {
573
620
  hookName,
574
621
  parameters,
575
622
  plugin,
623
+ message,
576
624
  }: {
577
625
  strategy: Strategy
578
626
  hookName: H
579
627
  parameters: PluginParameter<H>
580
628
  plugin: PluginWithLifeCycle
629
+ message: string
581
630
  }): ReturnType<ParseResult<H>> | null {
582
631
  const hook = plugin[hookName]
583
632
  let output: unknown
@@ -586,13 +635,23 @@ export class PluginManager {
586
635
  return null
587
636
  }
588
637
 
589
- this.events.emit('execute', { strategy, hookName, parameters, plugin })
638
+ this.events.emit('executing', { strategy, hookName, parameters, plugin, message })
590
639
 
591
640
  try {
592
641
  if (typeof hook === 'function') {
593
- const fn = (hook as Function).apply({ ...this.#core.api, plugin }, parameters) as ReturnType<ParseResult<H>>
642
+ const fn = (hook as Function).apply({ ...this.#core.context, plugin }, parameters) as ReturnType<ParseResult<H>>
594
643
 
595
644
  output = fn
645
+
646
+ this.#addExecutedToCallStack({
647
+ parameters,
648
+ output,
649
+ strategy,
650
+ hookName,
651
+ plugin,
652
+ message,
653
+ })
654
+
596
655
  return fn
597
656
  }
598
657
 
@@ -604,6 +663,7 @@ export class PluginManager {
604
663
  strategy,
605
664
  hookName,
606
665
  plugin,
666
+ message,
607
667
  })
608
668
 
609
669
  return hook
@@ -624,7 +684,7 @@ export class PluginManager {
624
684
  #parse<TPlugin extends UserPluginWithLifeCycle>(
625
685
  plugin: TPlugin,
626
686
  pluginManager: PluginManager,
627
- context: PluginCore['api'] | undefined,
687
+ context: PluginCore['context'] | undefined,
628
688
  ): Plugin<GetPluginFactoryOptions<TPlugin>> {
629
689
  const usedPluginNames = pluginManager.#usedPluginNames
630
690
 
@@ -632,20 +692,11 @@ export class PluginManager {
632
692
 
633
693
  const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean) as [typeof plugin.name, string]
634
694
 
635
- // default transform
636
- if (!plugin.transform) {
637
- plugin.transform = function transform(_path, code) {
638
- return code
639
- }
640
- }
641
-
642
- if (plugin.api && typeof plugin.api === 'function') {
643
- const api = (plugin.api as Function).call(context) as typeof plugin.api
644
-
695
+ if (plugin.context && typeof plugin.context === 'function') {
645
696
  return {
646
697
  ...plugin,
647
698
  key,
648
- api,
699
+ context: (plugin.context as Function).call(context) as typeof plugin.context,
649
700
  } as unknown as Plugin<GetPluginFactoryOptions<TPlugin>>
650
701
  }
651
702
 
@@ -678,6 +729,6 @@ export class PluginManager {
678
729
  }
679
730
 
680
731
  static get hooks() {
681
- return ['buildStart', 'resolvePath', 'resolveName', 'load', 'transform', 'writeFile', 'buildEnd'] as const
732
+ return ['buildStart', 'resolvePath', 'resolveName', 'buildEnd'] as const
682
733
  }
683
734
  }
@@ -0,0 +1,91 @@
1
+ [
2
+ {
3
+ "path": "src/index.ts",
4
+ "baseName": "index.ts",
5
+ "exports": [
6
+ {
7
+ "name": [
8
+ "hello"
9
+ ],
10
+ "path": "./sub/hello.ts",
11
+ "extName": ".ts"
12
+ },
13
+ {
14
+ "name": [
15
+ "world"
16
+ ],
17
+ "path": "./sub/world.ts",
18
+ "extName": ".ts"
19
+ },
20
+ {
21
+ "name": [
22
+ "test"
23
+ ],
24
+ "path": "./test.ts",
25
+ "extName": ".ts"
26
+ }
27
+ ],
28
+ "sources": [
29
+ {
30
+ "name": "test",
31
+ "value": "",
32
+ "isExportable": false,
33
+ "isIndexable": false
34
+ },
35
+ {
36
+ "name": "hello",
37
+ "value": "",
38
+ "isExportable": false,
39
+ "isIndexable": false
40
+ },
41
+ {
42
+ "name": "world",
43
+ "value": "",
44
+ "isExportable": false,
45
+ "isIndexable": false
46
+ }
47
+ ],
48
+ "id": "feabc02536bd6630458e734990f7e2a21a55c469",
49
+ "name": "index",
50
+ "extName": ".ts",
51
+ "imports": []
52
+ },
53
+ {
54
+ "path": "src/sub/index.ts",
55
+ "baseName": "index.ts",
56
+ "exports": [
57
+ {
58
+ "name": [
59
+ "hello"
60
+ ],
61
+ "path": "./hello.ts",
62
+ "extName": ".ts"
63
+ },
64
+ {
65
+ "name": [
66
+ "world"
67
+ ],
68
+ "path": "./world.ts",
69
+ "extName": ".ts"
70
+ }
71
+ ],
72
+ "sources": [
73
+ {
74
+ "name": "hello",
75
+ "value": "",
76
+ "isExportable": false,
77
+ "isIndexable": false
78
+ },
79
+ {
80
+ "name": "world",
81
+ "value": "",
82
+ "isExportable": false,
83
+ "isIndexable": false
84
+ }
85
+ ],
86
+ "id": "c67967bd2363dd9637437671f6fe1ed146debdbf",
87
+ "name": "index",
88
+ "extName": ".ts",
89
+ "imports": []
90
+ }
91
+ ]