@kubb/core 5.8.1 → 5.8.2

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/README.md CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  ### Core engine for Kubb
26
26
 
27
- Core engine for Kubb's plugin-based code generation system. Provides the plugin driver, file manager, `defineConfig`, `definePlugin`, `defineMiddleware`, and the build orchestration layer used by every Kubb plugin.
27
+ Core engine for Kubb's plugin-based code generation system. Provides the plugin driver, file manager, `defineConfig`, `defineExtension`, `defineMiddleware`, and the build orchestration layer used by every Kubb plugin.
28
28
 
29
29
  > **Note:** `@kubb/core` is an internal library. Install the [`kubb`](https://npmx.dev/package/kubb) meta-package instead and author plugins, generators, resolvers, parsers, and adapters through its `kubb/kit` subpath, which re-exports the authoring surface of this package.
30
30
 
@@ -7,7 +7,7 @@ import path, { dirname, isAbsolute, relative, resolve } from "node:path";
7
7
  import { ast, collectImportedRefNames, collectUsedSchemaNames, composeMacros, extractStringsFromNodes, operationDef, schemaDef, transform } from "@kubb/ast";
8
8
  import { EventEmitter } from "node:events";
9
9
  //#region package.json
10
- var version = "5.8.1";
10
+ var version = "5.8.2";
11
11
  //#endregion
12
12
  //#region ../../internals/utils/src/casing.ts
13
13
  /**
@@ -995,13 +995,61 @@ function checkDependencies({ name, dependencies, plugins }) {
995
995
  });
996
996
  }
997
997
  }
998
- function defineExtension({ kind, meta, build }) {
998
+ function createExtensionFactory({ kind, meta, build }) {
999
999
  const factory = (options) => build(options ?? {});
1000
1000
  return Object.assign(factory, meta ? {
1001
1001
  kind,
1002
1002
  meta
1003
1003
  } : { kind });
1004
1004
  }
1005
+ function defineExtension(definition) {
1006
+ switch (definition.kind) {
1007
+ case "plugin": {
1008
+ const { meta, dependencies, enforce, hooks = {}, setup } = definition;
1009
+ return createExtensionFactory({
1010
+ kind: "plugin",
1011
+ meta,
1012
+ build: (options) => ({
1013
+ name: meta.name,
1014
+ meta,
1015
+ options,
1016
+ dependencies,
1017
+ enforce,
1018
+ hooks,
1019
+ setup
1020
+ })
1021
+ });
1022
+ }
1023
+ case "adapter": {
1024
+ const { meta, setup, build } = definition;
1025
+ return createExtensionFactory({
1026
+ kind: "adapter",
1027
+ meta,
1028
+ build: (raw) => {
1029
+ const options = setup ? setup(raw) : raw;
1030
+ return Object.assign(build(options), {
1031
+ name: meta.name,
1032
+ meta,
1033
+ options
1034
+ });
1035
+ }
1036
+ });
1037
+ }
1038
+ case "parser": {
1039
+ const { meta, build } = definition;
1040
+ return createExtensionFactory({
1041
+ kind: "parser",
1042
+ meta,
1043
+ build: (options) => ({
1044
+ ...build(options),
1045
+ name: meta.name,
1046
+ meta,
1047
+ options
1048
+ })
1049
+ });
1050
+ }
1051
+ }
1052
+ }
1005
1053
  //#endregion
1006
1054
  //#region src/composables.ts
1007
1055
  const kubbContextKey = Symbol.for("kubb.context");
@@ -1134,7 +1182,7 @@ function assertPluginOption({ plugin, option, value, allowed }) {
1134
1182
  });
1135
1183
  }
1136
1184
  function definePlugin(input) {
1137
- if (typeof input === "function") return defineExtension({
1185
+ if (typeof input === "function") return createExtensionFactory({
1138
1186
  kind: "plugin",
1139
1187
  build: (options) => {
1140
1188
  const plugin = input(options);
@@ -1144,19 +1192,9 @@ function definePlugin(input) {
1144
1192
  };
1145
1193
  }
1146
1194
  });
1147
- const { meta, dependencies, enforce, hooks = {}, setup } = input;
1148
1195
  return defineExtension({
1149
1196
  kind: "plugin",
1150
- meta,
1151
- build: (options) => ({
1152
- name: meta.name,
1153
- meta,
1154
- options,
1155
- dependencies,
1156
- enforce,
1157
- hooks,
1158
- setup
1159
- })
1197
+ ...input
1160
1198
  });
1161
1199
  }
1162
1200
  //#endregion
@@ -2784,6 +2822,6 @@ function pluginNotFoundError({ pluginName, requiredBy }) {
2784
2822
  });
2785
2823
  }
2786
2824
  //#endregion
2787
- export { inParallel as A, useOptions as C, Diagnostics as D, resolveMeta as E, toPosixPath as F, write as I, toError as L, exists as M, isPathInside as N, formatMs as O, read as P, camelCase as R, useKubb as S, defineExtension as T, setMacros as _, _usingCtx as a, tryUseKubb as b, Resolver as c, definePlugin as d, addGenerator as f, requirePlugin as g, kubbContext as h, FileManager as i, clean as j, getElapsedMs as k, getInputKind as l, injectFile as m, pluginNotFoundError as n, Hookable as o, addMacro as p, createNodeCache as r, createResolver as s, KubbDriver as t, assertPluginOption as u, setOptions as v, checkCompatibility as w, useConfig as x, setResolver as y };
2825
+ export { getElapsedMs as A, useOptions as C, resolveMeta as D, defineExtension as E, read as F, toPosixPath as I, write as L, clean as M, exists as N, Diagnostics as O, isPathInside as P, toError as R, useKubb as S, createExtensionFactory as T, setMacros as _, _usingCtx as a, tryUseKubb as b, Resolver as c, definePlugin as d, addGenerator as f, requirePlugin as g, kubbContext as h, FileManager as i, inParallel as j, formatMs as k, getInputKind as l, injectFile as m, pluginNotFoundError as n, Hookable as o, addMacro as p, createNodeCache as r, createResolver as s, KubbDriver as t, assertPluginOption as u, setOptions as v, checkCompatibility as w, useConfig as x, setResolver as y, camelCase as z };
2788
2826
 
2789
- //# sourceMappingURL=KubbDriver-Dz36Klt9.js.map
2827
+ //# sourceMappingURL=KubbDriver-DBm4hRKA.js.map