@kubb/core 5.0.0-beta.1 → 5.0.0-beta.100

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.
Files changed (49) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +25 -158
  3. package/dist/index.cjs +2262 -1130
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +107 -295
  6. package/dist/index.js +2253 -1122
  7. package/dist/index.js.map +1 -1
  8. package/dist/mocks.cjs +81 -32
  9. package/dist/mocks.cjs.map +1 -1
  10. package/dist/mocks.d.ts +37 -14
  11. package/dist/mocks.js +83 -36
  12. package/dist/mocks.js.map +1 -1
  13. package/dist/types-DM7-MGjZ.d.ts +2838 -0
  14. package/dist/usingCtx-BNggxUEL.js +597 -0
  15. package/dist/usingCtx-BNggxUEL.js.map +1 -0
  16. package/dist/usingCtx-CZyLSqds.cjs +705 -0
  17. package/dist/usingCtx-CZyLSqds.cjs.map +1 -0
  18. package/package.json +7 -35
  19. package/dist/PluginDriver-BXibeQk-.cjs +0 -1036
  20. package/dist/PluginDriver-BXibeQk-.cjs.map +0 -1
  21. package/dist/PluginDriver-DV3p2Hky.js +0 -945
  22. package/dist/PluginDriver-DV3p2Hky.js.map +0 -1
  23. package/dist/types-CuNocrbJ.d.ts +0 -2148
  24. package/src/FileManager.ts +0 -115
  25. package/src/FileProcessor.ts +0 -86
  26. package/src/Kubb.ts +0 -300
  27. package/src/PluginDriver.ts +0 -424
  28. package/src/constants.ts +0 -35
  29. package/src/createAdapter.ts +0 -32
  30. package/src/createKubb.ts +0 -548
  31. package/src/createRenderer.ts +0 -57
  32. package/src/createStorage.ts +0 -70
  33. package/src/defineGenerator.ts +0 -87
  34. package/src/defineLogger.ts +0 -19
  35. package/src/defineMiddleware.ts +0 -62
  36. package/src/defineParser.ts +0 -44
  37. package/src/definePlugin.ts +0 -83
  38. package/src/defineResolver.ts +0 -521
  39. package/src/devtools.ts +0 -59
  40. package/src/index.ts +0 -20
  41. package/src/mocks.ts +0 -178
  42. package/src/renderNode.ts +0 -35
  43. package/src/storages/fsStorage.ts +0 -114
  44. package/src/storages/memoryStorage.ts +0 -55
  45. package/src/types.ts +0 -1296
  46. package/src/utils/diagnostics.ts +0 -18
  47. package/src/utils/isInputPath.ts +0 -10
  48. package/src/utils/packageJSON.ts +0 -99
  49. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
