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

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 (62) hide show
  1. package/README.md +13 -40
  2. package/dist/PluginDriver-Cu1Kj9S-.cjs +1075 -0
  3. package/dist/PluginDriver-Cu1Kj9S-.cjs.map +1 -0
  4. package/dist/PluginDriver-D8Z0Htid.js +978 -0
  5. package/dist/PluginDriver-D8Z0Htid.js.map +1 -0
  6. package/dist/createKubb-ALdb8lmq.d.ts +2082 -0
  7. package/dist/index.cjs +747 -1667
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +175 -269
  10. package/dist/index.js +734 -1638
  11. package/dist/index.js.map +1 -1
  12. package/dist/mocks.cjs +145 -0
  13. package/dist/mocks.cjs.map +1 -0
  14. package/dist/mocks.d.ts +80 -0
  15. package/dist/mocks.js +140 -0
  16. package/dist/mocks.js.map +1 -0
  17. package/package.json +47 -60
  18. package/src/FileManager.ts +115 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/PluginDriver.ts +355 -561
  21. package/src/constants.ts +21 -48
  22. package/src/createAdapter.ts +88 -5
  23. package/src/createKubb.ts +1266 -0
  24. package/src/createRenderer.ts +57 -0
  25. package/src/createStorage.ts +13 -1
  26. package/src/defineGenerator.ts +160 -119
  27. package/src/defineLogger.ts +46 -5
  28. package/src/defineMiddleware.ts +62 -0
  29. package/src/defineParser.ts +44 -0
  30. package/src/definePlugin.ts +379 -0
  31. package/src/defineResolver.ts +548 -25
  32. package/src/devtools.ts +22 -15
  33. package/src/index.ts +13 -15
  34. package/src/mocks.ts +177 -0
  35. package/src/storages/fsStorage.ts +13 -8
  36. package/src/storages/memoryStorage.ts +4 -2
  37. package/src/types.ts +40 -547
  38. package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
  39. package/dist/chunk-ByKO4r7w.cjs +0 -38
  40. package/dist/hooks.cjs +0 -103
  41. package/dist/hooks.cjs.map +0 -1
  42. package/dist/hooks.d.ts +0 -77
  43. package/dist/hooks.js +0 -98
  44. package/dist/hooks.js.map +0 -1
  45. package/src/Kubb.ts +0 -224
  46. package/src/build.ts +0 -418
  47. package/src/config.ts +0 -56
  48. package/src/createPlugin.ts +0 -28
  49. package/src/hooks/index.ts +0 -4
  50. package/src/hooks/useKubb.ts +0 -143
  51. package/src/hooks/useMode.ts +0 -11
  52. package/src/hooks/usePlugin.ts +0 -11
  53. package/src/hooks/usePluginDriver.ts +0 -11
  54. package/src/utils/FunctionParams.ts +0 -155
  55. package/src/utils/TreeNode.ts +0 -215
  56. package/src/utils/diagnostics.ts +0 -15
  57. package/src/utils/executeStrategies.ts +0 -81
  58. package/src/utils/formatters.ts +0 -56
  59. package/src/utils/getBarrelFiles.ts +0 -141
  60. package/src/utils/getConfigs.ts +0 -12
  61. package/src/utils/linters.ts +0 -25
  62. package/src/utils/packageJSON.ts +0 -61
@@ -0,0 +1,86 @@
1
+ import type { CodeNode, FileNode } from '@kubb/ast'
2
+ import { extractStringsFromNodes } from '@kubb/ast'
3
+ import pLimit from 'p-limit'
4
+ import { PARALLEL_CONCURRENCY_LIMIT } from './constants.ts'
5
+ import type { Parser } from './defineParser.ts'
6
+
7
+ type ParseOptions = {
8
+ parsers?: Map<FileNode['extname'], Parser>
9
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
10
+ }
11
+
12
+ type RunOptions = ParseOptions & {
13
+ /**
14
+ * @default 'sequential'
15
+ */
16
+ mode?: 'sequential' | 'parallel'
17
+ onStart?: (files: Array<FileNode>) => Promise<void> | void
18
+ onEnd?: (files: Array<FileNode>) => Promise<void> | void
19
+ onUpdate?: (params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }) => Promise<void> | void
20
+ }
21
+
22
+ function joinSources(file: FileNode): string {
23
+ return file.sources
24
+ .map((item) => extractStringsFromNodes(item.nodes as Array<CodeNode>))
25
+ .filter(Boolean)
26
+ .join('\n\n')
27
+ }
28
+
29
+ /**
30
+ * Converts a single file to a string using the registered parsers.
31
+ * Falls back to joining source values when no matching parser is found.
32
+ *
33
+ * @internal
34
+ */
35
+ export class FileProcessor {
36
+ readonly #limit = pLimit(PARALLEL_CONCURRENCY_LIMIT)
37
+
38
+ async parse(file: FileNode, { parsers, extension }: ParseOptions = {}): Promise<string> {
39
+ const parseExtName = extension?.[file.extname] || undefined
40
+
41
+ if (!parsers || !file.extname) {
42
+ return joinSources(file)
43
+ }
44
+
45
+ const parser = parsers.get(file.extname)
46
+
47
+ if (!parser) {
48
+ return joinSources(file)
49
+ }
50
+
51
+ return parser.parse(file, { extname: parseExtName })
52
+ }
53
+
54
+ async run(files: Array<FileNode>, { parsers, mode = 'sequential', extension, onStart, onEnd, onUpdate }: RunOptions = {}): Promise<Array<FileNode>> {
55
+ await onStart?.(files)
56
+
57
+ const total = files.length
58
+ let processed = 0
59
+
60
+ const processOne = async (file: FileNode) => {
61
+ const source = await this.parse(file, { extension, parsers })
62
+ const currentProcessed = ++processed
63
+ const percentage = (currentProcessed / total) * 100
64
+
65
+ await onUpdate?.({
66
+ file,
67
+ source,
68
+ processed: currentProcessed,
69
+ percentage,
70
+ total,
71
+ })
72
+ }
73
+
74
+ if (mode === 'sequential') {
75
+ for (const file of files) {
76
+ await processOne(file)
77
+ }
78
+ } else {
79
+ await Promise.all(files.map((file) => this.#limit(() => processOne(file))))
80
+ }
81
+
82
+ await onEnd?.(files)
83
+
84
+ return files
85
+ }
86
+ }