@kubb/core 5.0.0-beta.103 → 5.0.0-beta.105

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { $ as PluginName, A as Kubb, At as DiagnosticKind, B as Filter, Bt as Adapter, C as KubbWarnContext, Ct as ReporterContext, D as CreateKubbOptions, Dt as logLevel, E as UserConfig, Et as createReporter, F as KubbDriver, Ft as ProblemCode, G as KubbPluginStartContext, H as Include, Ht as AdapterSource, I as FileManagerHooks, It as ProblemDiagnostic, J as OutputMode, K as NormalizedPlugin, L as Parser, Lt as SerializedDiagnostic, M as Generator, Mt as DiagnosticSeverity, N as GeneratorContext, Nt as Diagnostics, O as GenerateOptions, Ot as Diagnostic, P as defineGenerator, Pt as PerformanceDiagnostic, Q as PluginFactoryOptions, R as defineParser, Rt as UpdateDiagnostic, S as KubbSuccessContext, St as Reporter, T as PostGenerateCommand, Tt as UserReporter, U as KubbPluginEndContext, Ut as createAdapter, V as Group, Vt as AdapterFactoryOptions, W as KubbPluginSetupContext, X as Override, Y as OutputOptions, Z as Plugin, _ as KubbHookStartContext, _t as RendererFactory, a as KubbBuildEndContext, at as ResolveFileOptions, b as KubbLifecycleStartContext, bt as createStorage, c as KubbErrorContext, ct as ResolvePathOptions, d as KubbFilesProcessingStartContext, dt as ResolverFile, et as ResolvePluginOptions, f as KubbFilesProcessingUpdateContext, ft as ResolverFileParams, g as KubbHookLineContext, gt as Renderer, h as KubbHookEndContext, ht as ResolverPathParams, i as Input, it as ResolveBannerFile, j as createKubb, jt as DiagnosticLocation, k as GenerateResult, kt as DiagnosticDoc, l as KubbFileProcessingUpdate, lt as Resolver, m as KubbGenerationStartContext, mt as ResolverPatch, n as CLIOptions, nt as BannerMeta, o as KubbBuildStartContext, ot as ResolveImportsOptions, p as KubbGenerationEndContext, pt as ResolverFilePathParams, q as Output, r as Config, rt as ResolveBannerContext, s as KubbDiagnosticContext, st as ResolveOptionsContext, t as BuildOutput, tt as definePlugin, u as KubbFilesProcessingEndContext, ut as ResolverDefault, v as KubbHooks, vt as createRenderer, w as PossibleConfig, wt as ReporterName, x as KubbPluginsEndContext, xt as GenerationResult, y as KubbInfoContext, yt as Storage, z as Exclude, zt as Hookable } from "./types-CYp43kqg.js";
2
+ import { $ as PluginFactoryOptions, A as Kubb, At as DiagnosticDoc, B as Exclude, Bt as Hookable, C as KubbWarnContext, Ct as Reporter, D as CreateKubbOptions, Dt as createReporter, E as UserConfig, Et as UserReporter, F as NodeCache, Ft as PerformanceDiagnostic, G as KubbPluginSetupContext, H as Group, Ht as AdapterFactoryOptions, I as KubbDriver, It as ProblemCode, J as Output, K as KubbPluginStartContext, L as FileManagerHooks, Lt as ProblemDiagnostic, M as Generator, Mt as DiagnosticLocation, N as GeneratorContext, Nt as DiagnosticSeverity, O as GenerateOptions, Ot as logLevel, P as defineGenerator, Pt as Diagnostics, Q as Plugin, R as Parser, Rt as SerializedDiagnostic, S as KubbSuccessContext, St as GenerationResult, T as PostGenerateCommand, Tt as ReporterName, U as Include, Ut as AdapterSource, V as Filter, Vt as Adapter, W as KubbPluginEndContext, Wt as createAdapter, X as OutputOptions, Y as OutputMode, Z as Override, _ as KubbHookStartContext, _t as Renderer, a as KubbBuildEndContext, at as ResolveBannerFile, b as KubbLifecycleStartContext, bt as Storage, c as KubbErrorContext, ct as ResolveOptionsContext, d as KubbFilesProcessingStartContext, dt as ResolverDefault, et as PluginName, f as KubbFilesProcessingUpdateContext, ft as ResolverFile, g as KubbHookLineContext, gt as ResolverPathParams, h as KubbHookEndContext, ht as ResolverPatch, i as Input, it as ResolveBannerContext, j as createKubb, jt as DiagnosticKind, k as GenerateResult, kt as Diagnostic, l as KubbFileProcessingUpdate, lt as ResolvePathOptions, m as KubbGenerationStartContext, mt as ResolverFilePathParams, n as CLIOptions, nt as definePlugin, o as KubbBuildStartContext, ot as ResolveFileOptions, p as KubbGenerationEndContext, pt as ResolverFileParams, q as NormalizedPlugin, r as Config, rt as BannerMeta, s as KubbDiagnosticContext, st as ResolveImportsOptions, t as BuildOutput, tt as ResolvePluginOptions, u as KubbFilesProcessingEndContext, ut as Resolver, v as KubbHooks, vt as RendererFactory, w as PossibleConfig, wt as ReporterContext, x as KubbPluginsEndContext, xt as createStorage, y as KubbInfoContext, yt as createRenderer, z as defineParser, zt as UpdateDiagnostic } from "./types-D116CBzm.js";
3
3
  //#region src/applyConfigDefaults.d.ts