@@ -0,0 +1,705 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", {
5
+ value,
6
+ configurable: true
7
+ });
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+ //#endregion
27
+ let node_fs_promises = require("node:fs/promises");
28
+ let node_path = require("node:path");
29
+ let _kubb_ast = require("@kubb/ast");
30
+ let node_events = require("node:events");
31
+ //#region ../../internals/utils/src/casing.ts
32
+ /**
33
+ * Shared implementation for camelCase and PascalCase conversion.
34
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
35
+ * and capitalizes each word according to `pascal`.
36
+ *
37
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
38
+ */
39
+ function toCamelOrPascal(text, pascal) {
40
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
41
+ if (word.length > 1 && word === word.toUpperCase()) return word;
42
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
43
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
44
+ }
45
+ /**
46
+ * Converts `text` to camelCase.
47
+ *
48
+ * @example Word boundaries
49
+ * `camelCase('hello-world') // 'helloWorld'`
50
+ *
51
+ * @example With a prefix
52
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
53
+ */
54
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
55
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
56
+ }
57
+ //#endregion
58
+ //#region ../../internals/utils/src/errors.ts
59
+ /**
60
+ * Thrown when one or more errors occur during a Kubb build.
61
+ * Carries the full list of underlying errors on `errors`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * throw new BuildError('Build failed', { errors: [err1, err2] })
66
+ * ```
67
+ */
68
+ var BuildError = class extends Error {
69
+ errors;
70
+ constructor(message, options) {
71
+ super(message, { cause: options.cause });
72
+ this.name = "BuildError";
73
+ this.errors = options.errors;
74
+ }
75
+ };
76
+ /**
77
+ * Coerces an unknown thrown value to an `Error` instance.
78
+ * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * try { ... } catch(err) {
83
+ * throw new BuildError('Build failed', { cause: toError(err), errors: [] })
84
+ * }
85
+ * ```
86
+ */
87
+ function toError(value) {
88
+ return value instanceof Error ? value : new Error(String(value));
89
+ }
90
+ /**
91
+ * Extracts a human-readable message from any thrown value.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * getErrorMessage(new Error('oops')) // 'oops'
96
+ * getErrorMessage('plain string') // 'plain string'
97
+ * ```
98
+ */
99
+ function getErrorMessage(value) {
100
+ return value instanceof Error ? value.message : String(value);
101
+ }
102
+ //#endregion
103
+ //#region ../../internals/utils/src/runtime.ts
104
+ /**
105
+ * Detects the JavaScript runtime executing the current process and exposes its name and version.
106
+ *
107
+ * Prefer the shared {@link runtime} instance over constructing your own.
108
+ */
109
+ var Runtime = class {
110
+ /**
111
+ * `true` when the current process is running under Bun.
112
+ *
113
+ * Detection keys off the global `Bun` object rather than `process.versions`,
114
+ * because Bun polyfills `process.versions.node` for Node compatibility and would
115
+ * otherwise look like Node.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * if (runtime.isBun) {
120
+ * await Bun.write(path, data)
121
+ * }
122
+ * ```
123
+ */
124
+ get isBun() {
125
+ return typeof Bun !== "undefined";
126
+ }
127
+ /**
128
+ * `true` when the current process is running under Deno.
129
+ */
130
+ get isDeno() {
131
+ return typeof globalThis.Deno !== "undefined";
132
+ }
133
+ /**
134
+ * `true` when the current process is running under Node.
135
+ *
136
+ * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.
137
+ */
138
+ get isNode() {
139
+ return !this.isBun && !this.isDeno && typeof process !== "undefined" && process.versions?.node != null;
140
+ }
141
+ /**
142
+ * Name of the runtime executing the current process.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
147
+ * ```
148
+ */
149
+ get name() {
150
+ if (this.isBun) return "bun";
151
+ if (this.isDeno) return "deno";
152
+ return "node";
153
+ }
154
+ /**
155
+ * Version of the active runtime, or an empty string when it cannot be read.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * runtime.version // '1.3.11' under Bun, '22.22.2' under Node
160
+ * ```
161
+ */
162
+ get version() {
163
+ if (this.isBun) return process.versions.bun ?? "";
164
+ if (this.isDeno) return globalThis.Deno?.version?.deno ?? "";
165
+ return process.versions?.node ?? "";
166
+ }
167
+ };
168
+ /**
169
+ * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.
170
+ */
171
+ const runtime = new Runtime();
172
+ //#endregion
173
+ //#region ../../internals/utils/src/fs.ts
174
+ /**
175
+ * Reads the file at `path` as a UTF-8 string.
176
+ * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const source = await read('./src/Pet.ts')
181
+ * ```
182
+ */
183
+ async function read(path) {
184
+ if (runtime.isBun) return Bun.file(path).text();
185
+ return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
186
+ }
187
+ /**
188
+ * Writes `data` to `path`, trimming leading/trailing whitespace before saving.
189
+ * Skips the write when the trimmed content is empty or identical to what is already on disk.
190
+ * Creates any missing parent directories automatically.
191
+ * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * await write('./src/Pet.ts', source) // writes and returns trimmed content
196
+ * await write('./src/Pet.ts', source) // null — file unchanged
197
+ * await write('./src/Pet.ts', ' ') // null — empty content skipped
198
+ * ```
199
+ */
200
+ async function write(path, data, options = {}) {
201
+ const trimmed = data.trim();
202
+ if (trimmed === "") return null;
203
+ const resolved = (0, node_path.resolve)(path);
204
+ if (runtime.isBun) {
205
+ const file = Bun.file(resolved);
206
+ if ((await file.exists() ? await file.text() : null) === trimmed) return null;
207
+ await Bun.write(resolved, trimmed);
208
+ return trimmed;
209
+ }
210
+ try {
211
+ if (await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" }) === trimmed) return null;
212
+ } catch {}
213
+ await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
214
+ await (0, node_fs_promises.writeFile)(resolved, trimmed, { encoding: "utf-8" });
215
+ if (options.sanity) {
216
+ const savedData = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
217
+ if (savedData !== trimmed) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
218
+ return savedData;
219
+ }
220
+ return trimmed;
221
+ }
222
+ /**
223
+ * Recursively removes `path`. Silently succeeds when `path` does not exist.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * await clean('./dist')
228
+ * ```
229
+ */
230
+ async function clean(path) {
231
+ return (0, node_fs_promises.rm)(path, {
232
+ recursive: true,
233
+ force: true
234
+ });
235
+ }
236
+ /**
237
+ * Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved
238
+ * to absolute paths first, so relative and `..`-containing inputs compare correctly.
239
+ *
240
+ * Guards destructive operations: before wiping an output directory, check that it does not contain
241
+ * the project root, otherwise a `clean` would delete `kubb.config` and every source file.
242
+ *
243
+ * @example
244
+ * isPathInside('./src/gen', '.') // true — nested inside the root
245
+ * isPathInside('.', '.') // true — the same directory counts as inside
246
+ * isPathInside('.', './src/gen') // false — the root is not inside its own output
247
+ * isPathInside('../other', '.') // false — escapes the root
248
+ */
249
+ function isPathInside(path, parent) {
250
+ const resolvedPath = (0, node_path.resolve)(path);
251
+ const resolvedParent = (0, node_path.resolve)(parent);
252
+ if (resolvedPath === resolvedParent) return true;
253
+ const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
254
+ return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
255
+ }
256
+ /**
257
+ * Converts a filesystem path to use POSIX (`/`) separators.
258
+ *
259
+ * Most of the codebase compares and composes paths as strings (prefix matching, joining for
260
+ * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated
261
+ * paths, but on Windows it returns `\`-separated paths, which breaks every such comparison.
262
+ *
263
+ * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the
264
+ * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is
265
+ * exercisable from POSIX CI.
266
+ *
267
+ * @example
268
+ * toPosixPath('C:\\repo\\src\\pet.ts') // 'C:/repo/src/pet.ts'
269
+ */
270
+ function toPosixPath(filePath) {
271
+ return filePath.replaceAll("\\", "/");
272
+ }
273
+ /**
274
+ * Builds a nested file path from a dotted name. Splits on dots that precede a letter
275
+ * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
276
+ * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
277
+ *
278
+ * Empty segments are dropped before joining. They arise when the name starts with a dot
279
+ * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
280
+ * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
281
+ * absolute path, letting generated files escape the configured output directory.
282
+ *
283
+ * @example Nested path from a dotted name
284
+ * `toFilePath('pet.petId') // 'pet/petId'`
285
+ *
286
+ * @example PascalCase the final segment
287
+ * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
288
+ *
289
+ * @example Suffix applied to the final segment only
290
+ * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
291
+ */
292
+ function toFilePath(name, caseLast = camelCase) {
293
+ const parts = name.split(/\.(?=[a-zA-Z])/);
294
+ return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
295
+ }
296
+ //#endregion
297
+ //#region src/Hookable.ts
298
+ /**
299
+ * Typed hook emitter that awaits all async listeners before resolving.
300
+ * Wraps Node's `EventEmitter` with full TypeScript hook-map inference.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * const hooks = new Hookable<{ build: [name: string] }>()
305
+ * hooks.hook('build', async (name) => { console.log(name) })
306
+ * await hooks.callHook('build', 'petstore') // all listeners awaited
307
+ * ```
308
+ */
309
+ var Hookable = class {
310
+ /**
311
+ * Maximum number of listeners per hook before Node emits a memory-leak warning.
312
+ * @default 10
313
+ */
314
+ constructor(maxListener = 10) {
315
+ this.#emitter.setMaxListeners(maxListener);
316
+ }
317
+ #emitter = new node_events.EventEmitter();
318
+ /**
319
+ * Calls `hookName` and awaits all registered listeners sequentially.
320
+ * Throws if any listener rejects, wrapping the cause with the hook name and serialized arguments.
321
+ *
322
+ * @example
323
+ * ```ts
324
+ * await hooks.callHook('build', 'petstore')
325
+ * ```
326
+ */
327
+ callHook(hookName, ...hookArgs) {
328
+ const listeners = this.#emitter.listeners(hookName);
329
+ if (listeners.length === 0) return;
330
+ return this.#emitAll(hookName, listeners, hookArgs);
331
+ }
332
+ async #emitAll(hookName, listeners, hookArgs) {
333
+ for (const listener of listeners) try {
334
+ await listener(...hookArgs);
335
+ } catch (err) {
336
+ let serializedArgs;
337
+ try {
338
+ serializedArgs = JSON.stringify(hookArgs);
339
+ } catch {
340
+ serializedArgs = String(hookArgs);
341
+ }
342
+ throw new Error(`Error in async listener for "${hookName}" with hookArgs ${serializedArgs}`, { cause: toError(err) });
343
+ }
344
+ }
345
+ /**
346
+ * Registers a persistent listener for `hookName` and returns a function that removes it.
347
+ *
348
+ * @example
349
+ * ```ts
350
+ * const unhook = hooks.hook('build', async (name) => { console.log(name) })
351
+ * unhook() // removes it
352
+ * ```
353
+ */
354
+ hook(hookName, handler) {
355
+ this.#emitter.on(hookName, handler);
356
+ return () => this.removeHook(hookName, handler);
357
+ }
358
+ /**
359
+ * Registers every handler in `configHooks` at once and returns a function that removes them
360
+ * all. Undefined entries are skipped, so a partial hook object registers only its present keys.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * const unhook = hooks.addHooks({ build: onBuild, done: onDone })
365
+ * unhook() // removes both
366
+ * ```
367
+ */
368
+ addHooks(configHooks) {
369
+ const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
370
+ return () => {
371
+ for (const unhook of unhooks) unhook();
372
+ };
373
+ }
374
+ /**
375
+ * Removes a previously registered listener.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * hooks.removeHook('build', handler)
380
+ * ```
381
+ */
382
+ removeHook(hookName, handler) {
383
+ this.#emitter.off(hookName, handler);
384
+ }
385
+ /**
386
+ * Returns the number of listeners registered for `hookName`.
387
+ *
388
+ * @example
389
+ * ```ts
390
+ * hooks.hook('build', handler)
391
+ * hooks.listenerCount('build') // 1
392
+ * ```
393
+ */
394
+ listenerCount(hookName) {
395
+ return this.#emitter.listenerCount(hookName);
396
+ }
397
+ /**
398
+ * Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.
399
+ * Set this above the expected listener count when many listeners attach by design.
400
+ *
401
+ * @example
402
+ * ```ts
403
+ * hooks.setMaxListeners(40)
404
+ * ```
405
+ */
406
+ setMaxListeners(max) {
407
+ this.#emitter.setMaxListeners(max);
408
+ }
409
+ /**
410
+ * Removes all listeners from every hook channel.
411
+ *
412
+ * @example
413
+ * ```ts
414
+ * hooks.removeAllHooks()
415
+ * ```
416
+ */
417
+ removeAllHooks() {
418
+ this.#emitter.removeAllListeners();
419
+ }
420
+ };
421
+ //#endregion
422
+ //#region src/FileManager.ts
423
+ function joinSources(file) {
424
+ return file.sources.map((source) => (0, _kubb_ast.extractStringsFromNodes)(source.nodes)).filter(Boolean).join("\n\n");
425
+ }
426
+ async function parseCopy(file) {
427
+ let content;
428
+ try {
429
+ content = await read(file.copy);
430
+ } catch (err) {
431
+ throw new Error(`[kubb] Could not copy file into output: ${file.copy}`, { cause: err });
432
+ }
433
+ return [
434
+ file.banner,
435
+ content,
436
+ file.footer
437
+ ].filter((segment) => Boolean(segment)).map((segment) => segment.trimEnd()).join("\n");
438
+ }
439
+ function mergeFile(a, b) {
440
+ return {
441
+ ...a,
442
+ banner: b.banner,
443
+ footer: b.footer,
444
+ copy: b.copy ?? a.copy,
445
+ sources: a.sources.length ? b.sources.length ? [...a.sources, ...b.sources] : a.sources : b.sources,
446
+ imports: a.imports.length ? b.imports.length ? [...a.imports, ...b.imports] : a.imports : b.imports,
447
+ exports: a.exports.length ? b.exports.length ? [...a.exports, ...b.exports] : a.exports : b.exports
448
+ };
449
+ }
450
+ function isIndexPath(path) {
451
+ return path.endsWith("/index.ts") || path === "index.ts";
452
+ }
453
+ function compareFiles(a, b) {
454
+ const lenDiff = a.path.length - b.path.length;
455
+ if (lenDiff !== 0) return lenDiff;
456
+ const aIsIndex = isIndexPath(a.path);
457
+ const bIsIndex = isIndexPath(b.path);
458
+ if (aIsIndex && !bIsIndex) return 1;
459
+ if (!aIsIndex && bIsIndex) return -1;
460
+ return 0;
461
+ }
462
+ /**
463
+ * In-memory file store for generated files, and the writer that turns them into source
464
+ * strings on `storage`. Files sharing a `path` are merged (sources/imports/exports
465
+ * concatenated). The `files` getter is sorted by path length (barrel `index.ts` last
466
+ * within a bucket).
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * const manager = new FileManager()
471
+ * manager.upsert(myFile)
472
+ * manager.files // sorted view
473
+ * await manager.write(manager.files, { storage: fsStorage() })
474
+ * ```
475
+ */
476
+ var FileManager = class {
477
+ hooks = new Hookable();
478
+ #cache = /* @__PURE__ */ new Map();
479
+ #sorted = null;
480
+ add(...files) {
481
+ return this.#store(files, false);
482
+ }
483
+ upsert(...files) {
484
+ return this.#store(files, true);
485
+ }
486
+ #store(files, mergeExisting) {
487
+ const batch = files.length > 1 ? this.#dedupe(files) : files;
488
+ const resolved = [];
489
+ for (const file of batch) {
490
+ const existing = this.#cache.get(file.path);
491
+ const merged = existing && mergeExisting ? _kubb_ast.ast.factory.createFile(mergeFile(existing, file)) : _kubb_ast.ast.factory.createFile(file);
492
+ this.#cache.set(merged.path, merged);
493
+ resolved.push(merged);
494
+ }
495
+ if (resolved.length > 0) this.#sorted = null;
496
+ return resolved;
497
+ }
498
+ #dedupe(files) {
499
+ const seen = /* @__PURE__ */ new Map();
500
+ for (const file of files) {
501
+ const prev = seen.get(file.path);
502
+ seen.set(file.path, prev ? mergeFile(prev, file) : file);
503
+ }
504
+ return [...seen.values()];
505
+ }
506
+ clear() {
507
+ this.#cache.clear();
508
+ this.#sorted = null;
509
+ }
510
+ /**
511
+ * Releases all stored files and clears every `hooks` listener. Called by the core after
512
+ * `kubb:build:end`.
513
+ */
514
+ dispose() {
515
+ this.clear();
516
+ this.hooks.removeAllHooks();
517
+ }
518
+ /**
519
+ * All stored files in stable sort order (shortest path first, barrel files
520
+ * last within a length bucket). Returns a cached view, do not mutate.
521
+ */
522
+ get files() {
523
+ return this.#sorted ??= [...this.#cache.values()].sort(compareFiles);
524
+ }
525
+ /**
526
+ * Converts a file's AST sources (or its `copy` source) into the final on-disk string.
527
+ */
528
+ async parse(file, { parsers } = {}) {
529
+ if (file.copy) return parseCopy(file);
530
+ if (!parsers || !file.extname) return joinSources(file);
531
+ const parser = parsers.get(file.extname);
532
+ if (!parser) return joinSources(file);
533
+ return parser.parse(file);
534
+ }
535
+ /**
536
+ * Converts and writes every file at once, letting `storage.setItem` decide how much of
537
+ * that runs concurrently.
538
+ */
539
+ async write(files, { storage, parsers }) {
540
+ if (files.length === 0) return;
541
+ await this.hooks.callHook("start", files);
542
+ const total = files.length;
543
+ let processed = 0;
544
+ await Promise.all(files.map(async (file) => {
545
+ const source = await this.parse(file, { parsers });
546
+ processed++;
547
+ await this.hooks.callHook("update", {
548
+ file,
549
+ source,
550
+ processed,
551
+ total,
552
+ percentage: processed / total * 100
553
+ });
554
+ if (source) await storage.setItem(file.path, source);
555
+ }));
556
+ await this.hooks.callHook("end", files);
557
+ }
558
+ };
559
+ //#endregion
560
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/usingCtx.js
561
+ function _usingCtx() {
562
+ var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
563
+ var n = Error();
564
+ return n.name = "SuppressedError", n.error = r, n.suppressed = e, n;
565
+ };
566
+ var e = {};
567
+ var n = [];
568
+ function using(r, e) {
569
+ if (null != e) {
570
+ if (Object(e) !== e) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
571
+ if (r) var o = e[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
572
+ if (void 0 === o && (o = e[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r)) var t = o;
573
+ if ("function" != typeof o) throw new TypeError("Object is not disposable.");
574
+ t && (o = function o() {
575
+ try {
576
+ t.call(e);
577
+ } catch (r) {
578
+ return Promise.reject(r);
579
+ }
580
+ }), n.push({
581
+ v: e,
582
+ d: o,
583
+ a: r
584
+ });
585
+ } else r && n.push({
586
+ d: e,
587
+ a: r
588
+ });
589
+ return e;
590
+ }
591
+ return {
592
+ e,
593
+ u: using.bind(null, !1),
594
+ a: using.bind(null, !0),
595
+ d: function d() {
596
+ var o;
597
+ var t = this.e;
598
+ var s = 0;
599
+ function next() {
600
+ for (; o = n.pop();) try {
601
+ if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
602
+ if (o.d) {
603
+ var r = o.d.call(o.v);
604
+ if (o.a) return s |= 2, Promise.resolve(r).then(next, err);
605
+ } else s |= 1;
606
+ } catch (r) {
607
+ return err(r);
608
+ }
609
+ if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
610
+ if (t !== e) throw t;
611
+ }
612
+ function err(n) {
613
+ return t = t !== e ? new r(n, t) : n, next();
614
+ }
615
+ return next();
616
+ }
617
+ };
618
+ }
619
+ //#endregion
620
+ Object.defineProperty(exports, "BuildError", {
621
+ enumerable: true,
622
+ get: function() {
623
+ return BuildError;
624
+ }
625
+ });
626
+ Object.defineProperty(exports, "FileManager", {
627
+ enumerable: true,
628
+ get: function() {
629
+ return FileManager;
630
+ }
631
+ });
632
+ Object.defineProperty(exports, "Hookable", {
633
+ enumerable: true,
634
+ get: function() {
635
+ return Hookable;
636
+ }
637
+ });
638
+ Object.defineProperty(exports, "__name", {
639
+ enumerable: true,
640
+ get: function() {
641
+ return __name;
642
+ }
643
+ });
644
+ Object.defineProperty(exports, "__toESM", {
645
+ enumerable: true,
646
+ get: function() {
647
+ return __toESM;
648
+ }
649
+ });
650
+ Object.defineProperty(exports, "_usingCtx", {
651
+ enumerable: true,
652
+ get: function() {
653
+ return _usingCtx;
654
+ }
655
+ });
656
+ Object.defineProperty(exports, "camelCase", {
657
+ enumerable: true,
658
+ get: function() {
659
+ return camelCase;
660
+ }
661
+ });
662
+ Object.defineProperty(exports, "clean", {
663
+ enumerable: true,
664
+ get: function() {
665
+ return clean;
666
+ }
667
+ });
668
+ Object.defineProperty(exports, "getErrorMessage", {
669
+ enumerable: true,
670
+ get: function() {
671
+ return getErrorMessage;
672
+ }
673
+ });
674
+ Object.defineProperty(exports, "isPathInside", {
675
+ enumerable: true,
676
+ get: function() {
677
+ return isPathInside;
678
+ }
679
+ });
680
+ Object.defineProperty(exports, "toError", {
681
+ enumerable: true,
682
+ get: function() {
683
+ return toError;
684
+ }
685
+ });
686
+ Object.defineProperty(exports, "toFilePath", {
687
+ enumerable: true,
688
+ get: function() {
689
+ return toFilePath;
690
+ }
691
+ });
692
+ Object.defineProperty(exports, "toPosixPath", {
693
+ enumerable: true,
694
+ get: function() {
695
+ return toPosixPath;
696
+ }
697
+ });
698
+ Object.defineProperty(exports, "write", {
699
+ enumerable: true,
700
+ get: function() {
701
+ return write;
702
+ }
703
+ });
704
+
705
+ //# sourceMappingURL=usingCtx-CZyLSqds.cjs.map