@kubb/core 4.11.1 → 4.11.2
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.
- package/dist/{getBarrelFiles-BkDzzugQ.cjs → getBarrelFiles-8VEWWk9Z.cjs} +80 -111
- package/dist/getBarrelFiles-8VEWWk9Z.cjs.map +1 -0
- package/dist/{getBarrelFiles-BVMBhc50.d.cts → getBarrelFiles-B_2WDywH.d.cts} +3 -3
- package/dist/{getBarrelFiles-a-GlnjYa.js → getBarrelFiles-DQ0hksqD.js} +80 -111
- package/dist/getBarrelFiles-DQ0hksqD.js.map +1 -0
- package/dist/{getBarrelFiles-DjQ68d4e.d.ts → getBarrelFiles-ZIHk_1ln.d.ts} +3 -3
- package/dist/hooks.d.cts +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +261 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +262 -43
- package/dist/index.js.map +1 -1
- package/dist/{logger-DIA19Yfz.js → logger-CQn6sdC0.js} +72 -7
- package/dist/{logger-CPt4U57Z.cjs.map → logger-CQn6sdC0.js.map} +1 -1
- package/dist/{logger-CPt4U57Z.cjs → logger-US5g7KdM.cjs} +72 -7
- package/dist/logger-US5g7KdM.cjs.map +1 -0
- package/dist/{logger-C96jDrSt.d.ts → logger-mq06Cxxv.d.cts} +29 -4
- package/dist/{logger-BJDkLsF0.d.cts → logger-o16AyvGp.d.ts} +29 -4
- package/dist/logger.cjs +1 -1
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/{types-tSSA1oz8.d.cts → types-CCEy_FVr.d.cts} +36 -27
- package/dist/{types-69-evK37.d.ts → types-DgfEZ3IN.d.ts} +36 -27
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/src/PluginManager.ts +81 -114
- package/src/build.ts +229 -25
- package/src/logger.ts +87 -9
- package/src/utils/ciDetection.ts +40 -0
- package/src/utils/diagnostics.ts +15 -0
- package/dist/getBarrelFiles-BkDzzugQ.cjs.map +0 -1
- package/dist/getBarrelFiles-a-GlnjYa.js.map +0 -1
- package/dist/logger-DIA19Yfz.js.map +0 -1
package/src/PluginManager.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
+
import { performance } from 'node:perf_hooks'
|
|
2
3
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
4
|
import type { Fabric } from '@kubb/react-fabric'
|
|
4
5
|
import { ValidationPluginError } from './errors.ts'
|
|
@@ -27,8 +28,7 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>
|
|
|
27
28
|
|
|
28
29
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq'
|
|
29
30
|
|
|
30
|
-
type
|
|
31
|
-
message: string
|
|
31
|
+
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
32
32
|
strategy: Strategy
|
|
33
33
|
hookName: H
|
|
34
34
|
plugin: Plugin
|
|
@@ -36,6 +36,32 @@ type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
36
36
|
output?: unknown
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
40
|
+
duration: number
|
|
41
|
+
strategy: Strategy
|
|
42
|
+
hookName: H
|
|
43
|
+
plugin: Plugin
|
|
44
|
+
parameters?: unknown[] | undefined
|
|
45
|
+
output?: unknown
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type ErrorMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
49
|
+
hookName: H
|
|
50
|
+
duration: number
|
|
51
|
+
strategy: Strategy
|
|
52
|
+
parameters?: unknown[] | undefined
|
|
53
|
+
plugin: Plugin
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
57
|
+
hookName: H
|
|
58
|
+
plugins: Array<Plugin>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
62
|
+
hookName: H
|
|
63
|
+
}
|
|
64
|
+
|
|
39
65
|
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H]
|
|
40
66
|
|
|
41
67
|
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
@@ -55,9 +81,11 @@ type Options = {
|
|
|
55
81
|
}
|
|
56
82
|
|
|
57
83
|
type Events = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
84
|
+
progress_start: [meta: ProgressStartMeta]
|
|
85
|
+
progress_stop: [meta: ProgressStopMeta]
|
|
86
|
+
executing: [meta: ExecutingMeta]
|
|
87
|
+
executed: [meta: ExecutedMeta]
|
|
88
|
+
error: [error: Error, meta: ErrorMeta]
|
|
61
89
|
}
|
|
62
90
|
|
|
63
91
|
type GetFileProps<TOptions = object> = {
|
|
@@ -79,9 +107,6 @@ export class PluginManager {
|
|
|
79
107
|
readonly events: EventEmitter<Events> = new EventEmitter()
|
|
80
108
|
|
|
81
109
|
readonly config: Config
|
|
82
|
-
|
|
83
|
-
readonly executed: Array<Executer> = []
|
|
84
|
-
readonly logger: Logger
|
|
85
110
|
readonly options: Options
|
|
86
111
|
|
|
87
112
|
readonly #plugins = new Set<Plugin<GetPluginFactoryOptions<any>>>()
|
|
@@ -91,11 +116,9 @@ export class PluginManager {
|
|
|
91
116
|
constructor(config: Config, options: Options) {
|
|
92
117
|
this.config = config
|
|
93
118
|
this.options = options
|
|
94
|
-
this.logger = options.logger
|
|
95
119
|
this.#promiseManager = new PromiseManager({
|
|
96
120
|
nullCheck: (state: SafeParseResult<'resolveName'> | null) => !!state?.result,
|
|
97
121
|
})
|
|
98
|
-
|
|
99
122
|
;[...(config.plugins || [])].forEach((plugin) => {
|
|
100
123
|
const parsedPlugin = this.#parse(plugin as UserPlugin)
|
|
101
124
|
|
|
@@ -171,27 +194,14 @@ export class PluginManager {
|
|
|
171
194
|
pluginKey: params.pluginKey,
|
|
172
195
|
hookName: 'resolvePath',
|
|
173
196
|
parameters: [params.baseName, params.mode, params.options as object],
|
|
174
|
-
message: `Resolving path '${params.baseName}'`,
|
|
175
197
|
})
|
|
176
198
|
|
|
177
|
-
if (paths && paths?.length > 1) {
|
|
178
|
-
this.logger.emit('debug', {
|
|
179
|
-
date: new Date(),
|
|
180
|
-
logs: [
|
|
181
|
-
`Cannot return a path where the 'pluginKey' ${
|
|
182
|
-
params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
|
|
183
|
-
} is not unique enough\n\nPaths: ${JSON.stringify(paths, undefined, 2)}\n\nFalling back on the first item.\n`,
|
|
184
|
-
],
|
|
185
|
-
})
|
|
186
|
-
}
|
|
187
|
-
|
|
188
199
|
return paths?.at(0) || defaultPath
|
|
189
200
|
}
|
|
190
201
|
|
|
191
202
|
const firstResult = this.hookFirstSync({
|
|
192
203
|
hookName: 'resolvePath',
|
|
193
204
|
parameters: [params.baseName, params.mode, params.options as object],
|
|
194
|
-
message: `Resolving path '${params.baseName}'`,
|
|
195
205
|
})
|
|
196
206
|
|
|
197
207
|
return firstResult?.result || defaultPath
|
|
@@ -203,27 +213,16 @@ export class PluginManager {
|
|
|
203
213
|
pluginKey: params.pluginKey,
|
|
204
214
|
hookName: 'resolveName',
|
|
205
215
|
parameters: [trim(params.name), params.type],
|
|
206
|
-
message: `Resolving name '${params.name}' and type '${params.type}'`,
|
|
207
216
|
})
|
|
208
217
|
|
|
209
|
-
|
|
210
|
-
this.logger.emit('debug', {
|
|
211
|
-
date: new Date(),
|
|
212
|
-
logs: [
|
|
213
|
-
`Cannot return a name where the 'pluginKey' ${
|
|
214
|
-
params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
|
|
215
|
-
} is not unique enough\n\nNames: ${JSON.stringify(names, undefined, 2)}\n\nFalling back on the first item.\n`,
|
|
216
|
-
],
|
|
217
|
-
})
|
|
218
|
-
}
|
|
218
|
+
const uniqueNames = new Set(names)
|
|
219
219
|
|
|
220
|
-
return transformReservedWord(
|
|
220
|
+
return transformReservedWord([...uniqueNames].at(0) || params.name)
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
const name = this.hookFirstSync({
|
|
224
224
|
hookName: 'resolveName',
|
|
225
225
|
parameters: [trim(params.name), params.type],
|
|
226
|
-
message: `Resolving name '${params.name}' and type '${params.type}'`,
|
|
227
226
|
}).result
|
|
228
227
|
|
|
229
228
|
return transformReservedWord(name)
|
|
@@ -243,16 +242,17 @@ export class PluginManager {
|
|
|
243
242
|
pluginKey,
|
|
244
243
|
hookName,
|
|
245
244
|
parameters,
|
|
246
|
-
message,
|
|
247
245
|
}: {
|
|
248
246
|
pluginKey: Plugin['key']
|
|
249
247
|
hookName: H
|
|
250
248
|
parameters: PluginParameter<H>
|
|
251
|
-
message: string
|
|
252
249
|
}): Promise<Array<ReturnType<ParseResult<H>> | null>> {
|
|
253
250
|
const plugins = this.getPluginsByKey(hookName, pluginKey)
|
|
254
251
|
|
|
255
|
-
this.
|
|
252
|
+
this.events.emit('progress_start', {
|
|
253
|
+
hookName,
|
|
254
|
+
plugins,
|
|
255
|
+
})
|
|
256
256
|
|
|
257
257
|
const items: Array<ReturnType<ParseResult<H>>> = []
|
|
258
258
|
|
|
@@ -262,7 +262,6 @@ export class PluginManager {
|
|
|
262
262
|
hookName,
|
|
263
263
|
parameters,
|
|
264
264
|
plugin,
|
|
265
|
-
message,
|
|
266
265
|
})
|
|
267
266
|
|
|
268
267
|
if (result !== undefined && result !== null) {
|
|
@@ -270,7 +269,7 @@ export class PluginManager {
|
|
|
270
269
|
}
|
|
271
270
|
}
|
|
272
271
|
|
|
273
|
-
this.
|
|
272
|
+
this.events.emit('progress_stop', { hookName })
|
|
274
273
|
|
|
275
274
|
return items
|
|
276
275
|
}
|
|
@@ -282,12 +281,10 @@ export class PluginManager {
|
|
|
282
281
|
pluginKey,
|
|
283
282
|
hookName,
|
|
284
283
|
parameters,
|
|
285
|
-
message,
|
|
286
284
|
}: {
|
|
287
285
|
pluginKey: Plugin['key']
|
|
288
286
|
hookName: H
|
|
289
287
|
parameters: PluginParameter<H>
|
|
290
|
-
message: string
|
|
291
288
|
}): Array<ReturnType<ParseResult<H>>> | null {
|
|
292
289
|
const plugins = this.getPluginsByKey(hookName, pluginKey)
|
|
293
290
|
|
|
@@ -298,7 +295,6 @@ export class PluginManager {
|
|
|
298
295
|
hookName,
|
|
299
296
|
parameters,
|
|
300
297
|
plugin,
|
|
301
|
-
message,
|
|
302
298
|
})
|
|
303
299
|
})
|
|
304
300
|
.filter(Boolean)
|
|
@@ -313,18 +309,16 @@ export class PluginManager {
|
|
|
313
309
|
hookName,
|
|
314
310
|
parameters,
|
|
315
311
|
skipped,
|
|
316
|
-
message,
|
|
317
312
|
}: {
|
|
318
313
|
hookName: H
|
|
319
314
|
parameters: PluginParameter<H>
|
|
320
315
|
skipped?: ReadonlySet<Plugin> | null
|
|
321
|
-
message: string
|
|
322
316
|
}): Promise<SafeParseResult<H>> {
|
|
323
317
|
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
324
318
|
return skipped ? skipped.has(plugin) : true
|
|
325
319
|
})
|
|
326
320
|
|
|
327
|
-
this.
|
|
321
|
+
this.events.emit('progress_start', { hookName, plugins })
|
|
328
322
|
|
|
329
323
|
const promises = plugins.map((plugin) => {
|
|
330
324
|
return async () => {
|
|
@@ -333,7 +327,6 @@ export class PluginManager {
|
|
|
333
327
|
hookName,
|
|
334
328
|
parameters,
|
|
335
329
|
plugin,
|
|
336
|
-
message,
|
|
337
330
|
})
|
|
338
331
|
|
|
339
332
|
return Promise.resolve({
|
|
@@ -345,7 +338,7 @@ export class PluginManager {
|
|
|
345
338
|
|
|
346
339
|
const result = await this.#promiseManager.run('first', promises)
|
|
347
340
|
|
|
348
|
-
this.
|
|
341
|
+
this.events.emit('progress_stop', { hookName })
|
|
349
342
|
|
|
350
343
|
return result
|
|
351
344
|
}
|
|
@@ -357,12 +350,10 @@ export class PluginManager {
|
|
|
357
350
|
hookName,
|
|
358
351
|
parameters,
|
|
359
352
|
skipped,
|
|
360
|
-
message,
|
|
361
353
|
}: {
|
|
362
354
|
hookName: H
|
|
363
355
|
parameters: PluginParameter<H>
|
|
364
356
|
skipped?: ReadonlySet<Plugin> | null
|
|
365
|
-
message: string
|
|
366
357
|
}): SafeParseResult<H> {
|
|
367
358
|
let parseResult: SafeParseResult<H> = null as unknown as SafeParseResult<H>
|
|
368
359
|
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
@@ -376,7 +367,6 @@ export class PluginManager {
|
|
|
376
367
|
hookName,
|
|
377
368
|
parameters,
|
|
378
369
|
plugin,
|
|
379
|
-
message,
|
|
380
370
|
}),
|
|
381
371
|
plugin,
|
|
382
372
|
} as SafeParseResult<H>
|
|
@@ -395,14 +385,12 @@ export class PluginManager {
|
|
|
395
385
|
async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
|
|
396
386
|
hookName,
|
|
397
387
|
parameters,
|
|
398
|
-
message,
|
|
399
388
|
}: {
|
|
400
389
|
hookName: H
|
|
401
390
|
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined
|
|
402
|
-
message: string
|
|
403
391
|
}): Promise<Awaited<TOuput>[]> {
|
|
404
392
|
const plugins = this.#getSortedPlugins(hookName)
|
|
405
|
-
this.
|
|
393
|
+
this.events.emit('progress_start', { hookName, plugins })
|
|
406
394
|
|
|
407
395
|
const promises = plugins.map((plugin) => {
|
|
408
396
|
return () =>
|
|
@@ -411,21 +399,24 @@ export class PluginManager {
|
|
|
411
399
|
hookName,
|
|
412
400
|
parameters,
|
|
413
401
|
plugin,
|
|
414
|
-
message,
|
|
415
402
|
}) as Promise<TOuput>
|
|
416
403
|
})
|
|
417
404
|
|
|
418
|
-
const results = await this.#promiseManager.run('parallel', promises, {
|
|
405
|
+
const results = await this.#promiseManager.run('parallel', promises, {
|
|
406
|
+
concurrency: this.options.concurrency,
|
|
407
|
+
})
|
|
419
408
|
|
|
420
409
|
results.forEach((result, index) => {
|
|
421
410
|
if (isPromiseRejectedResult<Error>(result)) {
|
|
422
411
|
const plugin = this.#getSortedPlugins(hookName)[index]
|
|
423
412
|
|
|
424
|
-
|
|
413
|
+
if (plugin) {
|
|
414
|
+
this.events.emit('error', result.reason, { plugin, hookName, strategy: 'hookParallel', duration: 0, parameters })
|
|
415
|
+
}
|
|
425
416
|
}
|
|
426
417
|
})
|
|
427
418
|
|
|
428
|
-
this.
|
|
419
|
+
this.events.emit('progress_stop', { hookName })
|
|
429
420
|
|
|
430
421
|
return results.filter((result) => result.status === 'fulfilled').map((result) => (result as PromiseFulfilledResult<Awaited<TOuput>>).value)
|
|
431
422
|
}
|
|
@@ -433,17 +424,9 @@ export class PluginManager {
|
|
|
433
424
|
/**
|
|
434
425
|
* Chains plugins
|
|
435
426
|
*/
|
|
436
|
-
async hookSeq<H extends PluginLifecycleHooks>({
|
|
437
|
-
hookName,
|
|
438
|
-
parameters,
|
|
439
|
-
message,
|
|
440
|
-
}: {
|
|
441
|
-
hookName: H
|
|
442
|
-
parameters?: PluginParameter<H>
|
|
443
|
-
message: string
|
|
444
|
-
}): Promise<void> {
|
|
427
|
+
async hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: PluginParameter<H> }): Promise<void> {
|
|
445
428
|
const plugins = this.#getSortedPlugins(hookName)
|
|
446
|
-
this.
|
|
429
|
+
this.events.emit('progress_start', { hookName, plugins })
|
|
447
430
|
|
|
448
431
|
const promises = plugins.map((plugin) => {
|
|
449
432
|
return () =>
|
|
@@ -452,13 +435,12 @@ export class PluginManager {
|
|
|
452
435
|
hookName,
|
|
453
436
|
parameters,
|
|
454
437
|
plugin,
|
|
455
|
-
message,
|
|
456
438
|
})
|
|
457
439
|
})
|
|
458
440
|
|
|
459
441
|
await this.#promiseManager.run('seq', promises)
|
|
460
442
|
|
|
461
|
-
this.
|
|
443
|
+
this.events.emit('progress_stop', { hookName })
|
|
462
444
|
}
|
|
463
445
|
|
|
464
446
|
#getSortedPlugins(hookName?: keyof PluginLifecycle): Array<Plugin> {
|
|
@@ -526,33 +508,14 @@ export class PluginManager {
|
|
|
526
508
|
// fallback on the core plugin when there is no match
|
|
527
509
|
|
|
528
510
|
const corePlugin = plugins.find((plugin) => plugin.name === 'core' && hookName in plugin)
|
|
511
|
+
// Removed noisy debug logs for missing hooks - these are expected behavior, not errors
|
|
529
512
|
|
|
530
|
-
if (corePlugin) {
|
|
531
|
-
this.logger.emit('debug', {
|
|
532
|
-
date: new Date(),
|
|
533
|
-
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`],
|
|
534
|
-
})
|
|
535
|
-
} else {
|
|
536
|
-
this.logger.emit('debug', {
|
|
537
|
-
date: new Date(),
|
|
538
|
-
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`],
|
|
539
|
-
})
|
|
540
|
-
}
|
|
541
513
|
return corePlugin ? [corePlugin] : []
|
|
542
514
|
}
|
|
543
515
|
|
|
544
516
|
return pluginByPluginName
|
|
545
517
|
}
|
|
546
518
|
|
|
547
|
-
#addExecutedToCallStack(executer: Executer | undefined) {
|
|
548
|
-
if (executer) {
|
|
549
|
-
this.events.emit('executed', executer)
|
|
550
|
-
this.executed.push(executer)
|
|
551
|
-
|
|
552
|
-
this.logger.emit('progressed', { id: executer.hookName, message: `${executer.plugin.name}: ${executer.message}` })
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
519
|
/**
|
|
557
520
|
* Run an async plugin hook and return the result.
|
|
558
521
|
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
@@ -565,13 +528,11 @@ export class PluginManager {
|
|
|
565
528
|
hookName,
|
|
566
529
|
parameters,
|
|
567
530
|
plugin,
|
|
568
|
-
message,
|
|
569
531
|
}: {
|
|
570
532
|
strategy: Strategy
|
|
571
533
|
hookName: H
|
|
572
534
|
parameters: unknown[] | undefined
|
|
573
535
|
plugin: PluginWithLifeCycle
|
|
574
|
-
message: string
|
|
575
536
|
}): Promise<ReturnType<ParseResult<H>> | null> | null {
|
|
576
537
|
const hook = plugin[hookName]
|
|
577
538
|
let output: unknown
|
|
@@ -580,7 +541,14 @@ export class PluginManager {
|
|
|
580
541
|
return null
|
|
581
542
|
}
|
|
582
543
|
|
|
583
|
-
this.events.emit('executing', {
|
|
544
|
+
this.events.emit('executing', {
|
|
545
|
+
strategy,
|
|
546
|
+
hookName,
|
|
547
|
+
parameters,
|
|
548
|
+
plugin,
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
const startTime = performance.now()
|
|
584
552
|
|
|
585
553
|
const task = (async () => {
|
|
586
554
|
try {
|
|
@@ -590,13 +558,13 @@ export class PluginManager {
|
|
|
590
558
|
|
|
591
559
|
output = result
|
|
592
560
|
|
|
593
|
-
this
|
|
561
|
+
this.events.emit('executed', {
|
|
562
|
+
duration: Math.round(performance.now() - startTime),
|
|
594
563
|
parameters,
|
|
595
564
|
output,
|
|
596
565
|
strategy,
|
|
597
566
|
hookName,
|
|
598
567
|
plugin,
|
|
599
|
-
message,
|
|
600
568
|
})
|
|
601
569
|
|
|
602
570
|
return result
|
|
@@ -604,18 +572,19 @@ export class PluginManager {
|
|
|
604
572
|
|
|
605
573
|
output = hook
|
|
606
574
|
|
|
607
|
-
this
|
|
575
|
+
this.events.emit('executed', {
|
|
576
|
+
duration: Math.round(performance.now() - startTime),
|
|
608
577
|
parameters,
|
|
609
578
|
output,
|
|
610
579
|
strategy,
|
|
611
580
|
hookName,
|
|
612
581
|
plugin,
|
|
613
|
-
message,
|
|
614
582
|
})
|
|
615
583
|
|
|
616
584
|
return hook
|
|
617
585
|
} catch (e) {
|
|
618
|
-
this
|
|
586
|
+
this.events.emit('error', e as Error, { plugin, hookName, strategy, duration: Math.round(performance.now() - startTime) })
|
|
587
|
+
|
|
619
588
|
return null
|
|
620
589
|
}
|
|
621
590
|
})()
|
|
@@ -635,13 +604,11 @@ export class PluginManager {
|
|
|
635
604
|
hookName,
|
|
636
605
|
parameters,
|
|
637
606
|
plugin,
|
|
638
|
-
message,
|
|
639
607
|
}: {
|
|
640
608
|
strategy: Strategy
|
|
641
609
|
hookName: H
|
|
642
610
|
parameters: PluginParameter<H>
|
|
643
611
|
plugin: PluginWithLifeCycle
|
|
644
|
-
message: string
|
|
645
612
|
}): ReturnType<ParseResult<H>> | null {
|
|
646
613
|
const hook = plugin[hookName]
|
|
647
614
|
let output: unknown
|
|
@@ -650,7 +617,14 @@ export class PluginManager {
|
|
|
650
617
|
return null
|
|
651
618
|
}
|
|
652
619
|
|
|
653
|
-
this.events.emit('executing', {
|
|
620
|
+
this.events.emit('executing', {
|
|
621
|
+
strategy,
|
|
622
|
+
hookName,
|
|
623
|
+
parameters,
|
|
624
|
+
plugin,
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
const startTime = performance.now()
|
|
654
628
|
|
|
655
629
|
try {
|
|
656
630
|
if (typeof hook === 'function') {
|
|
@@ -659,13 +633,13 @@ export class PluginManager {
|
|
|
659
633
|
|
|
660
634
|
output = fn
|
|
661
635
|
|
|
662
|
-
this
|
|
636
|
+
this.events.emit('executed', {
|
|
637
|
+
duration: Math.round(performance.now() - startTime),
|
|
663
638
|
parameters,
|
|
664
639
|
output,
|
|
665
640
|
strategy,
|
|
666
641
|
hookName,
|
|
667
642
|
plugin,
|
|
668
|
-
message,
|
|
669
643
|
})
|
|
670
644
|
|
|
671
645
|
return fn
|
|
@@ -673,30 +647,23 @@ export class PluginManager {
|
|
|
673
647
|
|
|
674
648
|
output = hook
|
|
675
649
|
|
|
676
|
-
this
|
|
650
|
+
this.events.emit('executed', {
|
|
651
|
+
duration: Math.round(performance.now() - startTime),
|
|
677
652
|
parameters,
|
|
678
653
|
output,
|
|
679
654
|
strategy,
|
|
680
655
|
hookName,
|
|
681
656
|
plugin,
|
|
682
|
-
message,
|
|
683
657
|
})
|
|
684
658
|
|
|
685
659
|
return hook
|
|
686
660
|
} catch (e) {
|
|
687
|
-
this
|
|
661
|
+
this.events.emit('error', e as Error, { plugin, hookName, strategy, duration: Math.round(performance.now() - startTime) })
|
|
688
662
|
|
|
689
663
|
return null
|
|
690
664
|
}
|
|
691
665
|
}
|
|
692
666
|
|
|
693
|
-
#catcher<H extends PluginLifecycleHooks>(cause: Error, plugin?: Plugin, hookName?: H) {
|
|
694
|
-
const text = `${cause.message} (plugin: ${plugin?.name || 'unknown'}, hook: ${hookName || 'unknown'})`
|
|
695
|
-
|
|
696
|
-
this.logger.emit('error', text, cause)
|
|
697
|
-
this.events.emit('error', cause)
|
|
698
|
-
}
|
|
699
|
-
|
|
700
667
|
#parse(plugin: UserPlugin): Plugin {
|
|
701
668
|
const usedPluginNames = this.#usedPluginNames
|
|
702
669
|
|