@kubb/core 3.16.2 → 3.16.3

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
@@ -0,0 +1,511 @@
1
+ import { BaseName, Extname, File, Mode, OptionalPath, Path, ResolvedFile } from "./index-BfD6z1P5.cjs";
2
+ import { EventEmitter, Logger } from "./logger-OWS6fqk0.cjs";
3
+
4
+ //#region src/utils/types.d.ts
5
+ type PossiblePromise<T> = Promise<T> | T;
6
+ type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
7
+ type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
8
+ //#endregion
9
+ //#region src/types.d.ts
10
+ /**
11
+ * Config used in `kubb.config.ts`
12
+ *
13
+ * @example
14
+ * import { defineConfig } from '@kubb/core'
15
+ * export default defineConfig({
16
+ * ...
17
+ * })
18
+ */
19
+ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & {
20
+ /**
21
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
22
+ * @default process.cwd()
23
+ */
24
+ root?: string;
25
+ /**
26
+ * 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.
27
+ */
28
+ plugins?: Array<Omit<UnknownUserPlugin, 'context'>>;
29
+ };
30
+ type InputPath = {
31
+ /**
32
+ * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
33
+ */
34
+ path: string;
35
+ };
36
+ type InputData = {
37
+ /**
38
+ * A `string` or `object` that contains your Swagger/OpenAPI data.
39
+ */
40
+ data: string | unknown;
41
+ };
42
+ type Input = InputPath | InputData | Array<InputPath>;
43
+ type BarrelType = 'all' | 'named' | 'propagate';
44
+ /**
45
+ * @private
46
+ */
47
+ type Config<TInput = Input> = {
48
+ /**
49
+ * The name to display in the CLI output.
50
+ */
51
+ name?: string;
52
+ /**
53
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
54
+ * @default process.cwd()
55
+ */
56
+ root: string;
57
+ /**
58
+ * You can use either `input.path` or `input.data`, depending on your specific needs.
59
+ */
60
+ input: TInput;
61
+ output: {
62
+ /**
63
+ * The path where all generated files will be exported.
64
+ * This can be an absolute path or a path relative to the specified root option.
65
+ */
66
+ path: string;
67
+ /**
68
+ * Clean the output directory before each build.
69
+ */
70
+ clean?: boolean;
71
+ /**
72
+ * Save files to the file system.
73
+ * @default true
74
+ */
75
+ write?: boolean;
76
+ /**
77
+ * Override the extension to the generated imports and exports, by default each plugin will add an extension
78
+ * @default { '.ts': '.ts'}
79
+ */
80
+ extension?: Record<Extname, Extname | ''>;
81
+ /**
82
+ * 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`.
83
+ * @default 'named'
84
+ */
85
+ barrelType?: Exclude<BarrelType, 'propagate'> | false;
86
+ /**
87
+ * Add a default banner to the beginning of every generated file. This makes it clear that the file was generated by Kubb.
88
+ * - 'simple': will only add banner with link to Kubb
89
+ * - 'full': will add source, title, description and the OpenAPI version used
90
+ * @default 'simple'
91
+ */
92
+ defaultBanner?: 'simple' | 'full' | false;
93
+ };
94
+ /**
95
+ * An array of Kubb plugins that will be used in the generation.
96
+ * Each plugin may include additional configurable options(defined in the plugin itself).
97
+ * If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
98
+ */
99
+ plugins?: Array<Plugin>;
100
+ /**
101
+ * Hooks that will be called when a specific action is triggered in Kubb.
102
+ */
103
+ hooks?: {
104
+ /**
105
+ * Hook that will be triggered at the end of all executions.
106
+ * Useful for running Prettier or ESLint to format/lint your code.
107
+ */
108
+ done?: string | Array<string>;
109
+ };
110
+ };
111
+ type PluginFactoryOptions<
112
+ /**
113
+ * Name to be used for the plugin, this will also be used for they key.
114
+ */
115
+ TName extends string = string,
116
+ /**
117
+ * Options of the plugin.
118
+ */
119
+ TOptions extends object = object,
120
+ /**
121
+ * Options of the plugin that can be used later on, see `options` inside your plugin config.
122
+ */
123
+ TResolvedOptions extends object = TOptions,
124
+ /**
125
+ * Context that you want to expose to other plugins.
126
+ */
127
+ TContext = any,
128
+ /**
129
+ * When calling `resolvePath` you can specify better types.
130
+ */
131
+ TResolvePathOptions extends object = object> = {
132
+ name: TName;
133
+ /**
134
+ * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
135
+ */
136
+ key: PluginKey<TName | string>;
137
+ options: TOptions;
138
+ resolvedOptions: TResolvedOptions;
139
+ context: TContext;
140
+ resolvePathOptions: TResolvePathOptions;
141
+ };
142
+ type PluginKey<TName> = [name: TName, identifier?: string | number];
143
+ type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
144
+ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
145
+ /**
146
+ * Unique name used for the plugin
147
+ * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
148
+ * @example @kubb/typescript
149
+ */
150
+ name: TOptions['name'];
151
+ /**
152
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
153
+ */
154
+ options: TOptions['resolvedOptions'];
155
+ /**
156
+ * 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.
157
+ * Can be used to validate dependent plugins.
158
+ */
159
+ pre?: Array<string>;
160
+ /**
161
+ * 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.
162
+ */
163
+ post?: Array<string>;
164
+ } & (TOptions['context'] extends never ? {
165
+ context?: never;
166
+ } : {
167
+ context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
168
+ });
169
+ type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
170
+ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
171
+ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
172
+ /**
173
+ * Unique name used for the plugin
174
+ * @example @kubb/typescript
175
+ */
176
+ name: TOptions['name'];
177
+ /**
178
+ * Internal key used when a developer uses more than one of the same plugin
179
+ * @private
180
+ */
181
+ key: TOptions['key'];
182
+ /**
183
+ * 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.
184
+ * Can be used to validate dependent plugins.
185
+ */
186
+ pre?: Array<string>;
187
+ /**
188
+ * 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.
189
+ */
190
+ post?: Array<string>;
191
+ /**
192
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
193
+ */
194
+ options: TOptions['resolvedOptions'];
195
+ } & (TOptions['context'] extends never ? {
196
+ context?: never;
197
+ } : {
198
+ context: TOptions['context'];
199
+ });
200
+ type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
201
+ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
202
+ /**
203
+ * Start of the lifecycle of a plugin.
204
+ * @type hookParallel
205
+ */
206
+ buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
207
+ /**
208
+ * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
209
+ * Options can als be included.
210
+ * @type hookFirst
211
+ * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
212
+ */
213
+ resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
214
+ /**
215
+ * Resolve to a name based on a string.
216
+ * Useful when converting to PascalCase or camelCase.
217
+ * @type hookFirst
218
+ * @example ('pet') => 'Pet'
219
+ */
220
+ resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
221
+ /**
222
+ * End of the plugin lifecycle.
223
+ * @type hookParallel
224
+ */
225
+ buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
226
+ };
227
+ type PluginLifecycleHooks = keyof PluginLifecycle;
228
+ type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
229
+ type ResolvePathParams<TOptions = object> = {
230
+ pluginKey?: Plugin['key'];
231
+ baseName: BaseName;
232
+ mode?: Mode;
233
+ /**
234
+ * Options to be passed to 'resolvePath' 3th parameter
235
+ */
236
+ options?: TOptions;
237
+ };
238
+ type ResolveNameParams = {
239
+ name: string;
240
+ pluginKey?: Plugin['key'];
241
+ /**
242
+ * `file` will be used to customize the name of the created file(use of camelCase)
243
+ * `function` can be used to customize the exported functions(use of camelCase)
244
+ * `type` is a special type for TypeScript(use of PascalCase)
245
+ * `const` can be used for variables(use of camelCase)
246
+ */
247
+ type?: 'file' | 'function' | 'type' | 'const';
248
+ };
249
+ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
250
+ config: Config;
251
+ fileManager: FileManager;
252
+ pluginManager: PluginManager;
253
+ addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
254
+ resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
255
+ resolveName: (params: ResolveNameParams) => string;
256
+ logger: Logger;
257
+ /**
258
+ * All plugins
259
+ */
260
+ plugins: Plugin[];
261
+ /**
262
+ * Current plugin
263
+ */
264
+ plugin: Plugin<TOptions>;
265
+ };
266
+ /**
267
+ * Specify the export location for the files and define the behavior of the output
268
+ */
269
+ type Output<TOptions> = {
270
+ /**
271
+ * Path to the output folder or file that will contain the generated code
272
+ */
273
+ path: string;
274
+ /**
275
+ * Define what needs to be exported, here you can also disable the export of barrel files
276
+ * @default 'named'
277
+ */
278
+ barrelType?: BarrelType | false;
279
+ /**
280
+ * Add a banner text in the beginning of every file
281
+ */
282
+ banner?: string | ((options: TOptions) => string);
283
+ /**
284
+ * Add a footer text in the beginning of every file
285
+ */
286
+ footer?: string | ((options: TOptions) => string);
287
+ };
288
+ type GroupContext = {
289
+ group: string;
290
+ };
291
+ type Group = {
292
+ /**
293
+ * Define a type where to group the files on
294
+ */
295
+ type: 'tag' | 'path';
296
+ /**
297
+ * Return the name of a group based on the group name, this will be used for the file and name generation
298
+ */
299
+ name?: (context: GroupContext) => string;
300
+ };
301
+ //#endregion
302
+ //#region src/FileManager.d.ts
303
+ type FileMetaBase = {
304
+ pluginKey?: Plugin['key'];
305
+ };
306
+ type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
307
+ type AddIndexesProps = {
308
+ type: BarrelType | false | undefined;
309
+ /**
310
+ * Root based on root and output.path specified in the config
311
+ */
312
+ root: string;
313
+ /**
314
+ * Output for plugin
315
+ */
316
+ output: {
317
+ path: string;
318
+ };
319
+ group?: {
320
+ output: string;
321
+ exportAs: string;
322
+ };
323
+ logger?: Logger;
324
+ meta?: FileMetaBase;
325
+ };
326
+ type WriteFilesProps = {
327
+ root: Config['root'];
328
+ extension?: Record<Extname, Extname | ''>;
329
+ logger?: Logger;
330
+ dryRun?: boolean;
331
+ };
332
+ declare class FileManager {
333
+ #private;
334
+ constructor();
335
+ add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
336
+ getByPath(path: Path): Promise<ResolvedFile | null>;
337
+ deleteByPath(path: Path): Promise<void>;
338
+ clear(): Promise<void>;
339
+ getFiles(): Promise<Array<ResolvedFile>>;
340
+ processFiles({
341
+ dryRun,
342
+ root,
343
+ extension,
344
+ logger
345
+ }: WriteFilesProps): Promise<Array<ResolvedFile>>;
346
+ getBarrelFiles({
347
+ type,
348
+ meta,
349
+ root,
350
+ output,
351
+ logger
352
+ }: AddIndexesProps): Promise<File[]>;
353
+ static getMode(path: string | undefined | null): Mode;
354
+ }
355
+ type GetSourceOptions = {
356
+ extname?: Extname;
357
+ logger?: Logger;
358
+ };
359
+ declare function getSource<TMeta extends FileMetaBase = FileMetaBase>(file: ResolvedFile<TMeta>, {
360
+ logger,
361
+ extname
362
+ }?: GetSourceOptions): Promise<string>;
363
+ //#endregion
364
+ //#region src/PluginManager.d.ts
365
+ type RequiredPluginLifecycle = Required<PluginLifecycle>;
366
+ type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
367
+ type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
368
+ message: string;
369
+ strategy: Strategy;
370
+ hookName: H;
371
+ plugin: Plugin;
372
+ parameters?: unknown[] | undefined;
373
+ output?: unknown;
374
+ };
375
+ type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
376
+ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
377
+ result: Result;
378
+ plugin: Plugin;
379
+ };
380
+ type Options = {
381
+ logger: Logger;
382
+ /**
383
+ * @default Number.POSITIVE_INFINITY
384
+ */
385
+ concurrency?: number;
386
+ };
387
+ type Events = {
388
+ executing: [executer: Executer];
389
+ executed: [executer: Executer];
390
+ error: [error: Error];
391
+ };
392
+ type GetFileProps<TOptions = object> = {
393
+ name: string;
394
+ mode?: Mode;
395
+ extname: Extname;
396
+ pluginKey: Plugin['key'];
397
+ options?: TOptions;
398
+ };
399
+ declare class PluginManager {
400
+ #private;
401
+ readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
402
+ readonly fileManager: FileManager;
403
+ readonly events: EventEmitter<Events>;
404
+ readonly config: Config;
405
+ readonly executed: Array<Executer>;
406
+ readonly logger: Logger;
407
+ readonly options: Options;
408
+ constructor(config: Config, options: Options);
409
+ getFile<TOptions = object>({
410
+ name,
411
+ mode,
412
+ extname,
413
+ pluginKey,
414
+ options
415
+ }: GetFileProps<TOptions>): File<{
416
+ pluginKey: Plugin['key'];
417
+ }>;
418
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => OptionalPath;
419
+ resolveName: (params: ResolveNameParams) => string;
420
+ /**
421
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
422
+ */
423
+ on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
424
+ /**
425
+ * Run a specific hookName for plugin x.
426
+ */
427
+ hookForPlugin<H extends PluginLifecycleHooks>({
428
+ pluginKey,
429
+ hookName,
430
+ parameters,
431
+ message
432
+ }: {
433
+ pluginKey: Plugin['key'];
434
+ hookName: H;
435
+ parameters: PluginParameter<H>;
436
+ message: string;
437
+ }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
438
+ /**
439
+ * Run a specific hookName for plugin x.
440
+ */
441
+ hookForPluginSync<H extends PluginLifecycleHooks>({
442
+ pluginKey,
443
+ hookName,
444
+ parameters,
445
+ message
446
+ }: {
447
+ pluginKey: Plugin['key'];
448
+ hookName: H;
449
+ parameters: PluginParameter<H>;
450
+ message: string;
451
+ }): Array<ReturnType<ParseResult<H>>> | null;
452
+ /**
453
+ * First non-null result stops and will return it's value.
454
+ */
455
+ hookFirst<H extends PluginLifecycleHooks>({
456
+ hookName,
457
+ parameters,
458
+ skipped,
459
+ message
460
+ }: {
461
+ hookName: H;
462
+ parameters: PluginParameter<H>;
463
+ skipped?: ReadonlySet<Plugin> | null;
464
+ message: string;
465
+ }): Promise<SafeParseResult<H>>;
466
+ /**
467
+ * First non-null result stops and will return it's value.
468
+ */
469
+ hookFirstSync<H extends PluginLifecycleHooks>({
470
+ hookName,
471
+ parameters,
472
+ skipped,
473
+ message
474
+ }: {
475
+ hookName: H;
476
+ parameters: PluginParameter<H>;
477
+ skipped?: ReadonlySet<Plugin> | null;
478
+ message: string;
479
+ }): SafeParseResult<H>;
480
+ /**
481
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
482
+ */
483
+ hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
484
+ hookName,
485
+ parameters,
486
+ message
487
+ }: {
488
+ hookName: H;
489
+ parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
490
+ message: string;
491
+ }): Promise<Awaited<TOuput>[]>;
492
+ /**
493
+ * Chains plugins
494
+ */
495
+ hookSeq<H extends PluginLifecycleHooks>({
496
+ hookName,
497
+ parameters,
498
+ message
499
+ }: {
500
+ hookName: H;
501
+ parameters?: PluginParameter<H>;
502
+ message: string;
503
+ }): Promise<void>;
504
+ getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
505
+ getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
506
+ 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;
507
+ static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
508
+ }
509
+ //#endregion
510
+ export { BarrelType, Config, FileManager, FileMetaBase, GetPluginFactoryOptions, Group, InputData, InputPath, Output, Plugin, PluginContext, PluginFactoryOptions, PluginKey, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, PossiblePromise, ResolveNameParams, ResolvePathParams, UserConfig, UserPlugin, UserPluginWithLifeCycle, getSource };
511
+ //# sourceMappingURL=PluginManager-Cvj5AlsU.d.cts.map
@@ -0,0 +1,39 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+
26
+ //#endregion
27
+
28
+ Object.defineProperty(exports, '__commonJS', {
29
+ enumerable: true,
30
+ get: function () {
31
+ return __commonJS;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, '__toESM', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return __toESM;
38
+ }
39
+ });
@@ -0,0 +1,33 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod$1) => function() {
9
+ return mod$1 || (0, cb[__getOwnPropNames(cb)[0]])((mod$1 = { exports: {} }).exports, mod$1), mod$1.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all) __defProp(target, name, {
13
+ get: all[name],
14
+ enumerable: true
15
+ });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
+ key = keys[i];
20
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
+ get: ((k) => from[k]).bind(null, key),
22
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
+ });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod$1, isNodeMode, target) => (target = mod$1 != null ? __create(__getProtoOf(mod$1)) : {}, __copyProps(isNodeMode || !mod$1 || !mod$1.__esModule ? __defProp(target, "default", {
28
+ value: mod$1,
29
+ enumerable: true
30
+ }) : target, mod$1));
31
+
32
+ //#endregion
33
+ export { __commonJS, __export, __toESM };
@@ -0,0 +1,87 @@
1
+ import { normalize, relative } from "node:path";
2
+ import fs from "fs-extra";
3
+ import { switcher } from "js-runtime";
4
+
5
+ //#region src/fs/clean.ts
6
+ async function clean(path$1) {
7
+ return fs.remove(path$1);
8
+ }
9
+
10
+ //#endregion
11
+ //#region src/fs/read.ts
12
+ const reader$1 = switcher({
13
+ node: async (path$1) => {
14
+ return fs.readFile(path$1, { encoding: "utf8" });
15
+ },
16
+ bun: async (path$1) => {
17
+ const file = Bun.file(path$1);
18
+ return file.text();
19
+ }
20
+ }, "node");
21
+ const syncReader$1 = switcher({
22
+ node: (path$1) => {
23
+ return fs.readFileSync(path$1, { encoding: "utf8" });
24
+ },
25
+ bun: () => {
26
+ throw new Error("Bun cannot read sync");
27
+ }
28
+ }, "node");
29
+ async function read(path$1) {
30
+ return reader$1(path$1);
31
+ }
32
+ function readSync(path$1) {
33
+ return syncReader$1(path$1);
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/fs/exists.ts
38
+ const reader = switcher({
39
+ node: async (path$1) => {
40
+ return fs.pathExists(path$1);
41
+ },
42
+ bun: async (path$1) => {
43
+ const file = Bun.file(path$1);
44
+ return file.exists();
45
+ }
46
+ }, "node");
47
+ const syncReader = switcher({
48
+ node: (path$1) => {
49
+ return fs.pathExistsSync(path$1);
50
+ },
51
+ bun: () => {
52
+ throw new Error("Bun cannot read sync");
53
+ }
54
+ }, "node");
55
+ async function exists(path$1) {
56
+ return reader(path$1);
57
+ }
58
+
59
+ //#endregion
60
+ //#region src/fs/utils.ts
61
+ function slash(path$1, platform = "linux") {
62
+ const isWindowsPath = /^\\\\\?\\/.test(path$1);
63
+ const normalizedPath = normalize(path$1);
64
+ if (["linux", "mac"].includes(platform) && !isWindowsPath) return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
65
+ return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
66
+ }
67
+ function getRelativePath(rootDir, filePath, platform = "linux") {
68
+ if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
69
+ const relativePath = relative(rootDir, filePath);
70
+ const slashedPath = slash(relativePath, platform);
71
+ if (slashedPath.startsWith("../")) return slashedPath;
72
+ return `./${slashedPath}`;
73
+ }
74
+
75
+ //#endregion
76
+ //#region src/fs/types.ts
77
+ var types_exports = {};
78
+
79
+ //#endregion
80
+ //#region src/fs/index.ts
81
+ function trimExtName(text) {
82
+ return text.replace(/\.[^/.]+$/, "");
83
+ }
84
+
85
+ //#endregion
86
+ export { clean, exists, getRelativePath, read, readSync, trimExtName, types_exports };
87
+ //# sourceMappingURL=fs-BacxV1CO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-BacxV1CO.js","names":["path: string","path","reader","path: string","path","syncReader","path: string","path","path: string","platform: 'windows' | 'mac' | 'linux'","path","rootDir?: string | null","filePath?: string | null","text: string"],"sources":["../src/fs/clean.ts","../src/fs/read.ts","../src/fs/exists.ts","../src/fs/utils.ts","../src/fs/types.ts","../src/fs/index.ts"],"sourcesContent":["import fs from 'fs-extra'\n\nexport async function clean(path: string): Promise<void> {\n return fs.remove(path)\n}\n","import fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.readFile(path, { encoding: 'utf8' })\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.text()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.readFileSync(path, { encoding: 'utf8' })\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function read(path: string): Promise<string> {\n return reader(path)\n}\n\nexport function readSync(path: string): string {\n return syncReader(path)\n}\n","import fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.pathExists(path)\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.exists()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.pathExistsSync(path)\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function exists(path: string): Promise<boolean> {\n return reader(path)\n}\n\nexport function existsSync(path: string): boolean {\n return syncReader(path)\n}\n","import { normalize, relative } from 'node:path'\n\nfunction slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {\n const isWindowsPath = /^\\\\\\\\\\?\\\\/.test(path)\n const normalizedPath = normalize(path)\n\n if (['linux', 'mac'].includes(platform) && !isWindowsPath) {\n // linux and mac\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n }\n\n // windows\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux'): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const slashedPath = slash(relativePath, platform)\n\n if (slashedPath.startsWith('../')) {\n return slashedPath\n }\n\n return `./${slashedPath}`\n}\n","type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type OptionalPath = Path | undefined | null\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default object-hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n","export { clean } from './clean.ts'\nexport { read, readSync } from './read.ts'\nexport { write } from './write.ts'\nexport { exists } from './exists.ts'\nexport { getRelativePath } from './utils.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport * as KubbFile from './types.ts'\n"],"mappings":";;;;;AAEA,eAAsB,MAAMA,QAA6B;AACvD,QAAO,GAAG,OAAOC,OAAK;AACvB;;;;ACDD,MAAMC,WAAS,SACb;CACE,MAAM,OAAOC,WAAiB;AAC5B,SAAO,GAAG,SAASC,QAAM,EAAE,UAAU,OAAQ,EAAC;CAC/C;CACD,KAAK,OAAOD,WAAiB;EAC3B,MAAM,OAAO,IAAI,KAAKC,OAAK;AAE3B,SAAO,KAAK,MAAM;CACnB;AACF,GACD,OACD;AAED,MAAMC,eAAa,SACjB;CACE,MAAM,CAACF,WAAiB;AACtB,SAAO,GAAG,aAAaC,QAAM,EAAE,UAAU,OAAQ,EAAC;CACnD;CACD,KAAK,MAAM;AACT,QAAM,IAAI,MAAM;CACjB;AACF,GACD,OACD;AAED,eAAsB,KAAKD,QAA+B;AACxD,QAAOD,SAAOE,OAAK;AACpB;AAED,SAAgB,SAASD,QAAsB;AAC7C,QAAOE,aAAWD,OAAK;AACxB;;;;AChCD,MAAM,SAAS,SACb;CACE,MAAM,OAAOE,WAAiB;AAC5B,SAAO,GAAG,WAAWC,OAAK;CAC3B;CACD,KAAK,OAAOD,WAAiB;EAC3B,MAAM,OAAO,IAAI,KAAKC,OAAK;AAE3B,SAAO,KAAK,QAAQ;CACrB;AACF,GACD,OACD;AAED,MAAM,aAAa,SACjB;CACE,MAAM,CAACD,WAAiB;AACtB,SAAO,GAAG,eAAeC,OAAK;CAC/B;CACD,KAAK,MAAM;AACT,QAAM,IAAI,MAAM;CACjB;AACF,GACD,OACD;AAED,eAAsB,OAAOD,QAAgC;AAC3D,QAAO,OAAOC,OAAK;AACpB;;;;AC7BD,SAAS,MAAMC,QAAcC,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAKC,OAAK;CAC5C,MAAM,iBAAiB,UAAUA,OAAK;AAEtC,KAAI,CAAC,SAAS,KAAM,EAAC,SAAS,SAAS,IAAI,CAAC,cAE1C,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;AAIjE,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;AAChE;AAED,SAAgB,gBAAgBC,SAAyBC,UAA0BH,WAAwC,SAAiB;AAC1I,KAAI,CAAC,WAAW,CAAC,SACf,OAAM,IAAI,MAAM,CAAC,oEAAoE,EAAE,WAAW,GAAG,CAAC,EAAE,YAAY,IAAI;CAG1H,MAAM,eAAe,SAAS,SAAS,SAAS;CAIhD,MAAM,cAAc,MAAM,cAAc,SAAS;AAEjD,KAAI,YAAY,WAAW,MAAM,CAC/B,QAAO;AAGT,QAAO,CAAC,EAAE,EAAE,aAAa;AAC1B;;;;;;;;AEzBD,SAAgB,YAAYI,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG;AACrC"}