@bundle-stats/utils 4.2.3-beta.0 → 4.2.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -10
- package/lib/browsertime/metrics.js +22 -22
- package/lib/browsertime/metrics.js.map +1 -1
- package/lib/config/component-links.js +7 -1
- package/lib/config/component-links.js.map +1 -1
- package/lib/config/file-types.js +3 -3
- package/lib/config/file-types.js.map +1 -1
- package/lib/config/index.js +1 -2
- package/lib/config/index.js.map +1 -1
- package/lib/config/metric-types.js +28 -0
- package/lib/config/metric-types.js.map +1 -0
- package/lib/constants.js +23 -22
- package/lib/constants.js.map +1 -1
- package/lib/i18n.js +15 -10
- package/lib/i18n.js.map +1 -1
- package/lib/jobs/create-job.js +17 -7
- package/lib/jobs/create-job.js.map +1 -1
- package/lib/jobs/create-jobs.js.map +1 -1
- package/lib/lighthouse/metrics.js +13 -13
- package/lib/lighthouse/metrics.js.map +1 -1
- package/lib/report/add-row-metric-data.js +4 -4
- package/lib/report/add-row-metric-data.js.map +1 -1
- package/lib/report/compare-metrics.js +4 -1
- package/lib/report/compare-metrics.js.map +1 -1
- package/lib/report/create.js +17 -7
- package/lib/report/create.js.map +1 -1
- package/lib/report/get-metric-changed.js.map +1 -1
- package/lib/report/index.js +1 -0
- package/lib/report/index.js.map +1 -1
- package/lib/report/merge-metrics-by-key.js +1 -1
- package/lib/report/merge-metrics-by-key.js.map +1 -1
- package/lib/utils/component-links.js +191 -27
- package/lib/utils/component-links.js.map +1 -1
- package/lib/utils/date.js.map +1 -1
- package/lib/utils/delta.js +35 -30
- package/lib/utils/delta.js.map +1 -1
- package/lib/utils/format.js +5 -6
- package/lib/utils/format.js.map +1 -1
- package/lib/utils/insights.js.map +1 -1
- package/lib/utils/metrics.js +49 -32
- package/lib/utils/metrics.js.map +1 -1
- package/lib/webpack/compare.js +16 -12
- package/lib/webpack/compare.js.map +1 -1
- package/lib/webpack/extract/assets.js +7 -1
- package/lib/webpack/extract/assets.js.map +1 -1
- package/lib/webpack/extract/meta.js.map +1 -1
- package/lib/webpack/extract/modules-packages-duplicate.js.map +1 -1
- package/lib/webpack/extract/modules-packages-new-insight.js.map +1 -1
- package/lib/webpack/extract/modules-packages.js +8 -1
- package/lib/webpack/extract/modules-packages.js.map +1 -1
- package/lib/webpack/extract/modules.js +45 -20
- package/lib/webpack/extract/modules.js.map +1 -1
- package/lib/webpack/metrics.js +35 -34
- package/lib/webpack/metrics.js.map +1 -1
- package/lib/webpack/selectors.js +40 -3
- package/lib/webpack/selectors.js.map +1 -1
- package/lib/webpack/types.js +1 -1
- package/lib/webpack/types.js.map +1 -1
- package/lib/webpack/utils.js +37 -25
- package/lib/webpack/utils.js.map +1 -1
- package/lib-esm/browsertime/metrics.js +22 -22
- package/lib-esm/browsertime/metrics.js.map +1 -1
- package/lib-esm/config/component-links.js +6 -0
- package/lib-esm/config/component-links.js.map +1 -1
- package/lib-esm/config/file-types.js +3 -3
- package/lib-esm/config/file-types.js.map +1 -1
- package/lib-esm/config/index.js +1 -2
- package/lib-esm/config/index.js.map +1 -1
- package/lib-esm/config/metric-types.js +25 -0
- package/lib-esm/config/metric-types.js.map +1 -0
- package/lib-esm/constants.js +19 -18
- package/lib-esm/constants.js.map +1 -1
- package/lib-esm/i18n.js +15 -10
- package/lib-esm/i18n.js.map +1 -1
- package/lib-esm/jobs/create-job.js.map +1 -1
- package/lib-esm/jobs/create-jobs.js.map +1 -1
- package/lib-esm/lighthouse/metrics.js +13 -13
- package/lib-esm/lighthouse/metrics.js.map +1 -1
- package/lib-esm/report/add-row-metric-data.js +4 -4
- package/lib-esm/report/add-row-metric-data.js.map +1 -1
- package/lib-esm/report/compare-metrics.js +4 -1
- package/lib-esm/report/compare-metrics.js.map +1 -1
- package/lib-esm/report/create.js.map +1 -1
- package/lib-esm/report/get-metric-changed.js.map +1 -1
- package/lib-esm/report/index.js +1 -0
- package/lib-esm/report/index.js.map +1 -1
- package/lib-esm/report/merge-metrics-by-key.js +1 -1
- package/lib-esm/report/merge-metrics-by-key.js.map +1 -1
- package/lib-esm/utils/component-links.js +185 -27
- package/lib-esm/utils/component-links.js.map +1 -1
- package/lib-esm/utils/date.js.map +1 -1
- package/lib-esm/utils/delta.js +32 -26
- package/lib-esm/utils/delta.js.map +1 -1
- package/lib-esm/utils/format.js.map +1 -1
- package/lib-esm/utils/insights.js.map +1 -1
- package/lib-esm/utils/metrics.js +44 -27
- package/lib-esm/utils/metrics.js.map +1 -1
- package/lib-esm/webpack/compare.js +7 -5
- package/lib-esm/webpack/compare.js.map +1 -1
- package/lib-esm/webpack/extract/assets.js +7 -1
- package/lib-esm/webpack/extract/assets.js.map +1 -1
- package/lib-esm/webpack/extract/meta.js.map +1 -1
- package/lib-esm/webpack/extract/modules-packages-duplicate.js.map +1 -1
- package/lib-esm/webpack/extract/modules-packages-new-insight.js.map +1 -1
- package/lib-esm/webpack/extract/modules-packages.js +8 -1
- package/lib-esm/webpack/extract/modules-packages.js.map +1 -1
- package/lib-esm/webpack/extract/modules.js +45 -20
- package/lib-esm/webpack/extract/modules.js.map +1 -1
- package/lib-esm/webpack/metrics.js +35 -34
- package/lib-esm/webpack/metrics.js.map +1 -1
- package/lib-esm/webpack/selectors.js +35 -1
- package/lib-esm/webpack/selectors.js.map +1 -1
- package/lib-esm/webpack/utils.js +37 -25
- package/lib-esm/webpack/utils.js.map +1 -1
- package/package.json +20 -22
- package/src/browsertime/metrics.js +22 -22
- package/src/config/component-links.js +7 -0
- package/src/config/file-types.js +3 -3
- package/src/config/index.js +1 -2
- package/src/config/metric-types.ts +25 -0
- package/src/constants.ts +94 -34
- package/src/i18n.js +15 -10
- package/src/lighthouse/metrics.js +13 -15
- package/src/report/add-row-metric-data.ts +42 -38
- package/src/report/compare-metrics.ts +7 -4
- package/src/report/create.ts +1 -1
- package/src/report/index.js +1 -0
- package/src/report/merge-metrics-by-key.ts +7 -5
- package/src/report/types.ts +17 -0
- package/src/utils/component-links.ts +276 -35
- package/src/utils/delta.ts +98 -0
- package/src/utils/metrics.ts +88 -0
- package/src/webpack/compare.ts +62 -0
- package/src/webpack/extract/assets.ts +13 -7
- package/src/webpack/extract/modules-packages.ts +74 -61
- package/src/webpack/extract/modules.ts +66 -33
- package/src/webpack/{metrics.js → metrics.ts} +41 -39
- package/src/webpack/selectors.js +82 -9
- package/src/webpack/types.ts +13 -4
- package/src/webpack/utils.ts +173 -0
- package/types/browsertime/compare.d.ts +1 -1
- package/types/browsertime/metrics.d.ts +63 -43
- package/types/config/component-links.d.ts +26 -18
- package/types/config/file-types.d.ts +17 -17
- package/types/config/index.d.ts +1 -2
- package/types/config/metric-types.d.ts +2 -0
- package/types/constants.d.ts +52 -29
- package/types/i18n.d.ts +19 -14
- package/types/lighthouse/compare.d.ts +1 -1
- package/types/lighthouse/filter.d.ts +1 -1
- package/types/lighthouse/metrics.d.ts +36 -28
- package/types/report/add-row-metric-data.d.ts +1 -16
- package/types/report/compare-metrics.d.ts +1 -1
- package/types/report/index.d.ts +1 -0
- package/types/report/merge-metrics-by-key.d.ts +1 -1
- package/types/report/types.d.ts +12 -0
- package/types/utils/component-links.d.ts +24 -8
- package/types/utils/delta.d.ts +4 -6
- package/types/utils/metrics.d.ts +4 -3
- package/types/webpack/compare.d.ts +11 -14
- package/types/webpack/constants.d.ts +1 -1
- package/types/webpack/extract/assets-size-total-insight.d.ts +2 -2
- package/types/webpack/extract/modules.d.ts +1 -1
- package/types/webpack/metrics.d.ts +7 -153
- package/types/webpack/selectors.d.ts +21 -7
- package/types/webpack/types.d.ts +4 -4
- package/types/webpack/utils.d.ts +8 -8
- package/CHANGELOG.md +0 -333
- package/lib/config/delta.js +0 -13
- package/lib/config/delta.js.map +0 -1
- package/lib/config/metrics.js +0 -32
- package/lib/config/metrics.js.map +0 -1
- package/lib-esm/config/delta.js +0 -10
- package/lib-esm/config/delta.js.map +0 -1
- package/lib-esm/config/metrics.js +0 -29
- package/lib-esm/config/metrics.js.map +0 -1
- package/src/config/delta.js +0 -11
- package/src/config/metrics.js +0 -35
- package/src/utils/delta.js +0 -94
- package/src/utils/metrics.js +0 -92
- package/src/webpack/compare.js +0 -81
- package/src/webpack/utils.js +0 -155
- package/types/config/delta.d.ts +0 -9
- package/types/config/metrics.d.ts +0 -35
|
@@ -1,114 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
METRIC_TYPE_FILE_SIZE,
|
|
3
|
-
METRIC_TYPE_NUMERIC,
|
|
4
|
-
METRIC_TYPE_PERCENTAGE,
|
|
5
|
-
} from '../config/metrics';
|
|
6
1
|
import { FILE_TYPE_LABELS } from '../config/file-types';
|
|
7
2
|
import { Metric } from './types';
|
|
3
|
+
import { MetricTypes, MetricConfig } from '../constants';
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
type WebpackMetrics = Partial<Record<Metric, MetricConfig>> & {
|
|
6
|
+
sizes: Partial<Record<Metric, MetricConfig>>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const metrics: WebpackMetrics = {
|
|
10
10
|
[Metric.BUNDLE_SIZE]: {
|
|
11
11
|
label: 'Bundle Size',
|
|
12
|
-
description: '
|
|
12
|
+
description: 'Total file size of the assets generated or processed by the bundler',
|
|
13
13
|
url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
|
|
14
|
-
type:
|
|
14
|
+
type: MetricTypes.FileSize,
|
|
15
15
|
},
|
|
16
16
|
[Metric.INITIAL_SIZE_JS]: {
|
|
17
17
|
label: 'Initial JS',
|
|
18
|
-
description: '
|
|
18
|
+
description: 'Total file size of the JavaScript initial chunks',
|
|
19
19
|
url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
|
|
20
|
-
type:
|
|
20
|
+
type: MetricTypes.FileSize,
|
|
21
21
|
},
|
|
22
22
|
[Metric.INITIAL_SIZE_CSS]: {
|
|
23
23
|
label: 'Initial CSS',
|
|
24
|
-
description: '
|
|
24
|
+
description: 'Total file size of the CSS initial chunks',
|
|
25
25
|
url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
|
|
26
|
-
type:
|
|
26
|
+
type: MetricTypes.FileSize,
|
|
27
27
|
},
|
|
28
28
|
[Metric.CACHE_INVALIDATION]: {
|
|
29
29
|
label: 'Cache Invalidation',
|
|
30
|
-
description:
|
|
30
|
+
description:
|
|
31
|
+
'Ratio between the total file size of the changed assets and the total file size(Bundle Size)',
|
|
31
32
|
url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
|
|
32
|
-
type:
|
|
33
|
-
biggerIsBetter:
|
|
33
|
+
type: MetricTypes.Percentage,
|
|
34
|
+
biggerIsBetter: null,
|
|
35
|
+
skipDelta: true,
|
|
34
36
|
},
|
|
35
37
|
[Metric.CHUNK_COUNT]: {
|
|
36
38
|
label: 'Chunks',
|
|
37
|
-
description: '
|
|
39
|
+
description: 'Total number of chunks generated by the bundler',
|
|
38
40
|
url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
|
|
39
|
-
type:
|
|
40
|
-
biggerIsBetter:
|
|
41
|
+
type: MetricTypes.Numeric,
|
|
42
|
+
biggerIsBetter: null,
|
|
41
43
|
},
|
|
42
44
|
[Metric.ASSET_COUNT]: {
|
|
43
45
|
label: 'Assets',
|
|
44
|
-
description: 'Total number of assets',
|
|
46
|
+
description: 'Total number of assets generated or produced by the bundler',
|
|
45
47
|
url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
|
|
46
|
-
type:
|
|
47
|
-
biggerIsBetter:
|
|
48
|
+
type: MetricTypes.Numeric,
|
|
49
|
+
biggerIsBetter: null,
|
|
48
50
|
},
|
|
49
51
|
[Metric.MODULE_COUNT]: {
|
|
50
52
|
label: 'Modules',
|
|
51
|
-
description: '
|
|
53
|
+
description: 'Total number of bundled modules',
|
|
52
54
|
url: 'https://relative-ci.com/documentation/metrics-and-data#modules-1',
|
|
53
|
-
type:
|
|
54
|
-
biggerIsBetter:
|
|
55
|
+
type: MetricTypes.Numeric,
|
|
56
|
+
biggerIsBetter: null,
|
|
55
57
|
},
|
|
56
58
|
[Metric.DUPLICATE_MODULES_COUNT]: {
|
|
57
59
|
label: 'Duplicate Modules',
|
|
58
|
-
description: '
|
|
60
|
+
description: 'Total number of modules included into more than one chunk',
|
|
59
61
|
url: 'https://relative-ci.com/documentation/metrics-and-data#modules-1',
|
|
60
|
-
type:
|
|
62
|
+
type: MetricTypes.Numeric,
|
|
61
63
|
biggerIsBetter: false,
|
|
62
64
|
},
|
|
63
65
|
[Metric.DUPLICATE_CODE]: {
|
|
64
66
|
label: 'Duplicate Code',
|
|
65
67
|
description: 'The percentage of total duplicate module size from the total module size',
|
|
66
68
|
url: 'https://relative-ci.com/documentation/metrics-and-data#modules-1',
|
|
67
|
-
type:
|
|
68
|
-
biggerIsBetter:
|
|
69
|
+
type: MetricTypes.Percentage,
|
|
70
|
+
biggerIsBetter: null,
|
|
69
71
|
},
|
|
70
72
|
[Metric.PACKAGE_COUNT]: {
|
|
71
73
|
label: 'Packages',
|
|
72
|
-
description: 'The total number of
|
|
74
|
+
description: 'The total number of bundled packages',
|
|
73
75
|
url: 'https://relative-ci.com/documentation/metrics-and-data#packages',
|
|
74
|
-
type:
|
|
76
|
+
type: MetricTypes.Numeric,
|
|
75
77
|
biggerIsBetter: false,
|
|
76
78
|
},
|
|
77
79
|
[Metric.DUPLICATE_PACKAGES_COUNT]: {
|
|
78
80
|
label: 'Duplicate Packages',
|
|
79
|
-
description: 'The total number of duplicate packages',
|
|
81
|
+
description: 'The total number of duplicate bundled packages',
|
|
80
82
|
url: 'https://relative-ci.com/documentation/metrics-and-data#packages',
|
|
81
|
-
type:
|
|
83
|
+
type: MetricTypes.Numeric,
|
|
82
84
|
biggerIsBetter: false,
|
|
83
85
|
},
|
|
84
86
|
sizes: {
|
|
85
87
|
[Metric.TOTAL_SIZE_JS]: {
|
|
86
88
|
label: FILE_TYPE_LABELS.JS,
|
|
87
|
-
type:
|
|
89
|
+
type: MetricTypes.FileSize,
|
|
88
90
|
},
|
|
89
91
|
[Metric.TOTAL_SIZE_CSS]: {
|
|
90
92
|
label: FILE_TYPE_LABELS.CSS,
|
|
91
|
-
type:
|
|
93
|
+
type: MetricTypes.FileSize,
|
|
92
94
|
},
|
|
93
95
|
[Metric.TOTAL_SIZE_IMG]: {
|
|
94
96
|
label: FILE_TYPE_LABELS.IMG,
|
|
95
|
-
type:
|
|
97
|
+
type: MetricTypes.FileSize,
|
|
96
98
|
},
|
|
97
99
|
[Metric.TOTAL_SIZE_MEDIA]: {
|
|
98
100
|
label: FILE_TYPE_LABELS.MEDIA,
|
|
99
|
-
type:
|
|
101
|
+
type: MetricTypes.FileSize,
|
|
100
102
|
},
|
|
101
103
|
[Metric.TOTAL_SIZE_FONT]: {
|
|
102
104
|
label: FILE_TYPE_LABELS.FONT,
|
|
103
|
-
type:
|
|
105
|
+
type: MetricTypes.FileSize,
|
|
104
106
|
},
|
|
105
107
|
[Metric.TOTAL_SIZE_HTML]: {
|
|
106
108
|
label: FILE_TYPE_LABELS.HTML,
|
|
107
|
-
type:
|
|
109
|
+
type: MetricTypes.FileSize,
|
|
108
110
|
},
|
|
109
111
|
[Metric.TOTAL_SIZE_OTHER]: {
|
|
110
112
|
label: FILE_TYPE_LABELS.OTHER,
|
|
111
|
-
type:
|
|
113
|
+
type: MetricTypes.FileSize,
|
|
112
114
|
},
|
|
113
115
|
},
|
|
114
116
|
};
|
package/src/webpack/selectors.js
CHANGED
|
@@ -26,10 +26,13 @@ const getStatsMetrics = (job) => {
|
|
|
26
26
|
const metrics = pick(data, SUMMARY_METRIC_PATHS);
|
|
27
27
|
|
|
28
28
|
// Rename metric keys
|
|
29
|
-
return Object.entries(metrics).reduce(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
return Object.entries(metrics).reduce(
|
|
30
|
+
(agg, [key, value]) => ({
|
|
31
|
+
...agg,
|
|
32
|
+
[`webpack.${key}`]: value,
|
|
33
|
+
}),
|
|
34
|
+
{},
|
|
35
|
+
);
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
/**
|
|
@@ -47,10 +50,13 @@ const getSizeMetrics = (job) => {
|
|
|
47
50
|
const metrics = get(job, 'metrics.webpack.sizes', {});
|
|
48
51
|
|
|
49
52
|
// List metrics by the metrics list
|
|
50
|
-
return Object.keys(metricTypes.sizes).reduce(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
return Object.keys(metricTypes.sizes).reduce(
|
|
54
|
+
(agg, key) => ({
|
|
55
|
+
...agg,
|
|
56
|
+
[`webpack.sizes.${key}`]: metrics[key],
|
|
57
|
+
}),
|
|
58
|
+
{},
|
|
59
|
+
);
|
|
54
60
|
};
|
|
55
61
|
|
|
56
62
|
/**
|
|
@@ -77,7 +83,74 @@ const getAssetsMetrics = (job) => get(job, 'metrics.webpack.assets', {});
|
|
|
77
83
|
*
|
|
78
84
|
* @return {Object} Webpack module metrics
|
|
79
85
|
*/
|
|
80
|
-
const getModulesMetrics = (job) =>
|
|
86
|
+
export const getModulesMetrics = (job) => {
|
|
87
|
+
const modules = get(job, 'metrics.webpack.modules', {});
|
|
88
|
+
|
|
89
|
+
const result = {};
|
|
90
|
+
|
|
91
|
+
Object.entries(modules).forEach(([moduleId, moduleData]) => {
|
|
92
|
+
result[moduleId] = {
|
|
93
|
+
...moduleData,
|
|
94
|
+
originalValue: moduleData.value,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return result;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* Select webpack module duplicate size
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} job Job data
|
|
106
|
+
* @param {Object} job.metrics Job metrics
|
|
107
|
+
* @param {Object} job.metrics.webpack Job webpack metrics
|
|
108
|
+
* @param {Object} job.metrics.webpack.modules Job webpack module metrics
|
|
109
|
+
*
|
|
110
|
+
* @return {Object} Webpack module metrics
|
|
111
|
+
*/
|
|
112
|
+
export const getModulesDuplicateSizeMetrics = (job) => {
|
|
113
|
+
const modules = get(job, 'metrics.webpack.modules', {});
|
|
114
|
+
|
|
115
|
+
const result = {};
|
|
116
|
+
|
|
117
|
+
Object.entries(modules).forEach(([moduleId, moduleData]) => {
|
|
118
|
+
result[moduleId] = {
|
|
119
|
+
...moduleData,
|
|
120
|
+
value: moduleData.value * (moduleData.chunkIds.length - 1),
|
|
121
|
+
originalValue: moduleData.value,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* Select webpack module size including duplication
|
|
131
|
+
*
|
|
132
|
+
* @param {Object} job Job data
|
|
133
|
+
* @param {Object} job.metrics Job metrics
|
|
134
|
+
* @param {Object} job.metrics.webpack Job webpack metrics
|
|
135
|
+
* @param {Object} job.metrics.webpack.modules Job webpack module metrics
|
|
136
|
+
*
|
|
137
|
+
* @return {Object} Webpack module metrics
|
|
138
|
+
*/
|
|
139
|
+
export const getModulesTotalSizeMetrics = (job) => {
|
|
140
|
+
const modules = get(job, 'metrics.webpack.modules', {});
|
|
141
|
+
|
|
142
|
+
const result = {};
|
|
143
|
+
|
|
144
|
+
Object.entries(modules).forEach(([moduleId, moduleData]) => {
|
|
145
|
+
result[moduleId] = {
|
|
146
|
+
...moduleData,
|
|
147
|
+
value: moduleData.value * moduleData.chunkIds.length,
|
|
148
|
+
originalValue: moduleData.value,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return result;
|
|
153
|
+
};
|
|
81
154
|
|
|
82
155
|
/**
|
|
83
156
|
*
|
package/src/webpack/types.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface MetaChunk {
|
|
|
29
29
|
name: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export interface
|
|
32
|
+
export interface AssetMetricRun extends MetricRun {
|
|
33
33
|
name: string;
|
|
34
34
|
isEntry: boolean;
|
|
35
35
|
isInitial: boolean;
|
|
@@ -37,7 +37,7 @@ export interface Asset extends MetricRun {
|
|
|
37
37
|
chunkId?: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export type Assets = Record<string,
|
|
40
|
+
export type Assets = Record<string, AssetMetricRun>;
|
|
41
41
|
|
|
42
42
|
export interface MetricsAssets {
|
|
43
43
|
metrics: {
|
|
@@ -48,12 +48,21 @@ export interface MetricsAssets {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Metric run data for a module entry
|
|
53
|
+
*/
|
|
51
54
|
export interface Module extends MetricRun {
|
|
55
|
+
/* Module name */
|
|
52
56
|
name: string;
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
/* Array of chunk IDs */
|
|
58
|
+
chunkIds: Array<string>;
|
|
59
|
+
/* Flag to identify if the module is duplicated on the current job */
|
|
60
|
+
duplicated?: boolean;
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Collection of module metrics
|
|
65
|
+
*/
|
|
57
66
|
export type Modules = Record<string, Module>;
|
|
58
67
|
|
|
59
68
|
export interface MetricsModules {
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import round from 'lodash/round';
|
|
2
|
+
|
|
3
|
+
import { PACKAGES_SEPARATOR, PACKAGE_ID_SEPARATOR } from '../config';
|
|
4
|
+
import { createGetMetricType } from '../utils/metrics';
|
|
5
|
+
import { metrics } from './metrics';
|
|
6
|
+
|
|
7
|
+
// Hex patterns
|
|
8
|
+
const HEX_HASH_PATTERN = '[a-f0-9]{5,32}';
|
|
9
|
+
const HEX_HASH_SEPARATOR_PATTERN = '[-_.~]';
|
|
10
|
+
|
|
11
|
+
// Base64URL patterns
|
|
12
|
+
const BASE64URL_HASH_PATTERN = '[A-Za-z0-9_-]{4,}';
|
|
13
|
+
const BASE64URL_SEPARATOR_PATTERN = '[.~]';
|
|
14
|
+
|
|
15
|
+
// Match multiple extensions: .js, .js.gz, .min.js, .chunk.js
|
|
16
|
+
const EXTENSION_PATTERN = /(?:\.[a-z0-9]{2,}){1,}/;
|
|
17
|
+
|
|
18
|
+
const PATTERNS = [
|
|
19
|
+
// Match path/name-HEXHASH.EXT,
|
|
20
|
+
// path/name.HEXHASH.EXT,
|
|
21
|
+
// path/name_HEXHASH.EXT,
|
|
22
|
+
// path/name-HEXHASH.chunk.EXT
|
|
23
|
+
{
|
|
24
|
+
pattern: new RegExp(
|
|
25
|
+
`(.*)${HEX_HASH_SEPARATOR_PATTERN}${HEX_HASH_PATTERN}(${EXTENSION_PATTERN.source})$`,
|
|
26
|
+
),
|
|
27
|
+
replace: '$1$2',
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
// Match path/name-BASE64URLHASH.EXT,
|
|
31
|
+
// path/name.BASE64URLHASH.EXT,
|
|
32
|
+
// path/name_BASE64URLHASH.EXT,
|
|
33
|
+
// path/name-BASE64URLHASH.chunk.EXT
|
|
34
|
+
{
|
|
35
|
+
pattern: new RegExp(
|
|
36
|
+
`(.*)${BASE64URL_SEPARATOR_PATTERN}${BASE64URL_HASH_PATTERN}(${EXTENSION_PATTERN.source})$`,
|
|
37
|
+
),
|
|
38
|
+
replace: '$1$2',
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// Match static/HEXHASH.ext
|
|
42
|
+
{
|
|
43
|
+
pattern: new RegExp(`(static)/${HEX_HASH_PATTERN}(.*${EXTENSION_PATTERN.source})$`),
|
|
44
|
+
replace: '$1$2',
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// Match static/HEXHASH/_name.ext
|
|
48
|
+
{
|
|
49
|
+
pattern: new RegExp(`(static)/${BASE64URL_HASH_PATTERN}/(_.*${EXTENSION_PATTERN.source})$`),
|
|
50
|
+
replace: '$1/[hash]/$2',
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const NO_BASENAME = /(^|.*\/)\..*$/;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Extract (guess) filename from a hashed filename
|
|
58
|
+
*/
|
|
59
|
+
export const getAssetName = (statsAssetPath?: string | null): string => {
|
|
60
|
+
if (!statsAssetPath) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < PATTERNS.length; i += 1) {
|
|
65
|
+
const { pattern, replace } = PATTERNS[i];
|
|
66
|
+
|
|
67
|
+
const extracted: string = statsAssetPath.replace(pattern, replace);
|
|
68
|
+
|
|
69
|
+
if (extracted && extracted !== statsAssetPath && !NO_BASENAME.test(extracted)) {
|
|
70
|
+
return extracted;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return statsAssetPath;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// css ./node_modules/css-loader/dist/cjs.js??ref--6-0!./src/assets/styles/default.styl
|
|
78
|
+
const NAME_WITH_LOADERS = /!/;
|
|
79
|
+
|
|
80
|
+
// ./src/index.jsx + 27 modules
|
|
81
|
+
const NAME_WITH_MODULES = /\s?\+\s?\d*\s?modules$/;
|
|
82
|
+
|
|
83
|
+
// css ../node_modules../node_modules/package-a
|
|
84
|
+
const INVALID_CSS_PREFIX = /^css\s.*node_modules(?!\/)/;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Extract normalize module name
|
|
88
|
+
*/
|
|
89
|
+
export const getModuleName = (name?: string | null) => {
|
|
90
|
+
if (!name) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (NAME_WITH_LOADERS.test(name)) {
|
|
95
|
+
const segments = name.split(NAME_WITH_LOADERS);
|
|
96
|
+
const normalizedName = segments[segments.length - 1];
|
|
97
|
+
|
|
98
|
+
if (normalizedName?.trim()) {
|
|
99
|
+
return normalizedName;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (NAME_WITH_MODULES.test(name)) {
|
|
104
|
+
return name.replace(NAME_WITH_MODULES, '');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (INVALID_CSS_PREFIX.test(name)) {
|
|
108
|
+
return name.replace(INVALID_CSS_PREFIX, '');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return name;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* Calculate cache invalidation metric on the baseline data
|
|
116
|
+
*
|
|
117
|
+
* The metric is the ratio between the total file size of the files that have changed (exclude
|
|
118
|
+
* deleted, added) and the total file size
|
|
119
|
+
*/
|
|
120
|
+
export const calculateCacheInvalidation = (rows: Array<any>): number => {
|
|
121
|
+
let cached = 0;
|
|
122
|
+
let invalidated = 0;
|
|
123
|
+
|
|
124
|
+
rows.forEach(({ changed, added, deleted, runs }) => {
|
|
125
|
+
// Added and deleted files do not count towards the caching index
|
|
126
|
+
if (added || deleted) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (changed) {
|
|
131
|
+
invalidated += runs[1].value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
cached += runs[1].value;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (cached === 0) {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return round((invalidated / cached) * 100, 2);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const getMetricAdded = (runs: Array<any>): boolean => {
|
|
145
|
+
const [current, baseline] = runs?.map((run) => run?.value) || [];
|
|
146
|
+
|
|
147
|
+
return Boolean(current !== null && !baseline);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const getMetricDeleted = (runs: Array<any>) => {
|
|
151
|
+
const [current, baseline] = runs?.map((run) => run?.value) || [];
|
|
152
|
+
|
|
153
|
+
return Boolean(baseline !== null && !current);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get webpack metric data
|
|
158
|
+
*/
|
|
159
|
+
export const getMetricType = createGetMetricType(metrics);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get public package name from package id
|
|
163
|
+
*/
|
|
164
|
+
export const getPackagePublicName = (packageId: string): string => {
|
|
165
|
+
// Split packages
|
|
166
|
+
const packageNames = packageId.split(PACKAGES_SEPARATOR);
|
|
167
|
+
const name = packageNames[packageNames.length - 1];
|
|
168
|
+
|
|
169
|
+
// Strip package suffix (eg: ~1)
|
|
170
|
+
return name.split(PACKAGE_ID_SEPARATOR)[0];
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const normalizeChunkId = (chunkId: string | number): string => chunkId.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function compare(jobs: any): import("
|
|
1
|
+
export function compare(jobs: any): import("..").ReportMetricRow[];
|
|
@@ -1,107 +1,127 @@
|
|
|
1
1
|
export namespace metrics {
|
|
2
2
|
namespace firstPaint {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
let label: string;
|
|
4
|
+
let type: MetricTypes;
|
|
5
5
|
}
|
|
6
6
|
namespace fullyLoaded {
|
|
7
|
-
|
|
7
|
+
let label_1: string;
|
|
8
8
|
export { label_1 as label };
|
|
9
|
-
|
|
9
|
+
let type_1: MetricTypes;
|
|
10
|
+
export { type_1 as type };
|
|
10
11
|
}
|
|
11
12
|
namespace backEndTime {
|
|
12
|
-
|
|
13
|
+
let label_2: string;
|
|
13
14
|
export { label_2 as label };
|
|
14
|
-
|
|
15
|
+
let type_2: MetricTypes;
|
|
16
|
+
export { type_2 as type };
|
|
15
17
|
}
|
|
16
18
|
namespace domContentLoadedTime {
|
|
17
|
-
|
|
19
|
+
let label_3: string;
|
|
18
20
|
export { label_3 as label };
|
|
19
|
-
|
|
21
|
+
let type_3: MetricTypes;
|
|
22
|
+
export { type_3 as type };
|
|
20
23
|
}
|
|
21
24
|
namespace domInteractiveTime {
|
|
22
|
-
|
|
25
|
+
let label_4: string;
|
|
23
26
|
export { label_4 as label };
|
|
24
|
-
|
|
27
|
+
let type_4: MetricTypes;
|
|
28
|
+
export { type_4 as type };
|
|
25
29
|
}
|
|
26
30
|
namespace domainLookupTime {
|
|
27
|
-
|
|
31
|
+
let label_5: string;
|
|
28
32
|
export { label_5 as label };
|
|
29
|
-
|
|
33
|
+
let type_5: MetricTypes;
|
|
34
|
+
export { type_5 as type };
|
|
30
35
|
}
|
|
31
36
|
namespace frontEndTime {
|
|
32
|
-
|
|
37
|
+
let label_6: string;
|
|
33
38
|
export { label_6 as label };
|
|
34
|
-
|
|
39
|
+
let type_6: MetricTypes;
|
|
40
|
+
export { type_6 as type };
|
|
35
41
|
}
|
|
36
42
|
namespace pageDownloadTime {
|
|
37
|
-
|
|
43
|
+
let label_7: string;
|
|
38
44
|
export { label_7 as label };
|
|
39
|
-
|
|
45
|
+
let type_7: MetricTypes;
|
|
46
|
+
export { type_7 as type };
|
|
40
47
|
}
|
|
41
48
|
namespace pageLoadTime {
|
|
42
|
-
|
|
49
|
+
let label_8: string;
|
|
43
50
|
export { label_8 as label };
|
|
44
|
-
|
|
51
|
+
let type_8: MetricTypes;
|
|
52
|
+
export { type_8 as type };
|
|
45
53
|
}
|
|
46
54
|
namespace redirectionTime {
|
|
47
|
-
|
|
55
|
+
let label_9: string;
|
|
48
56
|
export { label_9 as label };
|
|
49
|
-
|
|
57
|
+
let type_9: MetricTypes;
|
|
58
|
+
export { type_9 as type };
|
|
50
59
|
}
|
|
51
60
|
namespace serverConnectionTime {
|
|
52
|
-
|
|
61
|
+
let label_10: string;
|
|
53
62
|
export { label_10 as label };
|
|
54
|
-
|
|
63
|
+
let type_10: MetricTypes;
|
|
64
|
+
export { type_10 as type };
|
|
55
65
|
}
|
|
56
66
|
namespace serverResponseTime {
|
|
57
|
-
|
|
67
|
+
let label_11: string;
|
|
58
68
|
export { label_11 as label };
|
|
59
|
-
|
|
69
|
+
let type_11: MetricTypes;
|
|
70
|
+
export { type_11 as type };
|
|
60
71
|
}
|
|
61
72
|
namespace firstContentfulPaint {
|
|
62
|
-
|
|
73
|
+
let label_12: string;
|
|
63
74
|
export { label_12 as label };
|
|
64
|
-
|
|
75
|
+
let type_12: MetricTypes;
|
|
76
|
+
export { type_12 as type };
|
|
65
77
|
}
|
|
66
78
|
namespace rumSpeedIndex {
|
|
67
|
-
|
|
79
|
+
let label_13: string;
|
|
68
80
|
export { label_13 as label };
|
|
69
|
-
|
|
81
|
+
let type_13: MetricTypes;
|
|
82
|
+
export { type_13 as type };
|
|
70
83
|
}
|
|
71
84
|
namespace firstVisualChange {
|
|
72
|
-
|
|
85
|
+
let label_14: string;
|
|
73
86
|
export { label_14 as label };
|
|
74
|
-
|
|
87
|
+
let type_14: MetricTypes;
|
|
88
|
+
export { type_14 as type };
|
|
75
89
|
}
|
|
76
90
|
namespace lastVisualChange {
|
|
77
|
-
|
|
91
|
+
let label_15: string;
|
|
78
92
|
export { label_15 as label };
|
|
79
|
-
|
|
93
|
+
let type_15: MetricTypes;
|
|
94
|
+
export { type_15 as type };
|
|
80
95
|
}
|
|
81
96
|
namespace perceptualSpeedIndex {
|
|
82
|
-
|
|
97
|
+
let label_16: string;
|
|
83
98
|
export { label_16 as label };
|
|
84
|
-
|
|
99
|
+
let type_16: MetricTypes;
|
|
100
|
+
export { type_16 as type };
|
|
85
101
|
}
|
|
86
102
|
namespace speedIndex {
|
|
87
|
-
|
|
103
|
+
let label_17: string;
|
|
88
104
|
export { label_17 as label };
|
|
89
|
-
|
|
105
|
+
let type_17: MetricTypes;
|
|
106
|
+
export { type_17 as type };
|
|
90
107
|
}
|
|
91
108
|
namespace visualComplete85 {
|
|
92
|
-
|
|
109
|
+
let label_18: string;
|
|
93
110
|
export { label_18 as label };
|
|
94
|
-
|
|
111
|
+
let type_18: MetricTypes;
|
|
112
|
+
export { type_18 as type };
|
|
95
113
|
}
|
|
96
114
|
namespace visualComplete95 {
|
|
97
|
-
|
|
115
|
+
let label_19: string;
|
|
98
116
|
export { label_19 as label };
|
|
99
|
-
|
|
117
|
+
let type_19: MetricTypes;
|
|
118
|
+
export { type_19 as type };
|
|
100
119
|
}
|
|
101
120
|
namespace visualComplete99 {
|
|
102
|
-
|
|
121
|
+
let label_20: string;
|
|
103
122
|
export { label_20 as label };
|
|
104
|
-
|
|
123
|
+
let type_20: MetricTypes;
|
|
124
|
+
export { type_20 as type };
|
|
105
125
|
}
|
|
106
126
|
}
|
|
107
|
-
import {
|
|
127
|
+
import { MetricTypes } from '../constants';
|