@kubb/core 3.0.0-alpha.6 → 3.0.0-alpha.8

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 (72) hide show
  1. package/dist/{FileManager-wyXRkgIk.d.cts → FileManager-B0GJlthB.d.cts} +30 -16
  2. package/dist/{FileManager-Ceski1W9.d.ts → FileManager-BFycBDqG.d.ts} +30 -16
  3. package/dist/chunk-27CPVXAT.js +945 -0
  4. package/dist/chunk-27CPVXAT.js.map +1 -0
  5. package/dist/{chunk-34BPAXR2.cjs → chunk-5E2I6KH4.cjs} +7 -7
  6. package/dist/{chunk-34BPAXR2.cjs.map → chunk-5E2I6KH4.cjs.map} +1 -1
  7. package/dist/chunk-5IGANEGE.cjs +1564 -0
  8. package/dist/chunk-5IGANEGE.cjs.map +1 -0
  9. package/dist/{chunk-67C6RBGQ.cjs → chunk-A6PCLWEY.cjs} +5 -5
  10. package/dist/{chunk-67C6RBGQ.cjs.map → chunk-A6PCLWEY.cjs.map} +1 -1
  11. package/dist/{chunk-5HN4LW3R.cjs → chunk-DID47EQD.cjs} +3 -3
  12. package/dist/{chunk-5HN4LW3R.cjs.map → chunk-DID47EQD.cjs.map} +1 -1
  13. package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +6 -6
  14. package/dist/{chunk-LOLEBOMW.cjs → chunk-IPZQXBA2.cjs} +16 -21
  15. package/dist/chunk-IPZQXBA2.cjs.map +1 -0
  16. package/dist/{chunk-76UEJFFE.js → chunk-SCR3LUXT.js} +9 -16
  17. package/dist/{chunk-76UEJFFE.js.map → chunk-SCR3LUXT.js.map} +1 -1
  18. package/dist/{chunk-XCPFG6DO.cjs → chunk-SEH6NUCX.cjs} +4 -28
  19. package/dist/chunk-SEH6NUCX.cjs.map +1 -0
  20. package/dist/index.cjs +380 -378
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +325 -319
  25. package/dist/index.js.map +1 -1
  26. package/dist/logger.cjs +4 -4
  27. package/dist/logger.js +2 -3
  28. package/dist/mocks.cjs +20 -15
  29. package/dist/mocks.cjs.map +1 -1
  30. package/dist/mocks.d.cts +6 -5
  31. package/dist/mocks.d.ts +6 -5
  32. package/dist/mocks.js +15 -11
  33. package/dist/mocks.js.map +1 -1
  34. package/dist/{prompt-6FWP747F.cjs → prompt-DVQN7JTN.cjs} +61 -61
  35. package/dist/{prompt-6FWP747F.cjs.map → prompt-DVQN7JTN.cjs.map} +1 -1
  36. package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +5 -6
  37. package/dist/{prompt-HK3MWREM.js.map → prompt-WQQUN22Z.js.map} +1 -1
  38. package/dist/transformers.cjs +19 -19
  39. package/dist/transformers.js +0 -1
  40. package/dist/transformers.js.map +1 -1
  41. package/dist/utils.cjs +8 -4
  42. package/dist/utils.cjs.map +1 -1
  43. package/dist/utils.d.cts +25 -24
  44. package/dist/utils.d.ts +25 -24
  45. package/dist/utils.js +5 -2
  46. package/package.json +7 -7
  47. package/src/BarrelManager.ts +90 -40
  48. package/src/FileManager.ts +89 -109
  49. package/src/PluginManager.ts +2 -1
  50. package/src/__snapshots__/barrel.json +91 -0
  51. package/src/__snapshots__/grouped.json +114 -0
  52. package/src/__snapshots__/ordered.json +62 -0
  53. package/src/build.ts +60 -23
  54. package/src/plugin.ts +2 -2
  55. package/src/types.ts +22 -2
  56. package/src/utils/TreeNode.ts +43 -1
  57. package/src/utils/index.ts +1 -1
  58. package/src/utils/parser.ts +128 -67
  59. package/dist/chunk-AWAZR3D5.js +0 -360
  60. package/dist/chunk-AWAZR3D5.js.map +0 -1
  61. package/dist/chunk-DCZQYCCO.cjs +0 -1155
  62. package/dist/chunk-DCZQYCCO.cjs.map +0 -1
  63. package/dist/chunk-HMLY7DHA.js +0 -16
  64. package/dist/chunk-HMLY7DHA.js.map +0 -1
  65. package/dist/chunk-L3JJLZ5Q.cjs +0 -371
  66. package/dist/chunk-L3JJLZ5Q.cjs.map +0 -1
  67. package/dist/chunk-LOLEBOMW.cjs.map +0 -1
  68. package/dist/chunk-RIEGCND2.js +0 -525
  69. package/dist/chunk-RIEGCND2.js.map +0 -1
  70. package/dist/chunk-XCPFG6DO.cjs.map +0 -1
  71. package/schema.json +0 -86
  72. /package/dist/{chunk-25NKJ3DV.js.map → chunk-HBQM723K.js.map} +0 -0
