Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci/GitHub actions update #13

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/__tests__/history.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BundleSizeHistory } from '../plugins/history';
import { BundleStats } from '../types/history';
import { mkdir, writeFile, rm } from 'fs/promises';
import { join } from 'path';
import { tmpdir } from 'os';
import { ExportData } from '../types/history';

describe('BundleSizeHistory', () => {
let history: BundleSizeHistory;
Expand Down Expand Up @@ -264,7 +264,8 @@ describe('BundleSizeHistory', () => {
});

it('should handle invalid import data', async () => {
const result = await history.importHistory({} as any);
const invalidData = {} as Partial<ExportData>;
const result = await history.importHistory(invalidData as ExportData);
expect(result.success).toBe(false);
expect(result.message).toContain('Invalid export data format');
});
Expand Down
34 changes: 26 additions & 8 deletions src/ai/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ export interface AIAnalyzerOptions {
temperature?: number;
}

interface CodeSplittingResult {
splitPoints: string[];
impact: Array<{
path: string;
sizeReduction: number;
}>;
}

interface TreeShakingResult {
unusedExports: Array<{
module: string;
exports: string[];
}>;
potentialSavings: number;
}

interface ImpactEstimation {
sizeReduction: number;
performanceImprovement: number;
}

export class AIBundleAnalyzer {
private openai: OpenAI;
private model: string;
Expand Down Expand Up @@ -98,7 +119,7 @@ export class AIBundleAnalyzer {
.map(line => line.trim());
}

private parseCodeSplitting(suggestions: string): any {
private parseCodeSplitting(suggestions: string): CodeSplittingResult {
const lines = suggestions.split('\n').filter(line => line.trim());
const splitPoints = lines
.filter(line => line.includes('/'))
Expand All @@ -116,28 +137,25 @@ export class AIBundleAnalyzer {
};
}

private parseTreeShaking(suggestions: string): any {
private parseTreeShaking(suggestions: string): TreeShakingResult {
const lines = suggestions.split('\n').filter(line => line.trim());
const unusedExports = lines
.filter(line => line.includes('export'))
.map(line => {
const [module, ...exports] = line.split(':').map(s => s.trim());
return {
module,
exports: exports[0].split(',').map(e => e.trim())
exports: exports.join(':').split(',').map(e => e.trim())
};
});

return {
unusedExports,
potentialSavings: unusedExports.length * 1000 // Example estimation
potentialSavings: unusedExports.length * 1024 // Example estimation
};
}

private estimateImpact(suggestions: string, bundleInfo: BundleInfo): {
sizeReduction: number;
performanceImprovement: number;
} {
private estimateImpact(suggestions: string, bundleInfo: BundleInfo): ImpactEstimation {
const totalSize = bundleInfo.size.raw;
const codeSplitting = this.parseCodeSplitting(suggestions);
const treeShaking = this.parseTreeShaking(suggestions);
Expand Down
Loading
Loading