@kubb/core 5.0.0-beta.63 → 5.0.0-beta.64
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/{diagnostics-IjkPEgAO.d.ts → diagnostics-BqiNAWVS.d.ts} +9 -10
- package/dist/index.cjs +24 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +25 -35
- package/dist/index.js.map +1 -1
- package/dist/{memoryStorage-CWFzAz4o.js → memoryStorage-DWnhqUf2.js} +3 -3
- package/dist/{memoryStorage-CWFzAz4o.js.map → memoryStorage-DWnhqUf2.js.map} +1 -1
- package/dist/{memoryStorage-CUj1hrxa.cjs → memoryStorage-mojU6pbA.cjs} +2 -2
- package/dist/{memoryStorage-CUj1hrxa.cjs.map → memoryStorage-mojU6pbA.cjs.map} +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.js +2 -2
- package/package.json +4 -5
- package/src/FileManager.ts +0 -137
- package/src/FileProcessor.ts +0 -212
- package/src/KubbDriver.ts +0 -900
- package/src/Transform.ts +0 -105
- package/src/constants.ts +0 -126
- package/src/createAdapter.ts +0 -127
- package/src/createKubb.ts +0 -195
- package/src/createRenderer.ts +0 -72
- package/src/createReporter.ts +0 -134
- package/src/createStorage.ts +0 -83
- package/src/defineGenerator.ts +0 -211
- package/src/defineParser.ts +0 -63
- package/src/definePlugin.ts +0 -438
- package/src/defineResolver.ts +0 -711
- package/src/diagnostics.ts +0 -662
- package/src/index.ts +0 -20
- package/src/mocks.ts +0 -249
- package/src/reporters/cliReporter.ts +0 -89
- package/src/reporters/fileReporter.ts +0 -102
- package/src/reporters/jsonReporter.ts +0 -20
- package/src/reporters/report.ts +0 -85
- package/src/storages/fsStorage.ts +0 -82
- package/src/storages/memoryStorage.ts +0 -55
- package/src/types.ts +0 -829
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/FileProcessor.ts
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { AsyncEventEmitter } from '@internals/utils'
|
|
2
|
-
import type { CodeNode, FileNode } from '@kubb/ast'
|
|
3
|
-
import { extractStringsFromNodes } from '@kubb/ast/utils'
|
|
4
|
-
import { STREAM_FLUSH_EVERY } from './constants.ts'
|
|
5
|
-
import type { Storage } from './createStorage.ts'
|
|
6
|
-
import type { Parser } from './defineParser.ts'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Hooks fired by a `FileProcessor`.
|
|
10
|
-
*
|
|
11
|
-
* - `start` opens a batch, from `run` or a queue flush.
|
|
12
|
-
* - `update` fires once per file as it is converted.
|
|
13
|
-
* - `end` closes a batch.
|
|
14
|
-
* - `enqueue` fires for every `enqueue` call.
|
|
15
|
-
* - `drain` fires when `drain()` empties the queue with no in-flight batch left.
|
|
16
|
-
*/
|
|
17
|
-
export type FileProcessorHooks = {
|
|
18
|
-
start: [files: Array<FileNode>]
|
|
19
|
-
update: [params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }]
|
|
20
|
-
end: [files: Array<FileNode>]
|
|
21
|
-
enqueue: [file: FileNode]
|
|
22
|
-
drain: []
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Per-file progress record yielded by `stream` and surfaced through the `update` event.
|
|
27
|
-
*/
|
|
28
|
-
export type ParsedFile = {
|
|
29
|
-
file: FileNode
|
|
30
|
-
source: string
|
|
31
|
-
processed: number
|
|
32
|
-
total: number
|
|
33
|
-
percentage: number
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type FileProcessorOptions = {
|
|
37
|
-
/**
|
|
38
|
-
* Storage destination for queued writes.
|
|
39
|
-
*/
|
|
40
|
-
storage: Storage
|
|
41
|
-
/**
|
|
42
|
-
* Parsers indexed by file extension.
|
|
43
|
-
*/
|
|
44
|
-
parsers?: Map<FileNode['extname'], Parser>
|
|
45
|
-
/**
|
|
46
|
-
* Output extname per source extname, applied during conversion.
|
|
47
|
-
*/
|
|
48
|
-
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function joinSources(file: FileNode): string {
|
|
52
|
-
const sources = file.sources
|
|
53
|
-
if (sources.length === 0) return ''
|
|
54
|
-
const parts: Array<string> = []
|
|
55
|
-
for (const source of sources) {
|
|
56
|
-
const text = extractStringsFromNodes(source.nodes as Array<CodeNode>)
|
|
57
|
-
if (text) parts.push(text)
|
|
58
|
-
}
|
|
59
|
-
return parts.join('\n\n')
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Turns `FileNode`s into source strings and writes them to storage.
|
|
64
|
-
*
|
|
65
|
-
* Two modes share the same instance. Stateless mode (`parse`, `stream`, `run`) just runs the
|
|
66
|
-
* conversion. Queue mode (`enqueue`, `flush`, `drain`) buffers files deduped by path and
|
|
67
|
-
* writes each batch through storage with up to `STREAM_FLUSH_EVERY` requests in flight.
|
|
68
|
-
*
|
|
69
|
-
* `flush` does not wait for its batch to finish, so dispatch can overlap with IO. The next
|
|
70
|
-
* `flush` or `drain` picks the in-flight batch up. `drain` blocks until everything has been
|
|
71
|
-
* written and is meant for the end of a build.
|
|
72
|
-
*
|
|
73
|
-
* To surface build-level hook signals (`kubb:files:processing:*` and friends) subscribe to
|
|
74
|
-
* `hooks` and re-emit on the kubb bus.
|
|
75
|
-
*/
|
|
76
|
-
export class FileProcessor {
|
|
77
|
-
readonly hooks = new AsyncEventEmitter<FileProcessorHooks>()
|
|
78
|
-
readonly #parsers: Map<FileNode['extname'], Parser> | null
|
|
79
|
-
readonly #storage: Storage
|
|
80
|
-
readonly #extension: Record<FileNode['extname'], FileNode['extname'] | ''> | null
|
|
81
|
-
readonly #pending = new Map<string, FileNode>()
|
|
82
|
-
#runningFlush: Promise<void> | null = null
|
|
83
|
-
|
|
84
|
-
constructor(options: FileProcessorOptions) {
|
|
85
|
-
this.#parsers = options.parsers ?? null
|
|
86
|
-
this.#storage = options.storage
|
|
87
|
-
this.#extension = options.extension ?? null
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Files waiting in the queue.
|
|
92
|
-
*/
|
|
93
|
-
get size(): number {
|
|
94
|
-
return this.#pending.size
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
parse(file: FileNode): string {
|
|
98
|
-
const parsers = this.#parsers
|
|
99
|
-
const parseExtName = this.#extension?.[file.extname] || undefined
|
|
100
|
-
|
|
101
|
-
if (!parsers || !file.extname) {
|
|
102
|
-
return joinSources(file)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const parser = parsers.get(file.extname)
|
|
106
|
-
|
|
107
|
-
if (!parser) {
|
|
108
|
-
return joinSources(file)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return parser.parse(file, { extname: parseExtName })
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
*stream(files: ReadonlyArray<FileNode>): Generator<ParsedFile> {
|
|
115
|
-
const total = files.length
|
|
116
|
-
if (total === 0) return
|
|
117
|
-
|
|
118
|
-
let processed = 0
|
|
119
|
-
for (const file of files) {
|
|
120
|
-
const source = this.parse(file)
|
|
121
|
-
processed++
|
|
122
|
-
|
|
123
|
-
yield { file, source, processed, total, percentage: (processed / total) * 100 }
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async run(files: Array<FileNode>): Promise<Array<FileNode>> {
|
|
128
|
-
await this.hooks.emit('start', files)
|
|
129
|
-
|
|
130
|
-
for (const { file, source, processed, total, percentage } of this.stream(files)) {
|
|
131
|
-
await this.hooks.emit('update', { file, source, processed, percentage, total })
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
await this.hooks.emit('end', files)
|
|
135
|
-
|
|
136
|
-
return files
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Adds a file to the next flush. A later `enqueue` for the same path replaces the previous
|
|
141
|
-
* entry, matching `FileManager.upsert`. Fires the `enqueue` event.
|
|
142
|
-
*/
|
|
143
|
-
enqueue(file: FileNode): void {
|
|
144
|
-
this.#pending.set(file.path, file)
|
|
145
|
-
this.hooks.emit('enqueue', file)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Starts processing the queued files. Waits for any previous flush to finish (so two
|
|
150
|
-
* batches never run together) and then returns without waiting for the new one. The next
|
|
151
|
-
* `flush` or `drain` picks up the in-flight task.
|
|
152
|
-
*/
|
|
153
|
-
async flush(): Promise<void> {
|
|
154
|
-
if (this.#runningFlush) await this.#runningFlush
|
|
155
|
-
if (this.#pending.size === 0) return
|
|
156
|
-
|
|
157
|
-
const batch = [...this.#pending.values()]
|
|
158
|
-
this.#pending.clear()
|
|
159
|
-
|
|
160
|
-
this.#runningFlush = this.#processAndWrite(batch).finally(() => {
|
|
161
|
-
this.#runningFlush = null
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Waits for the in-flight flush and writes any files still queued. Fires the `drain` event
|
|
167
|
-
* when both are done.
|
|
168
|
-
*/
|
|
169
|
-
async drain(): Promise<void> {
|
|
170
|
-
if (this.#runningFlush) await this.#runningFlush
|
|
171
|
-
|
|
172
|
-
if (this.#pending.size > 0) {
|
|
173
|
-
const batch = [...this.#pending.values()]
|
|
174
|
-
this.#pending.clear()
|
|
175
|
-
await this.#processAndWrite(batch)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
await this.hooks.emit('drain')
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async #processAndWrite(files: Array<FileNode>): Promise<void> {
|
|
182
|
-
const storage = this.#storage
|
|
183
|
-
|
|
184
|
-
await this.hooks.emit('start', files)
|
|
185
|
-
|
|
186
|
-
// Single pass: each file's write starts right after its `update` fires, so IO overlaps
|
|
187
|
-
// parsing and the batch never holds every rendered source in memory at once.
|
|
188
|
-
const queue: Array<Promise<void>> = []
|
|
189
|
-
for (const item of this.stream(files)) {
|
|
190
|
-
await this.hooks.emit('update', item)
|
|
191
|
-
if (item.source) {
|
|
192
|
-
queue.push(storage.setItem(item.file.path, item.source))
|
|
193
|
-
if (queue.length >= STREAM_FLUSH_EVERY) await Promise.all(queue.splice(0))
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
await Promise.all(queue)
|
|
197
|
-
|
|
198
|
-
await this.hooks.emit('end', files)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Clears every listener and the pending queue.
|
|
203
|
-
*/
|
|
204
|
-
dispose(): void {
|
|
205
|
-
this.hooks.removeAll()
|
|
206
|
-
this.#pending.clear()
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
[Symbol.dispose](): void {
|
|
210
|
-
this.dispose()
|
|
211
|
-
}
|
|
212
|
-
}
|