@kubb/core 5.8.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.
- package/dist/{KubbDriver-DXDTb9_c.cjs → KubbDriver-DQ7pt93q.cjs} +99 -142
- package/dist/KubbDriver-DQ7pt93q.cjs.map +1 -0
- package/dist/{KubbDriver-BrltQ0nL.js → KubbDriver-Dz36Klt9.js} +95 -144
- package/dist/KubbDriver-Dz36Klt9.js.map +1 -0
- package/dist/{types-anBcq2U0.d.ts → createAdapter-BO_AxI05.d.ts} +1673 -1698
- package/dist/index.cjs +170 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +144 -5
- package/dist/index.js +166 -63
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.js +2 -2
- package/dist/{rolldown-runtime-C0LytTxp.js → rolldown-runtime-CRm0XQPb.js} +1 -0
- package/package.json +3 -2
- package/schemas/kubb-extension.json +168 -0
- package/dist/KubbDriver-BrltQ0nL.js.map +0 -1
- package/dist/KubbDriver-DXDTb9_c.cjs.map +0 -1
|
@@ -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.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,86 @@ 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 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
|
|
961
1032
|
//#region src/composables.ts
|
|
962
1033
|
const kubbContextKey = Symbol.for("kubb.context");
|
|
963
1034
|
const host = globalThis;
|
|
@@ -1025,7 +1096,7 @@ function injectFile(file) {
|
|
|
1025
1096
|
requireContext("injectFile").injectFile(file);
|
|
1026
1097
|
}
|
|
1027
1098
|
/**
|
|
1028
|
-
* Returns the options
|
|
1099
|
+
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
1029
1100
|
*/
|
|
1030
1101
|
function useOptions() {
|
|
1031
1102
|
return requireContext("useOptions").options;
|
|
@@ -1049,123 +1120,6 @@ function requirePlugin(name) {
|
|
|
1049
1120
|
return requireContext("requirePlugin").requirePlugin(name);
|
|
1050
1121
|
}
|
|
1051
1122
|
//#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
1123
|
//#region src/definePlugin.ts
|
|
1170
1124
|
/**
|
|
1171
1125
|
* Merges the `output.mode` default into the output config and validates the combination.
|
|
@@ -1208,7 +1162,7 @@ function assertPluginOption({ plugin, option, value, allowed }) {
|
|
|
1208
1162
|
function definePlugin(input) {
|
|
1209
1163
|
if (typeof input === "function") return defineExtension({
|
|
1210
1164
|
kind: "plugin",
|
|
1211
|
-
build: (
|
|
1165
|
+
build: (options) => {
|
|
1212
1166
|
const plugin = input(options);
|
|
1213
1167
|
return {
|
|
1214
1168
|
...plugin,
|
|
@@ -1216,16 +1170,14 @@ function definePlugin(input) {
|
|
|
1216
1170
|
};
|
|
1217
1171
|
}
|
|
1218
1172
|
});
|
|
1219
|
-
const { meta,
|
|
1173
|
+
const { meta, dependencies, enforce, hooks = {}, setup } = input;
|
|
1220
1174
|
return defineExtension({
|
|
1221
1175
|
kind: "plugin",
|
|
1222
1176
|
meta,
|
|
1223
|
-
|
|
1224
|
-
build: ({ options, parsedOptions }) => ({
|
|
1177
|
+
build: (options) => ({
|
|
1225
1178
|
name: meta.name,
|
|
1226
1179
|
meta,
|
|
1227
1180
|
options,
|
|
1228
|
-
...schema && { parsedOptions },
|
|
1229
1181
|
dependencies,
|
|
1230
1182
|
enforce,
|
|
1231
1183
|
hooks,
|
|
@@ -2268,26 +2220,25 @@ var KubbDriver = class {
|
|
|
2268
2220
|
this.adapter = config.adapter ?? null;
|
|
2269
2221
|
}
|
|
2270
2222
|
/**
|
|
2271
|
-
*
|
|
2223
|
+
* Checks the adapter's and parsers' `meta.compatibility`, then normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
|
|
2272
2224
|
* A plugin that another lists as a dependency runs first, then `enforce: 'pre'` before
|
|
2273
2225
|
* `'post'`. When the config has an adapter, the adapter source is resolved from the input
|
|
2274
2226
|
* so `run` can parse it later.
|
|
2275
2227
|
*/
|
|
2276
2228
|
async setup() {
|
|
2277
2229
|
this.options.signal?.throwIfAborted();
|
|
2278
|
-
for (const
|
|
2230
|
+
for (const extension of [this.config.adapter, ...this.config.parsers]) if (extension?.meta) checkCompatibility(extension.meta);
|
|
2279
2231
|
const normalized = this.#sortPlugins(this.config.plugins.map((rawPlugin) => {
|
|
2280
2232
|
if (rawPlugin.meta) checkCompatibility(rawPlugin.meta);
|
|
2281
2233
|
const meta = resolveMeta(rawPlugin);
|
|
2282
|
-
const options = rawPlugin.parsedOptions ?? rawPlugin.options;
|
|
2283
2234
|
return {
|
|
2284
2235
|
name: meta.name,
|
|
2285
2236
|
meta,
|
|
2286
|
-
dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(options ?? {}, { config: this.config }) : rawPlugin.dependencies,
|
|
2237
|
+
dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(rawPlugin.options ?? {}, { config: this.config }) : rawPlugin.dependencies,
|
|
2287
2238
|
enforce: rawPlugin.enforce,
|
|
2288
2239
|
hooks: rawPlugin.hooks,
|
|
2289
2240
|
setup: rawPlugin.setup,
|
|
2290
|
-
options: options ?? defaultPluginOptions(),
|
|
2241
|
+
options: rawPlugin.options ?? defaultPluginOptions(),
|
|
2291
2242
|
resolver: createResolver({ pluginName: meta.name })
|
|
2292
2243
|
};
|
|
2293
2244
|
}));
|
|
@@ -2931,6 +2882,12 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
2931
2882
|
return camelCase;
|
|
2932
2883
|
}
|
|
2933
2884
|
});
|
|
2885
|
+
Object.defineProperty(exports, "checkCompatibility", {
|
|
2886
|
+
enumerable: true,
|
|
2887
|
+
get: function() {
|
|
2888
|
+
return checkCompatibility;
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2934
2891
|
Object.defineProperty(exports, "clean", {
|
|
2935
2892
|
enumerable: true,
|
|
2936
2893
|
get: function() {
|
|
@@ -3094,4 +3051,4 @@ Object.defineProperty(exports, "write", {
|
|
|
3094
3051
|
}
|
|
3095
3052
|
});
|
|
3096
3053
|
|
|
3097
|
-
//# sourceMappingURL=KubbDriver-
|
|
3054
|
+
//# sourceMappingURL=KubbDriver-DQ7pt93q.cjs.map
|