@kubb/core 1.0.0-beta.4 → 1.0.0-beta.5
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/index.cjs +187 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +84 -24
- package/dist/index.js +187 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/build.ts +24 -7
- package/src/managers/pluginManager/PluginManager.ts +199 -60
- package/src/plugin.ts +9 -4
- package/src/types.ts +32 -14
- package/src/utils/jsdoc.ts +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -105,9 +105,9 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
105
105
|
*/
|
|
106
106
|
options?: TOptions['options'];
|
|
107
107
|
} & Partial<PluginLifecycle<TOptions>>;
|
|
108
|
-
type PluginFactoryOptions<Options = unknown, Nested extends boolean = false, Api = any,
|
|
108
|
+
type PluginFactoryOptions<Options = unknown, Nested extends boolean = false, Api = any, resolvePathOptions = Record<string, any>> = {
|
|
109
109
|
options: Options;
|
|
110
|
-
|
|
110
|
+
resolvePathOptions: resolvePathOptions;
|
|
111
111
|
nested: Nested;
|
|
112
112
|
api: Api;
|
|
113
113
|
};
|
|
@@ -123,13 +123,21 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
123
123
|
*/
|
|
124
124
|
buildStart: (this: PluginContext, kubbConfig: KubbConfig) => MaybePromise<void>;
|
|
125
125
|
/**
|
|
126
|
-
* Resolve to
|
|
126
|
+
* Resolve to a Path based on a fileName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
127
|
+
* Options can als be included.
|
|
127
128
|
* @type hookFirst
|
|
128
|
-
* @example ('./Pet.ts', './src/gen/')
|
|
129
|
+
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
129
130
|
*/
|
|
130
|
-
|
|
131
|
+
resolvePath: (this: Omit<PluginContext, 'addFile'>, fileName: string, directory?: string, options?: TOptions['resolvePathOptions']) => OptionalPath;
|
|
131
132
|
/**
|
|
132
|
-
*
|
|
133
|
+
* Resolve to a name based on a string.
|
|
134
|
+
* Useful when converting to PascalCase or camelCase.
|
|
135
|
+
* @type hookFirst
|
|
136
|
+
* @example ('pet') => 'Pet'
|
|
137
|
+
*/
|
|
138
|
+
resolveName: (this: Omit<PluginContext, 'addFile'>, name: string) => string | null;
|
|
139
|
+
/**
|
|
140
|
+
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
133
141
|
* @type hookFirst
|
|
134
142
|
*/
|
|
135
143
|
load: (this: Omit<PluginContext, 'addFile'>, path: Path) => MaybePromise<TransformResult | null>;
|
|
@@ -139,7 +147,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
139
147
|
*/
|
|
140
148
|
transform: (this: Omit<PluginContext, 'addFile'>, source: string, path: Path) => MaybePromise<TransformResult>;
|
|
141
149
|
/**
|
|
142
|
-
* Write the result to the file-system based on the id(defined by `
|
|
150
|
+
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
143
151
|
* @type hookParallel
|
|
144
152
|
*/
|
|
145
153
|
writeFile: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: Path) => MaybePromise<void>;
|
|
@@ -150,25 +158,34 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
150
158
|
buildEnd: (this: Omit<PluginContext, 'addFile'>) => MaybePromise<void>;
|
|
151
159
|
};
|
|
152
160
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
153
|
-
type
|
|
154
|
-
fileName: string;
|
|
155
|
-
directory?: string | undefined;
|
|
161
|
+
type ResolvePathParams<TOptions = Record<string, any>> = {
|
|
156
162
|
/**
|
|
157
|
-
* When set,
|
|
158
|
-
* If not defined it will fall back on the
|
|
163
|
+
* When set, resolvePath will only call resolvePath of the name of the plugin set here.
|
|
164
|
+
* If not defined it will fall back on the resolvePath of the core plugin.
|
|
159
165
|
*/
|
|
160
166
|
pluginName?: string;
|
|
167
|
+
fileName: string;
|
|
168
|
+
directory?: string | undefined;
|
|
161
169
|
/**
|
|
162
|
-
* Options to be passed to '
|
|
170
|
+
* Options to be passed to 'resolvePath' 3th parameter
|
|
163
171
|
*/
|
|
164
172
|
options?: TOptions;
|
|
165
173
|
};
|
|
174
|
+
type ResolveNameParams = {
|
|
175
|
+
/**
|
|
176
|
+
* When set, resolvePath will only call resolvePath of the name of the plugin set here.
|
|
177
|
+
* If not defined it will fall back on the resolvePath of the core plugin.
|
|
178
|
+
*/
|
|
179
|
+
pluginName?: string;
|
|
180
|
+
name: string;
|
|
181
|
+
};
|
|
166
182
|
type PluginContext<TOptions = Record<string, any>> = {
|
|
167
183
|
config: KubbConfig;
|
|
168
184
|
cache: Cache;
|
|
169
185
|
fileManager: FileManager;
|
|
170
186
|
addFile: (file: File) => Promise<File>;
|
|
171
|
-
|
|
187
|
+
resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
188
|
+
resolveName: (params: ResolveNameParams) => string | null;
|
|
172
189
|
load: (id: string) => MaybePromise<TransformResult | void>;
|
|
173
190
|
};
|
|
174
191
|
type TransformResult = string | null;
|
|
@@ -204,8 +221,8 @@ declare function nameSorter<T extends {
|
|
|
204
221
|
}>(a: T, b: T): 0 | 1 | -1;
|
|
205
222
|
|
|
206
223
|
declare function createJSDocBlockText({ comments }: {
|
|
207
|
-
comments: Array<string
|
|
208
|
-
}): string
|
|
224
|
+
comments: Array<string>;
|
|
225
|
+
}): string;
|
|
209
226
|
|
|
210
227
|
declare function getUniqueName(originalName: string, data: Record<string, number>): string;
|
|
211
228
|
|
|
@@ -322,7 +339,8 @@ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOpti
|
|
|
322
339
|
type Options = {
|
|
323
340
|
config: PluginContext['config'];
|
|
324
341
|
fileManager: FileManager;
|
|
325
|
-
|
|
342
|
+
resolvePath: PluginContext['resolvePath'];
|
|
343
|
+
resolveName: PluginContext['resolveName'];
|
|
326
344
|
load: PluginContext['load'];
|
|
327
345
|
};
|
|
328
346
|
type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>;
|
|
@@ -347,14 +365,56 @@ declare class PluginManager {
|
|
|
347
365
|
logger?: Logger;
|
|
348
366
|
task: QueueTask;
|
|
349
367
|
});
|
|
350
|
-
|
|
368
|
+
resolvePath: (params: ResolvePathParams) => OptionalPath;
|
|
369
|
+
resolveName: (params: ResolveNameParams) => string | null;
|
|
351
370
|
load: (id: string) => Promise<TransformResult>;
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
371
|
+
/**
|
|
372
|
+
*
|
|
373
|
+
* Run only hook for a specific plugin name
|
|
374
|
+
*/
|
|
375
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
|
|
376
|
+
pluginName: string;
|
|
377
|
+
hookName: H;
|
|
378
|
+
parameters: Parameters<PluginLifecycle[H]>;
|
|
379
|
+
}): Promise<ReturnType<PluginLifecycle[H]> | null>;
|
|
380
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
|
|
381
|
+
pluginName: string;
|
|
382
|
+
hookName: H;
|
|
383
|
+
parameters: Parameters<PluginLifecycle[H]>;
|
|
384
|
+
}): ReturnType<PluginLifecycle[H]> | null;
|
|
385
|
+
/**
|
|
386
|
+
*
|
|
387
|
+
* Chains, first non-null result stops and returns
|
|
388
|
+
*/
|
|
389
|
+
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
390
|
+
hookName: H;
|
|
391
|
+
parameters: Parameters<PluginLifecycle[H]>;
|
|
392
|
+
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
393
|
+
}): Promise<ReturnType<PluginLifecycle[H]> | null>;
|
|
394
|
+
/**
|
|
395
|
+
*
|
|
396
|
+
* Chains, first non-null result stops and returns
|
|
397
|
+
*/
|
|
398
|
+
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
399
|
+
hookName: H;
|
|
400
|
+
parameters: Parameters<PluginLifecycle[H]>;
|
|
401
|
+
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
402
|
+
}): ReturnType<PluginLifecycle[H]> | null;
|
|
403
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
404
|
+
hookName: H;
|
|
405
|
+
parameters?: Parameters<PluginLifecycle[H]> | undefined;
|
|
406
|
+
}): Promise<Awaited<TOuput>[]>;
|
|
407
|
+
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
408
|
+
hookName: H;
|
|
409
|
+
parameters: Parameters<PluginLifecycle[H]>;
|
|
410
|
+
reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>;
|
|
411
|
+
}): Promise<Argument0<H>>;
|
|
412
|
+
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
413
|
+
hookName: H;
|
|
414
|
+
parameters?: Parameters<PluginLifecycle[H]>;
|
|
415
|
+
}): Promise<void>;
|
|
357
416
|
private getSortedPlugins;
|
|
417
|
+
private getPlugin;
|
|
358
418
|
/**
|
|
359
419
|
* Run an async plugin hook and return the result.
|
|
360
420
|
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
@@ -395,4 +455,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
395
455
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
396
456
|
}
|
|
397
457
|
|
|
398
|
-
export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, File, FileManager, FileName, Generator, KubbBuild, KubbConfig, KubbJSONPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PathMode, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, Queue, QueueTask,
|
|
458
|
+
export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, File, FileManager, FileName, Generator, KubbBuild, KubbConfig, KubbJSONPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PathMode, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, Queue, QueueTask, ResolveNameParams, ResolvePathParams, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, build as default, defineConfig, getFileSource, getPathMode, getRelativePath, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, timeout, validatePlugins, write };
|
package/dist/index.js
CHANGED
|
@@ -139,7 +139,7 @@ function nameSorter(a, b) {
|
|
|
139
139
|
function createJSDocBlockText({ comments }) {
|
|
140
140
|
const filteredComments = comments.filter(Boolean);
|
|
141
141
|
if (!filteredComments.length) {
|
|
142
|
-
return
|
|
142
|
+
return "";
|
|
143
143
|
}
|
|
144
144
|
const text = filteredComments.reduce((acc, comment) => {
|
|
145
145
|
return `${acc}
|
|
@@ -214,7 +214,7 @@ function createPlugin(factory) {
|
|
|
214
214
|
}
|
|
215
215
|
var name = "core";
|
|
216
216
|
var definePlugin = createPlugin((options) => {
|
|
217
|
-
const { fileManager,
|
|
217
|
+
const { fileManager, resolvePath, resolveName, load } = options;
|
|
218
218
|
const api = {
|
|
219
219
|
get config() {
|
|
220
220
|
return options.config;
|
|
@@ -223,7 +223,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
223
223
|
async addFile(file) {
|
|
224
224
|
return fileManager.addOrAppend(file);
|
|
225
225
|
},
|
|
226
|
-
|
|
226
|
+
resolvePath,
|
|
227
|
+
resolveName,
|
|
227
228
|
load,
|
|
228
229
|
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
229
230
|
};
|
|
@@ -231,11 +232,14 @@ var definePlugin = createPlugin((options) => {
|
|
|
231
232
|
name,
|
|
232
233
|
options,
|
|
233
234
|
api,
|
|
234
|
-
|
|
235
|
+
resolvePath(fileName, directory) {
|
|
235
236
|
if (!directory) {
|
|
236
237
|
return null;
|
|
237
238
|
}
|
|
238
239
|
return pathParser2.resolve(directory, fileName);
|
|
240
|
+
},
|
|
241
|
+
resolveName(name2) {
|
|
242
|
+
return name2;
|
|
239
243
|
}
|
|
240
244
|
};
|
|
241
245
|
});
|
|
@@ -457,7 +461,8 @@ ${file.source}`;
|
|
|
457
461
|
var hookNames = {
|
|
458
462
|
validate: 1,
|
|
459
463
|
buildStart: 1,
|
|
460
|
-
|
|
464
|
+
resolvePath: 1,
|
|
465
|
+
resolveName: 1,
|
|
461
466
|
load: 1,
|
|
462
467
|
transform: 1,
|
|
463
468
|
writeFile: 1,
|
|
@@ -480,95 +485,196 @@ var PluginManager = class {
|
|
|
480
485
|
config,
|
|
481
486
|
fileManager: this.fileManager,
|
|
482
487
|
load: this.load,
|
|
483
|
-
|
|
488
|
+
resolvePath: this.resolvePath,
|
|
489
|
+
resolveName: this.resolveName
|
|
484
490
|
});
|
|
485
491
|
this.plugins = [this.core, ...config.plugins || []];
|
|
486
492
|
}
|
|
487
|
-
|
|
493
|
+
resolvePath = (params) => {
|
|
494
|
+
if (params.pluginName) {
|
|
495
|
+
return this.hookForPluginSync({
|
|
496
|
+
pluginName: params.pluginName,
|
|
497
|
+
hookName: "resolvePath",
|
|
498
|
+
parameters: [params.fileName, params.directory, params.options]
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
return this.hookFirstSync({
|
|
502
|
+
hookName: "resolvePath",
|
|
503
|
+
parameters: [params.fileName, params.directory, params.options]
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
resolveName = (params) => {
|
|
488
507
|
if (params.pluginName) {
|
|
489
|
-
return this.
|
|
508
|
+
return this.hookForPluginSync({
|
|
509
|
+
pluginName: params.pluginName,
|
|
510
|
+
hookName: "resolveName",
|
|
511
|
+
parameters: [params.name]
|
|
512
|
+
});
|
|
490
513
|
}
|
|
491
|
-
return this.
|
|
514
|
+
return this.hookFirstSync({
|
|
515
|
+
hookName: "resolveName",
|
|
516
|
+
parameters: [params.name]
|
|
517
|
+
});
|
|
492
518
|
};
|
|
493
519
|
load = async (id) => {
|
|
494
|
-
return this.hookFirst(
|
|
520
|
+
return this.hookFirst({
|
|
521
|
+
hookName: "load",
|
|
522
|
+
parameters: [id]
|
|
523
|
+
});
|
|
495
524
|
};
|
|
496
|
-
|
|
497
|
-
|
|
525
|
+
/**
|
|
526
|
+
*
|
|
527
|
+
* Run only hook for a specific plugin name
|
|
528
|
+
*/
|
|
529
|
+
hookForPlugin({
|
|
530
|
+
pluginName,
|
|
531
|
+
hookName,
|
|
532
|
+
parameters
|
|
533
|
+
}) {
|
|
534
|
+
const plugin = this.getPlugin(hookName, pluginName);
|
|
535
|
+
return this.run({
|
|
536
|
+
strategy: "hookFirst",
|
|
537
|
+
hookName,
|
|
538
|
+
parameters,
|
|
539
|
+
plugin
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
hookForPluginSync({
|
|
543
|
+
pluginName,
|
|
544
|
+
hookName,
|
|
545
|
+
parameters
|
|
546
|
+
}) {
|
|
547
|
+
const plugin = this.getPlugin(hookName, pluginName);
|
|
548
|
+
return this.runSync({
|
|
549
|
+
strategy: "hookFirst",
|
|
550
|
+
hookName,
|
|
551
|
+
parameters,
|
|
552
|
+
plugin
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
*
|
|
557
|
+
* Chains, first non-null result stops and returns
|
|
558
|
+
*/
|
|
559
|
+
hookFirst({
|
|
560
|
+
hookName,
|
|
561
|
+
parameters,
|
|
562
|
+
skipped
|
|
563
|
+
}) {
|
|
498
564
|
let promise = Promise.resolve(null);
|
|
499
|
-
for (const plugin of this.getSortedPlugins(hookName
|
|
565
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
500
566
|
if (skipped && skipped.has(plugin))
|
|
501
567
|
continue;
|
|
502
568
|
promise = promise.then((result) => {
|
|
503
569
|
if (result != null)
|
|
504
570
|
return result;
|
|
505
|
-
return this.run(
|
|
571
|
+
return this.run({
|
|
572
|
+
strategy: "hookFirst",
|
|
573
|
+
hookName,
|
|
574
|
+
parameters,
|
|
575
|
+
plugin
|
|
576
|
+
});
|
|
506
577
|
});
|
|
507
578
|
}
|
|
508
579
|
return promise;
|
|
509
580
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
581
|
+
/**
|
|
582
|
+
*
|
|
583
|
+
* Chains, first non-null result stops and returns
|
|
584
|
+
*/
|
|
585
|
+
hookFirstSync({
|
|
586
|
+
hookName,
|
|
587
|
+
parameters,
|
|
588
|
+
skipped
|
|
589
|
+
}) {
|
|
590
|
+
let result = null;
|
|
513
591
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
514
592
|
if (skipped && skipped.has(plugin))
|
|
515
593
|
continue;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
594
|
+
result = this.runSync({
|
|
595
|
+
strategy: "hookFirst",
|
|
596
|
+
hookName,
|
|
597
|
+
parameters,
|
|
598
|
+
plugin
|
|
520
599
|
});
|
|
600
|
+
if (result != null) {
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
521
603
|
}
|
|
522
|
-
return
|
|
604
|
+
return result;
|
|
523
605
|
}
|
|
524
606
|
// parallel
|
|
525
|
-
async hookParallel(
|
|
607
|
+
async hookParallel({
|
|
608
|
+
hookName,
|
|
609
|
+
parameters
|
|
610
|
+
}) {
|
|
526
611
|
const parallelPromises = [];
|
|
527
612
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
528
613
|
if (plugin[hookName]?.sequential) {
|
|
529
614
|
await Promise.all(parallelPromises);
|
|
530
615
|
parallelPromises.length = 0;
|
|
531
|
-
await this.run(
|
|
616
|
+
await this.run({
|
|
617
|
+
strategy: "hookParallel",
|
|
618
|
+
hookName,
|
|
619
|
+
parameters,
|
|
620
|
+
plugin
|
|
621
|
+
});
|
|
532
622
|
} else {
|
|
533
|
-
const promise = this.run("hookParallel", hookName, parameters, plugin);
|
|
623
|
+
const promise = this.run({ strategy: "hookParallel", hookName, parameters, plugin });
|
|
534
624
|
parallelPromises.push(promise);
|
|
535
625
|
}
|
|
536
626
|
}
|
|
537
627
|
return Promise.all(parallelPromises);
|
|
538
628
|
}
|
|
539
629
|
// chains, reduces returned value, handling the reduced value as the first hook argument
|
|
540
|
-
hookReduceArg0(
|
|
630
|
+
hookReduceArg0({
|
|
631
|
+
hookName,
|
|
632
|
+
parameters,
|
|
633
|
+
reduce
|
|
634
|
+
}) {
|
|
635
|
+
const [argument0, ...rest] = parameters;
|
|
541
636
|
let promise = Promise.resolve(argument0);
|
|
542
637
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
543
638
|
promise = promise.then(
|
|
544
|
-
(argument02) => this.run(
|
|
545
|
-
|
|
546
|
-
|
|
639
|
+
(argument02) => this.run({
|
|
640
|
+
strategy: "hookReduceArg0",
|
|
641
|
+
hookName,
|
|
642
|
+
parameters: [argument02, ...rest],
|
|
643
|
+
plugin
|
|
644
|
+
}).then((result) => reduce.call(this.core.api, argument02, result, plugin))
|
|
547
645
|
);
|
|
548
646
|
}
|
|
549
647
|
return promise;
|
|
550
648
|
}
|
|
551
649
|
// chains
|
|
552
|
-
hookSeq(hookName, parameters) {
|
|
650
|
+
hookSeq({ hookName, parameters }) {
|
|
553
651
|
let promise = Promise.resolve();
|
|
554
652
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
555
|
-
promise = promise.then(
|
|
653
|
+
promise = promise.then(
|
|
654
|
+
() => this.run({
|
|
655
|
+
strategy: "hookSeq",
|
|
656
|
+
hookName,
|
|
657
|
+
parameters,
|
|
658
|
+
plugin
|
|
659
|
+
})
|
|
660
|
+
);
|
|
556
661
|
}
|
|
557
662
|
return promise.then(noReturn);
|
|
558
663
|
}
|
|
559
|
-
getSortedPlugins(
|
|
664
|
+
getSortedPlugins(_hookName) {
|
|
560
665
|
const plugins = [...this.plugins];
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
666
|
+
return plugins;
|
|
667
|
+
}
|
|
668
|
+
getPlugin(hookName, pluginName) {
|
|
669
|
+
const plugins = [...this.plugins];
|
|
670
|
+
const pluginByPluginName = plugins.find((item) => item.name === pluginName && item[hookName]);
|
|
671
|
+
if (!pluginByPluginName) {
|
|
672
|
+
if (this.config.logLevel === "warn" && this.logger?.spinner) {
|
|
673
|
+
this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`);
|
|
568
674
|
}
|
|
569
|
-
return
|
|
675
|
+
return this.core;
|
|
570
676
|
}
|
|
571
|
-
return
|
|
677
|
+
return pluginByPluginName;
|
|
572
678
|
}
|
|
573
679
|
/**
|
|
574
680
|
* Run an async plugin hook and return the result.
|
|
@@ -577,7 +683,12 @@ var PluginManager = class {
|
|
|
577
683
|
* @param plugin The actual pluginObject to run.
|
|
578
684
|
*/
|
|
579
685
|
// Implementation signature
|
|
580
|
-
run(
|
|
686
|
+
run({
|
|
687
|
+
strategy,
|
|
688
|
+
hookName,
|
|
689
|
+
parameters,
|
|
690
|
+
plugin
|
|
691
|
+
}) {
|
|
581
692
|
const hook = plugin[hookName];
|
|
582
693
|
return Promise.resolve().then(() => {
|
|
583
694
|
if (typeof hook !== "function") {
|
|
@@ -613,12 +724,21 @@ var PluginManager = class {
|
|
|
613
724
|
* @param plugin The acutal plugin
|
|
614
725
|
* @param replaceContext When passed, the plugin context can be overridden.
|
|
615
726
|
*/
|
|
616
|
-
runSync(
|
|
727
|
+
runSync({
|
|
728
|
+
strategy,
|
|
729
|
+
hookName,
|
|
730
|
+
parameters,
|
|
731
|
+
plugin
|
|
732
|
+
}) {
|
|
617
733
|
const hook = plugin[hookName];
|
|
618
734
|
try {
|
|
735
|
+
if (typeof hook !== "function") {
|
|
736
|
+
return hook;
|
|
737
|
+
}
|
|
619
738
|
return hook.apply(this.core.api, parameters);
|
|
620
|
-
} catch (
|
|
621
|
-
|
|
739
|
+
} catch (e) {
|
|
740
|
+
this.catcher(e, plugin, hookName);
|
|
741
|
+
return null;
|
|
622
742
|
}
|
|
623
743
|
}
|
|
624
744
|
catcher(e, plugin, hookName) {
|
|
@@ -664,22 +784,38 @@ async function buildImplementation(options, done) {
|
|
|
664
784
|
const queueTask = async (id, file) => {
|
|
665
785
|
const { path } = file;
|
|
666
786
|
let code = getFileSource(file);
|
|
667
|
-
const loadedResult = await pluginManager.hookFirst(
|
|
787
|
+
const loadedResult = await pluginManager.hookFirst({
|
|
788
|
+
hookName: "load",
|
|
789
|
+
parameters: [path]
|
|
790
|
+
});
|
|
668
791
|
if (loadedResult) {
|
|
669
792
|
code = loadedResult;
|
|
670
793
|
}
|
|
671
794
|
if (code) {
|
|
672
|
-
const transformedCode = await pluginManager.hookReduceArg0(
|
|
795
|
+
const transformedCode = await pluginManager.hookReduceArg0({
|
|
796
|
+
hookName: "transform",
|
|
797
|
+
parameters: [code, path],
|
|
798
|
+
reduce: transformReducer
|
|
799
|
+
});
|
|
673
800
|
if (config.output.write || config.output.write === void 0) {
|
|
674
|
-
await pluginManager.hookParallel(
|
|
801
|
+
await pluginManager.hookParallel({
|
|
802
|
+
hookName: "writeFile",
|
|
803
|
+
parameters: [transformedCode, path]
|
|
804
|
+
});
|
|
675
805
|
}
|
|
676
806
|
}
|
|
677
807
|
};
|
|
678
808
|
const pluginManager = new PluginManager(config, { logger, task: queueTask });
|
|
679
809
|
const { plugins, fileManager } = pluginManager;
|
|
680
|
-
await pluginManager.hookParallel(
|
|
681
|
-
|
|
682
|
-
|
|
810
|
+
await pluginManager.hookParallel({
|
|
811
|
+
hookName: "validate",
|
|
812
|
+
parameters: [plugins]
|
|
813
|
+
});
|
|
814
|
+
await pluginManager.hookParallel({
|
|
815
|
+
hookName: "buildStart",
|
|
816
|
+
parameters: [config]
|
|
817
|
+
});
|
|
818
|
+
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
683
819
|
setTimeout(() => {
|
|
684
820
|
done({ files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) });
|
|
685
821
|
}, 500);
|