@kubb/core 4.36.1 → 5.0.0-alpha.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.
@@ -213,7 +213,7 @@ type GetFileProps<TOptions = object> = {
213
213
  name: string;
214
214
  mode?: KubbFile.Mode;
215
215
  extname: KubbFile.Extname;
216
- pluginKey: Plugin['key'];
216
+ pluginName: string;
217
217
  options?: TOptions;
218
218
  };
219
219
  declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode;
@@ -234,10 +234,10 @@ declare class PluginManager {
234
234
  name,
235
235
  mode,
236
236
  extname,
237
- pluginKey,
237
+ pluginName,
238
238
  options
239
239
  }: GetFileProps<TOptions>): KubbFile.File<{
240
- pluginKey: Plugin['key'];
240
+ pluginName: string;
241
241
  }>;
242
242
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
243
243
  resolveName: (params: ResolveNameParams) => string;
@@ -245,11 +245,11 @@ declare class PluginManager {
245
245
  * Run a specific hookName for plugin x.
246
246
  */
247
247
  hookForPlugin<H extends PluginLifecycleHooks>({
248
- pluginKey,
248
+ pluginName,
249
249
  hookName,
250
250
  parameters
251
251
  }: {
252
- pluginKey: Plugin['key'];
252
+ pluginName: string;
253
253
  hookName: H;
254
254
  parameters: PluginParameter<H>;
255
255
  }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
@@ -257,11 +257,11 @@ declare class PluginManager {
257
257
  * Run a specific hookName for plugin x.
258
258
  */
259
259
  hookForPluginSync<H extends PluginLifecycleHooks>({
260
- pluginKey,
260
+ pluginName,
261
261
  hookName,
262
262
  parameters
263
263
  }: {
264
- pluginKey: Plugin['key'];
264
+ pluginName: string;
265
265
  hookName: H;
266
266
  parameters: PluginParameter<H>;
267
267
  }): Array<ReturnType<ParseResult<H>>> | null;
@@ -309,8 +309,8 @@ declare class PluginManager {
309
309
  hookName: H;
310
310
  parameters?: PluginParameter<H>;
311
311
  }): Promise<void>;
312
- getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
313
- getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
312
+ getPluginByName(pluginName: string): Plugin | undefined;
313
+ getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
314
314
  }
315
315
  //#endregion
316
316
  //#region src/Kubb.d.ts
@@ -766,7 +766,7 @@ type Config<TInput = Input> = {
766
766
  };
767
767
  type PluginFactoryOptions<
768
768
  /**
769
- * Name to be used for the plugin, this will also be used for they key.
769
+ * Name to be used for the plugin.
770
770
  */
771
771
  TName extends string = string,
772
772
  /**
@@ -786,16 +786,11 @@ TContext = unknown,
786
786
  */
787
787
  TResolvePathOptions extends object = object> = {
788
788
  name: TName;
789
- /**
790
- * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
791
- */
792
- key: PluginKey<TName | string>;
793
789
  options: TOptions;
794
790
  resolvedOptions: TResolvedOptions;
795
791
  context: TContext;
796
792
  resolvePathOptions: TResolvePathOptions;
797
793
  };
798
- type PluginKey<TName> = [name: TName, identifier?: string | number];
799
794
  type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
800
795
  type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
801
796
  /**
@@ -827,11 +822,6 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
827
822
  * @example @kubb/typescript
828
823
  */
829
824
  name: TOptions['name'];
830
- /**
831
- * Internal key used when a developer uses more than one of the same plugin
832
- * @private
833
- */
834
- key: TOptions['key'];
835
825
  /**
836
826
  * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
837
827
  * Can be used to validate dependent plugins.
@@ -876,7 +866,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
876
866
  type PluginLifecycleHooks = keyof PluginLifecycle;
877
867
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
878
868
  type ResolvePathParams<TOptions = object> = {
879
- pluginKey?: Plugin['key'];
869
+ pluginName?: string;
880
870
  baseName: KubbFile.BaseName;
881
871
  mode?: KubbFile.Mode;
882
872
  /**
@@ -886,7 +876,7 @@ type ResolvePathParams<TOptions = object> = {
886
876
  };
887
877
  type ResolveNameParams = {
888
878
  name: string;
889
- pluginKey?: Plugin['key'];
879
+ pluginName?: string;
890
880
  /**
891
881
  * Specifies the type of entity being named.
892
882
  * - 'file' customizes the name of the created file (uses camelCase).
@@ -987,5 +977,5 @@ type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
987
977
  };
988
978
  type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>;
989
979
  //#endregion
990
- export { UserPlugin as A, AsyncEventEmitter as B, Printer as C, UnknownUserPlugin as D, ResolvePathParams as E, DefineStorage as F, defineStorage as I, formatters as L, KubbEvents as M, PluginManager as N, UserConfig as O, getMode as P, linters as R, PluginWithLifeCycle as S, ResolveNameParams as T, URLPath as V, PluginFactoryOptions as _, Config as a, PluginLifecycleHooks as b, Group as c, Logger as d, LoggerContext as f, PluginContext as g, Plugin as h, BarrelType as i, UserPluginWithLifeCycle as j, UserLogger as k, InputData as l, Output as m, AdapterFactoryOptions as n, DevtoolsOptions as o, LoggerOptions as p, AdapterSource as r, GetPluginFactoryOptions as s, Adapter as t, InputPath as u, PluginKey as v, PrinterFactoryOptions as w, PluginParameter as x, PluginLifecycle as y, logLevel as z };
991
- //# sourceMappingURL=types-D30QAz2y.d.ts.map
980
+ export { UserPluginWithLifeCycle as A, URLPath as B, PrinterFactoryOptions as C, UserConfig as D, UnknownUserPlugin as E, defineStorage as F, formatters as I, linters as L, PluginManager as M, getMode as N, UserLogger as O, DefineStorage as P, logLevel as R, Printer as S, ResolvePathParams as T, PluginFactoryOptions as _, Config as a, PluginParameter as b, Group as c, Logger as d, LoggerContext as f, PluginContext as g, Plugin as h, BarrelType as i, KubbEvents as j, UserPlugin as k, InputData as l, Output as m, AdapterFactoryOptions as n, DevtoolsOptions as o, LoggerOptions as p, AdapterSource as r, GetPluginFactoryOptions as s, Adapter as t, InputPath as u, PluginLifecycle as v, ResolveNameParams as w, PluginWithLifeCycle as x, PluginLifecycleHooks as y, AsyncEventEmitter as z };
981
+ //# sourceMappingURL=types-B7eZvqwD.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "4.36.1",
3
+ "version": "5.0.0-alpha.2",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -71,7 +71,7 @@
71
71
  "remeda": "^2.33.6",
72
72
  "semver": "^7.7.4",
73
73
  "tinyexec": "^1.0.4",
74
- "@kubb/ast": "4.36.1"
74
+ "@kubb/ast": "5.0.0-alpha.2"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/semver": "^7.7.1",
@@ -83,7 +83,7 @@
83
83
  "@kubb/react-fabric": "0.13.3"
84
84
  },
85
85
  "engines": {
86
- "node": ">=20"
86
+ "node": ">=22"
87
87
  },
88
88
  "publishConfig": {
89
89
  "access": "public",
@@ -51,7 +51,7 @@ type GetFileProps<TOptions = object> = {
51
51
  name: string
52
52
  mode?: KubbFile.Mode
53
53
  extname: KubbFile.Extname
54
- pluginKey: Plugin['key']
54
+ pluginName: string
55
55
  options?: TOptions
56
56
  }
57
57
 
@@ -158,19 +158,19 @@ export class PluginManager {
158
158
  return this.#getSortedPlugins()
159
159
  }
160
160
 
161
- getFile<TOptions = object>({ name, mode, extname, pluginKey, options }: GetFileProps<TOptions>): KubbFile.File<{ pluginKey: Plugin['key'] }> {
161
+ getFile<TOptions = object>({ name, mode, extname, pluginName, options }: GetFileProps<TOptions>): KubbFile.File<{ pluginName: string }> {
162
162
  const baseName = `${name}${extname}` as const
163
- const path = this.resolvePath({ baseName, mode, pluginKey, options })
163
+ const path = this.resolvePath({ baseName, mode, pluginName, options })
164
164
 
165
165
  if (!path) {
166
- throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`)
166
+ throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginName "${pluginName}"`)
167
167
  }
168
168
 
169
169
  return {
170
170
  path,
171
171
  baseName,
172
172
  meta: {
173
- pluginKey,
173
+ pluginName,
174
174
  },
175
175
  sources: [],
176
176
  imports: [],
@@ -182,9 +182,9 @@ export class PluginManager {
182
182
  const root = path.resolve(this.config.root, this.config.output.path)
183
183
  const defaultPath = path.resolve(root, params.baseName)
184
184
 
185
- if (params.pluginKey) {
185
+ if (params.pluginName) {
186
186
  const paths = this.hookForPluginSync({
187
- pluginKey: params.pluginKey,
187
+ pluginName: params.pluginName,
188
188
  hookName: 'resolvePath',
189
189
  parameters: [params.baseName, params.mode, params.options as object],
190
190
  })
@@ -201,9 +201,9 @@ export class PluginManager {
201
201
  }
202
202
  //TODO refactor by using the order of plugins and the cache of the fileManager instead of guessing and recreating the name/path
203
203
  resolveName = (params: ResolveNameParams): string => {
204
- if (params.pluginKey) {
204
+ if (params.pluginName) {
205
205
  const names = this.hookForPluginSync({
206
- pluginKey: params.pluginKey,
206
+ pluginName: params.pluginName,
207
207
  hookName: 'resolveName',
208
208
  parameters: [params.name.trim(), params.type],
209
209
  })
@@ -225,15 +225,15 @@ export class PluginManager {
225
225
  * Run a specific hookName for plugin x.
226
226
  */
227
227
  async hookForPlugin<H extends PluginLifecycleHooks>({
228
- pluginKey,
228
+ pluginName,
229
229
  hookName,
230
230
  parameters,
231
231
  }: {
232
- pluginKey: Plugin['key']
232
+ pluginName: string
233
233
  hookName: H
234
234
  parameters: PluginParameter<H>
235
235
  }): Promise<Array<ReturnType<ParseResult<H>> | null>> {
236
- const plugins = this.getPluginsByKey(hookName, pluginKey)
236
+ const plugins = this.getPluginsByName(hookName, pluginName)
237
237
 
238
238
  this.events.emit('plugins:hook:progress:start', {
239
239
  hookName,
@@ -264,15 +264,15 @@ export class PluginManager {
264
264
  */
265
265
 
266
266
  hookForPluginSync<H extends PluginLifecycleHooks>({
267
- pluginKey,
267
+ pluginName,
268
268
  hookName,
269
269
  parameters,
270
270
  }: {
271
- pluginKey: Plugin['key']
271
+ pluginName: string
272
272
  hookName: H
273
273
  parameters: PluginParameter<H>
274
274
  }): Array<ReturnType<ParseResult<H>>> | null {
275
- const plugins = this.getPluginsByKey(hookName, pluginKey)
275
+ const plugins = this.getPluginsByName(hookName, pluginName)
276
276
 
277
277
  const result = plugins
278
278
  .map((plugin) => {
@@ -476,41 +476,21 @@ export class PluginManager {
476
476
  })
477
477
  }
478
478
 
479
- getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined {
479
+ getPluginByName(pluginName: string): Plugin | undefined {
480
480
  const plugins = [...this.#plugins]
481
- const [searchPluginName] = pluginKey
482
481
 
483
- return plugins.find((item) => {
484
- const [name] = item.key
485
-
486
- return name === searchPluginName
487
- })
482
+ return plugins.find((item) => item.name === pluginName)
488
483
  }
489
484
 
490
- getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[] {
485
+ getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[] {
491
486
  const plugins = [...this.plugins]
492
- const [searchPluginName, searchIdentifier] = pluginKey
493
-
494
- const pluginByPluginName = plugins
495
- .filter((plugin) => hookName in plugin)
496
- .filter((item) => {
497
- const [name, identifier] = item.key
498
-
499
- const identifierCheck = identifier?.toString() === searchIdentifier?.toString()
500
- const nameCheck = name === searchPluginName
501
487
 
502
- if (searchIdentifier) {
503
- return identifierCheck && nameCheck
504
- }
505
-
506
- return nameCheck
507
- })
488
+ const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => item.name === pluginName)
508
489
 
509
490
  if (!pluginByPluginName?.length) {
510
491
  // fallback on the core plugin when there is no match
511
492
 
512
493
  const corePlugin = plugins.find((plugin) => plugin.name === CORE_PLUGIN_NAME && hookName in plugin)
513
- // Removed noisy debug logs for missing hooks - these are expected behavior, not errors
514
494
 
515
495
  return corePlugin ? [corePlugin] : []
516
496
  }
@@ -657,20 +637,16 @@ export class PluginManager {
657
637
 
658
638
  setUniqueName(plugin.name, usedPluginNames)
659
639
 
660
- // Emit warning if this is a duplicate plugin (will be removed in v5)
661
640
  const usageCount = usedPluginNames[plugin.name]
662
641
  if (usageCount && usageCount > 1) {
663
- this.events.emit(
664
- 'warn',
665
- `Multiple instances of plugin "${plugin.name}" detected. This behavior is deprecated and will be removed in v5.`,
666
- `Plugin key: [${plugin.name}, ${usageCount}]`,
642
+ throw new ValidationPluginError(
643
+ `Duplicate plugin "${plugin.name}" detected. Each plugin can only be used once. Use a different configuration instead of adding multiple instances of the same plugin.`,
667
644
  )
668
645
  }
669
646
 
670
647
  return {
671
648
  install() {},
672
649
  ...plugin,
673
- key: [plugin.name, usedPluginNames[plugin.name]].filter(Boolean) as [typeof plugin.name, string],
674
650
  } as unknown as Plugin
675
651
  }
676
652
  }
package/src/build.ts CHANGED
@@ -246,7 +246,7 @@ export async function safeBuild(options: BuildOptions, overrides?: SetupResult):
246
246
 
247
247
  await events.emit('debug', {
248
248
  date: timestamp,
249
- logs: ['Installing plugin...', ` • Plugin Key: [${plugin.key.join(', ')}]`],
249
+ logs: ['Installing plugin...', ` • Plugin Name: ${plugin.name}`],
250
250
  })
251
251
 
252
252
  await installer(context)
@@ -275,7 +275,7 @@ export async function safeBuild(options: BuildOptions, overrides?: SetupResult):
275
275
  date: errorTimestamp,
276
276
  logs: [
277
277
  '✗ Plugin installation failed',
278
- ` • Plugin Key: ${JSON.stringify(plugin.key)}`,
278
+ ` • Plugin Name: ${plugin.name}`,
279
279
  ` • Error: ${error.constructor.name} - ${error.message}`,
280
280
  ' • Stack Trace:',
281
281
  error.stack || 'No stack trace available',
@@ -361,9 +361,9 @@ type BuildBarrelExportsParams = {
361
361
  }
362
362
 
363
363
  function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }: BuildBarrelExportsParams): KubbFile.Export[] {
364
- const pluginKeyMap = new Map<string, Plugin>()
364
+ const pluginNameMap = new Map<string, Plugin>()
365
365
  for (const plugin of pluginManager.plugins) {
366
- pluginKeyMap.set(JSON.stringify(plugin.key), plugin)
366
+ pluginNameMap.set(plugin.name, plugin)
367
367
  }
368
368
 
369
369
  return barrelFiles.flatMap((file) => {
@@ -375,7 +375,7 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, plu
375
375
  }
376
376
 
377
377
  const meta = file.meta as FileMetaBase | undefined
378
- const plugin = meta?.pluginKey ? pluginKeyMap.get(JSON.stringify(meta.pluginKey)) : undefined
378
+ const plugin = meta?.pluginName ? pluginNameMap.get(meta.pluginName) : undefined
379
379
  const pluginOptions = plugin?.options as { output?: Output<unknown> } | undefined
380
380
 
381
381
  if (!pluginOptions || pluginOptions.output?.barrelType === false) {
package/src/types.ts CHANGED
@@ -255,7 +255,7 @@ export type Config<TInput = Input> = {
255
255
 
256
256
  export type PluginFactoryOptions<
257
257
  /**
258
- * Name to be used for the plugin, this will also be used for they key.
258
+ * Name to be used for the plugin.
259
259
  */
260
260
  TName extends string = string,
261
261
  /**
@@ -276,18 +276,12 @@ export type PluginFactoryOptions<
276
276
  TResolvePathOptions extends object = object,
277
277
  > = {
278
278
  name: TName
279
- /**
280
- * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
281
- */
282
- key: PluginKey<TName | string>
283
279
  options: TOptions
284
280
  resolvedOptions: TResolvedOptions
285
281
  context: TContext
286
282
  resolvePathOptions: TResolvePathOptions
287
283
  }
288
284
 
289
- export type PluginKey<TName> = [name: TName, identifier?: string | number]
290
-
291
285
  export type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never
292
286
 
293
287
  export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
@@ -323,11 +317,6 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
323
317
  * @example @kubb/typescript
324
318
  */
325
319
  name: TOptions['name']
326
- /**
327
- * Internal key used when a developer uses more than one of the same plugin
328
- * @private
329
- */
330
- key: TOptions['key']
331
320
  /**
332
321
  * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
333
322
  * Can be used to validate dependent plugins.
@@ -378,7 +367,7 @@ export type PluginLifecycleHooks = keyof PluginLifecycle
378
367
  export type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>
379
368
 
380
369
  export type ResolvePathParams<TOptions = object> = {
381
- pluginKey?: Plugin['key']
370
+ pluginName?: string
382
371
  baseName: KubbFile.BaseName
383
372
  mode?: KubbFile.Mode
384
373
  /**
@@ -389,7 +378,7 @@ export type ResolvePathParams<TOptions = object> = {
389
378
 
390
379
  export type ResolveNameParams = {
391
380
  name: string
392
- pluginKey?: Plugin['key']
381
+ pluginName?: string
393
382
  /**
394
383
  * Specifies the type of entity being named.
395
384
  * - 'file' customizes the name of the created file (uses camelCase).
@@ -1,10 +1,10 @@
1
1
  import { join } from 'node:path'
2
2
  import type { KubbFile } from '@kubb/fabric-core/types'
3
3
  import { BarrelManager } from '../BarrelManager.ts'
4
- import type { BarrelType, Plugin } from '../types.ts'
4
+ import type { BarrelType } from '../types.ts'
5
5
 
6
6
  export type FileMetaBase = {
7
- pluginKey?: Plugin['key']
7
+ pluginName?: string
8
8
  }
9
9
 
10
10
  type AddIndexesProps = {