@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.
- package/dist/{FileManager-wyXRkgIk.d.cts → FileManager-B0GJlthB.d.cts} +30 -16
- package/dist/{FileManager-Ceski1W9.d.ts → FileManager-BFycBDqG.d.ts} +30 -16
- package/dist/chunk-27CPVXAT.js +945 -0
- package/dist/chunk-27CPVXAT.js.map +1 -0
- package/dist/{chunk-34BPAXR2.cjs → chunk-5E2I6KH4.cjs} +7 -7
- package/dist/{chunk-34BPAXR2.cjs.map → chunk-5E2I6KH4.cjs.map} +1 -1
- package/dist/chunk-5IGANEGE.cjs +1564 -0
- package/dist/chunk-5IGANEGE.cjs.map +1 -0
- package/dist/{chunk-67C6RBGQ.cjs → chunk-A6PCLWEY.cjs} +5 -5
- package/dist/{chunk-67C6RBGQ.cjs.map → chunk-A6PCLWEY.cjs.map} +1 -1
- package/dist/{chunk-5HN4LW3R.cjs → chunk-DID47EQD.cjs} +3 -3
- package/dist/{chunk-5HN4LW3R.cjs.map → chunk-DID47EQD.cjs.map} +1 -1
- package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +6 -6
- package/dist/{chunk-LOLEBOMW.cjs → chunk-IPZQXBA2.cjs} +16 -21
- package/dist/chunk-IPZQXBA2.cjs.map +1 -0
- package/dist/{chunk-76UEJFFE.js → chunk-SCR3LUXT.js} +9 -16
- package/dist/{chunk-76UEJFFE.js.map → chunk-SCR3LUXT.js.map} +1 -1
- package/dist/{chunk-XCPFG6DO.cjs → chunk-SEH6NUCX.cjs} +4 -28
- package/dist/chunk-SEH6NUCX.cjs.map +1 -0
- package/dist/index.cjs +380 -378
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +325 -319
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +4 -4
- package/dist/logger.js +2 -3
- package/dist/mocks.cjs +20 -15
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +6 -5
- package/dist/mocks.d.ts +6 -5
- package/dist/mocks.js +15 -11
- package/dist/mocks.js.map +1 -1
- package/dist/{prompt-6FWP747F.cjs → prompt-DVQN7JTN.cjs} +61 -61
- package/dist/{prompt-6FWP747F.cjs.map → prompt-DVQN7JTN.cjs.map} +1 -1
- package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +5 -6
- package/dist/{prompt-HK3MWREM.js.map → prompt-WQQUN22Z.js.map} +1 -1
- package/dist/transformers.cjs +19 -19
- package/dist/transformers.js +0 -1
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +8 -4
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +25 -24
- package/dist/utils.d.ts +25 -24
- package/dist/utils.js +5 -2
- package/package.json +7 -7
- package/src/BarrelManager.ts +90 -40
- package/src/FileManager.ts +89 -109
- package/src/PluginManager.ts +2 -1
- package/src/__snapshots__/barrel.json +91 -0
- package/src/__snapshots__/grouped.json +114 -0
- package/src/__snapshots__/ordered.json +62 -0
- package/src/build.ts +60 -23
- package/src/plugin.ts +2 -2
- package/src/types.ts +22 -2
- package/src/utils/TreeNode.ts +43 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/parser.ts +128 -67
- package/dist/chunk-AWAZR3D5.js +0 -360
- package/dist/chunk-AWAZR3D5.js.map +0 -1
- package/dist/chunk-DCZQYCCO.cjs +0 -1155
- package/dist/chunk-DCZQYCCO.cjs.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-L3JJLZ5Q.cjs +0 -371
- package/dist/chunk-L3JJLZ5Q.cjs.map +0 -1
- package/dist/chunk-LOLEBOMW.cjs.map +0 -1
- package/dist/chunk-RIEGCND2.js +0 -525
- package/dist/chunk-RIEGCND2.js.map +0 -1
- package/dist/chunk-XCPFG6DO.cjs.map +0 -1
- package/schema.json +0 -86
- /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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
print: (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
print: (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
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-
|
|
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.
|
|
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.
|
|
88
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
89
|
-
"@kubb/types": "3.0.0-alpha.
|
|
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.
|
|
102
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
103
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
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"
|
package/src/BarrelManager.ts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import
|
|
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 {
|
|
7
|
+
import { combineExports, combineSources } from './FileManager.ts'
|
|
8
|
+
import type { Logger } from './logger.ts'
|
|
7
9
|
|
|
8
10
|
export type BarrelManagerOptions = {
|
|
9
|
-
|
|
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
|
-
|
|
29
|
-
const {
|
|
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
|
-
|
|
33
|
-
return null
|
|
34
|
-
}
|
|
26
|
+
const files = new Map<KubbFile.Path, KubbFile.File>()
|
|
35
27
|
|
|
36
|
-
|
|
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
|
|
33
|
+
const barrelPath: KubbFile.Path = join(treeNode.parent?.data.path, 'index.ts')
|
|
42
34
|
|
|
43
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
60
|
-
path:
|
|
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
|
-
|
|
67
|
-
fileReducer(files, childItem)
|
|
68
|
-
})
|
|
109
|
+
const previousBarrelFile = files.get(barrelFile.path)
|
|
69
110
|
|
|
70
|
-
|
|
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
|
|
123
|
+
return [...files.values()]
|
|
74
124
|
}
|
|
75
125
|
}
|