@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.
@@ -4,6 +4,7 @@ import { styleText } from "node:util";
4
4
  import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
5
  import path, { dirname, isAbsolute, relative, resolve } from "node:path";
6
6
  import { ast, collectImportedRefNames, collectUsedSchemaNames, composeMacros, extractStringsFromNodes, operationDef, schemaDef, transform } from "@kubb/ast";
7
+ import { satisfies } from "verkit";
7
8
  import { EventEmitter } from "node:events";
8
9
  //#region ../../internals/utils/src/casing.ts
9
10
  /**
@@ -329,7 +330,7 @@ function formatMs(ms) {
329
330
  }
330
331
  //#endregion
331
332
  //#region package.json
332
- var version = "5.6.3";
333
+ var version = "5.8.0";
333
334
  //#endregion
334
335
  //#region src/constants.ts
335
336
  /**
@@ -385,6 +386,18 @@ const diagnosticCode = {
385
386
  */
386
387
  pluginNotFound: "KUBB_PLUGIN_NOT_FOUND",
387
388
  /**
389
+ * The running Kubb or Node.js version is outside a plugin's `meta.compatibility`.
390
+ */
391
+ incompatibleExtension: "KUBB_INCOMPATIBLE_EXTENSION",
392
+ /**
393
+ * A required entry in a plugin's `dependencies` record is missing from the config.
394
+ */
395
+ missingDependency: "KUBB_MISSING_DEPENDENCY",
396
+ /**
397
+ * A dependency's `meta.version` is outside the range a plugin's `dependencies` record declares.
398
+ */
399
+ incompatibleDependency: "KUBB_INCOMPATIBLE_DEPENDENCY",
400
+ /**
388
401
  * A plugin threw while generating.
389
402
  */
390
403
  pluginFailed: "KUBB_PLUGIN_FAILED",
