@kubb/core 5.0.0-alpha.6 → 5.0.0-alpha.61
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/README.md +3 -2
- package/dist/PluginDriver-Bc0HQM8V.js +948 -0
- package/dist/PluginDriver-Bc0HQM8V.js.map +1 -0
- package/dist/PluginDriver-Dyl2fwfQ.cjs +1039 -0
- package/dist/PluginDriver-Dyl2fwfQ.cjs.map +1 -0
- package/dist/index.cjs +691 -1798
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +279 -265
- package/dist/index.js +678 -1765
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +138 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +133 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-mW3-Ihuf.d.ts +1903 -0
- package/package.json +51 -57
- package/src/FileManager.ts +110 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +205 -130
- package/src/PluginDriver.ts +424 -0
- package/src/constants.ts +20 -47
- package/src/createAdapter.ts +25 -0
- package/src/createKubb.ts +527 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +58 -0
- package/src/defineGenerator.ts +88 -100
- package/src/defineLogger.ts +13 -3
- package/src/defineMiddleware.ts +59 -0
- package/src/defineParser.ts +45 -0
- package/src/definePlugin.ts +78 -7
- package/src/defineResolver.ts +521 -0
- package/src/devtools.ts +14 -14
- package/src/index.ts +13 -17
- package/src/mocks.ts +171 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +40 -11
- package/src/storages/memoryStorage.ts +4 -3
- package/src/types.ts +738 -218
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +99 -0
- package/dist/PluginManager-vZodFEMe.d.ts +0 -1056
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -60
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -64
- package/dist/hooks.js +0 -56
- package/dist/hooks.js.map +0 -1
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PluginManager.ts +0 -667
- package/src/PromiseManager.ts +0 -40
- package/src/build.ts +0 -419
- package/src/config.ts +0 -56
- package/src/defineAdapter.ts +0 -22
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -55
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginManager.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/TreeNode.ts +0 -215
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getBarrelFiles.ts +0 -79
- package/src/utils/getConfigs.ts +0 -30
- package/src/utils/getPlugins.ts +0 -23
- package/src/utils/linters.ts +0 -25
- package/src/utils/resolveOptions.ts +0 -93
package/src/utils/diagnostics.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { version as nodeVersion } from 'node:process'
|
|
|
2
2
|
import { version as KubbVersion } from '../../package.json'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Returns a snapshot of the current runtime environment.
|
|
6
|
+
*
|
|
7
|
+
* Useful for attaching context to debug logs and error reports so that
|
|
8
|
+
* issues can be reproduced without manual information gathering.
|
|
6
9
|
*/
|
|
7
10
|
export function getDiagnosticInfo() {
|
|
8
11
|
return {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config, InputPath, UserConfig } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a given config has an `input.path`.
|
|
5
|
+
*/
|
|
6
|
+
export function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>
|
|
7
|
+
export function isInputPath(config: Config | undefined): config is Config<InputPath>
|
|
8
|
+
export function isInputPath(config: Config | UserConfig | undefined): config is Config<InputPath> | UserConfig<InputPath> {
|
|
9
|
+
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
10
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { findPackageJSON, readSync } from '@internals/utils'
|
|
2
|
+
|
|
3
|
+
type PackageJSON = {
|
|
4
|
+
dependencies?: Record<string, string>
|
|
5
|
+
devDependencies?: Record<string, string>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type DependencyName = string
|
|
9
|
+
type DependencyVersion = string
|
|
10
|
+
|
|
11
|
+
function getPackageJSONSync(cwd?: string): PackageJSON | null {
|
|
12
|
+
const pkgPath = findPackageJSON(cwd)
|
|
13
|
+
if (!pkgPath) {
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return JSON.parse(readSync(pkgPath)) as PackageJSON
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string | null {
|
|
21
|
+
const dependencies = {
|
|
22
|
+
...(packageJSON.dependencies || {}),
|
|
23
|
+
...(packageJSON.devDependencies || {}),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof dependency === 'string' && dependencies[dependency]) {
|
|
27
|
+
return dependencies[dependency]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const matched = Object.keys(dependencies).find((dep) => dep.match(dependency))
|
|
31
|
+
|
|
32
|
+
return matched ? (dependencies[matched] ?? null) : null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getVersionSync(dependency: DependencyName | RegExp, cwd?: string): DependencyVersion | null {
|
|
36
|
+
const packageJSON = getPackageJSONSync(cwd)
|
|
37
|
+
|
|
38
|
+
return packageJSON ? match(packageJSON, dependency) : null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns `true` when the nearest `package.json` declares a dependency that
|
|
43
|
+
* satisfies the given semver range.
|
|
44
|
+
*
|
|
45
|
+
* - Searches both `dependencies` and `devDependencies`.
|
|
46
|
+
* - Accepts a string package name or a `RegExp` to match scoped/pattern packages.
|
|
47
|
+
* - Uses `semver.satisfies` for range comparison; returns `false` when the
|
|
48
|
+
* version string cannot be coerced into a valid semver.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* satisfiesDependency('react', '>=18') // true when react@18.x is installed
|
|
53
|
+
* satisfiesDependency(/^@tanstack\//, '>=5') // true when any @tanstack/* >=5 is found
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function coerceSemver(version: string): [number, number, number] | null {
|
|
57
|
+
const m = version.match(/(\d+)(?:\.(\d+))?(?:\.(\d+))?/)
|
|
58
|
+
return m ? [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)] : null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function satisfiesSemver(v: [number, number, number], range: string): boolean {
|
|
62
|
+
return range
|
|
63
|
+
.trim()
|
|
64
|
+
.split(/\s+/)
|
|
65
|
+
.every((cond) => {
|
|
66
|
+
const m = cond.match(/^(>=|<=|>|<|=|\^|~)?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/)
|
|
67
|
+
if (!m) return false
|
|
68
|
+
const op = m[1] ?? '='
|
|
69
|
+
const r: [number, number, number] = [Number(m[2]), Number(m[3] ?? 0), Number(m[4] ?? 0)]
|
|
70
|
+
const cmp = v[0] !== r[0] ? v[0] - r[0] : v[1] !== r[1] ? v[1] - r[1] : v[2] - r[2]
|
|
71
|
+
if (op === '>=') return cmp >= 0
|
|
72
|
+
if (op === '<=') return cmp <= 0
|
|
73
|
+
if (op === '>') return cmp > 0
|
|
74
|
+
if (op === '<') return cmp < 0
|
|
75
|
+
if (op === '^') return v[0] === r[0] && cmp >= 0
|
|
76
|
+
if (op === '~') return v[0] === r[0] && v[1] === r[1] && cmp >= 0
|
|
77
|
+
return cmp === 0
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean {
|
|
82
|
+
const packageVersion = getVersionSync(dependency, cwd)
|
|
83
|
+
|
|
84
|
+
if (!packageVersion) {
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (packageVersion === version) {
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const semVer = coerceSemver(packageVersion)
|
|
93
|
+
|
|
94
|
+
if (!semVer) {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return satisfiesSemver(semVer, version)
|
|
99
|
+
}
|