@kubb/core 5.0.0-alpha.9 → 5.0.0-beta.1
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 +23 -20
- package/dist/PluginDriver-BXibeQk-.cjs +1036 -0
- package/dist/PluginDriver-BXibeQk-.cjs.map +1 -0
- package/dist/PluginDriver-DV3p2Hky.js +945 -0
- package/dist/PluginDriver-DV3p2Hky.js.map +1 -0
- package/dist/index.cjs +729 -1641
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +271 -225
- package/dist/index.js +713 -1609
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +145 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +80 -0
- package/dist/mocks.js +140 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-CuNocrbJ.d.ts +2148 -0
- package/package.json +51 -57
- package/src/FileManager.ts +115 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +207 -131
- package/src/PluginDriver.ts +325 -564
- package/src/constants.ts +20 -47
- package/src/createAdapter.ts +13 -6
- package/src/createKubb.ts +548 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +13 -1
- package/src/defineGenerator.ts +77 -124
- package/src/defineLogger.ts +4 -2
- package/src/defineMiddleware.ts +62 -0
- package/src/defineParser.ts +44 -0
- package/src/definePlugin.ts +83 -0
- package/src/defineResolver.ts +418 -28
- package/src/devtools.ts +14 -14
- package/src/index.ts +13 -15
- package/src/mocks.ts +178 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +41 -11
- package/src/storages/memoryStorage.ts +4 -2
- package/src/types.ts +1031 -283
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +50 -12
- package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -103
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -77
- package/dist/hooks.js +0 -98
- package/dist/hooks.js.map +0 -1
- package/src/build.ts +0 -418
- package/src/config.ts +0 -56
- package/src/createPlugin.ts +0 -28
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -143
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginDriver.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 -141
- package/src/utils/getConfigs.ts +0 -12
- package/src/utils/linters.ts +0 -25
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
|
+
}
|
package/src/utils/packageJSON.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { readSync } from '@internals/utils'
|
|
2
|
-
import * as pkg from 'empathic/package'
|
|
3
|
-
import { coerce, satisfies } from 'semver'
|
|
1
|
+
import { findPackageJSON, readSync } from '@internals/utils'
|
|
4
2
|
|
|
5
3
|
type PackageJSON = {
|
|
6
4
|
dependencies?: Record<string, string>
|
|
@@ -10,16 +8,16 @@ type PackageJSON = {
|
|
|
10
8
|
type DependencyName = string
|
|
11
9
|
type DependencyVersion = string
|
|
12
10
|
|
|
13
|
-
function getPackageJSONSync(cwd?: string): PackageJSON |
|
|
14
|
-
const pkgPath =
|
|
11
|
+
function getPackageJSONSync(cwd?: string): PackageJSON | null {
|
|
12
|
+
const pkgPath = findPackageJSON(cwd)
|
|
15
13
|
if (!pkgPath) {
|
|
16
|
-
return
|
|
14
|
+
return null
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
return JSON.parse(readSync(pkgPath)) as PackageJSON
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
function match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string |
|
|
20
|
+
function match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string | null {
|
|
23
21
|
const dependencies = {
|
|
24
22
|
...(packageJSON.dependencies || {}),
|
|
25
23
|
...(packageJSON.devDependencies || {}),
|
|
@@ -31,13 +29,53 @@ function match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): s
|
|
|
31
29
|
|
|
32
30
|
const matched = Object.keys(dependencies).find((dep) => dep.match(dependency))
|
|
33
31
|
|
|
34
|
-
return matched ? dependencies[matched] :
|
|
32
|
+
return matched ? (dependencies[matched] ?? null) : null
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
function getVersionSync(dependency: DependencyName | RegExp, cwd?: string): DependencyVersion |
|
|
35
|
+
function getVersionSync(dependency: DependencyName | RegExp, cwd?: string): DependencyVersion | null {
|
|
38
36
|
const packageJSON = getPackageJSONSync(cwd)
|
|
39
37
|
|
|
40
|
-
return packageJSON ? match(packageJSON, dependency) :
|
|
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
|
+
})
|
|
41
79
|
}
|
|
42
80
|
|
|
43
81
|
export function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean {
|
|
@@ -51,11 +89,11 @@ export function satisfiesDependency(dependency: DependencyName | RegExp, version
|
|
|
51
89
|
return true
|
|
52
90
|
}
|
|
53
91
|
|
|
54
|
-
const semVer =
|
|
92
|
+
const semVer = coerceSemver(packageVersion)
|
|
55
93
|
|
|
56
94
|
if (!semVer) {
|
|
57
95
|
return false
|
|
58
96
|
}
|
|
59
97
|
|
|
60
|
-
return
|
|
98
|
+
return satisfiesSemver(semVer, version)
|
|
61
99
|
}
|