@kubb/core 5.10.2 → 5.10.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/{Hookable-Bjfoua7Y.js → Hookable-D_Eafz_X.js} +11 -4
- package/dist/{Hookable-Bjfoua7Y.js.map → Hookable-D_Eafz_X.js.map} +1 -1
- package/dist/{createAdapter-CMnLz31B.d.ts → createAdapter-B5kKMsWV.d.ts} +1 -2
- package/dist/index.cjs +2918 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3763 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts +1 -2
- package/dist/mocks.js +1 -2
- package/dist/mocks.js.map +1 -1
- package/package.json +20 -8
- package/dist/Hookable-RTuEiBd9.cjs +0 -3044
- package/dist/Hookable-RTuEiBd9.cjs.map +0 -1
- package/dist/mocks.cjs +0 -209
- package/dist/mocks.cjs.map +0 -1
- package/dist/rolldown-runtime-CRm0XQPb.js +0 -9
package/dist/mocks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.js","names":[],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginType } from './definePlugin.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginType = PluginType>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginType> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginType>(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 adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginType, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.fileManager.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginType>(\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.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.fileManager.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAI,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;GAC3D,OAAO,SAAS;EAClB;EACA,cAAc,gBAAwB,SAAS,QAAQ;E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WA,eAAsB,0BACpB,WACA,OACA,MACe;CACf,IAAI,CAAC,UAAU,YAAY;CAC3B,MAAM,UAAU,0BAA0B,IAAI;CAC9C,MAAM,mBAAmB,KAAK,OAAO,QAAQ,SAAS,MAAM,KAAK,MAAM,YAAY,GAAG,KAAK,OAAO,MAAO,CAAC,IAAI;CAC9G,MAAM,SAAS,MAAM,UAAU,WAAW,kBAAkB;EAC1D,GAAG;EACH,SAAS,KAAK;CAChB,CAAC;CACD,MAAM,KAAK,OAAO,YAAY,SAAS;EAAE;EAAQ,UAAU,UAAU;CAAS,CAAC;AACjF;;;;;;;;;;;AA6BA,eAAsB,WAAW,OAAoC,UAA6B,CAAC,GAA6C;CAC9I,IAAI,CAAC,OAAO,QAAQ;CAEpB,MAAM,EAAE,0BAAU,IAAI,IAAI,GAAG,QAAQ,QAAQ;CAC7C,MAAM,cAAc,IAAI,YAAY;CACpC,MAAM,4BAAY,IAAI,IAAoB;CAE1C,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,MAAM,QAAQ,UAAU,IAAI,KAAK,IAAI,GACxC;EAGF,MAAM,SAAS,MAAM,YAAY,MAAM,MAAM,EAAE,QAAQ,CAAC;EACxD,MAAM,OAAO,KAAK,SAAS,SAAS,OAAO,KAAK,CAAC,SAAS,SAAS,MAAM,OAAO,MAAM;EAEtF,UAAU,IAAI,KAAK,MAAM,IAAI;EAE7B,MAAM,eAAe,KAAK,KAAK,iBAAiB,GAAI,MAAM,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,GAAI,KAAK,QAAQ;EAC/F,MAAM,OAAO,IAAI,CAAC,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"mocks.js","names":[],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginType } from './definePlugin.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginType = PluginType>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginType> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginType>(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 adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginType, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.fileManager.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginType>(\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.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.fileManager.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAI,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;GAC3D,OAAO,SAAS;EAClB;EACA,cAAc,gBAAwB,SAAS,QAAQ;EACvD;CACF;AACF;;AAGA,SAAgB,yBAAmE,EACjF,UAAU,CAAC,GACX,UAAU,CAAC,MACmD,CAAC,GAAqC;CACpG,MAAM,aAAa,QAAQ,KAAK,UAAU,EAAE,KAAK,EAAuB;CAExE,OAAO;EACL,QAAQ,EAAE,SAAS,WAAW;EAC9B;EACA,cAAc,GAAG,GAAG;EACpB,aAAa,GAAG,GAAG;EACnB,UAAU,GAAG,GAAG;EAChB,WAAW,GAAG,GAAG;EACjB,YAAY,GAAG,GAAG;EAClB,YAAY,GAAG,GAAG;EAClB,eAAe,GAAG,IAAI,eAAuB;GAC3C,MAAM,SAAS,WAAW,MAAM,UAAU,MAAM,SAAS,UAAU;GACnE,IAAI,CAAC,QAAQ,MAAM,oBAAoB,EAAE,WAAW,CAAC;GACrD,OAAO;EACT,CAAC;CACH;AACF;;;;;AAMA,SAAgB,oBACd,UAII,CAAC,GACc;CAQnB,OAAO;EANL,MAAO,QAAQ,QAAQ;EACvB,SAAU,QAAQ,mBAAmB,CAAC;EACtC,UAAU;EACV,OAAO,QAAQ,UAAU,YAAY,IAAI,QAAQ,YAAY;EAC7D,UAAU,YAAY,CAAC;CAEZ;AACf;;;;;;;AAQA,SAAgB,mBAA6D,QAM9C;CAC7B,OAAO;EACL,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf,cAAc,OAAO;EACrB,OAAO,CAAC;CAC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KAAK,iBAAiB,GAAI,MAAM,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,GAAI,KAAK,QAAQ;EAC/F,MAAM,OAAO,IAAI,CAAC,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.4",
|
|
4
4
|
"description": "Core engine for Kubb. Provides the plugin driver, file manager and build orchestration used by every Kubb plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generator",
|
|
@@ -56,14 +56,18 @@
|
|
|
56
56
|
},
|
|
57
57
|
"exports": {
|
|
58
58
|
".": {
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/index.d.ts",
|
|
61
|
+
"default": "./dist/index.js"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./dist/index.d.cts",
|
|
65
|
+
"default": "./dist/index.cjs"
|
|
66
|
+
}
|
|
62
67
|
},
|
|
63
68
|
"./mocks": {
|
|
64
69
|
"types": "./dist/mocks.d.ts",
|
|
65
|
-
"
|
|
66
|
-
"require": "./dist/mocks.cjs"
|
|
70
|
+
"default": "./dist/mocks.js"
|
|
67
71
|
},
|
|
68
72
|
"./schemas/*": "./schemas/*",
|
|
69
73
|
"./package.json": "./package.json"
|
|
@@ -73,7 +77,7 @@
|
|
|
73
77
|
"registry": "https://registry.npmjs.org/"
|
|
74
78
|
},
|
|
75
79
|
"dependencies": {
|
|
76
|
-
"@kubb/ast": "5.10.
|
|
80
|
+
"@kubb/ast": "5.10.4",
|
|
77
81
|
"tinyexec": "^1.3.1",
|
|
78
82
|
"unstorage": "^1.17.5",
|
|
79
83
|
"verkit": "^0.5.0"
|
|
@@ -82,8 +86,16 @@
|
|
|
82
86
|
"@internals/utils": "0.0.1",
|
|
83
87
|
"vue": "^3.5.43"
|
|
84
88
|
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"vitest": "^4.0.0 || ^5.0.0"
|
|
91
|
+
},
|
|
92
|
+
"peerDependenciesMeta": {
|
|
93
|
+
"vitest": {
|
|
94
|
+
"optional": true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
85
97
|
"engines": {
|
|
86
|
-
"node": ">=22"
|
|
98
|
+
"node": ">=22.12"
|
|
87
99
|
},
|
|
88
100
|
"scripts": {
|
|
89
101
|
"build": "tsdown",
|