@bundle-stats/utils 4.7.5-alpha.0 → 4.7.5-beta.2
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/lib/browsertime/metrics.js +22 -22
- package/lib/browsertime/metrics.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 +9 -19
- package/lib/constants.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 +2 -2
- package/lib/report/add-row-metric-data.js.map +1 -1
- package/lib/report/create.js.map +1 -1
- package/lib/utils/component-links.js +1 -7
- package/lib/utils/component-links.js.map +1 -1
- package/lib/utils/delta.js +29 -26
- package/lib/utils/delta.js.map +1 -1
- package/lib/utils/metrics.js +47 -29
- package/lib/utils/metrics.js.map +1 -1
- package/lib/webpack/compare.js +11 -11
- package/lib/webpack/compare.js.map +1 -1
- package/lib/webpack/metrics.js +25 -24
- package/lib/webpack/metrics.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/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 +8 -18
- package/lib-esm/constants.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 +2 -2
- package/lib-esm/report/add-row-metric-data.js.map +1 -1
- package/lib-esm/report/create.js.map +1 -1
- package/lib-esm/utils/component-links.js +1 -7
- package/lib-esm/utils/component-links.js.map +1 -1
- package/lib-esm/utils/delta.js +29 -26
- package/lib-esm/utils/delta.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 +4 -4
- package/lib-esm/webpack/compare.js.map +1 -1
- package/lib-esm/webpack/metrics.js +25 -24
- package/lib-esm/webpack/metrics.js.map +1 -1
- package/package.json +5 -5
- package/src/browsertime/metrics.js +22 -22
- package/src/config/index.js +1 -2
- package/src/config/metric-types.ts +25 -0
- package/src/constants.ts +64 -28
- package/src/lighthouse/metrics.js +13 -15
- package/src/report/add-row-metric-data.ts +3 -2
- package/src/report/create.ts +1 -1
- package/src/utils/component-links.ts +1 -7
- package/src/utils/delta.ts +91 -0
- package/src/utils/metrics.ts +81 -0
- package/src/webpack/compare.js +19 -12
- package/src/webpack/{metrics.js → metrics.ts} +30 -29
- package/types/browsertime/metrics.d.ts +43 -23
- package/types/config/index.d.ts +1 -2
- package/types/config/metric-types.d.ts +2 -0
- package/types/constants.d.ts +24 -22
- package/types/lighthouse/metrics.d.ts +25 -17
- package/types/report/add-row-metric-data.d.ts +4 -3
- package/types/utils/component-links.d.ts +0 -4
- package/types/utils/delta.d.ts +4 -6
- package/types/utils/metrics.d.ts +4 -3
- package/types/webpack/metrics.d.ts +7 -153
- package/types/webpack/utils.d.ts +1 -1
- 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 -31
- package/src/utils/delta.js +0 -94
- package/src/utils/metrics.js +0 -92
- package/types/config/delta.d.ts +0 -9
- package/types/config/metrics.d.ts +0 -6
package/src/config/delta.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const DELTA_TYPE_NEGATIVE = 'NEGATIVE';
|
|
2
|
-
export const DELTA_TYPE_NO_CHANGE = 'NO_CHANGE';
|
|
3
|
-
export const DELTA_TYPE_POSITIVE = 'POSITIVE';
|
|
4
|
-
|
|
5
|
-
export const DELTA_TYPE_LEVEL_LOW = 'LOW';
|
|
6
|
-
export const DELTA_TYPE_LEVEL_HIGH = 'HIGH';
|
|
7
|
-
|
|
8
|
-
export const DELTA_TYPE_LOW_NEGATIVE = `${DELTA_TYPE_LEVEL_LOW}_${DELTA_TYPE_NEGATIVE}`;
|
|
9
|
-
export const DELTA_TYPE_HIGH_NEGATIVE = `${DELTA_TYPE_LEVEL_HIGH}_${DELTA_TYPE_NEGATIVE}`;
|
|
10
|
-
export const DELTA_TYPE_LOW_POSITIVE = `${DELTA_TYPE_LEVEL_LOW}_${DELTA_TYPE_POSITIVE}`;
|
|
11
|
-
export const DELTA_TYPE_HIGH_POSITIVE = `${DELTA_TYPE_LEVEL_HIGH}_${DELTA_TYPE_POSITIVE}`;
|
package/src/config/metrics.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { formatNumber, formatDuration, formatFileSize, formatPercentage } from '../utils/format';
|
|
2
|
-
|
|
3
|
-
export const METRIC_TYPE_FILE_SIZE = 'METRIC_TYPE_FILE_SIZE';
|
|
4
|
-
export const METRIC_TYPE_DURATION = 'METRIC_TYPE_DURATION';
|
|
5
|
-
export const METRIC_TYPE_NUMERIC = 'METRIC_TYPE_NUMERIC';
|
|
6
|
-
export const METRIC_TYPE_SCORE = 'METRIC_TYPE_SCORE';
|
|
7
|
-
export const METRIC_TYPE_PERCENTAGE = 'METRIC_TYPE_PERCENTAGE';
|
|
8
|
-
|
|
9
|
-
/** @type {Record<string, import('../constants').MetricType>} */
|
|
10
|
-
export const METRIC_TYPES = {
|
|
11
|
-
[METRIC_TYPE_NUMERIC]: {
|
|
12
|
-
biggerIsBetter: false,
|
|
13
|
-
formatter: formatNumber,
|
|
14
|
-
},
|
|
15
|
-
[METRIC_TYPE_SCORE]: {
|
|
16
|
-
biggerIsBetter: true,
|
|
17
|
-
formatter: formatNumber,
|
|
18
|
-
},
|
|
19
|
-
[METRIC_TYPE_DURATION]: {
|
|
20
|
-
biggerIsBetter: false,
|
|
21
|
-
formatter: formatDuration,
|
|
22
|
-
},
|
|
23
|
-
[METRIC_TYPE_FILE_SIZE]: {
|
|
24
|
-
biggerIsBetter: false,
|
|
25
|
-
formatter: formatFileSize,
|
|
26
|
-
},
|
|
27
|
-
[METRIC_TYPE_PERCENTAGE]: {
|
|
28
|
-
biggerIsBetter: true,
|
|
29
|
-
formatter: formatPercentage,
|
|
30
|
-
},
|
|
31
|
-
};
|
package/src/utils/delta.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import round from 'lodash/round';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
DELTA_TYPE_NO_CHANGE,
|
|
5
|
-
DELTA_TYPE_NEGATIVE,
|
|
6
|
-
DELTA_TYPE_POSITIVE,
|
|
7
|
-
DELTA_TYPE_LEVEL_HIGH,
|
|
8
|
-
DELTA_TYPE_LEVEL_LOW,
|
|
9
|
-
} from '../config/delta';
|
|
10
|
-
|
|
11
|
-
export const getDelta = (baseline, current) => {
|
|
12
|
-
const baselineValue = (baseline && baseline.value) || 0;
|
|
13
|
-
const currentValue = (current && current.value) || 0;
|
|
14
|
-
|
|
15
|
-
if (baselineValue === currentValue) {
|
|
16
|
-
return {
|
|
17
|
-
delta: 0,
|
|
18
|
-
deltaPercentage: 0,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (baselineValue === 0) {
|
|
23
|
-
return {
|
|
24
|
-
delta: currentValue,
|
|
25
|
-
deltaPercentage: 100,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
delta: currentValue - baselineValue,
|
|
31
|
-
deltaPercentage: round((currentValue / baselineValue) * 100 - 100, 8),
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Format delta output
|
|
37
|
-
*
|
|
38
|
-
* @param {number} value Metric value
|
|
39
|
-
* @param {Function} formatter Metric type formatter
|
|
40
|
-
* @return {String} Delta output
|
|
41
|
-
*/
|
|
42
|
-
export const formatDelta = (value, formatter) => {
|
|
43
|
-
// eslint-disable-next-line no-nested-ternary
|
|
44
|
-
let sign = value > 0
|
|
45
|
-
? '+'
|
|
46
|
-
: (value < 0 ? '-' : '');
|
|
47
|
-
|
|
48
|
-
let absValue = Math.abs(value);
|
|
49
|
-
|
|
50
|
-
if (absValue > 0 && absValue < 0.01) {
|
|
51
|
-
sign = `~${sign}`;
|
|
52
|
-
absValue = 0.01;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (absValue > 0.01) {
|
|
56
|
-
absValue = round(absValue, 2);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return `${sign}${formatter(absValue)}`;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* Get delta type
|
|
65
|
-
*
|
|
66
|
-
* @param {number} deltaValue Delta value
|
|
67
|
-
* @param {Boolean} biggerIsBetter Metric flag
|
|
68
|
-
* @return {string} Delta type
|
|
69
|
-
*/
|
|
70
|
-
export const getDeltaType = (deltaValue, biggerIsBetter) => {
|
|
71
|
-
if (deltaValue === 0) {
|
|
72
|
-
return DELTA_TYPE_NO_CHANGE;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const absDiff = Math.abs(deltaValue);
|
|
76
|
-
let level = '';
|
|
77
|
-
|
|
78
|
-
if (absDiff <= 5) {
|
|
79
|
-
level = DELTA_TYPE_LEVEL_LOW;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (absDiff > 50) {
|
|
83
|
-
level = DELTA_TYPE_LEVEL_HIGH;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let type = '';
|
|
87
|
-
if ((deltaValue > 0 && biggerIsBetter) || (deltaValue < 0 && !biggerIsBetter)) {
|
|
88
|
-
type = DELTA_TYPE_POSITIVE;
|
|
89
|
-
} else {
|
|
90
|
-
type = DELTA_TYPE_NEGATIVE;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return `${level ? `${level}_` : ''}${type}`;
|
|
94
|
-
};
|
package/src/utils/metrics.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
|
|
3
|
-
import { METRIC_TYPE_NUMERIC, METRIC_TYPES } from '../config/metrics';
|
|
4
|
-
import { formatDelta, getDelta, getDeltaType } from './delta';
|
|
5
|
-
import { formatPercentage } from './format';
|
|
6
|
-
|
|
7
|
-
import { metrics as webpackMetricTypes } from '../webpack/metrics';
|
|
8
|
-
import { metrics as lighthouseMetricTypes } from '../lighthouse/metrics';
|
|
9
|
-
import { metrics as browsertimeMeticTypes } from '../browsertime/metrics';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create getMetricTypes handler
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} metrics
|
|
15
|
-
* @return {Function}
|
|
16
|
-
*/
|
|
17
|
-
export const createGetMetricType =
|
|
18
|
-
(metrics) =>
|
|
19
|
-
/**
|
|
20
|
-
* Get metric type data
|
|
21
|
-
*
|
|
22
|
-
* @param {String} key Metric key
|
|
23
|
-
* @param {String} [type] Default metric type
|
|
24
|
-
* @return {import('../constants').MetricType}
|
|
25
|
-
*/
|
|
26
|
-
// eslint-disable-next-line implicit-arrow-linebreak
|
|
27
|
-
(key, type) => {
|
|
28
|
-
/** @type {import('../constants').MetricTypeConfig} */
|
|
29
|
-
const metric = get(metrics, key);
|
|
30
|
-
|
|
31
|
-
if (metric && metric.type) {
|
|
32
|
-
return {
|
|
33
|
-
...METRIC_TYPES[metric.type],
|
|
34
|
-
...metric,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const resolvedType = type || METRIC_TYPE_NUMERIC;
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
...METRIC_TYPES[resolvedType],
|
|
42
|
-
type: resolvedType,
|
|
43
|
-
label: key,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get global metric type
|
|
49
|
-
*
|
|
50
|
-
* @param {String} key Metric key
|
|
51
|
-
* @param {import('../constants').MetricTypeType} [type] Default metric type
|
|
52
|
-
* @return {import('../constants').MetricType}
|
|
53
|
-
*/
|
|
54
|
-
export const getGlobalMetricType = createGetMetricType({
|
|
55
|
-
webpack: webpackMetricTypes,
|
|
56
|
-
lighthouse: lighthouseMetricTypes,
|
|
57
|
-
browsertime: browsertimeMeticTypes,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* Get metric information
|
|
63
|
-
*
|
|
64
|
-
* @param {import('../constants').MetricType} metric Metric data
|
|
65
|
-
* @param {number} currentValue Current value
|
|
66
|
-
* @param {number} baselineValue Baseline value
|
|
67
|
-
*
|
|
68
|
-
* @return {import('../constants').MetricRunInfo}
|
|
69
|
-
*/
|
|
70
|
-
export const getMetricRunInfo = (metric, currentValue, baselineValue) => {
|
|
71
|
-
const { formatter, biggerIsBetter } = metric;
|
|
72
|
-
|
|
73
|
-
const runInfo = {
|
|
74
|
-
value: currentValue,
|
|
75
|
-
displayValue: formatter(currentValue),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (typeof baselineValue === 'undefined') {
|
|
79
|
-
return runInfo;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const { delta, deltaPercentage } = getDelta({ value: baselineValue }, { value: currentValue });
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
...runInfo,
|
|
86
|
-
delta,
|
|
87
|
-
deltaPercentage,
|
|
88
|
-
displayDelta: formatDelta(delta, formatter),
|
|
89
|
-
displayDeltaPercentage: formatDelta(deltaPercentage, formatPercentage),
|
|
90
|
-
deltaType: getDeltaType(deltaPercentage, biggerIsBetter),
|
|
91
|
-
};
|
|
92
|
-
};
|
package/types/config/delta.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const DELTA_TYPE_NEGATIVE: "NEGATIVE";
|
|
2
|
-
export const DELTA_TYPE_NO_CHANGE: "NO_CHANGE";
|
|
3
|
-
export const DELTA_TYPE_POSITIVE: "POSITIVE";
|
|
4
|
-
export const DELTA_TYPE_LEVEL_LOW: "LOW";
|
|
5
|
-
export const DELTA_TYPE_LEVEL_HIGH: "HIGH";
|
|
6
|
-
export const DELTA_TYPE_LOW_NEGATIVE: string;
|
|
7
|
-
export const DELTA_TYPE_HIGH_NEGATIVE: string;
|
|
8
|
-
export const DELTA_TYPE_LOW_POSITIVE: string;
|
|
9
|
-
export const DELTA_TYPE_HIGH_POSITIVE: string;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export const METRIC_TYPE_FILE_SIZE: "METRIC_TYPE_FILE_SIZE";
|
|
2
|
-
export const METRIC_TYPE_DURATION: "METRIC_TYPE_DURATION";
|
|
3
|
-
export const METRIC_TYPE_NUMERIC: "METRIC_TYPE_NUMERIC";
|
|
4
|
-
export const METRIC_TYPE_SCORE: "METRIC_TYPE_SCORE";
|
|
5
|
-
export const METRIC_TYPE_PERCENTAGE: "METRIC_TYPE_PERCENTAGE";
|
|
6
|
-
export const METRIC_TYPES: Record<string, import('../constants').MetricType>;
|