@kubb/core 2.0.0-alpha.9 → 2.0.0-beta.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/README.md +1 -1
- package/dist/index.cjs +34 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -48
- package/dist/index.d.ts +35 -48
- package/dist/index.js +34 -26
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +9 -10
- package/src/FileManager.ts +7 -7
- package/src/PluginManager.ts +32 -30
- package/src/PromiseManager.ts +5 -1
- package/src/build.ts +0 -10
- package/src/plugin.ts +4 -4
- package/src/types.ts +22 -39
- package/src/utils/executeStrategies.ts +14 -2
package/dist/index.d.cts
CHANGED
|
@@ -167,7 +167,7 @@ declare class PluginManager {
|
|
|
167
167
|
}): Promise<void>;
|
|
168
168
|
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
169
169
|
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
|
|
170
|
-
static get hooks(): readonly ["
|
|
170
|
+
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
interface Cache<TStore extends object = object> {
|
|
@@ -282,7 +282,6 @@ type CLIOptions = {
|
|
|
282
282
|
*/
|
|
283
283
|
logLevel?: LogLevel;
|
|
284
284
|
};
|
|
285
|
-
type KubbPluginKind = 'schema' | 'controller';
|
|
286
285
|
type KubbUnionPlugins = PluginUnion;
|
|
287
286
|
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
288
287
|
type PluginFactoryOptions<
|
|
@@ -290,10 +289,6 @@ type PluginFactoryOptions<
|
|
|
290
289
|
* Name to be used for the plugin, this will also be used for they key.
|
|
291
290
|
*/
|
|
292
291
|
TName extends string = string,
|
|
293
|
-
/**
|
|
294
|
-
* @type "schema" | "controller"
|
|
295
|
-
*/
|
|
296
|
-
TKind extends KubbPluginKind = KubbPluginKind,
|
|
297
292
|
/**
|
|
298
293
|
* Options of the plugin.
|
|
299
294
|
*/
|
|
@@ -316,53 +311,47 @@ TResolvePathOptions extends object = object,
|
|
|
316
311
|
*/
|
|
317
312
|
TAppMeta = unknown> = {
|
|
318
313
|
name: TName;
|
|
319
|
-
kind: TKind;
|
|
320
314
|
/**
|
|
321
315
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
322
316
|
*/
|
|
323
|
-
key: [
|
|
317
|
+
key: [name: TName | string, identifier?: string | number];
|
|
324
318
|
options: TOptions;
|
|
325
319
|
resolvedOptions: TResolvedOptions;
|
|
326
320
|
api: TAPI;
|
|
327
321
|
resolvePathOptions: TResolvePathOptions;
|
|
328
322
|
appMeta: {
|
|
329
323
|
pluginManager: PluginManager;
|
|
330
|
-
plugin: KubbPlugin<PluginFactoryOptions<TName,
|
|
324
|
+
plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>;
|
|
331
325
|
} & TAppMeta;
|
|
332
326
|
};
|
|
333
327
|
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
334
328
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
335
329
|
/**
|
|
336
330
|
* Unique name used for the plugin
|
|
331
|
+
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
337
332
|
* @example @kubb/typescript
|
|
338
333
|
*/
|
|
339
334
|
name: TOptions['name'];
|
|
340
|
-
/**
|
|
341
|
-
* Internal key used when a developer uses more than one of the same plugin
|
|
342
|
-
* @private
|
|
343
|
-
*/
|
|
344
|
-
key?: TOptions['key'];
|
|
345
335
|
/**
|
|
346
336
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
347
337
|
*/
|
|
348
338
|
options: TOptions['resolvedOptions'];
|
|
339
|
+
/**
|
|
340
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
341
|
+
* Can be used to validate depended plugins.
|
|
342
|
+
*/
|
|
343
|
+
pre?: Array<string>;
|
|
344
|
+
/**
|
|
345
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
346
|
+
*/
|
|
347
|
+
post?: Array<string>;
|
|
349
348
|
} & (TOptions['api'] extends never ? {
|
|
350
349
|
api?: never;
|
|
351
350
|
} : {
|
|
352
351
|
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
353
|
-
}) & (TOptions['kind'] extends never ? {
|
|
354
|
-
kind?: never;
|
|
355
|
-
} : {
|
|
356
|
-
/**
|
|
357
|
-
* Kind/type for the plugin
|
|
358
|
-
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
359
|
-
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
360
|
-
* @default undefined
|
|
361
|
-
*/
|
|
362
|
-
kind: TOptions['kind'];
|
|
363
352
|
});
|
|
364
353
|
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
365
|
-
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any
|
|
354
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any>>;
|
|
366
355
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
367
356
|
/**
|
|
368
357
|
* Unique name used for the plugin
|
|
@@ -375,16 +364,18 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
375
364
|
*/
|
|
376
365
|
key: TOptions['key'];
|
|
377
366
|
/**
|
|
378
|
-
*
|
|
367
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
368
|
+
* Can be used to validate depended plugins.
|
|
379
369
|
*/
|
|
380
|
-
|
|
370
|
+
pre?: Array<string>;
|
|
381
371
|
/**
|
|
382
|
-
*
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
372
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
373
|
+
*/
|
|
374
|
+
post?: Array<string>;
|
|
375
|
+
/**
|
|
376
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
386
377
|
*/
|
|
387
|
-
|
|
378
|
+
options: TOptions['resolvedOptions'];
|
|
388
379
|
} & (TOptions['api'] extends never ? {
|
|
389
380
|
api?: never;
|
|
390
381
|
} : {
|
|
@@ -392,11 +383,6 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
392
383
|
});
|
|
393
384
|
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
394
385
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
395
|
-
/**
|
|
396
|
-
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
397
|
-
* @type hookParallel
|
|
398
|
-
*/
|
|
399
|
-
validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
|
|
400
386
|
/**
|
|
401
387
|
* Start of the lifecycle of a plugin.
|
|
402
388
|
* @type hookParallel
|
|
@@ -485,7 +471,7 @@ declare namespace KubbFile {
|
|
|
485
471
|
/**
|
|
486
472
|
* Import name to be used
|
|
487
473
|
* @example ["useState"]
|
|
488
|
-
* @
|
|
474
|
+
* @example "React"
|
|
489
475
|
*/
|
|
490
476
|
name: string | Array<string>;
|
|
491
477
|
/**
|
|
@@ -494,28 +480,28 @@ declare namespace KubbFile {
|
|
|
494
480
|
*/
|
|
495
481
|
path: string;
|
|
496
482
|
/**
|
|
497
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'
|
|
483
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
498
484
|
*/
|
|
499
485
|
isTypeOnly?: boolean;
|
|
500
486
|
};
|
|
501
487
|
type Export = {
|
|
502
488
|
/**
|
|
503
|
-
* Export name to be used
|
|
489
|
+
* Export name to be used.
|
|
504
490
|
* @example ["useState"]
|
|
505
|
-
* @
|
|
491
|
+
* @example "React"
|
|
506
492
|
*/
|
|
507
493
|
name?: string | Array<string>;
|
|
508
494
|
/**
|
|
509
|
-
* Path for the import
|
|
495
|
+
* Path for the import.
|
|
510
496
|
* @xample '@kubb/core'
|
|
511
497
|
*/
|
|
512
498
|
path: string;
|
|
513
499
|
/**
|
|
514
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'
|
|
500
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
515
501
|
*/
|
|
516
502
|
isTypeOnly?: boolean;
|
|
517
503
|
/**
|
|
518
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'
|
|
504
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
519
505
|
*/
|
|
520
506
|
asAlias?: boolean;
|
|
521
507
|
};
|
|
@@ -702,12 +688,13 @@ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
702
688
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
703
689
|
declare const pluginName = "core";
|
|
704
690
|
|
|
705
|
-
type PromiseFunc$1<T = unknown, T2 = never> = (state
|
|
691
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
706
692
|
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
707
693
|
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
708
694
|
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
709
|
-
type
|
|
710
|
-
type
|
|
695
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
696
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
697
|
+
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
711
698
|
|
|
712
699
|
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
713
700
|
type Options<TState = any> = {
|
|
@@ -736,4 +723,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
736
723
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
737
724
|
type Plugin = keyof Plugins;
|
|
738
725
|
|
|
739
|
-
export { CLIOptions, FileManager, Generator, GetPluginFactoryOptions, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin,
|
|
726
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, SchemaGenerator, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.d.ts
CHANGED
|
@@ -167,7 +167,7 @@ declare class PluginManager {
|
|
|
167
167
|
}): Promise<void>;
|
|
168
168
|
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
169
169
|
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
|
|
170
|
-
static get hooks(): readonly ["
|
|
170
|
+
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
interface Cache<TStore extends object = object> {
|
|
@@ -282,7 +282,6 @@ type CLIOptions = {
|
|
|
282
282
|
*/
|
|
283
283
|
logLevel?: LogLevel;
|
|
284
284
|
};
|
|
285
|
-
type KubbPluginKind = 'schema' | 'controller';
|
|
286
285
|
type KubbUnionPlugins = PluginUnion;
|
|
287
286
|
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
288
287
|
type PluginFactoryOptions<
|
|
@@ -290,10 +289,6 @@ type PluginFactoryOptions<
|
|
|
290
289
|
* Name to be used for the plugin, this will also be used for they key.
|
|
291
290
|
*/
|
|
292
291
|
TName extends string = string,
|
|
293
|
-
/**
|
|
294
|
-
* @type "schema" | "controller"
|
|
295
|
-
*/
|
|
296
|
-
TKind extends KubbPluginKind = KubbPluginKind,
|
|
297
292
|
/**
|
|
298
293
|
* Options of the plugin.
|
|
299
294
|
*/
|
|
@@ -316,53 +311,47 @@ TResolvePathOptions extends object = object,
|
|
|
316
311
|
*/
|
|
317
312
|
TAppMeta = unknown> = {
|
|
318
313
|
name: TName;
|
|
319
|
-
kind: TKind;
|
|
320
314
|
/**
|
|
321
315
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
322
316
|
*/
|
|
323
|
-
key: [
|
|
317
|
+
key: [name: TName | string, identifier?: string | number];
|
|
324
318
|
options: TOptions;
|
|
325
319
|
resolvedOptions: TResolvedOptions;
|
|
326
320
|
api: TAPI;
|
|
327
321
|
resolvePathOptions: TResolvePathOptions;
|
|
328
322
|
appMeta: {
|
|
329
323
|
pluginManager: PluginManager;
|
|
330
|
-
plugin: KubbPlugin<PluginFactoryOptions<TName,
|
|
324
|
+
plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>;
|
|
331
325
|
} & TAppMeta;
|
|
332
326
|
};
|
|
333
327
|
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
334
328
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
335
329
|
/**
|
|
336
330
|
* Unique name used for the plugin
|
|
331
|
+
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
337
332
|
* @example @kubb/typescript
|
|
338
333
|
*/
|
|
339
334
|
name: TOptions['name'];
|
|
340
|
-
/**
|
|
341
|
-
* Internal key used when a developer uses more than one of the same plugin
|
|
342
|
-
* @private
|
|
343
|
-
*/
|
|
344
|
-
key?: TOptions['key'];
|
|
345
335
|
/**
|
|
346
336
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
347
337
|
*/
|
|
348
338
|
options: TOptions['resolvedOptions'];
|
|
339
|
+
/**
|
|
340
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
341
|
+
* Can be used to validate depended plugins.
|
|
342
|
+
*/
|
|
343
|
+
pre?: Array<string>;
|
|
344
|
+
/**
|
|
345
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
346
|
+
*/
|
|
347
|
+
post?: Array<string>;
|
|
349
348
|
} & (TOptions['api'] extends never ? {
|
|
350
349
|
api?: never;
|
|
351
350
|
} : {
|
|
352
351
|
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
353
|
-
}) & (TOptions['kind'] extends never ? {
|
|
354
|
-
kind?: never;
|
|
355
|
-
} : {
|
|
356
|
-
/**
|
|
357
|
-
* Kind/type for the plugin
|
|
358
|
-
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
359
|
-
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
360
|
-
* @default undefined
|
|
361
|
-
*/
|
|
362
|
-
kind: TOptions['kind'];
|
|
363
352
|
});
|
|
364
353
|
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
365
|
-
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any
|
|
354
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any>>;
|
|
366
355
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
367
356
|
/**
|
|
368
357
|
* Unique name used for the plugin
|
|
@@ -375,16 +364,18 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
375
364
|
*/
|
|
376
365
|
key: TOptions['key'];
|
|
377
366
|
/**
|
|
378
|
-
*
|
|
367
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
368
|
+
* Can be used to validate depended plugins.
|
|
379
369
|
*/
|
|
380
|
-
|
|
370
|
+
pre?: Array<string>;
|
|
381
371
|
/**
|
|
382
|
-
*
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
372
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
373
|
+
*/
|
|
374
|
+
post?: Array<string>;
|
|
375
|
+
/**
|
|
376
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
386
377
|
*/
|
|
387
|
-
|
|
378
|
+
options: TOptions['resolvedOptions'];
|
|
388
379
|
} & (TOptions['api'] extends never ? {
|
|
389
380
|
api?: never;
|
|
390
381
|
} : {
|
|
@@ -392,11 +383,6 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
392
383
|
});
|
|
393
384
|
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
394
385
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
395
|
-
/**
|
|
396
|
-
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
397
|
-
* @type hookParallel
|
|
398
|
-
*/
|
|
399
|
-
validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
|
|
400
386
|
/**
|
|
401
387
|
* Start of the lifecycle of a plugin.
|
|
402
388
|
* @type hookParallel
|
|
@@ -485,7 +471,7 @@ declare namespace KubbFile {
|
|
|
485
471
|
/**
|
|
486
472
|
* Import name to be used
|
|
487
473
|
* @example ["useState"]
|
|
488
|
-
* @
|
|
474
|
+
* @example "React"
|
|
489
475
|
*/
|
|
490
476
|
name: string | Array<string>;
|
|
491
477
|
/**
|
|
@@ -494,28 +480,28 @@ declare namespace KubbFile {
|
|
|
494
480
|
*/
|
|
495
481
|
path: string;
|
|
496
482
|
/**
|
|
497
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'
|
|
483
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
498
484
|
*/
|
|
499
485
|
isTypeOnly?: boolean;
|
|
500
486
|
};
|
|
501
487
|
type Export = {
|
|
502
488
|
/**
|
|
503
|
-
* Export name to be used
|
|
489
|
+
* Export name to be used.
|
|
504
490
|
* @example ["useState"]
|
|
505
|
-
* @
|
|
491
|
+
* @example "React"
|
|
506
492
|
*/
|
|
507
493
|
name?: string | Array<string>;
|
|
508
494
|
/**
|
|
509
|
-
* Path for the import
|
|
495
|
+
* Path for the import.
|
|
510
496
|
* @xample '@kubb/core'
|
|
511
497
|
*/
|
|
512
498
|
path: string;
|
|
513
499
|
/**
|
|
514
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'
|
|
500
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
515
501
|
*/
|
|
516
502
|
isTypeOnly?: boolean;
|
|
517
503
|
/**
|
|
518
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'
|
|
504
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
519
505
|
*/
|
|
520
506
|
asAlias?: boolean;
|
|
521
507
|
};
|
|
@@ -702,12 +688,13 @@ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
702
688
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
703
689
|
declare const pluginName = "core";
|
|
704
690
|
|
|
705
|
-
type PromiseFunc$1<T = unknown, T2 = never> = (state
|
|
691
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
706
692
|
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
707
693
|
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
708
694
|
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
709
|
-
type
|
|
710
|
-
type
|
|
695
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
696
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
697
|
+
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
711
698
|
|
|
712
699
|
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
713
700
|
type Options<TState = any> = {
|
|
@@ -736,4 +723,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
736
723
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
737
724
|
type Plugin = keyof Plugins;
|
|
738
725
|
|
|
739
|
-
export { CLIOptions, FileManager, Generator, GetPluginFactoryOptions, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin,
|
|
726
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, SchemaGenerator, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.js
CHANGED
|
@@ -1127,8 +1127,7 @@ var definePlugin = createPlugin((options) => {
|
|
|
1127
1127
|
return {
|
|
1128
1128
|
name: pluginName,
|
|
1129
1129
|
options,
|
|
1130
|
-
key: ["
|
|
1131
|
-
kind: "controller",
|
|
1130
|
+
key: ["core"],
|
|
1132
1131
|
api() {
|
|
1133
1132
|
return {
|
|
1134
1133
|
get config() {
|
|
@@ -1195,6 +1194,9 @@ function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
|
1195
1194
|
}
|
|
1196
1195
|
return promise;
|
|
1197
1196
|
}
|
|
1197
|
+
function hookParallel(promises) {
|
|
1198
|
+
return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
|
|
1199
|
+
}
|
|
1198
1200
|
|
|
1199
1201
|
// src/PromiseManager.ts
|
|
1200
1202
|
var _options2;
|
|
@@ -1211,6 +1213,9 @@ var PromiseManager = class {
|
|
|
1211
1213
|
if (strategy === "first") {
|
|
1212
1214
|
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1213
1215
|
}
|
|
1216
|
+
if (strategy === "parallel") {
|
|
1217
|
+
return hookParallel(promises);
|
|
1218
|
+
}
|
|
1214
1219
|
throw new Error(`${strategy} not implemented`);
|
|
1215
1220
|
}
|
|
1216
1221
|
};
|
|
@@ -1415,14 +1420,10 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1415
1420
|
hookName,
|
|
1416
1421
|
parameters
|
|
1417
1422
|
}) {
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
parallelPromises.push(promise);
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
const results = await Promise.allSettled(parallelPromises);
|
|
1423
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1424
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1425
|
+
});
|
|
1426
|
+
const results = await __privateGet(this, _promiseManager).run("parallel", promises);
|
|
1426
1427
|
results.forEach((result, index) => {
|
|
1427
1428
|
if (isPromiseRejectedResult(result)) {
|
|
1428
1429
|
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
@@ -1470,16 +1471,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1470
1471
|
}
|
|
1471
1472
|
getPluginsByKey(hookName, pluginKey) {
|
|
1472
1473
|
const plugins = [...this.plugins];
|
|
1473
|
-
const [
|
|
1474
|
+
const [searchPluginName, searchIdentifier] = pluginKey;
|
|
1474
1475
|
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1475
|
-
const [
|
|
1476
|
+
const [name, identifier] = item.key;
|
|
1476
1477
|
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1477
|
-
const kindCheck = kind === searchKind;
|
|
1478
1478
|
const nameCheck = name === searchPluginName;
|
|
1479
1479
|
if (searchIdentifier) {
|
|
1480
|
-
return identifierCheck &&
|
|
1480
|
+
return identifierCheck && nameCheck;
|
|
1481
1481
|
}
|
|
1482
|
-
return
|
|
1482
|
+
return nameCheck;
|
|
1483
1483
|
});
|
|
1484
1484
|
if (!pluginByPluginName?.length) {
|
|
1485
1485
|
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
@@ -1511,7 +1511,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1511
1511
|
}
|
|
1512
1512
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1513
1513
|
static get hooks() {
|
|
1514
|
-
return ["
|
|
1514
|
+
return ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1515
1515
|
}
|
|
1516
1516
|
};
|
|
1517
1517
|
_core = new WeakMap();
|
|
@@ -1529,7 +1529,23 @@ getSortedPlugins_fn = function(hookName) {
|
|
|
1529
1529
|
}
|
|
1530
1530
|
return plugins.filter((item) => item[hookName]);
|
|
1531
1531
|
}
|
|
1532
|
-
return plugins
|
|
1532
|
+
return plugins.map((plugin) => {
|
|
1533
|
+
if (plugin.pre) {
|
|
1534
|
+
const isValid = plugin.pre.every((pluginName2) => plugins.find((pluginToFind) => pluginToFind.name === pluginName2));
|
|
1535
|
+
if (!isValid) {
|
|
1536
|
+
throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return plugin;
|
|
1540
|
+
}).sort((a, b) => {
|
|
1541
|
+
if (b.pre?.includes(a.name)) {
|
|
1542
|
+
return 1;
|
|
1543
|
+
}
|
|
1544
|
+
if (b.post?.includes(a.name)) {
|
|
1545
|
+
return -1;
|
|
1546
|
+
}
|
|
1547
|
+
return 0;
|
|
1548
|
+
});
|
|
1533
1549
|
};
|
|
1534
1550
|
_addExecutedToCallStack = new WeakSet();
|
|
1535
1551
|
addExecutedToCallStack_fn = function(executer) {
|
|
@@ -1620,7 +1636,7 @@ _parse = new WeakSet();
|
|
|
1620
1636
|
parse_fn = function(plugin, pluginManager, context) {
|
|
1621
1637
|
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1622
1638
|
setUniqueName(plugin.name, usedPluginNames);
|
|
1623
|
-
const key =
|
|
1639
|
+
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1624
1640
|
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1625
1641
|
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1626
1642
|
}
|
|
@@ -1743,10 +1759,6 @@ ${code}`);
|
|
|
1743
1759
|
async function build(options) {
|
|
1744
1760
|
const pluginManager = await setup(options);
|
|
1745
1761
|
const { fileManager, logger } = pluginManager;
|
|
1746
|
-
await pluginManager.hookParallel({
|
|
1747
|
-
hookName: "validate",
|
|
1748
|
-
parameters: [pluginManager.plugins]
|
|
1749
|
-
});
|
|
1750
1762
|
await pluginManager.hookParallel({
|
|
1751
1763
|
hookName: "buildStart",
|
|
1752
1764
|
parameters: [options.config]
|
|
@@ -1762,10 +1774,6 @@ async function safeBuild(options) {
|
|
|
1762
1774
|
const pluginManager = await setup(options);
|
|
1763
1775
|
const { fileManager, logger } = pluginManager;
|
|
1764
1776
|
try {
|
|
1765
|
-
await pluginManager.hookParallel({
|
|
1766
|
-
hookName: "validate",
|
|
1767
|
-
parameters: [pluginManager.plugins]
|
|
1768
|
-
});
|
|
1769
1777
|
await pluginManager.hookParallel({
|
|
1770
1778
|
hookName: "buildStart",
|
|
1771
1779
|
parameters: [options.config]
|