@kubb/core 3.0.0-alpha.3 → 3.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 (112) hide show
  1. package/README.md +13 -4
  2. package/dist/{FileManager-Bw-FNS3q.d.cts → FileManager-CqvmdzNO.d.cts} +128 -90
  3. package/dist/{FileManager-BW--rO8q.d.ts → FileManager-DIArE3b0.d.ts} +128 -90
  4. package/dist/chunk-2EU7DMPM.js +96 -0
  5. package/dist/chunk-2EU7DMPM.js.map +1 -0
  6. package/dist/{chunk-34BPAXR2.cjs → chunk-2UQARE2O.cjs} +54 -37
  7. package/dist/chunk-2UQARE2O.cjs.map +1 -0
  8. package/dist/chunk-4X5FFJPJ.js +8 -13
  9. package/dist/chunk-4X5FFJPJ.js.map +1 -1
  10. package/dist/{chunk-3OXCZ5DJ.js → chunk-E6CN2CZC.js} +63 -54
  11. package/dist/chunk-E6CN2CZC.js.map +1 -0
  12. package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +13 -27
  13. package/dist/chunk-HBQM723K.js.map +1 -0
  14. package/dist/{chunk-LM2YQC3T.cjs → chunk-LLKRRIBF.cjs} +81 -51
  15. package/dist/chunk-LLKRRIBF.cjs.map +1 -0
  16. package/dist/chunk-MD2LDZ3Z.js +889 -0
  17. package/dist/chunk-MD2LDZ3Z.js.map +1 -0
  18. package/dist/chunk-OX2X7B4Z.cjs +101 -0
  19. package/dist/chunk-OX2X7B4Z.cjs.map +1 -0
  20. package/dist/{chunk-67C6RBGQ.cjs → chunk-RIW2LFFQ.cjs} +28 -29
  21. package/dist/chunk-RIW2LFFQ.cjs.map +1 -0
  22. package/dist/chunk-SX5FHSVT.cjs +1532 -0
  23. package/dist/chunk-SX5FHSVT.cjs.map +1 -0
  24. package/dist/chunk-VBGWLAET.cjs +42 -0
  25. package/dist/chunk-VBGWLAET.cjs.map +1 -0
  26. package/dist/index.cjs +553 -619
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +7 -22
  29. package/dist/index.d.ts +7 -22
  30. package/dist/index.js +444 -525
  31. package/dist/index.js.map +1 -1
  32. package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
  33. package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
  34. package/dist/logger.cjs +25 -15
  35. package/dist/logger.cjs.map +1 -1
  36. package/dist/logger.d.cts +1 -2
  37. package/dist/logger.d.ts +1 -2
  38. package/dist/logger.js +3 -15
  39. package/dist/logger.js.map +1 -1
  40. package/dist/mocks.cjs +42 -31
  41. package/dist/mocks.cjs.map +1 -1
  42. package/dist/mocks.d.cts +7 -9
  43. package/dist/mocks.d.ts +7 -9
  44. package/dist/mocks.js +35 -33
  45. package/dist/mocks.js.map +1 -1
  46. package/dist/{prompt-6FWP747F.cjs → prompt-2PN2F25D.cjs} +89 -89
  47. package/dist/prompt-2PN2F25D.cjs.map +1 -0
  48. package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +9 -15
  49. package/dist/prompt-WQQUN22Z.js.map +1 -0
  50. package/dist/transformers.cjs +216 -49
  51. package/dist/transformers.cjs.map +1 -1
  52. package/dist/transformers.d.cts +2 -4
  53. package/dist/transformers.d.ts +2 -4
  54. package/dist/transformers.js +149 -35
  55. package/dist/transformers.js.map +1 -1
  56. package/dist/utils.cjs +65 -26
  57. package/dist/utils.cjs.map +1 -1
  58. package/dist/utils.d.cts +29 -3
  59. package/dist/utils.d.ts +29 -3
  60. package/dist/utils.js +3 -26
  61. package/dist/utils.js.map +1 -1
  62. package/package.json +11 -14
  63. package/src/BarrelManager.ts +95 -109
  64. package/src/{Generator.ts → BaseGenerator.ts} +1 -1
  65. package/src/FileManager.ts +199 -304
  66. package/src/PackageManager.ts +1 -1
  67. package/src/PluginManager.ts +152 -93
  68. package/src/PromiseManager.ts +1 -1
  69. package/src/__snapshots__/barrel.json +73 -0
  70. package/src/__snapshots__/grouped.json +120 -0
  71. package/src/__snapshots__/ordered.json +68 -0
  72. package/src/build.ts +86 -131
  73. package/src/config.ts +2 -4
  74. package/src/errors.ts +0 -11
  75. package/src/index.ts +2 -3
  76. package/src/logger.ts +76 -34
  77. package/src/plugin.ts +2 -5
  78. package/src/transformers/escape.ts +0 -10
  79. package/src/transformers/index.ts +2 -3
  80. package/src/transformers/stringify.ts +1 -1
  81. package/src/transformers/trim.ts +0 -4
  82. package/src/types.ts +52 -20
  83. package/src/utils/TreeNode.ts +132 -50
  84. package/src/utils/executeStrategies.ts +3 -3
  85. package/src/utils/index.ts +2 -1
  86. package/src/utils/parser.ts +156 -0
  87. package/dist/chunk-25NKJ3DV.js.map +0 -1
  88. package/dist/chunk-34BPAXR2.cjs.map +0 -1
  89. package/dist/chunk-3OXCZ5DJ.js.map +0 -1
  90. package/dist/chunk-5JZNFPUP.js +0 -309
  91. package/dist/chunk-5JZNFPUP.js.map +0 -1
  92. package/dist/chunk-67C6RBGQ.cjs.map +0 -1
  93. package/dist/chunk-ADC5UNZ5.cjs +0 -1227
  94. package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
  95. package/dist/chunk-HMLY7DHA.js +0 -16
  96. package/dist/chunk-HMLY7DHA.js.map +0 -1
  97. package/dist/chunk-JKZG2IJR.js +0 -283
  98. package/dist/chunk-JKZG2IJR.js.map +0 -1
  99. package/dist/chunk-LM2YQC3T.cjs.map +0 -1
  100. package/dist/chunk-PZT4CTBV.cjs +0 -299
  101. package/dist/chunk-PZT4CTBV.cjs.map +0 -1
  102. package/dist/chunk-SA2GZKXS.js +0 -596
  103. package/dist/chunk-SA2GZKXS.js.map +0 -1
  104. package/dist/chunk-XCPFG6DO.cjs +0 -66
  105. package/dist/chunk-XCPFG6DO.cjs.map +0 -1
  106. package/dist/chunk-YTSNYMHW.cjs +0 -320
  107. package/dist/chunk-YTSNYMHW.cjs.map +0 -1
  108. package/dist/prompt-6FWP747F.cjs.map +0 -1
  109. package/dist/prompt-HK3MWREM.js.map +0 -1
  110. package/schema.json +0 -86
  111. package/src/utils/cache.ts +0 -35
  112. package/src/utils/getParser.ts +0 -17
