@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.
package/dist/index.cjs CHANGED
@@ -29,10 +29,10 @@ let tinyexec = require("tinyexec");
29
29
  let node_fs_promises = require("node:fs/promises");
30
30
  let node_path = require("node:path");
31
31
  node_path = __toESM(node_path, 1);
32
+ let node_fs = require("node:fs");
32
33
  let node_util = require("node:util");
33
34
  let _kubb_ast = require("@kubb/ast");
34
35
  let node_crypto = require("node:crypto");
35
- let node_fs = require("node:fs");
36
36
  let node_os = require("node:os");
37
37
  let node_readline = require("node:readline");
38
38
  let unstorage = require("unstorage");
@@ -41,7 +41,7 @@ unstorage_drivers_fs = __toESM(unstorage_drivers_fs, 1);
41
41
  let node_url = require("node:url");
42
42
  let node_module = require("node:module");
43
43
  //#region package.json
44
- var version = "5.11.2";
44
+ var version = "5.11.4";
45
45
  //#endregion
46
46
  //#region ../../internals/utils/src/casing.ts
47
47
  /**
@@ -247,9 +247,26 @@ async function write(path, data, options = {}) {
247
247
  stored: stored ?? "",
248
248
  source: trimmed
249
249
  })) return null;
250
+ await writeRaw(resolved, content);
251
+ if (options.sanity) {
252
+ const savedData = await read(resolved);
253
+ if (savedData !== content) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
254
+ return savedData;
255
+ }
256
+ return content;
257
+ }
258
+ /**
259
+ * Writes UTF-8 content verbatim, including empty files and surrounding whitespace.
260
+ * Uses Bun.write under Bun and creates missing parent directories under either runtime.
261
+ *
262
+ * @example
263
+ * await writeRaw('./cache/output.ts', ' // keep these bytes\n\n')
264
+ */
265
+ async function writeRaw(path, content) {
266
+ const resolved = (0, node_path.resolve)(path);
250
267
  if (runtime.isBun) {
251
268
  await Bun.write(resolved, content);
252
- return content;
269
+ return;
253
270
  }
254
271
  try {
255
272
  await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
@@ -258,12 +275,29 @@ async function write(path, data, options = {}) {
258
275
  await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
259
276
  await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
260
277
  }
261
- if (options.sanity) {
262
- const savedData = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
263
- if (savedData !== content) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
264
- return savedData;
278
+ }
279
+ /**
280
+ * Lists non-hidden regular files below `directory` as relative POSIX paths, excluding directories and symlinks.
281
+ * Uses Bun.Glob under Bun because its Node glob compatibility API lacks directory-entry support.
282
+ *
283
+ * @example
284
+ * for await (const path of listFiles('./src')) console.log(path)
285
+ */
286
+ async function* listFiles(directory) {
287
+ const cwd = (0, node_path.resolve)(directory);
288
+ if (runtime.isBun) {
289
+ yield* new Bun.Glob("**/*").scan({
290
+ cwd,
291
+ dot: false,
292
+ onlyFiles: true,
293
+ followSymlinks: false
294
+ });
295
+ return;
265
296
  }
266
- return content;
297
+ for await (const entry of (0, node_fs_promises.glob)("**/*", {
298
+ cwd,
299
+ withFileTypes: true
300
+ })) if (entry.isFile()) yield toPosixPath((0, node_path.relative)(cwd, (0, node_path.join)(entry.parentPath, entry.name)));
267
301
  }
268
302
  /**
269
303
  * Converts a filesystem path to use POSIX (`/`) separators.
@@ -3008,7 +3042,7 @@ const fsStorage = createStorage(() => ({
3008
3042
  name: "fs",
3009
3043
  async readItem(key) {
3010
3044
  try {
3011
- return await (0, node_fs_promises.readFile)((0, node_path.resolve)(key), "utf8");
3045
+ return await read((0, node_path.resolve)(key));
3012
3046
  } catch (_error) {
3013
3047
  return null;
3014
3048
  }
@@ -3026,10 +3060,7 @@ const fsStorage = createStorage(() => ({
3026
3060
  const resolvedBase = (0, node_path.resolve)(base ?? process.cwd());
3027
3061
  const keys = [];
3028
3062
  try {
3029
- for await (const entry of (0, node_fs_promises.glob)("**/*", {
3030
- cwd: resolvedBase,
3031
- withFileTypes: true
3032
- })) if (entry.isFile()) keys.push(toPosixPath((0, node_path.relative)(resolvedBase, (0, node_path.join)(entry.parentPath, entry.name))));
3063
+ for await (const path of listFiles(resolvedBase)) keys.push(path);
3033
3064
  } catch (_error) {}
3034
3065
  return keys;
3035
3066
  },
@@ -3075,7 +3106,9 @@ const cacheStorage = createStorage(({ root = process.cwd() }) => {
3075
3106
  return {
3076
3107
  name: "cache",
3077
3108
  readItem: (key) => fs.readItem(toPath(key)),
3078
- writeItem: (key, value) => fs.writeItem(toPath(key), value),
3109
+ async writeItem(key, value) {
3110
+ await writeRaw(toPath(key), value);
3111
+ },
3079
3112
  removeItem: (key) => fs.removeItem(toPath(key)),
3080
3113
  readKeys: (base) => fs.readKeys(base ? toPath(base) : dir),
3081
3114
  empty: async (base) => base ? fs.empty(toPath(base)) : void 0