@kubb/core 5.0.0-alpha.4 → 5.0.0-alpha.41

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 (71) hide show
  1. package/dist/PluginDriver-BQwm8hDd.cjs +1729 -0
  2. package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
  3. package/dist/PluginDriver-CgXFtmNP.js +1617 -0
  4. package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
  5. package/dist/index.cjs +915 -1901
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +268 -264
  8. package/dist/index.js +894 -1863
  9. package/dist/index.js.map +1 -1
  10. package/dist/mocks.cjs +164 -0
  11. package/dist/mocks.cjs.map +1 -0
  12. package/dist/mocks.d.ts +74 -0
  13. package/dist/mocks.js +159 -0
  14. package/dist/mocks.js.map +1 -0
  15. package/dist/types-C6NCtNqM.d.ts +2151 -0
  16. package/package.json +11 -14
  17. package/src/FileManager.ts +131 -0
  18. package/src/FileProcessor.ts +84 -0
  19. package/src/Kubb.ts +174 -85
  20. package/src/PluginDriver.ts +941 -0
  21. package/src/constants.ts +33 -43
  22. package/src/createAdapter.ts +25 -0
  23. package/src/createKubb.ts +605 -0
  24. package/src/createPlugin.ts +31 -0
  25. package/src/createRenderer.ts +57 -0
  26. package/src/createStorage.ts +58 -0
  27. package/src/defineGenerator.ts +88 -100
  28. package/src/defineLogger.ts +13 -3
  29. package/src/defineParser.ts +45 -0
  30. package/src/definePlugin.ts +90 -7
  31. package/src/defineResolver.ts +453 -0
  32. package/src/devtools.ts +14 -14
  33. package/src/index.ts +12 -17
  34. package/src/mocks.ts +234 -0
  35. package/src/renderNode.ts +35 -0
  36. package/src/storages/fsStorage.ts +29 -9
  37. package/src/storages/memoryStorage.ts +2 -2
  38. package/src/types.ts +821 -152
  39. package/src/utils/TreeNode.ts +47 -9
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/executeStrategies.ts +16 -13
  42. package/src/utils/getBarrelFiles.ts +88 -15
  43. package/src/utils/isInputPath.ts +10 -0
  44. package/src/utils/packageJSON.ts +75 -0
  45. package/dist/chunk-ByKO4r7w.cjs +0 -38
  46. package/dist/hooks.cjs +0 -50
  47. package/dist/hooks.cjs.map +0 -1
  48. package/dist/hooks.d.ts +0 -49
  49. package/dist/hooks.js +0 -46
  50. package/dist/hooks.js.map +0 -1
  51. package/dist/types-Bbh1o0yW.d.ts +0 -1057
  52. package/src/BarrelManager.ts +0 -74
  53. package/src/PackageManager.ts +0 -180
  54. package/src/PluginManager.ts +0 -668
  55. package/src/PromiseManager.ts +0 -40
  56. package/src/build.ts +0 -420
  57. package/src/config.ts +0 -56
  58. package/src/defineAdapter.ts +0 -22
  59. package/src/defineStorage.ts +0 -56
  60. package/src/errors.ts +0 -1
  61. package/src/hooks/index.ts +0 -8
  62. package/src/hooks/useKubb.ts +0 -22
  63. package/src/hooks/useMode.ts +0 -11
  64. package/src/hooks/usePlugin.ts +0 -11
  65. package/src/hooks/usePluginManager.ts +0 -11
  66. package/src/utils/FunctionParams.ts +0 -155
  67. package/src/utils/formatters.ts +0 -56
  68. package/src/utils/getConfigs.ts +0 -30
  69. package/src/utils/getPlugins.ts +0 -23
  70. package/src/utils/linters.ts +0 -25
  71. package/src/utils/resolveOptions.ts +0 -93
