@kubb/core 5.0.0-alpha.30 → 5.0.0-alpha.32
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/{PluginDriver-D110FoJ-.d.ts → PluginDriver-nm7tvGs9.d.ts} +336 -73
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +2 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +374 -181
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -149
- package/dist/index.js +377 -185
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/src/FileManager.ts +131 -0
- package/src/FileProcessor.ts +83 -0
- package/src/Kubb.ts +5 -5
- package/src/PluginDriver.ts +29 -23
- package/src/build.ts +118 -111
- package/src/constants.ts +7 -2
- package/src/{config.ts → defineConfig.ts} +2 -8
- package/src/defineGenerator.ts +12 -13
- package/src/defineParser.ts +57 -0
- package/src/defineResolver.ts +18 -22
- package/src/devtools.ts +14 -14
- package/src/hooks/useMode.ts +2 -3
- package/src/index.ts +3 -3
- package/src/renderNode.tsx +8 -7
- package/src/types.ts +103 -56
- package/src/utils/TreeNode.ts +7 -7
- package/src/utils/getBarrelFiles.ts +30 -28
- package/src/utils/getConfigs.ts +1 -1
- package/src/utils/isInputPath.ts +8 -0
package/src/utils/TreeNode.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import type {
|
|
2
|
+
import type { FileNode } from '@kubb/ast/types'
|
|
3
3
|
import { getMode } from '../PluginDriver.ts'
|
|
4
4
|
|
|
5
5
|
type BarrelData = {
|
|
6
|
-
file?:
|
|
6
|
+
file?: FileNode
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated use file instead
|
|
9
9
|
*/
|
|
10
|
-
type:
|
|
10
|
+
type: 'single' | 'split'
|
|
11
11
|
path: string
|
|
12
12
|
name: string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Tree structure used to build per-directory barrel (`index.ts`) files from a
|
|
17
|
-
* flat list of generated {@link
|
|
17
|
+
* flat list of generated {@link FileNode} entries.
|
|
18
18
|
*
|
|
19
19
|
* Each node represents either a directory or a file within the output tree.
|
|
20
20
|
* Use {@link TreeNode.build} to construct a root node from a file list, then
|
|
@@ -143,7 +143,7 @@ export class TreeNode {
|
|
|
143
143
|
* - Filters to files under `root` (when provided) and skips `.json` files.
|
|
144
144
|
* - Returns `null` when no files match.
|
|
145
145
|
*/
|
|
146
|
-
public static build(files:
|
|
146
|
+
public static build(files: FileNode[], root?: string): TreeNode | null {
|
|
147
147
|
try {
|
|
148
148
|
const filteredTree = buildDirectoryTree(files, root)
|
|
149
149
|
|
|
@@ -187,13 +187,13 @@ export class TreeNode {
|
|
|
187
187
|
type DirectoryTree = {
|
|
188
188
|
name: string
|
|
189
189
|
path: string
|
|
190
|
-
file?:
|
|
190
|
+
file?: FileNode
|
|
191
191
|
children: Array<DirectoryTree>
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
const normalizePath = (p: string): string => p.replaceAll('\\', '/')
|
|
195
195
|
|
|
196
|
-
function buildDirectoryTree(files: Array<
|
|
196
|
+
function buildDirectoryTree(files: Array<FileNode>, rootFolder = ''): DirectoryTree | null {
|
|
197
197
|
const normalizedRootFolder = normalizePath(rootFolder)
|
|
198
198
|
const rootPrefix = normalizedRootFolder.endsWith('/') ? normalizedRootFolder : `${normalizedRootFolder}/`
|
|
199
199
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import { getRelativePath } from '@internals/utils'
|
|
4
|
-
import
|
|
4
|
+
import { createExport, createFile, createSource } from '@kubb/ast'
|
|
5
|
+
import type { FileNode } from '@kubb/ast/types'
|
|
5
6
|
import type { BarrelType } from '../types.ts'
|
|
6
7
|
import { TreeNode } from './TreeNode.ts'
|
|
7
8
|
|
|
@@ -29,22 +30,22 @@ type AddIndexesProps = {
|
|
|
29
30
|
meta?: FileMetaBase
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
function getBarrelFilesByRoot(root: string | undefined, files: Array<
|
|
33
|
-
const cachedFiles = new Map<
|
|
33
|
+
function getBarrelFilesByRoot(root: string | undefined, files: Array<FileNode>): Array<FileNode> {
|
|
34
|
+
const cachedFiles = new Map<string, FileNode>()
|
|
34
35
|
|
|
35
36
|
TreeNode.build(files, root)?.forEach((treeNode) => {
|
|
36
37
|
if (!treeNode?.children || !treeNode.parent?.data.path) {
|
|
37
38
|
return
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
const barrelFilePath = join(treeNode.parent?.data.path, 'index.ts')
|
|
41
|
-
const barrelFile
|
|
41
|
+
const barrelFilePath = join(treeNode.parent?.data.path, 'index.ts')
|
|
42
|
+
const barrelFile = createFile({
|
|
42
43
|
path: barrelFilePath,
|
|
43
44
|
baseName: 'index.ts',
|
|
44
45
|
exports: [],
|
|
45
46
|
imports: [],
|
|
46
47
|
sources: [],
|
|
47
|
-
}
|
|
48
|
+
})
|
|
48
49
|
const previousBarrelFile = cachedFiles.get(barrelFile.path)
|
|
49
50
|
const leaves = treeNode.leaves
|
|
50
51
|
|
|
@@ -67,26 +68,30 @@ function getBarrelFilesByRoot(root: string | undefined, files: Array<FabricFile.
|
|
|
67
68
|
return
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
barrelFile.exports
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
barrelFile.exports.push(
|
|
72
|
+
createExport({
|
|
73
|
+
name: [source.name],
|
|
74
|
+
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
75
|
+
isTypeOnly: source.isTypeOnly,
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
barrelFile.sources.push(
|
|
80
|
+
createSource({
|
|
81
|
+
name: source.name,
|
|
82
|
+
isTypeOnly: source.isTypeOnly,
|
|
83
|
+
//TODO use parser to generate import
|
|
84
|
+
value: '',
|
|
85
|
+
isExportable: false,
|
|
86
|
+
isIndexable: false,
|
|
87
|
+
}),
|
|
88
|
+
)
|
|
84
89
|
})
|
|
85
90
|
})
|
|
86
91
|
|
|
87
92
|
if (previousBarrelFile) {
|
|
88
93
|
previousBarrelFile.sources.push(...barrelFile.sources)
|
|
89
|
-
previousBarrelFile.exports
|
|
94
|
+
previousBarrelFile.exports.push(...barrelFile.exports)
|
|
90
95
|
} else {
|
|
91
96
|
cachedFiles.set(barrelFile.path, barrelFile)
|
|
92
97
|
}
|
|
@@ -113,10 +118,7 @@ function trimExtName(text: string): string {
|
|
|
113
118
|
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
114
119
|
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
115
120
|
*/
|
|
116
|
-
export async function getBarrelFiles(
|
|
117
|
-
files: Array<FabricFile.ResolvedFile>,
|
|
118
|
-
{ type, meta = {}, root, output }: AddIndexesProps,
|
|
119
|
-
): Promise<Array<FabricFile.File>> {
|
|
121
|
+
export async function getBarrelFiles(files: Array<FileNode>, { type, meta = {}, root, output }: AddIndexesProps): Promise<Array<FileNode>> {
|
|
120
122
|
if (!type || type === 'propagate') {
|
|
121
123
|
return []
|
|
122
124
|
}
|
|
@@ -133,13 +135,13 @@ export async function getBarrelFiles(
|
|
|
133
135
|
return barrelFiles.map((file) => {
|
|
134
136
|
return {
|
|
135
137
|
...file,
|
|
136
|
-
exports: file.exports
|
|
138
|
+
exports: file.exports.map((exportItem) => {
|
|
137
139
|
return {
|
|
138
140
|
...exportItem,
|
|
139
141
|
name: undefined,
|
|
140
142
|
}
|
|
141
143
|
}),
|
|
142
|
-
}
|
|
144
|
+
} as FileNode
|
|
143
145
|
})
|
|
144
146
|
}
|
|
145
147
|
|
|
@@ -147,6 +149,6 @@ export async function getBarrelFiles(
|
|
|
147
149
|
return {
|
|
148
150
|
...indexFile,
|
|
149
151
|
meta,
|
|
150
|
-
}
|
|
152
|
+
} as FileNode
|
|
151
153
|
})
|
|
152
154
|
}
|
package/src/utils/getConfigs.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InputPath, UserConfig } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a given config has an `input.path`.
|
|
5
|
+
*/
|
|
6
|
+
export function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> {
|
|
7
|
+
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
8
|
+
}
|