@kubb/plugin-ts 5.0.0-beta.10 → 5.0.0-beta.15
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/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/extension.yaml +13 -10
- package/package.json +6 -6
- package/src/generators/typeGenerator.tsx +10 -10
package/extension.yaml
CHANGED
|
@@ -43,7 +43,7 @@ options:
|
|
|
43
43
|
- name: output
|
|
44
44
|
type: Output
|
|
45
45
|
required: false
|
|
46
|
-
default: "{ path: 'types',
|
|
46
|
+
default: "{ path: 'types', barrel: { type: 'named' } }"
|
|
47
47
|
description: Specify the export location for the files and define the behavior of the output.
|
|
48
48
|
properties:
|
|
49
49
|
- name: path
|
|
@@ -53,13 +53,11 @@ options:
|
|
|
53
53
|
tip: |
|
|
54
54
|
if `output.path` is a file, `group` cannot be used.
|
|
55
55
|
default: "'types'"
|
|
56
|
-
- name:
|
|
57
|
-
type: "
|
|
56
|
+
- name: barrel
|
|
57
|
+
type: "{ type: 'named' | 'all', nested?: boolean } | false"
|
|
58
58
|
required: false
|
|
59
|
-
default: "'named'"
|
|
60
|
-
description:
|
|
61
|
-
tip: |
|
|
62
|
-
Using `propagate` will prevent a plugin from creating a barrel file, but it will still propagate, allowing [`output.barrelType`](https://kubb.dev/docs/5.x/configuration#output-barreltype) to export the specific function or type.
|
|
59
|
+
default: "{ type: 'named' }"
|
|
60
|
+
description: 'Configure barrel file export strategy. Use `type` to control named vs. wildcard exports; set `nested: true` to generate hierarchical barrels in subdirectories.'
|
|
63
61
|
examples:
|
|
64
62
|
- name: all
|
|
65
63
|
files:
|
|
@@ -73,10 +71,15 @@ options:
|
|
|
73
71
|
code: |
|
|
74
72
|
export { PetService } from './gen/petService.ts'
|
|
75
73
|
twoslash: false
|
|
76
|
-
- name:
|
|
74
|
+
- name: nested
|
|
77
75
|
files:
|
|
78
|
-
-
|
|
79
|
-
|
|
76
|
+
- name: kubb.config.ts
|
|
77
|
+
lang: typescript
|
|
78
|
+
code: |
|
|
79
|
+
output: {
|
|
80
|
+
path: './gen',
|
|
81
|
+
barrel: { type: 'named', nested: true },
|
|
82
|
+
}
|
|
80
83
|
twoslash: false
|
|
81
84
|
- name: 'false'
|
|
82
85
|
files:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.15",
|
|
4
4
|
"description": "Generate TypeScript types, interfaces, and enums from your OpenAPI specification. The foundational plugin that powers type safety across the entire Kubb ecosystem.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"registry": "https://registry.npmjs.org/"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@kubb/core": "5.0.0-beta.
|
|
50
|
-
"@kubb/parser-ts": "5.0.0-beta.
|
|
51
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
52
|
-
"remeda": "^2.34.
|
|
49
|
+
"@kubb/core": "5.0.0-beta.19",
|
|
50
|
+
"@kubb/parser-ts": "5.0.0-beta.19",
|
|
51
|
+
"@kubb/renderer-jsx": "5.0.0-beta.19",
|
|
52
|
+
"remeda": "^2.34.1",
|
|
53
53
|
"typescript": "^6.0.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@internals/utils": "0.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
60
|
+
"@kubb/renderer-jsx": "5.0.0-beta.19"
|
|
61
61
|
},
|
|
62
62
|
"size-limit": [
|
|
63
63
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ast, defineGenerator } from '@kubb/core'
|
|
2
|
-
import { File,
|
|
2
|
+
import { File, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
3
3
|
import { Type } from '../components/Type.tsx'
|
|
4
4
|
import { ENUM_TYPES_WITH_KEY_SUFFIX } from '../constants.ts'
|
|
5
5
|
import { printerTs } from '../printers/printerTs.ts'
|
|
@@ -26,10 +26,10 @@ function getPerContentTypeName(dataName: string, suffix: string): string {
|
|
|
26
26
|
|
|
27
27
|
export const typeGenerator = defineGenerator<PluginTs>({
|
|
28
28
|
name: 'typescript',
|
|
29
|
-
renderer:
|
|
29
|
+
renderer: jsxRendererSync,
|
|
30
30
|
schema(node, ctx) {
|
|
31
31
|
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options
|
|
32
|
-
const { adapter, config, resolver, root } = ctx
|
|
32
|
+
const { adapter, config, resolver, root, inputNode } = ctx
|
|
33
33
|
|
|
34
34
|
if (!node.name) {
|
|
35
35
|
return
|
|
@@ -37,7 +37,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
37
37
|
const mode = ctx.getMode(output)
|
|
38
38
|
// Build a set of schema names that are enums so the ref handler and getImports
|
|
39
39
|
// callback can use the suffixed type name (e.g. `StatusKey`) for those refs.
|
|
40
|
-
const enumSchemaNames = new Set(
|
|
40
|
+
const enumSchemaNames = new Set(inputNode.schemas.filter((s) => ast.narrowSchema(s, ast.schemaTypes.enum) && s.name).map((s) => s.name!))
|
|
41
41
|
|
|
42
42
|
function resolveImportName(schemaName: string): string {
|
|
43
43
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) {
|
|
@@ -76,8 +76,8 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
76
76
|
baseName={meta.file.baseName}
|
|
77
77
|
path={meta.file.path}
|
|
78
78
|
meta={meta.file.meta}
|
|
79
|
-
banner={resolver.resolveBanner(
|
|
80
|
-
footer={resolver.resolveFooter(
|
|
79
|
+
banner={resolver.resolveBanner(inputNode, { output, config })}
|
|
80
|
+
footer={resolver.resolveFooter(inputNode, { output, config })}
|
|
81
81
|
>
|
|
82
82
|
{mode === 'split' &&
|
|
83
83
|
imports.map((imp) => (
|
|
@@ -97,7 +97,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
97
97
|
},
|
|
98
98
|
operation(node, ctx) {
|
|
99
99
|
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = ctx.options
|
|
100
|
-
const { adapter, config, resolver, root } = ctx
|
|
100
|
+
const { adapter, config, resolver, root, inputNode } = ctx
|
|
101
101
|
|
|
102
102
|
const mode = ctx.getMode(output)
|
|
103
103
|
|
|
@@ -109,7 +109,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
109
109
|
|
|
110
110
|
// Build a set of schema names that are enums so the ref handler and getImports
|
|
111
111
|
// callback can use the suffixed type name (e.g. `StatusKey`) for those refs.
|
|
112
|
-
const enumSchemaNames = new Set(
|
|
112
|
+
const enumSchemaNames = new Set(inputNode.schemas.filter((s) => ast.narrowSchema(s, ast.schemaTypes.enum) && s.name).map((s) => s.name!))
|
|
113
113
|
|
|
114
114
|
function resolveImportName(schemaName: string): string {
|
|
115
115
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) {
|
|
@@ -281,8 +281,8 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
281
281
|
baseName={meta.file.baseName}
|
|
282
282
|
path={meta.file.path}
|
|
283
283
|
meta={meta.file.meta}
|
|
284
|
-
banner={resolver.resolveBanner(
|
|
285
|
-
footer={resolver.resolveFooter(
|
|
284
|
+
banner={resolver.resolveBanner(inputNode, { output, config })}
|
|
285
|
+
footer={resolver.resolveFooter(inputNode, { output, config })}
|
|
286
286
|
>
|
|
287
287
|
{paramTypes}
|
|
288
288
|
{responseTypes}
|