@kubb/core 5.0.0-alpha.8 → 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.
Files changed (70) 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 +756 -1693
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +297 -239
  9. package/dist/index.js +743 -1661
  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 +208 -160
  21. package/src/PluginDriver.ts +326 -565
  22. package/src/constants.ts +20 -47
  23. package/src/createAdapter.ts +16 -6
  24. package/src/createKubb.ts +548 -0
  25. package/src/createRenderer.ts +57 -0
  26. package/src/createStorage.ts +40 -26
  27. package/src/defineGenerator.ts +87 -0
  28. package/src/defineLogger.ts +19 -0
  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 +521 -0
  33. package/src/devtools.ts +14 -14
  34. package/src/index.ts +14 -17
  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 +1054 -270
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/isInputPath.ts +10 -0
  42. package/src/utils/packageJSON.ts +99 -0
  43. package/dist/PluginDriver-DRfJIbG1.d.ts +0 -1056
  44. package/dist/chunk-ByKO4r7w.cjs +0 -38
  45. package/dist/hooks.cjs +0 -102
  46. package/dist/hooks.cjs.map +0 -1
  47. package/dist/hooks.d.ts +0 -75
  48. package/dist/hooks.js +0 -97
  49. package/dist/hooks.js.map +0 -1
  50. package/src/PackageManager.ts +0 -180
  51. package/src/build.ts +0 -419
  52. package/src/config.ts +0 -56
  53. package/src/createGenerator.ts +0 -106
  54. package/src/createLogger.ts +0 -7
  55. package/src/createPlugin.ts +0 -12
  56. package/src/errors.ts +0 -1
  57. package/src/hooks/index.ts +0 -4
  58. package/src/hooks/useKubb.ts +0 -138
  59. package/src/hooks/useMode.ts +0 -11
  60. package/src/hooks/usePlugin.ts +0 -11
  61. package/src/hooks/usePluginDriver.ts +0 -11
  62. package/src/utils/FunctionParams.ts +0 -155
  63. package/src/utils/TreeNode.ts +0 -215
  64. package/src/utils/executeStrategies.ts +0 -81
  65. package/src/utils/formatters.ts +0 -56
  66. package/src/utils/getBarrelFiles.ts +0 -141
  67. package/src/utils/getConfigs.ts +0 -30
  68. package/src/utils/getPlugins.ts +0 -23
  69. package/src/utils/linters.ts +0 -25
  70. package/src/utils/resolveOptions.ts +0 -93
@@ -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
+ }
@@ -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
+ }