@kubb/core 3.16.2 → 3.16.4

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 (106) hide show
  1. package/dist/FileManager-Dk759iZ3.js +918 -0
  2. package/dist/FileManager-Dk759iZ3.js.map +1 -0
  3. package/dist/FileManager-DsRjYJa_.cjs +1031 -0
  4. package/dist/FileManager-DsRjYJa_.cjs.map +1 -0
  5. package/dist/PluginManager-1jPxuyQK.d.ts +511 -0
  6. package/dist/PluginManager-Cvj5AlsU.d.cts +511 -0
  7. package/dist/chunk-DWy1uDak.cjs +39 -0
  8. package/dist/chunk-DbvY3SJr.js +33 -0
  9. package/dist/fs-BacxV1CO.js +87 -0
  10. package/dist/fs-BacxV1CO.js.map +1 -0
  11. package/dist/fs-BazSaf2y.cjs +129 -0
  12. package/dist/fs-BazSaf2y.cjs.map +1 -0
  13. package/dist/fs.cjs +15 -39
  14. package/dist/fs.d.cts +2 -19
  15. package/dist/fs.d.ts +2 -19
  16. package/dist/fs.js +4 -3
  17. package/dist/index-BKHQGQVq.d.ts +140 -0
  18. package/dist/index-BfD6z1P5.d.cts +141 -0
  19. package/dist/index-Cb4pChs8.d.ts +180 -0
  20. package/dist/index-D2ptHzfn.d.cts +180 -0
  21. package/dist/index.cjs +997 -1077
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +107 -89
  24. package/dist/index.d.ts +107 -89
  25. package/dist/index.js +1020 -864
  26. package/dist/index.js.map +1 -1
  27. package/dist/logger-BxvJpQMX.cjs +1115 -0
  28. package/dist/logger-BxvJpQMX.cjs.map +1 -0
  29. package/dist/logger-Cs45J4yy.js +1085 -0
  30. package/dist/logger-Cs45J4yy.js.map +1 -0
  31. package/dist/logger-OWS6fqk0.d.cts +69 -0
  32. package/dist/logger-xcdTETKy.d.ts +69 -0
  33. package/dist/logger.cjs +6 -24
  34. package/dist/logger.d.cts +2 -3
  35. package/dist/logger.d.ts +2 -3
  36. package/dist/logger.js +4 -4
  37. package/dist/mocks.cjs +49 -65
  38. package/dist/mocks.cjs.map +1 -1
  39. package/dist/mocks.d.cts +6 -6
  40. package/dist/mocks.d.ts +6 -6
  41. package/dist/mocks.js +48 -59
  42. package/dist/mocks.js.map +1 -1
  43. package/dist/prompt-DwEAzq0q.js +853 -0
  44. package/dist/prompt-DwEAzq0q.js.map +1 -0
  45. package/dist/prompt-qiwl6Be9.cjs +855 -0
  46. package/dist/prompt-qiwl6Be9.cjs.map +1 -0
  47. package/dist/transformers-B3CHtwuB.cjs +948 -0
  48. package/dist/transformers-B3CHtwuB.cjs.map +1 -0
  49. package/dist/transformers-CJqBQFIl.js +829 -0
  50. package/dist/transformers-CJqBQFIl.js.map +1 -0
  51. package/dist/transformers.cjs +33 -88
  52. package/dist/transformers.d.cts +75 -54
  53. package/dist/transformers.d.ts +75 -54
  54. package/dist/transformers.js +4 -3
  55. package/dist/utils.cjs +20 -73
  56. package/dist/utils.d.cts +5 -126
  57. package/dist/utils.d.ts +5 -126
  58. package/dist/utils.js +6 -5
  59. package/dist/write-CLTPlucv.js +42 -0
  60. package/dist/write-CLTPlucv.js.map +1 -0
  61. package/dist/write-l_NzIqyy.cjs +48 -0
  62. package/dist/write-l_NzIqyy.cjs.map +1 -0
  63. package/package.json +25 -32
  64. package/src/BarrelManager.ts +1 -0
  65. package/src/PromiseManager.ts +1 -7
  66. package/src/build.ts +9 -11
  67. package/src/index.ts +5 -5
  68. package/src/logger.ts +10 -10
  69. package/src/utils/FunctionParams.ts +3 -1
  70. package/src/utils/TreeNode.ts +3 -1
  71. package/dist/PluginManager-E3SghPP9.d.cts +0 -458
  72. package/dist/PluginManager-PDmRCu9k.d.ts +0 -458
  73. package/dist/chunk-4V7HK7PT.js +0 -1199
  74. package/dist/chunk-4V7HK7PT.js.map +0 -1
  75. package/dist/chunk-BHSTNFNQ.cjs +0 -701
  76. package/dist/chunk-BHSTNFNQ.cjs.map +0 -1
  77. package/dist/chunk-CAZ37TGB.js +0 -918
  78. package/dist/chunk-CAZ37TGB.js.map +0 -1
  79. package/dist/chunk-E4XLCCPK.cjs +0 -170
  80. package/dist/chunk-E4XLCCPK.cjs.map +0 -1
  81. package/dist/chunk-GBYHPDPK.js +0 -595
  82. package/dist/chunk-GBYHPDPK.js.map +0 -1
  83. package/dist/chunk-L3A3DTAX.cjs +0 -1074
  84. package/dist/chunk-L3A3DTAX.cjs.map +0 -1
  85. package/dist/chunk-MCNA6SYG.cjs +0 -1231
  86. package/dist/chunk-MCNA6SYG.cjs.map +0 -1
  87. package/dist/chunk-YRPOID7E.js +0 -157
  88. package/dist/chunk-YRPOID7E.js.map +0 -1
  89. package/dist/fs.cjs.map +0 -1
  90. package/dist/fs.js.map +0 -1
  91. package/dist/logger-BWq-oJU_.d.cts +0 -63
  92. package/dist/logger-BWq-oJU_.d.ts +0 -63
  93. package/dist/logger.cjs.map +0 -1
  94. package/dist/logger.js.map +0 -1
  95. package/dist/parser-C1vOjVEd.d.ts +0 -41
  96. package/dist/parser-D6vU1kA9.d.cts +0 -41
  97. package/dist/prompt-ELTHGQK6.js +0 -753
  98. package/dist/prompt-ELTHGQK6.js.map +0 -1
  99. package/dist/prompt-U7M5G25C.cjs +0 -761
  100. package/dist/prompt-U7M5G25C.cjs.map +0 -1
  101. package/dist/transformers.cjs.map +0 -1
  102. package/dist/transformers.js.map +0 -1
  103. package/dist/types-CA8nQKwM.d.cts +0 -132
  104. package/dist/types-CA8nQKwM.d.ts +0 -132
  105. package/dist/utils.cjs.map +0 -1
  106. package/dist/utils.js.map +0 -1
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- export { setup, build, build as default, safeBuild } from './build.ts'
1
+ export { BaseGenerator } from './BaseGenerator.ts'
2
+ export { build, build as default, safeBuild, setup } from './build.ts'
2
3
  export { defineConfig, isInputPath } from './config.ts'
