@kubb/core 2.0.0-beta.1 → 2.0.0-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "Generator core",
5
5
  "keywords": [
6
6
  "typescript",
@@ -57,8 +57,8 @@
57
57
  "picocolors": "^1.0.0",
58
58
  "seedrandom": "^3.0.5",
59
59
  "semver": "^7.5.4",
60
- "@kubb/parser": "2.0.0-beta.1",
61
- "@kubb/types": "2.0.0-beta.1"
60
+ "@kubb/parser": "2.0.0-beta.2",
61
+ "@kubb/types": "2.0.0-beta.2"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@types/fs-extra": "^11.0.4",
@@ -71,8 +71,8 @@
71
71
  "tsup": "^8.0.1",
72
72
  "typescript": "^5.3.2",
73
73
  "@kubb/eslint-config": "1.1.8",
74
- "@kubb/tsup-config": "1.1.8",
75
- "@kubb/ts-config": "0.1.0"
74
+ "@kubb/ts-config": "0.1.0",
75
+ "@kubb/tsup-config": "1.1.8"
76
76
  },
77
77
  "packageManager": "pnpm@8.3.0",
78
78
  "engines": {
@@ -388,28 +388,46 @@ export class PluginManager {
388
388
 
389
389
  return plugins.filter((item) => item[hookName])
390
390
  }
391
+ // TODO add test case for sorting with pre/post
391
392
 
392
- return plugins
393
+ return plugins.map(plugin => {
394
+ if (plugin.pre) {
395
+ const isValid = plugin.pre.every(pluginName => plugins.find(pluginToFind => pluginToFind.name === pluginName))
396
+
397
+ if (!isValid) {
398
+ throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, undefined, 2)})`)
399
+ }
400
+ }
401
+
402
+ return plugin
403
+ }).sort((a, b) => {
404
+ if (b.pre?.includes(a.name)) {
405
+ return 1
406
+ }
407
+ if (b.post?.includes(a.name)) {
408
+ return -1
409
+ }
410
+ return 0
411
+ })
393
412
  }
394
413
 
395
414
  getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[] {
396
415
  const plugins = [...this.plugins]
397
- const [searchKind, searchPluginName, searchIdentifier] = pluginKey
416
+ const [searchPluginName, searchIdentifier] = pluginKey
398
417
 
399
418
  const pluginByPluginName = plugins
400
419
  .filter((plugin) => plugin[hookName])
401
420
  .filter((item) => {
402
- const [kind, name, identifier] = item.key
421
+ const [name, identifier] = item.key
403
422
 
404
423
  const identifierCheck = identifier?.toString() === searchIdentifier?.toString()
405
- const kindCheck = kind === searchKind
406
424
  const nameCheck = name === searchPluginName
407
425
 
408
426
  if (searchIdentifier) {
409
- return identifierCheck && kindCheck && nameCheck
427
+ return identifierCheck && nameCheck
410
428
  }
411
429
 
412
- return kindCheck && nameCheck
430
+ return nameCheck
413
431
  })
414
432
 
415
433
  if (!pluginByPluginName?.length) {
@@ -569,7 +587,7 @@ export class PluginManager {
569
587
 
570
588
  setUniqueName(plugin.name, usedPluginNames)
571
589
 
572
- const key = plugin.key || ([plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean) as [typeof plugin.kind, typeof plugin.name, string])
590
+ const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean) as [typeof plugin.name, string]
573
591
 
574
592
  if (plugin.name !== 'core' && usedPluginNames[plugin.name]! >= 2) {
575
593
  pluginManager.logger.warn('Using multiple of the same plugin is an experimental feature')
@@ -624,6 +642,6 @@ export class PluginManager {
624
642
 
625
643
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
626
644
  static get hooks() {
627
- return ['validate', 'buildStart', 'resolvePath', 'resolveName', 'load', 'transform', 'writeFile', 'buildEnd'] as const
645
+ return ['buildStart', 'resolvePath', 'resolveName', 'load', 'transform', 'writeFile', 'buildEnd'] as const
628
646
  }
629
647
  }
package/src/build.ts CHANGED
@@ -157,11 +157,6 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
157
157
 
158
158
  const { fileManager, logger } = pluginManager
159
159
 
160
- await pluginManager.hookParallel<'validate', true>({
161
- hookName: 'validate',
162
- parameters: [pluginManager.plugins],
163
- })
164
-
165
160
  await pluginManager.hookParallel({
166
161
  hookName: 'buildStart',
167
162
  parameters: [options.config],
@@ -183,11 +178,6 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
183
178
  const { fileManager, logger } = pluginManager
184
179
 
185
180
  try {
186
- await pluginManager.hookParallel<'validate', true>({
187
- hookName: 'validate',
188
- parameters: [pluginManager.plugins],
189
- })
190
-
191
181
  await pluginManager.hookParallel({
192
182
  hookName: 'buildStart',
193
183
  parameters: [options.config],
package/src/plugin.ts CHANGED
@@ -26,10 +26,10 @@ type Options = {
26
26
  }
27
27
 
28
28
  // not publicly exported
29
- export type CorePluginOptions = PluginFactoryOptions<'core', 'controller', Options, Options, PluginContext, never>
29
+ export type CorePluginOptions = PluginFactoryOptions<'core', Options, Options, PluginContext, never>
30
30
 
31
31
  export const pluginName = 'core' satisfies CorePluginOptions['name']
32
- export const pluginKey: CorePluginOptions['key'] = ['controller', pluginName] satisfies CorePluginOptions['key']
32
+ export const pluginKey: CorePluginOptions['key'] = [pluginName] satisfies CorePluginOptions['key']
33
33
 
34
34
  export const definePlugin = createPlugin<CorePluginOptions>((options) => {
35
35
  const { fileManager, pluginManager, resolvePath, resolveName, logger } = options
@@ -37,8 +37,8 @@ export const definePlugin = createPlugin<CorePluginOptions>((options) => {
37
37
  return {
38
38
  name: pluginName,
39
39
  options,
40
- key: ['controller', 'core'],
41
- kind: 'controller',
40
+ key: ['core'],
41
+
42
42
  api() {
43
43
  return {
44
44
  get config() {
package/src/types.ts CHANGED
@@ -123,8 +123,6 @@ export type CLIOptions = {
123
123
 
124
124
  // plugin
125
125
 
126
- export type KubbPluginKind = 'schema' | 'controller'
127
-
128
126
  export type KubbUnionPlugins = PluginUnion
129
127
 
130
128
  export type KubbObjectPlugin = keyof OptionsPlugins
@@ -134,10 +132,6 @@ export type PluginFactoryOptions<
134
132
  * Name to be used for the plugin, this will also be used for they key.
135
133
  */
136
134
  TName extends string = string,
137
- /**
138
- * @type "schema" | "controller"
139
- */
140
- TKind extends KubbPluginKind = KubbPluginKind,
141
135
  /**
142
136
  * Options of the plugin.
143
137
  */
@@ -161,18 +155,17 @@ export type PluginFactoryOptions<
161
155
  TAppMeta = unknown,
162
156
  > = {
163
157
  name: TName
164
- kind: TKind
165
158
  /**
166
159
  * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
167
160
  */
168
- key: [kind: TKind | undefined, name: TName | string, identifier?: string | number]
161
+ key: [name: TName | string, identifier?: string | number]
169
162
  options: TOptions
170
163
  resolvedOptions: TResolvedOptions
171
164
  api: TAPI
172
165
  resolvePathOptions: TResolvePathOptions
173
166
  appMeta: {
174
167
  pluginManager: PluginManager
175
- plugin: KubbPlugin<PluginFactoryOptions<TName, TKind, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>
168
+ plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>
176
169
  } & TAppMeta
177
170
  }
178
171
 
@@ -182,18 +175,23 @@ export type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactory
182
175
  & {
183
176
  /**
184
177
  * Unique name used for the plugin
178
+ * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
185
179
  * @example @kubb/typescript
186
180
  */
187
181
  name: TOptions['name']
188
- /**
189
- * Internal key used when a developer uses more than one of the same plugin
190
- * @private
191
- */
192
- key?: TOptions['key']
193
182
  /**
194
183
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
195
184
  */
196
185
  options: TOptions['resolvedOptions']
186
+ /**
187
+ * 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.
188
+ * Can be used to validate depended plugins.
189
+ */
190
+ pre?: Array<string>
191
+ /**
192
+ * 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.
193
+ */
194
+ post?: Array<string>
197
195
  }
198
196
  & (TOptions['api'] extends never ? {
199
197
  api?: never
@@ -201,24 +199,10 @@ export type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactory
201
199
  : {
202
200
  api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api']
203
201
  })
204
- & (TOptions['kind'] extends never ? {
205
- kind?: never
206
- }
207
- : {
208
- /**
209
- * Kind/type for the plugin
210
- *
211
- * Type 'schema' can be used for JSON schema's, TypeScript types, ...
212
- *
213
- * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
214
- * @default undefined
215
- */
216
- kind: TOptions['kind']
217
- })
218
202
 
219
203
  export type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>
220
204
 
221
- type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any, any>>
205
+ type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any>>
222
206
 
223
207
  export type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
224
208
  & {
@@ -233,16 +217,18 @@ export type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
233
217
  */
234
218
  key: TOptions['key']
235
219
  /**
236
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
220
+ * 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.
221
+ * Can be used to validate depended plugins.
237
222
  */
238
- options: TOptions['resolvedOptions']
223
+ pre?: Array<string>
239
224
  /**
240
- * Kind/type for the plugin
241
- * Type 'schema' can be used for JSON schema's, TypeScript types, ...
242
- * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
243
- * @default undefined
225
+ * 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.
244
226
  */
245
- kind?: TOptions['kind']
227
+ post?: Array<string>
228
+ /**
229
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
230
+ */
231
+ options: TOptions['resolvedOptions']
246
232
  /**
247
233
  * Define an api that can be used by other plugins, see `PluginManager' where we convert from `KubbUserPlugin` to `KubbPlugin`(used when calling `createPlugin`).
248
234
  */
@@ -257,11 +243,6 @@ export type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
257
243
  export type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>
258
244
 
259
245
  export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
260
- /**
261
- * Valdiate all plugins to see if their depended plugins are installed and configured.
262
- * @type hookParallel
263
- */
264
- validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>
265
246
  /**
266
247
  * Start of the lifecycle of a plugin.
267
248
  * @type hookParallel