@kubb/core 5.6.2 → 5.6.3

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.
@@ -1,805 +0,0 @@
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 || !__hasOwnProp.call(mod, "default") ? __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
- * Coerces an unknown thrown value to an `Error` instance.
61
- * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
62
- *
63
- * @example
64
- * ```ts
65
- * try { ... } catch(err) {
66
- * throw new Error('Build failed', { cause: toError(err) })
67
- * }
68
- * ```
69
- */
70
- function toError(value) {
71
- return value instanceof Error ? value : new Error(String(value));
72
- }
73
- /**
74
- * Extracts a human-readable message from any thrown value.
75
- *
76
- * @example
77
- * ```ts
78
- * getErrorMessage(new Error('oops')) // 'oops'
79
- * getErrorMessage('plain string') // 'plain string'
80
- * ```
81
- */
82
- function getErrorMessage(value) {
83
- return value instanceof Error ? value.message : String(value);
84
- }
85
- //#endregion
86
- //#region ../../internals/utils/src/runtime.ts
87
- /**
88
- * Detects the JavaScript runtime executing the current process and exposes its name and version.
89
- *
90
- * Prefer the shared {@link runtime} instance over constructing your own.
91
- */
92
- var Runtime = class {
93
- /**
94
- * `true` when the current process is running under Bun.
95
- *
96
- * Detection keys off the global `Bun` object rather than `process.versions`,
97
- * because Bun polyfills `process.versions.node` for Node compatibility and would
98
- * otherwise look like Node.
99
- *
100
- * @example
101
- * ```ts
102
- * if (runtime.isBun) {
103
- * await Bun.write(path, data)
104
- * }
105
- * ```
106
- */
107
- get isBun() {
108
- return typeof Bun !== "undefined";
109
- }
110
- /**
111
- * `true` when the current process is running under Deno.
112
- */
113
- get isDeno() {
114
- return typeof globalThis.Deno !== "undefined";
115
- }
116
- /**
117
- * `true` when the current process is running under Node.
118
- *
119
- * Bun and Deno are excluded first so a polyfilled `process` does not register as Node.
120
- */
121
- get isNode() {
122
- return !this.isBun && !this.isDeno && typeof process !== "undefined" && process.versions?.node != null;
123
- }
124
- /**
125
- * Name of the runtime executing the current process.
126
- *
127
- * @example
128
- * ```ts
129
- * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
130
- * ```
131
- */
132
- get name() {
133
- if (this.isBun) return "bun";
134
- if (this.isDeno) return "deno";
135
- return "node";
136
- }
137
- /**
138
- * Version of the active runtime, or an empty string when it cannot be read.
139
- *
140
- * @example
141
- * ```ts
142
- * runtime.version // '1.3.11' under Bun, '22.22.2' under Node
143
- * ```
144
- */
145
- get version() {
146
- if (this.isBun) return process.versions.bun ?? "";
147
- if (this.isDeno) return globalThis.Deno?.version?.deno ?? "";
148
- return process.versions?.node ?? "";
149
- }
150
- };
151
- /**
152
- * Shared {@link Runtime} instance describing the JavaScript runtime executing the current process.
153
- */
154
- const runtime = new Runtime();
155
- //#endregion
156
- //#region ../../internals/utils/src/fs.ts
157
- /**
158
- * Resolves to `true` when the file or directory at `path` exists.
159
- * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
160
- *
161
- * @example
162
- * ```ts
163
- * if (await exists('./kubb.config.ts')) {
164
- * const content = await read('./kubb.config.ts')
165
- * }
166
- * ```
167
- */
168
- async function exists(path) {
169
- if (runtime.isBun) return Bun.file(path).exists();
170
- return (0, node_fs_promises.access)(path).then(() => true, () => false);
171
- }
172
- /**
173
- * Reads the file at `path` as a UTF-8 string.
174
- * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
175
- *
176
- * @example
177
- * ```ts
178
- * const source = await read('./src/Pet.ts')
179
- * ```
180
- */
181
- async function read(path) {
182
- if (runtime.isBun) return Bun.file(path).text();
183
- return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
184
- }
185
- /**
186
- * Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact
187
- * bytes. Surrounding whitespace is what a formatter adds and what editors strip, and neither is a
188
- * reason to rewrite the file.
189
- *
190
- * Both sides are trimmed, so a storage that keeps bytes verbatim settles on the same answer as one
191
- * that normalizes what it stores. Trimming only `stored` would leave a source with leading
192
- * whitespace rewritten on every build, since the stored copy keeps the whitespace the comparison
193
- * has already dropped.
194
- */
195
- function matchesStored({ stored, source }) {
196
- return stored.trim() === source.trim();
197
- }
198
- /**
199
- * Writes `data` to `path`, trimming surrounding whitespace and ending the file with a single newline
200
- * the way prettier, biome, and oxfmt all do.
201
- * Skips the write when the trimmed content is empty, or when the file already holds that content.
202
- * Creates any missing parent directories automatically.
203
- * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.
204
- *
205
- * @example
206
- * ```ts
207
- * await write('./src/Pet.ts', source) // writes and returns the trimmed content plus a newline
208
- * await write('./src/Pet.ts', source) // null — file unchanged
209
- * await write('./src/Pet.ts', ' ') // null — empty content skipped
210
- * ```
211
- */
212
- async function write(path, data, options = {}) {
213
- const trimmed = data.trim();
214
- if (trimmed === "") return null;
215
- const content = `${trimmed}\n`;
216
- const resolved = (0, node_path.resolve)(path);
217
- let stored = options.stored;
218
- if (stored === void 0) {
219
- if (runtime.isBun) {
220
- const file = Bun.file(resolved);
221
- stored = await file.exists() ? await file.text() : null;
222
- } else try {
223
- stored = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
224
- } catch {
225
- stored = null;
226
- }
227
- }
228
- if (matchesStored({
229
- stored: stored ?? "",
230
- source: trimmed
231
- })) return null;
232
- if (runtime.isBun) {
233
- await Bun.write(resolved, content);
234
- return content;
235
- }
236
- try {
237
- await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
238
- } catch (error) {
239
- if (error.code !== "ENOENT") throw error;
240
- await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
241
- await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
242
- }
243
- if (options.sanity) {
244
- const savedData = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
245
- if (savedData !== content) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
246
- return savedData;
247
- }
248
- return content;
249
- }
250
- /**
251
- * Recursively removes `path`. Silently succeeds when `path` does not exist.
252
- *
253
- * @example
254
- * ```ts
255
- * await clean('./dist')
256
- * ```
257
- */
258
- async function clean(path) {
259
- return (0, node_fs_promises.rm)(path, {
260
- recursive: true,
261
- force: true
262
- });
263
- }
264
- /**
265
- * Converts a filesystem path to use POSIX (`/`) separators.
266
- *
267
- * Most of the codebase compares and composes paths as strings (prefix matching, joining for
268
- * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated
269
- * paths, but on Windows it returns `\`-separated paths, which breaks every such comparison.
270
- *
271
- * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the
272
- * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is
273
- * exercisable from POSIX CI.
274
- *
275
- * @example
276
- * toPosixPath('C:\\repo\\src\\pet.ts') // 'C:/repo/src/pet.ts'
277
- */
278
- function toPosixPath(filePath) {
279
- return filePath.replaceAll("\\", "/");
280
- }
281
- /**
282
- * Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved
283
- * to absolute paths first, so relative and `..`-containing inputs compare correctly.
284
- *
285
- * Guards a destructive or an out-of-tree operation: before wiping an output directory, check that
286
- * it does not contain the project root, and before loading a path a caller supplied, check that it
287
- * did not escape the directory it is allowed to read from.
288
- *
289
- * @example
290
- * isPathInside('./src/gen', '.') // true — nested inside the root
291
- * isPathInside('.', '.') // true — the same directory counts as inside
292
- * isPathInside('.', './src/gen') // false — the root is not inside its own output
293
- * isPathInside('../other', '.') // false — escapes the root
294
- */
295
- function isPathInside(path, parent) {
296
- const resolvedPath = (0, node_path.resolve)(path);
297
- const resolvedParent = (0, node_path.resolve)(parent);
298
- if (resolvedPath === resolvedParent) return true;
299
- const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
300
- return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
301
- }
302
- //#endregion
303
- //#region ../../internals/utils/src/promise.ts
304
- /**
305
- * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
306
- * takes the next item the moment it frees up instead of waiting for a batch to drain.
307
- *
308
- * @example
309
- * ```ts
310
- * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
311
- * ```
312
- */
313
- async function inParallel({ items, limit, run }) {
314
- const queue = items.entries();
315
- const worker = async () => {
316
- for (const [index, item] of queue) await run(item, index);
317
- };
318
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
319
- }
320
- //#endregion
321
- //#region src/Hookable.ts
322
- /**
323
- * Typed hook emitter that awaits all async listeners before resolving.
324
- * Wraps Node's `EventEmitter` with full TypeScript hook-map inference.
325
- *
326
- * @example
327
- * ```ts
328
- * const hooks = new Hookable<{ build: [name: string] }>()
329
- * hooks.hook('build', async (name) => { console.log(name) })
330
- * await hooks.callHook('build', 'petstore') // all listeners awaited
331
- * ```
332
- */
333
- var Hookable = class {
334
- /**
335
- * Maximum number of listeners per hook before Node emits a memory-leak warning.
336
- * @default 10
337
- */
338
- constructor(maxListener = 10) {
339
- this.#emitter.setMaxListeners(maxListener);
340
- }
341
- #emitter = new node_events.EventEmitter();
342
- /**
343
- * Calls `hookName` and awaits all registered listeners sequentially.
344
- * Throws if any listener rejects, wrapping the cause in an error that names the hook.
345
- *
346
- * @example
347
- * ```ts
348
- * await hooks.callHook('build', 'petstore')
349
- * ```
350
- */
351
- callHook(hookName, ...hookArgs) {
352
- const listeners = this.#emitter.listeners(hookName);
353
- if (listeners.length === 0) return;
354
- return this.#emitAll(hookName, listeners, hookArgs);
355
- }
356
- async #emitAll(hookName, listeners, hookArgs) {
357
- for (const listener of listeners) try {
358
- await listener(...hookArgs);
359
- } catch (err) {
360
- throw new Error(`Error in async listener for "${hookName}"`, { cause: toError(err) });
361
- }
362
- }
363
- /**
364
- * Registers a persistent listener for `hookName` and returns a function that removes it.
365
- *
366
- * @example
367
- * ```ts
368
- * const unhook = hooks.hook('build', async (name) => { console.log(name) })
369
- * unhook() // removes it
370
- * ```
371
- */
372
- hook(hookName, handler) {
373
- this.#emitter.on(hookName, handler);
374
- return () => this.removeHook(hookName, handler);
375
- }
376
- /**
377
- * Registers every handler in `configHooks` at once and returns a function that removes them
378
- * all. Undefined entries are skipped, so a partial hook object registers only its present keys.
379
- *
380
- * @example
381
- * ```ts
382
- * const unhook = hooks.addHooks({ build: onBuild, done: onDone })
383
- * unhook() // removes both
384
- * ```
385
- */
386
- addHooks(configHooks) {
387
- const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
388
- return () => {
389
- for (const unhook of unhooks) unhook();
390
- };
391
- }
392
- /**
393
- * Removes a previously registered listener.
394
- *
395
- * @example
396
- * ```ts
397
- * hooks.removeHook('build', handler)
398
- * ```
399
- */
400
- removeHook(hookName, handler) {
401
- this.#emitter.off(hookName, handler);
402
- }
403
- /**
404
- * Returns the number of listeners registered for `hookName`.
405
- *
406
- * @example
407
- * ```ts
408
- * hooks.hook('build', handler)
409
- * hooks.listenerCount('build') // 1
410
- * ```
411
- */
412
- listenerCount(hookName) {
413
- return this.#emitter.listenerCount(hookName);
414
- }
415
- /**
416
- * Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.
417
- * Set this above the expected listener count when many listeners attach by design.
418
- *
419
- * @example
420
- * ```ts
421
- * hooks.setMaxListeners(40)
422
- * ```
423
- */
424
- setMaxListeners(max) {
425
- this.#emitter.setMaxListeners(max);
426
- }
427
- /**
428
- * Removes all listeners from every hook channel.
429
- *
430
- * @example
431
- * ```ts
432
- * hooks.removeAllHooks()
433
- * ```
434
- */
435
- removeAllHooks() {
436
- this.#emitter.removeAllListeners();
437
- }
438
- };
439
- //#endregion
440
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/usingCtx.js
441
- function _usingCtx() {
442
- var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
443
- var n = Error();
444
- return n.name = "SuppressedError", n.error = r, n.suppressed = e, n;
445
- };
446
- var e = {};
447
- var n = [];
448
- function using(r, e) {
449
- if (null != e) {
450
- if (Object(e) !== e) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
451
- if (r) var o = e[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
452
- if (void 0 === o && (o = e[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r)) var t = o;
453
- if ("function" != typeof o) throw new TypeError("Object is not disposable.");
454
- t && (o = function o() {
455
- try {
456
- t.call(e);
457
- } catch (r) {
458
- return Promise.reject(r);
459
- }
460
- }), n.push({
461
- v: e,
462
- d: o,
463
- a: r
464
- });
465
- } else r && n.push({
466
- d: e,
467
- a: r
468
- });
469
- return e;
470
- }
471
- return {
472
- e,
473
- u: using.bind(null, !1),
474
- a: using.bind(null, !0),
475
- d: function d() {
476
- var o;
477
- var t = this.e;
478
- var s = 0;
479
- function next() {
480
- for (; o = n.pop();) try {
481
- if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
482
- if (o.d) {
483
- var r = o.d.call(o.v);
484
- if (o.a) return s |= 2, Promise.resolve(r).then(next, err);
485
- } else s |= 1;
486
- } catch (r) {
487
- return err(r);
488
- }
489
- if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
490
- if (t !== e) throw t;
491
- }
492
- function err(n) {
493
- return t = t !== e ? new r(n, t) : n, next();
494
- }
495
- return next();
496
- }
497
- };
498
- }
499
- function joinSources(file) {
500
- return file.sources.map((source) => (0, _kubb_ast.extractStringsFromNodes)(source.nodes)).filter(Boolean).join("\n\n");
501
- }
502
- /**
503
- * Reads a `copy` file and prints it through the parser's `copy` hook, or verbatim with `banner`/`footer` when there is none.
504
- */
505
- async function parseCopy(file, parser) {
506
- let content;
507
- try {
508
- content = await read(file.copy);
509
- } catch (err) {
510
- throw new Error(`[kubb] Could not copy file into output: ${file.copy}`, { cause: err });
511
- }
512
- if (parser?.copy) return parser.parse(_kubb_ast.ast.factory.createFile(parser.copy(file, content)));
513
- return [
514
- file.banner,
515
- content,
516
- file.footer
517
- ].filter((segment) => Boolean(segment)).map((segment) => segment.trimEnd()).join("\n");
518
- }
519
- function mergeFile(a, b) {
520
- return {
521
- ...a,
522
- banner: b.banner,
523
- footer: b.footer,
524
- copy: b.copy ?? a.copy,
525
- sources: a.sources.length ? b.sources.length ? [...a.sources, ...b.sources] : a.sources : b.sources,
526
- imports: a.imports.length ? b.imports.length ? [...a.imports, ...b.imports] : a.imports : b.imports,
527
- exports: a.exports.length ? b.exports.length ? [...a.exports, ...b.exports] : a.exports : b.exports
528
- };
529
- }
530
- function isIndexPath(path) {
531
- return path.endsWith("/index.ts") || path === "index.ts";
532
- }
533
- function compareFiles(a, b) {
534
- return a.path.length - b.path.length || Number(isIndexPath(a.path)) - Number(isIndexPath(b.path));
535
- }
536
- function isUnchanged({ stored, source, key, manifest }) {
537
- if (stored === null) return false;
538
- if (matchesStored({
539
- stored,
540
- source
541
- })) return true;
542
- return manifest?.isUpToDate({
543
- key,
544
- source,
545
- disk: stored
546
- }) ?? false;
547
- }
548
- /**
549
- * In-memory file store for generated files, and the writer that turns them into source
550
- * strings on `storage`. Files sharing a `path` are merged (sources/imports/exports
551
- * concatenated). The `files` getter is sorted by path length (barrel `index.ts` last
552
- * within a bucket).
553
- *
554
- * @example
555
- * ```ts
556
- * const manager = new FileManager()
557
- * manager.upsert(myFile)
558
- * manager.files // sorted view
559
- * await manager.write(manager.files, { storage: fsStorage() })
560
- * ```
561
- */
562
- var FileManager = class {
563
- hooks = new Hookable();
564
- #cache = /* @__PURE__ */ new Map();
565
- #sorted = null;
566
- add(...files) {
567
- return this.#store(files, false);
568
- }
569
- upsert(...files) {
570
- return this.#store(files, true);
571
- }
572
- /** Stores a generator result: a file array is upserted as is, an element renders through `renderer` first, falsy is a no-op. */
573
- async dispatch({ result, renderer }) {
574
- try {
575
- var _usingCtx$1 = _usingCtx();
576
- if (!result) return;
577
- if (Array.isArray(result)) {
578
- this.upsert(...result);
579
- return;
580
- }
581
- if (!renderer) return;
582
- const instance = _usingCtx$1.u(renderer());
583
- await instance.render(result);
584
- this.upsert(...instance.files);
585
- } catch (_) {
586
- _usingCtx$1.e = _;
587
- } finally {
588
- _usingCtx$1.d();
589
- }
590
- }
591
- #store(files, mergeExisting) {
592
- const batch = files.length > 1 ? this.#dedupe(files) : files;
593
- const resolved = [];
594
- for (const file of batch) {
595
- const existing = this.#cache.get(file.path);
596
- const merged = existing && mergeExisting ? _kubb_ast.ast.factory.createFile(mergeFile(existing, file)) : _kubb_ast.ast.factory.createFile(file);
597
- this.#cache.set(merged.path, merged);
598
- resolved.push(merged);
599
- }
600
- if (resolved.length > 0) this.#sorted = null;
601
- return resolved;
602
- }
603
- #dedupe(files) {
604
- const seen = /* @__PURE__ */ new Map();
605
- for (const file of files) {
606
- const prev = seen.get(file.path);
607
- seen.set(file.path, prev ? mergeFile(prev, file) : file);
608
- }
609
- return [...seen.values()];
610
- }
611
- /**
612
- * Releases all stored files and clears every `hooks` listener. Called by the core after
613
- * `kubb:build:end`.
614
- */
615
- dispose() {
616
- this.#cache.clear();
617
- this.#sorted = null;
618
- this.hooks.removeAllHooks();
619
- }
620
- /**
621
- * All stored files in stable sort order (shortest path first, barrel files
622
- * last within a length bucket). Returns a cached view, do not mutate.
623
- */
624
- get files() {
625
- return this.#sorted ??= [...this.#cache.values()].sort(compareFiles);
626
- }
627
- /**
628
- * Converts a file's AST sources (or its `copy` source) into the final on-disk string.
629
- */
630
- async parse(file, { parsers } = {}) {
631
- const parser = parsers?.get(file.extname);
632
- if (file.copy) return parseCopy(file, parser);
633
- if (!parser) return joinSources(file);
634
- return parser.parse(file);
635
- }
636
- /**
637
- * Parses and writes every file through a bounded pool of workers. A small spec runs all its files
638
- * at once; a spec with thousands of files keeps at most {@link FILE_CONCURRENCY} parsed sources in
639
- * memory rather than holding every source, while still overlapping each file's write with the
640
- * next file's parse. Each `update` carries the file's input position, so a consumer can present
641
- * the files in generation order even though they finish in whatever order they parse.
642
- *
643
- * A file the storage already holds is skipped, so a rebuild that generates identical output
644
- * writes nothing and leaves every mtime where it was.
645
- */
646
- async write(files, { storage, parsers, manifest, signal }) {
647
- if (files.length === 0) return;
648
- await this.hooks.callHook("start", files);
649
- const total = files.length;
650
- await inParallel({
651
- items: files,
652
- limit: 50,
653
- run: async (file, index) => {
654
- signal?.throwIfAborted();
655
- const source = await this.parse(file, { parsers });
656
- await this.hooks.callHook("update", {
657
- file,
658
- source,
659
- processed: index + 1,
660
- total,
661
- percentage: (index + 1) / total * 100
662
- });
663
- if (!source) return;
664
- signal?.throwIfAborted();
665
- const stored = await storage.readItem(file.path);
666
- if (isUnchanged({
667
- stored,
668
- source,
669
- key: file.path,
670
- manifest
671
- })) return;
672
- signal?.throwIfAborted();
673
- await storage.writeItem(file.path, source, { stored });
674
- manifest?.track({
675
- key: file.path,
676
- source
677
- });
678
- }
679
- });
680
- await this.hooks.callHook("end", files);
681
- }
682
- };
683
- //#endregion
684
- //#region src/nodeCache.ts
685
- /**
686
- * Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate
687
- * walk.
688
- */
689
- function createNodeCache() {
690
- const store = /* @__PURE__ */ new Map();
691
- return {
692
- readItem(key) {
693
- return store.get(key);
694
- },
695
- writeItem(key, value) {
696
- store.set(key, value);
697
- return value;
698
- },
699
- ensureItem(key, factory) {
700
- if (store.has(key)) return store.get(key);
701
- const value = factory();
702
- store.set(key, value);
703
- return value;
704
- }
705
- };
706
- }
707
- //#endregion
708
- Object.defineProperty(exports, "FileManager", {
709
- enumerable: true,
710
- get: function() {
711
- return FileManager;
712
- }
713
- });
714
- Object.defineProperty(exports, "Hookable", {
715
- enumerable: true,
716
- get: function() {
717
- return Hookable;
718
- }
719
- });
720
- Object.defineProperty(exports, "__name", {
721
- enumerable: true,
722
- get: function() {
723
- return __name;
724
- }
725
- });
726
- Object.defineProperty(exports, "__toESM", {
727
- enumerable: true,
728
- get: function() {
729
- return __toESM;
730
- }
731
- });
732
- Object.defineProperty(exports, "_usingCtx", {
733
- enumerable: true,
734
- get: function() {
735
- return _usingCtx;
736
- }
737
- });
738
- Object.defineProperty(exports, "camelCase", {
739
- enumerable: true,
740
- get: function() {
741
- return camelCase;
742
- }
743
- });
744
- Object.defineProperty(exports, "clean", {
745
- enumerable: true,
746
- get: function() {
747
- return clean;
748
- }
749
- });
750
- Object.defineProperty(exports, "createNodeCache", {
751
- enumerable: true,
752
- get: function() {
753
- return createNodeCache;
754
- }
755
- });
756
- Object.defineProperty(exports, "exists", {
757
- enumerable: true,
758
- get: function() {
759
- return exists;
760
- }
761
- });
762
- Object.defineProperty(exports, "getErrorMessage", {
763
- enumerable: true,
764
- get: function() {
765
- return getErrorMessage;
766
- }
767
- });
768
- Object.defineProperty(exports, "inParallel", {
769
- enumerable: true,
770
- get: function() {
771
- return inParallel;
772
- }
773
- });
774
- Object.defineProperty(exports, "isPathInside", {
775
- enumerable: true,
776
- get: function() {
777
- return isPathInside;
778
- }
779
- });
780
- Object.defineProperty(exports, "read", {
781
- enumerable: true,
782
- get: function() {
783
- return read;
784
- }
785
- });
786
- Object.defineProperty(exports, "toError", {
787
- enumerable: true,
788
- get: function() {
789
- return toError;
790
- }
791
- });
792
- Object.defineProperty(exports, "toPosixPath", {
793
- enumerable: true,
794
- get: function() {
795
- return toPosixPath;
796
- }
797
- });
798
- Object.defineProperty(exports, "write", {
799
- enumerable: true,
800
- get: function() {
801
- return write;
802
- }
803
- });
804
-
805
- //# sourceMappingURL=nodeCache-CllHsCcy.cjs.map