3
- export { FileManager, getSource } from './FileManager.ts'
4
4
  export type { FileMetaBase } from './FileManager.ts'
5
- export { BaseGenerator } from './BaseGenerator.ts'
5
+ export { FileManager, getSource } from './FileManager.ts'
6
6
  export { PackageManager } from './PackageManager.ts'
7
- export { createPlugin } from './plugin.ts'
8
7
  export { PluginManager } from './PluginManager.ts'
9
8
  export { PromiseManager } from './PromiseManager.ts'
10
- export { getDefaultBanner } from './utils'
9
+ export { createPlugin } from './plugin.ts'
11
10
  export type * from './types.ts'
11
+ export { getDefaultBanner } from './utils'
package/src/logger.ts CHANGED
@@ -1,12 +1,11 @@
1
+ import { resolve } from 'node:path'
2
+ import type { ConsolaInstance, LogLevel } from 'consola'
3
+ import { createConsola } from 'consola'
4
+ import pc from 'picocolors'
1
5
  import seedrandom from 'seedrandom'
2
- import { colors } from 'consola/utils'
3
-
6
+ import { write } from './fs/write.ts'
4
7
  import { EventEmitter } from './utils/EventEmitter.ts'
5
8
 
6
- import { resolve } from 'node:path'
7
- import { write } from './fs/index.ts'
8
- import { type ConsolaInstance, type LogLevel, createConsola } from 'consola'
9
-
10
9
  type DebugEvent = { date: Date; logs: string[]; fileName?: string }
