@kubb/core 3.15.1 → 3.16.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/{FileManager-HxsypMy8.d.cts → PluginManager-E3SghPP9.d.cts} +125 -161
- package/dist/{FileManager-Cm7Iylcx.d.ts → PluginManager-PDmRCu9k.d.ts} +125 -161
- package/dist/{chunk-7P6FFVGF.js → chunk-4V7HK7PT.js} +3 -3
- package/dist/{chunk-7P6FFVGF.js.map → chunk-4V7HK7PT.js.map} +1 -1
- package/dist/{chunk-TEEWO6UV.cjs → chunk-BHSTNFNQ.cjs} +2 -23
- package/dist/chunk-BHSTNFNQ.cjs.map +1 -0
- package/dist/{chunk-XTSQKCYI.js → chunk-CAZ37TGB.js} +93 -114
- package/dist/chunk-CAZ37TGB.js.map +1 -0
- package/dist/{chunk-MKN7YSK2.cjs → chunk-E4XLCCPK.cjs} +2 -20
- package/dist/chunk-E4XLCCPK.cjs.map +1 -0
- package/dist/{chunk-TJJOSCFA.cjs → chunk-MCNA6SYG.cjs} +5 -24
- package/dist/chunk-MCNA6SYG.cjs.map +1 -0
- package/dist/chunk-QR7CQIA3.cjs +943 -0
- package/dist/chunk-QR7CQIA3.cjs.map +1 -0
- package/dist/{chunk-CMKZBNCX.js → chunk-YRPOID7E.js} +2 -2
- package/dist/{chunk-CMKZBNCX.js.map → chunk-YRPOID7E.js.map} +1 -1
- package/dist/fs.cjs +9 -10
- package/dist/fs.d.cts +10 -2
- package/dist/fs.d.ts +10 -2
- package/dist/fs.js +1 -1
- package/dist/index.cjs +109 -260
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +88 -83
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +6 -7
- package/dist/logger.js +2 -2
- package/dist/mocks.cjs +8 -11
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +2 -2
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.js +2 -2
- package/dist/{parser-CcELSk43.d.ts → parser-C1vOjVEd.d.ts} +2 -2
- package/dist/{parser-Dwb7eMU3.d.cts → parser-D6vU1kA9.d.cts} +2 -2
- package/dist/{prompt-55FJQYBV.cjs → prompt-U7M5G25C.cjs} +2 -4
- package/dist/prompt-U7M5G25C.cjs.map +1 -0
- package/dist/transformers.cjs +21 -22
- package/dist/{types-CX9JVw2n.d.cts → types-CA8nQKwM.d.cts} +1 -15
- package/dist/{types-CX9JVw2n.d.ts → types-CA8nQKwM.d.ts} +1 -15
- package/dist/utils.cjs +22 -19
- package/dist/utils.d.cts +15 -4
- package/dist/utils.d.ts +15 -4
- package/dist/utils.js +2 -2
- package/package.json +6 -6
- package/src/BarrelManager.ts +1 -20
- package/src/FileManager.ts +78 -121
- package/src/PluginManager.ts +40 -33
- package/src/PromiseManager.ts +2 -1
- package/src/__snapshots__/barrel.json +80 -6
- package/src/build.ts +57 -55
- package/src/fs/types.ts +0 -6
- package/src/index.ts +1 -1
- package/src/utils/Cache.ts +31 -0
- package/src/utils/executeStrategies.ts +9 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/parser.ts +6 -7
- package/dist/chunk-FAQ7SBKL.cjs +0 -1636
- package/dist/chunk-FAQ7SBKL.cjs.map +0 -1
- package/dist/chunk-KZOJCFA7.cjs +0 -42
- package/dist/chunk-KZOJCFA7.cjs.map +0 -1
- package/dist/chunk-MKN7YSK2.cjs.map +0 -1
- package/dist/chunk-TEEWO6UV.cjs.map +0 -1
- package/dist/chunk-TJJOSCFA.cjs.map +0 -1
- package/dist/chunk-XTSQKCYI.js.map +0 -1
- package/dist/prompt-55FJQYBV.cjs.map +0 -1
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"path": "src/test.ts",
|
|
4
|
+
"baseName": "test.ts",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"name": "test",
|
|
8
|
+
"value": "export const test = 2;",
|
|
9
|
+
"isExportable": true,
|
|
10
|
+
"isIndexable": true
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"id": "f8e2d98f76d6e33f21aa686d674544b5c7d6fa3e",
|
|
14
|
+
"name": "test",
|
|
15
|
+
"extname": ".ts",
|
|
16
|
+
"imports": [],
|
|
17
|
+
"exports": [],
|
|
18
|
+
"meta": {}
|
|
19
|
+
},
|
|
2
20
|
{
|
|
3
21
|
"path": "src/index.ts",
|
|
4
22
|
"baseName": "index.ts",
|
|
@@ -40,17 +58,53 @@
|
|
|
40
58
|
"meta": {}
|
|
41
59
|
},
|
|
42
60
|
{
|
|
43
|
-
"path": "src/sub/
|
|
44
|
-
"baseName": "
|
|
45
|
-
"
|
|
61
|
+
"path": "src/sub/hello.ts",
|
|
62
|
+
"baseName": "hello.ts",
|
|
63
|
+
"sources": [
|
|
46
64
|
{
|
|
47
|
-
"
|
|
48
|
-
|
|
65
|
+
"name": "hello",
|
|
66
|
+
"value": "export const hello = 2;",
|
|
67
|
+
"isExportable": true,
|
|
68
|
+
"isIndexable": true
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"id": "4b588b3e31d5ea58e60ceedfcf54b9292fbf6986",
|
|
72
|
+
"name": "hello",
|
|
73
|
+
"extname": ".ts",
|
|
74
|
+
"imports": [],
|
|
75
|
+
"exports": [],
|
|
76
|
+
"meta": {}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"path": "src/sub/world.ts",
|
|
80
|
+
"baseName": "world.ts",
|
|
81
|
+
"sources": [
|
|
49
82
|
{
|
|
50
|
-
"
|
|
83
|
+
"name": "world",
|
|
84
|
+
"value": "export const world = 2;",
|
|
85
|
+
"isExportable": true,
|
|
86
|
+
"isIndexable": true
|
|
51
87
|
}
|
|
52
88
|
],
|
|
89
|
+
"id": "53fb0d18b280dd7edc4a2bc5bbf71ea203680f70",
|
|
90
|
+
"name": "world",
|
|
91
|
+
"extname": ".ts",
|
|
92
|
+
"imports": [],
|
|
93
|
+
"exports": [],
|
|
94
|
+
"meta": {}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"path": "src/sub/index.ts",
|
|
98
|
+
"baseName": "index.ts",
|
|
53
99
|
"sources": [
|
|
100
|
+
{
|
|
101
|
+
"name": "hello",
|
|
102
|
+
"value": ""
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "world",
|
|
106
|
+
"value": ""
|
|
107
|
+
},
|
|
54
108
|
{
|
|
55
109
|
"name": "hello",
|
|
56
110
|
"value": "",
|
|
@@ -64,6 +118,26 @@
|
|
|
64
118
|
"isIndexable": false
|
|
65
119
|
}
|
|
66
120
|
],
|
|
121
|
+
"exports": [
|
|
122
|
+
{
|
|
123
|
+
"path": "./hello.ts"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": "./world.ts"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": [
|
|
130
|
+
"hello"
|
|
131
|
+
],
|
|
132
|
+
"path": "./sub/hello.ts"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": [
|
|
136
|
+
"world"
|
|
137
|
+
],
|
|
138
|
+
"path": "./sub/world.ts"
|
|
139
|
+
}
|
|
140
|
+
],
|
|
67
141
|
"id": "c67967bd2363dd9637437671f6fe1ed146debdbf",
|
|
68
142
|
"name": "index",
|
|
69
143
|
"extname": ".ts",
|
package/src/build.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { clean, exists } from './fs/index.ts'
|
|
1
|
+
import { clean, exists, getRelativePath } from './fs/index.ts'
|
|
2
2
|
import type { KubbFile } from './fs/index.ts'
|
|
3
|
-
import { type FileManager, processFiles } from './FileManager.ts'
|
|
4
3
|
import { PluginManager } from './PluginManager.ts'
|
|
5
4
|
import { isInputPath } from './config.ts'
|
|
6
5
|
import { createLogger } from './logger.ts'
|
|
7
6
|
import { URLPath } from './utils/URLPath.ts'
|
|
8
7
|
|
|
9
8
|
import { join, resolve } from 'node:path'
|
|
10
|
-
import { getRelativePath } from './fs/index.ts'
|
|
11
9
|
import type { Logger } from './logger.ts'
|
|
12
10
|
import type { Config, Output, UserConfig } from './types.ts'
|
|
13
11
|
import consola from 'consola'
|
|
14
12
|
import { colors } from 'consola/utils'
|
|
13
|
+
import { isDeepEqual } from 'remeda'
|
|
15
14
|
|
|
16
15
|
type BuildOptions = {
|
|
17
16
|
config: UserConfig
|
|
@@ -23,7 +22,7 @@ type BuildOptions = {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
type BuildOutput = {
|
|
26
|
-
files:
|
|
25
|
+
files: Array<KubbFile.ResolvedFile>
|
|
27
26
|
pluginManager: PluginManager
|
|
28
27
|
/**
|
|
29
28
|
* Only for safeBuild
|
|
@@ -77,7 +76,7 @@ export async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
77
76
|
await clean(join(definedConfig.root, '.kubb'))
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
return new PluginManager(definedConfig, { logger })
|
|
79
|
+
return new PluginManager(definedConfig, { logger, concurrency: 5 })
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
@@ -93,7 +92,6 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
96
|
-
let files = []
|
|
97
95
|
const pluginManager = await setup(options)
|
|
98
96
|
const config = pluginManager.config
|
|
99
97
|
|
|
@@ -115,64 +113,73 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
|
115
113
|
message: 'buildStart',
|
|
116
114
|
})
|
|
117
115
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
if (config.output.barrelType) {
|
|
117
|
+
// create root barrel file
|
|
118
|
+
const root = resolve(config.root)
|
|
119
|
+
const rootPath = resolve(root, config.output.path, 'index.ts')
|
|
120
|
+
|
|
121
|
+
//TODO find clean method without loading all files
|
|
122
|
+
const files = await pluginManager.fileManager.getFiles()
|
|
123
|
+
|
|
124
|
+
const barrelFiles = files.filter((file) => {
|
|
125
|
+
return file.sources.some((source) => source.isIndexable)
|
|
126
|
+
})
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
128
|
+
const rootFile: KubbFile.File = {
|
|
129
|
+
path: rootPath,
|
|
130
|
+
baseName: 'index.ts',
|
|
131
|
+
exports: barrelFiles
|
|
132
|
+
.flatMap((file) => {
|
|
133
|
+
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly)
|
|
134
|
+
|
|
135
|
+
return file.sources
|
|
136
|
+
?.map((source) => {
|
|
137
|
+
if (!file.path || !source.isIndexable) {
|
|
138
|
+
return undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// validate of the file is coming from plugin x, needs pluginKey on every file TODO update typing
|
|
142
|
+
const plugin = [...pluginManager.plugins].find((item) => {
|
|
143
|
+
const meta = file.meta as any
|
|
144
|
+
return isDeepEqual(item.key, meta?.pluginKey)
|
|
145
|
+
})
|
|
146
|
+
const pluginOptions = plugin?.options as { output?: Output<any> }
|
|
147
|
+
|
|
148
|
+
if (!pluginOptions || pluginOptions?.output?.barrelType === false) {
|
|
149
|
+
return undefined
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
name: config.output.barrelType === 'all' ? undefined : [source.name],
|
|
154
|
+
path: getRelativePath(rootPath, file.path),
|
|
155
|
+
isTypeOnly: config.output.barrelType === 'all' ? containsOnlyTypes : source.isTypeOnly,
|
|
156
|
+
} as KubbFile.Export
|
|
141
157
|
})
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
name: config.output.barrelType === 'all' ? undefined : [source.name],
|
|
150
|
-
path: getRelativePath(rootPath, file.path),
|
|
151
|
-
isTypeOnly: config.output.barrelType === 'all' ? containsOnlyTypes : source.isTypeOnly,
|
|
152
|
-
} as KubbFile.Export
|
|
153
|
-
})
|
|
154
|
-
.filter(Boolean)
|
|
155
|
-
})
|
|
156
|
-
.filter(Boolean),
|
|
157
|
-
sources: [],
|
|
158
|
-
meta: {},
|
|
159
|
-
}
|
|
158
|
+
.filter(Boolean)
|
|
159
|
+
})
|
|
160
|
+
.filter(Boolean),
|
|
161
|
+
sources: [],
|
|
162
|
+
meta: {},
|
|
163
|
+
}
|
|
160
164
|
|
|
161
|
-
if (config.output.barrelType) {
|
|
162
165
|
await pluginManager.fileManager.add(rootFile)
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
files = await processFiles({
|
|
168
|
+
const files = await pluginManager.fileManager.processFiles({
|
|
166
169
|
root: config.root,
|
|
167
170
|
extension: config.output.extension,
|
|
168
171
|
dryRun: !config.output.write,
|
|
169
|
-
files: pluginManager.fileManager.files,
|
|
170
172
|
logger: pluginManager.logger,
|
|
171
173
|
})
|
|
172
174
|
|
|
173
175
|
await pluginManager.hookParallel({ hookName: 'buildEnd', message: `Build stopped for ${config.name}` })
|
|
174
176
|
|
|
175
|
-
pluginManager.fileManager.clear()
|
|
177
|
+
await pluginManager.fileManager.clear()
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
files,
|
|
181
|
+
pluginManager,
|
|
182
|
+
}
|
|
176
183
|
} catch (e) {
|
|
177
184
|
return {
|
|
178
185
|
files: [],
|
|
@@ -180,9 +187,4 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
|
180
187
|
error: e as Error,
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
files,
|
|
186
|
-
pluginManager,
|
|
187
|
-
}
|
|
188
190
|
}
|
package/src/fs/types.ts
CHANGED
|
@@ -104,12 +104,6 @@ export type File<TMeta extends object = object> = {
|
|
|
104
104
|
sources: Array<Source>
|
|
105
105
|
imports?: Array<Import>
|
|
106
106
|
exports?: Array<Export>
|
|
107
|
-
/**
|
|
108
|
-
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
109
|
-
* This will also ignore the combinefiles utils
|
|
110
|
-
* @default `false`
|
|
111
|
-
*/
|
|
112
|
-
override?: boolean
|
|
113
107
|
/**
|
|
114
108
|
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
115
109
|
*/
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { setup, build, build as default, safeBuild } from './build.ts'
|
|
2
2
|
export { defineConfig, isInputPath } from './config.ts'
|
|
3
|
-
export { FileManager, getSource
|
|
3
|
+
export { FileManager, getSource } from './FileManager.ts'
|
|
4
4
|
export type { FileMetaBase } from './FileManager.ts'
|
|
5
5
|
export { BaseGenerator } from './BaseGenerator.ts'
|
|
6
6
|
export { PackageManager } from './PackageManager.ts'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class Cache<T> {
|
|
2
|
+
#buffer = new Map<string, T>()
|
|
3
|
+
|
|
4
|
+
async get(key: string): Promise<T | null> {
|
|
5
|
+
return this.#buffer.get(key) ?? null
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async set(key: string, value: T): Promise<void> {
|
|
9
|
+
this.#buffer.set(key, value)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async delete(key: string): Promise<void> {
|
|
13
|
+
this.#buffer.delete(key)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async clear(): Promise<void> {
|
|
17
|
+
this.#buffer.clear()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async keys(): Promise<string[]> {
|
|
21
|
+
return [...this.#buffer.keys()]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async values(): Promise<T[]> {
|
|
25
|
+
return [...this.#buffer.values()]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async flush(): Promise<void> {
|
|
29
|
+
// No-op for base cache
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import pLimit from 'p-limit'
|
|
2
|
+
|
|
1
3
|
type PromiseFunc<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2
|
|
2
4
|
|
|
3
5
|
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc<infer X, infer Y>> ? X | Y : never
|
|
@@ -53,12 +55,17 @@ export function hookFirst<TInput extends Array<PromiseFunc<TValue, null>>, TValu
|
|
|
53
55
|
type HookParallelOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
|
-
*
|
|
58
|
+
* Runs an array of promise functions with optional concurrency limit.
|
|
57
59
|
*/
|
|
58
60
|
export function hookParallel<TInput extends Array<PromiseFunc<TValue, null>>, TValue = unknown, TOutput = HookParallelOutput<TInput, TValue>>(
|
|
59
61
|
promises: TInput,
|
|
62
|
+
concurrency: number = Number.POSITIVE_INFINITY,
|
|
60
63
|
): TOutput {
|
|
61
|
-
|
|
64
|
+
const limit = pLimit(concurrency)
|
|
65
|
+
|
|
66
|
+
const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()))
|
|
67
|
+
|
|
68
|
+
return Promise.allSettled(tasks) as TOutput
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
export type Strategy = 'seq' | 'first' | 'parallel'
|
package/src/utils/index.ts
CHANGED
|
@@ -12,3 +12,4 @@ export type { URLObject } from './URLPath.ts'
|
|
|
12
12
|
export { URLPath } from './URLPath.ts'
|
|
13
13
|
export { getFileParser, createFileImport, createFileExport, createFile, createFileParser, getDefaultBanner } from './parser.ts'
|
|
14
14
|
export type { ParserModule } from './parser.ts'
|
|
15
|
+
export { Cache } from './Cache.ts'
|
package/src/utils/parser.ts
CHANGED
|
@@ -57,24 +57,23 @@ export function getDefaultBanner({ title, description, version, config }: { titl
|
|
|
57
57
|
*/
|
|
58
58
|
export function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {
|
|
59
59
|
const extname = path.extname(file.baseName) as KubbFile.Extname
|
|
60
|
-
|
|
61
60
|
if (!extname) {
|
|
62
61
|
throw new Error(`No extname found for ${file.baseName}`)
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
const source = file.sources.map((item) => item.value).join('\n\n')
|
|
66
|
-
const exports = file.exports ? combineExports(file.exports) : []
|
|
67
|
-
const imports = file.imports && source ? combineImports(file.imports, exports, source) : []
|
|
68
|
-
const sources = file.sources ? combineSources(file.sources) : []
|
|
65
|
+
const exports = file.exports?.length ? combineExports(file.exports) : []
|
|
66
|
+
const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []
|
|
67
|
+
const sources = file.sources?.length ? combineSources(file.sources) : []
|
|
69
68
|
|
|
70
69
|
return {
|
|
71
70
|
...file,
|
|
72
71
|
id: hash({ path: file.path }),
|
|
73
72
|
name: trimExtName(file.baseName),
|
|
74
73
|
extname,
|
|
75
|
-
imports: imports.map(
|
|
76
|
-
exports: exports.map(
|
|
77
|
-
sources: sources.map(
|
|
74
|
+
imports: imports.map(createFileImport),
|
|
75
|
+
exports: exports.map(createFileExport),
|
|
76
|
+
sources: sources.map(createFileSource),
|
|
78
77
|
meta: file.meta || ({} as TMeta),
|
|
79
78
|
}
|
|
80
79
|
}
|