4
4
  type ApplyConfigDefaultsOptions<TOutput> = {
5
5
  defaultAdapter: Adapter;
@@ -183,5 +183,5 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
183
183
  */
184
184
  declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
185
185
  //#endregion
186
- export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, Input, type InputKind, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, type PluginName, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, applyConfigDefaults, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, jsonReporter, logLevel, memoryStorage };
186
+ export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, Input, type InputKind, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, type PluginName, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, applyConfigDefaults, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, jsonReporter, logLevel, memoryStorage };
187
187
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { a as isPathInside, c as write, d as toError, f as camelCase, i as clean, l as BuildError, n as FileManager, o as toFilePath, r as Hookable, s as toPosixPath, t as _usingCtx, u as getErrorMessage } from "./usingCtx-C8EG-wqH.js";
2
+ import { a as clean, c as toPosixPath, d as getErrorMessage, f as toError, i as Hookable, l as write, n as createNodeCache, o as isPathInside, p as camelCase, r as FileManager, s as toFilePath, t as _usingCtx, u as BuildError } from "./usingCtx-C24YU3KM.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { stripVTControlCharacters, styleText } from "node:util";
5
5
  import { hash } from "node:crypto";
6
6
  import { access, glob, readFile, rm } from "node:fs/promises";
7
7
  import path, { join, relative, resolve } from "node:path";
8
- import { ast, collectSync, collectUsedSchemaNames, composeMacros, narrowSchema, operationDef, resolveRefName, schemaDef, transform } from "@kubb/ast";
8
+ import { ast, collectImportedRefNames, collectUsedSchemaNames, composeMacros, operationDef, schemaDef, transform } from "@kubb/ast";
9
9
  import process$1 from "node:process";
10
10
  //#region src/createAdapter.ts
11
11
  /**
@@ -149,7 +149,7 @@ function randomCliColor(text) {
149
149
  }
150
150
  //#endregion
151
151
  //#region package.json
152
- var version = "5.0.0-beta.103";
152
+ var version = "5.0.0-beta.105";
153
153
  //#endregion
154
154
  //#region src/constants.ts
155
155
  /**
@@ -845,28 +845,24 @@ var Resolver = class Resolver {
845
845
  * schemas (`targetName`) import the emitted name. Names and paths go through the top-level
846
846
  * `name` and `file`, so import entries follow the plugin's conventions, and a per-call
847
847
  * `name` override wins over both.
848
+ *
849
+ * The subtree scan runs through `collectImportedRefNames`, which memoizes by node identity, so a
850
+ * schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
851
+ * reads the same ref set instead of re-scanning it per plugin.
848
852
  */
