@kubb/core 5.11.2 → 5.11.4

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,8 +1,9 @@
1
1
  import "node:module";
2
2
  import { satisfies } from "verkit";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
- import { mkdir, readFile, writeFile } from "node:fs/promises";
5
- import path, { dirname, isAbsolute, relative, resolve } from "node:path";
4
+ import { glob, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
+ import path, { dirname, isAbsolute, join, relative, resolve } from "node:path";
6
+ import { existsSync as existsSync$1 } from "node:fs";
6
7
  import { stripVTControlCharacters, styleText } from "node:util";
7
8
  import { ast, collectImportedRefNames, collectUsedSchemaNames, extractStringsFromNodes } from "@kubb/ast";
8
9
  //#region \0rolldown/runtime.js
@@ -13,7 +14,7 @@ var __name = (target, value) => __defProp(target, "name", {
13
14
  });
14
15
  //#endregion
15
16
  //#region package.json
16
- var version = "5.11.2";
17
+ var version = "5.11.4";
17
18
  //#endregion
18
19
  //#region ../../internals/utils/src/casing.ts
19
20
  /**
@@ -190,9 +191,26 @@ async function write(path, data, options = {}) {
190
191
  stored: stored ?? "",
191
192
  source: trimmed
192
193
  })) return null;
194
+ await writeRaw(resolved, content);
195
+ if (options.sanity) {
196
+ const savedData = await read(resolved);
197
+ if (savedData !== content) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
198
+ return savedData;
199
+ }
200
+ return content;
201
+ }
202
+ /**
203
+ * Writes UTF-8 content verbatim, including empty files and surrounding whitespace.
204
+ * Uses Bun.write under Bun and creates missing parent directories under either runtime.
205
+ *
206
+ * @example
207
+ * await writeRaw('./cache/output.ts', ' // keep these bytes\n\n')
208
+ */
209
+ async function writeRaw(path, content) {
210
+ const resolved = resolve(path);
193
211
  if (runtime.isBun) {
194
212
  await Bun.write(resolved, content);
195
- return content;
213
+ return;
196
214
  }
197
215
  try {
198
216
  await writeFile(resolved, content, { encoding: "utf-8" });
@@ -201,12 +219,29 @@ async function write(path, data, options = {}) {
201
219
  await mkdir(dirname(resolved), { recursive: true });
202
220
  await writeFile(resolved, content, { encoding: "utf-8" });
203
221
  }
204
- if (options.sanity) {
205
- const savedData = await readFile(resolved, { encoding: "utf-8" });
206
- if (savedData !== content) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
207
- return savedData;
222
+ }
223
+ /**
224
+ * Lists non-hidden regular files below `directory` as relative POSIX paths, excluding directories and symlinks.
225
+ * Uses Bun.Glob under Bun because its Node glob compatibility API lacks directory-entry support.
226
+ *
227
+ * @example
228
+ * for await (const path of listFiles('./src')) console.log(path)
229
+ */
230
+ async function* listFiles(directory) {
231
+ const cwd = resolve(directory);
232
+ if (runtime.isBun) {
233
+ yield* new Bun.Glob("**/*").scan({
234
+ cwd,
235
+ dot: false,
236
+ onlyFiles: true,
237
+ followSymlinks: false
238
+ });
239
+ return;
208
240
  }
209
- return content;
241
+ for await (const entry of glob("**/*", {
242
+ cwd,
243
+ withFileTypes: true
244
+ })) if (entry.isFile()) yield toPosixPath(relative(cwd, join(entry.parentPath, entry.name)));
210
245
  }
211
246
  /**
212
247
  * Converts a filesystem path to use POSIX (`/`) separators.
@@ -2799,6 +2834,6 @@ var Hookable = class {
2799
2834
  }
2800
2835
  };
2801
2836
  //#endregion
2802
- export { inParallel as A, useOptions as C, Diagnostics as D, resolveMeta as E, toError as F, camelCase as I, __name as L, read as M, toPosixPath as N, formatMs as O, write as P, useKubb as S, defineExtension as T, setMacros as _, FileManager as a, tryUseKubb as b, Resolver as c, definePlugin as d, addGenerator as f, requirePlugin as g, kubbContext as h, createNodeCache as i, isPathInside as j, getElapsedMs as k, getInputKind as l, injectFile as m, KubbDriver as n, _usingCtx as o, addMacro as p, pluginNotFoundError as r, createResolver as s, Hookable as t, assertPluginOption as u, setOptions as v, checkCompatibility as w, useConfig as x, setResolver as y };
2837
+ export { inParallel as A, __name as B, useOptions as C, Diagnostics as D, resolveMeta as E, rm as F, write as I, writeRaw as L, isPathInside as M, listFiles as N, formatMs as O, read as P, toError as R, useKubb as S, defineExtension as T, setMacros as _, FileManager as a, tryUseKubb as b, Resolver as c, definePlugin as d, addGenerator as f, requirePlugin as g, kubbContext as h, createNodeCache as i, existsSync$1 as j, getElapsedMs as k, getInputKind as l, injectFile as m, KubbDriver as n, _usingCtx as o, addMacro as p, pluginNotFoundError as r, createResolver as s, Hookable as t, assertPluginOption as u, setOptions as v, checkCompatibility as w, useConfig as x, setResolver as y, camelCase as z };
2803
2838
 
2804
- //# sourceMappingURL=Hookable-DmJSLHWf.js.map
2839
+ //# sourceMappingURL=Hookable-C2bwJUE5.js.map