@@ -7,6 +7,27 @@ export interface AIAnalyzerOptions {
7
7
temperature ?: number ;
8
8
}
9
9
10
+ interface CodeSplittingResult {
11
+ splitPoints : string [ ] ;
12
+ impact : Array < {
13
+ path : string ;
14
+ sizeReduction : number ;
15
+ } > ;
16
+ }
17
+
18
+ interface TreeShakingResult {
19
+ unusedExports : Array < {
20
+ module : string ;
21
+ exports : string [ ] ;
22
+ } > ;
23
+ potentialSavings : number ;
24
+ }
25
+
26
+ interface ImpactEstimation {
27
+ sizeReduction : number ;
28
+ performanceImprovement : number ;
29
+ }
30
+
10
31
export class AIBundleAnalyzer {
11
32
private openai : OpenAI ;
12
33
private model : string ;
@@ -98,7 +119,7 @@ export class AIBundleAnalyzer {
98
119
. map ( line => line . trim ( ) ) ;
99
120
}
100
121
101
- private parseCodeSplitting ( suggestions : string ) : any {
122
+ private parseCodeSplitting ( suggestions : string ) : CodeSplittingResult {
102
123
const lines = suggestions . split ( '\n' ) . filter ( line => line . trim ( ) ) ;
103
124
const splitPoints = lines
104
125
. filter ( line => line . includes ( '/' ) )
@@ -116,28 +137,25 @@ export class AIBundleAnalyzer {
116
137
} ;
117
138
}
118
139
119
- private parseTreeShaking ( suggestions : string ) : any {
140
+ private parseTreeShaking ( suggestions : string ) : TreeShakingResult {
120
141
const lines = suggestions . split ( '\n' ) . filter ( line => line . trim ( ) ) ;
121
142
const unusedExports = lines
122
143
. filter ( line => line . includes ( 'export' ) )
123
144
. map ( line => {
124
145
const [ module , ...exports ] = line . split ( ':' ) . map ( s => s . trim ( ) ) ;
125
146
return {
126
147
module,
127
- exports : exports [ 0 ] . split ( ',' ) . map ( e => e . trim ( ) )
148
+ exports : exports . join ( ':' ) . split ( ',' ) . map ( e => e . trim ( ) )
128
149
} ;
129
150
} ) ;
130
151
131
152
return {
132
153
unusedExports,
133
- potentialSavings : unusedExports . length * 1000 // Example estimation
154
+ potentialSavings : unusedExports . length * 1024 // Example estimation
134
155
} ;
135
156
}
136
157
137
- private estimateImpact ( suggestions : string , bundleInfo : BundleInfo ) : {
138
- sizeReduction : number ;
139
- performanceImprovement : number ;
140
- } {
158
+ private estimateImpact ( suggestions : string , bundleInfo : BundleInfo ) : ImpactEstimation {
141
159
const totalSize = bundleInfo . size . raw ;
142
160
const codeSplitting = this . parseCodeSplitting ( suggestions ) ;
143
161
const treeShaking = this . parseTreeShaking ( suggestions ) ;
0 commit comments