@kubb/core 5.7.0 → 5.8.1

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.1";
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.7.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
@@ -949,11 +949,96 @@ var Diagnostics = class Diagnostics {
949
949
  }
950
950
  };
951
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 defineExtension({ kind, meta, build }) {
1025
+ const factory = (options) => build(options ?? {});
1026
+ return Object.assign(factory, meta ? {
1027
+ kind,
1028
+ meta
1029
+ } : { kind });
1030
+ }
1031
+ //#endregion
952
1032
  //#region src/composables.ts
1033
+ const kubbContextKey = Symbol.for("kubb.context");
1034
+ const host = globalThis;
953
1035
  /**
954
1036
  * Holds the setup context of the plugin whose `setup` or `kubb:plugin:setup` is running. `KubbDriver` sets it for each plugin.
1037
+ *
1038
+ * The store lives on `globalThis`, so the ESM and CommonJS builds of `@kubb/core` share one. A plugin that a
1039
+ * CommonJS config loads would otherwise read an empty store and fail with `KUBB_NO_CONTEXT`.
955
1040
  */
956
- const kubbContext = new node_async_hooks.AsyncLocalStorage();
1041
+ const kubbContext = host[kubbContextKey] ??= new node_async_hooks.AsyncLocalStorage();
957
1042
  function requireContext(caller) {
958
1043
  const ctx = kubbContext.getStore();
959
1044
  if (ctx) return ctx;
@@ -1035,86 +1120,6 @@ function requirePlugin(name) {
1035
1120
  return requireContext("requirePlugin").requirePlugin(name);
1036
1121
  }
1037
1122
  //#endregion
1038
- //#region src/defineExtension.ts
1039
- /**
1040
- * Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
1041
- */
1042
- function resolveMeta({ name, meta }) {
1043
- if (meta) return meta;
1044
- if (name) return { name };
1045
- throw new Diagnostics.Error({
1046
- code: Diagnostics.code.invalidPluginOptions,
1047
- severity: "error",
1048
- message: "An extension has neither `meta.name` nor `name`.",
1049
- help: "Set `meta: { name }` on the plugin or parser.",
1050
- location: { kind: "config" }
1051
- });
1052
- }
1053
- /**
1054
- * Throws `KUBB_INCOMPATIBLE_EXTENSION` when the running Kubb or Node.js version is outside `meta.compatibility`.
1055
- */
1056
- function checkCompatibility(meta) {
1057
- const checks = [{
1058
- target: "Kubb",
1059
- range: meta.compatibility?.kubb,
1060
- version
1061
- }, {
1062
- target: "Node.js",
1063
- range: meta.compatibility?.node,
1064
- version: process.versions.node
1065
- }];
1066
- for (const { target, range, version } of checks) {
1067
- if (!range || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
1068
- throw new Diagnostics.Error({
1069
- code: Diagnostics.code.incompatibleExtension,
1070
- severity: "error",
1071
- message: `"${meta.name}" requires ${target} ${range}, but ${version} is running.`,
1072
- help: `Use a ${target} version that satisfies ${range}, or a version of "${meta.name}" that supports ${target} ${version}.`,
1073
- location: { kind: "config" },
1074
- plugin: meta.name
1075
- });
1076
- }
1077
- }
1078
- /**
1079
- * Throws `KUBB_MISSING_DEPENDENCY` for a missing required entry in a `dependencies` record, and
1080
- * `KUBB_INCOMPATIBLE_DEPENDENCY` when an entry's `meta.version` is out of range. Arrays are not checked.
1081
- */
1082
- function checkDependencies({ name, dependencies, plugins }) {
1083
- if (!dependencies || Array.isArray(dependencies)) return;
1084
- for (const [dependencyName, dependency] of Object.entries(dependencies)) {
1085
- const target = plugins.get(dependencyName);
1086
- if (!target) {
1087
- if (dependency?.optional) continue;
1088
- throw new Diagnostics.Error({
1089
- code: Diagnostics.code.missingDependency,
1090
- severity: "error",
1091
- message: `Plugin "${dependencyName}" is required by "${name}" but not found.`,
1092
- help: `Add "${dependencyName}" to the \`plugins\` array in kubb.config.ts.`,
1093
- location: { kind: "config" },
1094
- plugin: name
1095
- });
1096
- }
1097
- const range = dependency?.version;
1098
- const version = target.meta?.version;
1099
- if (!range || !version || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
1100
- throw new Diagnostics.Error({
1101
- code: Diagnostics.code.incompatibleDependency,
1102
- severity: "error",
1103
- message: `"${name}" requires "${dependencyName}" ${range}, but ${version} is configured.`,
1104
- help: `Install a version of "${dependencyName}" that satisfies ${range}.`,
1105
- location: { kind: "config" },
1106
- plugin: name
1107
- });
1108
- }
1109
- }
1110
- function defineExtension({ kind, meta, build }) {
1111
- const factory = (options) => build(options ?? {});
1112
- return Object.assign(factory, meta ? {
1113
- kind,
1114
- meta
1115
- } : { kind });
1116
- }
1117
- //#endregion
1118
1123
  //#region src/definePlugin.ts
1119
1124
  /**
1120
1125
  * Merges the `output.mode` default into the output config and validates the combination.
@@ -1791,7 +1796,7 @@ var Hookable = class {
1791
1796
  }
1792
1797
  };
1793
1798
  //#endregion
1794
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/usingCtx.js
1799
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
1795
1800
  function _usingCtx() {
1796
1801
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
1797
1802
  var n = Error();
@@ -2215,14 +2220,14 @@ var KubbDriver = class {
2215
2220
  this.adapter = config.adapter ?? null;
2216
2221
  }
2217
2222
  /**
2218
- * Normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
2223
+ * Checks the adapter's and parsers' `meta.compatibility`, then normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
2219
2224
  * A plugin that another lists as a dependency runs first, then `enforce: 'pre'` before
2220
2225
  * `'post'`. When the config has an adapter, the adapter source is resolved from the input
2221
2226
  * so `run` can parse it later.
2222
2227
  */
2223
2228
  async setup() {
2224
2229
  this.options.signal?.throwIfAborted();
2225
- for (const parser of this.config.parsers) if (parser.meta) checkCompatibility(parser.meta);
2230
+ for (const extension of [this.config.adapter, ...this.config.parsers]) if (extension?.meta) checkCompatibility(extension.meta);
2226
2231
  const normalized = this.#sortPlugins(this.config.plugins.map((rawPlugin) => {
2227
2232
  if (rawPlugin.meta) checkCompatibility(rawPlugin.meta);
2228
2233
  const meta = resolveMeta(rawPlugin);
@@ -2877,6 +2882,12 @@ Object.defineProperty(exports, "camelCase", {
2877
2882
  return camelCase;
2878
2883
  }
2879
2884
  });
2885
+ Object.defineProperty(exports, "checkCompatibility", {
2886
+ enumerable: true,
2887
+ get: function() {
2888
+ return checkCompatibility;
2889
+ }
2890
+ });
2880
2891
  Object.defineProperty(exports, "clean", {
2881
2892
  enumerable: true,
2882
2893
  get: function() {
@@ -3040,4 +3051,4 @@ Object.defineProperty(exports, "write", {
3040
3051
  }
3041
3052
  });
3042
3053
 
3043
- //# sourceMappingURL=KubbDriver-BcoHguLM.cjs.map
3054
+ //# sourceMappingURL=KubbDriver-DQ7pt93q.cjs.map