Skip to content

Commit

Permalink
fix: Modules - use original size for compute fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Aug 19, 2024
1 parent a34760f commit f4e30a7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export const addRowFlags = (row: ReportMetricRow): ReportMetricModuleRow => {
return run;
}

const moduleRun = run as Module & ReportMetricRun;
const moduleRun = run as Module & ReportMetricRun & { originalValue: number };
const chunkCount = moduleRun.chunkIds?.length || 0;

return {
...moduleRun,
size: moduleRun.value,
sizeDuplicate: chunkCount > 1 ? (chunkCount - 1) * moduleRun.value : 0,
sizeTotal: chunkCount * moduleRun.value,
size: moduleRun.originalValue,
sizeDuplicate: chunkCount > 1 ? (chunkCount - 1) * moduleRun.originalValue : 0,
sizeTotal: chunkCount * moduleRun.originalValue,
};
});

Expand Down
75 changes: 50 additions & 25 deletions packages/utils/src/webpack/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ const getStatsMetrics = (job) => {
const metrics = pick(data, SUMMARY_METRIC_PATHS);

// Rename metric keys
return Object.entries(metrics).reduce((agg, [key, value]) => ({
...agg,
[`webpack.${key}`]: value,
}), {});
return Object.entries(metrics).reduce(
(agg, [key, value]) => ({
...agg,
[`webpack.${key}`]: value,
}),
{},
);
};

/**
Expand All @@ -47,10 +50,13 @@ const getSizeMetrics = (job) => {
const metrics = get(job, 'metrics.webpack.sizes', {});

// List metrics by the metrics list
return Object.keys(metricTypes.sizes).reduce((agg, key) => ({
...agg,
[`webpack.sizes.${key}`]: metrics[key],
}), {});
return Object.keys(metricTypes.sizes).reduce(
(agg, key) => ({
...agg,
[`webpack.sizes.${key}`]: metrics[key],
}),
{},
);
};

/**
Expand All @@ -77,7 +83,20 @@ const getAssetsMetrics = (job) => get(job, 'metrics.webpack.assets', {});
*
* @return {Object} Webpack module metrics
*/
const getModulesMetrics = (job) => get(job, 'metrics.webpack.modules', {});
export const getModulesMetrics = (job) => {
const modules = get(job, 'metrics.webpack.modules', {});

const result = {};

Object.entries(modules).forEach(([moduleId, moduleData]) => {
result[moduleId] = {
...moduleData,
originalValue: moduleData.value,
};
});

return result;
};

/**
*
Expand All @@ -92,15 +111,18 @@ const getModulesMetrics = (job) => get(job, 'metrics.webpack.modules', {});
*/
export const getModulesDuplicateSizeMetrics = (job) => {
const modules = get(job, 'metrics.webpack.modules', {});
return Object.keys(modules).reduce((modulesWithDupes, key) => {
const module = modules[key];
// eslint-disable-next-line no-param-reassign
modulesWithDupes[key] = {
...module,
value: module.value * (module.chunkIds.length - 1),

const result = {};

Object.entries(modules).forEach(([moduleId, moduleData]) => {
result[moduleId] = {
...moduleData,
value: moduleData.value * (moduleData.chunkIds.length - 1),
originalValue: moduleData.value,
};
return modulesWithDupes;
}, {});
});

return result;
};

/**
Expand All @@ -116,15 +138,18 @@ export const getModulesDuplicateSizeMetrics = (job) => {
*/
export const getModulesTotalSizeMetrics = (job) => {
const modules = get(job, 'metrics.webpack.modules', {});
return Object.keys(modules).reduce((modulesWithDupes, key) => {
const module = modules[key];
// eslint-disable-next-line no-param-reassign
modulesWithDupes[key] = {
...module,
value: module.value * module.chunkIds.length,

const result = {};

Object.entries(modules).forEach(([moduleId, moduleData]) => {
result[moduleId] = {
...moduleData,
value: moduleData.value * moduleData.chunkIds.length,
originalValue: moduleData.value,
};
return modulesWithDupes;
}, {});
});

return result;
};

/**
Expand Down

0 comments on commit f4e30a7

Please sign in to comment.