package/dist/utils.cjs CHANGED
@@ -1,27 +1,66 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
- var _chunkYTSNYMHWcjs = require('./chunk-YTSNYMHW.cjs');
13
- require('./chunk-67C6RBGQ.cjs');
14
- require('./chunk-XCPFG6DO.cjs');
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
- exports.FunctionParams = _chunkYTSNYMHWcjs.FunctionParams; exports.URLPath = _chunkYTSNYMHWcjs.URLPath; exports.getParser = _chunkYTSNYMHWcjs.getParser; exports.getUniqueName = _chunkYTSNYMHWcjs.getUniqueName; exports.isPromise = _chunkYTSNYMHWcjs.isPromise; exports.isPromiseFulfilledResult = _chunkYTSNYMHWcjs.isPromiseFulfilledResult; exports.isPromiseRejectedResult = _chunkYTSNYMHWcjs.isPromiseRejectedResult; exports.renderTemplate = _chunkYTSNYMHWcjs.renderTemplate; exports.setUniqueName = _chunkYTSNYMHWcjs.setUniqueName; exports.timeout = _chunkYTSNYMHWcjs.timeout;
1
+ 'use strict';
2
+
3
+ var chunkSX5FHSVT_cjs = require('./chunk-SX5FHSVT.cjs');
4
+ require('./chunk-RIW2LFFQ.cjs');
5
+ require('./chunk-VBGWLAET.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "FunctionParams", {
10
+ enumerable: true,
11
+ get: function () { return chunkSX5FHSVT_cjs.FunctionParams; }
12
+ });
13
+ Object.defineProperty(exports, "URLPath", {
14
+ enumerable: true,
15
+ get: function () { return chunkSX5FHSVT_cjs.URLPath; }
16
+ });
17
+ Object.defineProperty(exports, "createFile", {
18
+ enumerable: true,
19
+ get: function () { return chunkSX5FHSVT_cjs.createFile; }
20
+ });
21
+ Object.defineProperty(exports, "createFileExport", {
22
+ enumerable: true,
23
+ get: function () { return chunkSX5FHSVT_cjs.createFileExport; }
24
+ });
25
+ Object.defineProperty(exports, "createFileImport", {
26
+ enumerable: true,
27
+ get: function () { return chunkSX5FHSVT_cjs.createFileImport; }
28
+ });
29
+ Object.defineProperty(exports, "createFileParser", {
30
+ enumerable: true,
31
+ get: function () { return chunkSX5FHSVT_cjs.createFileParser; }
32
+ });
33
+ Object.defineProperty(exports, "getFileParser", {
34
+ enumerable: true,
35
+ get: function () { return chunkSX5FHSVT_cjs.getFileParser; }
36
+ });
37
+ Object.defineProperty(exports, "getUniqueName", {
38
+ enumerable: true,
39
+ get: function () { return chunkSX5FHSVT_cjs.getUniqueName; }
40
+ });
41
+ Object.defineProperty(exports, "isPromise", {
42
+ enumerable: true,
43
+ get: function () { return chunkSX5FHSVT_cjs.isPromise; }
44
+ });
45
+ Object.defineProperty(exports, "isPromiseFulfilledResult", {
46
+ enumerable: true,
47
+ get: function () { return chunkSX5FHSVT_cjs.isPromiseFulfilledResult; }
48
+ });
49
+ Object.defineProperty(exports, "isPromiseRejectedResult", {
50
+ enumerable: true,
51
+ get: function () { return chunkSX5FHSVT_cjs.isPromiseRejectedResult; }
52
+ });
53
+ Object.defineProperty(exports, "renderTemplate", {
54
+ enumerable: true,
55
+ get: function () { return chunkSX5FHSVT_cjs.renderTemplate; }
56
+ });
57
+ Object.defineProperty(exports, "setUniqueName", {
58
+ enumerable: true,
59
+ get: function () { return chunkSX5FHSVT_cjs.setUniqueName; }
60
+ });
61
+ Object.defineProperty(exports, "timeout", {
62
+ enumerable: true,
63
+ get: function () { return chunkSX5FHSVT_cjs.timeout; }
64
+ });
65
+ //# sourceMappingURL=utils.cjs.map
27
66
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/core/dist/utils.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,+jBAAC","file":"/home/runner/work/kubb/kubb/packages/core/dist/utils.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"utils.cjs"}
package/dist/utils.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PossiblePromise } from '@kubb/types';
2
- import * as _kubb_parser_ts from '@kubb/parser-ts';
2
+ import * as KubbFile from '@kubb/fs/types';
3
+ import { L as Logger } from './logger-DvbHXjIO.cjs';
4
+ import 'consola';
3
5
 
