@kubb/core 5.0.0-alpha.9 → 5.0.0-beta.75

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.
Files changed (64) hide show
  1. package/README.md +23 -20
  2. package/dist/PluginDriver-BXibeQk-.cjs +1036 -0
  3. package/dist/PluginDriver-BXibeQk-.cjs.map +1 -0
  4. package/dist/PluginDriver-DV3p2Hky.js +945 -0
  5. package/dist/PluginDriver-DV3p2Hky.js.map +1 -0
  6. package/dist/index.cjs +729 -1641
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +271 -225
  9. package/dist/index.js +713 -1609
  10. package/dist/index.js.map +1 -1
  11. package/dist/mocks.cjs +145 -0
  12. package/dist/mocks.cjs.map +1 -0
  13. package/dist/mocks.d.ts +80 -0
  14. package/dist/mocks.js +140 -0
  15. package/dist/mocks.js.map +1 -0
  16. package/dist/types-CuNocrbJ.d.ts +2148 -0
  17. package/package.json +51 -57
  18. package/src/FileManager.ts +115 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/Kubb.ts +207 -131
  21. package/src/PluginDriver.ts +325 -564
  22. package/src/constants.ts +20 -47
  23. package/src/createAdapter.ts +13 -6
  24. package/src/createKubb.ts +548 -0
  25. package/src/createRenderer.ts +57 -0
  26. package/src/createStorage.ts +13 -1
  27. package/src/defineGenerator.ts +77 -124
  28. package/src/defineLogger.ts +4 -2
  29. package/src/defineMiddleware.ts +62 -0
  30. package/src/defineParser.ts +44 -0
  31. package/src/definePlugin.ts +83 -0
  32. package/src/defineResolver.ts +418 -28
  33. package/src/devtools.ts +14 -14
  34. package/src/index.ts +13 -15
  35. package/src/mocks.ts +178 -0
  36. package/src/renderNode.ts +35 -0
  37. package/src/storages/fsStorage.ts +41 -11
  38. package/src/storages/memoryStorage.ts +4 -2
  39. package/src/types.ts +1031 -283
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/isInputPath.ts +10 -0
  42. package/src/utils/packageJSON.ts +50 -12
  43. package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
  44. package/dist/chunk-ByKO4r7w.cjs +0 -38
  45. package/dist/hooks.cjs +0 -103
  46. package/dist/hooks.cjs.map +0 -1
  47. package/dist/hooks.d.ts +0 -77
  48. package/dist/hooks.js +0 -98
  49. package/dist/hooks.js.map +0 -1
  50. package/src/build.ts +0 -418
  51. package/src/config.ts +0 -56
  52. package/src/createPlugin.ts +0 -28
  53. package/src/hooks/index.ts +0 -4
  54. package/src/hooks/useKubb.ts +0 -143
  55. package/src/hooks/useMode.ts +0 -11
  56. package/src/hooks/usePlugin.ts +0 -11
  57. package/src/hooks/usePluginDriver.ts +0 -11
  58. package/src/utils/FunctionParams.ts +0 -155
  59. package/src/utils/TreeNode.ts +0 -215
  60. package/src/utils/executeStrategies.ts +0 -81
  61. package/src/utils/formatters.ts +0 -56
  62. package/src/utils/getBarrelFiles.ts +0 -141
  63. package/src/utils/getConfigs.ts +0 -12
  64. package/src/utils/linters.ts +0 -25
@@ -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
- * Get diagnostic information for debugging
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
+ }
@@ -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 | undefined {
14
- const pkgPath = pkg.up({ cwd })
11
+ function getPackageJSONSync(cwd?: string): PackageJSON | null {
12
+ const pkgPath = findPackageJSON(cwd)
15
13
  if (!pkgPath) {
16
- return undefined
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 | undefined {
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] : undefined
32
+ return matched ? (dependencies[matched] ?? null) : null
35
33
  }
36
34
 
37
- function getVersionSync(dependency: DependencyName | RegExp, cwd?: string): DependencyVersion | undefined {
35
+ function getVersionSync(dependency: DependencyName | RegExp, cwd?: string): DependencyVersion | null {
38
36
  const packageJSON = getPackageJSONSync(cwd)
39
37
 
40
- return packageJSON ? match(packageJSON, dependency) : undefined
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 = coerce(packageVersion)
92
+ const semVer = coerceSemver(packageVersion)
55
93
 
56
94
  if (!semVer) {
57
95
  return false
58
96
  }
59
97
 
60
- return satisfies(semVer, version)
98
+ return satisfiesSemver(semVer, version)
61
99
  }