@kubb/core 4.2.0 → 4.2.1
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/URLPath-8WVzHBnA.cjs +134 -0
- package/dist/URLPath-8WVzHBnA.cjs.map +1 -0
- package/dist/URLPath-BYceu_vY.js +117 -0
- package/dist/URLPath-BYceu_vY.js.map +1 -0
- package/dist/{acorn-DExO7r0H.cjs → acorn-BAVXZMtK.cjs} +1 -1
- package/dist/{acorn-DExO7r0H.cjs.map → acorn-BAVXZMtK.cjs.map} +1 -1
- package/dist/{acorn-B0JdnMwY.js → acorn-D-VhIOLw.js} +1 -1
- package/dist/{acorn-B0JdnMwY.js.map → acorn-D-VhIOLw.js.map} +1 -1
- package/dist/{angular-C2M8l5eL.cjs → angular-Bp0XO9db.cjs} +1 -1
- package/dist/{angular-C2M8l5eL.cjs.map → angular-Bp0XO9db.cjs.map} +1 -1
- package/dist/{angular-CmU_K35W.js → angular-Czhp4eq5.js} +1 -1
- package/dist/{angular-CmU_K35W.js.map → angular-Czhp4eq5.js.map} +1 -1
- package/dist/{babel-CfF0c5A9.js → babel-DCR_B4Qn.js} +1 -1
- package/dist/{babel-CfF0c5A9.js.map → babel-DCR_B4Qn.js.map} +1 -1
- package/dist/{babel-BKn0s9Rj.cjs → babel-NI0v59ga.cjs} +1 -1
- package/dist/{babel-BKn0s9Rj.cjs.map → babel-NI0v59ga.cjs.map} +1 -1
- package/dist/casing-BSeq_teY.js +100 -0
- package/dist/casing-BSeq_teY.js.map +1 -0
- package/dist/casing-CP-9GGdK.cjs +112 -0
- package/dist/casing-CP-9GGdK.cjs.map +1 -0
- package/dist/{estree-Br3l79C5.cjs → estree-C3BZPlpU.cjs} +1 -1
- package/dist/{estree-Br3l79C5.cjs.map → estree-C3BZPlpU.cjs.map} +1 -1
- package/dist/{estree-B_YMDsR7.js → estree-DU2NummP.js} +1 -1
- package/dist/{estree-B_YMDsR7.js.map → estree-DU2NummP.js.map} +1 -1
- package/dist/{flow-B_3vaVXc.cjs → flow-CWUBUkoi.cjs} +1 -1
- package/dist/{flow-B_3vaVXc.cjs.map → flow-CWUBUkoi.cjs.map} +1 -1
- package/dist/{flow-Dc3wao4M.js → flow-JiEbweKj.js} +1 -1
- package/dist/{flow-Dc3wao4M.js.map → flow-JiEbweKj.js.map} +1 -1
- package/dist/fs.d.cts +1 -1
- package/dist/fs.d.ts +1 -1
- package/dist/{glimmer-BF35HI3l.cjs → glimmer-CX9OqG1j.cjs} +1 -1
- package/dist/{glimmer-BF35HI3l.cjs.map → glimmer-CX9OqG1j.cjs.map} +1 -1
- package/dist/{glimmer-CwM1XZA1.js → glimmer-t9nWn9aE.js} +1 -1
- package/dist/{glimmer-CwM1XZA1.js.map → glimmer-t9nWn9aE.js.map} +1 -1
- package/dist/{graphql-KQQTidk7.js → graphql-DjErlIi5.js} +1 -1
- package/dist/{graphql-KQQTidk7.js.map → graphql-DjErlIi5.js.map} +1 -1
- package/dist/{graphql-DhaHiYrP.cjs → graphql-GOxQAKxM.cjs} +1 -1
- package/dist/{graphql-DhaHiYrP.cjs.map → graphql-GOxQAKxM.cjs.map} +1 -1
- package/dist/hooks.d.cts +3 -2
- package/dist/hooks.d.ts +4 -3
- package/dist/{html-B2QWX43c.cjs → html-CWrdYAhQ.cjs} +1 -1
- package/dist/{html-B2QWX43c.cjs.map → html-CWrdYAhQ.cjs.map} +1 -1
- package/dist/{html-DQoJX7Yj.js → html-_apcbx34.js} +1 -1
- package/dist/{html-DQoJX7Yj.js.map → html-_apcbx34.js.map} +1 -1
- package/dist/{index-BY_kka8d.d.ts → index-BTe91LHd.d.ts} +2 -2
- package/dist/{index-Iq8NJRgc.d.cts → index-BmQIxvw0.d.cts} +2 -2
- package/dist/index.cjs +378 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -4
- package/dist/index.d.ts +38 -5
- package/dist/index.js +371 -15
- package/dist/index.js.map +1 -1
- package/dist/{logger-BkGPbocD.d.ts → logger-BA-za85-.d.ts} +1 -1
- package/dist/{logger-S_t55o9n.cjs → logger-BXL0YCrv.cjs} +2 -2
- package/dist/{logger-S_t55o9n.cjs.map → logger-BXL0YCrv.cjs.map} +1 -1
- package/dist/{logger-CsQ2EGpR.js → logger-CDxSrFkR.js} +2 -2
- package/dist/{logger-CsQ2EGpR.js.map → logger-CDxSrFkR.js.map} +1 -1
- package/dist/logger.cjs +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/{markdown-CDf4HsAQ.js → markdown-ckUc3Q6q.js} +1 -1
- package/dist/{markdown-CDf4HsAQ.js.map → markdown-ckUc3Q6q.js.map} +1 -1
- package/dist/{markdown-HXmAlxeH.cjs → markdown-pzqiRmft.cjs} +1 -1
- package/dist/{markdown-HXmAlxeH.cjs.map → markdown-pzqiRmft.cjs.map} +1 -1
- package/dist/{meriyah-D8fyVkyI.js → meriyah-BjnGqpUs.js} +1 -1
- package/dist/{meriyah-D8fyVkyI.js.map → meriyah-BjnGqpUs.js.map} +1 -1
- package/dist/{meriyah-CWoiYjq_.cjs → meriyah-D_x7itbT.cjs} +1 -1
- package/dist/{meriyah-CWoiYjq_.cjs.map → meriyah-D_x7itbT.cjs.map} +1 -1
- package/dist/mocks.cjs +24 -24
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +3 -2
- package/dist/mocks.d.ts +4 -3
- package/dist/mocks.js +19 -20
- package/dist/mocks.js.map +1 -1
- package/dist/{postcss-bESf1Yzf.cjs → postcss-B_c2wbFu.cjs} +1 -1
- package/dist/{postcss-bESf1Yzf.cjs.map → postcss-B_c2wbFu.cjs.map} +1 -1
- package/dist/{postcss-Dqh1XvaI.js → postcss-v7BP6SZ-.js} +1 -1
- package/dist/{postcss-Dqh1XvaI.js.map → postcss-v7BP6SZ-.js.map} +1 -1
- package/dist/{prompt-C5GR2LPU.js → prompt-DBVnG4Me.js} +1 -1
- package/dist/{prompt-C5GR2LPU.js.map → prompt-DBVnG4Me.js.map} +1 -1
- package/dist/{prompt-ZBXNC-aV.cjs → prompt-DgONOpPH.cjs} +1 -1
- package/dist/{prompt-ZBXNC-aV.cjs.map → prompt-DgONOpPH.cjs.map} +1 -1
- package/dist/{transformers-BIx7CVmw.cjs → transformers-BH0KLJJP.cjs} +119 -228
- package/dist/transformers-BH0KLJJP.cjs.map +1 -0
- package/dist/{transformers-5BubQvcu.js → transformers-DzHGqYO2.js} +118 -215
- package/dist/transformers-DzHGqYO2.js.map +1 -0
- package/dist/transformers.cjs +4 -3
- package/dist/transformers.js +2 -1
- package/dist/types-BzI9JlV8.d.ts +5 -0
- package/dist/types-C3ea5qNG.d.cts +5 -0
- package/dist/{types-IOE1JAFC.d.cts → types-DNxlynJr.d.cts} +11 -70
- package/dist/{types-DtokChaW.d.ts → types-DPeNK0FO.d.ts} +12 -71
- package/dist/{typescript-BYxryL2A.cjs → typescript-6kMN6Wqz.cjs} +1 -1
- package/dist/{typescript-BYxryL2A.cjs.map → typescript-6kMN6Wqz.cjs.map} +1 -1
- package/dist/{typescript-B7n7vRma.js → typescript-B_IBfKSe.js} +1 -1
- package/dist/{typescript-B7n7vRma.js.map → typescript-B_IBfKSe.js.map} +1 -1
- package/dist/typescript-C5hce4HG.cjs +4 -0
- package/dist/typescript-Cas1XcNz.js +3 -0
- package/dist/utils.cjs +165 -20
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +136 -5
- package/dist/utils.d.ts +136 -5
- package/dist/utils.js +156 -5
- package/dist/utils.js.map +1 -0
- package/dist/{yaml-BMiF8MYP.js → yaml-BfWM_B73.js} +1 -1
- package/dist/{yaml-BMiF8MYP.js.map → yaml-BfWM_B73.js.map} +1 -1
- package/dist/{yaml-DQCs4b_O.cjs → yaml-DZs6MhV1.cjs} +1 -1
- package/dist/{yaml-DQCs4b_O.cjs.map → yaml-DZs6MhV1.cjs.map} +1 -1
- package/package.json +3 -3
- package/src/FileManager.ts +34 -302
- package/src/PluginManager.ts +9 -8
- package/src/__snapshots__/barrel.json +5 -5
- package/src/build.ts +19 -5
- package/src/index.ts +1 -2
- package/src/mocks/index.ts +4 -3
- package/src/plugin.ts +1 -1
- package/src/types.ts +4 -1
- package/src/utils/TreeNode.ts +3 -3
- package/src/utils/index.ts +2 -4
- package/dist/FileManager-DlkY9W5A.cjs +0 -1001
- package/dist/FileManager-DlkY9W5A.cjs.map +0 -1
- package/dist/FileManager-zlhCXf6A.js +0 -879
- package/dist/FileManager-zlhCXf6A.js.map +0 -1
- package/dist/index-CYcjcRdj.d.ts +0 -179
- package/dist/index-DaYv9bst.d.cts +0 -179
- package/dist/transformers-5BubQvcu.js.map +0 -1
- package/dist/transformers-BIx7CVmw.cjs.map +0 -1
- package/dist/typescript-CIdP4XPm.js +0 -3
- package/dist/typescript-CbuCkdxv.cjs +0 -4
- package/src/utils/parser.ts +0 -199
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"!/**/__tests__/**"
|
|
88
88
|
],
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@kubb/fabric-core": "
|
|
90
|
+
"@kubb/fabric-core": "0.0.0-canary-20251021185909",
|
|
91
91
|
"@kubb/parser-ts": "^4.1.4",
|
|
92
92
|
"camelcase": "^8.0.0",
|
|
93
93
|
"find-up": "^7.0.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"remeda": "^2.32.0",
|
|
101
101
|
"seedrandom": "^3.0.5",
|
|
102
102
|
"semver": "^7.7.3",
|
|
103
|
-
"@kubb/react": "4.2.
|
|
103
|
+
"@kubb/react": "4.2.1"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@types/fs-extra": "^11.0.4",
|
package/src/FileManager.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
import { extname, join
|
|
2
|
-
|
|
3
|
-
import { orderBy } from 'natural-orderby'
|
|
4
|
-
import pLimit from 'p-limit'
|
|
5
|
-
import { isDeepEqual, uniqueBy } from 'remeda'
|
|
6
|
-
|
|
1
|
+
import { extname, join } from 'node:path'
|
|
7
2
|
import { BarrelManager } from './BarrelManager.ts'
|
|
8
|
-
|
|
9
3
|
import type { KubbFile } from './fs/index.ts'
|
|
10
|
-
import { trimExtName
|
|
11
|
-
import type { ResolvedFile } from './fs/types.ts'
|
|
4
|
+
import { trimExtName } from './fs/index.ts'
|
|
12
5
|
import type { Logger } from './logger.ts'
|
|
13
|
-
import type { BarrelType,
|
|
14
|
-
import { createFile, getFileParser } from './utils'
|
|
15
|
-
import { Cache } from './utils/Cache.ts'
|
|
16
|
-
import type { GreaterThan } from './utils/types.ts'
|
|
6
|
+
import type { BarrelType, Plugin } from './types.ts'
|
|
17
7
|
|
|
18
8
|
export type FileMetaBase = {
|
|
19
9
|
pluginKey?: Plugin['key']
|
|
20
10
|
}
|
|
21
11
|
|
|
22
|
-
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>
|
|
23
|
-
|
|
24
12
|
type AddIndexesProps = {
|
|
25
13
|
type: BarrelType | false | undefined
|
|
26
14
|
/**
|
|
@@ -42,307 +30,51 @@ type AddIndexesProps = {
|
|
|
42
30
|
meta?: FileMetaBase
|
|
43
31
|
}
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
logger?: Logger
|
|
49
|
-
dryRun?: boolean
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class FileManager {
|
|
53
|
-
#cache = new Cache<KubbFile.ResolvedFile>()
|
|
54
|
-
#limit = pLimit(100)
|
|
55
|
-
|
|
56
|
-
constructor() {
|
|
57
|
-
return this
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T> {
|
|
61
|
-
const resolvedFiles: KubbFile.ResolvedFile[] = []
|
|
62
|
-
|
|
63
|
-
const mergedFiles = new Map<string, KubbFile.File>()
|
|
64
|
-
|
|
65
|
-
files.forEach((file) => {
|
|
66
|
-
const existing = mergedFiles.get(file.path)
|
|
67
|
-
if (existing) {
|
|
68
|
-
mergedFiles.set(file.path, mergeFile(existing, file))
|
|
69
|
-
} else {
|
|
70
|
-
mergedFiles.set(file.path, file)
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
for (const file of mergedFiles.values()) {
|
|
75
|
-
const existing = await this.#cache.get(file.path)
|
|
76
|
-
|
|
77
|
-
const merged = existing ? mergeFile(existing, file) : file
|
|
78
|
-
const resolvedFile = createFile(merged)
|
|
79
|
-
|
|
80
|
-
await this.#cache.set(resolvedFile.path, resolvedFile)
|
|
81
|
-
await this.#cache.flush()
|
|
82
|
-
|
|
83
|
-
resolvedFiles.push(resolvedFile)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (files.length > 1) {
|
|
87
|
-
return resolvedFiles as unknown as AddResult<T>
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return resolvedFiles[0] as unknown as AddResult<T>
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async getByPath(path: KubbFile.Path): Promise<KubbFile.ResolvedFile | null> {
|
|
94
|
-
return this.#cache.get(path)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async deleteByPath(path: KubbFile.Path): Promise<void> {
|
|
98
|
-
await this.#cache.delete(path)
|
|
33
|
+
export function getMode(path: string | undefined | null): KubbFile.Mode {
|
|
34
|
+
if (!path) {
|
|
35
|
+
return 'split'
|
|
99
36
|
}
|
|
37
|
+
return extname(path) ? 'single' : 'split'
|
|
38
|
+
}
|
|
100
39
|
|
|
101
|
-
|
|
102
|
-
|
|
40
|
+
export async function getBarrelFiles(
|
|
41
|
+
files: Array<KubbFile.ResolvedFile>,
|
|
42
|
+
{ type, meta = {}, root, output, logger }: AddIndexesProps,
|
|
43
|
+
): Promise<KubbFile.File[]> {
|
|
44
|
+
if (!type || type === 'propagate') {
|
|
45
|
+
return []
|
|
103
46
|
}
|
|
104
47
|
|
|
105
|
-
|
|
106
|
-
const cachedKeys = await this.#cache.keys()
|
|
48
|
+
const barrelManager = new BarrelManager({ logger })
|
|
107
49
|
|
|
108
|
-
|
|
109
|
-
const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])
|
|
50
|
+
const pathToBuildFrom = join(root, output.path)
|
|
110
51
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const file = await this.#cache.get(key)
|
|
114
|
-
return file as KubbFile.ResolvedFile
|
|
115
|
-
}),
|
|
116
|
-
)
|
|
52
|
+
if (trimExtName(pathToBuildFrom).endsWith('index')) {
|
|
53
|
+
logger?.emit('warning', 'Output has the same fileName as the barrelFiles, please disable barrel generation')
|
|
117
54
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return files.filter(Boolean)
|
|
55
|
+
return []
|
|
121
56
|
}
|
|
122
57
|
|
|
123
|
-
|
|
124
|
-
const files = await this.getFiles()
|
|
125
|
-
|
|
126
|
-
logger?.emit('progress_start', { id: 'files', size: files.length, message: 'Writing files ...' })
|
|
127
|
-
|
|
128
|
-
const promises = files.map((file) => {
|
|
129
|
-
return this.#limit(async () => {
|
|
130
|
-
const message = file ? `Writing ${relative(root, file.path)}` : ''
|
|
131
|
-
const extname = extension?.[file.extname] || undefined
|
|
58
|
+
const barrelFiles = barrelManager.getFiles({ files, root: pathToBuildFrom, meta })
|
|
132
59
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
await write(file.path, source, { sanity: false })
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
logger?.emit('progressed', { id: 'files', message })
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
await Promise.all(promises)
|
|
143
|
-
|
|
144
|
-
logger?.emit('progress_stop', { id: 'files' })
|
|
145
|
-
|
|
146
|
-
return files
|
|
147
|
-
}
|
|
148
|
-
async getBarrelFiles({ type, meta = {}, root, output, logger }: AddIndexesProps): Promise<KubbFile.File[]> {
|
|
149
|
-
if (!type || type === 'propagate') {
|
|
150
|
-
return []
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const barrelManager = new BarrelManager({ logger })
|
|
154
|
-
const files = await this.getFiles()
|
|
155
|
-
|
|
156
|
-
const pathToBuildFrom = join(root, output.path)
|
|
157
|
-
|
|
158
|
-
if (trimExtName(pathToBuildFrom).endsWith('index')) {
|
|
159
|
-
logger?.emit('warning', 'Output has the same fileName as the barrelFiles, please disable barrel generation')
|
|
160
|
-
|
|
161
|
-
return []
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const barrelFiles = barrelManager.getFiles({ files, root: pathToBuildFrom, meta })
|
|
165
|
-
|
|
166
|
-
if (type === 'all') {
|
|
167
|
-
return barrelFiles.map((file) => {
|
|
168
|
-
return {
|
|
169
|
-
...file,
|
|
170
|
-
exports: file.exports?.map((exportItem) => {
|
|
171
|
-
return {
|
|
172
|
-
...exportItem,
|
|
173
|
-
name: undefined,
|
|
174
|
-
}
|
|
175
|
-
}),
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return barrelFiles.map((indexFile) => {
|
|
60
|
+
if (type === 'all') {
|
|
61
|
+
return barrelFiles.map((file) => {
|
|
181
62
|
return {
|
|
182
|
-
...
|
|
183
|
-
|
|
63
|
+
...file,
|
|
64
|
+
exports: file.exports?.map((exportItem) => {
|
|
65
|
+
return {
|
|
66
|
+
...exportItem,
|
|
67
|
+
name: undefined,
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
184
70
|
}
|
|
185
71
|
})
|
|
186
72
|
}
|
|
187
73
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
74
|
+
return barrelFiles.map((indexFile) => {
|
|
75
|
+
return {
|
|
76
|
+
...indexFile,
|
|
77
|
+
meta,
|
|
192
78
|
}
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
type GetSourceOptions = {
|
|
198
|
-
extname?: KubbFile.Extname
|
|
199
|
-
logger?: Logger
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export async function getSource<TMeta extends FileMetaBase = FileMetaBase>(
|
|
203
|
-
file: ResolvedFile<TMeta>,
|
|
204
|
-
{ logger, extname }: GetSourceOptions = {},
|
|
205
|
-
): Promise<string> {
|
|
206
|
-
const parser = await getFileParser(file.extname)
|
|
207
|
-
|
|
208
|
-
return parser.print(file, { logger, extname })
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function mergeFile<TMeta extends FileMetaBase = FileMetaBase>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {
|
|
212
|
-
return {
|
|
213
|
-
...a,
|
|
214
|
-
sources: [...(a.sources || []), ...(b.sources || [])],
|
|
215
|
-
imports: [...(a.imports || []), ...(b.imports || [])],
|
|
216
|
-
exports: [...(a.exports || []), ...(b.exports || [])],
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {
|
|
221
|
-
return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {
|
|
225
|
-
return orderBy(exports, [
|
|
226
|
-
(v) => !!Array.isArray(v.name),
|
|
227
|
-
(v) => !v.isTypeOnly,
|
|
228
|
-
(v) => v.path,
|
|
229
|
-
(v) => !!v.name,
|
|
230
|
-
(v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),
|
|
231
|
-
]).reduce(
|
|
232
|
-
(prev, curr) => {
|
|
233
|
-
const name = curr.name
|
|
234
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path)
|
|
235
|
-
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)
|
|
236
|
-
|
|
237
|
-
if (prevByPathAndIsTypeOnly) {
|
|
238
|
-
// we already have an export that has the same path but uses `isTypeOnly` (export type ...)
|
|
239
|
-
return prev
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const uniquePrev = prev.findLast(
|
|
243
|
-
(imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,
|
|
244
|
-
)
|
|
245
|
-
|
|
246
|
-
// we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes
|
|
247
|
-
if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {
|
|
248
|
-
return prev
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (!prevByPath) {
|
|
252
|
-
return [
|
|
253
|
-
...prev,
|
|
254
|
-
{
|
|
255
|
-
...curr,
|
|
256
|
-
name: Array.isArray(name) ? [...new Set(name)] : name,
|
|
257
|
-
},
|
|
258
|
-
]
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// merge all names when prev and current both have the same isTypeOnly set
|
|
262
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
263
|
-
prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]
|
|
264
|
-
|
|
265
|
-
return prev
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return [...prev, curr]
|
|
269
|
-
},
|
|
270
|
-
[] as Array<KubbFile.Export>,
|
|
271
|
-
)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {
|
|
275
|
-
return orderBy(imports, [
|
|
276
|
-
(v) => !!Array.isArray(v.name),
|
|
277
|
-
(v) => !v.isTypeOnly,
|
|
278
|
-
(v) => v.path,
|
|
279
|
-
(v) => !!v.name,
|
|
280
|
-
(v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),
|
|
281
|
-
]).reduce(
|
|
282
|
-
(prev, curr) => {
|
|
283
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
284
|
-
|
|
285
|
-
const hasImportInSource = (importName: string) => {
|
|
286
|
-
if (!source) {
|
|
287
|
-
return true
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const checker = (name?: string) => {
|
|
291
|
-
return name && source.includes(name)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (curr.path === curr.root) {
|
|
298
|
-
// root and path are the same file, remove the "./" import
|
|
299
|
-
return prev
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// merge all names and check if the importName is being used in the generated source and if not filter those imports out
|
|
303
|
-
if (Array.isArray(name)) {
|
|
304
|
-
name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)
|
|
308
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)
|
|
309
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)
|
|
310
|
-
|
|
311
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
312
|
-
// we already have an export that has the same path but uses `isTypeOnly` (import type ...)
|
|
313
|
-
return prev
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// already unique enough or name is empty
|
|
317
|
-
if (uniquePrev || (Array.isArray(name) && !name.length)) {
|
|
318
|
-
return prev
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// new item, append name
|
|
322
|
-
if (!prevByPath) {
|
|
323
|
-
return [
|
|
324
|
-
...prev,
|
|
325
|
-
{
|
|
326
|
-
...curr,
|
|
327
|
-
name,
|
|
328
|
-
},
|
|
329
|
-
]
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// merge all names when prev and current both have the same isTypeOnly set
|
|
333
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
334
|
-
prevByPath.name = [...new Set([...prevByPath.name, ...name])]
|
|
335
|
-
|
|
336
|
-
return prev
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// no import was found in the source, ignore import
|
|
340
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
341
|
-
return prev
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return [...prev, curr]
|
|
345
|
-
},
|
|
346
|
-
[] as Array<KubbFile.Import>,
|
|
347
|
-
)
|
|
79
|
+
})
|
|
348
80
|
}
|
package/src/PluginManager.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { FileManager } from '
|
|
2
|
-
import { isPromiseRejectedResult } from './PromiseManager.ts'
|
|
3
|
-
import { PromiseManager } from './PromiseManager.ts'
|
|
1
|
+
import { FileManager } from '@kubb/fabric-core'
|
|
4
2
|
import { ValidationPluginError } from './errors.ts'
|
|
5
|
-
import { pluginCore } from './plugin.ts'
|
|
6
|
-
import { transformReservedWord } from './transformers/transformReservedWord.ts'
|
|
7
|
-
import { EventEmitter } from './utils/EventEmitter.ts'
|
|
8
|
-
import { setUniqueName } from './utils/uniqueName.ts'
|
|
9
|
-
|
|
10
3
|
import type { KubbFile } from './fs/index.ts'
|
|
11
4
|
import type { Logger } from './logger.ts'
|
|
5
|
+
import { isPromiseRejectedResult, PromiseManager } from './PromiseManager.ts'
|
|
12
6
|
import type { PluginCore } from './plugin.ts'
|
|
7
|
+
import { pluginCore } from './plugin.ts'
|
|
8
|
+
import { transformReservedWord } from './transformers/transformReservedWord.ts'
|
|
13
9
|
import { trim } from './transformers/trim.ts'
|
|
14
10
|
import type {
|
|
15
11
|
Config,
|
|
@@ -25,6 +21,8 @@ import type {
|
|
|
25
21
|
UserPlugin,
|
|
26
22
|
UserPluginWithLifeCycle,
|
|
27
23
|
} from './types.ts'
|
|
24
|
+
import { EventEmitter } from './utils/EventEmitter.ts'
|
|
25
|
+
import { setUniqueName } from './utils/uniqueName.ts'
|
|
28
26
|
|
|
29
27
|
type RequiredPluginLifecycle = Required<PluginLifecycle>
|
|
30
28
|
|
|
@@ -72,6 +70,9 @@ type GetFileProps<TOptions = object> = {
|
|
|
72
70
|
|
|
73
71
|
export class PluginManager {
|
|
74
72
|
readonly plugins = new Set<Plugin<GetPluginFactoryOptions<any>>>()
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated do not use from pluginManager
|
|
75
|
+
*/
|
|
75
76
|
readonly fileManager: FileManager
|
|
76
77
|
readonly events: EventEmitter<Events> = new EventEmitter()
|
|
77
78
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"isIndexable": true
|
|
11
11
|
}
|
|
12
12
|
],
|
|
13
|
-
"id": "
|
|
13
|
+
"id": "24be171099f802b26a7c97f02b0017ea44a6f9147e7fbe8c3ad6bc45283d4903",
|
|
14
14
|
"name": "test",
|
|
15
15
|
"extname": ".ts",
|
|
16
16
|
"imports": [],
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"isIndexable": false
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
|
-
"id": "
|
|
54
|
+
"id": "be25f3f85c5b85e95514080872ba0bca69acd8e1cec464b632945e79fed1d5b6",
|
|
55
55
|
"name": "index",
|
|
56
56
|
"extname": ".ts",
|
|
57
57
|
"imports": [],
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"isIndexable": true
|
|
69
69
|
}
|
|
70
70
|
],
|
|
71
|
-
"id": "
|
|
71
|
+
"id": "2605e7687b17f9a3fbc22bb108d789832b4d51be66f9250e1b08baffec006a71",
|
|
72
72
|
"name": "hello",
|
|
73
73
|
"extname": ".ts",
|
|
74
74
|
"imports": [],
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"isIndexable": true
|
|
87
87
|
}
|
|
88
88
|
],
|
|
89
|
-
"id": "
|
|
89
|
+
"id": "9522fa0378a8d8ecb5a5c54aac78b9a8644518860de49cf71ced4e6fe9c6e940",
|
|
90
90
|
"name": "world",
|
|
91
91
|
"extname": ".ts",
|
|
92
92
|
"imports": [],
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"path": "./sub/world.ts"
|
|
139
139
|
}
|
|
140
140
|
],
|
|
141
|
-
"id": "
|
|
141
|
+
"id": "216ca4d733d9d347d0ef4ec8865f8209e6ebab829cde4bbfef25e7a40e839b9f",
|
|
142
142
|
"name": "index",
|
|
143
143
|
"extname": ".ts",
|
|
144
144
|
"imports": [],
|
package/src/build.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, resolve } from 'node:path'
|
|
1
|
+
import { join, relative, resolve } from 'node:path'
|
|
2
2
|
import pc from 'picocolors'
|
|
3
3
|
import { isDeepEqual } from 'remeda'
|
|
4
4
|
import { isInputPath } from './config.ts'
|
|
@@ -91,6 +91,7 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
|
91
91
|
|
|
92
92
|
export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
93
93
|
const pluginManager = await setup(options)
|
|
94
|
+
|
|
94
95
|
const config = pluginManager.config
|
|
95
96
|
|
|
96
97
|
try {
|
|
@@ -117,7 +118,7 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
|
117
118
|
const rootPath = resolve(root, config.output.path, 'index.ts')
|
|
118
119
|
|
|
119
120
|
//TODO find clean method without loading all files
|
|
120
|
-
const files = await pluginManager.fileManager.
|
|
121
|
+
const files = await pluginManager.fileManager.files
|
|
121
122
|
|
|
122
123
|
const barrelFiles = files.filter((file) => {
|
|
123
124
|
return file.sources.some((source) => source.isIndexable)
|
|
@@ -163,11 +164,24 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
|
163
164
|
await pluginManager.fileManager.add(rootFile)
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
pluginManager.fileManager.processor.on('start', ({ files }) => {
|
|
168
|
+
pluginManager.logger.emit('progress_start', { id: 'files', size: files.length, message: 'Writing files ...' })
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
pluginManager.fileManager.processor.on('file:start', ({ file }) => {
|
|
172
|
+
const message = file ? `Writing ${relative(config.root, file.path)}` : ''
|
|
173
|
+
pluginManager.logger.emit('progressed', { id: 'files', message })
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
pluginManager.fileManager.processor.on('file:finish', () => {})
|
|
177
|
+
|
|
178
|
+
pluginManager.fileManager.processor.on('finish', () => {
|
|
179
|
+
pluginManager.logger.emit('progress_stop', { id: 'files' })
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const files = await pluginManager.fileManager.write({
|
|
168
183
|
extension: config.output.extension,
|
|
169
184
|
dryRun: !config.output.write,
|
|
170
|
-
logger: pluginManager.logger,
|
|
171
185
|
})
|
|
172
186
|
|
|
173
187
|
await pluginManager.hookParallel({ hookName: 'buildEnd', message: `Build stopped for ${config.name}` })
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,9 @@ export { BaseGenerator } from './BaseGenerator.ts'
|
|
|
2
2
|
export { build, build as default, safeBuild, setup } from './build.ts'
|
|
3
3
|
export { defineConfig, isInputPath } from './config.ts'
|
|
4
4
|
export type { FileMetaBase } from './FileManager.ts'
|
|
5
|
-
export {
|
|
5
|
+
export { getBarrelFiles, getMode } from './FileManager.ts'
|
|
6
6
|
export { PackageManager } from './PackageManager.ts'
|
|
7
7
|
export { PluginManager } from './PluginManager.ts'
|
|
8
8
|
export { PromiseManager } from './PromiseManager.ts'
|
|
9
9
|
export { createPlugin } from './plugin.ts'
|
|
10
10
|
export type * from './types.ts'
|
|
11
|
-
export { getDefaultBanner } from './utils'
|
package/src/mocks/index.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
+
import { createFile, FileProcessor } from '@kubb/fabric-core'
|
|
2
3
|
import { format } from '../../mocks/format.ts'
|
|
3
|
-
import { getSource } from '../FileManager'
|
|
4
4
|
import type { File, ResolvedFile } from '../fs/types.ts'
|
|
5
5
|
import type { Logger } from '../logger'
|
|
6
6
|
import type { PluginManager } from '../PluginManager.ts'
|
|
7
7
|
import { camelCase, pascalCase } from '../transformers/casing.ts'
|
|
8
8
|
import type { Plugin } from '../types.ts'
|
|
9
|
-
import { createFile } from '../utils'
|
|
10
9
|
|
|
11
10
|
export const mockedLogger = {
|
|
12
11
|
emit(_type, _message) {},
|
|
@@ -67,8 +66,10 @@ export async function matchFiles(files: Array<ResolvedFile | File> | undefined,
|
|
|
67
66
|
return undefined
|
|
68
67
|
}
|
|
69
68
|
|
|
69
|
+
const fileProcessor = new FileProcessor()
|
|
70
|
+
|
|
70
71
|
for await (const file of files) {
|
|
71
|
-
const source = await
|
|
72
|
+
const source = await fileProcessor.parse(createFile(file))
|
|
72
73
|
let code = source
|
|
73
74
|
if (!file.baseName.endsWith('.json')) {
|
|
74
75
|
code = await format(source)
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
|
-
import type { FileManager } from '
|
|
3
|
+
import type { FileManager } from '@kubb/fabric-core'
|
|
4
4
|
import type { PluginManager } from './PluginManager.ts'
|
|
5
5
|
import type { Plugin, PluginContext, PluginFactoryOptions, UserPluginWithLifeCycle } from './types.ts'
|
|
6
6
|
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FileManager } from '
|
|
1
|
+
import type { FileManager } from '@kubb/fabric-core'
|
|
2
2
|
import type { KubbFile } from './fs/index.ts'
|
|
3
3
|
import type { Logger } from './logger.ts'
|
|
4
4
|
import type { PluginManager } from './PluginManager.ts'
|
|
@@ -300,6 +300,9 @@ export type ResolveNameParams = {
|
|
|
300
300
|
|
|
301
301
|
export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
302
302
|
config: Config
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated
|
|
305
|
+
*/
|
|
303
306
|
fileManager: FileManager
|
|
304
307
|
pluginManager: PluginManager
|
|
305
308
|
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>
|
package/src/utils/TreeNode.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getMode } from '../FileManager.ts'
|
|
2
2
|
import type { KubbFile } from '../fs/index.ts'
|
|
3
3
|
|
|
4
4
|
type BarrelData = {
|
|
@@ -124,7 +124,7 @@ export class TreeNode {
|
|
|
124
124
|
name: filteredTree.name,
|
|
125
125
|
path: filteredTree.path,
|
|
126
126
|
file: filteredTree.file,
|
|
127
|
-
type:
|
|
127
|
+
type: getMode(filteredTree.path),
|
|
128
128
|
})
|
|
129
129
|
|
|
130
130
|
const recurse = (node: typeof treeNode, item: DirectoryTree) => {
|
|
@@ -132,7 +132,7 @@ export class TreeNode {
|
|
|
132
132
|
name: item.name,
|
|
133
133
|
path: item.path,
|
|
134
134
|
file: item.file,
|
|
135
|
-
type:
|
|
135
|
+
type: getMode(item.path),
|
|
136
136
|
})
|
|
137
137
|
|
|
138
138
|
if (item.children?.length) {
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { Cache } from './Cache.ts'
|
|
1
2
|
export type { FunctionParamsAST } from './FunctionParams.ts'
|
|
2
3
|
export { FunctionParams } from './FunctionParams.ts'
|
|
3
4
|
export {
|
|
@@ -7,9 +8,6 @@ export {
|
|
|
7
8
|
} from './promise.ts'
|
|
8
9
|
export { renderTemplate } from './renderTemplate.ts'
|
|
9
10
|
export { timeout } from './timeout.ts'
|
|
10
|
-
export { getUniqueName, setUniqueName } from './uniqueName.ts'
|
|
11
11
|
export type { URLObject } from './URLPath.ts'
|
|
12
12
|
export { URLPath } from './URLPath.ts'
|
|
13
|
-
export {
|
|
14
|
-
export type { ParserModule } from './parser.ts'
|
|
15
|
-
export { Cache } from './Cache.ts'
|
|
13
|
+
export { getUniqueName, setUniqueName } from './uniqueName.ts'
|