@kubb/core 5.0.0-beta.60 → 5.0.0-beta.61
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/{diagnostics-B-UZnFqP.d.ts → diagnostics-DiaUv_iK.d.ts} +11 -13
- package/dist/index.cjs +62 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +63 -37
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +4 -4
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +3 -3
- package/dist/mocks.js +5 -5
- package/dist/mocks.js.map +1 -1
- package/package.json +4 -4
- package/src/KubbDriver.ts +13 -12
- package/src/Transform.ts +57 -27
- package/src/defineGenerator.ts +1 -8
- package/src/definePlugin.ts +9 -4
- package/src/mocks.ts +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { $ as KubbPluginSetupContext, A as KubbHookStartContext, At as Adapter, B as ParsedFile, C as KubbFilesProcessingEndContext, Ct as GenerationResult, D as KubbGenerationStartContext, Dt as UserReporter, E as KubbGenerationEndContext, Et as ReporterName, F as KubbSuccessContext, G as Generator, H as createKubb, I as KubbWarnContext, J as KubbDriver, K as GeneratorContext, L as PossibleConfig, M as KubbInfoContext, Mt as AdapterSource, N as KubbLifecycleStartContext, Nt as createAdapter, O as KubbHookEndContext, Ot as createReporter, P as KubbPluginsEndContext, Pt as AsyncEventEmitter, Q as KubbPluginEndContext, R as UserConfig, S as KubbFileProcessingUpdate, St as createStorage, T as KubbFilesProcessingUpdateContext, Tt as ReporterContext, U as Parser, V as Kubb, W as defineParser, X as Group, Y as Exclude, Z as Include, _ as InputPath, _t as defineResolver, a as DiagnosticLocation, at as Override, b as KubbDiagnosticContext, bt as createRenderer, c as PerformanceDiagnostic, ct as definePlugin, d as SerializedDiagnostic, dt as ResolveBannerFile, et as KubbPluginStartContext, f as UpdateDiagnostic, ft as ResolveOptionsContext, g as InputData, gt as ResolverPathParams, h as Config, ht as ResolverFileParams, i as DiagnosticKind, it as OutputOptions, j as KubbHooks, jt as AdapterFactoryOptions, k as KubbHookLineContext, kt as logLevel, l as ProblemCode, lt as BannerMeta, m as CLIOptions, mt as ResolverContext, n as DiagnosticByCode, nt as Output, o as DiagnosticSeverity, ot as Plugin, p as BuildOutput, pt as Resolver, q as defineGenerator, r as DiagnosticDoc, rt as OutputMode, s as Diagnostics, st as PluginFactoryOptions, t as Diagnostic, tt as NormalizedPlugin, u as ProblemDiagnostic, ut as ResolveBannerContext, v as KubbBuildEndContext, vt as Renderer, w as KubbFilesProcessingStartContext, wt as Reporter, x as KubbErrorContext, xt as Storage, y as KubbBuildStartContext, yt as RendererFactory, z as FileProcessorHooks } from "./diagnostics-
|
|
2
|
+
import { $ as KubbPluginSetupContext, A as KubbHookStartContext, At as Adapter, B as ParsedFile, C as KubbFilesProcessingEndContext, Ct as GenerationResult, D as KubbGenerationStartContext, Dt as UserReporter, E as KubbGenerationEndContext, Et as ReporterName, F as KubbSuccessContext, G as Generator, H as createKubb, I as KubbWarnContext, J as KubbDriver, K as GeneratorContext, L as PossibleConfig, M as KubbInfoContext, Mt as AdapterSource, N as KubbLifecycleStartContext, Nt as createAdapter, O as KubbHookEndContext, Ot as createReporter, P as KubbPluginsEndContext, Pt as AsyncEventEmitter, Q as KubbPluginEndContext, R as UserConfig, S as KubbFileProcessingUpdate, St as createStorage, T as KubbFilesProcessingUpdateContext, Tt as ReporterContext, U as Parser, V as Kubb, W as defineParser, X as Group, Y as Exclude, Z as Include, _ as InputPath, _t as defineResolver, a as DiagnosticLocation, at as Override, b as KubbDiagnosticContext, bt as createRenderer, c as PerformanceDiagnostic, ct as definePlugin, d as SerializedDiagnostic, dt as ResolveBannerFile, et as KubbPluginStartContext, f as UpdateDiagnostic, ft as ResolveOptionsContext, g as InputData, gt as ResolverPathParams, h as Config, ht as ResolverFileParams, i as DiagnosticKind, it as OutputOptions, j as KubbHooks, jt as AdapterFactoryOptions, k as KubbHookLineContext, kt as logLevel, l as ProblemCode, lt as BannerMeta, m as CLIOptions, mt as ResolverContext, n as DiagnosticByCode, nt as Output, o as DiagnosticSeverity, ot as Plugin, p as BuildOutput, pt as Resolver, q as defineGenerator, r as DiagnosticDoc, rt as OutputMode, s as Diagnostics, st as PluginFactoryOptions, t as Diagnostic, tt as NormalizedPlugin, u as ProblemDiagnostic, ut as ResolveBannerContext, v as KubbBuildEndContext, vt as Renderer, w as KubbFilesProcessingStartContext, wt as Reporter, x as KubbErrorContext, xt as Storage, y as KubbBuildStartContext, yt as RendererFactory, z as FileProcessorHooks } from "./diagnostics-DiaUv_iK.js";
|
|
3
3
|
import * as ast from "@kubb/ast";
|
|
4
4
|
|
|
5
5
|
//#region ../../internals/utils/src/url.d.ts
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { stripVTControlCharacters, styleText } from "node:util";
|
|
|
5
5
|
import { access, glob, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
6
6
|
import path, { dirname, join, relative, resolve } from "node:path";
|
|
7
7
|
import * as ast from "@kubb/ast";
|
|
8
|
-
import { operationDef, schemaDef, transform } from "@kubb/ast";
|
|
8
|
+
import { composeMacros, operationDef, schemaDef, transform } from "@kubb/ast";
|
|
9
9
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
10
|
import * as factory from "@kubb/ast/factory";
|
|
11
11
|
import { collectUsedSchemaNames } from "@kubb/ast/utils";
|
|
@@ -608,7 +608,7 @@ function createAdapter(build) {
|
|
|
608
608
|
/**
|
|
609
609
|
* Docs major version, derived from the package version so the link tracks the published major.
|
|
610
610
|
*/
|
|
611
|
-
const docsMajor = "5.0.0-beta.
|
|
611
|
+
const docsMajor = "5.0.0-beta.61".split(".")[0] ?? "5";
|
|
612
612
|
/**
|
|
613
613
|
* Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
|
|
614
614
|
*
|
|
@@ -1489,45 +1489,55 @@ function defineResolver(build) {
|
|
|
1489
1489
|
//#endregion
|
|
1490
1490
|
//#region src/Transform.ts
|
|
1491
1491
|
/**
|
|
1492
|
-
* Holds
|
|
1493
|
-
* isolation on the original adapter node
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1492
|
+
* Holds an ordered list of macros per plugin, keyed by plugin name. Each plugin's macros run in
|
|
1493
|
+
* isolation on the original adapter node and are composed into a single `Visitor` that the
|
|
1494
|
+
* `@kubb/ast` `transform` primitive applies. `applyTo` is a per-plugin lookup, not a cross-plugin
|
|
1495
|
+
* chain, so plugin A's macros never see plugin B's output. When a plugin has no macros, `applyTo`
|
|
1496
|
+
* returns the original node reference, and `transform` does the same when the composed visitor
|
|
1497
|
+
* leaves the tree untouched, so callers can detect a no-op by identity.
|
|
1498
|
+
*
|
|
1499
|
+
* Registration order matches the order setup hooks fire, which the driver has already sorted by
|
|
1500
|
+
* `enforce` and dependency edges. The registry preserves that order; macro `enforce` only reorders
|
|
1501
|
+
* within a single plugin's list.
|
|
1500
1502
|
*/
|
|
1501
1503
|
var Transform = class {
|
|
1502
|
-
#
|
|
1504
|
+
#macros = /* @__PURE__ */ new Map();
|
|
1505
|
+
#composed = /* @__PURE__ */ new Map();
|
|
1503
1506
|
#memo = /* @__PURE__ */ new Map();
|
|
1504
1507
|
/**
|
|
1505
|
-
* Number of plugins with
|
|
1508
|
+
* Number of plugins with at least one registered macro.
|
|
1506
1509
|
*/
|
|
1507
1510
|
get size() {
|
|
1508
|
-
return this.#
|
|
1511
|
+
return this.#macros.size;
|
|
1509
1512
|
}
|
|
1510
1513
|
/**
|
|
1511
|
-
*
|
|
1512
|
-
* replaces the first.
|
|
1514
|
+
* Appends `macro` to the plugin's list, after any macros already registered.
|
|
1513
1515
|
*/
|
|
1514
|
-
|
|
1515
|
-
this.#
|
|
1516
|
-
|
|
1516
|
+
add(pluginName, macro) {
|
|
1517
|
+
const list = this.#macros.get(pluginName);
|
|
1518
|
+
if (list) list.push(macro);
|
|
1519
|
+
else this.#macros.set(pluginName, [macro]);
|
|
1520
|
+
this.#invalidate(pluginName);
|
|
1517
1521
|
}
|
|
1518
1522
|
/**
|
|
1519
|
-
*
|
|
1520
|
-
|
|
1523
|
+
* Replaces the plugin's macro list with `macros`.
|
|
1524
|
+
*/
|
|
1525
|
+
set(pluginName, macros) {
|
|
1526
|
+
this.#macros.set(pluginName, [...macros]);
|
|
1527
|
+
this.#invalidate(pluginName);
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Looks up the composed visitor for `pluginName`, or `undefined` when the plugin has no macros.
|
|
1521
1531
|
*/
|
|
1522
1532
|
get(pluginName) {
|
|
1523
|
-
return this.#
|
|
1533
|
+
return this.#visitorFor(pluginName);
|
|
1524
1534
|
}
|
|
1525
1535
|
/**
|
|
1526
|
-
* Runs the plugin's
|
|
1527
|
-
*
|
|
1536
|
+
* Runs the plugin's macros on `node`. Returns the original node reference when the plugin has no
|
|
1537
|
+
* macros, so callers can compare by identity to detect a no-op.
|
|
1528
1538
|
*/
|
|
1529
1539
|
applyTo(pluginName, node) {
|
|
1530
|
-
const visitor = this.#
|
|
1540
|
+
const visitor = this.#visitorFor(pluginName);
|
|
1531
1541
|
if (!visitor) return node;
|
|
1532
1542
|
let memo = this.#memo.get(pluginName);
|
|
1533
1543
|
if (!memo) {
|
|
@@ -1541,13 +1551,28 @@ var Transform = class {
|
|
|
1541
1551
|
return result;
|
|
1542
1552
|
}
|
|
1543
1553
|
/**
|
|
1544
|
-
* Clears every registration. Called from the driver's `dispose()` so
|
|
1545
|
-
*
|
|
1554
|
+
* Clears every registration. Called from the driver's `dispose()` so macros do not leak across
|
|
1555
|
+
* builds.
|
|
1546
1556
|
*/
|
|
1547
1557
|
dispose() {
|
|
1548
|
-
this.#
|
|
1558
|
+
this.#macros.clear();
|
|
1559
|
+
this.#composed.clear();
|
|
1549
1560
|
this.#memo.clear();
|
|
1550
1561
|
}
|
|
1562
|
+
#invalidate(pluginName) {
|
|
1563
|
+
this.#composed.delete(pluginName);
|
|
1564
|
+
this.#memo.delete(pluginName);
|
|
1565
|
+
}
|
|
1566
|
+
#visitorFor(pluginName) {
|
|
1567
|
+
const macros = this.#macros.get(pluginName);
|
|
1568
|
+
if (!macros || macros.length === 0) return void 0;
|
|
1569
|
+
let composed = this.#composed.get(pluginName);
|
|
1570
|
+
if (!composed) {
|
|
1571
|
+
composed = composeMacros(macros);
|
|
1572
|
+
this.#composed.set(pluginName, composed);
|
|
1573
|
+
}
|
|
1574
|
+
return composed;
|
|
1575
|
+
}
|
|
1551
1576
|
};
|
|
1552
1577
|
//#endregion
|
|
1553
1578
|
//#region src/KubbDriver.ts
|
|
@@ -1588,7 +1613,7 @@ var KubbDriver = class {
|
|
|
1588
1613
|
*/
|
|
1589
1614
|
#listeners = [];
|
|
1590
1615
|
/**
|
|
1591
|
-
* Transform registry. Plugins populate it during `kubb:plugin:setup` via `
|
|
1616
|
+
* Transform registry. Plugins populate it during `kubb:plugin:setup` via `addMacro`/`setMacros`,
|
|
1592
1617
|
* and `#runGenerators` reads it once per `(plugin, node)` pair through `applyTo`.
|
|
1593
1618
|
*/
|
|
1594
1619
|
#transforms = new Transform();
|
|
@@ -1671,7 +1696,7 @@ var KubbDriver = class {
|
|
|
1671
1696
|
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
1672
1697
|
*
|
|
1673
1698
|
* The `kubb:plugin:setup` listener wraps the global context in a plugin-specific one so
|
|
1674
|
-
* `addGenerator`, `setResolver`, and `
|
|
1699
|
+
* `addGenerator`, `setResolver`, and `setMacros` target the right `normalizedPlugin`.
|
|
1675
1700
|
* Every other `KubbHooks` event registers as a pass-through listener that external tooling
|
|
1676
1701
|
* can observe via `hooks.on(...)`.
|
|
1677
1702
|
*
|
|
@@ -1691,8 +1716,11 @@ var KubbDriver = class {
|
|
|
1691
1716
|
setResolver: (resolver) => {
|
|
1692
1717
|
this.setPluginResolver(plugin.name, resolver);
|
|
1693
1718
|
},
|
|
1694
|
-
|
|
1695
|
-
this.#transforms.
|
|
1719
|
+
addMacro: (macro) => {
|
|
1720
|
+
this.#transforms.add(plugin.name, macro);
|
|
1721
|
+
},
|
|
1722
|
+
setMacros: (macros) => {
|
|
1723
|
+
this.#transforms.set(plugin.name, macros);
|
|
1696
1724
|
},
|
|
1697
1725
|
setOptions: (opts) => {
|
|
1698
1726
|
plugin.options = {
|
|
@@ -1725,7 +1753,7 @@ var KubbDriver = class {
|
|
|
1725
1753
|
}
|
|
1726
1754
|
/**
|
|
1727
1755
|
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
1728
|
-
* can configure generators, resolvers,
|
|
1756
|
+
* can configure generators, resolvers, macros and renderers before `buildStart` runs.
|
|
1729
1757
|
*
|
|
1730
1758
|
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
1731
1759
|
*/
|
|
@@ -1736,7 +1764,8 @@ var KubbDriver = class {
|
|
|
1736
1764
|
options: {},
|
|
1737
1765
|
addGenerator: noop,
|
|
1738
1766
|
setResolver: noop,
|
|
1739
|
-
|
|
1767
|
+
addMacro: noop,
|
|
1768
|
+
setMacros: noop,
|
|
1740
1769
|
setOptions: noop,
|
|
1741
1770
|
injectFile: noop,
|
|
1742
1771
|
updateConfig: noop
|
|
@@ -1928,7 +1957,7 @@ var KubbDriver = class {
|
|
|
1928
1957
|
}
|
|
1929
1958
|
/**
|
|
1930
1959
|
* Streams schemas and operations through every plugin's generators. Each node is run
|
|
1931
|
-
* through the plugin's
|
|
1960
|
+
* through the plugin's macros (from `this.#transforms`) before the generator sees it,
|
|
1932
1961
|
* so plugins stay isolated and the hot path stays per-node. Schemas run before operations
|
|
1933
1962
|
* because the two passes share `flushPending` and the FileProcessor's event emitter.
|
|
1934
1963
|
* A failing plugin contributes an error diagnostic so the rest of the build continues.
|
|
@@ -2232,9 +2261,6 @@ var KubbDriver = class {
|
|
|
2232
2261
|
get resolver() {
|
|
2233
2262
|
return driver.getResolver(plugin.name);
|
|
2234
2263
|
},
|
|
2235
|
-
get transformer() {
|
|
2236
|
-
return driver.#transforms.get(plugin.name);
|
|
2237
|
-
},
|
|
2238
2264
|
warn(message) {
|
|
2239
2265
|
report({
|
|
2240
2266
|
code: Diagnostics.code.pluginWarning,
|