@kubb/mcp 5.0.0-beta.7 → 5.0.0-beta.71

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.
@@ -1,78 +0,0 @@
1
- import { existsSync } from 'node:fs'
2
- import path from 'node:path'
3
- import type { Config } from '@kubb/core'
4
- import { createJiti } from 'jiti'
5
- import { ALLOWED_CONFIG_EXTENSIONS } from '../constants.ts'
6
- import { NotifyTypes } from '../types.ts'
7
-
8
- type NotifyFunction = (type: string, message: string, data?: Record<string, unknown>) => Promise<void>
9
-
10
- const jiti = createJiti(import.meta.url, {
11
- jsx: {
12
- runtime: 'automatic',
13
- importSource: '@kubb/renderer-jsx',
14
- },
15
- moduleCache: false,
16
- })
17
-
18
- const loadedModules = new Map<string, unknown>()
19
-
20
- async function loadModule(filePath: string): Promise<unknown> {
21
- const ext = path.extname(filePath)
22
- if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {
23
- throw new Error(`Invalid config file extension "${ext}". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`)
24
- }
25
- if (loadedModules.has(filePath)) {
26
- return loadedModules.get(filePath)
27
- }
28
- const mod = await jiti.import(filePath, { default: true })
29
- loadedModules.set(filePath, mod)
30
- return mod
31
- }
32
-
33
- export async function loadUserConfig(configPath: string | undefined, { notify }: { notify: NotifyFunction }): Promise<{ userConfig: Config; cwd: string }> {
34
- if (configPath) {
35
- const ext = path.extname(configPath)
36
- if (!ALLOWED_CONFIG_EXTENSIONS.has(ext)) {
37
- const msg = `Invalid config file extension "${ext}". Allowed: ${[...ALLOWED_CONFIG_EXTENSIONS].join(', ')}`
38
- await notify(NotifyTypes.CONFIG_ERROR, msg)
39
- throw new Error(msg)
40
- }
41
- const base = path.resolve(process.cwd())
42
- const resolvedConfigPath = path.resolve(base, configPath)
43
- const relative = path.relative(base, resolvedConfigPath)
44
- if (relative.startsWith('..') || path.isAbsolute(relative)) {
45
- const msg = 'Invalid config file path: must be within the current working directory'
46
- await notify(NotifyTypes.CONFIG_ERROR, msg)
47
- throw new Error(msg)
48
- }
49
- const cwd = path.dirname(resolvedConfigPath)
50
- try {
51
- const userConfig = (await loadModule(resolvedConfigPath)) as Config
52
- await notify(NotifyTypes.CONFIG_LOADED, `Loaded config from ${resolvedConfigPath}`)
53
- return { userConfig, cwd }
54
- } catch (error) {
55
- const msg = `Failed to load config: ${error instanceof Error ? error.message : String(error)}`
56
- await notify(NotifyTypes.CONFIG_ERROR, msg)
57
- throw new Error(msg)
58
- }
59
- }
60
-
61
- const cwd = process.cwd()
62
- const configFileNames = ['kubb.config.ts', 'kubb.config.mts', 'kubb.config.cts', 'kubb.config.js', 'kubb.config.cjs']
63
-
64
- for (const configFileName of configFileNames) {
65
- const configFilePath = path.resolve(process.cwd(), configFileName)
66
- if (!existsSync(configFilePath)) continue
67
- try {
68
- const userConfig = (await loadModule(configFilePath)) as Config
69
- await notify(NotifyTypes.CONFIG_LOADED, `Loaded ${configFileName} from current directory`)
70
- return { userConfig, cwd }
71
- } catch (err) {
72
- await notify(NotifyTypes.CONFIG_ERROR, `Failed to load ${configFileName}: ${err instanceof Error ? err.message : String(err)}`)
73
- }
74
- }
75
-
76
- await notify(NotifyTypes.CONFIG_ERROR, 'No config file found')
77
- throw new Error(`No config file found. Please provide a config path or create one of: ${configFileNames.join(', ')}`)
78
- }
@@ -1,20 +0,0 @@
1
- import path from 'node:path'
2
- import type { Config } from '@kubb/core'
3
-
4
- /**
5
- * Determine the root directory based on userConfig.root and resolvedConfigDir
6
- * 1. If userConfig.root exists and is absolute, use it as-is
7
- * 2. If userConfig.root exists and is relative, resolve it relative to config directory
8
- * 3. Otherwise, use the config directory as root
9
- */
10
- export function resolveCwd(userConfig: Config, cwd: string): string {
11
- if (userConfig.root) {
12
- if (path.isAbsolute(userConfig.root)) {
13
- return userConfig.root
14
- }
15
-
16
- return path.resolve(cwd, userConfig.root)
17
- }
18
-
19
- return cwd
20
- }
@@ -1,13 +0,0 @@
1
- import { isPromise } from '@internals/utils'
2
- import type { CLIOptions, Config, PossibleConfig } from '@kubb/core'
3
-
4
- export type ResolveUserConfigOptions = {
5
- configPath?: string
6
- logLevel?: string
7
- }
8
-
9
- export async function resolveUserConfig(config: PossibleConfig<CLIOptions>, options: ResolveUserConfigOptions): Promise<Config> {
10
- const result = typeof config === 'function' ? config({ logLevel: options.logLevel as CLIOptions['logLevel'], config: options.configPath }) : config
11
- const resolved = isPromise(result) ? await result : result
12
- return (Array.isArray(resolved) ? resolved[0] : resolved) as Config
13
- }