4
6
  type FunctionParamsASTWithoutType = {
5
7
  name?: string;
@@ -101,6 +103,30 @@ declare class URLPath {
101
103
  toURLPath(): string;
102
104
  }
103
105
 
104
- declare function getParser(language: string | undefined): Promise<typeof _kubb_parser_ts>;
106
+ /**
107
+ * Helper to create a file with name and id set
108
+ */
109
+ declare function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta>;
110
+ /**
111
+ * Helper to create a fileImport with extname set
112
+ */
113
+ declare function createFileImport(imp: KubbFile.Import): KubbFile.ResolvedImport;
114
+ /**
115
+ * Helper to create a fileExport with extname set
116
+ */
117
+ declare function createFileExport(exp: KubbFile.Export): KubbFile.ResolvedExport;
118
+ type ParserModule<TMeta extends object = object> = {
119
+ format: (source: string) => Promise<string>;
120
+ /**
121
+ * Convert a file to string
122
+ */
123
+ print: (file: KubbFile.ResolvedFile<TMeta>, options: PrintOptions) => Promise<string>;
124
+ };
125
+ declare function createFileParser<TMeta extends object = object>(parser: ParserModule<TMeta>): ParserModule<TMeta>;
126
+ type PrintOptions = {
127
+ extname?: KubbFile.Extname;
128
+ logger?: Logger;
129
+ };
130
+ declare function getFileParser<TMeta extends object = object>(extname: KubbFile.Extname | undefined): Promise<ParserModule<TMeta>>;
105
131
 
106
- export { FunctionParams, type FunctionParamsAST, type URLObject, URLPath, getParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
132
+ export { FunctionParams, type FunctionParamsAST, type ParserModule, type URLObject, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PossiblePromise } from '@kubb/types';
2
- import * as _kubb_parser_ts from '@kubb/parser-ts';
2
+ import * as KubbFile from '@kubb/fs/types';
3
+ import { L as Logger } from './logger-DvbHXjIO.js';
4
+ import 'consola';
3
5
 
4
6
  type FunctionParamsASTWithoutType = {
5
7
  name?: string;
@@ -101,6 +103,30 @@ declare class URLPath {
101
103
  toURLPath(): string;
102
104
  }
103
105
 
104
- declare function getParser(language: string | undefined): Promise<typeof _kubb_parser_ts>;
106
+ /**
107
+ * Helper to create a file with name and id set
108
+ */
109
+ declare function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta>;
110
+ /**
111
+ * Helper to create a fileImport with extname set
112
+ */
113
+ declare function createFileImport(imp: KubbFile.Import): KubbFile.ResolvedImport;
114
+ /**
115
+ * Helper to create a fileExport with extname set
116
+ */
117
+ declare function createFileExport(exp: KubbFile.Export): KubbFile.ResolvedExport;
118
+ type ParserModule<TMeta extends object = object> = {
119
+ format: (source: string) => Promise<string>;
120
+ /**
121
+ * Convert a file to string
122
+ */
123
+ print: (file: KubbFile.ResolvedFile<TMeta>, options: PrintOptions) => Promise<string>;
124
+ };
125
+ declare function createFileParser<TMeta extends object = object>(parser: ParserModule<TMeta>): ParserModule<TMeta>;
126
+ type PrintOptions = {
127
+ extname?: KubbFile.Extname;
128
+ logger?: Logger;
129
+ };
130
+ declare function getFileParser<TMeta extends object = object>(extname: KubbFile.Extname | undefined): Promise<ParserModule<TMeta>>;
105
131
 
106
- export { FunctionParams, type FunctionParamsAST, type URLObject, URLPath, getParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
132
+ export { FunctionParams, type FunctionParamsAST, type ParserModule, type URLObject, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
package/dist/utils.js CHANGED
@@ -1,27 +1,4 @@
1
- import {
2
- FunctionParams,
3
- URLPath,
4
- getParser,
5
- getUniqueName,
6
- isPromise,
7
- isPromiseFulfilledResult,
8
- isPromiseRejectedResult,
9
- renderTemplate,
10
- setUniqueName,
11
- timeout
12
- } from "./chunk-5JZNFPUP.js";
13
- import "./chunk-4X5FFJPJ.js";
14
- import "./chunk-HMLY7DHA.js";
15
- export {
16
- FunctionParams,
17
- URLPath,
18
- getParser,
19
- getUniqueName,
20
- isPromise,
21
- isPromiseFulfilledResult,
22
- isPromiseRejectedResult,
23
- renderTemplate,
24
- setUniqueName,
25
- timeout
26
- };
1
+ export { FunctionParams, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout } from './chunk-MD2LDZ3Z.js';
2
+ import './chunk-4X5FFJPJ.js';
3
+ //# sourceMappingURL=utils.js.map
27
4
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.30",
4
4
  "description": "Generator core",
5
5
  "keywords": [
6
6
  "typescript",
@@ -76,31 +76,28 @@
76
76
  ],
77
77
  "dependencies": {
78
78
  "change-case": "^5.4.4",
79
- "directory-tree": "^3.5.2",
80
79
  "find-up": "^7.0.0",
81
80
  "natural-orderby": "^3.0.2",
81
+ "object-hash": "^3.0.0",
82
82
  "p-queue": "^8.0.1",
83
- "remeda": "^2.11.0",
83
+ "remeda": "^2.14.0",
84
84
  "seedrandom": "^3.0.5",
85
85
  "semver": "^7.6.3",
86
- "unraw": "^3.0.0",
87
- "@kubb/fs": "3.0.0-alpha.3",
88
- "@kubb/parser-ts": "3.0.0-alpha.3",
89
- "@kubb/types": "3.0.0-alpha.3"
86
+ "@kubb/fs": "3.0.0-alpha.30",
87
+ "@kubb/parser-ts": "3.0.0-alpha.30",
88
+ "@kubb/types": "3.0.0-alpha.30"
90
89
  },
91
90
  "devDependencies": {
92
- "@types/react": "^18.3.4",
91
+ "@types/object-hash": "^3.0.6",
93
92
  "@types/seedrandom": "^3.0.8",
94
93
  "@types/semver": "^7.5.8",
95
94
  "consola": "^3.2.3",
96
- "ora": "^8.0.1",
97
95
  "prettier": "^3.3.3",
98
96
  "tinyrainbow": "^1.2.0",
99
- "tsup": "^8.2.4",
100
- "typescript": "^5.5.4",
101
- "@kubb/config-biome": "3.0.0-alpha.3",
102
- "@kubb/config-ts": "3.0.0-alpha.3",
103
- "@kubb/config-tsup": "3.0.0-alpha.3"
97
+ "tsup": "^8.3.0",
98
+ "typescript": "^5.6.2",
99
+ "@kubb/config-ts": "3.0.0-alpha.30",
100
+ "@kubb/config-tsup": "3.0.0-alpha.30"
104
101
  },
105
102
  "engines": {
106
103
  "node": ">=20"
@@ -1,20 +1,14 @@
1
- import { getExports } from '@kubb/parser-ts'
1
+ import { join } from 'node:path'
2
2
 
3
- import path from 'node:path'
4
-
5
- import { trimExtName } from './transformers/trim.ts'
6
3
  import { TreeNode } from './utils/TreeNode.ts'
7
4
 
5
+ import { getRelativePath } from '@kubb/fs'
8
6
  import type * as KubbFile from '@kubb/fs/types'
9
- import type { DirectoryTreeOptions } from 'directory-tree'
10
-
11
- export type BarrelManagerOptions = {
12
- treeNode?: DirectoryTreeOptions
13
- isTypeOnly?: boolean
14
- /**
15
- * Add .ts or .js
16
- */
17
- extName?: KubbFile.Extname
7
+ import type { FileMetaBase } from './FileManager.ts'
8
+ import type { Logger } from './logger.ts'
9
+
10
+ type BarrelManagerOptions = {
11
+ logger?: Logger
18
12
  }
19
13
 
20
14
  export class BarrelManager {
@@ -26,116 +20,108 @@ export class BarrelManager {
26
20
  return this
27
21
  }
28
22
 
29
- getNamedExport(root: string, item: KubbFile.Export): KubbFile.Export[] {
30
- const exportedNames = getExports(path.resolve(root, item.path))
31
-
32
- if (!exportedNames) {
33
- return [item]
34
- }
23
+ getFiles({ files: generatedFiles, root, meta }: { files: KubbFile.File[]; root?: string; meta?: FileMetaBase | undefined }): Array<KubbFile.File> {
24
+ const { logger } = this.#options
35
25
 
36
- return exportedNames.reduce(
37
- (prev, curr) => {
38
- if (!prev[0]?.name || !prev[1]?.name) {
39
- return prev
40
- }
41
-
42
- if (curr.isTypeOnly) {
43
- prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] }
44
- } else {
45
- prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] }
46
- }
47
-
48
- return prev
49
- },
50
- [
51
- {
52
- ...item,
53
- name: [],
54
- isTypeOnly: false,
55
- },
56
- {
57
- ...item,
58
- name: [],
59
- isTypeOnly: true,
60
- },
61
- ] as KubbFile.Export[],
62
- )
63
- }
64
-
65
- getNamedExports(root: string, exports: KubbFile.Export[]): KubbFile.Export[] {
66
- return exports?.flatMap((item) => {
67
- return this.getNamedExport(root, item)
68
- })
69
- }
26
+ const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()
70
27
 
71
- getIndexes(root: string): Array<KubbFile.File> | null {
72
- const { treeNode = {}, isTypeOnly, extName } = this.#options
73
- const tree = TreeNode.build(root, treeNode)
28
+ logger?.emit('debug', { date: new Date(), logs: [`Start barrel generation for pluginKey ${meta?.pluginKey?.join('.')} and root '${root}'`] })
74
29
 
75
- if (!tree) {
76
- return null
77
- }
30
+ TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
31
+ if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
32
+ return undefined
33
+ }
78
34
 
79
- const fileReducer = (files: Array<KubbFile.File>, treeNode: TreeNode) => {
80
- if (!treeNode.children) {
81
- return []
35
+ const barrelFile: KubbFile.File = {
36
+ path: join(treeNode.parent?.data.path, 'index.ts') as KubbFile.Path,
37
+ baseName: 'index.ts',
38
+ exports: [],
39
+ sources: [],
82
40
  }
41
+ const previousBarrelFile = cachedFiles.get(barrelFile.path)
42
+ const leaves = treeNode.leaves
83
43
 
84
- if (treeNode.children.length > 1) {
85
- const indexPath: KubbFile.Path = path.resolve(treeNode.data.path, 'index.ts')
44
+ leaves.forEach((item) => {
45
+ if (!item.data.name) {
46
+ return undefined
47
+ }
86
48
 
87
- const exports: Array<KubbFile.Export> = treeNode.children
88
- .filter(Boolean)
89
- .map((file) => {
90
- const importPath: string = file.data.type === 'split' ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`
49
+ const sources = item.data.file?.sources || []
91
50
 
92
- if (importPath.endsWith('index') && file.data.type === 'single') {
93
- return undefined
94
- }
51
+ if (!sources.some((source) => source.isIndexable)) {
52
+ logger?.emit(
53
+ 'warning',
54
+ `No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, undefined, 2)}`,
55
+ )
56
+ }
95
57
 
96
- return {
97
- path: extName ? `${importPath}${extName}` : importPath,
98
- isTypeOnly,
99
- } as KubbFile.Export
58
+ sources.forEach((source) => {
59
+ if (!item.data.file?.path || !source.isIndexable || !source.name) {
60
+ return undefined
61
+ }
62
+ const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item) => item.name === source.name)
63
+
64
+ if (alreadyContainInPreviousBarrelFile) {
65
+ return undefined
66
+ }
67
+
68
+ if (!barrelFile.exports) {
69
+ barrelFile.exports = []
70
+ }
71
+
72
+ // true when we have a subdirectory that also contains barrel files
73
+ const isSubExport = !!treeNode.parent?.data.path?.split?.('/')?.length
74
+
75
+ if (isSubExport) {
76
+ barrelFile.exports.push({
77
+ name: [source.name],
78
+ path: getRelativePath(treeNode.parent?.data.path, item.data.path),
79
+ isTypeOnly: source.isTypeOnly,
80
+ })
81
+ } else {
82
+ barrelFile.exports.push({
83
+ name: [source.name],
84
+ path: `./${item.data.file.baseName}`,
85
+ isTypeOnly: source.isTypeOnly,
86
+ })
87
+ }
88
+
89
+ barrelFile.sources.push({
90
+ name: source.name,
91
+ isTypeOnly: source.isTypeOnly,
92
+ //TODO use parser to generate import
93
+ value: '',
94
+ isExportable: false,
95
+ isIndexable: false,
100
96
  })
101
- .filter(Boolean)
102
-
103
- files.push({
104
- path: indexPath,
105
- baseName: 'index.ts',
106
- source: '',
107
- exports,
108
- exportable: true,
109
97
  })
110
- } else if (treeNode.children.length === 1) {
111
- const [treeNodeChild] = treeNode.children as [TreeNode]
112
-
113
- const indexPath = path.resolve(treeNode.data.path, 'index.ts')
114
- const importPath = treeNodeChild.data.type === 'split' ? `./${treeNodeChild.data.name}/index` : `./${trimExtName(treeNodeChild.data.name)}`
115
-
116
- const exports = [
117
- {
118
- path: extName ? `${importPath}${extName}` : importPath,
119
- isTypeOnly,
120
- },
121
- ]
122
-
123
- files.push({
124
- path: indexPath,
125
- baseName: 'index.ts',
126
- source: '',
127
- exports,
128
- exportable: true,
129
- })
130
- }
98
+ })
99
+
100
+ logger?.emit('debug', {
101
+ date: new Date(),
102
+ logs: [
103
+ `Generating barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with ${barrelFile.sources.length} indexable exports: '${barrelFile.sources?.map((source) => source.name).join(', ')}'`,
104
+ ],
105
+ })
131
106
 
132
- treeNode.children.forEach((childItem) => {
133
- fileReducer(files, childItem)
107
+ logger?.emit('debug', {
108
+ date: new Date(),
109
+ logs: [
110
+ `Generated barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with exports: '${cachedFiles
111
+ .get(barrelFile.path)
112
+ ?.sources?.map((source) => source.name)
113
+ .join(', ')}'`,
114
+ ],
134
115
  })
135
116
 
136
- return files
137
- }
117
+ if (previousBarrelFile) {
118
+ previousBarrelFile.sources.push(...barrelFile.sources)
119
+ previousBarrelFile.exports?.push(...(barrelFile.exports || []))
120
+ } else {
121
+ cachedFiles.set(barrelFile.path, barrelFile)
122
+ }
123
+ })
138
124
 
139
- return fileReducer([], tree).reverse()
125
+ return [...cachedFiles.values()]
140
126
  }
141
127
  }
@@ -2,7 +2,7 @@
2
2
  * Abstract class that contains the building blocks for plugins to create their own Generator
3
3
  * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
4
4
  */
5
- export abstract class Generator<TOptions = unknown, TContext = unknown> {
5
+ export abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
6
6
  #options: TOptions = {} as TOptions
7
7
  #context: TContext = {} as TContext
8
8