@kubb/plugin-barrel 5.0.0-beta.51
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/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/chunk-C0LytTxp.js +8 -0
- package/dist/index.cjs +410 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.js +386 -0
- package/dist/index.js.map +1 -0
- package/extension.yaml +197 -0
- package/package.json +69 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +162 -0
- package/src/types.ts +54 -0
- package/src/utils.ts +258 -0
package/extension.yaml
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
$schema: https://kubb.dev/schemas/extension.json
|
|
2
|
+
kind: plugin
|
|
3
|
+
id: plugin-barrel
|
|
4
|
+
name: Barrel
|
|
5
|
+
description: Generates `index.ts` re-export files for every plugin output and one root barrel. Ships with Kubb and is enabled by default.
|
|
6
|
+
category: output
|
|
7
|
+
type: official
|
|
8
|
+
npmPackage: '@kubb/plugin-barrel'
|
|
9
|
+
docsPath: /plugins/plugin-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/plugins/plugin-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/plugin-barrel/CHANGELOG.md
|
|
27
|
+
featured: true
|
|
28
|
+
intro: |-
|
|
29
|
+
`@kubb/plugin-barrel` generates an `index.ts` for every plugin output directory and one root barrel at `output.path/index.ts` after the build completes. The result is a single import surface for every consumer — `import { Pet, usePetByIdQuery, petMock } from './gen'`.
|
|
30
|
+
|
|
31
|
+
The plugin ships with Kubb and is registered by default in `defineConfig`, so barrels appear out of the box with no extra configuration. When `pluginBarrel` is part of `config.plugins`, `defineConfig` also applies a default `output.barrel` of `{ type: 'named' }`.
|
|
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 used for every generated barrel file. Set via `output.barrel` in `defineConfig` (applies to all plugins and the root barrel) or per plugin via that plugin's own `output.barrel`. It is not an argument to the plugin itself.
|
|
41
|
+
|
|
42
|
+
At the config level:
|
|
43
|
+
|
|
44
|
+
- `{ type: 'all' }` — `export * from '...'` for every generated file.
|
|
45
|
+
- `{ type: 'named' }` — `export { Foo, Bar } from '...'` using each file's named exports.
|
|
46
|
+
- `false` — disables barrel generation entirely.
|
|
47
|
+
|
|
48
|
+
At the plugin level you also get `nested`:
|
|
49
|
+
|
|
50
|
+
- `{ type: 'named', nested: true }` — generates a barrel for every subdirectory, re-exporting only direct children. Lets callers import from any depth.
|
|
51
|
+
- `false` — disables the plugin's barrel and removes its files from the root barrel.
|
|
52
|
+
|
|
53
|
+
The `{ type: 'named' }` default kicks in only when `pluginBarrel` is part of `config.plugins`.
|
|
54
|
+
codeBlock:
|
|
55
|
+
lang: typescript
|
|
56
|
+
title: kubb.config.ts
|
|
57
|
+
twoslash: false
|
|
58
|
+
code: |-
|
|
59
|
+
import { defineConfig } from 'kubb'
|
|
60
|
+
import { pluginBarrel } from '@kubb/plugin-barrel'
|
|
61
|
+
|
|
62
|
+
export default defineConfig({
|
|
63
|
+
input: { path: './petStore.yaml' },
|
|
64
|
+
output: { path: './src/gen', barrel: { type: 'named' } },
|
|
65
|
+
plugins: [pluginBarrel()],
|
|
66
|
+
})
|
|
67
|
+
examples:
|
|
68
|
+
- name: "{ type: 'named' } (default)"
|
|
69
|
+
files:
|
|
70
|
+
- name: kubb.config.ts
|
|
71
|
+
lang: typescript
|
|
72
|
+
twoslash: false
|
|
73
|
+
code: |-
|
|
74
|
+
import { defineConfig } from 'kubb'
|
|
75
|
+
|
|
76
|
+
export default defineConfig({
|
|
77
|
+
input: { path: './petStore.yaml' },
|
|
78
|
+
output: { path: './src/gen' },
|
|
79
|
+
plugins: [],
|
|
80
|
+
})
|
|
81
|
+
- name: Generated output
|
|
82
|
+
lang: typescript
|
|
83
|
+
twoslash: false
|
|
84
|
+
code: |-
|
|
85
|
+
// src/gen/index.ts
|
|
86
|
+
export { getUser, User } from './api/user'
|
|
87
|
+
export { getPost, Post } from './api/post'
|
|
88
|
+
export { User } from './api/types/User'
|
|
89
|
+
export { useUser } from './hooks/useUser'
|
|
90
|
+
|
|
91
|
+
// src/gen/api/index.ts
|
|
92
|
+
export { getUser, User } from './user'
|
|
93
|
+
export { getPost, Post } from './post'
|
|
94
|
+
export { User } from './types/User'
|
|
95
|
+
|
|
96
|
+
// src/gen/api/types/index.ts
|
|
97
|
+
export { User } from './User'
|
|
98
|
+
- name: "{ type: 'all' }"
|
|
99
|
+
files:
|
|
100
|
+
- name: kubb.config.ts
|
|
101
|
+
lang: typescript
|
|
102
|
+
twoslash: false
|
|
103
|
+
code: |-
|
|
104
|
+
import { defineConfig } from 'kubb'
|
|
105
|
+
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
input: { path: './petStore.yaml' },
|
|
108
|
+
output: { path: './src/gen', barrel: { type: 'all' } },
|
|
109
|
+
plugins: [],
|
|
110
|
+
})
|
|
111
|
+
- name: Generated output
|
|
112
|
+
lang: typescript
|
|
113
|
+
twoslash: false
|
|
114
|
+
code: |-
|
|
115
|
+
// src/gen/index.ts
|
|
116
|
+
export * from './api/user'
|
|
117
|
+
export * from './api/post'
|
|
118
|
+
export * from './api/types/User'
|
|
119
|
+
export * from './hooks/useUser'
|
|
120
|
+
|
|
121
|
+
// src/gen/api/index.ts
|
|
122
|
+
export * from './user'
|
|
123
|
+
export * from './post'
|
|
124
|
+
export * from './types/User'
|
|
125
|
+
|
|
126
|
+
// src/gen/api/types/index.ts
|
|
127
|
+
export * from './User'
|
|
128
|
+
- name: "{ type: 'named', nested: true }"
|
|
129
|
+
files:
|
|
130
|
+
- name: kubb.config.ts
|
|
131
|
+
lang: typescript
|
|
132
|
+
twoslash: false
|
|
133
|
+
code: |-
|
|
134
|
+
import { defineConfig } from 'kubb'
|
|
135
|
+
|
|
136
|
+
export default defineConfig({
|
|
137
|
+
input: { path: './petStore.yaml' },
|
|
138
|
+
output: { path: './src/gen', barrel: { type: 'named', nested: true } },
|
|
139
|
+
plugins: [],
|
|
140
|
+
})
|
|
141
|
+
- name: Generated output (chained structure)
|
|
142
|
+
lang: typescript
|
|
143
|
+
twoslash: false
|
|
144
|
+
code: |-
|
|
145
|
+
// src/gen/index.ts (only exports directories)
|
|
146
|
+
export * from './api'
|
|
147
|
+
export * from './hooks'
|
|
148
|
+
|
|
149
|
+
// src/gen/api/index.ts (exports files and subdirs)
|
|
150
|
+
export * from './user'
|
|
151
|
+
export * from './post'
|
|
152
|
+
export * from './types'
|
|
153
|
+
|
|
154
|
+
// src/gen/api/types/index.ts (exports files)
|
|
155
|
+
export * from './User'
|
|
156
|
+
- name: Disable the barrel for a single plugin
|
|
157
|
+
files:
|
|
158
|
+
- name: kubb.config.ts
|
|
159
|
+
lang: typescript
|
|
160
|
+
twoslash: false
|
|
161
|
+
code: |-
|
|
162
|
+
import { defineConfig } from 'kubb'
|
|
163
|
+
import { pluginTs } from '@kubb/plugin-ts'
|
|
164
|
+
import { pluginZod } from '@kubb/plugin-zod'
|
|
165
|
+
|
|
166
|
+
// pluginZod opts out: no zod/index.ts is created,
|
|
167
|
+
// and zod files are excluded from the root index.ts.
|
|
168
|
+
export default defineConfig({
|
|
169
|
+
input: { path: './petStore.yaml' },
|
|
170
|
+
output: { path: './src/gen' },
|
|
171
|
+
plugins: [
|
|
172
|
+
pluginTs(),
|
|
173
|
+
pluginZod({ output: { barrel: false } }),
|
|
174
|
+
],
|
|
175
|
+
})
|
|
176
|
+
- name: Disable only the root barrel
|
|
177
|
+
files:
|
|
178
|
+
- name: kubb.config.ts
|
|
179
|
+
lang: typescript
|
|
180
|
+
twoslash: false
|
|
181
|
+
code: |-
|
|
182
|
+
import { defineConfig } from 'kubb'
|
|
183
|
+
|
|
184
|
+
# No root index.ts is generated, but each plugin
|
|
185
|
+
# still gets its own barrel using its inherited config.
|
|
186
|
+
export default defineConfig({
|
|
187
|
+
input: { path: './petStore.yaml' },
|
|
188
|
+
output: { path: './src/gen', barrel: false },
|
|
189
|
+
plugins: [],
|
|
190
|
+
})
|
|
191
|
+
notes:
|
|
192
|
+
- type: tip
|
|
193
|
+
body: |-
|
|
194
|
+
`plugin-barrel` ships with Kubb and is enabled automatically. Install it explicitly only when customizing barrel behavior.
|
|
195
|
+
- type: note
|
|
196
|
+
body: |-
|
|
197
|
+
`output.barrel` is auto-defaulted to `{ type: 'named' }` only when `pluginBarrel` is part of `config.plugins`. Without it, set `output.barrel` yourself if you still want a barrel.
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubb/plugin-barrel",
|
|
3
|
+
"version": "5.0.0-beta.51",
|
|
4
|
+
"description": "Barrel-file plugin for Kubb. Automatically generates index.ts re-export files per plugin output directory and an optional root barrel after all plugins complete.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"barrel",
|
|
7
|
+
"codegen",
|
|
8
|
+
"kubb",
|
|
9
|
+
"plugin",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "stijnvanhulle",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/kubb-labs/kubb.git",
|
|
17
|
+
"directory": "packages/plugin-barrel"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"src",
|
|
21
|
+
"dist",
|
|
22
|
+
"extension.yaml",
|
|
23
|
+
"*.d.ts",
|
|
24
|
+
"*.d.cts",
|
|
25
|
+
"!/**/**.test.**",
|
|
26
|
+
"!/**/__tests__/**",
|
|
27
|
+
"!/**/__snapshots__/**"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"require": "./dist/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://registry.npmjs.org/"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@kubb/ast": "5.0.0-beta.51",
|
|
47
|
+
"@kubb/core": "5.0.0-beta.51"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@internals/utils": "0.0.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@kubb/core": "5.0.0-beta.51"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsdown",
|
|
60
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
61
|
+
"lint": "oxlint .",
|
|
62
|
+
"lint:fix": "oxlint --fix .",
|
|
63
|
+
"release": "pnpm publish --no-git-check",
|
|
64
|
+
"release:stage": "pnpm stage publish --no-git-check",
|
|
65
|
+
"start": "tsdown --watch",
|
|
66
|
+
"test": "vitest --passWithNoTests",
|
|
67
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/index.ts
ADDED
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import type { FileNode } from '@kubb/ast'
|
|
4
|
+
import { definePlugin } from '@kubb/core'
|
|
5
|
+
import type { Config, NormalizedPlugin, Plugin } from '@kubb/core'
|
|
6
|
+
import type { BarrelConfig, PluginBarrelConfig } from './types.ts'
|
|
7
|
+
import { getBarrelFiles, getPluginOutputPrefix, isExcludedPath } from './utils.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Applies a plugin's configured `output.banner`/`footer` to a barrel file, flagged as `isBarrel`.
|
|
11
|
+
*
|
|
12
|
+
* Resolves through the plugin's own resolver, and only when the plugin explicitly sets a
|
|
13
|
+
* banner/footer, so barrels stay banner-free by default and never inherit the implicit
|
|
14
|
+
* "Generated by Kubb" notice.
|
|
15
|
+
*/
|
|
16
|
+
function withBarrelBannerFooter({ file, plugin, config }: { file: FileNode; plugin: NormalizedPlugin; config: Config }): FileNode {
|
|
17
|
+
const output = plugin.options?.output
|
|
18
|
+
const resolver = plugin.resolver
|
|
19
|
+
if (!resolver) return file
|
|
20
|
+
|
|
21
|
+
const hasBanner = output?.banner !== undefined
|
|
22
|
+
const hasFooter = output?.footer !== undefined
|
|
23
|
+
if (!hasBanner && !hasFooter) return file
|
|
24
|
+
|
|
25
|
+
const context = { output, config, file: { path: file.path, baseName: file.baseName, isBarrel: true } }
|
|
26
|
+
return {
|
|
27
|
+
...file,
|
|
28
|
+
banner: hasBanner ? resolver.resolveBanner(undefined, context) : file.banner,
|
|
29
|
+
footer: hasFooter ? resolver.resolveFooter(undefined, context) : file.footer,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare global {
|
|
34
|
+
namespace Kubb {
|
|
35
|
+
interface PluginOptionsRegistry {
|
|
36
|
+
output: {
|
|
37
|
+
/**
|
|
38
|
+
* Barrel configuration for this plugin's output.
|
|
39
|
+
* Set to `false` to disable barrel generation for this plugin entirely. Doing so also
|
|
40
|
+
* excludes the plugin's files from the root barrel.
|
|
41
|
+
*
|
|
42
|
+
* Falls back to `config.output.barrel` when omitted.
|
|
43
|
+
*
|
|
44
|
+
* @default { type: 'named' }
|
|
45
|
+
*/
|
|
46
|
+
barrel?: PluginBarrelConfig | false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
interface ConfigOptionsRegistry {
|
|
50
|
+
output: {
|
|
51
|
+
/**
|
|
52
|
+
* Barrel configuration for the root barrel file at `config.output.path/index.ts`.
|
|
53
|
+
* Set to `false` to disable root barrel generation. Individual plugins can override
|
|
54
|
+
* this via their own `output.barrel`.
|
|
55
|
+
*
|
|
56
|
+
* @default { type: 'named' }
|
|
57
|
+
*/
|
|
58
|
+
barrel?: BarrelConfig | false
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Canonical plugin name for `@kubb/plugin-barrel`. Used for driver lookups
|
|
66
|
+
* and to guard the `kubb:plugin:end` handler against reacting to its own lifecycle event.
|
|
67
|
+
*/
|
|
68
|
+
export const pluginBarrelName = 'plugin-barrel' satisfies Plugin['name']
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generates an `index.ts` for every plugin output directory and one root
|
|
72
|
+
* barrel at `config.output.path/index.ts` after the build completes. Ships
|
|
73
|
+
* with Kubb and is registered by default in `defineConfig`.
|
|
74
|
+
*
|
|
75
|
+
* Each plugin inherits `output.barrel` from `config.output.barrel` (which
|
|
76
|
+
* defaults to `{ type: 'named' }`). Set `barrel: false` on a plugin to skip
|
|
77
|
+
* its barrel and also exclude its files from the root barrel.
|
|
78
|
+
*
|
|
79
|
+
* A plugin with `output.mode: 'file'` gets no per-plugin barrel, since its output
|
|
80
|
+
* is a single file. The root barrel re-exports that file directly.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { defineConfig } from '@kubb/core'
|
|
85
|
+
* import { pluginBarrel } from '@kubb/plugin-barrel'
|
|
86
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
87
|
+
* import { pluginZod } from '@kubb/plugin-zod'
|
|
88
|
+
*
|
|
89
|
+
* export default defineConfig({
|
|
90
|
+
* input: { path: './petStore.yaml' },
|
|
91
|
+
* output: { path: 'src/gen', barrel: { type: 'named' } },
|
|
92
|
+
* plugins: [
|
|
93
|
+
* pluginTs({ output: { path: 'types', barrel: { type: 'all' } } }),
|
|
94
|
+
* pluginZod({ output: { path: 'schemas' } }),
|
|
95
|
+
* pluginBarrel(),
|
|
96
|
+
* ],
|
|
97
|
+
* })
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export const pluginBarrel = definePlugin(() => {
|
|
101
|
+
const excludedPrefixes = new Set<string>()
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
name: pluginBarrelName,
|
|
105
|
+
enforce: 'post' as const,
|
|
106
|
+
hooks: {
|
|
107
|
+
'kubb:plugin:end'({ plugin, config, files, upsertFile }) {
|
|
108
|
+
// Skip reactions to the barrel plugin's own lifecycle event
|
|
109
|
+
if (plugin.name === pluginBarrelName) return
|
|
110
|
+
|
|
111
|
+
const pluginBarrelOpt = plugin.options.output?.barrel
|
|
112
|
+
const configBarrel = config.output.barrel
|
|
113
|
+
const defaultBarrel = { type: 'named' } as const
|
|
114
|
+
|
|
115
|
+
// Root config barrel doesn't have nested, so we add it
|
|
116
|
+
const barrelConfig: PluginBarrelConfig | false = (() => {
|
|
117
|
+
if (pluginBarrelOpt !== undefined) return pluginBarrelOpt
|
|
118
|
+
if (configBarrel !== undefined) return configBarrel === false ? false : { ...configBarrel, nested: false }
|
|
119
|
+
return defaultBarrel
|
|
120
|
+
})()
|
|
121
|
+
|
|
122
|
+
if (barrelConfig === false) {
|
|
123
|
+
excludedPrefixes.add(getPluginOutputPrefix(plugin, config))
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// `mode: 'file'` writes a single file, so there is no directory to barrel. The root barrel
|
|
128
|
+
// re-exports that file as a direct leaf of `config.output.path`.
|
|
129
|
+
if (plugin.options.output.mode === 'file') {
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const barrelType = barrelConfig.type
|
|
134
|
+
const nested = barrelConfig.nested ?? false
|
|
135
|
+
|
|
136
|
+
const base = resolve(config.root, config.output.path)
|
|
137
|
+
const target = resolve(base, plugin.options.output.path)
|
|
138
|
+
const relative = path.relative(base, target)
|
|
139
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
140
|
+
throw new Error('Invalid output path')
|
|
141
|
+
}
|
|
142
|
+
for (const file of getBarrelFiles({ outputPath: target, files, barrelType, nested, recursive: true })) {
|
|
143
|
+
upsertFile(withBarrelBannerFooter({ file, plugin, config }))
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
'kubb:plugins:end'({ files, config, upsertFile }) {
|
|
147
|
+
const barrelConfig = config.output.barrel ?? { type: 'named' }
|
|
148
|
+
|
|
149
|
+
const filteredFiles = excludedPrefixes.size === 0 ? files : files.filter((f) => !isExcludedPath(f.path, excludedPrefixes))
|
|
150
|
+
excludedPrefixes.clear()
|
|
151
|
+
|
|
152
|
+
if (barrelConfig === false) return
|
|
153
|
+
|
|
154
|
+
const barrelType = barrelConfig.type
|
|
155
|
+
|
|
156
|
+
for (const file of getBarrelFiles({ outputPath: resolve(config.root, config.output.path), files: filteredFiles, barrelType })) {
|
|
157
|
+
upsertFile(file)
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
})
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel export strategy.
|
|
3
|
+
*
|
|
4
|
+
* - `'all'` generates `export * from '...'` for every file
|
|
5
|
+
* - `'named'` generates `export { name1, name2 } from '...'` using each file's named exports
|
|
6
|
+
*/
|
|
7
|
+
export type BarrelType = 'all' | 'named'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Barrel configuration at the root config level.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* barrel: { type: 'named' } // default
|
|
15
|
+
* barrel: { type: 'all' }
|
|
16
|
+
* barrel: false // disable barrel generation
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type BarrelConfig = {
|
|
20
|
+
/**
|
|
21
|
+
* Export strategy for the root barrel file.
|
|
22
|
+
* - `'all'` wildcard exports: `export * from './file'`
|
|
23
|
+
* - `'named'` explicit exports: `export { x, y } from './file'`
|
|
24
|
+
*/
|
|
25
|
+
type: BarrelType
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Barrel configuration at the plugin level.
|
|
30
|
+
* Supports nested barrel generation in subdirectories.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* barrel: { type: 'named' } // single barrel with named exports
|
|
35
|
+
* barrel: { type: 'all', nested: true } // hierarchical barrels with wildcard exports
|
|
36
|
+
* barrel: { type: 'named', nested: true } // hierarchical barrels with named exports
|
|
37
|
+
* barrel: false // disable barrel generation
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type PluginBarrelConfig = {
|
|
41
|
+
/**
|
|
42
|
+
* Export strategy for the plugin's barrel files.
|
|
43
|
+
* - `'all'` wildcard exports: `export * from './file'`
|
|
44
|
+
* - `'named'` explicit exports: `export { x, y } from './file'`
|
|
45
|
+
*/
|
|
46
|
+
type: BarrelType
|
|
47
|
+
/**
|
|
48
|
+
* Generate an `index.ts` in every sub-directory, each re-exporting only what's directly inside it.
|
|
49
|
+
* Creates a hierarchical barrel structure instead of flat exports from the root.
|
|
50
|
+
*
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
nested?: boolean
|
|
54
|
+
}
|