849
853
  imports(options) {
850
854
  const { node, root, output, group, extname = ".ts", name } = options;
851
855
  const resolveName = name ?? ((schemaName) => this.name(schemaName));
852
- const seen = /* @__PURE__ */ new Set();
853
- return collectSync(node, { schema: (schemaNode) => {
854
- const schemaRef = narrowSchema(schemaNode, "ref");
855
- if (!schemaRef?.ref) return null;
856
- const schemaName = resolveRefName(schemaRef);
857
- if (!schemaName || seen.has(schemaName)) return null;
858
- seen.add(schemaName);
859
- return ast.factory.createImport({
860
- name: [resolveName(schemaName)],
861
- path: this.file({
862
- name: schemaName,
863
- extname,
864
- root,
865
- output,
866
- group
867
- }).path
868
- });
869
- } });
856
+ return collectImportedRefNames(node).map((schemaName) => ast.factory.createImport({
857
+ name: [resolveName(schemaName)],
858
+ path: this.file({
859
+ name: schemaName,
860
+ extname,
861
+ root,
862
+ output,
863
+ group
864
+ }).path
865
+ }));
870
866
  }
871
867
  /**
872
868
  * Folds each `override` over `base`, left to right, and returns a new resolver with helpers
@@ -1590,16 +1586,20 @@ var KubbDriver = class {
1590
1586
  }));
1591
1587
  }
1592
1588
  /**
1593
- * Runs schemas and operations through every plugin's generators. Each node is run
1594
- * through the plugin's macros (from `this.#transforms`) before the generator sees it,
1595
- * so plugins stay isolated and the hot path stays per-node. Schemas run before operations
1596
- * so file output stays deterministic across runs.
1597
- * A failing plugin contributes an error diagnostic so the rest of the build continues.
1598
- * Every plugin also contributes a `timing` diagnostic.
1589
+ * Runs schemas and operations through every plugin's generators. The walk is node-outer: each
1590
+ * schema is visited once and each operation once, and the node fans out to the matching
1591
+ * generators of every plugin in dependency order. A per-node cache (`createNodeCache`) is created
1592
+ * once per node and shared by all of that node's plugins, so node-derived work is computed once
1593
+ * and reused instead of recomputed per plugin. Each node still runs through the plugin's macros
1594
+ * (from `this.#transforms`) and its exclude/include/override filters before that plugin's
1595
+ * generator sees it, so plugins stay isolated. Schemas run before operations so file output
1596
+ * stays deterministic across runs. A generator with a `match` predicate that resolves `false`
1597
+ * for a node is skipped for that node, without calling `schema`/`operation`.
1599
1598
  *
1600
- * Plugins are processed one at a time, in full, so `kubb:plugin:end` fires as each one
1601
- * completes rather than all at once at the end. That ordering drives the CLI's
1602
- * `Plugins N/M` counter.
1599
+ * A failing plugin is dropped from the remaining walk, contributes an error diagnostic, and no
1600
+ * longer aborts the other plugins. `kubb:plugin:end` and each plugin's `timing` diagnostic fire
1601
+ * in dependency order once the walk finishes, driving the CLI's `Plugins N/M` counter. The
1602
+ * `operations` batch fires once per plugin after the single operation walk.
1603
1603
  *
1604
1604
  * When `this.inputNode` is `null`, every entry still gets a `kubb:plugin:end` so
1605
1605
  * post-plugin listeners (the barrel writer and friends) complete.
@@ -1637,105 +1637,133 @@ var KubbDriver = class {
1637
1637
  }) !== null);
1638
1638
  allowedSchemaNamesByPlugin.set(plugin.name, collectUsedSchemaNames(includedOps, schemas));
1639
1639
  }
1640
- for (const { plugin, context, hrStart } of entries) {
1640
+ const states = entries.map(({ plugin, context, hrStart }) => {
1641
1641
  const generatorContext = {
1642
1642
  ...context,
1643
1643
  resolver: this.getResolver(plugin.name)
1644
1644
  };
1645
1645
  const { exclude, include, override } = plugin.options;
1646
- const optionsAreStatic = !exclude?.length && !include?.length && !override?.length;
1647
- const allowedSchemaNames = allowedSchemaNamesByPlugin.get(plugin.name) ?? null;
1648
1646
  const generators = plugin.generators ?? [];
1649
- const schemaGenerators = generators.filter((generator) => generator.schema);
1650
- const operationGenerators = generators.filter((generator) => generator.operation);
1651
- const operationsGenerators = generators.filter((generator) => generator.operations);
1652
- let error = null;
1653
- const resolveForPlugin = (node) => {
1654
- const transformedNode = transforms.applyTo(plugin.name, node);
1655
- if (optionsAreStatic) return {
1656
- transformedNode,
1657
- options: plugin.options
1658
- };
1659
- const options = generatorContext.resolver.default.options(transformedNode, {
1660
- options: plugin.options,
1661
- exclude,
1662
- include,
1663
- override
1664
- });
1665
- if (options === null) return null;
1666
- return {
1667
- transformedNode,
1668
- options
1669
- };
1647
+ return {
1648
+ plugin,
1649
+ hrStart,
1650
+ generatorContext,
1651
+ exclude,
1652
+ include,
1653
+ override,
1654
+ optionsAreStatic: !exclude?.length && !include?.length && !override?.length,
1655
+ allowedSchemaNames: allowedSchemaNamesByPlugin.get(plugin.name) ?? null,
1656
+ schemaGenerators: generators.filter((generator) => generator.schema),
1657
+ operationGenerators: generators.filter((generator) => generator.operation),
1658
+ operationsGenerators: generators.filter((generator) => generator.operations),
1659
+ pluginOperations: [],
1660
+ error: null
1670
1661
  };
1671
- if (schemaGenerators.length) for (const node of schemas) {
1672
- if (error) break;
1662
+ });
1663
+ const resolveForPlugin = (state, node) => {
1664
+ const transformedNode = transforms.applyTo(state.plugin.name, node);
1665
+ if (state.optionsAreStatic) return {
1666
+ transformedNode,
1667
+ options: state.plugin.options
1668
+ };
1669
+ const options = state.generatorContext.resolver.default.options(transformedNode, {
1670
+ options: state.plugin.options,
1671
+ exclude: state.exclude,
1672
+ include: state.include,
1673
+ override: state.override
1674
+ });
1675
+ if (options === null) return null;
1676
+ return {
1677
+ transformedNode,
1678
+ options
1679
+ };
1680
+ };
1681
+ for (const node of schemas) {
1682
+ const cache = createNodeCache();
1683
+ for (const state of states) {
1684
+ if (state.error || !state.schemaGenerators.length) continue;
1673
1685
  try {
1674
- const resolved = resolveForPlugin(node);
1686
+ const resolved = resolveForPlugin(state, node);
1675
1687
  if (!resolved) continue;
1676
1688
  const { transformedNode, options } = resolved;
1677
- if (allowedSchemaNames !== null && transformedNode.name && !allowedSchemaNames.has(transformedNode.name)) continue;
1689
+ if (state.allowedSchemaNames !== null && transformedNode.name && !state.allowedSchemaNames.has(transformedNode.name)) continue;
1678
1690
  const ctx = {
1679
- ...generatorContext,
1680
- options
1691
+ ...state.generatorContext,
1692
+ options,
1693
+ cache
1681
1694
  };
1682
- for (const generator of schemaGenerators) await this.dispatch({
1683
- result: await generator.schema(transformedNode, ctx),
1684
- renderer: generator.renderer
1685
- });
1695
+ for (const generator of state.schemaGenerators) {
1696
+ if (!(generator.match ? await generator.match(transformedNode, ctx) : true)) continue;
1697
+ await this.dispatch({
1698
+ result: await generator.schema(transformedNode, ctx),
1699
+ renderer: generator.renderer
1700
+ });
1701
+ }
1686
1702
  await this.hooks.callHook("kubb:generate:schema", transformedNode, ctx);
1687
1703
  } catch (caughtError) {
1688
- error = toError(caughtError);
1704
+ state.error = toError(caughtError);
1689
1705
  }
1690
1706
  }
1691
- const pluginOperations = [];
1692
- if (operationGenerators.length || operationsGenerators.length) for (const node of operations) {
1693
- if (error) break;
1707
+ }
1708
+ for (const node of operations) {
1709
+ const cache = createNodeCache();
1710
+ for (const state of states) {
1711
+ if (state.error || !state.operationGenerators.length && !state.operationsGenerators.length) continue;
1694
1712
  try {
1695
- const resolved = resolveForPlugin(node);
1713
+ const resolved = resolveForPlugin(state, node);
1696
1714
  if (!resolved) continue;
1697
- pluginOperations.push(resolved.transformedNode);
1698
- if (operationGenerators.length) {
1715
+ state.pluginOperations.push(resolved.transformedNode);
1716
+ if (state.operationGenerators.length) {
1699
1717
  const ctx = {
1700
- ...generatorContext,
1701
- options: resolved.options
1718
+ ...state.generatorContext,
1719
+ options: resolved.options,
1720
+ cache
1702
1721
  };
1703
- for (const generator of operationGenerators) await this.dispatch({
1704
- result: await generator.operation(resolved.transformedNode, ctx),
1705
- renderer: generator.renderer
1706
- });
1722
+ for (const generator of state.operationGenerators) {
1723
+ if (!(generator.match ? await generator.match(resolved.transformedNode, ctx) : true)) continue;
1724
+ await this.dispatch({
1725
+ result: await generator.operation(resolved.transformedNode, ctx),
1726
+ renderer: generator.renderer
1727
+ });
1728
+ }
1707
1729
  await this.hooks.callHook("kubb:generate:operation", resolved.transformedNode, ctx);
1708
1730
  }
1709
1731
  } catch (caughtError) {
1710
- error = toError(caughtError);
1732
+ state.error = toError(caughtError);
1711
1733
  }
1712
1734
  }
1713
- if (!error && operationsGenerators.length) try {
1735
+ }
1736
+ for (const state of states) {
1737
+ if (state.error || !state.operationsGenerators.length) continue;
1738
+ try {
1714
1739
  const ctx = {
1715
- ...generatorContext,
1716
- options: plugin.options
1740
+ ...state.generatorContext,
1741
+ options: state.plugin.options,
1742
+ cache: createNodeCache()
1717
1743
  };
1718
- for (const generator of operationsGenerators) await this.dispatch({
1719
- result: await generator.operations(pluginOperations, ctx),
1744
+ for (const generator of state.operationsGenerators) await this.dispatch({
1745
+ result: await generator.operations(state.pluginOperations, ctx),
1720
1746
  renderer: generator.renderer
1721
1747
  });
1722
- await this.hooks.callHook("kubb:generate:operations", pluginOperations, ctx);
1748
+ await this.hooks.callHook("kubb:generate:operations", state.pluginOperations, ctx);
1723
1749
  } catch (caughtError) {
1724
- error = toError(caughtError);
1750
+ state.error = toError(caughtError);
1725
1751
  }
1726
- const duration = getElapsedMs(hrStart);
1752
+ }
1753
+ for (const state of states) {
1754
+ const duration = getElapsedMs(state.hrStart);
1727
1755
  await this.#emitPluginEnd({
1728
- plugin,
1756
+ plugin: state.plugin,
1729
1757
  duration,
1730
- success: !error,
1731
- error: error ?? void 0
1758
+ success: !state.error,
1759
+ error: state.error ?? void 0
1732
1760
  });
1733
- if (error) diagnostics.push({
1734
- ...Diagnostics.from(error),
1735
- plugin: plugin.name
1761
+ if (state.error) diagnostics.push({
1762
+ ...Diagnostics.from(state.error),
1763
+ plugin: state.plugin.name
1736
1764
  });
1737
1765
  diagnostics.push(Diagnostics.performance({
1738
- plugin: plugin.name,
1766
+ plugin: state.plugin.name,
1739
1767
  duration
1740
1768
  }));
1741
1769
  }