@kubb/core 5.8.0 → 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.
@@ -24,14 +24,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
+ let verkit = require("verkit");
27
28
  let node_async_hooks = require("node:async_hooks");
28
29
  let node_util = require("node:util");
29
30
  let node_fs_promises = require("node:fs/promises");
30
31
  let node_path = require("node:path");
31
32
  node_path = __toESM(node_path, 1);
32
33
  let _kubb_ast = require("@kubb/ast");
33
- let verkit = require("verkit");
34
34
  let node_events = require("node:events");
35
+ //#region package.json
36
+ var version = "5.8.2";
37
+ //#endregion
35
38
  //#region ../../internals/utils/src/casing.ts
36
39
  /**
37
40
  * Shared implementation for camelCase and PascalCase conversion.
@@ -355,9 +358,6 @@ function formatMs(ms) {
355
358
  return `${Math.round(ms)}ms`;
356
359
  }
357
360
  //#endregion
358
- //#region package.json
359
- var version = "5.8.0";
360
- //#endregion
361
361
  //#region src/constants.ts
362
362
  /**
363
363
  * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode
@@ -469,10 +469,6 @@ const diagnosticCode = {
469
469
  */
470
470
  invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS",
471
471
  /**
472
- * An extension's options fail its options `schema`.
473
- */
474
- invalidOptions: "KUBB_INVALID_OPTIONS",
475
- /**
476
472
  * A post-generate command (`output.postGenerate`) exited with a failure.
477
473
  */
478
474
  postGenerateFailed: "KUBB_POST_GENERATE_FAILED",
@@ -680,11 +676,6 @@ const diagnosticCatalog = {
680
676
  cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
681
677
  fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or use `output.mode: 'directory'`."
682
678
  },
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
- },
688
679
  [diagnosticCode.postGenerateFailed]: {
689
680
  title: "Post-generate command failed",
690
681
  cause: "A post-generate command (`output.postGenerate`) exited with a non-zero status.",
@@ -958,6 +949,134 @@ var Diagnostics = class Diagnostics {
958
949
  }
959
950
  };
960
951
  //#endregion