@@ -1,74 +0,0 @@
1
- /** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
2
- import { join } from 'node:path'
3
- import { getRelativePath } from '@internals/utils'
4
- import type { KubbFile } from '@kubb/fabric-core/types'
5
-
6
- import type { FileMetaBase } from './utils/getBarrelFiles.ts'
7
- import { TreeNode } from './utils/TreeNode.ts'
8
-
9
- export class BarrelManager {
10
- getFiles({ files: generatedFiles, root }: { files: KubbFile.File[]; root?: string; meta?: FileMetaBase | undefined }): Array<KubbFile.File> {
11
- const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()
12
-
13
- TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
14
- if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
15
- return
16
- }
17
-
18
- const barrelFile: KubbFile.File = {
19
- path: join(treeNode.parent?.data.path, 'index.ts') as KubbFile.Path,
20
- baseName: 'index.ts',
21
- exports: [],
22
- imports: [],
23
- sources: [],
24
- }
25
- const previousBarrelFile = cachedFiles.get(barrelFile.path)
26
- const leaves = treeNode.leaves
27
-
28
- leaves.forEach((item) => {
29
- if (!item.data.name) {
30
- return
31
- }
32
-
33
- const sources = item.data.file?.sources || []
34
-
35
- sources.forEach((source) => {
36
- if (!item.data.file?.path || !source.isIndexable || !source.name) {
37
- return
38
- }
39
- const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some(
40
- (item) => item.name === source.name && item.isTypeOnly === source.isTypeOnly,
41
- )
42
-
43
- if (alreadyContainInPreviousBarrelFile) {
44
- return
45
- }
46
-
47
- barrelFile.exports!.push({
48
- name: [source.name],
49
- path: getRelativePath(treeNode.parent?.data.path, item.data.path),
50
- isTypeOnly: source.isTypeOnly,
51
- })
52
-
53
- barrelFile.sources.push({
54
- name: source.name,
55
- isTypeOnly: source.isTypeOnly,
56
- //TODO use parser to generate import
57
- value: '',
58
- isExportable: false,
59
- isIndexable: false,
60
- })
61
- })
62
- })
63
-
64
- if (previousBarrelFile) {
65
- previousBarrelFile.sources.push(...barrelFile.sources)
66
- previousBarrelFile.exports?.push(...(barrelFile.exports || []))
67
- } else {
68
- cachedFiles.set(barrelFile.path, barrelFile)
69
- }
70
- })
71
-
72
- return [...cachedFiles.values()]
73
- }
74
- }
@@ -1,180 +0,0 @@
1
- import mod from 'node:module'
2
- import os from 'node:os'
3
- import { pathToFileURL } from 'node:url'
4
- import { read, readSync } from '@internals/utils'
5
- import * as pkg from 'empathic/package'
6
- import { coerce, satisfies } from 'semver'
7
- import { PATH_SEPARATORS } from './constants.ts'
8
-
9
- type PackageJSON = {
10
- dependencies?: Record<string, string>
11
- devDependencies?: Record<string, string>
12
- }
13
-
14
- type DependencyName = string
15
-
16
- type DependencyVersion = string
17
-
18
- export class PackageManager {
19
- static #cache: Record<DependencyName, DependencyVersion> = {}
20
-
21
- #cwd?: string
22
-
23
- constructor(workspace?: string) {
24
- if (workspace) {
25
- this.#cwd = workspace
26
- }
27
- }
28
-
29
- set workspace(workspace: string) {
30
- this.#cwd = workspace
31
- }
32
-
33
- get workspace(): string | undefined {
34
- return this.#cwd
35
- }
36
-
37
- normalizeDirectory(directory: string): string {
38
- const lastChar = directory[directory.length - 1]
39
- if (lastChar && !(PATH_SEPARATORS as readonly string[]).includes(lastChar)) {
40
- return `${directory}/`
41
- }
42
-
43
- return directory
44
- }
45
-
46
- getLocation(path: string): string {
47
- let location = path
48
-
49
- if (this.#cwd) {
50
- const require = mod.createRequire(this.normalizeDirectory(this.#cwd))
51
- location = require.resolve(path)
52
- }
53
-
54
- return location
55
- }
56
-
57
- async import(path: string): Promise<unknown> {
58
- let location = this.getLocation(path)
59
-
60
- if (os.platform() === 'win32') {
61
- location = pathToFileURL(location).href
62
- }
63
-
64
- const module = await import(location)
65
-
66
- return module?.default ?? module
67
- }
68
-
69
- async getPackageJSON(): Promise<PackageJSON | undefined> {
70
- const pkgPath = pkg.up({
71
- cwd: this.#cwd,
72
- })
73
- if (!pkgPath) {
74
- return undefined
75
- }
76
-
77
- const json = await read(pkgPath)
78
-
79
- return JSON.parse(json) as PackageJSON
80
- }
81
-
82
- getPackageJSONSync(): PackageJSON | undefined {
83
- const pkgPath = pkg.up({
84
- cwd: this.#cwd,
85
- })
86
- if (!pkgPath) {
87
- return undefined
88
- }
89
-
90
- const json = readSync(pkgPath)
91
-
92
- return JSON.parse(json) as PackageJSON
93
- }
94
-
95
- static setVersion(dependency: DependencyName, version: DependencyVersion): void {
96
- PackageManager.#cache[dependency] = version
97
- }
98
-
99
- #match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string | undefined {
100
- const dependencies = {
101
- ...(packageJSON.dependencies || {}),
102
- ...(packageJSON.devDependencies || {}),
103
- }
104
-
105
- if (typeof dependency === 'string' && dependencies[dependency]) {
106
- return dependencies[dependency]
107
- }
108
-
109
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency))
110
-
111
- return matchedDependency ? dependencies[matchedDependency] : undefined
112
- }
113
-
114
- async getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined> {
115
- if (typeof dependency === 'string' && PackageManager.#cache[dependency]) {
116
- return PackageManager.#cache[dependency]
117
- }
118
-
119
- const packageJSON = await this.getPackageJSON()
120
-
121
- if (!packageJSON) {
122
- return undefined
123
- }
124
-
125
- return this.#match(packageJSON, dependency)
126
- }
127
-
128
- getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined {
129
- if (typeof dependency === 'string' && PackageManager.#cache[dependency]) {
130
- return PackageManager.#cache[dependency]
131
- }
132
-
133
- const packageJSON = this.getPackageJSONSync()
134
-
135
- if (!packageJSON) {
136
- return undefined
137
- }
138
-
139
- return this.#match(packageJSON, dependency)
140
- }
141
-
142
- async isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean> {
143
- const packageVersion = await this.getVersion(dependency)
144
-
145
- if (!packageVersion) {
146
- return false
147
- }
148
-
149
- if (packageVersion === version) {
150
- return true
151
- }
152
-
153
- const semVer = coerce(packageVersion)
154
-
155
- if (!semVer) {
156
- return false
157
- }
158
-
159
- return satisfies(semVer, version)
160
- }
161
- isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean {
162
- const packageVersion = this.getVersionSync(dependency)
163
-
164
- if (!packageVersion) {
165
- return false
166
- }
167
-
168
- if (packageVersion === version) {
169
- return true
170
- }
171
-
172
- const semVer = coerce(packageVersion)
173
-
174
- if (!semVer) {
175
- return false
176
- }
177
-
178
- return satisfies(semVer, version)
179
- }
180
- }