11
10
 
12
11
  type Events = {
@@ -73,11 +72,11 @@ export function createLogger({ logLevel = 3, name, consola: _consola }: Props =
73
72
  })
74
73
 
75
74
  events.on('warning', (message) => {
76
- consola.warn(colors.yellow(message))
75
+ consola.warn(pc.yellow(message))
77
76
  })
78
77
 
79
78
  events.on('info', (message) => {
80
- consola.info(colors.yellow(message))
79
+ consola.info(pc.yellow(message))
81
80
  })
82
81
 
83
82
  events.on('debug', (message) => {
@@ -134,7 +133,7 @@ export function createLogger({ logLevel = 3, name, consola: _consola }: Props =
134
133
  return logger
135
134
  }
136
135
 
137
- export function randomColour(text?: string): keyof typeof colors {
136
+ export function randomColour(text?: string): 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' {
138
137
  if (!text) {
139
138
  return 'white'
140
139
  }
@@ -154,5 +153,6 @@ export function randomCliColour(text?: string): string {
154
153
 
155
154
  const colour = randomColour(text)
156
155
 
157
- return colors[colour]?.(text)
156
+ const fn = pc[colour]
157
+ return fn ? fn(text) : text
158
158
  }
@@ -53,7 +53,9 @@ export class FunctionParams {
53
53
  }
54
54
 
55
55
  if (Array.isArray(item)) {
56
- item.filter(Boolean).forEach((it) => this.#items.push(it))
56
+ item.filter(Boolean).forEach((it) => {
57
+ this.#items.push(it)
58
+ })
57
59
  return this
58
60
  }
59
61
  this.#items.push(item)
@@ -142,7 +142,9 @@ export class TreeNode {
142
142
  }
143
143
  }
144
144
 
145
- filteredTree.children?.forEach((child) => recurse(treeNode, child))
145
+ filteredTree.children?.forEach((child) => {
146
+ recurse(treeNode, child)
147
+ })
146
148
 
147
149
  return treeNode
148
150
  } catch (e) {
@@ -1,458 +0,0 @@
1
- import { E as Extname, B as BaseName, M as Mode, O as OptionalPath, F as File, R as ResolvedFile, P as Path } from './types-CA8nQKwM.cjs';
2
- import { L as Logger, E as EventEmitter } from './logger-BWq-oJU_.cjs';
3
-
4
- type PossiblePromise<T> = Promise<T> | T;
5
- type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
6
- type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
7
-
8
- /**
9
- * Config used in `kubb.config.ts`
10
- *
11
- * @example
12
- * import { defineConfig } from '@kubb/core'
13
- * export default defineConfig({
14
- * ...
15
- * })
16
- */
17
- type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & {
18
- /**
19
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
20
- * @default process.cwd()
21
- */
22
- root?: string;
23
- /**
24
- * An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details.
25
- */
26
- plugins?: Array<Omit<UnknownUserPlugin, 'context'>>;
27
- };
28
- type InputPath = {
29
- /**
30
- * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
31
- */
32
- path: string;
33
- };
34
- type InputData = {
35
- /**
36
- * A `string` or `object` that contains your Swagger/OpenAPI data.
37
- */
38
- data: string | unknown;
39
- };
40
- type Input = InputPath | InputData | Array<InputPath>;
41
- type BarrelType = 'all' | 'named' | 'propagate';
42
- /**
43
- * @private
44
- */
45
- type Config<TInput = Input> = {
46
- /**
47
- * The name to display in the CLI output.
48
- */
49
- name?: string;
50
- /**
51
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
52
- * @default process.cwd()
53
- */
54
- root: string;
55
- /**
56
- * You can use either `input.path` or `input.data`, depending on your specific needs.
57
- */
58
- input: TInput;
59
- output: {
60
- /**
61
- * The path where all generated files will be exported.
62
- * This can be an absolute path or a path relative to the specified root option.
63
- */
64
- path: string;
65
- /**
66
- * Clean the output directory before each build.
67
- */
68
- clean?: boolean;
69
- /**
70
- * Save files to the file system.
71
- * @default true
72
- */
73
- write?: boolean;
74
- /**
75
- * Override the extension to the generated imports and exports, by default each plugin will add an extension
76
- * @default { '.ts': '.ts'}
77
- */
78
- extension?: Record<Extname, Extname | ''>;
79
- /**
80
- * Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
81
- * @default 'named'
82
- */
83
- barrelType?: Exclude<BarrelType, 'propagate'> | false;
84
- /**
85
- * Add a default banner to the beginning of every generated file. This makes it clear that the file was generated by Kubb.
86
- * - 'simple': will only add banner with link to Kubb
87
- * - 'full': will add source, title, description and the OpenAPI version used
88
- * @default 'simple'
89
- */
90
- defaultBanner?: 'simple' | 'full' | false;
91
- };
92
- /**
93
- * An array of Kubb plugins that will be used in the generation.
94
- * Each plugin may include additional configurable options(defined in the plugin itself).
95
- * If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
96
- */
97
- plugins?: Array<Plugin>;
98
- /**
99
- * Hooks that will be called when a specific action is triggered in Kubb.
100
- */
101
- hooks?: {
102
- /**
103
- * Hook that will be triggered at the end of all executions.
104
- * Useful for running Prettier or ESLint to format/lint your code.
105
- */
106
- done?: string | Array<string>;
107
- };
108
- };
109
- type PluginFactoryOptions<
110
- /**
111
- * Name to be used for the plugin, this will also be used for they key.
112
- */
113
- TName extends string = string,
114
- /**
115
- * Options of the plugin.
116
- */
117
- TOptions extends object = object,
118
- /**
119
- * Options of the plugin that can be used later on, see `options` inside your plugin config.
120
- */
121
- TResolvedOptions extends object = TOptions,
122
- /**
123
- * Context that you want to expose to other plugins.
124
- */
125
- TContext = any,
126
- /**
127
- * When calling `resolvePath` you can specify better types.
128
- */
129
- TResolvePathOptions extends object = object> = {
130
- name: TName;
131
- /**
132
- * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
133
- */
134
- key: PluginKey<TName | string>;
135
- options: TOptions;
136
- resolvedOptions: TResolvedOptions;
137
- context: TContext;
138
- resolvePathOptions: TResolvePathOptions;
139
- };
140
- type PluginKey<TName> = [name: TName, identifier?: string | number];
141
- type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
142
- type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
143
- /**
144
- * Unique name used for the plugin
145
- * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
146
- * @example @kubb/typescript
147
- */
148
- name: TOptions['name'];
149
- /**
150
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
151
- */
152
- options: TOptions['resolvedOptions'];
153
- /**
154
- * 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.
155
- * Can be used to validate dependent plugins.
156
- */
157
- pre?: Array<string>;
158
- /**
159
- * 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.
160
- */
161
- post?: Array<string>;
162
- } & (TOptions['context'] extends never ? {
163
- context?: never;
164
- } : {
165
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
166
- });
167
- type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
168
- type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
169
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
170
- /**
171
- * Unique name used for the plugin
172
- * @example @kubb/typescript
173
- */
174
- name: TOptions['name'];
175
- /**
176
- * Internal key used when a developer uses more than one of the same plugin
177
- * @private
178
- */
179
- key: TOptions['key'];
180
- /**
181
- * 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.
182
- * Can be used to validate dependent plugins.
183
- */
184
- pre?: Array<string>;
185
- /**
186
- * 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.
187
- */
188
- post?: Array<string>;
189
- /**
190
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
191
- */
192
- options: TOptions['resolvedOptions'];
193
- } & (TOptions['context'] extends never ? {
194
- context?: never;
195
- } : {
196
- context: TOptions['context'];
197
- });
198
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
199
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
200
- /**
201
- * Start of the lifecycle of a plugin.
202
- * @type hookParallel
203
- */
204
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
205
- /**
206
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
207
- * Options can als be included.
208
- * @type hookFirst
209
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
210
- */
211
- resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
212
- /**
213
- * Resolve to a name based on a string.
214
- * Useful when converting to PascalCase or camelCase.
215
- * @type hookFirst
216
- * @example ('pet') => 'Pet'
217
- */
218
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
219
- /**
220
- * End of the plugin lifecycle.
221
- * @type hookParallel
222
- */
223
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
224
- };
225
- type PluginLifecycleHooks = keyof PluginLifecycle;
226
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
227
- type ResolvePathParams<TOptions = object> = {
228
- pluginKey?: Plugin['key'];
229
- baseName: BaseName;
230
- mode?: Mode;
231
- /**
232
- * Options to be passed to 'resolvePath' 3th parameter
233
- */
234
- options?: TOptions;
235
- };
236
- type ResolveNameParams = {
237
- name: string;
238
- pluginKey?: Plugin['key'];
239
- /**
240
- * `file` will be used to customize the name of the created file(use of camelCase)
241
- * `function` can be used to customize the exported functions(use of camelCase)
242
- * `type` is a special type for TypeScript(use of PascalCase)
243
- * `const` can be used for variables(use of camelCase)
244
- */
245
- type?: 'file' | 'function' | 'type' | 'const';
246
- };
247
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
248
- config: Config;
249
- fileManager: FileManager;
250
- pluginManager: PluginManager;
251
- addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
252
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
253
- resolveName: (params: ResolveNameParams) => string;
254
- logger: Logger;
255
- /**
256
- * All plugins
257
- */
258
- plugins: Plugin[];
259
- /**
260
- * Current plugin
261
- */
262
- plugin: Plugin<TOptions>;
263
- };
264
- /**
265
- * Specify the export location for the files and define the behavior of the output
266
- */
267
- type Output<TOptions> = {
268
- /**
269
- * Path to the output folder or file that will contain the generated code
270
- */
271
- path: string;
272
- /**
273
- * Define what needs to be exported, here you can also disable the export of barrel files
274
- * @default 'named'
275
- */
276
- barrelType?: BarrelType | false;
277
- /**
278
- * Add a banner text in the beginning of every file
279
- */
280
- banner?: string | ((options: TOptions) => string);
281
- /**
282
- * Add a footer text in the beginning of every file
283
- */
284
- footer?: string | ((options: TOptions) => string);
285
- };
286
- type GroupContext = {
287
- group: string;
288
- };
289
- type Group = {
290
- /**
291
- * Define a type where to group the files on
292
- */
293
- type: 'tag' | 'path';
294
- /**
295
- * Return the name of a group based on the group name, this will be used for the file and name generation
296
- */
297
- name?: (context: GroupContext) => string;
298
- };
299
-
300
- type FileMetaBase = {
301
- pluginKey?: Plugin['key'];
302
- };
303
- type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
304
- type AddIndexesProps = {
305
- type: BarrelType | false | undefined;
306
- /**
307
- * Root based on root and output.path specified in the config
308
- */
309
- root: string;
310
- /**
311
- * Output for plugin
312
- */
313
- output: {
314
- path: string;
315
- };
316
- group?: {
317
- output: string;
318
- exportAs: string;
319
- };
320
- logger?: Logger;
321
- meta?: FileMetaBase;
322
- };
323
- type WriteFilesProps = {
324
- root: Config['root'];
325
- extension?: Record<Extname, Extname | ''>;
326
- logger?: Logger;
327
- dryRun?: boolean;
328
- };
329
- declare class FileManager {
330
- #private;
331
- constructor();
332
- add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
333
- getByPath(path: Path): Promise<ResolvedFile | null>;
334
- deleteByPath(path: Path): Promise<void>;
335
- clear(): Promise<void>;
336
- getFiles(): Promise<Array<ResolvedFile>>;
337
- processFiles({ dryRun, root, extension, logger }: WriteFilesProps): Promise<Array<ResolvedFile>>;
338
- getBarrelFiles({ type, meta, root, output, logger }: AddIndexesProps): Promise<File[]>;
339
- static getMode(path: string | undefined | null): Mode;
340
- }
341
- type GetSourceOptions = {
342
- extname?: Extname;
343
- logger?: Logger;
344
- };
345
- declare function getSource<TMeta extends FileMetaBase = FileMetaBase>(file: ResolvedFile<TMeta>, { logger, extname }?: GetSourceOptions): Promise<string>;
346
-
347
- type RequiredPluginLifecycle = Required<PluginLifecycle>;
348
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
349
- type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
350
- message: string;
351
- strategy: Strategy;
352
- hookName: H;
353
- plugin: Plugin;
354
- parameters?: unknown[] | undefined;
355
- output?: unknown;
356
- };
357
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
358
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
359
- result: Result;
360
- plugin: Plugin;
361
- };
362
- type Options = {
363
- logger: Logger;
364
- /**
365
- * @default Number.POSITIVE_INFINITY
366
- */
367
- concurrency?: number;
368
- };
369
- type Events = {
370
- executing: [executer: Executer];
371
- executed: [executer: Executer];
372
- error: [error: Error];
373
- };
374
- type GetFileProps<TOptions = object> = {
375
- name: string;
376
- mode?: Mode;
377
- extname: Extname;
378
- pluginKey: Plugin['key'];
379
- options?: TOptions;
380
- };
381
- declare class PluginManager {
382
- #private;
383
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
384
- readonly fileManager: FileManager;
385
- readonly events: EventEmitter<Events>;
386
- readonly config: Config;
387
- readonly executed: Array<Executer>;
388
- readonly logger: Logger;
389
- readonly options: Options;
390
- constructor(config: Config, options: Options);
391
- getFile<TOptions = object>({ name, mode, extname, pluginKey, options }: GetFileProps<TOptions>): File<{
392
- pluginKey: Plugin['key'];
393
- }>;
394
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
395
- resolveName: (params: ResolveNameParams) => string;
396
- /**
397
- * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
398
- */
399
- on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
400
- /**
401
- * Run a specific hookName for plugin x.
402
- */
403
- hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, message, }: {
404
- pluginKey: Plugin['key'];
405
- hookName: H;
406
- parameters: PluginParameter<H>;
407
- message: string;
408
- }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
409
- /**
410
- * Run a specific hookName for plugin x.
411
- */
412
- hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, message, }: {
413
- pluginKey: Plugin['key'];
414
- hookName: H;
415
- parameters: PluginParameter<H>;
416
- message: string;
417
- }): Array<ReturnType<ParseResult<H>>> | null;
418
- /**
419
- * First non-null result stops and will return it's value.
420
- */
421
- hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, message, }: {
422
- hookName: H;
423
- parameters: PluginParameter<H>;
424
- skipped?: ReadonlySet<Plugin> | null;
425
- message: string;
426
- }): Promise<SafeParseResult<H>>;
427
- /**
428
- * First non-null result stops and will return it's value.
429
- */
430
- hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, message, }: {
431
- hookName: H;
432
- parameters: PluginParameter<H>;
433
- skipped?: ReadonlySet<Plugin> | null;
434
- message: string;
435
- }): SafeParseResult<H>;
436
- /**
437
- * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
438
- */
439
- hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, message, }: {
440
- hookName: H;
441
- parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
442
- message: string;
443
- }): Promise<Awaited<TOuput>[]>;
444
- /**
445
- * Chains plugins
446
- */
447
- hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters, message, }: {
448
- hookName: H;
449
- parameters?: PluginParameter<H>;
450
- message: string;
451
- }): Promise<void>;
452
- getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
453
- getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
454
- static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>]>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
455
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
456
- }
457
-
458
- export { type BarrelType as B, type Config as C, FileManager as F, type GetPluginFactoryOptions as G, type InputPath as I, type Output as O, PluginManager as P, type ResolvePathParams as R, type UserConfig as U, type PossiblePromise as a, type PluginFactoryOptions as b, type UserPluginWithLifeCycle as c, type FileMetaBase as d, type InputData as e, type PluginKey as f, getSource as g, type UserPlugin as h, type Plugin as i, type PluginWithLifeCycle as j, type PluginLifecycle as k, type PluginLifecycleHooks as l, type PluginParameter as m, type ResolveNameParams as n, type PluginContext as o, type Group as p };