@kubb/core 3.0.0-alpha.2 → 3.0.0-alpha.21
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/README.md +13 -4
- package/dist/{FileManager-Bw-FNS3q.d.cts → FileManager-4lbobkix.d.cts} +124 -84
- package/dist/{FileManager-BW--rO8q.d.ts → FileManager-CdXrquQt.d.ts} +124 -84
- package/dist/chunk-2EU7DMPM.js +96 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/{chunk-LM2YQC3T.cjs → chunk-3MDDPVXB.cjs} +81 -51
- package/dist/chunk-3MDDPVXB.cjs.map +1 -0
- package/dist/chunk-4X5FFJPJ.js +8 -13
- package/dist/chunk-4X5FFJPJ.js.map +1 -1
- package/dist/{chunk-67C6RBGQ.cjs → chunk-6NKPFDXC.cjs} +28 -29
- package/dist/chunk-6NKPFDXC.cjs.map +1 -0
- package/dist/chunk-CLTNHSMO.js +895 -0
- package/dist/chunk-CLTNHSMO.js.map +1 -0
- package/dist/{chunk-3OXCZ5DJ.js → chunk-E6CN2CZC.js} +63 -54
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/chunk-HBQM723K.js +1049 -0
- package/dist/chunk-HBQM723K.js.map +1 -0
- package/dist/chunk-MHOAMP5V.cjs +1537 -0
- package/dist/chunk-MHOAMP5V.cjs.map +1 -0
- package/dist/chunk-PWFXUBH6.cjs +101 -0
- package/dist/chunk-PWFXUBH6.cjs.map +1 -0
- package/dist/chunk-RSTRL2FG.cjs +42 -0
- package/dist/chunk-RSTRL2FG.cjs.map +1 -0
- package/dist/chunk-SWGRKRKB.cjs +1088 -0
- package/dist/chunk-SWGRKRKB.cjs.map +1 -0
- package/dist/index.cjs +551 -599
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -22
- package/dist/index.d.ts +7 -22
- package/dist/index.js +442 -512
- package/dist/index.js.map +1 -1
- package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
- package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
- package/dist/logger.cjs +25 -15
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -2
- package/dist/logger.d.ts +1 -2
- package/dist/logger.js +3 -15
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +42 -31
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +7 -9
- package/dist/mocks.d.ts +7 -9
- package/dist/mocks.js +35 -33
- package/dist/mocks.js.map +1 -1
- package/dist/prompt-7BUJOOIL.cjs +760 -0
- package/dist/prompt-7BUJOOIL.cjs.map +1 -0
- package/dist/prompt-WQQUN22Z.js +749 -0
- package/dist/prompt-WQQUN22Z.js.map +1 -0
- package/dist/transformers.cjs +216 -49
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +1 -3
- package/dist/transformers.d.ts +1 -3
- package/dist/transformers.js +149 -35
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -26
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +32 -3
- package/dist/utils.d.ts +32 -3
- package/dist/utils.js +3 -26
- package/dist/utils.js.map +1 -1
- package/package.json +11 -14
- package/src/BarrelManager.ts +95 -109
- package/src/{Generator.ts → BaseGenerator.ts} +1 -1
- package/src/FileManager.ts +190 -298
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +149 -90
- package/src/PromiseManager.ts +1 -1
- package/src/__snapshots__/barrel.json +93 -0
- package/src/__snapshots__/grouped.json +120 -0
- package/src/__snapshots__/ordered.json +68 -0
- package/src/build.ts +87 -122
- package/src/config.ts +2 -4
- package/src/errors.ts +0 -11
- package/src/index.ts +2 -3
- package/src/logger.ts +76 -34
- package/src/plugin.ts +2 -5
- package/src/transformers/escape.ts +0 -10
- package/src/transformers/index.ts +2 -3
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +48 -17
- package/src/utils/TreeNode.ts +132 -50
- package/src/utils/executeStrategies.ts +3 -3
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +166 -0
- package/dist/chunk-3OXCZ5DJ.js.map +0 -1
- package/dist/chunk-5JZNFPUP.js +0 -309
- package/dist/chunk-5JZNFPUP.js.map +0 -1
- package/dist/chunk-67C6RBGQ.cjs.map +0 -1
- package/dist/chunk-ADC5UNZ5.cjs +0 -1227
- package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-JKZG2IJR.js +0 -283
- package/dist/chunk-JKZG2IJR.js.map +0 -1
- package/dist/chunk-LM2YQC3T.cjs.map +0 -1
- package/dist/chunk-PZT4CTBV.cjs +0 -299
- package/dist/chunk-PZT4CTBV.cjs.map +0 -1
- package/dist/chunk-SA2GZKXS.js +0 -596
- package/dist/chunk-SA2GZKXS.js.map +0 -1
- package/dist/chunk-XCPFG6DO.cjs +0 -66
- package/dist/chunk-XCPFG6DO.cjs.map +0 -1
- package/dist/chunk-YTSNYMHW.cjs +0 -320
- package/dist/chunk-YTSNYMHW.cjs.map +0 -1
- package/schema.json +0 -86
- package/src/utils/cache.ts +0 -35
- package/src/utils/getParser.ts +0 -17
package/src/BarrelManager.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
|
|
5
|
-
import { trimExtName } from './transformers/trim.ts'
|
|
6
3
|
import { TreeNode } from './utils/TreeNode.ts'
|
|
7
4
|
|
|
5
|
+
import { getRelativePath } from '@kubb/fs'
|
|
8
6
|
import type * as KubbFile from '@kubb/fs/types'
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Add .ts or .js
|
|
16
|
-
*/
|
|
17
|
-
extName?: KubbFile.Extname
|
|
7
|
+
import type { FileMetaBase } from './FileManager.ts'
|
|
8
|
+
import type { Logger } from './logger.ts'
|
|
9
|
+
|
|
10
|
+
type BarrelManagerOptions = {
|
|
11
|
+
logger?: Logger
|
|
18
12
|
}
|
|
19
13
|
|
|
20
14
|
export class BarrelManager {
|
|
@@ -26,116 +20,108 @@ export class BarrelManager {
|
|
|
26
20
|
return this
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (!exportedNames) {
|
|
33
|
-
return [item]
|
|
34
|
-
}
|
|
23
|
+
getFiles({ files: generatedFiles, root, meta }: { files: KubbFile.File[]; root?: string; meta?: FileMetaBase | undefined }): Array<KubbFile.File> {
|
|
24
|
+
const { logger } = this.#options
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
(prev, curr) => {
|
|
38
|
-
if (!prev[0]?.name || !prev[1]?.name) {
|
|
39
|
-
return prev
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (curr.isTypeOnly) {
|
|
43
|
-
prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] }
|
|
44
|
-
} else {
|
|
45
|
-
prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return prev
|
|
49
|
-
},
|
|
50
|
-
[
|
|
51
|
-
{
|
|
52
|
-
...item,
|
|
53
|
-
name: [],
|
|
54
|
-
isTypeOnly: false,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
...item,
|
|
58
|
-
name: [],
|
|
59
|
-
isTypeOnly: true,
|
|
60
|
-
},
|
|
61
|
-
] as KubbFile.Export[],
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getNamedExports(root: string, exports: KubbFile.Export[]): KubbFile.Export[] {
|
|
66
|
-
return exports?.flatMap((item) => {
|
|
67
|
-
return this.getNamedExport(root, item)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
26
|
+
const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()
|
|
70
27
|
|
|
71
|
-
|
|
72
|
-
const { treeNode = {}, isTypeOnly, extName } = this.#options
|
|
73
|
-
const tree = TreeNode.build(root, treeNode)
|
|
28
|
+
logger?.emit('debug', { date: new Date(), logs: [`Start barrel generation for pluginKey ${meta?.pluginKey?.join('.')} and root '${root}'`] })
|
|
74
29
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
30
|
+
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
31
|
+
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
78
34
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
const barrelFile: KubbFile.File = {
|
|
36
|
+
path: join(treeNode.parent?.data.path, 'index.ts') as KubbFile.Path,
|
|
37
|
+
baseName: 'index.ts',
|
|
38
|
+
exports: [],
|
|
39
|
+
sources: [],
|
|
82
40
|
}
|
|
41
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path)
|
|
42
|
+
const leaves = treeNode.leaves
|
|
83
43
|
|
|
84
|
-
|
|
85
|
-
|
|
44
|
+
leaves.forEach((item) => {
|
|
45
|
+
if (!item.data.name) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
86
48
|
|
|
87
|
-
const
|
|
88
|
-
.filter(Boolean)
|
|
89
|
-
.map((file) => {
|
|
90
|
-
const importPath: string = file.data.type === 'split' ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`
|
|
49
|
+
const sources = item.data.file?.sources || []
|
|
91
50
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
51
|
+
if (!sources.some((source) => source.isIndexable)) {
|
|
52
|
+
logger?.emit(
|
|
53
|
+
'warning',
|
|
54
|
+
`No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, undefined, 2)}`,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
95
57
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
sources.forEach((source) => {
|
|
59
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item) => item.name === source.name)
|
|
63
|
+
|
|
64
|
+
if (alreadyContainInPreviousBarrelFile) {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!barrelFile.exports) {
|
|
69
|
+
barrelFile.exports = []
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// true when we have a subdirectory that also contains barrel files
|
|
73
|
+
const isSubExport = !!treeNode.parent?.data.path?.split?.('/')?.length
|
|
74
|
+
|
|
75
|
+
if (isSubExport) {
|
|
76
|
+
barrelFile.exports.push({
|
|
77
|
+
name: [source.name],
|
|
78
|
+
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
79
|
+
isTypeOnly: source.isTypeOnly,
|
|
80
|
+
})
|
|
81
|
+
} else {
|
|
82
|
+
barrelFile.exports.push({
|
|
83
|
+
name: [source.name],
|
|
84
|
+
path: `./${item.data.file.baseName}`,
|
|
85
|
+
isTypeOnly: source.isTypeOnly,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
barrelFile.sources.push({
|
|
90
|
+
name: source.name,
|
|
91
|
+
isTypeOnly: source.isTypeOnly,
|
|
92
|
+
//TODO use parser to generate import
|
|
93
|
+
value: '',
|
|
94
|
+
isExportable: false,
|
|
95
|
+
isIndexable: false,
|
|
100
96
|
})
|
|
101
|
-
.filter(Boolean)
|
|
102
|
-
|
|
103
|
-
files.push({
|
|
104
|
-
path: indexPath,
|
|
105
|
-
baseName: 'index.ts',
|
|
106
|
-
source: '',
|
|
107
|
-
exports,
|
|
108
|
-
exportable: true,
|
|
109
97
|
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
119
|
-
isTypeOnly,
|
|
120
|
-
},
|
|
121
|
-
]
|
|
122
|
-
|
|
123
|
-
files.push({
|
|
124
|
-
path: indexPath,
|
|
125
|
-
baseName: 'index.ts',
|
|
126
|
-
source: '',
|
|
127
|
-
exports,
|
|
128
|
-
exportable: true,
|
|
129
|
-
})
|
|
130
|
-
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
logger?.emit('debug', {
|
|
101
|
+
date: new Date(),
|
|
102
|
+
logs: [
|
|
103
|
+
`Generating barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with ${barrelFile.sources.length} indexable exports: '${barrelFile.sources?.map((source) => source.name).join(', ')}'`,
|
|
104
|
+
],
|
|
105
|
+
})
|
|
131
106
|
|
|
132
|
-
|
|
133
|
-
|
|
107
|
+
logger?.emit('debug', {
|
|
108
|
+
date: new Date(),
|
|
109
|
+
logs: [
|
|
110
|
+
`Generated barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with exports: '${cachedFiles
|
|
111
|
+
.get(barrelFile.path)
|
|
112
|
+
?.sources?.map((source) => source.name)
|
|
113
|
+
.join(', ')}'`,
|
|
114
|
+
],
|
|
134
115
|
})
|
|
135
116
|
|
|
136
|
-
|
|
137
|
-
|
|
117
|
+
if (previousBarrelFile) {
|
|
118
|
+
previousBarrelFile.sources.push(...barrelFile.sources)
|
|
119
|
+
previousBarrelFile.exports?.push(...(barrelFile.exports || []))
|
|
120
|
+
} else {
|
|
121
|
+
cachedFiles.set(barrelFile.path, barrelFile)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
138
124
|
|
|
139
|
-
return
|
|
125
|
+
return [...cachedFiles.values()]
|
|
140
126
|
}
|
|
141
127
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
3
3
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
4
4
|
*/
|
|
5
|
-
export abstract class
|
|
5
|
+
export abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
6
6
|
#options: TOptions = {} as TOptions
|
|
7
7
|
#context: TContext = {} as TContext
|
|
8
8
|
|