@kubb/core 5.0.0-alpha.3 → 5.0.0-alpha.30

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 (54) hide show
  1. package/dist/PluginDriver-D110FoJ-.d.ts +1632 -0
  2. package/dist/hooks.cjs +12 -27
  3. package/dist/hooks.cjs.map +1 -1
  4. package/dist/hooks.d.ts +11 -36
  5. package/dist/hooks.js +13 -27
  6. package/dist/hooks.js.map +1 -1
  7. package/dist/index.cjs +1410 -823
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +597 -95
  10. package/dist/index.js +1391 -818
  11. package/dist/index.js.map +1 -1
  12. package/package.json +7 -7
  13. package/src/Kubb.ts +40 -58
  14. package/src/{PluginManager.ts → PluginDriver.ts} +165 -177
  15. package/src/build.ts +167 -44
  16. package/src/config.ts +9 -8
  17. package/src/constants.ts +40 -7
  18. package/src/createAdapter.ts +25 -0
  19. package/src/createPlugin.ts +30 -0
  20. package/src/createStorage.ts +58 -0
  21. package/src/defineGenerator.ts +126 -0
  22. package/src/defineLogger.ts +13 -3
  23. package/src/definePresets.ts +16 -0
  24. package/src/defineResolver.ts +457 -0
  25. package/src/hooks/index.ts +1 -6
  26. package/src/hooks/useDriver.ts +11 -0
  27. package/src/hooks/useMode.ts +5 -5
  28. package/src/hooks/usePlugin.ts +3 -3
  29. package/src/index.ts +18 -7
  30. package/src/renderNode.tsx +25 -0
  31. package/src/storages/fsStorage.ts +2 -2
  32. package/src/storages/memoryStorage.ts +2 -2
  33. package/src/types.ts +589 -52
  34. package/src/utils/FunctionParams.ts +2 -2
  35. package/src/utils/TreeNode.ts +45 -7
  36. package/src/utils/diagnostics.ts +4 -1
  37. package/src/utils/executeStrategies.ts +29 -10
  38. package/src/utils/formatters.ts +10 -21
  39. package/src/utils/getBarrelFiles.ts +83 -10
  40. package/src/utils/getConfigs.ts +8 -22
  41. package/src/utils/getPreset.ts +78 -0
  42. package/src/utils/linters.ts +23 -3
  43. package/src/utils/packageJSON.ts +76 -0
  44. package/dist/types-CiPWLv-5.d.ts +0 -1001
  45. package/src/BarrelManager.ts +0 -74
  46. package/src/PackageManager.ts +0 -180
  47. package/src/PromiseManager.ts +0 -40
  48. package/src/defineAdapter.ts +0 -22
  49. package/src/definePlugin.ts +0 -12
  50. package/src/defineStorage.ts +0 -56
  51. package/src/errors.ts +0 -1
  52. package/src/hooks/useKubb.ts +0 -22
  53. package/src/hooks/usePluginManager.ts +0 -11
  54. package/src/utils/getPlugins.ts +0 -23
package/src/index.ts CHANGED
@@ -1,15 +1,24 @@
1
1
  export { AsyncEventEmitter, URLPath } from '@internals/utils'
2
- export { definePrinter } from '@kubb/ast'
2
+ export { composeTransformers, definePrinter } from '@kubb/ast'
3
3
  export { build, build as default, safeBuild, setup } from './build.ts'
4
4
  export { type CLIOptions, type ConfigInput, defineConfig, isInputPath } from './config.ts'
5
5
  export { formatters, linters, logLevel } from './constants.ts'
6
- export { defineAdapter } from './defineAdapter.ts'
6
+ export { createAdapter } from './createAdapter.ts'
7
+ export { createPlugin } from './createPlugin.ts'
8
+ export { createStorage } from './createStorage.ts'
9
+ export { defineGenerator, mergeGenerators } from './defineGenerator.ts'
7
10
  export { defineLogger } from './defineLogger.ts'
