@kubb/core 5.6.3 → 5.8.0

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.
@@ -30,6 +30,7 @@ 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
32
  let _kubb_ast = require("@kubb/ast");
33
+ let verkit = require("verkit");
33
34
  let node_events = require("node:events");
34
35
  //#region ../../internals/utils/src/casing.ts
35
36
  /**
@@ -355,7 +356,7 @@ function formatMs(ms) {
355
356
  }
356
357
  //#endregion
357
358
  //#region package.json
358
- var version = "5.6.3";
359
+ var version = "5.8.0";
359
360
  //#endregion
360
361
  //#region src/constants.ts
361
362
  /**
@@ -411,6 +412,18 @@ const diagnosticCode = {
411
412
  */
412
413
  pluginNotFound: "KUBB_PLUGIN_NOT_FOUND",
413
414
  /**
415
+ * The running Kubb or Node.js version is outside a plugin's `meta.compatibility`.
416
+ */
417
+ incompatibleExtension: "KUBB_INCOMPATIBLE_EXTENSION",
418
+ /**
419
+ * A required entry in a plugin's `dependencies` record is missing from the config.
420
+ */
421
+ missingDependency: "KUBB_MISSING_DEPENDENCY",
422
+ /**
423
+ * A dependency's `meta.version` is outside the range a plugin's `dependencies` record declares.
424
+ */
425
+ incompatibleDependency: "KUBB_INCOMPATIBLE_DEPENDENCY",
426
+ /**
414
427
  * A plugin threw while generating.
415
428
  */
416
429
  pluginFailed: "KUBB_PLUGIN_FAILED",
