@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.
@@ -1,20 +1,20 @@
1
1
  import path from 'node:path'
2
- import type { FabricFile } from '@kubb/fabric-core/types'
2
+ import type { FileNode } from '@kubb/ast/types'
3
3
  import { getMode } from '../PluginDriver.ts'
4
4
 
5
5
  type BarrelData = {
6
- file?: FabricFile.File
6
+ file?: FileNode
7
7
  /**
8
8
  * @deprecated use file instead
9
9
  */
10
- type: FabricFile.Mode
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 FabricFile.File} entries.
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: FabricFile.File[], root?: string): TreeNode | null {
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?: FabricFile.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<FabricFile.File>, rootFolder = ''): DirectoryTree | null {
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 type { FabricFile } from '@kubb/fabric-core/types'
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<FabricFile.ResolvedFile>): Array<FabricFile.File> {
33
- const cachedFiles = new Map<FabricFile.Path, FabricFile.File>()
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') as FabricFile.Path
41
- const barrelFile: FabricFile.File = {
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!.push({
71
- name: [source.name],
72
- path: getRelativePath(treeNode.parent?.data.path, item.data.path),
73
- isTypeOnly: source.isTypeOnly,
74
- })
75
-
76
- barrelFile.sources.push({
77
- name: source.name,
78
- isTypeOnly: source.isTypeOnly,
79
- //TODO use parser to generate import
80
- value: '',
81
- isExportable: false,
82
- isIndexable: false,
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?.push(...(barrelFile.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?.map((exportItem) => {
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
  }
@@ -1,4 +1,4 @@
1
- import type { CLIOptions, ConfigInput } from '../config.ts'
1
+ import type { CLIOptions, ConfigInput } from '../defineConfig.ts'
2
2
  import type { Config, UserConfig } from '../types.ts'
3
3
 
4
4
  /**
@@ -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
+ }