8
- export { definePlugin } from './definePlugin.ts'
9
- export { defineStorage } from './defineStorage.ts'
10
- export { PackageManager } from './PackageManager.ts'
11
- export { getMode, PluginManager } from './PluginManager.ts'
12
- export { PromiseManager } from './PromiseManager.ts'
11
+ export { definePresets } from './definePresets.ts'
12
+ export {
13
+ buildDefaultBanner,
14
+ defaultResolveBanner,
15
+ defaultResolveFile,
16
+ defaultResolveFooter,
17
+ defaultResolveOptions,
18
+ defaultResolvePath,
19
+ defineResolver,
20
+ } from './defineResolver.ts'
21
+ export { getMode, PluginDriver } from './PluginDriver.ts'
13
22
  export { fsStorage } from './storages/fsStorage.ts'
14
23
  export { memoryStorage } from './storages/memoryStorage.ts'
15
24
  export * from './types.ts'
@@ -19,4 +28,6 @@ export { detectFormatter } from './utils/formatters.ts'
19
28
  export type { FileMetaBase } from './utils/getBarrelFiles.ts'
20
29
  export { getBarrelFiles } from './utils/getBarrelFiles.ts'
21
30
  export { getConfigs } from './utils/getConfigs.ts'
31
+ export { getPreset } from './utils/getPreset.ts'
22
32
  export { detectLinter } from './utils/linters.ts'
33
+ export { satisfiesDependency } from './utils/packageJSON.ts'
@@ -0,0 +1,25 @@
1
+ import type { FabricFile } from '@kubb/fabric-core/types'
2
+ import { createReactFabric, Fabric } from '@kubb/react-fabric'
3
+ import type { FabricReactNode, Fabric as FabricType } from '@kubb/react-fabric/types'
4
+
5
+ /**
6
+ * Handles the return value of a plugin AST hook or generator method.
7
+ *
8
+ * - React element → rendered via an isolated react-fabric context, files merged into `fabric`
9
+ * - `Array<FabricFile.File>` → upserted directly into `fabric`
10
+ * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)
11
+ */
12
+ export async function applyHookResult(result: FabricReactNode | Array<FabricFile.File> | void, fabric: FabricType): Promise<void> {
13
+ if (!result) return
14
+
15
+ if (Array.isArray(result)) {
16
+ await fabric.upsertFile(...(result as Array<FabricFile.File>))
17
+ return
18
+ }
19
+
20
+ // Non-array truthy result is treated as a React element (FabricReactNode)
21
+ const fabricChild = createReactFabric()
22
+ await fabricChild.render(<Fabric>{result as FabricReactNode}</Fabric>)
23
+ fabric.context.fileManager.upsert(...fabricChild.files)
24
+ fabricChild.unmount()
25
+ }
@@ -2,7 +2,7 @@ import type { Dirent } from 'node:fs'
2
2
  import { access, readdir, readFile, rm } from 'node:fs/promises'
3
3
  import { join, resolve } from 'node:path'
4
4
  import { clean, write } from '@internals/utils'
5
- import { defineStorage } from '../defineStorage.ts'
5
+ import { createStorage } from '../createStorage.ts'
6
6
 
7
7
  /**
8
8
  * Built-in filesystem storage driver.
@@ -27,7 +27,7 @@ import { defineStorage } from '../defineStorage.ts'
27
27
  * })
28
28
  * ```
29
29
  */
30
- export const fsStorage = defineStorage(() => ({
30
+ export const fsStorage = createStorage(() => ({
31
31
  name: 'fs',
32
32
  async hasItem(key: string) {
33
33
  try {
@@ -1,4 +1,4 @@
1
- import { defineStorage } from '../defineStorage.ts'
1
+ import { createStorage } from '../createStorage.ts'
2
2
 
3
3
  /**
4
4
  * In-memory storage driver. Useful for testing and dry-run scenarios where
@@ -17,7 +17,7 @@ import { defineStorage } from '../defineStorage.ts'
17
17
  * })
18
18
  * ```
19
19
  */
20
- export const memoryStorage = defineStorage(() => {
20
+ export const memoryStorage = createStorage(() => {
21
21
  const store = new Map<string, string>()
22
22
 
23
23
  return {