package/dist/utils.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PossiblePromise } from '@kubb/types';
2
2
  import * as KubbFile from '@kubb/fs/types';
3
+ import { L as Logger } from './logger-BWFeedRk.cjs';
4
+ import 'consola';
3
5
 
4
6
  type FunctionParamsASTWithoutType = {
5
7
  name?: string;
@@ -105,29 +107,28 @@ declare class URLPath {
105
107
  * Helper to create a file with name and id set
106
108
  */
107
109
  declare function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta>;
108
- type ParserModule<TImport = unknown, TExport = unknown> = {
109
- createImport: (props: {
110
- name: string | Array<string | {
111
- propertyName: string;
112
- name?: string;
113
- }>;
114
- path: string;
115
- isTypeOnly?: boolean;
116
- isNameSpace?: boolean;
117
- }) => TImport | undefined;
118
- createExport: (props: {
119
- path: string;
120
- asAlias?: boolean;
121
- isTypeOnly?: boolean;
122
- name?: string | Array<string>;
123
- }) => TExport | undefined;
124
- print: (props: {
125
- imports: Array<TImport>;
126
- exports: Array<TExport>;
127
- source: string;
128
- }) => string;
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
+ /**
120
+ * By default @kubb/react is used
121
+ */
122
+ render: (item: any) => any;
123
+ /**
124
+ * Convert a file to string
125
+ */
126
+ print: (file: KubbFile.ResolvedFile<TMeta>, options: PrintOptions) => Promise<string>;
127
+ };
128
+ declare function createFileParser<TMeta extends object = object>(parser: ParserModule<TMeta>): ParserModule<TMeta>;
129
+ type PrintOptions = {
130
+ logger?: Logger;
129
131
  };
130
- declare function createFileParser<TImport = unknown, TExport = unknown>(parser: ParserModule<TImport, TExport>): ParserModule<TImport, TExport>;
131
- declare function getFileParser(extName: string | undefined): Promise<ParserModule<any, any>>;
132
+ declare function getFileParser<TMeta extends object = object>(extName: KubbFile.Extname | undefined): Promise<ParserModule<TMeta>>;
132
133
 
133
- export { FunctionParams, type FunctionParamsAST, type ParserModule, type URLObject, URLPath, createFile, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
134
+ 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
2
  import * as KubbFile from '@kubb/fs/types';
3
+ import { L as Logger } from './logger-BWFeedRk.js';
4
+ import 'consola';
3
5
 
4
6
  type FunctionParamsASTWithoutType = {
5
7
  name?: string;
@@ -105,29 +107,28 @@ declare class URLPath {
105
107
  * Helper to create a file with name and id set
106
108
  */
107
109
  declare function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta>;
108
- type ParserModule<TImport = unknown, TExport = unknown> = {
109
- createImport: (props: {
110
- name: string | Array<string | {
111
- propertyName: string;
112
- name?: string;
113
- }>;
114
- path: string;
115
- isTypeOnly?: boolean;
116
- isNameSpace?: boolean;
117
- }) => TImport | undefined;
118
- createExport: (props: {
119
- path: string;
120
- asAlias?: boolean;
121
- isTypeOnly?: boolean;
122
- name?: string | Array<string>;
123
- }) => TExport | undefined;
124
- print: (props: {
125
- imports: Array<TImport>;
126
- exports: Array<TExport>;
127
- source: string;
128
- }) => string;
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
+ /**
120
+ * By default @kubb/react is used
121
+ */
122
+ render: (item: any) => any;
123
+ /**
124
+ * Convert a file to string
125
+ */
126
+ print: (file: KubbFile.ResolvedFile<TMeta>, options: PrintOptions) => Promise<string>;
127
+ };
128
+ declare function createFileParser<TMeta extends object = object>(parser: ParserModule<TMeta>): ParserModule<TMeta>;
129
+ type PrintOptions = {
130
+ logger?: Logger;
129
131
  };
130
- declare function createFileParser<TImport = unknown, TExport = unknown>(parser: ParserModule<TImport, TExport>): ParserModule<TImport, TExport>;
131
- declare function getFileParser(extName: string | undefined): Promise<ParserModule<any, any>>;
132
+ declare function getFileParser<TMeta extends object = object>(extName: KubbFile.Extname | undefined): Promise<ParserModule<TMeta>>;
132
133
 
133
- export { FunctionParams, type FunctionParamsAST, type ParserModule, type URLObject, URLPath, createFile, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
134
+ 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
@@ -2,6 +2,8 @@ import {
2
2
  FunctionParams,
3
3
  URLPath,
4
4
  createFile,
5
+ createFileExport,
6
+ createFileImport,
5
7
  createFileParser,
6
8
  getFileParser,
7
9
  getUniqueName,
@@ -11,13 +13,14 @@ import {
11
13
  renderTemplate,
12
14
  setUniqueName,
13
15
  timeout
14
- } from "./chunk-AWAZR3D5.js";
16
+ } from "./chunk-27CPVXAT.js";
15
17
  import "./chunk-4X5FFJPJ.js";
16
- import "./chunk-HMLY7DHA.js";
17
18
  export {
18
19
  FunctionParams,
19
20
  URLPath,
20
21
  createFile,
22
+ createFileExport,
23
+ createFileImport,
21
24
  createFileParser,
22
25
  getFileParser,
23
26
  getUniqueName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "Generator core",
5
5
  "keywords": [
6
6
  "typescript",
@@ -84,9 +84,9 @@
84
84
  "seedrandom": "^3.0.5",
85
85
  "semver": "^7.6.3",
86
86
  "unraw": "^3.0.0",
87
- "@kubb/fs": "3.0.0-alpha.6",
88
- "@kubb/parser-ts": "3.0.0-alpha.6",
89
- "@kubb/types": "3.0.0-alpha.6"
87
+ "@kubb/fs": "3.0.0-alpha.8",
88
+ "@kubb/parser-ts": "3.0.0-alpha.8",
89
+ "@kubb/types": "3.0.0-alpha.8"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@types/object-hash": "^3.0.6",
@@ -98,9 +98,9 @@
98
98
  "tinyrainbow": "^1.2.0",
99
99
  "tsup": "^8.2.4",
100
100
  "typescript": "^5.5.4",
101
- "@kubb/config-biome": "3.0.0-alpha.6",
102
- "@kubb/config-ts": "3.0.0-alpha.6",
103
- "@kubb/config-tsup": "3.0.0-alpha.6"
101
+ "@kubb/config-biome": "3.0.0-alpha.8",
102
+ "@kubb/config-ts": "3.0.0-alpha.8",
103
+ "@kubb/config-tsup": "3.0.0-alpha.8"
104
104
  },
105
105
  "engines": {
106
106
  "node": ">=20"
@@ -1,21 +1,16 @@
1
- import path from 'node:path'
1
+ import { join } from 'node:path'
2
2
 
3
3
  import { TreeNode } from './utils/TreeNode.ts'
4
4
 
5
+ import { getRelativePath } from '@kubb/fs'
5
6
  import type * as KubbFile from '@kubb/fs/types'
6
- import { trimExtName } from '@kubb/fs'
7
+ import { combineExports, combineSources } from './FileManager.ts'
8
+ import type { Logger } from './logger.ts'
7
9
 
8
10
  export type BarrelManagerOptions = {
9
- isTypeOnly?: boolean
10
- /**
11
- * Add .ts or .js
12
- */
13
- extName?: string
11
+ logger?: Logger
14
12
  }
15
13
 
16
- /**
17
- * Replace with the use of the FileManager exports/imports
18
- */
19
14
  export class BarrelManager {
20
15
  #options: BarrelManagerOptions
21
16
 
@@ -25,51 +20,106 @@ export class BarrelManager {
25
20
  return this
26
21
  }
27
22
 
28
- getIndexes(generatedFiles: KubbFile.File[], root: string): Array<KubbFile.File> | null {
29
- const { isTypeOnly, extName } = this.#options
30
- const tree = TreeNode.build(generatedFiles, root)
23
+ getFiles(generatedFiles: KubbFile.File[], root?: string): Array<KubbFile.File> {
24
+ const { logger } = this.#options
31
25
 
32
- if (!tree) {
33
- return null
34
- }
26
+ const files = new Map<KubbFile.Path, KubbFile.File>()
35
27
 
36
- const fileReducer = (files: Array<KubbFile.File>, treeNode: TreeNode) => {
37
- if (!treeNode.children) {
38
- return []
28
+ TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
29
+ if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
30
+ return undefined
39
31
  }
40
32
 
41
- const indexPath: KubbFile.Path = path.resolve(treeNode.data.path, 'index.ts')
33
+ const barrelPath: KubbFile.Path = join(treeNode.parent?.data.path, 'index.ts')
42
34
 
43
- const exports: Array<KubbFile.Export> = treeNode.children
44
- .filter((item) => !!item.data.name)
45
- .map((treeNode) => {
46
- const importPath: string = treeNode.data.file ? `./${trimExtName(treeNode.data.name)}` : `./${treeNode.data.name}/index`
35
+ const leaves = treeNode.leaves
47
36
 
48
- if (importPath.endsWith('index') && treeNode.data.file) {
37
+ // biome-ignore lint/complexity/useFlatMap: we have a custom map in TreeNode
38
+ const exports = leaves
39
+ .map((item) => {
40
+ if (!item.data.name) {
49
41
  return undefined
50
42
  }
51
43
 
52
- return {
53
- path: extName ? `${importPath}${extName}` : importPath,
54
- isTypeOnly,
55
- } as KubbFile.Export
44
+ const sources = item.data.file?.sources || []
45
+
46
+ if (!sources.some((source) => source.isIndexable)) {
47
+ logger?.emit(
48
+ 'warning',
49
+ `No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, undefined, 2)}`,
50
+ )
51
+ }
52
+
53
+ return sources.map((source) => {
54
+ if (!item.data.file?.path || !source.isIndexable) {
55
+ return undefined
56
+ }
57
+
58
+ // true when we have a subdirectory that also contains barrel files
59
+ const isSubExport = !!treeNode.parent?.data.path?.split?.('/')?.length
60
+
61
+ if (isSubExport) {
62
+ return {
63
+ name: [source.name],
64
+ path: getRelativePath(treeNode.parent?.data.path, item.data.path),
65
+ isTypeOnly: source.isTypeOnly,
66
+ } as KubbFile.Export
67
+ }
68
+
69
+ return {
70
+ name: [source.name],
71
+ path: `./${item.data.file.baseName}`,
72
+ isTypeOnly: source.isTypeOnly,
73
+ } as KubbFile.Export
74
+ })
56
75
  })
76
+ .flat()
57
77
  .filter(Boolean)
58
78
 
59
- files.push({
60
- path: indexPath,
79
+ const barrelFile: KubbFile.File = {
80
+ path: barrelPath,
61
81
  baseName: 'index.ts',
62
- exports,
63
- sources: [],
64
- })
82
+ exports: exports,
83
+ sources: exports.flatMap((item) => {
84
+ if (Array.isArray(item.name)) {
85
+ return item.name.map((name) => {
86
+ return {
87
+ name: name,
88
+ isTypeOnly: item.isTypeOnly,
89
+ //TODO use parser to generate import
90
+ value: '',
91
+ isExportable: false,
92
+ isIndexable: false,
93
+ } as KubbFile.Source
94
+ })
95
+ }
96
+ return [
97
+ {
98
+ name: item.name,
99
+ isTypeOnly: item.isTypeOnly,
100
+ //TODO use parser to generate import
101
+ value: '',
102
+ isExportable: false,
103
+ isIndexable: false,
104
+ } as KubbFile.Source,
105
+ ]
106
+ }),
107
+ }
65
108
 
66
- treeNode.children.forEach((childItem) => {
67
- fileReducer(files, childItem)
68
- })
109
+ const previousBarrelFile = files.get(barrelFile.path)
69
110
 
70
- return files
71
- }
111
+ if (previousBarrelFile) {
112
+ files.set(barrelFile.path, {
113
+ ...previousBarrelFile,
114
+ ...barrelFile,
115
+ exports: combineExports([...(previousBarrelFile.exports || []), ...(barrelFile.exports || [])]),
116
+ sources: combineSources([...(previousBarrelFile.sources || []), ...(barrelFile.sources || [])]),
117
+ })
118
+ } else {
119
+ files.set(barrelFile.path, barrelFile)
120
+ }
121
+ })
72
122
 
73
- return fileReducer([], tree).reverse()
123
+ return [...files.values()]
74
124
  }
75
125
  }