@kubb/core 5.0.0-alpha.2 → 5.0.0-alpha.4
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 +108 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +38 -2
- package/dist/index.js +109 -15
- package/dist/index.js.map +1 -1
- package/dist/{types-B7eZvqwD.d.ts → types-Bbh1o0yW.d.ts} +85 -9
- package/package.json +2 -2
- package/src/PluginManager.ts +32 -16
- package/src/build.ts +1 -0
- package/src/defineGenerator.ts +106 -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/index.ts +2 -0
- package/src/types.ts +29 -7
- package/src/utils/resolveOptions.ts +93 -0
package/dist/hooks.cjs
CHANGED
|
@@ -1,24 +1,48 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./chunk-ByKO4r7w.cjs");
|
|
3
3
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
4
|
+
//#region src/hooks/useKubb.ts
|
|
5
|
+
function useKubb() {
|
|
6
|
+
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
7
|
+
return {
|
|
8
|
+
plugin: meta.plugin,
|
|
9
|
+
mode: meta.mode,
|
|
10
|
+
config: meta.pluginManager.config,
|
|
11
|
+
getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),
|
|
12
|
+
getFile: meta.pluginManager.getFile.bind(meta.pluginManager),
|
|
13
|
+
resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),
|
|
14
|
+
resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
4
18
|
//#region src/hooks/useMode.ts
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use `useKubb` instead
|
|
21
|
+
*/
|
|
5
22
|
function useMode() {
|
|
6
23
|
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
7
24
|
return meta.mode;
|
|
8
25
|
}
|
|
9
26
|
//#endregion
|
|
10
27
|
//#region src/hooks/usePlugin.ts
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated use useApp instead
|
|
30
|
+
*/
|
|
11
31
|
function usePlugin() {
|
|
12
32
|
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
13
33
|
return meta.plugin;
|
|
14
34
|
}
|
|
15
35
|
//#endregion
|
|
16
36
|
//#region src/hooks/usePluginManager.ts
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated use `useKubb` instead
|
|
39
|
+
*/
|
|
17
40
|
function usePluginManager() {
|
|
18
41
|
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
19
42
|
return meta.pluginManager;
|
|
20
43
|
}
|
|
21
44
|
//#endregion
|
|
45
|
+
exports.useKubb = useKubb;
|
|
22
46
|
exports.useMode = useMode;
|
|
23
47
|
exports.usePlugin = usePlugin;
|
|
24
48
|
exports.usePluginManager = usePluginManager;
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useMode(): KubbFile.Mode {\n const { meta } = useApp<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useApp<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\nexport function usePluginManager(): PluginManager {\n const { meta } = useApp<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp as useAppBase } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>() {\n const { meta } = useAppBase<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n pluginManager: PluginManager\n }>()\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config: meta.pluginManager.config,\n getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),\n getFile: meta.pluginManager.getFile.bind(meta.pluginManager),\n resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),\n resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager),\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useApp<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useApp instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useApp<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginManager(): PluginManager {\n const { meta } = useApp<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;;AAKA,SAAgB,UAAwE;CACtF,MAAM,EAAE,UAAA,GAAA,mBAAA,SAIJ;AAEJ,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,QAAQ,KAAK,cAAc;EAC3B,iBAAiB,KAAK,cAAc,gBAAgB,KAAK,KAAK,cAAc;EAC5E,SAAS,KAAK,cAAc,QAAQ,KAAK,KAAK,cAAc;EAC5D,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACpE,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACrE;;;;;;;ACdH,SAAgB,UAAyB;CACvC,MAAM,EAAE,UAAA,GAAA,mBAAA,SAA0C;AAElD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,SAA+C;AAEvD,QAAO,KAAK;;;;;;;ACHd,SAAgB,mBAAkC;CAChD,MAAM,EAAE,UAAA,GAAA,mBAAA,SAAmD;AAE3D,QAAO,KAAK"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,15 +1,49 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
2
|
+
import { I as PluginManager, T as ResolvePathParams, _ as PluginFactoryOptions, a as Config, h as Plugin, w as ResolveNameParams } from "./types-Bbh1o0yW.js";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
|
+
//#region src/hooks/useKubb.d.ts
|
|
6
|
+
declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): {
|
|
7
|
+
plugin: Plugin<TOptions>;
|
|
8
|
+
mode: KubbFile.Mode;
|
|
9
|
+
config: Config;
|
|
10
|
+
getPluginByName: (pluginName: string) => Plugin | undefined;
|
|
11
|
+
getFile: <TOptions_1 = object>({
|
|
12
|
+
name,
|
|
13
|
+
mode,
|
|
14
|
+
extname,
|
|
15
|
+
pluginName,
|
|
16
|
+
options
|
|
17
|
+
}: {
|
|
18
|
+
name: string;
|
|
19
|
+
mode?: KubbFile.Mode;
|
|
20
|
+
extname: KubbFile.Extname;
|
|
21
|
+
pluginName: string;
|
|
22
|
+
options?: TOptions_1 | undefined;
|
|
23
|
+
}) => KubbFile.File<{
|
|
24
|
+
pluginName: string;
|
|
25
|
+
}>;
|
|
26
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
27
|
+
resolvePath: <TOptions_1 = object>(params: ResolvePathParams<TOptions_1>) => KubbFile.Path;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
5
30
|
//#region src/hooks/useMode.d.ts
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated use `useKubb` instead
|
|
33
|
+
*/
|
|
6
34
|
declare function useMode(): KubbFile.Mode;
|
|
7
35
|
//#endregion
|
|
8
36
|
//#region src/hooks/usePlugin.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated use useApp instead
|
|
39
|
+
*/
|
|
9
40
|
declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
|
|
10
41
|
//#endregion
|
|
11
42
|
//#region src/hooks/usePluginManager.d.ts
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated use `useKubb` instead
|
|
45
|
+
*/
|
|
12
46
|
declare function usePluginManager(): PluginManager;
|
|
13
47
|
//#endregion
|
|
14
|
-
export { useMode, usePlugin, usePluginManager };
|
|
48
|
+
export { useKubb, useMode, usePlugin, usePluginManager };
|
|
15
49
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.js
CHANGED
|
@@ -1,23 +1,46 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { useApp } from "@kubb/react-fabric";
|
|
3
|
+
//#region src/hooks/useKubb.ts
|
|
4
|
+
function useKubb() {
|
|
5
|
+
const { meta } = useApp();
|
|
6
|
+
return {
|
|
7
|
+
plugin: meta.plugin,
|
|
8
|
+
mode: meta.mode,
|
|
9
|
+
config: meta.pluginManager.config,
|
|
10
|
+
getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),
|
|
11
|
+
getFile: meta.pluginManager.getFile.bind(meta.pluginManager),
|
|
12
|
+
resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),
|
|
13
|
+
resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
3
17
|
//#region src/hooks/useMode.ts
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use `useKubb` instead
|
|
20
|
+
*/
|
|
4
21
|
function useMode() {
|
|
5
22
|
const { meta } = useApp();
|
|
6
23
|
return meta.mode;
|
|
7
24
|
}
|
|
8
25
|
//#endregion
|
|
9
26
|
//#region src/hooks/usePlugin.ts
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use useApp instead
|
|
29
|
+
*/
|
|
10
30
|
function usePlugin() {
|
|
11
31
|
const { meta } = useApp();
|
|
12
32
|
return meta.plugin;
|
|
13
33
|
}
|
|
14
34
|
//#endregion
|
|
15
35
|
//#region src/hooks/usePluginManager.ts
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated use `useKubb` instead
|
|
38
|
+
*/
|
|
16
39
|
function usePluginManager() {
|
|
17
40
|
const { meta } = useApp();
|
|
18
41
|
return meta.pluginManager;
|
|
19
42
|
}
|
|
20
43
|
//#endregion
|
|
21
|
-
export { useMode, usePlugin, usePluginManager };
|
|
44
|
+
export { useKubb, useMode, usePlugin, usePluginManager };
|
|
22
45
|
|
|
23
46
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp } from '@kubb/react-fabric'\n\nexport function useMode(): KubbFile.Mode {\n const { meta } = useApp<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useApp<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\nexport function usePluginManager(): PluginManager {\n const { meta } = useApp<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"hooks.js","names":["useAppBase"],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp as useAppBase } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>() {\n const { meta } = useAppBase<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n pluginManager: PluginManager\n }>()\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config: meta.pluginManager.config,\n getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),\n getFile: meta.pluginManager.getFile.bind(meta.pluginManager),\n resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),\n resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager),\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useApp<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useApp instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useApp<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginManager(): PluginManager {\n const { meta } = useApp<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;AAKA,SAAgB,UAAwE;CACtF,MAAM,EAAE,SAASA,QAIb;AAEJ,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,QAAQ,KAAK,cAAc;EAC3B,iBAAiB,KAAK,cAAc,gBAAgB,KAAK,KAAK,cAAc;EAC5E,SAAS,KAAK,cAAc,QAAQ,KAAK,KAAK,cAAc;EAC5D,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACpE,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACrE;;;;;;;ACdH,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,QAAiC;AAElD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,QAAsC;AAEvD,QAAO,KAAK;;;;;;;ACHd,SAAgB,mBAAkC;CAChD,MAAM,EAAE,SAAS,QAA0C;AAE3D,QAAO,KAAK"}
|
package/dist/index.cjs
CHANGED
|
@@ -959,7 +959,7 @@ function isPromiseRejectedResult(result) {
|
|
|
959
959
|
//#region src/PluginManager.ts
|
|
960
960
|
function getMode(fileOrFolder) {
|
|
961
961
|
if (!fileOrFolder) return "split";
|
|
962
|
-
return node_path.
|
|
962
|
+
return (0, node_path.extname)(fileOrFolder) ? "single" : "split";
|
|
963
963
|
}
|
|
964
964
|
var PluginManager = class {
|
|
965
965
|
config;
|
|
@@ -969,6 +969,7 @@ var PluginManager = class {
|
|
|
969
969
|
* the build pipeline after the adapter's `parse()` resolves.
|
|
970
970
|
*/
|
|
971
971
|
rootNode = void 0;
|
|
972
|
+
adapter = void 0;
|
|
972
973
|
#studioIsOpen = false;
|
|
973
974
|
#plugins = /* @__PURE__ */ new Set();
|
|
974
975
|
#usedPluginNames = {};
|
|
@@ -994,7 +995,7 @@ var PluginManager = class {
|
|
|
994
995
|
plugin,
|
|
995
996
|
events: this.options.events,
|
|
996
997
|
pluginManager: this,
|
|
997
|
-
mode: getMode(node_path.
|
|
998
|
+
mode: getMode((0, node_path.resolve)(this.config.root, this.config.output.path)),
|
|
998
999
|
addFile: async (...files) => {
|
|
999
1000
|
await this.options.fabric.addFile(...files);
|
|
1000
1001
|
},
|
|
@@ -1004,10 +1005,13 @@ var PluginManager = class {
|
|
|
1004
1005
|
get rootNode() {
|
|
1005
1006
|
return pluginManager.rootNode;
|
|
1006
1007
|
},
|
|
1008
|
+
get adapter() {
|
|
1009
|
+
return pluginManager.adapter;
|
|
1010
|
+
},
|
|
1007
1011
|
openInStudio(options) {
|
|
1012
|
+
if (!pluginManager.config.devtools || pluginManager.#studioIsOpen) return;
|
|
1008
1013
|
if (typeof pluginManager.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
1009
|
-
if (!pluginManager.rootNode) throw new Error("
|
|
1010
|
-
if (pluginManager.#studioIsOpen) return;
|
|
1014
|
+
if (!pluginManager.rootNode || !pluginManager.adapter) throw new Error("adapter is not defined, make sure you have set the parser in kubb.config.ts");
|
|
1011
1015
|
pluginManager.#studioIsOpen = true;
|
|
1012
1016
|
const studioUrl = pluginManager.config.devtools?.studioUrl ?? "https://studio.kubb.dev";
|
|
1013
1017
|
return openInStudio(pluginManager.rootNode, studioUrl, options);
|
|
@@ -1027,17 +1031,21 @@ var PluginManager = class {
|
|
|
1027
1031
|
return this.#getSortedPlugins();
|
|
1028
1032
|
}
|
|
1029
1033
|
getFile({ name, mode, extname, pluginName, options }) {
|
|
1030
|
-
const
|
|
1034
|
+
const resolvedName = mode ? mode === "single" ? "" : this.resolveName({
|
|
1035
|
+
name,
|
|
1036
|
+
pluginName,
|
|
1037
|
+
type: "file"
|
|
1038
|
+
}) : name;
|
|
1031
1039
|
const path = this.resolvePath({
|
|
1032
|
-
baseName
|
|
1040
|
+
baseName: `${resolvedName}${extname}`,
|
|
1033
1041
|
mode,
|
|
1034
1042
|
pluginName,
|
|
1035
1043
|
options
|
|
1036
1044
|
});
|
|
1037
|
-
if (!path) throw new Error(`Filepath should be defined for resolvedName "${
|
|
1045
|
+
if (!path) throw new Error(`Filepath should be defined for resolvedName "${resolvedName}" and pluginName "${pluginName}"`);
|
|
1038
1046
|
return {
|
|
1039
1047
|
path,
|
|
1040
|
-
baseName,
|
|
1048
|
+
baseName: (0, node_path.basename)(path),
|
|
1041
1049
|
meta: { pluginName },
|
|
1042
1050
|
sources: [],
|
|
1043
1051
|
imports: [],
|
|
@@ -1045,8 +1053,7 @@ var PluginManager = class {
|
|
|
1045
1053
|
};
|
|
1046
1054
|
}
|
|
1047
1055
|
resolvePath = (params) => {
|
|
1048
|
-
const
|
|
1049
|
-
const defaultPath = node_path.default.resolve(root, params.baseName);
|
|
1056
|
+
const defaultPath = (0, node_path.resolve)((0, node_path.resolve)(this.config.root, this.config.output.path), params.baseName);
|
|
1050
1057
|
if (params.pluginName) return this.hookForPluginSync({
|
|
1051
1058
|
pluginName: params.pluginName,
|
|
1052
1059
|
hookName: "resolvePath",
|
|
@@ -1234,7 +1241,8 @@ var PluginManager = class {
|
|
|
1234
1241
|
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
1235
1242
|
return plugins.map((plugin) => {
|
|
1236
1243
|
if (plugin.pre) {
|
|
1237
|
-
|
|
1244
|
+
let missingPlugins = plugin.pre.filter((pluginName) => !plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
1245
|
+
if (missingPlugins.includes("plugin-oas") && this.adapter) missingPlugins = missingPlugins.filter((pluginName) => pluginName !== "plugin-oas");
|
|
1238
1246
|
if (missingPlugins.length > 0) throw new ValidationPluginError(`The plugin '${plugin.name}' has a pre set that references missing plugins for '${missingPlugins.join(", ")}'`);
|
|
1239
1247
|
}
|
|
1240
1248
|
return plugin;
|
|
@@ -1456,7 +1464,7 @@ const fsStorage = defineStorage(() => ({
|
|
|
1456
1464
|
}));
|
|
1457
1465
|
//#endregion
|
|
1458
1466
|
//#region package.json
|
|
1459
|
-
var version = "5.0.0-alpha.
|
|
1467
|
+
var version = "5.0.0-alpha.4";
|
|
1460
1468
|
//#endregion
|
|
1461
1469
|
//#region src/utils/diagnostics.ts
|
|
1462
1470
|
/**
|
|
@@ -1581,6 +1589,7 @@ async function setup(options) {
|
|
|
1581
1589
|
date: /* @__PURE__ */ new Date(),
|
|
1582
1590
|
logs: [`Running adapter: ${definedConfig.adapter.name}`]
|
|
1583
1591
|
});
|
|
1592
|
+
pluginManager.adapter = definedConfig.adapter;
|
|
1584
1593
|
pluginManager.rootNode = await definedConfig.adapter.parse(source);
|
|
1585
1594
|
await events.emit("debug", {
|
|
1586
1595
|
date: /* @__PURE__ */ new Date(),
|
|
@@ -1788,6 +1797,36 @@ function defineAdapter(build) {
|
|
|
1788
1797
|
return (options) => build(options ?? {});
|
|
1789
1798
|
}
|
|
1790
1799
|
//#endregion
|
|
1800
|
+
//#region src/defineGenerator.ts
|
|
1801
|
+
function defineGenerator(generator) {
|
|
1802
|
+
if (generator.type === "react") return {
|
|
1803
|
+
version: "2",
|
|
1804
|
+
Operations() {
|
|
1805
|
+
return null;
|
|
1806
|
+
},
|
|
1807
|
+
Operation() {
|
|
1808
|
+
return null;
|
|
1809
|
+
},
|
|
1810
|
+
Schema() {
|
|
1811
|
+
return null;
|
|
1812
|
+
},
|
|
1813
|
+
...generator
|
|
1814
|
+
};
|
|
1815
|
+
return {
|
|
1816
|
+
version: "2",
|
|
1817
|
+
async operations() {
|
|
1818
|
+
return [];
|
|
1819
|
+
},
|
|
1820
|
+
async operation() {
|
|
1821
|
+
return [];
|
|
1822
|
+
},
|
|
1823
|
+
async schema() {
|
|
1824
|
+
return [];
|
|
1825
|
+
},
|
|
1826
|
+
...generator
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
//#endregion
|
|
1791
1830
|
//#region src/defineLogger.ts
|
|
1792
1831
|
function defineLogger(logger) {
|
|
1793
1832
|
return { ...logger };
|
|
@@ -2301,6 +2340,61 @@ async function detectLinter() {
|
|
|
2301
2340
|
]) if (await isLinterAvailable(linter)) return linter;
|
|
2302
2341
|
}
|
|
2303
2342
|
//#endregion
|
|
2343
|
+
//#region src/utils/resolveOptions.ts
|
|
2344
|
+
function matchesOperationPattern(node, type, pattern) {
|
|
2345
|
+
switch (type) {
|
|
2346
|
+
case "tag": return node.tags.some((tag) => !!tag.match(pattern));
|
|
2347
|
+
case "operationId": return !!node.operationId.match(pattern);
|
|
2348
|
+
case "path": return !!node.path.match(pattern);
|
|
2349
|
+
case "method": return !!node.method.toLowerCase().match(pattern);
|
|
2350
|
+
default: return false;
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
function matchesSchemaPattern(node, type, pattern) {
|
|
2354
|
+
switch (type) {
|
|
2355
|
+
case "schemaName": return node.name ? !!node.name.match(pattern) : false;
|
|
2356
|
+
default: return null;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Resolves the effective plugin options for a given AST node by applying
|
|
2361
|
+
* `exclude`, `include`, and `override` rules from the plugin configuration.
|
|
2362
|
+
*
|
|
2363
|
+
* Returns `null` when the node is excluded or not matched by `include`.
|
|
2364
|
+
* Returns the merged options (base options merged with any matching `override`) otherwise.
|
|
2365
|
+
*
|
|
2366
|
+
* Supported filter types for `OperationNode`: `tag`, `operationId`, `path`, `method`.
|
|
2367
|
+
* Supported filter types for `SchemaNode`: `schemaName`.
|
|
2368
|
+
*
|
|
2369
|
+
* @example
|
|
2370
|
+
* const resolved = resolveOptions(operationNode, { options, exclude, include, override })
|
|
2371
|
+
* if (!resolved) return // excluded
|
|
2372
|
+
*/
|
|
2373
|
+
function resolveOptions(node, { options, exclude = [], include, override = [] }) {
|
|
2374
|
+
if ((0, _kubb_ast.isOperationNode)(node)) {
|
|
2375
|
+
if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
2376
|
+
if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
|
|
2377
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
|
|
2378
|
+
return {
|
|
2379
|
+
...options,
|
|
2380
|
+
...overrideOptions
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
if ((0, _kubb_ast.isSchemaNode)(node)) {
|
|
2384
|
+
if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
|
|
2385
|
+
if (include) {
|
|
2386
|
+
const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
|
|
2387
|
+
if (applicable.length > 0 && !applicable.includes(true)) return null;
|
|
2388
|
+
}
|
|
2389
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
|
|
2390
|
+
return {
|
|
2391
|
+
...options,
|
|
2392
|
+
...overrideOptions
|
|
2393
|
+
};
|
|
2394
|
+
}
|
|
2395
|
+
return options;
|
|
2396
|
+
}
|
|
2397
|
+
//#endregion
|
|
2304
2398
|
exports.AsyncEventEmitter = AsyncEventEmitter;
|
|
2305
2399
|
exports.FunctionParams = FunctionParams;
|
|
2306
2400
|
exports.PackageManager = PackageManager;
|
|
@@ -2311,6 +2405,7 @@ exports.build = build;
|
|
|
2311
2405
|
exports.default = build;
|
|
2312
2406
|
exports.defineAdapter = defineAdapter;
|
|
2313
2407
|
exports.defineConfig = defineConfig;
|
|
2408
|
+
exports.defineGenerator = defineGenerator;
|
|
2314
2409
|
exports.defineLogger = defineLogger;
|
|
2315
2410
|
exports.definePlugin = definePlugin;
|
|
2316
2411
|
Object.defineProperty(exports, "definePrinter", {
|
|
@@ -2331,6 +2426,7 @@ exports.isInputPath = isInputPath;
|
|
|
2331
2426
|
exports.linters = linters;
|
|
2332
2427
|
exports.logLevel = logLevel;
|
|
2333
2428
|
exports.memoryStorage = memoryStorage;
|
|
2429
|
+
exports.resolveOptions = resolveOptions;
|
|
2334
2430
|
exports.safeBuild = safeBuild;
|
|
2335
2431
|
exports.setup = setup;
|
|
2336
2432
|
|