@kubb/core 3.0.0-alpha.9 → 3.0.0-beta.2
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 +14 -5
- package/dist/{FileManager-B0GJlthB.d.cts → FileManager-C9aZTwst.d.ts} +94 -77
- package/dist/{FileManager-BFycBDqG.d.ts → FileManager-ibNoWwHN.d.cts} +94 -77
- package/dist/chunk-2EU7DMPM.js +2 -3
- package/dist/chunk-2EU7DMPM.js.map +1 -1
- package/dist/{chunk-DID47EQD.cjs → chunk-2TOEDZ2U.cjs} +6 -7
- package/dist/chunk-2TOEDZ2U.cjs.map +1 -0
- package/dist/{chunk-A6PCLWEY.cjs → chunk-4GJEWGQN.cjs} +30 -31
- package/dist/chunk-4GJEWGQN.cjs.map +1 -0
- package/dist/{chunk-SEH6NUCX.cjs → chunk-72BWXKV4.cjs} +10 -10
- package/dist/chunk-72BWXKV4.cjs.map +1 -0
- package/dist/{chunk-4X5FFJPJ.js → chunk-BQXM32UO.js} +11 -16
- package/dist/chunk-BQXM32UO.js.map +1 -0
- package/dist/{chunk-27CPVXAT.js → chunk-DXGMSPTW.js} +174 -231
- package/dist/chunk-DXGMSPTW.js.map +1 -0
- package/dist/{chunk-SCR3LUXT.js → chunk-E6CN2CZC.js} +38 -27
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/chunk-HBQM723K.js +12 -26
- package/dist/chunk-HBQM723K.js.map +1 -1
- package/dist/{chunk-5E2I6KH4.cjs → chunk-KXT7F2WS.cjs} +54 -37
- package/dist/chunk-KXT7F2WS.cjs.map +1 -0
- package/dist/{chunk-IPZQXBA2.cjs → chunk-MVWRVN66.cjs} +57 -34
- package/dist/chunk-MVWRVN66.cjs.map +1 -0
- package/dist/{chunk-5IGANEGE.cjs → chunk-SQBOUPF4.cjs} +268 -301
- package/dist/chunk-SQBOUPF4.cjs.map +1 -0
- package/dist/index.cjs +223 -241
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -6
- package/dist/index.d.ts +4 -6
- package/dist/index.js +106 -148
- package/dist/index.js.map +1 -1
- package/dist/{logger-BWFeedRk.d.cts → logger-DvbHXjIO.d.cts} +10 -8
- package/dist/{logger-BWFeedRk.d.ts → logger-DvbHXjIO.d.ts} +10 -8
- package/dist/logger.cjs +25 -14
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +3 -13
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +29 -24
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +4 -3
- package/dist/mocks.d.ts +4 -3
- package/dist/mocks.js +22 -25
- package/dist/mocks.js.map +1 -1
- package/dist/{prompt-DVQN7JTN.cjs → prompt-FODZPXQF.cjs} +89 -89
- package/dist/prompt-FODZPXQF.cjs.map +1 -0
- package/dist/prompt-WQQUN22Z.js +8 -13
- package/dist/prompt-WQQUN22Z.js.map +1 -1
- package/dist/transformers.cjs +63 -52
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +1 -1
- package/dist/transformers.d.ts +1 -1
- package/dist/transformers.js +10 -37
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -34
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +6 -8
- package/dist/utils.d.ts +6 -8
- package/dist/utils.js +3 -33
- package/dist/utils.js.map +1 -1
- package/package.json +10 -13
- package/src/BarrelManager.ts +76 -74
- package/src/FileManager.ts +55 -60
- package/src/PluginManager.ts +61 -61
- package/src/PromiseManager.ts +1 -1
- package/src/__snapshots__/barrel.json +11 -29
- package/src/__snapshots__/grouped.json +18 -12
- package/src/__snapshots__/ordered.json +18 -12
- package/src/build.ts +24 -11
- package/src/config.ts +2 -4
- package/src/index.ts +1 -1
- package/src/logger.ts +41 -7
- package/src/plugin.ts +0 -3
- package/src/transformers/escape.ts +0 -10
- package/src/transformers/stringify.ts +1 -1
- package/src/types.ts +70 -38
- package/src/utils/TreeNode.ts +31 -56
- package/src/utils/executeStrategies.ts +2 -2
- package/src/utils/parser.ts +38 -39
- package/dist/chunk-27CPVXAT.js.map +0 -1
- package/dist/chunk-4X5FFJPJ.js.map +0 -1
- package/dist/chunk-5E2I6KH4.cjs.map +0 -1
- package/dist/chunk-5IGANEGE.cjs.map +0 -1
- package/dist/chunk-A6PCLWEY.cjs.map +0 -1
- package/dist/chunk-DID47EQD.cjs.map +0 -1
- package/dist/chunk-IPZQXBA2.cjs.map +0 -1
- package/dist/chunk-SCR3LUXT.js.map +0 -1
- package/dist/chunk-SEH6NUCX.cjs.map +0 -1
- package/dist/prompt-DVQN7JTN.cjs.map +0 -1
- package/src/utils/cache.ts +0 -35
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "Generator core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -77,30 +77,27 @@
|
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"change-case": "^5.4.4",
|
|
79
79
|
"find-up": "^7.0.0",
|
|
80
|
-
"natural-orderby": "^
|
|
80
|
+
"natural-orderby": "^4.0.0",
|
|
81
81
|
"object-hash": "^3.0.0",
|
|
82
82
|
"p-queue": "^8.0.1",
|
|
83
|
-
"remeda": "^2.
|
|
83
|
+
"remeda": "^2.14.0",
|
|
84
84
|
"seedrandom": "^3.0.5",
|
|
85
85
|
"semver": "^7.6.3",
|
|
86
|
-
"
|
|
87
|
-
"@kubb/
|
|
88
|
-
"@kubb/
|
|
89
|
-
"@kubb/types": "3.0.0-alpha.9"
|
|
86
|
+
"@kubb/fs": "3.0.0-beta.2",
|
|
87
|
+
"@kubb/parser-ts": "3.0.0-beta.2",
|
|
88
|
+
"@kubb/types": "3.0.0-beta.2"
|
|
90
89
|
},
|
|
91
90
|
"devDependencies": {
|
|
92
91
|
"@types/object-hash": "^3.0.6",
|
|
93
|
-
"@types/react": "^18.3.4",
|
|
94
92
|
"@types/seedrandom": "^3.0.8",
|
|
95
93
|
"@types/semver": "^7.5.8",
|
|
96
94
|
"consola": "^3.2.3",
|
|
97
95
|
"prettier": "^3.3.3",
|
|
98
96
|
"tinyrainbow": "^1.2.0",
|
|
99
|
-
"tsup": "^8.
|
|
100
|
-
"typescript": "^5.
|
|
101
|
-
"@kubb/config-
|
|
102
|
-
"@kubb/config-
|
|
103
|
-
"@kubb/config-tsup": "3.0.0-alpha.9"
|
|
97
|
+
"tsup": "^8.3.0",
|
|
98
|
+
"typescript": "^5.6.2",
|
|
99
|
+
"@kubb/config-ts": "3.0.0-beta.2",
|
|
100
|
+
"@kubb/config-tsup": "3.0.0-beta.2"
|
|
104
101
|
},
|
|
105
102
|
"engines": {
|
|
106
103
|
"node": ">=20"
|
package/src/BarrelManager.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { TreeNode } from './utils/TreeNode.ts'
|
|
|
4
4
|
|
|
5
5
|
import { getRelativePath } from '@kubb/fs'
|
|
6
6
|
import type * as KubbFile from '@kubb/fs/types'
|
|
7
|
-
import {
|
|
7
|
+
import type { FileMetaBase } from './FileManager.ts'
|
|
8
8
|
import type { Logger } from './logger.ts'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type BarrelManagerOptions = {
|
|
11
11
|
logger?: Logger
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -20,106 +20,108 @@ export class BarrelManager {
|
|
|
20
20
|
return this
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
getFiles(generatedFiles: KubbFile.File[]
|
|
23
|
+
getFiles({ files: generatedFiles, root, meta }: { files: KubbFile.File[]; root?: string; meta?: FileMetaBase | undefined }): Array<KubbFile.File> {
|
|
24
24
|
const { logger } = this.#options
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()
|
|
27
|
+
|
|
28
|
+
logger?.emit('debug', { date: new Date(), logs: [`Start barrel generation for pluginKey ${meta?.pluginKey?.join('.')} and root '${root}'`] })
|
|
27
29
|
|
|
28
30
|
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
29
31
|
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
|
|
30
32
|
return undefined
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
const
|
|
34
|
-
|
|
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: [],
|
|
40
|
+
}
|
|
41
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path)
|
|
35
42
|
const leaves = treeNode.leaves
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
leaves.forEach((item) => {
|
|
45
|
+
if (!item.data.name) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const sources = item.data.file?.sources || []
|
|
43
50
|
|
|
44
|
-
|
|
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
|
+
}
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
`No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, undefined, 2)}`,
|
|
50
|
-
)
|
|
58
|
+
sources.forEach((source) => {
|
|
59
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) {
|
|
60
|
+
return undefined
|
|
51
61
|
}
|
|
62
|
+
const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item) => item.name === source.name)
|
|
52
63
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
64
|
+
if (alreadyContainInPreviousBarrelFile) {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
if (!barrelFile.exports) {
|
|
69
|
+
barrelFile.exports = []
|
|
70
|
+
}
|
|
60
71
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
name: [source.name],
|
|
64
|
-
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
65
|
-
isTypeOnly: source.isTypeOnly,
|
|
66
|
-
} as KubbFile.Export
|
|
67
|
-
}
|
|
72
|
+
// true when we have a subdirectory that also contains barrel files
|
|
73
|
+
const isSubExport = !!treeNode.parent?.data.path?.split?.('/')?.length
|
|
68
74
|
|
|
69
|
-
|
|
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({
|
|
70
83
|
name: [source.name],
|
|
71
84
|
path: `./${item.data.file.baseName}`,
|
|
72
85
|
isTypeOnly: source.isTypeOnly,
|
|
73
|
-
} as KubbFile.Export
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
.flat()
|
|
77
|
-
.filter(Boolean)
|
|
78
|
-
|
|
79
|
-
const barrelFile: KubbFile.File = {
|
|
80
|
-
path: barrelPath,
|
|
81
|
-
baseName: 'index.ts',
|
|
82
|
-
exports: exports,
|
|
83
|
-
sources: exports.flatMap((item) => {
|
|
84
|
-
if (Array.isArray(item.name)) {
|
|
85
|
-
return item.name.map((name) => {
|
|
86
|
-
return {
|
|
87
|
-
name: name,
|
|
88
|
-
isTypeOnly: item.isTypeOnly,
|
|
89
|
-
//TODO use parser to generate import
|
|
90
|
-
value: '',
|
|
91
|
-
isExportable: false,
|
|
92
|
-
isIndexable: false,
|
|
93
|
-
} as KubbFile.Source
|
|
94
86
|
})
|
|
95
87
|
}
|
|
96
|
-
return [
|
|
97
|
-
{
|
|
98
|
-
name: item.name,
|
|
99
|
-
isTypeOnly: item.isTypeOnly,
|
|
100
|
-
//TODO use parser to generate import
|
|
101
|
-
value: '',
|
|
102
|
-
isExportable: false,
|
|
103
|
-
isIndexable: false,
|
|
104
|
-
} as KubbFile.Source,
|
|
105
|
-
]
|
|
106
|
-
}),
|
|
107
|
-
}
|
|
108
88
|
|
|
109
|
-
|
|
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,
|
|
96
|
+
})
|
|
97
|
+
})
|
|
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
|
+
})
|
|
106
|
+
|
|
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
|
+
],
|
|
115
|
+
})
|
|
110
116
|
|
|
111
117
|
if (previousBarrelFile) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
...barrelFile,
|
|
115
|
-
exports: combineExports([...(previousBarrelFile.exports || []), ...(barrelFile.exports || [])]),
|
|
116
|
-
sources: combineSources([...(previousBarrelFile.sources || []), ...(barrelFile.sources || [])]),
|
|
117
|
-
})
|
|
118
|
+
previousBarrelFile.sources.push(...barrelFile.sources)
|
|
119
|
+
previousBarrelFile.exports?.push(...(barrelFile.exports || []))
|
|
118
120
|
} else {
|
|
119
|
-
|
|
121
|
+
cachedFiles.set(barrelFile.path, barrelFile)
|
|
120
122
|
}
|
|
121
123
|
})
|
|
122
124
|
|
|
123
|
-
return [...
|
|
125
|
+
return [...cachedFiles.values()]
|
|
124
126
|
}
|
|
125
127
|
}
|
package/src/FileManager.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { ResolvedFile } from '@kubb/fs/types'
|
|
|
13
13
|
import type { GreaterThan } from '@kubb/types'
|
|
14
14
|
import PQueue from 'p-queue'
|
|
15
15
|
import type { Logger } from './logger.ts'
|
|
16
|
-
import type { Config, Plugin } from './types.ts'
|
|
16
|
+
import type { BarrelType, Config, Plugin } from './types.ts'
|
|
17
17
|
import { createFile, getFileParser } from './utils'
|
|
18
18
|
import { type DirectoryTree, TreeNode, buildDirectoryTree } from './utils/TreeNode.ts'
|
|
19
19
|
|
|
@@ -24,6 +24,7 @@ export type FileMetaBase = {
|
|
|
24
24
|
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>
|
|
25
25
|
|
|
26
26
|
type AddIndexesProps = {
|
|
27
|
+
type: BarrelType | false | undefined
|
|
27
28
|
/**
|
|
28
29
|
* Root based on root and output.path specified in the config
|
|
29
30
|
*/
|
|
@@ -34,9 +35,6 @@ type AddIndexesProps = {
|
|
|
34
35
|
*/
|
|
35
36
|
output: {
|
|
36
37
|
path: string
|
|
37
|
-
extName?: KubbFile.Extname
|
|
38
|
-
exportAs?: string
|
|
39
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
40
38
|
}
|
|
41
39
|
group?: {
|
|
42
40
|
output: string
|
|
@@ -49,31 +47,33 @@ type AddIndexesProps = {
|
|
|
49
47
|
|
|
50
48
|
export class FileManager {
|
|
51
49
|
#filesByPath: Map<KubbFile.Path, KubbFile.ResolvedFile> = new Map()
|
|
52
|
-
#files: Set<KubbFile.ResolvedFile> = new Set()
|
|
53
50
|
constructor() {
|
|
54
51
|
return this
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
get files(): Array<KubbFile.ResolvedFile> {
|
|
58
|
-
return
|
|
55
|
+
return [...this.#filesByPath.values()]
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
get orderedFiles(): Array<KubbFile.ResolvedFile> {
|
|
62
|
-
return orderBy(
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
return orderBy(
|
|
60
|
+
[...this.#filesByPath.values()],
|
|
61
|
+
[
|
|
62
|
+
(v) => v?.meta && 'pluginKey' in v.meta && !v.meta.pluginKey,
|
|
63
|
+
(v) => v.path.length,
|
|
64
|
+
(v) => trimExtName(v.path).endsWith('index'),
|
|
65
|
+
(v) => trimExtName(v.baseName),
|
|
66
|
+
(v) => v.path.split('.').pop(),
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
get groupedFiles(): DirectoryTree | null {
|
|
72
|
-
return buildDirectoryTree(
|
|
72
|
+
return buildDirectoryTree([...this.#filesByPath.values()])
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
get treeNode(): TreeNode | null {
|
|
76
|
-
return TreeNode.build(
|
|
76
|
+
return TreeNode.build([...this.#filesByPath.values()])
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
async add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T> {
|
|
@@ -98,14 +98,12 @@ export class FileManager {
|
|
|
98
98
|
const resolvedFile = createFile(file)
|
|
99
99
|
|
|
100
100
|
this.#filesByPath.set(resolvedFile.path, resolvedFile)
|
|
101
|
-
this.#files.add(resolvedFile)
|
|
102
101
|
|
|
103
102
|
return resolvedFile
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
clear() {
|
|
107
106
|
this.#filesByPath.clear()
|
|
108
|
-
this.#files.clear()
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
async #addOrAppend(file: KubbFile.File): Promise<ResolvedFile> {
|
|
@@ -113,7 +111,6 @@ export class FileManager {
|
|
|
113
111
|
|
|
114
112
|
if (previousFile) {
|
|
115
113
|
this.#filesByPath.delete(previousFile.path)
|
|
116
|
-
this.#files.delete(previousFile)
|
|
117
114
|
|
|
118
115
|
return this.#add(mergeFile(previousFile, file))
|
|
119
116
|
}
|
|
@@ -121,14 +118,7 @@ export class FileManager {
|
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
getCacheById(id: string): KubbFile.File | undefined {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.#files.forEach((file) => {
|
|
127
|
-
if (file.id === id) {
|
|
128
|
-
cache = file
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
return cache
|
|
121
|
+
return [...this.#filesByPath.values()].find((file) => file.id === id)
|
|
132
122
|
}
|
|
133
123
|
|
|
134
124
|
getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | undefined {
|
|
@@ -142,17 +132,15 @@ export class FileManager {
|
|
|
142
132
|
}
|
|
143
133
|
|
|
144
134
|
this.#filesByPath.delete(path)
|
|
145
|
-
this.#files.delete(cacheItem)
|
|
146
135
|
}
|
|
147
136
|
|
|
148
|
-
async getBarrelFiles({ files, meta, root, output, logger }: AddIndexesProps): Promise<KubbFile.File[]> {
|
|
149
|
-
|
|
150
|
-
const barrelManager = new BarrelManager({ logger })
|
|
151
|
-
|
|
152
|
-
if (exportType === false) {
|
|
137
|
+
async getBarrelFiles({ type, files, meta = {}, root, output, logger }: AddIndexesProps): Promise<KubbFile.File[]> {
|
|
138
|
+
if (!type) {
|
|
153
139
|
return []
|
|
154
140
|
}
|
|
155
141
|
|
|
142
|
+
const barrelManager = new BarrelManager({ logger })
|
|
143
|
+
|
|
156
144
|
const pathToBuildFrom = join(root, output.path)
|
|
157
145
|
|
|
158
146
|
if (trimExtName(pathToBuildFrom).endsWith('index')) {
|
|
@@ -161,9 +149,9 @@ export class FileManager {
|
|
|
161
149
|
return []
|
|
162
150
|
}
|
|
163
151
|
|
|
164
|
-
const barrelFiles = barrelManager.getFiles(files, pathToBuildFrom)
|
|
152
|
+
const barrelFiles = barrelManager.getFiles({ files, root: pathToBuildFrom, meta })
|
|
165
153
|
|
|
166
|
-
if (
|
|
154
|
+
if (type === 'all') {
|
|
167
155
|
return barrelFiles.map((file) => {
|
|
168
156
|
return {
|
|
169
157
|
...file,
|
|
@@ -203,16 +191,21 @@ export class FileManager {
|
|
|
203
191
|
}
|
|
204
192
|
|
|
205
193
|
type GetSourceOptions = {
|
|
194
|
+
extname?: KubbFile.Extname
|
|
206
195
|
logger?: Logger
|
|
207
196
|
}
|
|
208
197
|
|
|
209
|
-
export async function getSource<TMeta extends FileMetaBase = FileMetaBase>(
|
|
210
|
-
|
|
198
|
+
export async function getSource<TMeta extends FileMetaBase = FileMetaBase>(
|
|
199
|
+
file: ResolvedFile<TMeta>,
|
|
200
|
+
{ logger, extname }: GetSourceOptions = {},
|
|
201
|
+
): Promise<string> {
|
|
202
|
+
const parser = await getFileParser(file.extname)
|
|
203
|
+
const source = await parser.print(file, { logger, extname })
|
|
211
204
|
|
|
212
|
-
return parser.
|
|
205
|
+
return parser.format(source)
|
|
213
206
|
}
|
|
214
207
|
|
|
215
|
-
|
|
208
|
+
function mergeFile<TMeta extends FileMetaBase = FileMetaBase>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {
|
|
216
209
|
return {
|
|
217
210
|
...a,
|
|
218
211
|
sources: [...(a.sources || []), ...(b.sources || [])],
|
|
@@ -224,7 +217,7 @@ export function mergeFile<TMeta extends FileMetaBase = FileMetaBase>(a: KubbFile
|
|
|
224
217
|
export function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {
|
|
225
218
|
return sources.reduce(
|
|
226
219
|
(prev, curr) => {
|
|
227
|
-
const prevByName = prev.findLast((imp) => imp.name === curr.name)
|
|
220
|
+
const prevByName = prev.findLast((imp) => imp.name && imp.name === curr.name)
|
|
228
221
|
const prevByPathAndIsExportable = prev.findLast((imp) => imp.name === curr.name && imp.isExportable)
|
|
229
222
|
|
|
230
223
|
if (prevByPathAndIsExportable) {
|
|
@@ -248,7 +241,13 @@ export function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.
|
|
|
248
241
|
}
|
|
249
242
|
|
|
250
243
|
export function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {
|
|
251
|
-
|
|
244
|
+
return orderBy(exports, [
|
|
245
|
+
(v) => !!Array.isArray(v.name),
|
|
246
|
+
(v) => !v.isTypeOnly,
|
|
247
|
+
(v) => v.path,
|
|
248
|
+
(v) => !!v.name,
|
|
249
|
+
(v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),
|
|
250
|
+
]).reduce(
|
|
252
251
|
(prev, curr) => {
|
|
253
252
|
const name = curr.name
|
|
254
253
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path)
|
|
@@ -289,18 +288,16 @@ export function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.
|
|
|
289
288
|
},
|
|
290
289
|
[] as Array<KubbFile.Export>,
|
|
291
290
|
)
|
|
291
|
+
}
|
|
292
292
|
|
|
293
|
-
|
|
293
|
+
export function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {
|
|
294
|
+
return orderBy(imports, [
|
|
294
295
|
(v) => !!Array.isArray(v.name),
|
|
295
296
|
(v) => !v.isTypeOnly,
|
|
296
297
|
(v) => v.path,
|
|
297
298
|
(v) => !!v.name,
|
|
298
299
|
(v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),
|
|
299
|
-
])
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {
|
|
303
|
-
const combinedImports = imports.reduce(
|
|
300
|
+
]).reduce(
|
|
304
301
|
(prev, curr) => {
|
|
305
302
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
306
303
|
|
|
@@ -309,7 +306,9 @@ export function combineImports(imports: Array<KubbFile.Import>, exports: Array<K
|
|
|
309
306
|
return true
|
|
310
307
|
}
|
|
311
308
|
|
|
312
|
-
const checker = (name?: string) =>
|
|
309
|
+
const checker = (name?: string) => {
|
|
310
|
+
return name && !!source.includes(name)
|
|
311
|
+
}
|
|
313
312
|
|
|
314
313
|
return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))
|
|
315
314
|
}
|
|
@@ -365,15 +364,8 @@ export function combineImports(imports: Array<KubbFile.Import>, exports: Array<K
|
|
|
365
364
|
},
|
|
366
365
|
[] as Array<KubbFile.Import>,
|
|
367
366
|
)
|
|
368
|
-
|
|
369
|
-
return orderBy(combinedImports, [
|
|
370
|
-
(v) => !!Array.isArray(v.name),
|
|
371
|
-
(v) => !v.isTypeOnly,
|
|
372
|
-
(v) => v.path,
|
|
373
|
-
(v) => !!v.name,
|
|
374
|
-
(v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),
|
|
375
|
-
])
|
|
376
367
|
}
|
|
368
|
+
|
|
377
369
|
type WriteFilesProps = {
|
|
378
370
|
config: Config
|
|
379
371
|
files: Array<KubbFile.ResolvedFile>
|
|
@@ -393,22 +385,25 @@ export async function processFiles({ dryRun, config, logger, files }: WriteFiles
|
|
|
393
385
|
])
|
|
394
386
|
|
|
395
387
|
logger.emit('debug', {
|
|
388
|
+
date: new Date(),
|
|
396
389
|
logs: [JSON.stringify({ files: orderedFiles }, null, 2)],
|
|
397
|
-
fileName: 'kubb-files.
|
|
398
|
-
override: true,
|
|
390
|
+
fileName: 'kubb-files.log',
|
|
399
391
|
})
|
|
400
392
|
|
|
401
393
|
if (!dryRun) {
|
|
402
394
|
const size = orderedFiles.length
|
|
403
395
|
|
|
404
|
-
logger.emit('progress_start', { id: 'files', size })
|
|
396
|
+
logger.emit('progress_start', { id: 'files', size, message: 'Writing files ...' })
|
|
405
397
|
const promises = orderedFiles.map(async (file) => {
|
|
406
398
|
await queue.add(async () => {
|
|
407
|
-
const
|
|
399
|
+
const message = file ? `Writing ${relative(config.root, file.path)}` : ''
|
|
400
|
+
const extname = config.output.extension?.[file.extname]
|
|
401
|
+
|
|
402
|
+
const source = await getSource(file, { logger, extname })
|
|
408
403
|
|
|
409
404
|
await write(file.path, source, { sanity: false })
|
|
410
405
|
|
|
411
|
-
logger.emit('
|
|
406
|
+
logger.emit('progressed', { id: 'files', message })
|
|
412
407
|
})
|
|
413
408
|
})
|
|
414
409
|
|