Skip to content

Commit 0305191

Browse files
committed
Fixing bug where .map files would be included in the reported bundle size
1 parent d3a7ae0 commit 0305191

4 files changed

Lines changed: 53 additions & 15 deletions

File tree

dist/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96252,12 +96252,19 @@ var __webpack_exports__ = {};
9625296252
}
9625396253
const data = JSON.parse(external_fs_.readFileSync(filePath, 'utf8'));
9625496254
const { assets, chunks } = data.data.chunkGraph;
96255+
const excludedExtensions = [
96256+
'.js.map',
96257+
'.css.map',
96258+
'.ts.map',
96259+
'.LICENSE.txt'
96260+
];
9625596261
let totalSize = 0;
9625696262
let jsSize = 0;
9625796263
let cssSize = 0;
9625896264
let htmlSize = 0;
9625996265
let otherSize = 0;
96260-
const assetAnalysis = assets.map((asset)=>{
96266+
const assetAnalysis = assets.reduce((acc, asset)=>{
96267+
if (excludedExtensions.some((ext)=>asset.path.endsWith(ext))) return acc;
9626196268
totalSize += asset.size;
9626296269
let type = 'other';
9626396270
if (asset.path.endsWith('.js')) {
@@ -96270,12 +96277,13 @@ var __webpack_exports__ = {};
9627096277
type = 'html';
9627196278
htmlSize += asset.size;
9627296279
} else otherSize += asset.size;
96273-
return {
96280+
acc.push({
9627496281
path: asset.path,
9627596282
size: asset.size,
9627696283
type
96277-
};
96278-
});
96284+
});
96285+
return acc;
96286+
}, []);
9627996287
const chunkAnalysis = chunks.map((chunk)=>({
9628096288
name: chunk.name,
9628196289
size: chunk.size,

src/__tests__/fixtures/rsdoctor-data.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@
1313
"path": "dist/static/css/index.css",
1414
"size": 10485760,
1515
"chunks": ["index"]
16+
},
17+
{
18+
"id": 3,
19+
"path": "dist/static/js/index.js.map",
20+
"size": 104857600,
21+
"chunks": ["index"]
22+
},
23+
{
24+
"id": 4,
25+
"path": "dist/static/css/index.css.map",
26+
"size": 5242880,
27+
"chunks": ["index"]
28+
},
29+
{
30+
"id": 5,
31+
"path": "dist/static/js/vendor.LICENSE.txt",
32+
"size": 10240,
33+
"chunks": ["index"]
1634
}
1735
],
1836
"chunks": [

src/__tests__/report.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ describe('Report Module', () => {
2525
const result = parseRsdoctorData('non-existent.json');
2626
expect(result).toBeNull();
2727
});
28+
29+
describe('should exclude source maps and license files from size calculations', () => {
30+
it('should exclude .js.map, .css.map and .LICENSE.txt assets (fixture has 5, 3 should be excluded)', () => {
31+
const result = parseRsdoctorData(mockRsdoctorDataPath);
32+
expect(result?.assets).toHaveLength(2);
33+
});
34+
35+
it('should not include source map or license file sizes in otherSize', () => {
36+
const result = parseRsdoctorData(mockRsdoctorDataPath);
37+
expect(result?.otherSize).toBe(0);
38+
});
39+
});
2840
});
2941

3042
describe('generateProjectMarkdown', () => {

src/report.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,19 @@ export function parseRsdoctorData(filePath: string): BundleAnalysis | null {
9696

9797
const data: RsdoctorData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
9898
const { assets, chunks } = data.data.chunkGraph;
99-
99+
const excludedExtensions = ['.js.map', '.css.map', '.ts.map', '.LICENSE.txt'];
100+
100101
let totalSize = 0;
101102
let jsSize = 0;
102103
let cssSize = 0;
103104
let htmlSize = 0;
104105
let otherSize = 0;
105-
106-
const assetAnalysis = assets.map(asset => {
106+
107+
const assetAnalysis = assets.reduce((acc: Array<{ path: string; size: number; type: 'js' | 'css' | 'html' | 'other' }>, asset) => {
108+
if (excludedExtensions.some(ext => asset.path.endsWith(ext))) return acc;
109+
107110
totalSize += asset.size;
108-
111+
109112
let type: 'js' | 'css' | 'html' | 'other' = 'other';
110113
if (asset.path.endsWith('.js')) {
111114
type = 'js';
@@ -119,13 +122,10 @@ export function parseRsdoctorData(filePath: string): BundleAnalysis | null {
119122
} else {
120123
otherSize += asset.size;
121124
}
122-
123-
return {
124-
path: asset.path,
125-
size: asset.size,
126-
type
127-
};
128-
});
125+
126+
acc.push({ path: asset.path, size: asset.size, type });
127+
return acc;
128+
}, []);
129129

130130
const chunkAnalysis = chunks.map(chunk => ({
131131
name: chunk.name,

0 commit comments

Comments
 (0)