@kubb/core 5.0.0-alpha.2 → 5.0.0-alpha.3
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/hooks.cjs +24 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +36 -2
- package/dist/hooks.js +24 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +21 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/{types-B7eZvqwD.d.ts → types-CiPWLv-5.d.ts} +28 -8
- package/package.json +2 -2
- package/src/PluginManager.ts +32 -16
- package/src/build.ts +1 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useKubb.ts +22 -0
- package/src/hooks/useMode.ts +3 -0
- package/src/hooks/usePlugin.ts +3 -0
- package/src/hooks/usePluginManager.ts +3 -0
- package/src/types.ts +28 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as UserPluginWithLifeCycle, B as URLPath, C as PrinterFactoryOptions, D as UserConfig, E as UnknownUserPlugin, F as defineStorage, I as formatters, L as linters, M as PluginManager, N as getMode, O as UserLogger, P as DefineStorage, R as logLevel, S as Printer, T as ResolvePathParams, _ as PluginFactoryOptions, a as Config, b as PluginParameter, c as Group, d as Logger, f as LoggerContext, g as PluginContext, h as Plugin, i as BarrelType, j as KubbEvents, k as UserPlugin, l as InputData, m as Output, n as AdapterFactoryOptions, o as DevtoolsOptions, p as LoggerOptions, r as AdapterSource, s as GetPluginFactoryOptions, t as Adapter, u as InputPath, v as PluginLifecycle, w as ResolveNameParams, x as PluginWithLifeCycle, y as PluginLifecycleHooks, z as AsyncEventEmitter } from "./types-
|
|
2
|
+
import { A as UserPluginWithLifeCycle, B as URLPath, C as PrinterFactoryOptions, D as UserConfig, E as UnknownUserPlugin, F as defineStorage, I as formatters, L as linters, M as PluginManager, N as getMode, O as UserLogger, P as DefineStorage, R as logLevel, S as Printer, T as ResolvePathParams, _ as PluginFactoryOptions, a as Config, b as PluginParameter, c as Group, d as Logger, f as LoggerContext, g as PluginContext, h as Plugin, i as BarrelType, j as KubbEvents, k as UserPlugin, l as InputData, m as Output, n as AdapterFactoryOptions, o as DevtoolsOptions, p as LoggerOptions, r as AdapterSource, s as GetPluginFactoryOptions, t as Adapter, u as InputPath, v as PluginLifecycle, w as ResolveNameParams, x as PluginWithLifeCycle, y as PluginLifecycleHooks, z as AsyncEventEmitter } from "./types-CiPWLv-5.js";
|
|
3
3
|
import { definePrinter } from "@kubb/ast";
|
|
4
4
|
import { Fabric } from "@kubb/react-fabric";
|
|
5
5
|
import { KubbFile } from "@kubb/fabric-core/types";
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { EventEmitter } from "node:events";
|
|
|
4
4
|
import { parseArgs, styleText } from "node:util";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
7
|
-
import path, { dirname, join, posix, relative, resolve } from "node:path";
|
|
7
|
+
import path, { basename, dirname, extname, join, posix, relative, resolve } from "node:path";
|
|
8
8
|
import { definePrinter } from "@kubb/ast";
|
|
9
9
|
import { createFabric } from "@kubb/react-fabric";
|
|
10
10
|
import { typescriptParser } from "@kubb/react-fabric/parsers";
|
|
@@ -951,7 +951,7 @@ function isPromiseRejectedResult(result) {
|
|
|
951
951
|
//#region src/PluginManager.ts
|
|
952
952
|
function getMode(fileOrFolder) {
|
|
953
953
|
if (!fileOrFolder) return "split";
|
|
954
|
-
return
|
|
954
|
+
return extname(fileOrFolder) ? "single" : "split";
|
|
955
955
|
}
|
|
956
956
|
var PluginManager = class {
|
|
957
957
|
config;
|
|
@@ -961,6 +961,7 @@ var PluginManager = class {
|
|
|
961
961
|
* the build pipeline after the adapter's `parse()` resolves.
|
|
962
962
|
*/
|
|
963
963
|
rootNode = void 0;
|
|
964
|
+
adapter = void 0;
|
|
964
965
|
#studioIsOpen = false;
|
|
965
966
|
#plugins = /* @__PURE__ */ new Set();
|
|
966
967
|
#usedPluginNames = {};
|
|
@@ -986,7 +987,7 @@ var PluginManager = class {
|
|
|
986
987
|
plugin,
|
|
987
988
|
events: this.options.events,
|
|
988
989
|
pluginManager: this,
|
|
989
|
-
mode: getMode(
|
|
990
|
+
mode: getMode(resolve(this.config.root, this.config.output.path)),
|
|
990
991
|
addFile: async (...files) => {
|
|
991
992
|
await this.options.fabric.addFile(...files);
|
|
992
993
|
},
|
|
@@ -996,10 +997,13 @@ var PluginManager = class {
|
|
|
996
997
|
get rootNode() {
|
|
997
998
|
return pluginManager.rootNode;
|
|
998
999
|
},
|
|
1000
|
+
get adapter() {
|
|
1001
|
+
return pluginManager.adapter;
|
|
1002
|
+
},
|
|
999
1003
|
openInStudio(options) {
|
|
1004
|
+
if (!pluginManager.config.devtools || pluginManager.#studioIsOpen) return;
|
|
1000
1005
|
if (typeof pluginManager.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
1001
|
-
if (!pluginManager.rootNode) throw new Error("
|
|
1002
|
-
if (pluginManager.#studioIsOpen) return;
|
|
1006
|
+
if (!pluginManager.rootNode || !pluginManager.adapter) throw new Error("adapter is not defined, make sure you have set the parser in kubb.config.ts");
|
|
1003
1007
|
pluginManager.#studioIsOpen = true;
|
|
1004
1008
|
const studioUrl = pluginManager.config.devtools?.studioUrl ?? "https://studio.kubb.dev";
|
|
1005
1009
|
return openInStudio(pluginManager.rootNode, studioUrl, options);
|
|
@@ -1019,17 +1023,21 @@ var PluginManager = class {
|
|
|
1019
1023
|
return this.#getSortedPlugins();
|
|
1020
1024
|
}
|
|
1021
1025
|
getFile({ name, mode, extname, pluginName, options }) {
|
|
1022
|
-
const
|
|
1026
|
+
const resolvedName = mode ? mode === "single" ? "" : this.resolveName({
|
|
1027
|
+
name,
|
|
1028
|
+
pluginName,
|
|
1029
|
+
type: "file"
|
|
1030
|
+
}) : name;
|
|
1023
1031
|
const path = this.resolvePath({
|
|
1024
|
-
baseName
|
|
1032
|
+
baseName: `${resolvedName}${extname}`,
|
|
1025
1033
|
mode,
|
|
1026
1034
|
pluginName,
|
|
1027
1035
|
options
|
|
1028
1036
|
});
|
|
1029
|
-
if (!path) throw new Error(`Filepath should be defined for resolvedName "${
|
|
1037
|
+
if (!path) throw new Error(`Filepath should be defined for resolvedName "${resolvedName}" and pluginName "${pluginName}"`);
|
|
1030
1038
|
return {
|
|
1031
1039
|
path,
|
|
1032
|
-
baseName,
|
|
1040
|
+
baseName: basename(path),
|
|
1033
1041
|
meta: { pluginName },
|
|
1034
1042
|
sources: [],
|
|
1035
1043
|
imports: [],
|
|
@@ -1037,8 +1045,7 @@ var PluginManager = class {
|
|
|
1037
1045
|
};
|
|
1038
1046
|
}
|
|
1039
1047
|
resolvePath = (params) => {
|
|
1040
|
-
const
|
|
1041
|
-
const defaultPath = path.resolve(root, params.baseName);
|
|
1048
|
+
const defaultPath = resolve(resolve(this.config.root, this.config.output.path), params.baseName);
|
|
1042
1049
|
if (params.pluginName) return this.hookForPluginSync({
|
|
1043
1050
|
pluginName: params.pluginName,
|
|
1044
1051
|
hookName: "resolvePath",
|
|
@@ -1226,7 +1233,8 @@ var PluginManager = class {
|
|
|
1226
1233
|
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
1227
1234
|
return plugins.map((plugin) => {
|
|
1228
1235
|
if (plugin.pre) {
|
|
1229
|
-
|
|
1236
|
+
let missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1237
|
+
if (missingPlugins.includes("plugin-oas") && this.adapter) missingPlugins = missingPlugins.filter((pluginName) => pluginName !== "plugin-oas");
|
|
1230
1238
|
if (missingPlugins.length > 0) throw new ValidationPluginError(`The plugin '${plugin.name}' has a pre set that references missing plugins for '${missingPlugins.join(", ")}'`);
|
|
1231
1239
|
}
|
|
1232
1240
|
return plugin;
|
|
@@ -1448,7 +1456,7 @@ const fsStorage = defineStorage(() => ({
|
|
|
1448
1456
|
}));
|
|
1449
1457
|
//#endregion
|
|
1450
1458
|
//#region package.json
|
|
1451
|
-
var version$1 = "5.0.0-alpha.
|
|
1459
|
+
var version$1 = "5.0.0-alpha.3";
|
|
1452
1460
|
//#endregion
|
|
1453
1461
|
//#region src/utils/diagnostics.ts
|
|
1454
1462
|
/**
|
|
@@ -1573,6 +1581,7 @@ async function setup(options) {
|
|
|
1573
1581
|
date: /* @__PURE__ */ new Date(),
|
|
1574
1582
|
logs: [`Running adapter: ${definedConfig.adapter.name}`]
|
|
1575
1583
|
});
|
|
1584
|
+
pluginManager.adapter = definedConfig.adapter;
|
|
1576
1585
|
pluginManager.rootNode = await definedConfig.adapter.parse(source);
|
|
1577
1586
|
await events.emit("debug", {
|
|
1578
1587
|
date: /* @__PURE__ */ new Date(),
|