@@ -397,6 +410,10 @@ const diagnosticCode = {
397
410
  */
398
411
  pluginInfo: "KUBB_PLUGIN_INFO",
399
412
  /**
413
+ * A `kubb/kit` composable was called outside a plugin's `setup` and `kubb:plugin:setup`.
414
+ */
415
+ noContext: "KUBB_NO_CONTEXT",
416
+ /**
400
417
  * A schema uses a `format` Kubb does not map to a specific type. Reserved for
401
418
  * adapters to emit as a `warning`.
402
419
  */
@@ -426,6 +443,10 @@ const diagnosticCode = {
426
443
  */
427
444
  invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS",
428
445
  /**
446
+ * An extension's options fail its options `schema`.
447
+ */
448
+ invalidOptions: "KUBB_INVALID_OPTIONS",
449
+ /**
429
450
  * A post-generate command (`output.postGenerate`) exited with a failure.
430
451
  */
431
452
  postGenerateFailed: "KUBB_POST_GENERATE_FAILED",
@@ -568,6 +589,21 @@ const diagnosticCatalog = {
568
589
  cause: "A plugin that another plugin depends on is missing from the config.",
569
590
  fix: "Add the required plugin to the `plugins` array in kubb.config.ts, or remove the dependency on it."
570
591
  },
592
+ [diagnosticCode.incompatibleExtension]: {
593
+ title: "Incompatible extension",
594
+ cause: "A plugin sets `meta.compatibility.kubb` or `meta.compatibility.node` to a range the running Kubb or Node.js version does not satisfy.",
595
+ 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."
596
+ },
597
+ [diagnosticCode.missingDependency]: {
598
+ title: "Missing dependency",
599
+ cause: "A plugin lists another plugin in its `dependencies` record without `optional: true`, and the config does not include it.",
600
+ fix: "Add the missing plugin to the `plugins` array in kubb.config.ts."
601
+ },
602
+ [diagnosticCode.incompatibleDependency]: {
603
+ title: "Incompatible dependency",
604
+ cause: "A plugin's `dependencies` record sets a `version` range, and the configured plugin's `meta.version` falls outside it.",
605
+ fix: "Install a version of the dependency inside the range, or a version of the dependent plugin that supports the installed dependency."
606
+ },
571
607
  [diagnosticCode.pluginFailed]: {
572
608
  title: "Plugin failed",
573
609
  cause: "A plugin threw while generating, or reported an error through `ctx.error`.",
@@ -583,6 +619,11 @@ const diagnosticCatalog = {
583
619
  cause: "A plugin reported an informational message through `ctx.info`.",
584
620
  fix: "Informational only. No action is required."
585
621
  },
622
+ [diagnosticCode.noContext]: {
623
+ title: "No plugin context",
624
+ 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.",
625
+ fix: "Call the composable inside `setup` or `kubb:plugin:setup`, including in code that setup awaits."
626
+ },
586
627
  [diagnosticCode.unsupportedFormat]: {
587
628
  title: "Unsupported format",
588
629
  cause: "A schema uses a `format` Kubb does not map to a specific type, so it falls back to the base type.",
@@ -613,6 +654,11 @@ const diagnosticCatalog = {
613
654
  cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
614
655
  fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or use `output.mode: 'directory'`."
615
656
  },
657
+ [diagnosticCode.invalidOptions]: {
658
+ title: "Invalid options",
659
+ cause: "A plugin declares an options `schema`, and the options passed to it in kubb.config.ts do not match it.",
660
+ fix: "Fix each option the message lists by its path, such as `enum.type`. The plugin documentation lists the accepted values."
661
+ },
616
662
  [diagnosticCode.postGenerateFailed]: {
617
663
  title: "Post-generate command failed",
618
664
  cause: "A post-generate command (`output.postGenerate`) exited with a non-zero status.",
@@ -886,6 +932,214 @@ var Diagnostics = class Diagnostics {
886
932
  }
887
933
  };
888
934
  //#endregion
935
+ //#region src/composables.ts
936
+ const kubbContextKey = Symbol.for("kubb.context");
937
+ const host = globalThis;
938
+ /**
939
+ * Holds the setup context of the plugin whose `setup` or `kubb:plugin:setup` is running. `KubbDriver` sets it for each plugin.
940
+ *
941
+ * The store lives on `globalThis`, so the ESM and CommonJS builds of `@kubb/core` share one. A plugin that a
942
+ * CommonJS config loads would otherwise read an empty store and fail with `KUBB_NO_CONTEXT`.
943
+ */
944
+ const kubbContext = host[kubbContextKey] ??= new AsyncLocalStorage();
945
+ function requireContext(caller) {
946
+ const ctx = kubbContext.getStore();
947
+ if (ctx) return ctx;
948
+ throw new Diagnostics.Error({
949
+ code: Diagnostics.code.noContext,
950
+ severity: "error",
951
+ message: `\`${caller}()\` was called outside a plugin setup.`,
952
+ help: `Call \`${caller}()\` inside \`setup\` or \`kubb:plugin:setup\`, including in code that setup awaits.`
953
+ });
954
+ }
955
+ /**
956
+ * Returns the context of the plugin whose `kubb:plugin:setup` is running. It stays available after an `await`.
957
+ * Throws `KUBB_NO_CONTEXT` outside setup.
958
+ */
959
+ function useKubb() {
960
+ return requireContext("useKubb");
961
+ }
962
+ /**
963
+ * Returns the same context as {@link useKubb}, or `undefined` outside `setup` and `kubb:plugin:setup`.
964
+ */
965
+ function tryUseKubb() {
966
+ return kubbContext.getStore();
967
+ }
968
+ /**
969
+ * Registers generators on the plugin being set up, like `ctx.addGenerator`.
970
+ *
971
+ * @example
972
+ * `addGenerator(typeGenerator, enumGenerator)`
973
+ */
974
+ function addGenerator(...generators) {
975
+ requireContext("addGenerator").addGenerator(...generators);
976
+ }
977
+ /**
978
+ * Sets the resolver of the plugin being set up, like `ctx.setResolver`.
979
+ */
980
+ function setResolver(resolver) {
981
+ requireContext("setResolver").setResolver(resolver);
982
+ }
983
+ /**
984
+ * Adds a macro to the plugin being set up, like `ctx.addMacro`.
985
+ */
986
+ function addMacro(macro) {
987
+ requireContext("addMacro").addMacro(macro);
988
+ }
989
+ /**
990
+ * Replaces the macros of the plugin being set up, like `ctx.setMacros`.
991
+ */
992
+ function setMacros(macros) {
993
+ requireContext("setMacros").setMacros(macros);
994
+ }
995
+ /**
996
+ * Adds a raw file to the build output, like `ctx.injectFile`.
997
+ */
998
+ function injectFile(file) {
999
+ requireContext("injectFile").injectFile(file);
1000
+ }
1001
+ /**
1002
+ * Returns the options of the plugin being set up, parsed by its options `schema` when it has one, like `ctx.options`.
1003
+ */
1004
+ function useOptions() {
1005
+ return requireContext("useOptions").options;
1006
+ }
1007
+ /**
1008
+ * Sets the resolved options of the plugin being set up, like `ctx.setOptions`.
1009
+ */
1010
+ function setOptions(options) {
1011
+ requireContext("setOptions").setOptions(options);
1012
+ }
1013
+ /**
1014
+ * Returns the resolved build configuration, like `ctx.config`.
1015
+ */
1016
+ function useConfig() {
1017
+ return requireContext("useConfig").config;
1018
+ }
1019
+ /**
1020
+ * Returns another plugin from the config, typed through `Kubb.PluginRegistry`, like `ctx.requirePlugin`.
1021
+ */
1022
+ function requirePlugin(name) {
1023
+ return requireContext("requirePlugin").requirePlugin(name);
1024
+ }
1025
+ //#endregion
1026
+ //#region src/defineExtension.ts
1027
+ /**
1028
+ * Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
1029
+ */
1030
+ function resolveMeta({ name, meta }) {
1031
+ if (meta) return meta;
1032
+ if (name) return { name };
1033
+ throw new Diagnostics.Error({
1034
+ code: Diagnostics.code.invalidPluginOptions,
1035
+ severity: "error",
1036
+ message: "An extension has neither `meta.name` nor `name`.",
1037
+ help: "Set `meta: { name }` on the plugin or parser.",
1038
+ location: { kind: "config" }
1039
+ });
1040
+ }
1041
+ /**
1042
+ * Throws `KUBB_INCOMPATIBLE_EXTENSION` when the running Kubb or Node.js version is outside `meta.compatibility`.
1043
+ */
1044
+ function checkCompatibility(meta) {
1045
+ const checks = [{
1046
+ target: "Kubb",
1047
+ range: meta.compatibility?.kubb,
1048
+ version
1049
+ }, {
1050
+ target: "Node.js",
1051
+ range: meta.compatibility?.node,
1052
+ version: process.versions.node
1053
+ }];
1054
+ for (const { target, range, version } of checks) {
1055
+ if (!range || satisfies(version, range, { includePrerelease: true })) continue;
1056
+ throw new Diagnostics.Error({
1057
+ code: Diagnostics.code.incompatibleExtension,
1058
+ severity: "error",
1059
+ message: `"${meta.name}" requires ${target} ${range}, but ${version} is running.`,
1060
+ help: `Use a ${target} version that satisfies ${range}, or a version of "${meta.name}" that supports ${target} ${version}.`,
1061
+ location: { kind: "config" },
1062
+ plugin: meta.name
1063
+ });
1064
+ }
1065
+ }
1066
+ /**
1067
+ * Throws `KUBB_MISSING_DEPENDENCY` for a missing required entry in a `dependencies` record, and
1068
+ * `KUBB_INCOMPATIBLE_DEPENDENCY` when an entry's `meta.version` is out of range. Arrays are not checked.
1069
+ */
1070
+ function checkDependencies({ name, dependencies, plugins }) {
1071
+ if (!dependencies || Array.isArray(dependencies)) return;
1072
+ for (const [dependencyName, dependency] of Object.entries(dependencies)) {
1073
+ const target = plugins.get(dependencyName);
1074
+ if (!target) {
1075
+ if (dependency?.optional) continue;
1076
+ throw new Diagnostics.Error({
1077
+ code: Diagnostics.code.missingDependency,
1078
+ severity: "error",
1079
+ message: `Plugin "${dependencyName}" is required by "${name}" but not found.`,
1080
+ help: `Add "${dependencyName}" to the \`plugins\` array in kubb.config.ts.`,
1081
+ location: { kind: "config" },
1082
+ plugin: name
1083
+ });
1084
+ }
1085
+ const range = dependency?.version;
1086
+ const version = target.meta?.version;
1087
+ if (!range || !version || satisfies(version, range, { includePrerelease: true })) continue;
1088
+ throw new Diagnostics.Error({
1089
+ code: Diagnostics.code.incompatibleDependency,
1090
+ severity: "error",
1091
+ message: `"${name}" requires "${dependencyName}" ${range}, but ${version} is configured.`,
1092
+ help: `Install a version of "${dependencyName}" that satisfies ${range}.`,
1093
+ location: { kind: "config" },
1094
+ plugin: name
1095
+ });
1096
+ }
1097
+ }
1098
+ function formatIssuePath(path) {
1099
+ return (path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
1100
+ }
1101
+ /**
1102
+ * Validates an extension's raw options against its `schema` and returns the parsed value, with the schema's defaults.
1103
+ * Throws `KUBB_INVALID_OPTIONS`, naming the extension and each issue path, when the options are invalid.
1104
+ * Refuses an async validator, because extension factories run synchronously while the config loads.
1105
+ */
1106
+ function parseExtensionOptions({ kind, meta, schema, input }) {
1107
+ const validated = schema["~standard"].validate(input);
1108
+ if (typeof validated.then === "function") {
1109
+ Promise.resolve(validated).catch(() => void 0);
1110
+ throw new Error(`The options schema of ${kind} "${meta.name}" validates asynchronously. Use a synchronous schema, because Kubb validates options while the config loads.`);
1111
+ }
1112
+ const result = validated;
1113
+ if (!result.issues) return result.value;
1114
+ const issues = result.issues.map((issue) => {
1115
+ const path = formatIssuePath(issue.path);
1116
+ return path ? `\`${path}\`: ${issue.message}` : issue.message;
1117
+ });
1118
+ throw new Diagnostics.Error({
1119
+ code: Diagnostics.code.invalidOptions,
1120
+ severity: "error",
1121
+ message: `Invalid options for ${kind} "${meta.name}". ${issues.join("; ")}`,
1122
+ help: `Fix the listed options of "${meta.name}" in kubb.config.ts. Its documentation lists the accepted values.`,
1123
+ location: { kind: "config" },
1124
+ ...kind === "plugin" && { plugin: meta.name }
1125
+ });
1126
+ }
1127
+ function defineExtension({ kind, meta, schema, build }) {
1128
+ const factory = (raw) => {
1129
+ const options = raw ?? {};
1130
+ return build({
1131
+ options,
1132
+ parsedOptions: schema && meta ? parseExtensionOptions({
1133
+ kind,
1134
+ meta,
1135
+ schema,
1136
+ input: options
1137
+ }) : options
1138
+ });
1139
+ };
1140
+ return Object.assign(factory, { kind }, meta && { meta }, schema && { schema });
1141
+ }
1142
+ //#endregion
889
1143
  //#region src/definePlugin.ts
890
1144
  /**
891
1145
  * Merges the `output.mode` default into the output config and validates the combination.
@@ -925,30 +1179,33 @@ function assertPluginOption({ plugin, option, value, allowed }) {
925
1179
  plugin
926
1180
  });
927
1181
  }
928
- /**
929
- * Wraps a plugin factory and returns a function that accepts user options and
930
- * yields a typed `Plugin`. Lifecycle handlers go inside a single `hooks` object.
931
- *
932
- * Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
933
- * `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
934
- * convention (`plugin-react-query`, `plugin-zod`, ...).
935
- *
936
- * @example
937
- * ```ts
938
- * import { definePlugin } from '@kubb/core'
939
- *
940
- * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
941
- * name: 'plugin-ts',
942
- * hooks: {
943
- * 'kubb:plugin:setup'(ctx) {
944
- * ctx.setResolver(resolverTs)
945
- * },
946
- * },
947
- * }))
948
- * ```
949
- */
950
- function definePlugin(factory) {
951
- return (options) => factory(options ?? {});
1182
+ function definePlugin(input) {
1183
+ if (typeof input === "function") return defineExtension({
1184
+ kind: "plugin",
1185
+ build: ({ options }) => {
1186
+ const plugin = input(options);
1187
+ return {
1188
+ ...plugin,
1189
+ meta: resolveMeta(plugin)
1190
+ };
1191
+ }
1192
+ });
1193
+ const { meta, schema, dependencies, enforce, hooks = {}, setup } = input;
1194
+ return defineExtension({
1195
+ kind: "plugin",
1196
+ meta,
1197
+ schema,
1198
+ build: ({ options, parsedOptions }) => ({
1199
+ name: meta.name,
1200
+ meta,
1201
+ options,
1202
+ ...schema && { parsedOptions },
1203
+ dependencies,
1204
+ enforce,
1205
+ hooks,
1206
+ setup
1207
+ })
1208
+ });
952
1209
  }
953
1210
  //#endregion
954
1211
  //#region src/input.ts
@@ -1561,7 +1818,7 @@ var Hookable = class {
1561
1818
  }
1562
1819
  };
1563
1820
  //#endregion
1564
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/usingCtx.js
1821
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
1565
1822
  function _usingCtx() {
1566
1823
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
1567
1824
  var n = Error();
@@ -1985,23 +2242,35 @@ var KubbDriver = class {
1985
2242
  this.adapter = config.adapter ?? null;
1986
2243
  }
1987
2244
  /**
1988
- * Normalizes every configured plugin, orders them, and registers their lifecycle handlers.
2245
+ * Normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
1989
2246
  * A plugin that another lists as a dependency runs first, then `enforce: 'pre'` before
1990
2247
  * `'post'`. When the config has an adapter, the adapter source is resolved from the input
1991
2248
  * so `run` can parse it later.
1992
2249
  */
1993
2250
  async setup() {
1994
2251
  this.options.signal?.throwIfAborted();
2252
+ for (const parser of this.config.parsers) if (parser.meta) checkCompatibility(parser.meta);
1995
2253
  const normalized = this.#sortPlugins(this.config.plugins.map((rawPlugin) => {
2254
+ if (rawPlugin.meta) checkCompatibility(rawPlugin.meta);
2255
+ const meta = resolveMeta(rawPlugin);
2256
+ const options = rawPlugin.parsedOptions ?? rawPlugin.options;
1996
2257
  return {
1997
- name: rawPlugin.name,
1998
- dependencies: rawPlugin.dependencies,
2258
+ name: meta.name,
2259
+ meta,
2260
+ dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(options ?? {}, { config: this.config }) : rawPlugin.dependencies,
1999
2261
  enforce: rawPlugin.enforce,
2000
2262
  hooks: rawPlugin.hooks,
2001
- options: rawPlugin.options ?? defaultPluginOptions(),
2002
- resolver: createResolver({ pluginName: rawPlugin.name })
2263
+ setup: rawPlugin.setup,
2264
+ options: options ?? defaultPluginOptions(),
2265
+ resolver: createResolver({ pluginName: meta.name })
2003
2266
  };
2004
2267
  }));
2268
+ const byName = new Map(normalized.map((plugin) => [plugin.name, plugin]));
2269
+ for (const plugin of normalized) checkDependencies({
2270
+ name: plugin.name,
2271
+ dependencies: plugin.dependencies,
2272
+ plugins: byName
2273
+ });
2005
2274
  for (const plugin of normalized) {
2006
2275
  this.#registerPlugin(plugin);
2007
2276
  this.plugins.set(plugin.name, plugin);
@@ -2019,7 +2288,10 @@ var KubbDriver = class {
2019
2288
  #sortPlugins(plugins) {
2020
2289
  const queue = [...plugins].sort((a, b) => enforceWeight(a) - enforceWeight(b));
2021
2290
  const names = new Set(queue.map((plugin) => plugin.name));
2022
- const blockedBy = new Map(queue.map((plugin) => [plugin.name, new Set(plugin.dependencies?.filter((name) => names.has(name) && name !== plugin.name))]));
2291
+ const blockedBy = new Map(queue.map((plugin) => {
2292
+ const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
2293
+ return [plugin.name, new Set(dependencies.filter((name) => names.has(name) && name !== plugin.name))];
2294
+ }));
2023
2295
  const sorted = [];
2024
2296
  for (const _ of plugins) {
2025
2297
  const index = queue.findIndex((plugin) => blockedBy.get(plugin.name)?.size === 0);
@@ -2064,41 +2336,45 @@ var KubbDriver = class {
2064
2336
  this.#unhooks.push(this.hooks.addHooks(configHooks));
2065
2337
  }
2066
2338
  /**
2067
- * Runs each plugin's `kubb:plugin:setup` handler, in plugin order, with a context scoped to that
2339
+ * Runs each plugin's `setup` and `kubb:plugin:setup` handler, in plugin order, with a context scoped to that
2068
2340
  * plugin so `addGenerator`, `setResolver`, `addMacro`, `setMacros`, and `setOptions` target its
2069
2341
  * `NormalizedPlugin` entry. Called once from `run` before the plugin execution loop begins, so
2070
2342
  * plugins can configure generators, resolvers, macros, and options before `buildStart`.
2071
2343
  */
2072
2344
  async setupHooks() {
2073
2345
  for (const plugin of this.plugins.values()) {
2074
- const setup = plugin.hooks?.["kubb:plugin:setup"];
2075
- if (!setup) continue;
2346
+ const setupHook = plugin.hooks?.["kubb:plugin:setup"];
2347
+ if (!plugin.setup && !setupHook) continue;
2348
+ const ctx = {
2349
+ config: this.config,
2350
+ options: plugin.options ?? {},
2351
+ addGenerator: (...generators) => {
2352
+ plugin.generators = [...plugin.generators ?? [], ...generators];
2353
+ },
2354
+ setResolver: (resolver) => {
2355
+ plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
2356
+ },
2357
+ addMacro: (macro) => {
2358
+ this.#transforms.add(plugin.name, macro);
2359
+ },
2360
+ setMacros: (macros) => {
2361
+ this.#transforms.set(plugin.name, macros);
2362
+ },
2363
+ setOptions: (opts) => {
2364
+ plugin.options = normalizePluginOptions({
2365
+ ...plugin.options,
2366
+ ...opts
2367
+ }, plugin.name);
2368
+ },
2369
+ injectFile: (userFileNode) => {
2370
+ this.fileManager.add(ast.factory.createFile(userFileNode));
2371
+ },
2372
+ requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
2373
+ };
2076
2374
  try {
2077
- await setup({
2078
- config: this.config,
2079
- options: plugin.options ?? {},
2080
- addGenerator: (...generators) => {
2081
- plugin.generators = [...plugin.generators ?? [], ...generators];
2082
- },
2083
- setResolver: (resolver) => {
2084
- plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
2085
- },
2086
- addMacro: (macro) => {
2087
- this.#transforms.add(plugin.name, macro);
2088
- },
2089
- setMacros: (macros) => {
2090
- this.#transforms.set(plugin.name, macros);
2091
- },
2092
- setOptions: (opts) => {
2093
- plugin.options = normalizePluginOptions({
2094
- ...plugin.options,
2095
- ...opts
2096
- }, plugin.name);
2097
- },
2098
- injectFile: (userFileNode) => {
2099
- this.fileManager.add(ast.factory.createFile(userFileNode));
2100
- },
2101
- requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
2375
+ await kubbContext.run(ctx, async () => {
2376
+ if (plugin.setup) plugin.options = normalizePluginOptions(await plugin.setup(ctx.options, ctx), plugin.name);
2377
+ await setupHook?.(ctx);
2102
2378
  });
2103
2379
  } catch (caughtError) {
2104
2380
  const diagnostic = Diagnostics.from(caughtError);
@@ -2557,6 +2833,6 @@ function pluginNotFoundError({ pluginName, requiredBy }) {
2557
2833
  });
2558
2834
  }
2559
2835
  //#endregion
2560
- export { camelCase as C, toError as S, exists as _, _usingCtx as a, toPosixPath as b, Resolver as c, definePlugin as d, Diagnostics as f, clean as g, inParallel as h, FileManager as i, getInputKind as l, getElapsedMs as m, pluginNotFoundError as n, Hookable as o, formatMs as p, createNodeCache as r, createResolver as s, KubbDriver as t, assertPluginOption as u, isPathInside as v, write as x, read as y };
2836
+ export { clean as A, useConfig as C, formatMs as D, Diagnostics as E, write as F, toError as I, camelCase as L, isPathInside as M, read as N, getElapsedMs as O, toPosixPath as P, tryUseKubb as S, useOptions as T, kubbContext as _, _usingCtx as a, setOptions as b, Resolver as c, definePlugin as d, defineExtension as f, injectFile as g, addMacro as h, FileManager as i, exists as j, inParallel as k, getInputKind as l, addGenerator as m, pluginNotFoundError as n, Hookable as o, resolveMeta as p, createNodeCache as r, createResolver as s, KubbDriver as t, assertPluginOption as u, requirePlugin as v, useKubb as w, setResolver as x, setMacros as y };
2561
2837
 
2562
- //# sourceMappingURL=KubbDriver-BZBnKODj.js.map
2838
+ //# sourceMappingURL=KubbDriver-BrltQ0nL.js.map