@kubb/core 5.14.6 → 5.15.1

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.
@@ -11,17 +11,15 @@ import { ast, collectImportedRefNames, collectUsedSchemaNames, extractStringsFro
11
11
  import dns from "node:dns";
12
12
  import net from "node:net";
13
13
  import { tmpdir } from "node:os";
14
- //#region \0rolldown/runtime.js
14
+ // \0rolldown/runtime.js
15
15
  var __defProp = Object.defineProperty;
16
16
  var __name = (target, value) => __defProp(target, "name", {
17
17
  value,
18
18
  configurable: true
19
19
  });
20
- //#endregion
21
- //#region package.json
22
- var version = "5.14.6";
23
- //#endregion
24
- //#region ../../internals/utils/src/casing.ts
20
+ // package.json
21
+ var version = "5.15.1";
22
+ // ../../internals/utils/src/casing.ts
25
23
  /**
26
24
  * Shared implementation for camelCase and PascalCase conversion.
27
25
  * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
@@ -36,7 +34,7 @@ function convert(text, pascal) {
36
34
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
37
35
  }
38
36
  const cache = /* @__PURE__ */ new Map();
39
- const cacheLimit = 1e4;
37
+ const cacheLimit = 1e5;
40
38
  function toCamelOrPascal(text, pascal) {
41
39
  const key = `${pascal ? "P" : "c"}${text}`;
42
40
  const cached = cache.get(key);
@@ -58,8 +56,19 @@ function toCamelOrPascal(text, pascal) {
58
56
  function camelCase(text, { prefix = "", suffix = "" } = {}) {
59
57
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
60
58
  }
61
- //#endregion
62
- //#region ../../internals/utils/src/errors.ts
59
+ /**
60
+ * Converts `text` to PascalCase.
61
+ *
62
+ * @example Word boundaries
63
+ * `pascalCase('hello-world') // 'HelloWorld'`
64
+ *
65
+ * @example With a suffix
66
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
67
+ */
68
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
69
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
70
+ }
71
+ // ../../internals/utils/src/errors.ts
63
72
  /**
64
73
  * Coerces an unknown thrown value to an `Error` instance.
65
74
  * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
@@ -101,8 +110,7 @@ function getErrorChain(error) {
101
110
  for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) chain.push(current);
102
111
  return chain;
103
112
  }
104
- //#endregion
105
- //#region ../../internals/utils/src/runtime.ts
113
+ // ../../internals/utils/src/runtime.ts
106
114
  const isBun = typeof Bun !== "undefined";
107
115
  const isDeno = "Deno" in globalThis;
108
116
  /**
@@ -131,8 +139,7 @@ function detect() {
131
139
  version: process.versions?.node ?? ""
132
140
  };
133
141
  }
134
- //#endregion
135
- //#region ../../internals/utils/src/fs.ts
142
+ // ../../internals/utils/src/fs.ts
136
143
  /**
137
144
  * Resolves to `true` when the file or directory at `path` exists.
138
145
  * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
@@ -298,8 +305,7 @@ function isPathInside(path, parent) {
298
305
  const rel = relative(resolvedParent, resolvedPath);
299
306
  return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
300
307
  }
301
- //#endregion
302
- //#region ../../internals/utils/src/promise.ts
308
+ // ../../internals/utils/src/promise.ts
303
309
  /**
304
310
  * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
305
311
  * takes the next item the moment it frees up instead of waiting for a batch to drain.
@@ -316,8 +322,7 @@ async function inParallel({ items, limit, run }) {
316
322
  };
317
323
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
318
324
  }
319
- //#endregion
320
- //#region ../../internals/utils/src/time.ts
325
+ // ../../internals/utils/src/time.ts
321
326
  /**
322
327
  * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
323
328
  * Rounds to 2 decimal places for sub-millisecond precision without noise.
@@ -349,8 +354,7 @@ function formatMs(ms) {
349
354
  if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
350
355
  return `${Math.round(ms)}ms`;
351
356
  }
352
- //#endregion
353
- //#region src/diagnosticCatalog.ts
357
+ // src/diagnosticCatalog.ts
354
358
  /**
355
359
  * Every diagnostic code with its docs entry: a short title, what triggers it, and how to resolve
356
360
  * it. The source of truth for {@link diagnosticCode}, and the kubb.dev `/reference/diagnostics`
@@ -579,8 +583,7 @@ const diagnosticCatalog = {
579
583
  * these instead of inlining the string at a throw site.
580
584
  */
581
585
  const diagnosticCode = Object.fromEntries(Object.entries(diagnosticCatalog).map(([key, { code }]) => [key, code]));
582
- //#endregion
583
- //#region src/formatDiagnostic.ts
586
+ // src/formatDiagnostic.ts
584
587
  /** A problem's `help`, or the catalog fix. `info` gets none: its catalog fix says no action is needed. */
585
588
  function getHelp(problem) {
586
589
  if (problem.help || problem.severity === "info") return problem.help;
@@ -697,8 +700,7 @@ function format(diagnostic, { audience = "agent", verbose = false, width = 0, po
697
700
  if (code !== diagnosticCode.unknown) details.push(` ${paint("dim", "↳ Learn more")} ${paint("cyan", Diagnostics.docsUrl(code).replace(/^https:\/\//, ""))}`);
698
701
  return [...headline, ...details];
699
702
  }
700
- //#endregion
701
- //#region src/Diagnostics.ts
703
+ // src/Diagnostics.ts
702
704
  /**
703
705
  * Docs major version, derived from the package version so the link tracks the published major.
704
706
  */
@@ -991,8 +993,7 @@ var Diagnostics = class Diagnostics {
991
993
  */
992
994
  static format = format;
993
995
  };
994
- //#endregion
995
- //#region src/defineExtension.ts
996
+ // src/defineExtension.ts
996
997
  /**
997
998
  * Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
998
999
  */
@@ -1126,8 +1127,7 @@ function defineExtension(definition) {
1126
1127
  }
1127
1128
  }
1128
1129
  }
1129
- //#endregion
1130
- //#region src/composables.ts
1130
+ // src/composables.ts
1131
1131
  const kubbContextKey = Symbol.for("kubb.context");
1132
1132
  const host = globalThis;
1133
1133
  /**
@@ -1194,6 +1194,10 @@ function injectFile(file) {
1194
1194
  requireContext("injectFile").injectFile(file);
1195
1195
  }
1196
1196
  /**
1197
+ * Returns a value computed once per build and shared by every plugin, like `ctx.memo`.
1198
+ */
1199
+ const memo = (key, compute) => requireContext("memo").memo(key, compute);
1200
+ /**
1197
1201
  * Returns the options the user passed to the plugin being set up, like `ctx.options`.
1198
1202
  */
1199
1203
  function useOptions() {
@@ -1217,8 +1221,7 @@ function useConfig() {
1217
1221
  function requirePlugin(name) {
1218
1222
  return requireContext("requirePlugin").requirePlugin(name);
1219
1223
  }
1220
- //#endregion
1221
- //#region src/definePlugin.ts
1224
+ // src/definePlugin.ts
1222
1225
  /**
1223
1226
  * Merges the `output.mode` default into the output config and validates the combination.
1224
1227
  * Throws `KUBB_INVALID_PLUGIN_OPTIONS` when `mode: 'file'` is paired with a `group` option,
@@ -1268,8 +1271,14 @@ function definePlugin(definition) {
1268
1271
  ...definition
1269
1272
  });
1270
1273
  }
1271
- //#endregion
1272
- //#region src/publicAddress.ts
1274
+ // src/memo.ts
1275
+ function memoize(store, key, compute) {
1276
+ if (store.has(key)) return store.get(key);
1277
+ const value = compute();
1278
+ store.set(key, value);
1279
+ return value;
1280
+ }
1281
+ // src/publicAddress.ts
1273
1282
  function createBlockList() {
1274
1283
  const list = new net.BlockList();
1275
1284
  for (const [address, prefix] of [
@@ -1304,8 +1313,7 @@ function isPublicAddress(address, blocked = privateAddresses) {
1304
1313
  const family = net.isIP(address);
1305
1314
  return family !== 0 && !blocked.check(address, family === 4 ? "ipv4" : "ipv6");
1306
1315
  }
1307
- //#endregion
1308
- //#region src/gitInput.ts
1316
+ // src/gitInput.ts
1309
1317
  /** Matches a git `input`: the `git+` prefix npm uses for git dependencies. */
1310
1318
  const gitInputRegExp = /^git\+/i;
1311
1319
  function gitError(message, cause) {
@@ -1477,8 +1485,7 @@ async function checkoutGitInput(input, signal, { publicOnly = false, authorizati
1477
1485
  dispose
1478
1486
  };
1479
1487
  }
1480
- //#endregion
1481
- //#region src/input.ts
1488
+ // src/input.ts
1482
1489
  /**
1483
1490
  * Classifies an `input` value so callers branch on it once instead of repeating the checks.
1484
1491
  *
@@ -1556,8 +1563,7 @@ function inputToAdapterSource(config) {
1556
1563
  path: resolve(config.root, input)
1557
1564
  };
1558
1565
  }
1559
- //#endregion
1560
- //#region src/resolveOptions.ts
1566
+ // src/resolveOptions.ts
1561
1567
  const patternCache = /* @__PURE__ */ new Map();
1562
1568
  const optionsCache = /* @__PURE__ */ new WeakMap();
1563
1569
  function testPattern(value, pattern) {
@@ -1625,8 +1631,7 @@ function resolveOptions(node, context) {
1625
1631
  byOptions.set(node, { value: result });
1626
1632
  return result;
1627
1633
  }
1628
- //#endregion
1629
- //#region src/Resolver.ts
1634
+ // src/Resolver.ts
1630
1635
  function isNamespace(value) {
1631
1636
  return typeof value === "object" && value !== null && !Array.isArray(value);
1632
1637
  }
@@ -1700,8 +1705,8 @@ var Resolver = class Resolver {
1700
1705
  /** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
1701
1706
  default;
1702
1707
  #options;
1708
+ #memo = /* @__PURE__ */ new Map();
1703
1709
  #usedNames = /* @__PURE__ */ new Set();
1704
- #resolvedNames = /* @__PURE__ */ new Map();
1705
1710
  #baseName;
1706
1711
  #filePath;
1707
1712
  constructor(options) {
@@ -1727,6 +1732,12 @@ var Resolver = class Resolver {
1727
1732
  return this.default.name(name);
1728
1733
  }
1729
1734
  /**
1735
+ * Returns what `compute` produced the first time this build asked for `key`. A resolver lives for one build.
1736
+ */
1737
+ memo(key, compute) {
1738
+ return memoize(this.#memo, key, compute);
1739
+ }
1740
+ /**
1730
1741
  * Reserves emitted identifiers before allocating other declarations. The driver reserves component
1731
1742
  * names. Reserve extra identifiers, such as enum type aliases, before calling `resolveName`.
1732
1743
  *
@@ -1757,18 +1768,16 @@ var Resolver = class Resolver {
1757
1768
  * ```
1758
1769
  */
1759
1770
  resolveName({ key, name, normalize = (name) => name }) {
1760
- const cacheKey = JSON.stringify(key);
1761
- const previous = this.#resolvedNames.get(cacheKey);
1762
- if (previous !== void 0) return previous;
1763
- const emitted = (value) => {
1764
- const names = normalize(value);
1765
- return typeof names === "string" ? [names] : names;
1771
+ const cacheKey = typeof key === "string" ? `s:${key}` : `a:${key.map((segment) => segment === void 0 ? "u" : `${segment.length}:${segment}`).join("")}`;
1772
+ const allocate = (suffix) => {
1773
+ const candidate = suffix === 1 ? name : `${name}${suffix}`;
1774
+ const normalized = normalize(candidate);
1775
+ const names = typeof normalized === "string" ? [normalized] : normalized;
1776
+ if (names.some((emittedName) => this.#usedNames.has(emittedName))) return allocate(suffix + 1);
1777
+ this.reserveNames(names);
1778
+ return candidate;
1766
1779
  };
1767
- let result = name;
1768
- for (let suffix = 2; emitted(result).some((emittedName) => this.#usedNames.has(emittedName)); suffix++) result = `${name}${suffix}`;
1769
- this.reserveNames(emitted(result));
1770
- this.#resolvedNames.set(cacheKey, result);
1771
- return result;
1780
+ return this.memo(`resolveName:${cacheKey}`, () => allocate(1));
1772
1781
  }
1773
1782
  file(options) {
1774
1783
  return this.#resolveFile(options);
@@ -1929,8 +1938,8 @@ var Resolver = class Resolver {
1929
1938
  description: meta?.description,
1930
1939
  version: meta?.version,
1931
1940
  baseURL: meta?.baseURL,
1932
- circularNames: meta?.circularNames ?? [],
1933
- enumNames: meta?.enumNames ?? [],
1941
+ circularNames: meta?.circularNames ?? /* @__PURE__ */ new Set(),
1942
+ enumNames: meta?.enumNames ?? /* @__PURE__ */ new Set(),
1934
1943
  filePath: file?.path ?? "",
1935
1944
  baseName: file?.baseName ?? "",
1936
1945
  isBarrel: file?.isBarrel ?? false,
@@ -1977,8 +1986,7 @@ var Resolver = class Resolver {
1977
1986
  return Resolver.#resolveUserText(output?.footer, meta, file) ?? null;
1978
1987
  }
1979
1988
  };
1980
- //#endregion
1981
- //#region src/createResolver.ts
1989
+ // src/createResolver.ts
1982
1990
  /**
1983
1991
  * Defines a plugin resolver, the object that decides what every generated symbol and file
1984
1992
  * path is called. Override the top-level `name` and `file` to set the plugin's conventions,
@@ -1991,7 +1999,7 @@ var Resolver = class Resolver {
1991
1999
  * export const resolverTs = createResolver<PluginTs>({
1992
2000
  * pluginName: 'plugin-ts',
1993
2001
  * name(name) {
1994
- * return ensureValidVarName(pascalCase(name))
2002
+ * return this.memo(`name:${name}`, () => ensureValidVarName(pascalCase(name)))
1995
2003
  * },
1996
2004
  * })
1997
2005
  * ```
@@ -2026,8 +2034,7 @@ var Resolver = class Resolver {
2026
2034
  function createResolver(options) {
2027
2035
  return new Resolver(options);
2028
2036
  }
2029
- //#endregion
2030
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
2037
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/usingCtx.js
2031
2038
  function _usingCtx() {
2032
2039
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
2033
2040
  var n = Error();
@@ -2142,9 +2149,9 @@ function compareFiles(a, b) {
2142
2149
  * manifest, as what the output passes make of it. Checking here rather than in a driver gives a
2143
2150
  * storage writing to S3 or a database the same guarantee `fsStorage` has. `false` when skipped.
2144
2151
  */
2145
- async function writeChanged({ storage, manifest, file, source, signal }) {
2152
+ async function writeChanged({ storage, manifest, file, source, signal, cleaned }) {
2146
2153
  signal?.throwIfAborted();
2147
- const stored = await storage.readItem(file.path);
2154
+ const stored = cleaned && isPathInside(file.path, cleaned) ? null : await storage.readItem(file.path);
2148
2155
  if (stored !== null && (matchesStored({
2149
2156
  stored,
2150
2157
  source
@@ -2324,7 +2331,7 @@ var FileManager = class {
2324
2331
  * writes nothing and leaves every mtime where it was. `kubb:files:processing:end` lists the
2325
2332
  * skipped paths as `unchanged`.
2326
2333
  */
2327
- async write(files, { storage, parsers, manifest, signal, hooks, config }) {
2334
+ async write(files, { storage, parsers, manifest, signal, hooks, config, cleaned }) {
2328
2335
  if (files.length === 0) return;
2329
2336
  await hooks?.callHook("kubb:files:processing:start", { files });
2330
2337
  const unchanged = [];
@@ -2340,7 +2347,8 @@ var FileManager = class {
2340
2347
  manifest,
2341
2348
  file,
2342
2349
  source,
2343
- signal
2350
+ signal,
2351
+ cleaned
2344
2352
  })) unchanged.push(file.path);
2345
2353
  await progress?.(index);
2346
2354
  }
@@ -2351,8 +2359,7 @@ var FileManager = class {
2351
2359
  });
2352
2360
  }
2353
2361
  };
2354
- //#endregion
2355
- //#region src/nodeCache.ts
2362
+ // src/nodeCache.ts
2356
2363
  /**
2357
2364
  * Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate
2358
2365
  * walk.
@@ -2375,8 +2382,7 @@ function createNodeCache() {
2375
2382
  }
2376
2383
  };
2377
2384
  }
2378
- //#endregion
2379
- //#region src/KubbDriver.ts
2385
+ // src/KubbDriver.ts
2380
2386
  const ENFORCE_ORDER = {
2381
2387
  pre: -1,
2382
2388
  post: 1
@@ -2484,6 +2490,7 @@ var KubbDriver = class {
2484
2490
  */
2485
2491
  fileManager = new FileManager();
2486
2492
  plugins = /* @__PURE__ */ new Map();
2493
+ #memo = /* @__PURE__ */ new Map();
2487
2494
  /**
2488
2495
  * Removers for every listener the driver added (plugin, generator) so `dispose()` can detach
2489
2496
  * them in one pass. External `hooks.hook(...)` listeners are not tracked.
@@ -2645,7 +2652,8 @@ var KubbDriver = class {
2645
2652
  injectFile: (userFileNode) => {
2646
2653
  this.fileManager.add(ast.factory.createFile(userFileNode));
2647
2654
  },
2648
- requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
2655
+ requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name })),
2656
+ memo: this.memo.bind(this)
2649
2657
  };
2650
2658
  try {
2651
2659
  await kubbContext.run(ctx, async () => {
@@ -2747,6 +2755,7 @@ var KubbDriver = class {
2747
2755
  parsers: parsersMap,
2748
2756
  manifest: this.options.manifest,
2749
2757
  signal: this.options.signal,
2758
+ cleaned: this.options.cleanPath,
2750
2759
  hooks,
2751
2760
  config
2752
2761
  });
@@ -3035,6 +3044,7 @@ var KubbDriver = class {
3035
3044
  this.fileManager.dispose();
3036
3045
  this.inputNode = null;
3037
3046
  this.#adapterSource = null;
3047
+ this.#memo.clear();
3038
3048
  }
3039
3049
  [Symbol.dispose]() {
3040
3050
  this.dispose();
@@ -3042,6 +3052,9 @@ var KubbDriver = class {
3042
3052
  getResolver(pluginName) {
3043
3053
  return this.plugins.get(pluginName)?.resolver ?? createResolver({ pluginName });
3044
3054
  }
3055
+ memo(key, compute) {
3056
+ return memoize(this.#memo, key, compute);
3057
+ }
3045
3058
  getContext(plugin) {
3046
3059
  const driver = this;
3047
3060
  const report = (diagnostic) => {
@@ -3061,6 +3074,7 @@ var KubbDriver = class {
3061
3074
  getPlugin: driver.getPlugin.bind(driver),
3062
3075
  requirePlugin: ((name) => driver.requirePlugin(name, { requiredBy: plugin.name })),
3063
3076
  getResolver: driver.getResolver.bind(driver),
3077
+ memo: driver.memo.bind(driver),
3064
3078
  driver,
3065
3079
  addFile: async (...files) => {
3066
3080
  driver.fileManager.add(...files);
@@ -3070,8 +3084,8 @@ var KubbDriver = class {
3070
3084
  },
3071
3085
  get meta() {
3072
3086
  return driver.inputNode?.meta ?? {
3073
- circularNames: [],
3074
- enumNames: []
3087
+ circularNames: /* @__PURE__ */ new Set(),
3088
+ enumNames: /* @__PURE__ */ new Set()
3075
3089
  };
3076
3090
  },
3077
3091
  get adapter() {
@@ -3140,8 +3154,7 @@ function pluginNotFoundError({ pluginName, requiredBy }) {
3140
3154
  ...requiredBy ? { plugin: requiredBy } : {}
3141
3155
  });
3142
3156
  }
3143
- //#endregion
3144
- //#region src/Hookable.ts
3157
+ // src/Hookable.ts
3145
3158
  /**
3146
3159
  * Typed hook emitter that awaits all async listeners before resolving.
3147
3160
  *
@@ -3247,7 +3260,6 @@ var Hookable = class {
3247
3260
  this.#listeners.clear();
3248
3261
  }
3249
3262
  };
3250
- //#endregion
3251
- export { formatMs as A, writeRaw as B, useConfig as C, defineExtension as D, checkCompatibility as E, isPathInside as F, camelCase as H, listFiles as I, read as L, inParallel as M, exists as N, resolveMeta as O, existsSync$1 as P, rm$1 as R, tryUseKubb as S, useOptions as T, __name as U, toError as V, kubbContext as _, FileManager as a, setOptions as b, Resolver as c, isPublicAddress as d, assertPluginOption as f, injectFile as g, addMacro as h, createNodeCache as i, getElapsedMs as j, Diagnostics as k, getInputKind as l, addGenerator as m, KubbDriver as n, _usingCtx as o, definePlugin as p, pluginNotFoundError as r, createResolver as s, Hookable as t, checkoutGitInput as u, requirePlugin as v, useKubb as w, setResolver as x, setMacros as y, write as z };
3263
+ export { resolveMeta as A, rm$1 as B, setResolver as C, useOptions as D, useKubb as E, exists as F, pascalCase as G, writeRaw as H, existsSync$1 as I, __name as K, isPathInside as L, formatMs as M, getElapsedMs as N, checkCompatibility as O, inParallel as P, listFiles as R, setOptions as S, useConfig as T, toError as U, write as V, camelCase as W, injectFile as _, FileManager as a, requirePlugin as b, Resolver as c, isPublicAddress as d, memoize as f, addMacro as g, addGenerator as h, createNodeCache as i, Diagnostics as j, defineExtension as k, getInputKind as l, definePlugin as m, KubbDriver as n, _usingCtx as o, assertPluginOption as p, pluginNotFoundError as r, createResolver as s, Hookable as t, checkoutGitInput as u, kubbContext as v, tryUseKubb as w, setMacros as x, memo as y, read as z };
3252
3264
 
3253
- //# sourceMappingURL=Hookable-CyMsl7Bl.js.map
3265
+ //# sourceMappingURL=Hookable-C9bM5HsI.js.map