@@ -423,6 +436,10 @@ const diagnosticCode = {
423
436
  */
424
437
  pluginInfo: "KUBB_PLUGIN_INFO",
425
438
  /**
439
+ * A `kubb/kit` composable was called outside a plugin's `setup` and `kubb:plugin:setup`.
440
+ */
441
+ noContext: "KUBB_NO_CONTEXT",
442
+ /**
426
443
  * A schema uses a `format` Kubb does not map to a specific type. Reserved for
427
444
  * adapters to emit as a `warning`.
428
445
  */
@@ -452,6 +469,10 @@ const diagnosticCode = {
452
469
  */
453
470
  invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS",
454
471
  /**
472
+ * An extension's options fail its options `schema`.
473
+ */
474
+ invalidOptions: "KUBB_INVALID_OPTIONS",
475
+ /**
455
476
  * A post-generate command (`output.postGenerate`) exited with a failure.
456
477
  */
457
478
  postGenerateFailed: "KUBB_POST_GENERATE_FAILED",
@@ -594,6 +615,21 @@ const diagnosticCatalog = {
594
615
  cause: "A plugin that another plugin depends on is missing from the config.",
595
616
  fix: "Add the required plugin to the `plugins` array in kubb.config.ts, or remove the dependency on it."
596
617
  },
618
+ [diagnosticCode.incompatibleExtension]: {
619
+ title: "Incompatible extension",
620
+ cause: "A plugin sets `meta.compatibility.kubb` or `meta.compatibility.node` to a range the running Kubb or Node.js version does not satisfy.",
621
+ fix: "Upgrade Kubb or Node.js to a version in the range, or install a version of the plugin that supports your current Kubb and Node.js."
622
+ },
623
+ [diagnosticCode.missingDependency]: {
624
+ title: "Missing dependency",
625
+ cause: "A plugin lists another plugin in its `dependencies` record without `optional: true`, and the config does not include it.",
626
+ fix: "Add the missing plugin to the `plugins` array in kubb.config.ts."
627
+ },
628
+ [diagnosticCode.incompatibleDependency]: {
629
+ title: "Incompatible dependency",
630
+ cause: "A plugin's `dependencies` record sets a `version` range, and the configured plugin's `meta.version` falls outside it.",
631
+ fix: "Install a version of the dependency inside the range, or a version of the dependent plugin that supports the installed dependency."
632
+ },
597
633
  [diagnosticCode.pluginFailed]: {
598
634
  title: "Plugin failed",
599
635
  cause: "A plugin threw while generating, or reported an error through `ctx.error`.",
@@ -609,6 +645,11 @@ const diagnosticCatalog = {
609
645
  cause: "A plugin reported an informational message through `ctx.info`.",
610
646
  fix: "Informational only. No action is required."
611
647
  },
648
+ [diagnosticCode.noContext]: {
649
+ title: "No plugin context",
650
+ cause: "A `kubb/kit` composable such as `useKubb()` or `addGenerator()` ran outside the `setup` and `kubb:plugin:setup` of a plugin, so there is no plugin to apply it to.",
651
+ fix: "Call the composable inside `setup` or `kubb:plugin:setup`, including in code that setup awaits."
652
+ },
612
653
  [diagnosticCode.unsupportedFormat]: {
613
654
  title: "Unsupported format",
614
655
  cause: "A schema uses a `format` Kubb does not map to a specific type, so it falls back to the base type.",
@@ -639,6 +680,11 @@ const diagnosticCatalog = {
639
680
  cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
640
681
  fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or use `output.mode: 'directory'`."
641
682
  },
683
+ [diagnosticCode.invalidOptions]: {
684
+ title: "Invalid options",
685
+ cause: "A plugin declares an options `schema`, and the options passed to it in kubb.config.ts do not match it.",
686
+ fix: "Fix each option the message lists by its path, such as `enum.type`. The plugin documentation lists the accepted values."
687
+ },
642
688
  [diagnosticCode.postGenerateFailed]: {
643
689
  title: "Post-generate command failed",
644
690
  cause: "A post-generate command (`output.postGenerate`) exited with a non-zero status.",
@@ -912,6 +958,214 @@ var Diagnostics = class Diagnostics {
912
958
  }
913
959
  };
914
960
  //#endregion
961
+ //#region src/composables.ts
962
+ const kubbContextKey = Symbol.for("kubb.context");
963
+ const host = globalThis;
964
+ /**
965
+ * Holds the setup context of the plugin whose `setup` or `kubb:plugin:setup` is running. `KubbDriver` sets it for each plugin.
966
+ *
967
+ * The store lives on `globalThis`, so the ESM and CommonJS builds of `@kubb/core` share one. A plugin that a
968
+ * CommonJS config loads would otherwise read an empty store and fail with `KUBB_NO_CONTEXT`.
969
+ */
970
+ const kubbContext = host[kubbContextKey] ??= new node_async_hooks.AsyncLocalStorage();
971
+ function requireContext(caller) {
972
+ const ctx = kubbContext.getStore();
973
+ if (ctx) return ctx;
974
+ throw new Diagnostics.Error({
975
+ code: Diagnostics.code.noContext,
976
+ severity: "error",
977
+ message: `\`${caller}()\` was called outside a plugin setup.`,
978
+ help: `Call \`${caller}()\` inside \`setup\` or \`kubb:plugin:setup\`, including in code that setup awaits.`
979
+ });
980
+ }
981
+ /**
982
+ * Returns the context of the plugin whose `kubb:plugin:setup` is running. It stays available after an `await`.
983
+ * Throws `KUBB_NO_CONTEXT` outside setup.
984
+ */
985
+ function useKubb() {
986
+ return requireContext("useKubb");
987
+ }
988
+ /**
989
+ * Returns the same context as {@link useKubb}, or `undefined` outside `setup` and `kubb:plugin:setup`.
990
+ */
991
+ function tryUseKubb() {
992
+ return kubbContext.getStore();
993
+ }
994
+ /**
995
+ * Registers generators on the plugin being set up, like `ctx.addGenerator`.
996
+ *
997
+ * @example
998
+ * `addGenerator(typeGenerator, enumGenerator)`
999
+ */
1000
+ function addGenerator(...generators) {
1001
+ requireContext("addGenerator").addGenerator(...generators);
1002
+ }
1003
+ /**
1004
+ * Sets the resolver of the plugin being set up, like `ctx.setResolver`.
1005
+ */
1006
+ function setResolver(resolver) {
1007
+ requireContext("setResolver").setResolver(resolver);
1008
+ }
1009
+ /**
1010
+ * Adds a macro to the plugin being set up, like `ctx.addMacro`.
1011
+ */
1012
+ function addMacro(macro) {
1013
+ requireContext("addMacro").addMacro(macro);
1014
+ }
1015
+ /**
1016
+ * Replaces the macros of the plugin being set up, like `ctx.setMacros`.
1017
+ */
1018
+ function setMacros(macros) {
1019
+ requireContext("setMacros").setMacros(macros);
1020
+ }
1021
+ /**
1022
+ * Adds a raw file to the build output, like `ctx.injectFile`.
1023
+ */
1024
+ function injectFile(file) {
1025
+ requireContext("injectFile").injectFile(file);
1026
+ }
1027
+ /**
1028
+ * Returns the options of the plugin being set up, parsed by its options `schema` when it has one, like `ctx.options`.
1029
+ */
1030
+ function useOptions() {
1031
+ return requireContext("useOptions").options;
1032
+ }
1033
+ /**
1034
+ * Sets the resolved options of the plugin being set up, like `ctx.setOptions`.
1035
+ */
1036
+ function setOptions(options) {
1037
+ requireContext("setOptions").setOptions(options);
1038
+ }
1039
+ /**
1040
+ * Returns the resolved build configuration, like `ctx.config`.
1041
+ */
1042
+ function useConfig() {
1043
+ return requireContext("useConfig").config;
1044
+ }
1045
+ /**
1046
+ * Returns another plugin from the config, typed through `Kubb.PluginRegistry`, like `ctx.requirePlugin`.
1047
+ */
1048
+ function requirePlugin(name) {
1049
+ return requireContext("requirePlugin").requirePlugin(name);
1050
+ }
1051
+ //#endregion
1052
+ //#region src/defineExtension.ts
1053
+ /**
1054
+ * Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
1055
+ */
1056
+ function resolveMeta({ name, meta }) {
1057
+ if (meta) return meta;
1058
+ if (name) return { name };
1059
+ throw new Diagnostics.Error({
1060
+ code: Diagnostics.code.invalidPluginOptions,
1061
+ severity: "error",
1062
+ message: "An extension has neither `meta.name` nor `name`.",
1063
+ help: "Set `meta: { name }` on the plugin or parser.",
1064
+ location: { kind: "config" }
1065
+ });
1066
+ }
1067
+ /**
1068
+ * Throws `KUBB_INCOMPATIBLE_EXTENSION` when the running Kubb or Node.js version is outside `meta.compatibility`.
1069
+ */
1070
+ function checkCompatibility(meta) {
1071
+ const checks = [{
1072
+ target: "Kubb",
1073
+ range: meta.compatibility?.kubb,
1074
+ version
1075
+ }, {
1076
+ target: "Node.js",
1077
+ range: meta.compatibility?.node,
1078
+ version: process.versions.node
1079
+ }];
1080
+ for (const { target, range, version } of checks) {
1081
+ if (!range || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
1082
+ throw new Diagnostics.Error({
1083
+ code: Diagnostics.code.incompatibleExtension,
1084
+ severity: "error",
1085
+ message: `"${meta.name}" requires ${target} ${range}, but ${version} is running.`,
1086
+ help: `Use a ${target} version that satisfies ${range}, or a version of "${meta.name}" that supports ${target} ${version}.`,
1087
+ location: { kind: "config" },
1088
+ plugin: meta.name
1089
+ });
1090
+ }
1091
+ }
1092
+ /**
1093
+ * Throws `KUBB_MISSING_DEPENDENCY` for a missing required entry in a `dependencies` record, and
1094
+ * `KUBB_INCOMPATIBLE_DEPENDENCY` when an entry's `meta.version` is out of range. Arrays are not checked.
1095
+ */
1096
+ function checkDependencies({ name, dependencies, plugins }) {
1097
+ if (!dependencies || Array.isArray(dependencies)) return;
1098
+ for (const [dependencyName, dependency] of Object.entries(dependencies)) {
1099
+ const target = plugins.get(dependencyName);
1100
+ if (!target) {
1101
+ if (dependency?.optional) continue;
1102
+ throw new Diagnostics.Error({
1103
+ code: Diagnostics.code.missingDependency,
1104
+ severity: "error",
1105
+ message: `Plugin "${dependencyName}" is required by "${name}" but not found.`,
1106
+ help: `Add "${dependencyName}" to the \`plugins\` array in kubb.config.ts.`,
1107
+ location: { kind: "config" },
1108
+ plugin: name
1109
+ });
1110
+ }
1111
+ const range = dependency?.version;
1112
+ const version = target.meta?.version;
1113
+ if (!range || !version || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
1114
+ throw new Diagnostics.Error({
1115
+ code: Diagnostics.code.incompatibleDependency,
1116
+ severity: "error",
1117
+ message: `"${name}" requires "${dependencyName}" ${range}, but ${version} is configured.`,
1118
+ help: `Install a version of "${dependencyName}" that satisfies ${range}.`,
1119
+ location: { kind: "config" },
1120
+ plugin: name
1121
+ });
1122
+ }
1123
+ }
1124
+ function formatIssuePath(path) {
1125
+ return (path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
1126
+ }
1127
+ /**
1128
+ * Validates an extension's raw options against its `schema` and returns the parsed value, with the schema's defaults.
1129
+ * Throws `KUBB_INVALID_OPTIONS`, naming the extension and each issue path, when the options are invalid.
1130
+ * Refuses an async validator, because extension factories run synchronously while the config loads.
1131
+ */
1132
+ function parseExtensionOptions({ kind, meta, schema, input }) {
1133
+ const validated = schema["~standard"].validate(input);
1134
+ if (typeof validated.then === "function") {
1135
+ Promise.resolve(validated).catch(() => void 0);
1136
+ throw new Error(`The options schema of ${kind} "${meta.name}" validates asynchronously. Use a synchronous schema, because Kubb validates options while the config loads.`);
1137
+ }
1138
+ const result = validated;
1139
+ if (!result.issues) return result.value;
1140
+ const issues = result.issues.map((issue) => {
1141
+ const path = formatIssuePath(issue.path);
1142
+ return path ? `\`${path}\`: ${issue.message}` : issue.message;
1143
+ });
1144
+ throw new Diagnostics.Error({
1145
+ code: Diagnostics.code.invalidOptions,
1146
+ severity: "error",
1147
+ message: `Invalid options for ${kind} "${meta.name}". ${issues.join("; ")}`,
1148
+ help: `Fix the listed options of "${meta.name}" in kubb.config.ts. Its documentation lists the accepted values.`,
1149
+ location: { kind: "config" },
1150
+ ...kind === "plugin" && { plugin: meta.name }
1151
+ });
1152
+ }
1153
+ function defineExtension({ kind, meta, schema, build }) {
1154
+ const factory = (raw) => {
1155
+ const options = raw ?? {};
1156
+ return build({
1157
+ options,
1158
+ parsedOptions: schema && meta ? parseExtensionOptions({
1159
+ kind,
1160
+ meta,
1161
+ schema,
1162
+ input: options
1163
+ }) : options
1164
+ });
1165
+ };
1166
+ return Object.assign(factory, { kind }, meta && { meta }, schema && { schema });
1167
+ }
1168
+ //#endregion
915
1169
  //#region src/definePlugin.ts
916
1170
  /**
917
1171
  * Merges the `output.mode` default into the output config and validates the combination.
@@ -951,30 +1205,33 @@ function assertPluginOption({ plugin, option, value, allowed }) {
951
1205
  plugin
952
1206
  });
953
1207
  }
954
- /**
955
- * Wraps a plugin factory and returns a function that accepts user options and
956
- * yields a typed `Plugin`. Lifecycle handlers go inside a single `hooks` object.
957
- *
958
- * Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
959
- * `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
960
- * convention (`plugin-react-query`, `plugin-zod`, ...).
961
- *
962
- * @example
963
- * ```ts
964
- * import { definePlugin } from '@kubb/core'
965
- *
966
- * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
967
- * name: 'plugin-ts',
968
- * hooks: {
969
- * 'kubb:plugin:setup'(ctx) {
970
- * ctx.setResolver(resolverTs)
971
- * },
972
- * },
973
- * }))
974
- * ```
975
- */
976
- function definePlugin(factory) {
977
- return (options) => factory(options ?? {});
1208
+ function definePlugin(input) {
1209
+ if (typeof input === "function") return defineExtension({
1210
+ kind: "plugin",
1211
+ build: ({ options }) => {
1212
+ const plugin = input(options);
1213
+ return {
1214
+ ...plugin,
1215
+ meta: resolveMeta(plugin)
1216
+ };
1217
+ }
1218
+ });
1219
+ const { meta, schema, dependencies, enforce, hooks = {}, setup } = input;
1220
+ return defineExtension({
1221
+ kind: "plugin",
1222
+ meta,
1223
+ schema,
1224
+ build: ({ options, parsedOptions }) => ({
1225
+ name: meta.name,
1226
+ meta,
1227
+ options,
1228
+ ...schema && { parsedOptions },
1229
+ dependencies,
1230
+ enforce,
1231
+ hooks,
1232
+ setup
1233
+ })
1234
+ });
978
1235
  }
979
1236
  //#endregion
980
1237
  //#region src/input.ts
@@ -1587,7 +1844,7 @@ var Hookable = class {
1587
1844
  }
1588
1845
  };
1589
1846
  //#endregion
1590
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/usingCtx.js
1847
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
1591
1848
  function _usingCtx() {
1592
1849
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
1593
1850
  var n = Error();
@@ -2011,23 +2268,35 @@ var KubbDriver = class {
2011
2268
  this.adapter = config.adapter ?? null;
2012
2269
  }
2013
2270
  /**
2014
- * Normalizes every configured plugin, orders them, and registers their lifecycle handlers.
2271
+ * Normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
2015
2272
  * A plugin that another lists as a dependency runs first, then `enforce: 'pre'` before
2016
2273
  * `'post'`. When the config has an adapter, the adapter source is resolved from the input
2017
2274
  * so `run` can parse it later.
2018
2275
  */
2019
2276
  async setup() {
2020
2277
  this.options.signal?.throwIfAborted();
2278
+ for (const parser of this.config.parsers) if (parser.meta) checkCompatibility(parser.meta);
2021
2279
  const normalized = this.#sortPlugins(this.config.plugins.map((rawPlugin) => {
2280
+ if (rawPlugin.meta) checkCompatibility(rawPlugin.meta);
2281
+ const meta = resolveMeta(rawPlugin);
2282
+ const options = rawPlugin.parsedOptions ?? rawPlugin.options;
2022
2283
  return {
2023
- name: rawPlugin.name,
2024
- dependencies: rawPlugin.dependencies,
2284
+ name: meta.name,
2285
+ meta,
2286
+ dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(options ?? {}, { config: this.config }) : rawPlugin.dependencies,
2025
2287
  enforce: rawPlugin.enforce,
2026
2288
  hooks: rawPlugin.hooks,
2027
- options: rawPlugin.options ?? defaultPluginOptions(),
2028
- resolver: createResolver({ pluginName: rawPlugin.name })
2289
+ setup: rawPlugin.setup,
2290
+ options: options ?? defaultPluginOptions(),
2291
+ resolver: createResolver({ pluginName: meta.name })
2029
2292
  };
2030
2293
  }));
2294
+ const byName = new Map(normalized.map((plugin) => [plugin.name, plugin]));
2295
+ for (const plugin of normalized) checkDependencies({
2296
+ name: plugin.name,
2297
+ dependencies: plugin.dependencies,
2298
+ plugins: byName
2299
+ });
2031
2300
  for (const plugin of normalized) {
2032
2301
  this.#registerPlugin(plugin);
2033
2302
  this.plugins.set(plugin.name, plugin);
@@ -2045,7 +2314,10 @@ var KubbDriver = class {
2045
2314
  #sortPlugins(plugins) {
2046
2315
  const queue = [...plugins].sort((a, b) => enforceWeight(a) - enforceWeight(b));
2047
2316
  const names = new Set(queue.map((plugin) => plugin.name));
2048
- const blockedBy = new Map(queue.map((plugin) => [plugin.name, new Set(plugin.dependencies?.filter((name) => names.has(name) && name !== plugin.name))]));
2317
+ const blockedBy = new Map(queue.map((plugin) => {
2318
+ const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
2319
+ return [plugin.name, new Set(dependencies.filter((name) => names.has(name) && name !== plugin.name))];
2320
+ }));
2049
2321
  const sorted = [];
2050
2322
  for (const _ of plugins) {
2051
2323
  const index = queue.findIndex((plugin) => blockedBy.get(plugin.name)?.size === 0);
@@ -2090,41 +2362,45 @@ var KubbDriver = class {
2090
2362
  this.#unhooks.push(this.hooks.addHooks(configHooks));
2091
2363
  }
2092
2364
  /**
2093
- * Runs each plugin's `kubb:plugin:setup` handler, in plugin order, with a context scoped to that
2365
+ * Runs each plugin's `setup` and `kubb:plugin:setup` handler, in plugin order, with a context scoped to that
2094
2366
  * plugin so `addGenerator`, `setResolver`, `addMacro`, `setMacros`, and `setOptions` target its
2095
2367
  * `NormalizedPlugin` entry. Called once from `run` before the plugin execution loop begins, so
2096
2368
  * plugins can configure generators, resolvers, macros, and options before `buildStart`.
2097
2369
  */
2098
2370
  async setupHooks() {
2099
2371
  for (const plugin of this.plugins.values()) {
2100
- const setup = plugin.hooks?.["kubb:plugin:setup"];
2101
- if (!setup) continue;
2372
+ const setupHook = plugin.hooks?.["kubb:plugin:setup"];
2373
+ if (!plugin.setup && !setupHook) continue;
2374
+ const ctx = {
2375
+ config: this.config,
2376
+ options: plugin.options ?? {},
2377
+ addGenerator: (...generators) => {
2378
+ plugin.generators = [...plugin.generators ?? [], ...generators];
2379
+ },
2380
+ setResolver: (resolver) => {
2381
+ plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
2382
+ },
2383
+ addMacro: (macro) => {
2384
+ this.#transforms.add(plugin.name, macro);
2385
+ },
2386
+ setMacros: (macros) => {
2387
+ this.#transforms.set(plugin.name, macros);
2388
+ },
2389
+ setOptions: (opts) => {
2390
+ plugin.options = normalizePluginOptions({
2391
+ ...plugin.options,
2392
+ ...opts
2393
+ }, plugin.name);
2394
+ },
2395
+ injectFile: (userFileNode) => {
2396
+ this.fileManager.add(_kubb_ast.ast.factory.createFile(userFileNode));
2397
+ },
2398
+ requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
2399
+ };
2102
2400
  try {
2103
- await setup({
2104
- config: this.config,
2105
- options: plugin.options ?? {},
2106
- addGenerator: (...generators) => {
2107
- plugin.generators = [...plugin.generators ?? [], ...generators];
2108
- },
2109
- setResolver: (resolver) => {
2110
- plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
2111
- },
2112
- addMacro: (macro) => {
2113
- this.#transforms.add(plugin.name, macro);
2114
- },
2115
- setMacros: (macros) => {
2116
- this.#transforms.set(plugin.name, macros);
2117
- },
2118
- setOptions: (opts) => {
2119
- plugin.options = normalizePluginOptions({
2120
- ...plugin.options,
2121
- ...opts
2122
- }, plugin.name);
2123
- },
2124
- injectFile: (userFileNode) => {
2125
- this.fileManager.add(_kubb_ast.ast.factory.createFile(userFileNode));
2126
- },
2127
- requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
2401
+ await kubbContext.run(ctx, async () => {
2402
+ if (plugin.setup) plugin.options = normalizePluginOptions(await plugin.setup(ctx.options, ctx), plugin.name);
2403
+ await setupHook?.(ctx);
2128
2404
  });
2129
2405
  } catch (caughtError) {
2130
2406
  const diagnostic = Diagnostics.from(caughtError);
@@ -2631,6 +2907,18 @@ Object.defineProperty(exports, "_usingCtx", {
2631
2907
  return _usingCtx;
2632
2908
  }
2633
2909
  });
2910
+ Object.defineProperty(exports, "addGenerator", {
2911
+ enumerable: true,
2912
+ get: function() {
2913
+ return addGenerator;
2914
+ }
2915
+ });
2916
+ Object.defineProperty(exports, "addMacro", {
2917
+ enumerable: true,
2918
+ get: function() {
2919
+ return addMacro;
2920
+ }
2921
+ });
2634
2922
  Object.defineProperty(exports, "assertPluginOption", {
2635
2923
  enumerable: true,
2636
2924
  get: function() {
@@ -2661,6 +2949,12 @@ Object.defineProperty(exports, "createResolver", {
2661
2949
  return createResolver;
2662
2950
  }
2663
2951
  });
2952
+ Object.defineProperty(exports, "defineExtension", {
2953
+ enumerable: true,
2954
+ get: function() {
2955
+ return defineExtension;
2956
+ }
2957
+ });
2664
2958
  Object.defineProperty(exports, "definePlugin", {
2665
2959
  enumerable: true,
2666
2960
  get: function() {
@@ -2697,12 +2991,24 @@ Object.defineProperty(exports, "inParallel", {
2697
2991
  return inParallel;
2698
2992
  }
2699
2993
  });
2994
+ Object.defineProperty(exports, "injectFile", {
2995
+ enumerable: true,
2996
+ get: function() {
2997
+ return injectFile;
2998
+ }
2999
+ });
2700
3000
  Object.defineProperty(exports, "isPathInside", {
2701
3001
  enumerable: true,
2702
3002
  get: function() {
2703
3003
  return isPathInside;
2704
3004
  }
2705
3005
  });
3006
+ Object.defineProperty(exports, "kubbContext", {
3007
+ enumerable: true,
3008
+ get: function() {
3009
+ return kubbContext;
3010
+ }
3011
+ });
2706
3012
  Object.defineProperty(exports, "pluginNotFoundError", {
2707
3013
  enumerable: true,
2708
3014
  get: function() {
@@ -2715,6 +3021,36 @@ Object.defineProperty(exports, "read", {
2715
3021
  return read;
2716
3022
  }
2717
3023
  });
3024
+ Object.defineProperty(exports, "requirePlugin", {
3025
+ enumerable: true,
3026
+ get: function() {
3027
+ return requirePlugin;
3028
+ }
3029
+ });
3030
+ Object.defineProperty(exports, "resolveMeta", {
3031
+ enumerable: true,
3032
+ get: function() {
3033
+ return resolveMeta;
3034
+ }
3035
+ });
3036
+ Object.defineProperty(exports, "setMacros", {
3037
+ enumerable: true,
3038
+ get: function() {
3039
+ return setMacros;
3040
+ }
3041
+ });
3042
+ Object.defineProperty(exports, "setOptions", {
3043
+ enumerable: true,
3044
+ get: function() {
3045
+ return setOptions;
3046
+ }
3047
+ });
3048
+ Object.defineProperty(exports, "setResolver", {
3049
+ enumerable: true,
3050
+ get: function() {
3051
+ return setResolver;
3052
+ }
3053
+ });
2718
3054
  Object.defineProperty(exports, "toError", {
2719
3055
  enumerable: true,
2720
3056
  get: function() {
@@ -2727,6 +3063,30 @@ Object.defineProperty(exports, "toPosixPath", {
2727
3063
  return toPosixPath;
2728
3064
  }
2729
3065
  });
3066
+ Object.defineProperty(exports, "tryUseKubb", {
3067
+ enumerable: true,
3068
+ get: function() {
3069
+ return tryUseKubb;
3070
+ }
3071
+ });
3072
+ Object.defineProperty(exports, "useConfig", {
3073
+ enumerable: true,
3074
+ get: function() {
3075
+ return useConfig;
3076
+ }
3077
+ });
3078
+ Object.defineProperty(exports, "useKubb", {
3079
+ enumerable: true,
3080
+ get: function() {
3081
+ return useKubb;
3082
+ }
3083
+ });
3084
+ Object.defineProperty(exports, "useOptions", {
3085
+ enumerable: true,
3086
+ get: function() {
3087
+ return useOptions;
3088
+ }
3089
+ });
2730
3090
  Object.defineProperty(exports, "write", {
2731
3091
  enumerable: true,
2732
3092
  get: function() {
@@ -2734,4 +3094,4 @@ Object.defineProperty(exports, "write", {
2734
3094
  }
2735
3095
  });
2736
3096
 
2737
- //# sourceMappingURL=KubbDriver-CVFm4dwb.cjs.map
3097
+ //# sourceMappingURL=KubbDriver-DXDTb9_c.cjs.map