@kubb/plugin-client 5.5.5 → 5.5.6

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/src/plugin.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { createGroupConfig } from '@internals/shared'
2
- import { definePlugin, Resolver } from 'kubb/kit'
2
+ import { addGenerator, definePlugin, Resolver, setMacros, setResolver } from 'kubb/kit'
3
+ import { version } from '../package.json'
3
4
  import { pluginTsName } from '@kubb/plugin-ts'
4
5
  import { pluginZodName } from '@kubb/plugin-zod'
5
6
  import { clientGenerator } from './generators/clientGenerator.tsx'
6
7
  import { defaultMacros, resolverClient } from '@internals/client'
7
- import type { PluginClient, ResolvedOptions, ResolverClient } from './types.ts'
8
+ import type { PluginClient, ResolverClient } from './types.ts'
8
9
 
9
10
  /**
10
11
  * Canonical plugin name for `@kubb/plugin-client`.
@@ -21,49 +22,43 @@ export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
21
22
  * pluginClient({ importPath: '../api/client' })
22
23
  * ```
23
24
  */
24
- export const pluginClient = definePlugin<PluginClient>((options) => {
25
- const {
26
- output = { path: 'clients', barrel: { type: 'named' } },
27
- exclude = [],
28
- include,
29
- override = [],
30
- importPath,
31
- throwOnErrorDefault = true,
32
- validator = false,
33
- group,
34
- resolver: userResolver,
35
- } = options
25
+ export const pluginClient = definePlugin<PluginClient>({
26
+ meta: { name: pluginClientName, version, compatibility: { kubb: '>=5.8.0' } },
27
+ dependencies: (options) => ({ [pluginTsName]: { optional: true }, [pluginZodName]: { optional: !options.validator } }),
28
+ setup(options) {
29
+ const {
30
+ output = { path: 'clients', barrel: { type: 'named' } },
31
+ exclude = [],
32
+ include,
33
+ override = [],
34
+ importPath,
35
+ throwOnErrorDefault = true,
36
+ validator = false,
37
+ group,
38
+ resolver: userResolver,
39
+ } = options
36
40
 
37
- const resolved: ResolvedOptions = {
38
- output,
39
- exclude,
40
- include,
41
- override,
42
- group: createGroupConfig(group),
43
- importPath,
44
- baseURL: undefined,
45
- throwOnErrorDefault,
46
- validator,
47
- returnType: 'plain',
48
- sdk: undefined,
49
- resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
50
- }
41
+ const resolver = userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient
51
42
 
52
- return {
53
- name: pluginClientName,
54
- options,
55
- dependencies: [pluginTsName, pluginZodName],
56
- hooks: {
57
- 'kubb:plugin:setup'(ctx) {
58
- if (validator) ctx.requirePlugin(pluginZodName)
43
+ setResolver(resolver)
44
+ setMacros([...defaultMacros, ...(options.macros ?? [])])
45
+ addGenerator(clientGenerator)
59
46
 
60
- ctx.setOptions(resolved)
61
- ctx.setResolver(resolved.resolver)
62
- ctx.setMacros([...defaultMacros, ...(options.macros ?? [])])
63
- ctx.addGenerator(clientGenerator)
64
- },
65
- },
66
- }
47
+ return {
48
+ output,
49
+ exclude,
50
+ include,
51
+ override,
52
+ group: createGroupConfig(group),
53
+ importPath,
54
+ baseURL: undefined,
55
+ throwOnErrorDefault,
56
+ validator,
57
+ returnType: 'plain',
58
+ sdk: undefined,
59
+ resolver,
60
+ }
61
+ },
67
62
  })
68
63
 
69
64
  export default pluginClient