Skip to content

Commit 4d33bc1

Browse files
authored
Merge pull request #15 from avixiii-dev/ci/github-actions-update
Ci/GitHub actions update
2 parents 2ab34fe + c551124 commit 4d33bc1

File tree

6 files changed

+151
-110
lines changed

6 files changed

+151
-110
lines changed

.github/workflows/ci.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ jobs:
3333
- name: Run tests with coverage
3434
run: npm run test:coverage
3535

36-
- name: Upload coverage reports
36+
- name: Upload coverage to Codecov
3737
uses: codecov/codecov-action@v3
3838
with:
3939
token: ${{ secrets.CODECOV_TOKEN }}
4040
files: ./coverage/lcov.info
4141
flags: unittests
4242
name: codecov-umbrella
43-
fail_ci_if_error: true
43+
fail_ci_if_error: false
44+
verbose: true
4445

4546
build:
4647
needs: test

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"scripts": {
1515
"build": "tsc",
1616
"test": "jest --passWithNoTests",
17+
"test:coverage": "jest --coverage",
1718
"lint": "eslint \"src/**/*.{js,ts}\" --fix",
1819
"prepublishOnly": "npm run build",
1920
"prepare": "npm run build"

src/__tests__/history.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { BundleSizeHistory } from '../plugins/history';
2-
import { BundleStats } from '../types/history';
32
import { mkdir, writeFile, rm } from 'fs/promises';
43
import { join } from 'path';
54
import { tmpdir } from 'os';
5+
import { ExportData } from '../types/history';
66

77
describe('BundleSizeHistory', () => {
88
let history: BundleSizeHistory;
@@ -264,7 +264,8 @@ describe('BundleSizeHistory', () => {
264264
});
265265

266266
it('should handle invalid import data', async () => {
267-
const result = await history.importHistory({} as any);
267+
const invalidData = {} as Partial<ExportData>;
268+
const result = await history.importHistory(invalidData as ExportData);
268269
expect(result.success).toBe(false);
269270
expect(result.message).toContain('Invalid export data format');
270271
});

src/ai/analyzer.ts

+26-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ export interface AIAnalyzerOptions {
77
temperature?: number;
88
}
99

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+
1031
export class AIBundleAnalyzer {
1132
private openai: OpenAI;
1233
private model: string;
@@ -98,7 +119,7 @@ export class AIBundleAnalyzer {
98119
.map(line => line.trim());
99120
}
100121

101-
private parseCodeSplitting(suggestions: string): any {
122+
private parseCodeSplitting(suggestions: string): CodeSplittingResult {
102123
const lines = suggestions.split('\n').filter(line => line.trim());
103124
const splitPoints = lines
104125
.filter(line => line.includes('/'))
@@ -116,28 +137,25 @@ export class AIBundleAnalyzer {
116137
};
117138
}
118139

119-
private parseTreeShaking(suggestions: string): any {
140+
private parseTreeShaking(suggestions: string): TreeShakingResult {
120141
const lines = suggestions.split('\n').filter(line => line.trim());
121142
const unusedExports = lines
122143
.filter(line => line.includes('export'))
123144
.map(line => {
124145
const [module, ...exports] = line.split(':').map(s => s.trim());
125146
return {
126147
module,
127-
exports: exports[0].split(',').map(e => e.trim())
148+
exports: exports.join(':').split(',').map(e => e.trim())
128149
};
129150
});
130151

131152
return {
132153
unusedExports,
133-
potentialSavings: unusedExports.length * 1000 // Example estimation
154+
potentialSavings: unusedExports.length * 1024 // Example estimation
134155
};
135156
}
136157

137-
private estimateImpact(suggestions: string, bundleInfo: BundleInfo): {
138-
sizeReduction: number;
139-
performanceImprovement: number;
140-
} {
158+
private estimateImpact(suggestions: string, bundleInfo: BundleInfo): ImpactEstimation {
141159
const totalSize = bundleInfo.size.raw;
142160
const codeSplitting = this.parseCodeSplitting(suggestions);
143161
const treeShaking = this.parseTreeShaking(suggestions);

0 commit comments

Comments
 (0)