@kubb/middleware-barrel 5.0.0-beta.3 → 5.0.0-beta.5
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/extension.yaml +191 -0
- package/package.json +3 -2
package/extension.yaml
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
$schema: https://kubb.dev/schemas/extension.json
|
|
2
|
+
kind: middleware
|
|
3
|
+
id: middleware-barrel
|
|
4
|
+
name: Barrel
|
|
5
|
+
description: Automatically generates barrel files (index.ts exports) for every plugin output directory. Ships with Kubb and is enabled by default.
|
|
6
|
+
category: output
|
|
7
|
+
type: official
|
|
8
|
+
npmPackage: '@kubb/middleware-barrel'
|
|
9
|
+
docsPath: /middlewares/middleware-barrel
|
|
10
|
+
repo: https://github.com/kubb-labs/kubb
|
|
11
|
+
maintainers:
|
|
12
|
+
- name: Stijn Van Hulle
|
|
13
|
+
github: stijnvanhulle
|
|
14
|
+
compatibility:
|
|
15
|
+
kubb: '>=5.0.0'
|
|
16
|
+
node: '>=22'
|
|
17
|
+
tags:
|
|
18
|
+
- barrel
|
|
19
|
+
- index
|
|
20
|
+
- exports
|
|
21
|
+
- output
|
|
22
|
+
resources:
|
|
23
|
+
documentation: https://kubb.dev/middlewares/middleware-barrel
|
|
24
|
+
repository: https://github.com/kubb-labs/kubb
|
|
25
|
+
issues: https://github.com/kubb-labs/kubb/issues
|
|
26
|
+
changelog: https://github.com/kubb-labs/kubb/blob/main/packages/middleware-barrel/CHANGELOG.md
|
|
27
|
+
featured: true
|
|
28
|
+
intro: |-
|
|
29
|
+
The barrel middleware automatically generates `index.ts` (and `index.js`) re-export files for every plugin output directory **and** a root barrel at `config.output.path/index.ts` after the build finishes.
|
|
30
|
+
|
|
31
|
+
It ships with Kubb and is registered as a default middleware in `defineConfig`, so you get barrel files out of the box with no extra configuration. When `middlewareBarrel` is part of `config.middleware`, `defineConfig` also applies a default `output.barrel` of `{ type: 'named' }`. Custom middleware lists that omit `middlewareBarrel` leave `barrel` untouched.
|
|
32
|
+
|
|
33
|
+
Plugins inherit `output.barrel` from `config.output.barrel` when their own value is omitted. Setting `barrel: false` on a plugin disables that plugin's barrel **and** excludes its files from the root barrel.
|
|
34
|
+
options:
|
|
35
|
+
- name: barrel
|
|
36
|
+
type: "{ type: 'all' | 'named', nested?: boolean } | false"
|
|
37
|
+
required: false
|
|
38
|
+
default: "{ type: 'named' }"
|
|
39
|
+
description: |-
|
|
40
|
+
Re-export style for the generated barrel files. Configured via `output.barrel` in `defineConfig` (root level) or per plugin via the plugin's own `output.barrel`. This is not a middleware argument.
|
|
41
|
+
|
|
42
|
+
At the config level:
|
|
43
|
+
- `{ type: 'all' }` — `export * from '...'` for every generated file
|
|
44
|
+
- `{ type: 'named' }` — `export { name1, name2 } from '...'` using each file's named exports
|
|
45
|
+
- `false` — disables barrel generation entirely
|
|
46
|
+
|
|
47
|
+
At the plugin level, the `nested` flag is also available:
|
|
48
|
+
- `{ type: 'named', nested: true }` — generates a barrel for every directory, re-exporting only direct children, creating a chain for imports from any depth
|
|
49
|
+
- `false` — disables barrel generation for that plugin and excludes its files from the root barrel
|
|
50
|
+
|
|
51
|
+
The `{ type: 'named' }` default is applied automatically by `defineConfig` only when `middlewareBarrel` is part of `config.middleware`.
|
|
52
|
+
codeBlock:
|
|
53
|
+
lang: typescript
|
|
54
|
+
title: kubb.config.ts
|
|
55
|
+
twoslash: false
|
|
56
|
+
code: |-
|
|
57
|
+
import { defineConfig } from 'kubb'
|
|
58
|
+
import { middlewareBarrel } from '@kubb/middleware-barrel'
|
|
59
|
+
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
input: { path: './petstore.yaml' },
|
|
62
|
+
output: { path: './src/gen', barrel: { type: 'named' } },
|
|
63
|
+
middleware: [middlewareBarrel()],
|
|
64
|
+
})
|
|
65
|
+
examples:
|
|
66
|
+
- name: "barrel: { type: 'named' } (default)"
|
|
67
|
+
files:
|
|
68
|
+
- name: kubb.config.ts
|
|
69
|
+
lang: typescript
|
|
70
|
+
twoslash: false
|
|
71
|
+
code: |-
|
|
72
|
+
import { defineConfig } from 'kubb'
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
input: { path: './petstore.yaml' },
|
|
76
|
+
output: { path: './src/gen' },
|
|
77
|
+
})
|
|
78
|
+
- name: 'Generated output'
|
|
79
|
+
lang: typescript
|
|
80
|
+
twoslash: false
|
|
81
|
+
code: |-
|
|
82
|
+
// src/gen/index.ts
|
|
83
|
+
export { getUser, User } from './api/user'
|
|
84
|
+
export { getPost, Post } from './api/post'
|
|
85
|
+
export { User } from './api/types/User'
|
|
86
|
+
export { useUser } from './hooks/useUser'
|
|
87
|
+
|
|
88
|
+
// src/gen/api/index.ts
|
|
89
|
+
export { getUser, User } from './user'
|
|
90
|
+
export { getPost, Post } from './post'
|
|
91
|
+
export { User } from './types/User'
|
|
92
|
+
|
|
93
|
+
// src/gen/api/types/index.ts
|
|
94
|
+
export { User } from './User'
|
|
95
|
+
- name: "barrel: { type: 'all' }"
|
|
96
|
+
files:
|
|
97
|
+
- name: kubb.config.ts
|
|
98
|
+
lang: typescript
|
|
99
|
+
twoslash: false
|
|
100
|
+
code: |-
|
|
101
|
+
import { defineConfig } from 'kubb'
|
|
102
|
+
|
|
103
|
+
export default defineConfig({
|
|
104
|
+
input: { path: './petstore.yaml' },
|
|
105
|
+
output: { path: './src/gen', barrel: { type: 'all' } },
|
|
106
|
+
})
|
|
107
|
+
- name: 'Generated output'
|
|
108
|
+
lang: typescript
|
|
109
|
+
twoslash: false
|
|
110
|
+
code: |-
|
|
111
|
+
// src/gen/index.ts
|
|
112
|
+
export * from './api/user'
|
|
113
|
+
export * from './api/post'
|
|
114
|
+
export * from './api/types/User'
|
|
115
|
+
export * from './hooks/useUser'
|
|
116
|
+
|
|
117
|
+
// src/gen/api/index.ts
|
|
118
|
+
export * from './user'
|
|
119
|
+
export * from './post'
|
|
120
|
+
export * from './types/User'
|
|
121
|
+
|
|
122
|
+
// src/gen/api/types/index.ts
|
|
123
|
+
export * from './User'
|
|
124
|
+
- name: "barrel: { type: 'named', nested: true }"
|
|
125
|
+
files:
|
|
126
|
+
- name: kubb.config.ts
|
|
127
|
+
lang: typescript
|
|
128
|
+
twoslash: false
|
|
129
|
+
code: |-
|
|
130
|
+
import { defineConfig } from 'kubb'
|
|
131
|
+
|
|
132
|
+
export default defineConfig({
|
|
133
|
+
input: { path: './petstore.yaml' },
|
|
134
|
+
output: { path: './src/gen', barrel: { type: 'named', nested: true } },
|
|
135
|
+
})
|
|
136
|
+
- name: 'Generated output (chained structure)'
|
|
137
|
+
lang: typescript
|
|
138
|
+
twoslash: false
|
|
139
|
+
code: |-
|
|
140
|
+
// src/gen/index.ts (only exports directories)
|
|
141
|
+
export * from './api'
|
|
142
|
+
export * from './hooks'
|
|
143
|
+
|
|
144
|
+
// src/gen/api/index.ts (exports files and subdirs)
|
|
145
|
+
export * from './user'
|
|
146
|
+
export * from './post'
|
|
147
|
+
export * from './types'
|
|
148
|
+
|
|
149
|
+
// src/gen/api/types/index.ts (exports files)
|
|
150
|
+
export * from './User'
|
|
151
|
+
- name: Disable barrel for a single plugin
|
|
152
|
+
files:
|
|
153
|
+
- name: kubb.config.ts
|
|
154
|
+
lang: typescript
|
|
155
|
+
twoslash: false
|
|
156
|
+
code: |-
|
|
157
|
+
import { defineConfig } from 'kubb'
|
|
158
|
+
import { pluginTs } from '@kubb/plugin-ts'
|
|
159
|
+
import { pluginZod } from '@kubb/plugin-zod'
|
|
160
|
+
|
|
161
|
+
// pluginZod opts out: no zod/index.ts is created
|
|
162
|
+
// and zod files are excluded from the root index.ts.
|
|
163
|
+
export default defineConfig({
|
|
164
|
+
input: { path: './petstore.yaml' },
|
|
165
|
+
output: { path: './src/gen' },
|
|
166
|
+
plugins: [
|
|
167
|
+
pluginTs(),
|
|
168
|
+
pluginZod({ output: { barrel: false } }),
|
|
169
|
+
],
|
|
170
|
+
})
|
|
171
|
+
- name: Disable the root barrel only
|
|
172
|
+
files:
|
|
173
|
+
- name: kubb.config.ts
|
|
174
|
+
lang: typescript
|
|
175
|
+
twoslash: false
|
|
176
|
+
code: |-
|
|
177
|
+
import { defineConfig } from 'kubb'
|
|
178
|
+
|
|
179
|
+
// No root index.ts is generated, but each plugin
|
|
180
|
+
// still gets its own barrel using its inherited barrel config.
|
|
181
|
+
export default defineConfig({
|
|
182
|
+
input: { path: './petstore.yaml' },
|
|
183
|
+
output: { path: './src/gen', barrel: false },
|
|
184
|
+
})
|
|
185
|
+
notes:
|
|
186
|
+
- type: tip
|
|
187
|
+
body: |-
|
|
188
|
+
`middleware-barrel` is bundled with Kubb and enabled automatically when no `middleware` option is provided. You only need to install it explicitly when customising the barrel behaviour alongside other middlewares.
|
|
189
|
+
- type: note
|
|
190
|
+
body: |-
|
|
191
|
+
`output.barrel` is only auto-defaulted to `{ type: 'named' }` when `middlewareBarrel` is part of `config.middleware`. If you provide a custom middleware list without it, set `output.barrel` yourself if you still want a barrel.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/middleware-barrel",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.5",
|
|
4
4
|
"description": "Barrel-file generation middleware for Kubb. Generates index.ts barrel files for each plugin's output directory and a root index.ts after all plugins have run.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"barrel",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"src",
|
|
23
23
|
"dist",
|
|
24
|
+
"extension.yaml",
|
|
24
25
|
"*.d.ts",
|
|
25
26
|
"*.d.cts",
|
|
26
27
|
"!/**/**.test.**",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"@internals/utils": "0.0.0"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
|
-
"@kubb/core": "5.0.0-beta.
|
|
51
|
+
"@kubb/core": "5.0.0-beta.5"
|
|
51
52
|
},
|
|
52
53
|
"engines": {
|
|
53
54
|
"node": ">=22"
|