@kubb/core 5.0.0-alpha.35 → 5.0.0-alpha.36
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/PluginDriver-B_65W4fv.js +1677 -0
- package/dist/PluginDriver-B_65W4fv.js.map +1 -0
- package/dist/{PluginDriver-D8lWvtUg.d.ts → PluginDriver-C9iBgYbk.d.ts} +3 -4
- package/dist/PluginDriver-CCdkwR14.cjs +1806 -0
- package/dist/PluginDriver-CCdkwR14.cjs.map +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +31 -1696
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -2
- package/dist/index.js +6 -1676
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +165 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +11 -4
- package/src/index.ts +2 -0
- package/src/mocks.ts +234 -0
- package/src/types.ts +1 -2
package/dist/mocks.cjs
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./chunk-ByKO4r7w.cjs");
|
|
3
|
+
const require_PluginDriver = require("./PluginDriver-CCdkwR14.cjs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let _kubb_ast = require("@kubb/ast");
|
|
6
|
+
//#region src/mocks.ts
|
|
7
|
+
function toCamelOrPascal(text, pascal) {
|
|
8
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
9
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
10
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
11
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
12
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
13
|
+
}
|
|
14
|
+
function camelCase(text) {
|
|
15
|
+
return toCamelOrPascal(text, false);
|
|
16
|
+
}
|
|
17
|
+
function pascalCase(text) {
|
|
18
|
+
return toCamelOrPascal(text, true);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a minimal `PluginDriver` mock suitable for unit tests.
|
|
22
|
+
*/
|
|
23
|
+
function createMockedPluginDriver(options = {}) {
|
|
24
|
+
return {
|
|
25
|
+
resolveName: (result) => {
|
|
26
|
+
if (result.type === "file") return camelCase(options?.name || result.name);
|
|
27
|
+
if (result.type === "type") return pascalCase(result.name);
|
|
28
|
+
if (result.type === "function") return camelCase(result.name);
|
|
29
|
+
return camelCase(result.name);
|
|
30
|
+
},
|
|
31
|
+
config: options?.config ?? {
|
|
32
|
+
root: ".",
|
|
33
|
+
output: { path: "./path" }
|
|
34
|
+
},
|
|
35
|
+
resolvePath: ({ baseName }) => baseName,
|
|
36
|
+
getFile: ({ name, extname, pluginName, options: fileOptions }) => {
|
|
37
|
+
const baseName = `${name}${extname}`;
|
|
38
|
+
const groupDir = fileOptions?.group?.tag ?? fileOptions?.group?.path?.split("/").filter(Boolean)[0];
|
|
39
|
+
return {
|
|
40
|
+
path: groupDir ? `${groupDir}/${baseName}` : baseName,
|
|
41
|
+
baseName,
|
|
42
|
+
meta: { pluginName }
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
getPlugin(_pluginName) {
|
|
46
|
+
return options?.plugin;
|
|
47
|
+
},
|
|
48
|
+
fileManager: new require_PluginDriver.FileManager()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a minimal `Adapter` mock suitable for unit tests.
|
|
53
|
+
*
|
|
54
|
+
* - `parse` returns an empty `InputNode` by default; override via `options.parse`.
|
|
55
|
+
* - `getImports` returns `[]` by default (single-file mode, no cross-file imports).
|
|
56
|
+
*/
|
|
57
|
+
function createMockedAdapter(options = {}) {
|
|
58
|
+
return {
|
|
59
|
+
name: options.name ?? "oas",
|
|
60
|
+
options: options.resolvedOptions ?? {},
|
|
61
|
+
inputNode: options.inputNode ?? null,
|
|
62
|
+
parse: options.parse ?? (async () => ({
|
|
63
|
+
kind: "Input",
|
|
64
|
+
schemas: [],
|
|
65
|
+
operations: []
|
|
66
|
+
})),
|
|
67
|
+
getImports: options.getImports ?? ((_node, _resolve) => [])
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a minimal `Plugin` mock suitable for unit tests.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })
|
|
75
|
+
*/
|
|
76
|
+
function createMockedPlugin(params) {
|
|
77
|
+
return {
|
|
78
|
+
name: params.name,
|
|
79
|
+
options: params.options,
|
|
80
|
+
resolver: params.resolver,
|
|
81
|
+
transformer: params.transformer,
|
|
82
|
+
dependencies: params.dependencies,
|
|
83
|
+
install: () => {},
|
|
84
|
+
inject: () => void 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createMockedPluginContext(opts) {
|
|
88
|
+
const root = (0, node_path.resolve)(opts.config.root, opts.config.output.path);
|
|
89
|
+
return {
|
|
90
|
+
config: opts.config,
|
|
91
|
+
root,
|
|
92
|
+
getMode: (output) => require_PluginDriver.getMode((0, node_path.resolve)(root, output.path)),
|
|
93
|
+
adapter: opts.adapter,
|
|
94
|
+
resolver: opts.resolver,
|
|
95
|
+
plugin: opts.plugin,
|
|
96
|
+
driver: opts.driver,
|
|
97
|
+
inputNode: {
|
|
98
|
+
kind: "Input",
|
|
99
|
+
schemas: [],
|
|
100
|
+
operations: []
|
|
101
|
+
},
|
|
102
|
+
upsertFile: async (...files) => opts.driver.fileManager.upsert(...files),
|
|
103
|
+
warn: (msg) => console.warn(msg),
|
|
104
|
+
error: (msg) => console.error(msg),
|
|
105
|
+
info: (msg) => console.info(msg),
|
|
106
|
+
openInStudio: async () => {}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Renders a generator's `schema` method in a test context.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
114
|
+
* await matchFiles(driver.fileManager.files)
|
|
115
|
+
*/
|
|
116
|
+
async function renderGeneratorSchema(generator, node, opts) {
|
|
117
|
+
if (!generator.schema) return;
|
|
118
|
+
const context = createMockedPluginContext(opts);
|
|
119
|
+
const transformedNode = opts.plugin.transformer ? (0, _kubb_ast.transform)(node, opts.plugin.transformer) : node;
|
|
120
|
+
await require_PluginDriver.applyHookResult(await generator.schema(transformedNode, {
|
|
121
|
+
...context,
|
|
122
|
+
options: opts.options
|
|
123
|
+
}), opts.driver, generator.renderer ?? void 0);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Renders a generator's `operation` method in a test context.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
130
|
+
* await matchFiles(driver.fileManager.files)
|
|
131
|
+
*/
|
|
132
|
+
async function renderGeneratorOperation(generator, node, opts) {
|
|
133
|
+
if (!generator.operation) return;
|
|
134
|
+
const context = createMockedPluginContext(opts);
|
|
135
|
+
const transformedNode = opts.plugin.transformer ? (0, _kubb_ast.transform)(node, opts.plugin.transformer) : node;
|
|
136
|
+
await require_PluginDriver.applyHookResult(await generator.operation(transformedNode, {
|
|
137
|
+
...context,
|
|
138
|
+
options: opts.options
|
|
139
|
+
}), opts.driver, generator.renderer ?? void 0);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Renders a generator's `operations` method in a test context.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })
|
|
146
|
+
* await matchFiles(driver.fileManager.files)
|
|
147
|
+
*/
|
|
148
|
+
async function renderGeneratorOperations(generator, nodes, opts) {
|
|
149
|
+
if (!generator.operations) return;
|
|
150
|
+
const context = createMockedPluginContext(opts);
|
|
151
|
+
const transformedNodes = opts.plugin.transformer ? nodes.map((n) => (0, _kubb_ast.transform)(n, opts.plugin.transformer)) : nodes;
|
|
152
|
+
await require_PluginDriver.applyHookResult(await generator.operations(transformedNodes, {
|
|
153
|
+
...context,
|
|
154
|
+
options: opts.options
|
|
155
|
+
}), opts.driver, generator.renderer ?? void 0);
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
exports.createMockedAdapter = createMockedAdapter;
|
|
159
|
+
exports.createMockedPlugin = createMockedPlugin;
|
|
160
|
+
exports.createMockedPluginDriver = createMockedPluginDriver;
|
|
161
|
+
exports.renderGeneratorOperation = renderGeneratorOperation;
|
|
162
|
+
exports.renderGeneratorOperations = renderGeneratorOperations;
|
|
163
|
+
exports.renderGeneratorSchema = renderGeneratorSchema;
|
|
164
|
+
|
|
165
|
+
//# sourceMappingURL=mocks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mocks.cjs","names":["FileManager","getMode","applyHookResult"],"sources":["../src/mocks.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { FileNode, OperationNode, SchemaNode, Visitor } from '@kubb/ast'\nimport { transform } from '@kubb/ast'\nimport { FileManager } from './FileManager.ts'\nimport { getMode, type PluginDriver } from './PluginDriver.ts'\nimport { applyHookResult } from './renderNode.ts'\nimport type {\n Adapter,\n AdapterFactoryOptions,\n Config,\n Generator,\n GeneratorContext,\n Plugin,\n PluginFactoryOptions,\n ResolveNameParams,\n ResolvePathParams,\n} from './types.ts'\n\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\nfunction camelCase(text: string): string {\n return toCamelOrPascal(text, false)\n}\n\nfunction pascalCase(text: string): string {\n return toCamelOrPascal(text, true)\n}\n\n/**\n * Creates a minimal `PluginDriver` mock suitable for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: Plugin<any>; config?: Config } = {}): PluginDriver {\n return {\n resolveName: (result: ResolveNameParams) => {\n if (result.type === 'file') {\n return camelCase(options?.name || result.name)\n }\n\n if (result.type === 'type') {\n return pascalCase(result.name)\n }\n\n if (result.type === 'function') {\n return camelCase(result.name)\n }\n\n return camelCase(result.name)\n },\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n resolvePath: ({ baseName }: ResolvePathParams) => baseName,\n getFile: ({\n name,\n extname,\n pluginName,\n options: fileOptions,\n }: {\n name: string\n extname: `.${string}`\n pluginName: string\n options?: { group?: { tag?: string; path?: string } }\n }) => {\n const baseName = `${name}${extname}`\n const groupDir = fileOptions?.group?.tag ?? fileOptions?.group?.path?.split('/').filter(Boolean)[0]\n const filePath = groupDir ? `${groupDir}/${baseName}` : baseName\n\n return {\n path: filePath,\n baseName,\n meta: { pluginName },\n }\n },\n getPlugin(_pluginName: Plugin['name']): Plugin | undefined {\n return options?.plugin\n },\n fileManager: new FileManager(),\n } as unknown as PluginDriver\n}\n\n/**\n * Creates a minimal `Adapter` mock suitable for unit tests.\n *\n * - `parse` returns an empty `InputNode` by default; override via `options.parse`.\n * - `getImports` returns `[]` by default (single-file mode, no cross-file imports).\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n inputNode?: Adapter<TOptions>['inputNode']\n parse?: Adapter<TOptions>['parse']\n getImports?: Adapter<TOptions>['getImports']\n } = {},\n): Adapter<TOptions> {\n return {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n inputNode: options.inputNode ?? null,\n parse: options.parse ?? (async () => ({ kind: 'Input' as const, schemas: [], operations: [] })),\n getImports: options.getImports ?? ((_node: SchemaNode, _resolve: (schemaName: string) => { name: string; path: string }) => []),\n } as Adapter<TOptions>\n}\n\n/**\n * Creates a minimal `Plugin` mock suitable for unit tests.\n *\n * @example\n * const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })\n */\nexport function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n transformer?: Visitor\n dependencies?: Array<string>\n}): Plugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n transformer: params.transformer,\n dependencies: params.dependencies,\n install: () => {},\n inject: () => undefined as TOptions['context'],\n } as unknown as Plugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {\n config: Config\n adapter: Adapter\n driver: PluginDriver\n plugin: Plugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginFactoryOptions>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n getMode: (output: { path: string }) => getMode(resolve(root, output.path)),\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n inputNode: { kind: 'Input', schemas: [], operations: [] },\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n openInStudio: async () => {},\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n */\nexport async function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n const context = createMockedPluginContext(opts)\n const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node\n const result = await generator.schema(transformedNode, { ...context, options: opts.options })\n await applyHookResult(result, opts.driver, generator.renderer ?? undefined)\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n */\nexport async function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n const context = createMockedPluginContext(opts)\n const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node\n const result = await generator.operation(transformedNode, { ...context, options: opts.options })\n await applyHookResult(result, opts.driver, generator.renderer ?? undefined)\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n */\nexport async function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.transformer ? nodes.map((n) => transform(n, opts.plugin.transformer!)) : nodes\n const result = await generator.operations(transformedNodes, { ...context, options: opts.options })\n await applyHookResult(result, opts.driver, generator.renderer ?? undefined)\n}\n"],"mappings":";;;;;;AAkBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;AAGjC,SAAS,UAAU,MAAsB;AACvC,QAAO,gBAAgB,MAAM,MAAM;;AAGrC,SAAS,WAAW,MAAsB;AACxC,QAAO,gBAAgB,MAAM,KAAK;;;;;AAMpC,SAAgB,yBAAyB,UAAoE,EAAE,EAAgB;AAC7H,QAAO;EACL,cAAc,WAA8B;AAC1C,OAAI,OAAO,SAAS,OAClB,QAAO,UAAU,SAAS,QAAQ,OAAO,KAAK;AAGhD,OAAI,OAAO,SAAS,OAClB,QAAO,WAAW,OAAO,KAAK;AAGhC,OAAI,OAAO,SAAS,WAClB,QAAO,UAAU,OAAO,KAAK;AAG/B,UAAO,UAAU,OAAO,KAAK;;EAE/B,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,UACP;GACF;EACD,cAAc,EAAE,eAAkC;EAClD,UAAU,EACR,MACA,SACA,YACA,SA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2
|
+
import { N as PluginFactoryOptions, f as Config, i as Generator, j as Plugin, o as Adapter, s as AdapterFactoryOptions, t as PluginDriver } from "./PluginDriver-C9iBgYbk.js";
|
|
3
|
+
import { OperationNode, SchemaNode, Visitor } from "@kubb/ast";
|
|
4
|
+
|
|
5
|
+
//#region src/mocks.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a minimal `PluginDriver` mock suitable for unit tests.
|
|
8
|
+
*/
|
|
9
|
+
declare function createMockedPluginDriver(options?: {
|
|
10
|
+
name?: string;
|
|
11
|
+
plugin?: Plugin<any>;
|
|
12
|
+
config?: Config;
|
|
13
|
+
}): PluginDriver;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a minimal `Adapter` mock suitable for unit tests.
|
|
16
|
+
*
|
|
17
|
+
* - `parse` returns an empty `InputNode` by default; override via `options.parse`.
|
|
18
|
+
* - `getImports` returns `[]` by default (single-file mode, no cross-file imports).
|
|
19
|
+
*/
|
|
20
|
+
declare function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(options?: {
|
|
21
|
+
name?: TOptions['name'];
|
|
22
|
+
resolvedOptions?: TOptions['resolvedOptions'];
|
|
23
|
+
inputNode?: Adapter<TOptions>['inputNode'];
|
|
24
|
+
parse?: Adapter<TOptions>['parse'];
|
|
25
|
+
getImports?: Adapter<TOptions>['getImports'];
|
|
26
|
+
}): Adapter<TOptions>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a minimal `Plugin` mock suitable for unit tests.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })
|
|
32
|
+
*/
|
|
33
|
+
declare function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {
|
|
34
|
+
name: TOptions['name'];
|
|
35
|
+
options: TOptions['resolvedOptions'];
|
|
36
|
+
resolver?: TOptions['resolver'];
|
|
37
|
+
transformer?: Visitor;
|
|
38
|
+
dependencies?: Array<string>;
|
|
39
|
+
}): Plugin<TOptions>;
|
|
40
|
+
type RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
41
|
+
config: Config;
|
|
42
|
+
adapter: Adapter;
|
|
43
|
+
driver: PluginDriver;
|
|
44
|
+
plugin: Plugin<TOptions>;
|
|
45
|
+
options: TOptions['resolvedOptions'];
|
|
46
|
+
resolver: TOptions['resolver'];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Renders a generator's `schema` method in a test context.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
53
|
+
* await matchFiles(driver.fileManager.files)
|
|
54
|
+
*/
|
|
55
|
+
declare function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(generator: Generator<TOptions>, node: SchemaNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Renders a generator's `operation` method in a test context.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
61
|
+
* await matchFiles(driver.fileManager.files)
|
|
62
|
+
*/
|
|
63
|
+
declare function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(generator: Generator<TOptions>, node: OperationNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Renders a generator's `operations` method in a test context.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })
|
|
69
|
+
* await matchFiles(driver.fileManager.files)
|
|
70
|
+
*/
|
|
71
|
+
declare function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(generator: Generator<TOptions>, nodes: Array<OperationNode>, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
|
|
72
|
+
//#endregion
|
|
73
|
+
export { createMockedAdapter, createMockedPlugin, createMockedPluginDriver, renderGeneratorOperation, renderGeneratorOperations, renderGeneratorSchema };
|
|
74
|
+
//# sourceMappingURL=mocks.d.ts.map
|
package/dist/mocks.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { i as FileManager, n as getMode, r as applyHookResult } from "./PluginDriver-B_65W4fv.js";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { transform } from "@kubb/ast";
|
|
5
|
+
//#region src/mocks.ts
|
|
6
|
+
function toCamelOrPascal(text, pascal) {
|
|
7
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
8
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
9
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
10
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
11
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
12
|
+
}
|
|
13
|
+
function camelCase(text) {
|
|
14
|
+
return toCamelOrPascal(text, false);
|
|
15
|
+
}
|
|
16
|
+
function pascalCase(text) {
|
|
17
|
+
return toCamelOrPascal(text, true);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a minimal `PluginDriver` mock suitable for unit tests.
|
|
21
|
+
*/
|
|
22
|
+
function createMockedPluginDriver(options = {}) {
|
|
23
|
+
return {
|
|
24
|
+
resolveName: (result) => {
|
|
25
|
+
if (result.type === "file") return camelCase(options?.name || result.name);
|
|
26
|
+
if (result.type === "type") return pascalCase(result.name);
|
|
27
|
+
if (result.type === "function") return camelCase(result.name);
|
|
28
|
+
return camelCase(result.name);
|
|
29
|
+
},
|
|
30
|
+
config: options?.config ?? {
|
|
31
|
+
root: ".",
|
|
32
|
+
output: { path: "./path" }
|
|
33
|
+
},
|
|
34
|
+
resolvePath: ({ baseName }) => baseName,
|
|
35
|
+
getFile: ({ name, extname, pluginName, options: fileOptions }) => {
|
|
36
|
+
const baseName = `${name}${extname}`;
|
|
37
|
+
const groupDir = fileOptions?.group?.tag ?? fileOptions?.group?.path?.split("/").filter(Boolean)[0];
|
|
38
|
+
return {
|
|
39
|
+
path: groupDir ? `${groupDir}/${baseName}` : baseName,
|
|
40
|
+
baseName,
|
|
41
|
+
meta: { pluginName }
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
getPlugin(_pluginName) {
|
|
45
|
+
return options?.plugin;
|
|
46
|
+
},
|
|
47
|
+
fileManager: new FileManager()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a minimal `Adapter` mock suitable for unit tests.
|
|
52
|
+
*
|
|
53
|
+
* - `parse` returns an empty `InputNode` by default; override via `options.parse`.
|
|
54
|
+
* - `getImports` returns `[]` by default (single-file mode, no cross-file imports).
|
|
55
|
+
*/
|
|
56
|
+
function createMockedAdapter(options = {}) {
|
|
57
|
+
return {
|
|
58
|
+
name: options.name ?? "oas",
|
|
59
|
+
options: options.resolvedOptions ?? {},
|
|
60
|
+
inputNode: options.inputNode ?? null,
|
|
61
|
+
parse: options.parse ?? (async () => ({
|
|
62
|
+
kind: "Input",
|
|
63
|
+
schemas: [],
|
|
64
|
+
operations: []
|
|
65
|
+
})),
|
|
66
|
+
getImports: options.getImports ?? ((_node, _resolve) => [])
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a minimal `Plugin` mock suitable for unit tests.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })
|
|
74
|
+
*/
|
|
75
|
+
function createMockedPlugin(params) {
|
|
76
|
+
return {
|
|
77
|
+
name: params.name,
|
|
78
|
+
options: params.options,
|
|
79
|
+
resolver: params.resolver,
|
|
80
|
+
transformer: params.transformer,
|
|
81
|
+
dependencies: params.dependencies,
|
|
82
|
+
install: () => {},
|
|
83
|
+
inject: () => void 0
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createMockedPluginContext(opts) {
|
|
87
|
+
const root = resolve(opts.config.root, opts.config.output.path);
|
|
88
|
+
return {
|
|
89
|
+
config: opts.config,
|
|
90
|
+
root,
|
|
91
|
+
getMode: (output) => getMode(resolve(root, output.path)),
|
|
92
|
+
adapter: opts.adapter,
|
|
93
|
+
resolver: opts.resolver,
|
|
94
|
+
plugin: opts.plugin,
|
|
95
|
+
driver: opts.driver,
|
|
96
|
+
inputNode: {
|
|
97
|
+
kind: "Input",
|
|
98
|
+
schemas: [],
|
|
99
|
+
operations: []
|
|
100
|
+
},
|
|
101
|
+
upsertFile: async (...files) => opts.driver.fileManager.upsert(...files),
|
|
102
|
+
warn: (msg) => console.warn(msg),
|
|
103
|
+
error: (msg) => console.error(msg),
|
|
104
|
+
info: (msg) => console.info(msg),
|
|
105
|
+
openInStudio: async () => {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Renders a generator's `schema` method in a test context.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
113
|
+
* await matchFiles(driver.fileManager.files)
|
|
114
|
+
*/
|
|
115
|
+
async function renderGeneratorSchema(generator, node, opts) {
|
|
116
|
+
if (!generator.schema) return;
|
|
117
|
+
const context = createMockedPluginContext(opts);
|
|
118
|
+
const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node;
|
|
119
|
+
await applyHookResult(await generator.schema(transformedNode, {
|
|
120
|
+
...context,
|
|
121
|
+
options: opts.options
|
|
122
|
+
}), opts.driver, generator.renderer ?? void 0);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Renders a generator's `operation` method in a test context.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
129
|
+
* await matchFiles(driver.fileManager.files)
|
|
130
|
+
*/
|
|
131
|
+
async function renderGeneratorOperation(generator, node, opts) {
|
|
132
|
+
if (!generator.operation) return;
|
|
133
|
+
const context = createMockedPluginContext(opts);
|
|
134
|
+
const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node;
|
|
135
|
+
await applyHookResult(await generator.operation(transformedNode, {
|
|
136
|
+
...context,
|
|
137
|
+
options: opts.options
|
|
138
|
+
}), opts.driver, generator.renderer ?? void 0);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Renders a generator's `operations` method in a test context.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })
|
|
145
|
+
* await matchFiles(driver.fileManager.files)
|
|
146
|
+
*/
|
|
147
|
+
async function renderGeneratorOperations(generator, nodes, opts) {
|
|
148
|
+
if (!generator.operations) return;
|
|
149
|
+
const context = createMockedPluginContext(opts);
|
|
150
|
+
const transformedNodes = opts.plugin.transformer ? nodes.map((n) => transform(n, opts.plugin.transformer)) : nodes;
|
|
151
|
+
await applyHookResult(await generator.operations(transformedNodes, {
|
|
152
|
+
...context,
|
|
153
|
+
options: opts.options
|
|
154
|
+
}), opts.driver, generator.renderer ?? void 0);
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
export { createMockedAdapter, createMockedPlugin, createMockedPluginDriver, renderGeneratorOperation, renderGeneratorOperations, renderGeneratorSchema };
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=mocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mocks.js","names":[],"sources":["../src/mocks.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { FileNode, OperationNode, SchemaNode, Visitor } from '@kubb/ast'\nimport { transform } from '@kubb/ast'\nimport { FileManager } from './FileManager.ts'\nimport { getMode, type PluginDriver } from './PluginDriver.ts'\nimport { applyHookResult } from './renderNode.ts'\nimport type {\n Adapter,\n AdapterFactoryOptions,\n Config,\n Generator,\n GeneratorContext,\n Plugin,\n PluginFactoryOptions,\n ResolveNameParams,\n ResolvePathParams,\n} from './types.ts'\n\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\nfunction camelCase(text: string): string {\n return toCamelOrPascal(text, false)\n}\n\nfunction pascalCase(text: string): string {\n return toCamelOrPascal(text, true)\n}\n\n/**\n * Creates a minimal `PluginDriver` mock suitable for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: Plugin<any>; config?: Config } = {}): PluginDriver {\n return {\n resolveName: (result: ResolveNameParams) => {\n if (result.type === 'file') {\n return camelCase(options?.name || result.name)\n }\n\n if (result.type === 'type') {\n return pascalCase(result.name)\n }\n\n if (result.type === 'function') {\n return camelCase(result.name)\n }\n\n return camelCase(result.name)\n },\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n resolvePath: ({ baseName }: ResolvePathParams) => baseName,\n getFile: ({\n name,\n extname,\n pluginName,\n options: fileOptions,\n }: {\n name: string\n extname: `.${string}`\n pluginName: string\n options?: { group?: { tag?: string; path?: string } }\n }) => {\n const baseName = `${name}${extname}`\n const groupDir = fileOptions?.group?.tag ?? fileOptions?.group?.path?.split('/').filter(Boolean)[0]\n const filePath = groupDir ? `${groupDir}/${baseName}` : baseName\n\n return {\n path: filePath,\n baseName,\n meta: { pluginName },\n }\n },\n getPlugin(_pluginName: Plugin['name']): Plugin | undefined {\n return options?.plugin\n },\n fileManager: new FileManager(),\n } as unknown as PluginDriver\n}\n\n/**\n * Creates a minimal `Adapter` mock suitable for unit tests.\n *\n * - `parse` returns an empty `InputNode` by default; override via `options.parse`.\n * - `getImports` returns `[]` by default (single-file mode, no cross-file imports).\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n inputNode?: Adapter<TOptions>['inputNode']\n parse?: Adapter<TOptions>['parse']\n getImports?: Adapter<TOptions>['getImports']\n } = {},\n): Adapter<TOptions> {\n return {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n inputNode: options.inputNode ?? null,\n parse: options.parse ?? (async () => ({ kind: 'Input' as const, schemas: [], operations: [] })),\n getImports: options.getImports ?? ((_node: SchemaNode, _resolve: (schemaName: string) => { name: string; path: string }) => []),\n } as Adapter<TOptions>\n}\n\n/**\n * Creates a minimal `Plugin` mock suitable for unit tests.\n *\n * @example\n * const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })\n */\nexport function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n transformer?: Visitor\n dependencies?: Array<string>\n}): Plugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n transformer: params.transformer,\n dependencies: params.dependencies,\n install: () => {},\n inject: () => undefined as TOptions['context'],\n } as unknown as Plugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {\n config: Config\n adapter: Adapter\n driver: PluginDriver\n plugin: Plugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginFactoryOptions>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n getMode: (output: { path: string }) => getMode(resolve(root, output.path)),\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n inputNode: { kind: 'Input', schemas: [], operations: [] },\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n openInStudio: async () => {},\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n */\nexport async function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n const context = createMockedPluginContext(opts)\n const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node\n const result = await generator.schema(transformedNode, { ...context, options: opts.options })\n await applyHookResult(result, opts.driver, generator.renderer ?? undefined)\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n */\nexport async function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n const context = createMockedPluginContext(opts)\n const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node\n const result = await generator.operation(transformedNode, { ...context, options: opts.options })\n await applyHookResult(result, opts.driver, generator.renderer ?? undefined)\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n */\nexport async function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.transformer ? nodes.map((n) => transform(n, opts.plugin.transformer!)) : nodes\n const result = await generator.operations(transformedNodes, { ...context, options: opts.options })\n await applyHookResult(result, opts.driver, generator.renderer ?? undefined)\n}\n"],"mappings":";;;;;AAkBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;AAGjC,SAAS,UAAU,MAAsB;AACvC,QAAO,gBAAgB,MAAM,MAAM;;AAGrC,SAAS,WAAW,MAAsB;AACxC,QAAO,gBAAgB,MAAM,KAAK;;;;;AAMpC,SAAgB,yBAAyB,UAAoE,EAAE,EAAgB;AAC7H,QAAO;E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a,CAAC,GAAG;AAE9G,OAAM,gBADS,MAAM,UAAU,WAAW,kBAAkB;EAAE,GAAG;EAAS,SAAS,KAAK;EAAS,CAAC,EACpE,KAAK,QAAQ,UAAU,YAAY,KAAA,EAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.36",
|
|
4
4
|
"description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"import": "./dist/hooks.js",
|
|
36
36
|
"require": "./dist/hooks.cjs"
|
|
37
37
|
},
|
|
38
|
+
"./mocks": {
|
|
39
|
+
"import": "./dist/mocks.js",
|
|
40
|
+
"require": "./dist/mocks.cjs"
|
|
41
|
+
},
|
|
38
42
|
"./package.json": "./package.json"
|
|
39
43
|
},
|
|
40
44
|
"types": "./dist/index.d.ts",
|
|
@@ -42,6 +46,9 @@
|
|
|
42
46
|
"*": {
|
|
43
47
|
"hooks": [
|
|
44
48
|
"./dist/hooks.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"mocks": [
|
|
51
|
+
"./dist/mocks.d.ts"
|
|
45
52
|
]
|
|
46
53
|
}
|
|
47
54
|
},
|
|
@@ -68,8 +75,8 @@
|
|
|
68
75
|
"remeda": "^2.33.7",
|
|
69
76
|
"semver": "^7.7.4",
|
|
70
77
|
"tinyexec": "^1.1.1",
|
|
71
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
72
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
78
|
+
"@kubb/ast": "5.0.0-alpha.36",
|
|
79
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.36"
|
|
73
80
|
},
|
|
74
81
|
"devDependencies": {
|
|
75
82
|
"@types/semver": "^7.7.1",
|
|
@@ -77,7 +84,7 @@
|
|
|
77
84
|
"@internals/utils": "0.0.0"
|
|
78
85
|
},
|
|
79
86
|
"peerDependencies": {
|
|
80
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
87
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.36"
|
|
81
88
|
},
|
|
82
89
|
"engines": {
|
|
83
90
|
"node": ">=22"
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ export {
|
|
|
20
20
|
defaultResolvePath,
|
|
21
21
|
defineResolver,
|
|
22
22
|
} from './defineResolver.ts'
|
|
23
|
+
export { FileManager } from './FileManager.ts'
|
|
24
|
+
export { FileProcessor } from './FileProcessor.ts'
|
|
23
25
|
export { getMode, PluginDriver } from './PluginDriver.ts'
|
|
24
26
|
export { fsStorage } from './storages/fsStorage.ts'
|
|
25
27
|
export { memoryStorage } from './storages/memoryStorage.ts'
|