952
+ //#region src/defineExtension.ts
953
+ /**
954
+ * Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
955
+ */
956
+ function resolveMeta({ name, meta }) {
957
+ if (meta) return meta;
958
+ if (name) return { name };
959
+ throw new Diagnostics.Error({
960
+ code: Diagnostics.code.invalidPluginOptions,
961
+ severity: "error",
962
+ message: "An extension has neither `meta.name` nor `name`.",
963
+ help: "Set `meta: { name }` on the plugin or parser.",
964
+ location: { kind: "config" }
965
+ });
966
+ }
967
+ /**
968
+ * Throws `KUBB_INCOMPATIBLE_EXTENSION` when the running Kubb or Node.js version is outside `meta.compatibility`.
969
+ */
970
+ function checkCompatibility(meta) {
971
+ const checks = [{
972
+ target: "Kubb",
973
+ range: meta.compatibility?.kubb,
974
+ version
975
+ }, {
976
+ target: "Node.js",
977
+ range: meta.compatibility?.node,
978
+ version: process.versions.node
979
+ }];
980
+ for (const { target, range, version } of checks) {
981
+ if (!range || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
982
+ throw new Diagnostics.Error({
983
+ code: Diagnostics.code.incompatibleExtension,
984
+ severity: "error",
985
+ message: `"${meta.name}" requires ${target} ${range}, but ${version} is running.`,
986
+ help: `Use a ${target} version that satisfies ${range}, or a version of "${meta.name}" that supports ${target} ${version}.`,
987
+ location: { kind: "config" },
988
+ plugin: meta.name
989
+ });
990
+ }
991
+ }
992
+ /**
993
+ * Throws `KUBB_MISSING_DEPENDENCY` for a missing required entry in a `dependencies` record, and
994
+ * `KUBB_INCOMPATIBLE_DEPENDENCY` when an entry's `meta.version` is out of range. Arrays are not checked.
995
+ */
996
+ function checkDependencies({ name, dependencies, plugins }) {
997
+ if (!dependencies || Array.isArray(dependencies)) return;
998
+ for (const [dependencyName, dependency] of Object.entries(dependencies)) {
999
+ const target = plugins.get(dependencyName);
1000
+ if (!target) {
1001
+ if (dependency?.optional) continue;
1002
+ throw new Diagnostics.Error({
1003
+ code: Diagnostics.code.missingDependency,
1004
+ severity: "error",
1005
+ message: `Plugin "${dependencyName}" is required by "${name}" but not found.`,
1006
+ help: `Add "${dependencyName}" to the \`plugins\` array in kubb.config.ts.`,
1007
+ location: { kind: "config" },
1008
+ plugin: name
1009
+ });
1010
+ }
1011
+ const range = dependency?.version;
1012
+ const version = target.meta?.version;
1013
+ if (!range || !version || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
1014
+ throw new Diagnostics.Error({
1015
+ code: Diagnostics.code.incompatibleDependency,
1016
+ severity: "error",
1017
+ message: `"${name}" requires "${dependencyName}" ${range}, but ${version} is configured.`,
1018
+ help: `Install a version of "${dependencyName}" that satisfies ${range}.`,
1019
+ location: { kind: "config" },
1020
+ plugin: name
1021
+ });
1022
+ }
1023
+ }
1024
+ function createExtensionFactory({ kind, meta, build }) {
1025
+ const factory = (options) => build(options ?? {});
1026
+ return Object.assign(factory, meta ? {
1027
+ kind,
1028
+ meta
1029
+ } : { kind });
1030
+ }
1031
+ function defineExtension(definition) {
1032
+ switch (definition.kind) {
1033
+ case "plugin": {
1034
+ const { meta, dependencies, enforce, hooks = {}, setup } = definition;
1035
+ return createExtensionFactory({
1036
+ kind: "plugin",
1037
+ meta,
1038
+ build: (options) => ({
1039
+ name: meta.name,
1040
+ meta,
1041
+ options,
1042
+ dependencies,
1043
+ enforce,
1044
+ hooks,
1045
+ setup
1046
+ })
1047
+ });
1048
+ }
1049
+ case "adapter": {
1050
+ const { meta, setup, build } = definition;
1051
+ return createExtensionFactory({
1052
+ kind: "adapter",
1053
+ meta,
1054
+ build: (raw) => {
1055
+ const options = setup ? setup(raw) : raw;
1056
+ return Object.assign(build(options), {
1057
+ name: meta.name,
1058
+ meta,
1059
+ options
1060
+ });
1061
+ }
1062
+ });
1063
+ }
1064
+ case "parser": {
1065
+ const { meta, build } = definition;
1066
+ return createExtensionFactory({
1067
+ kind: "parser",
1068
+ meta,
1069
+ build: (options) => ({
1070
+ ...build(options),
1071
+ name: meta.name,
1072
+ meta,
1073
+ options
1074
+ })
1075
+ });
1076
+ }
1077
+ }
1078
+ }
1079
+ //#endregion
961
1080
  //#region src/composables.ts
962
1081
  const kubbContextKey = Symbol.for("kubb.context");
963
1082
  const host = globalThis;
@@ -1025,7 +1144,7 @@ function injectFile(file) {
1025
1144
  requireContext("injectFile").injectFile(file);
1026
1145
  }
1027
1146
  /**
1028
- * Returns the options of the plugin being set up, parsed by its options `schema` when it has one, like `ctx.options`.
1147
+ * Returns the options the user passed to the plugin being set up, like `ctx.options`.
1029
1148
  */
1030
1149
  function useOptions() {
1031
1150
  return requireContext("useOptions").options;
@@ -1049,123 +1168,6 @@ function requirePlugin(name) {
1049
1168
  return requireContext("requirePlugin").requirePlugin(name);
1050
1169
  }
1051
1170
  //#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
1169
1171
  //#region src/definePlugin.ts
1170
1172
  /**
1171
1173
  * Merges the `output.mode` default into the output config and validates the combination.
@@ -1206,9 +1208,9 @@ function assertPluginOption({ plugin, option, value, allowed }) {
1206
1208
  });
1207
1209
  }
1208
1210
  function definePlugin(input) {
1209
- if (typeof input === "function") return defineExtension({
1211
+ if (typeof input === "function") return createExtensionFactory({
1210
1212
  kind: "plugin",
1211
- build: ({ options }) => {
1213
+ build: (options) => {
1212
1214
  const plugin = input(options);
1213
1215
  return {
1214
1216
  ...plugin,
@@ -1216,21 +1218,9 @@ function definePlugin(input) {
1216
1218
  };
1217
1219
  }
1218
1220
  });
1219
- const { meta, schema, dependencies, enforce, hooks = {}, setup } = input;
1220
1221
  return defineExtension({
1221
1222
  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
- })
1223
+ ...input
1234
1224
  });
1235
1225
  }
1236
1226
  //#endregion
@@ -2268,26 +2258,25 @@ var KubbDriver = class {
2268
2258
  this.adapter = config.adapter ?? null;
2269
2259
  }
2270
2260
  /**
2271
- * Normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
2261
+ * Checks the adapter's and parsers' `meta.compatibility`, then normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
2272
2262
  * A plugin that another lists as a dependency runs first, then `enforce: 'pre'` before
2273
2263
  * `'post'`. When the config has an adapter, the adapter source is resolved from the input
2274
2264
  * so `run` can parse it later.
2275
2265
  */
2276
2266
  async setup() {
2277
2267
  this.options.signal?.throwIfAborted();
2278
- for (const parser of this.config.parsers) if (parser.meta) checkCompatibility(parser.meta);
2268
+ for (const extension of [this.config.adapter, ...this.config.parsers]) if (extension?.meta) checkCompatibility(extension.meta);
2279
2269
  const normalized = this.#sortPlugins(this.config.plugins.map((rawPlugin) => {
2280
2270
  if (rawPlugin.meta) checkCompatibility(rawPlugin.meta);
2281
2271
  const meta = resolveMeta(rawPlugin);
2282
- const options = rawPlugin.parsedOptions ?? rawPlugin.options;
2283
2272
  return {
2284
2273
  name: meta.name,
2285
2274
  meta,
2286
- dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(options ?? {}, { config: this.config }) : rawPlugin.dependencies,
2275
+ dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(rawPlugin.options ?? {}, { config: this.config }) : rawPlugin.dependencies,
2287
2276
  enforce: rawPlugin.enforce,
2288
2277
  hooks: rawPlugin.hooks,
2289
2278
  setup: rawPlugin.setup,
2290
- options: options ?? defaultPluginOptions(),
2279
+ options: rawPlugin.options ?? defaultPluginOptions(),
2291
2280
  resolver: createResolver({ pluginName: meta.name })
2292
2281
  };
2293
2282
  }));
@@ -2931,12 +2920,24 @@ Object.defineProperty(exports, "camelCase", {
2931
2920
  return camelCase;
2932
2921
  }
2933
2922
  });
2923
+ Object.defineProperty(exports, "checkCompatibility", {
2924
+ enumerable: true,
2925
+ get: function() {
2926
+ return checkCompatibility;
2927
+ }
2928
+ });
2934
2929
  Object.defineProperty(exports, "clean", {
2935
2930
  enumerable: true,
2936
2931
  get: function() {
2937
2932
  return clean;
2938
2933
  }
2939
2934
  });
2935
+ Object.defineProperty(exports, "createExtensionFactory", {
2936
+ enumerable: true,
2937
+ get: function() {
2938
+ return createExtensionFactory;
2939
+ }
2940
+ });
2940
2941
  Object.defineProperty(exports, "createNodeCache", {
2941
2942
  enumerable: true,
2942
2943
  get: function() {
@@ -3094,4 +3095,4 @@ Object.defineProperty(exports, "write", {
3094
3095
  }
3095
3096
  });
3096
3097
 
3097
- //# sourceMappingURL=KubbDriver-DXDTb9_c.cjs.map
3098
+ //# sourceMappingURL=KubbDriver-DxWuvJWV.cjs.map