@bundle-stats/utils 4.2.2 → 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.
Files changed (188) hide show
  1. package/README.md +15 -10
  2. package/lib/browsertime/metrics.js +22 -22
  3. package/lib/browsertime/metrics.js.map +1 -1
  4. package/lib/config/component-links.js +7 -1
  5. package/lib/config/component-links.js.map +1 -1
  6. package/lib/config/file-types.js +3 -3
  7. package/lib/config/file-types.js.map +1 -1
  8. package/lib/config/index.js +1 -2
  9. package/lib/config/index.js.map +1 -1
  10. package/lib/config/metric-types.js +28 -0
  11. package/lib/config/metric-types.js.map +1 -0
  12. package/lib/constants.js +23 -22
  13. package/lib/constants.js.map +1 -1
  14. package/lib/i18n.js +15 -10
  15. package/lib/i18n.js.map +1 -1
  16. package/lib/jobs/create-job.js +17 -7
  17. package/lib/jobs/create-job.js.map +1 -1
  18. package/lib/jobs/create-jobs.js.map +1 -1
  19. package/lib/lighthouse/metrics.js +13 -13
  20. package/lib/lighthouse/metrics.js.map +1 -1
  21. package/lib/report/add-row-metric-data.js +4 -4
  22. package/lib/report/add-row-metric-data.js.map +1 -1
  23. package/lib/report/compare-metrics.js +4 -1
  24. package/lib/report/compare-metrics.js.map +1 -1
  25. package/lib/report/create.js +17 -7
  26. package/lib/report/create.js.map +1 -1
  27. package/lib/report/get-metric-changed.js.map +1 -1
  28. package/lib/report/index.js +1 -0
  29. package/lib/report/index.js.map +1 -1
  30. package/lib/report/merge-metrics-by-key.js +1 -1
  31. package/lib/report/merge-metrics-by-key.js.map +1 -1
  32. package/lib/utils/component-links.js +191 -27
  33. package/lib/utils/component-links.js.map +1 -1
  34. package/lib/utils/date.js.map +1 -1
  35. package/lib/utils/delta.js +35 -30
  36. package/lib/utils/delta.js.map +1 -1
  37. package/lib/utils/format.js +5 -6
  38. package/lib/utils/format.js.map +1 -1
  39. package/lib/utils/insights.js.map +1 -1
  40. package/lib/utils/metrics.js +49 -32
  41. package/lib/utils/metrics.js.map +1 -1
  42. package/lib/webpack/compare.js +16 -12
  43. package/lib/webpack/compare.js.map +1 -1
  44. package/lib/webpack/extract/assets.js +7 -1
  45. package/lib/webpack/extract/assets.js.map +1 -1
  46. package/lib/webpack/extract/meta.js.map +1 -1
  47. package/lib/webpack/extract/modules-packages-duplicate.js +13 -8
  48. package/lib/webpack/extract/modules-packages-duplicate.js.map +1 -1
  49. package/lib/webpack/extract/modules-packages-new-insight.js.map +1 -1
  50. package/lib/webpack/extract/modules-packages.js +8 -1
  51. package/lib/webpack/extract/modules-packages.js.map +1 -1
  52. package/lib/webpack/extract/modules.js +45 -20
  53. package/lib/webpack/extract/modules.js.map +1 -1
  54. package/lib/webpack/metrics.js +35 -34
  55. package/lib/webpack/metrics.js.map +1 -1
  56. package/lib/webpack/selectors.js +40 -3
  57. package/lib/webpack/selectors.js.map +1 -1
  58. package/lib/webpack/types.js +1 -1
  59. package/lib/webpack/types.js.map +1 -1
  60. package/lib/webpack/utils.js +37 -25
  61. package/lib/webpack/utils.js.map +1 -1
  62. package/lib-esm/browsertime/metrics.js +22 -22
  63. package/lib-esm/browsertime/metrics.js.map +1 -1
  64. package/lib-esm/config/component-links.js +6 -0
  65. package/lib-esm/config/component-links.js.map +1 -1
  66. package/lib-esm/config/file-types.js +3 -3
  67. package/lib-esm/config/file-types.js.map +1 -1
  68. package/lib-esm/config/index.js +1 -2
  69. package/lib-esm/config/index.js.map +1 -1
  70. package/lib-esm/config/metric-types.js +25 -0
  71. package/lib-esm/config/metric-types.js.map +1 -0
  72. package/lib-esm/constants.js +19 -18
  73. package/lib-esm/constants.js.map +1 -1
  74. package/lib-esm/i18n.js +15 -10
  75. package/lib-esm/i18n.js.map +1 -1
  76. package/lib-esm/jobs/create-job.js.map +1 -1
  77. package/lib-esm/jobs/create-jobs.js.map +1 -1
  78. package/lib-esm/lighthouse/metrics.js +13 -13
  79. package/lib-esm/lighthouse/metrics.js.map +1 -1
  80. package/lib-esm/report/add-row-metric-data.js +4 -4
  81. package/lib-esm/report/add-row-metric-data.js.map +1 -1
  82. package/lib-esm/report/compare-metrics.js +4 -1
  83. package/lib-esm/report/compare-metrics.js.map +1 -1
  84. package/lib-esm/report/create.js.map +1 -1
  85. package/lib-esm/report/get-metric-changed.js.map +1 -1
  86. package/lib-esm/report/index.js +1 -0
  87. package/lib-esm/report/index.js.map +1 -1
  88. package/lib-esm/report/merge-metrics-by-key.js +1 -1
  89. package/lib-esm/report/merge-metrics-by-key.js.map +1 -1
  90. package/lib-esm/utils/component-links.js +185 -27
  91. package/lib-esm/utils/component-links.js.map +1 -1
  92. package/lib-esm/utils/date.js.map +1 -1
  93. package/lib-esm/utils/delta.js +32 -26
  94. package/lib-esm/utils/delta.js.map +1 -1
  95. package/lib-esm/utils/format.js.map +1 -1
  96. package/lib-esm/utils/insights.js.map +1 -1
  97. package/lib-esm/utils/metrics.js +44 -27
  98. package/lib-esm/utils/metrics.js.map +1 -1
  99. package/lib-esm/webpack/compare.js +7 -5
  100. package/lib-esm/webpack/compare.js.map +1 -1
  101. package/lib-esm/webpack/extract/assets.js +7 -1
  102. package/lib-esm/webpack/extract/assets.js.map +1 -1
  103. package/lib-esm/webpack/extract/meta.js.map +1 -1
  104. package/lib-esm/webpack/extract/modules-packages-duplicate.js +13 -8
  105. package/lib-esm/webpack/extract/modules-packages-duplicate.js.map +1 -1
  106. package/lib-esm/webpack/extract/modules-packages-new-insight.js.map +1 -1
  107. package/lib-esm/webpack/extract/modules-packages.js +8 -1
  108. package/lib-esm/webpack/extract/modules-packages.js.map +1 -1
  109. package/lib-esm/webpack/extract/modules.js +45 -20
  110. package/lib-esm/webpack/extract/modules.js.map +1 -1
  111. package/lib-esm/webpack/metrics.js +35 -34
  112. package/lib-esm/webpack/metrics.js.map +1 -1
  113. package/lib-esm/webpack/selectors.js +35 -1
  114. package/lib-esm/webpack/selectors.js.map +1 -1
  115. package/lib-esm/webpack/utils.js +37 -25
  116. package/lib-esm/webpack/utils.js.map +1 -1
  117. package/package.json +20 -22
  118. package/src/browsertime/metrics.js +22 -22
  119. package/src/config/component-links.js +7 -0
  120. package/src/config/file-types.js +3 -3
  121. package/src/config/index.js +1 -2
  122. package/src/config/metric-types.ts +25 -0
  123. package/src/constants.ts +94 -34
  124. package/src/i18n.js +15 -10
  125. package/src/lighthouse/metrics.js +13 -15
  126. package/src/report/add-row-metric-data.ts +42 -38
  127. package/src/report/compare-metrics.ts +7 -4
  128. package/src/report/create.ts +1 -1
  129. package/src/report/index.js +1 -0
  130. package/src/report/merge-metrics-by-key.ts +7 -5
  131. package/src/report/types.ts +17 -0
  132. package/src/utils/component-links.ts +276 -35
  133. package/src/utils/delta.ts +98 -0
  134. package/src/utils/metrics.ts +88 -0
  135. package/src/webpack/compare.ts +62 -0
  136. package/src/webpack/extract/assets.ts +13 -7
  137. package/src/webpack/extract/modules-packages-duplicate.ts +23 -15
  138. package/src/webpack/extract/modules-packages.ts +74 -61
  139. package/src/webpack/extract/modules.ts +66 -33
  140. package/src/webpack/{metrics.js → metrics.ts} +41 -39
  141. package/src/webpack/selectors.js +82 -9
  142. package/src/webpack/types.ts +13 -4
  143. package/src/webpack/utils.ts +173 -0
  144. package/types/browsertime/compare.d.ts +1 -1
  145. package/types/browsertime/metrics.d.ts +63 -43
  146. package/types/config/component-links.d.ts +26 -18
  147. package/types/config/file-types.d.ts +17 -17
  148. package/types/config/index.d.ts +1 -2
  149. package/types/config/metric-types.d.ts +2 -0
  150. package/types/constants.d.ts +52 -29
  151. package/types/i18n.d.ts +19 -14
  152. package/types/lighthouse/compare.d.ts +1 -1
  153. package/types/lighthouse/filter.d.ts +1 -1
  154. package/types/lighthouse/metrics.d.ts +36 -28
  155. package/types/report/add-row-metric-data.d.ts +1 -16
  156. package/types/report/compare-metrics.d.ts +1 -1
  157. package/types/report/index.d.ts +1 -0
  158. package/types/report/merge-metrics-by-key.d.ts +1 -1
  159. package/types/report/types.d.ts +12 -0
  160. package/types/utils/component-links.d.ts +24 -8
  161. package/types/utils/delta.d.ts +4 -6
  162. package/types/utils/metrics.d.ts +4 -3
  163. package/types/webpack/compare.d.ts +11 -14
  164. package/types/webpack/constants.d.ts +1 -1
  165. package/types/webpack/extract/assets-size-total-insight.d.ts +2 -2
  166. package/types/webpack/extract/modules-packages-duplicate.d.ts +3 -3
  167. package/types/webpack/extract/modules.d.ts +1 -1
  168. package/types/webpack/metrics.d.ts +7 -153
  169. package/types/webpack/selectors.d.ts +21 -7
  170. package/types/webpack/types.d.ts +4 -4
  171. package/types/webpack/utils.d.ts +8 -8
  172. package/CHANGELOG.md +0 -333
  173. package/lib/config/delta.js +0 -13
  174. package/lib/config/delta.js.map +0 -1
  175. package/lib/config/metrics.js +0 -32
  176. package/lib/config/metrics.js.map +0 -1
  177. package/lib-esm/config/delta.js +0 -10
  178. package/lib-esm/config/delta.js.map +0 -1
  179. package/lib-esm/config/metrics.js +0 -29
  180. package/lib-esm/config/metrics.js.map +0 -1
  181. package/src/config/delta.js +0 -11
  182. package/src/config/metrics.js +0 -35
  183. package/src/utils/delta.js +0 -94
  184. package/src/utils/metrics.js +0 -92
  185. package/src/webpack/compare.js +0 -81
  186. package/src/webpack/utils.js +0 -155
  187. package/types/config/delta.d.ts +0 -9
  188. package/types/config/metrics.d.ts +0 -35
@@ -1 +0,0 @@
1
- {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/config/metrics.js"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAC3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,mBAAmB,CAAC,EAAE;QACrB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,YAAY;KACxB;IACD,CAAC,iBAAiB,CAAC,EAAE;QACnB,cAAc,EAAE,IAAI;QACpB,SAAS,EAAE,YAAY;KACxB;IACD,CAAC,oBAAoB,CAAC,EAAE;QACtB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,cAAc;KAC1B;IACD,CAAC,qBAAqB,CAAC,EAAE;QACvB,cAAc,EAAE,KAAK;QACrB,SAAS,EAAE,cAAc;KAC1B;IACD,CAAC,sBAAsB,CAAC,EAAE;QACxB,cAAc,EAAE,IAAI;QACpB,SAAS,EAAE,gBAAgB;KAC5B;CACF,CAAC"}
@@ -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}`;
@@ -1,35 +0,0 @@
1
- import {
2
- formatNumber,
3
- formatDuration,
4
- formatFileSize,
5
- formatPercentage,
6
- } from '../utils/format';
7
-
8
- export const METRIC_TYPE_FILE_SIZE = 'METRIC_TYPE_FILE_SIZE';
9
- export const METRIC_TYPE_DURATION = 'METRIC_TYPE_DURATION';
10
- export const METRIC_TYPE_NUMERIC = 'METRIC_TYPE_NUMERIC';
11
- export const METRIC_TYPE_SCORE = 'METRIC_TYPE_SCORE';
12
- export const METRIC_TYPE_PERCENTAGE = 'METRIC_TYPE_PERCENTAGE';
13
-
14
- export const METRIC_TYPES = {
15
- [METRIC_TYPE_NUMERIC]: {
16
- biggerIsBetter: false,
17
- formatter: formatNumber,
18
- },
19
- [METRIC_TYPE_SCORE]: {
20
- biggerIsBetter: true,
21
- formatter: formatNumber,
22
- },
23
- [METRIC_TYPE_DURATION]: {
24
- biggerIsBetter: false,
25
- formatter: formatDuration,
26
- },
27
- [METRIC_TYPE_FILE_SIZE]: {
28
- biggerIsBetter: false,
29
- formatter: formatFileSize,
30
- },
31
- [METRIC_TYPE_PERCENTAGE]: {
32
- biggerIsBetter: true,
33
- formatter: formatPercentage,
34
- },
35
- };
@@ -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
- };
@@ -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
- };
@@ -1,81 +0,0 @@
1
- import { METRIC_TYPE_FILE_SIZE } from '../config/metrics';
2
- import { compareMetrics } from '../report/compare-metrics';
3
- import {
4
- SECTION_WEBPACK_STATS,
5
- SECTION_WEBPACK_SIZES,
6
- SECTION_WEBPACK_ASSETS,
7
- SECTION_WEBPACK_MODULES,
8
- SECTION_WEBPACK_PACKAGES,
9
- SECTIONS,
10
- } from './constants';
11
- import { selectors } from './selectors';
12
-
13
- /**
14
- * Compare stats metrics
15
- *
16
- * @param {Object[]} jobs - List of jobs to compare
17
- * @param {Array<Function>} [rowTransformers]
18
- *
19
- * @return {Object[]} Compared stats metrics
20
- */
21
- const compareStats = (jobs, rowTransformers) => compareMetrics(
22
- jobs, selectors.stats, undefined, rowTransformers,
23
- );
24
-
25
- /**
26
- * Compare size metrics
27
- *
28
- * @param {Object[]} jobs - List of jobs to compare
29
- * @param {Array<Function>} [rowTransformers]
30
- *
31
- * @return {Object[]} Compared size metrics
32
- */
33
- const compareSizes = (jobs, rowTransformers) => compareMetrics(jobs, selectors.sizes, undefined, rowTransformers);
34
-
35
- /**
36
- * Compare asset metrics
37
- *
38
- * @param {Object[]} jobs - List of jobs to compare
39
- * @param {Array<Function>} [rowTransformers]
40
- *
41
- * @return {Object[]} Compared asset metrics
42
- */
43
- const compareAssets = (jobs, rowTransformers) => compareMetrics(jobs, selectors.assets, METRIC_TYPE_FILE_SIZE, rowTransformers);
44
-
45
- /**
46
- * Compare all modules
47
- *
48
- * @param {Object[]} jobs - List of jobs to compare
49
- * @param {Array<Function>} [rowTransformers]
50
- * @return {Object[]} Compared module metrics
51
- */
52
- const compareModules = (jobs, rowTransformers) => compareMetrics(jobs, selectors.modules, METRIC_TYPE_FILE_SIZE, rowTransformers);
53
-
54
- /**
55
- * Compare package metrics
56
- *
57
- * @param {Object[]} jobs - List of jobs to compare
58
- * @param {Array<Function>} [rowTransformers]
59
- *
60
- * @return {Object[]} Compared package metrics
61
- */
62
- const comparePackages = (jobs, rowTransformers) => compareMetrics(jobs, selectors.packages, METRIC_TYPE_FILE_SIZE, rowTransformers);
63
-
64
- export const compareBySection = {
65
- [SECTION_WEBPACK_STATS]: compareStats,
66
- [SECTION_WEBPACK_SIZES]: compareSizes,
67
- [SECTION_WEBPACK_ASSETS]: compareAssets,
68
- [SECTION_WEBPACK_MODULES]: compareModules,
69
- [SECTION_WEBPACK_PACKAGES]: comparePackages,
70
- };
71
-
72
- /**
73
- * Compare webpack sections
74
- *
75
- * @param {Object[]} jobs - List of jobs to compare
76
- * @return {Object} Compared metrics by section
77
- */
78
- export const compare = (jobs) => SECTIONS.reduce((agg, sectionId) => ({
79
- ...agg,
80
- [sectionId]: compareBySection[sectionId](jobs),
81
- }), {});
@@ -1,155 +0,0 @@
1
- import last from 'lodash/last';
2
- import map from 'lodash/map';
3
- import round from 'lodash/round';
4
-
5
- import { PACKAGES_SEPARATOR, PACKAGE_ID_SEPARATOR } from '../config';
6
- import { createGetMetricType } from '../utils/metrics';
7
- import { metrics } from './metrics';
8
-
9
- // Md5 hash matcher
10
- const HASH_PATTERN = '[a-f|0-9]{5,32}';
11
-
12
- // Match has prefix
13
- const HASH_SEPARATOR_PATTERN = '[-|.]';
14
-
15
- // Match multiple extensions: .js, .js.gz, .min.js, .chunk.js
16
- const EXTENSION_PATTERN = /(?:\.[a-z|0-9]{2,}){1,}/;
17
-
18
- const PATTERNS = [
19
- // Match path/name-HASH.ext, path/name.HASH.ext, path/name-HASH.chunk.ext
20
- `(.*)${HASH_SEPARATOR_PATTERN}${HASH_PATTERN}(${EXTENSION_PATTERN.source})$`,
21
-
22
- // Match static/HASH
23
- `(static)/${HASH_PATTERN}(.*${EXTENSION_PATTERN.source})$`,
24
- ].map((pattern) => new RegExp(pattern));
25
-
26
- const NO_BASENAME = /(^|.*\/)\..*$/;
27
-
28
- /**
29
- * Extract (guess) filename from a hashed filename
30
- */
31
- export const getAssetName = (assetFilepath) => {
32
- if (!assetFilepath) {
33
- return '';
34
- }
35
-
36
- let result;
37
-
38
- for (let i = 0; i < PATTERNS.length && !result; i += 1) {
39
- const pattern = PATTERNS[i];
40
- const extracted = assetFilepath.replace(pattern, '$1$2');
41
-
42
- if (extracted && extracted !== assetFilepath && !NO_BASENAME.test(extracted)) {
43
- result = extracted;
44
- }
45
- }
46
-
47
- if (!result) {
48
- return assetFilepath;
49
- }
50
-
51
- return result;
52
- };
53
-
54
- // css ./node_modules/css-loader/dist/cjs.js??ref--6-0!./src/assets/styles/default.styl
55
- const NAME_WITH_LOADERS = /!/;
56
-
57
- // ./src/index.jsx + 27 modules
58
- const NAME_WITH_MODULES = /\s\+\s\d*\smodules$/;
59
-
60
- // css ../node_modules../node_modules/package-a
61
- const INVALID_CSS_PREFIX = /^css\s.*node_modules(?!\/)/;
62
-
63
- export const getModuleName = (name) => {
64
- if (!name) {
65
- return '';
66
- }
67
-
68
- if (NAME_WITH_LOADERS.test(name)) {
69
- const normalizedName = last(name.split(NAME_WITH_LOADERS));
70
-
71
- if (normalizedName?.trim()) {
72
- return normalizedName;
73
- }
74
- }
75
-
76
- if (NAME_WITH_MODULES.test(name)) {
77
- return name.replace(NAME_WITH_MODULES, '');
78
- }
79
-
80
- if (INVALID_CSS_PREFIX.test(name)) {
81
- return name.replace(INVALID_CSS_PREFIX, '');
82
- }
83
-
84
- return name;
85
- };
86
-
87
- /*
88
- * Calculate cache invalidation metric on the baseline data
89
- *
90
- * The metric is the ratio between the total file size of the files that have changed (exclude
91
- * deleted, added) and the total file size
92
- */
93
- export const calculateCacheInvalidation = (rows) => {
94
- let cached = 0;
95
- let invalidated = 0;
96
-
97
- rows.forEach(({ changed, added, deleted, runs }) => {
98
- // Added and deleted files do not count towards the caching index
99
- if (added || deleted) {
100
- return;
101
- }
102
-
103
- if (changed) {
104
- invalidated += runs[1].value;
105
- }
106
-
107
- cached += runs[1].value;
108
- });
109
-
110
- if (cached === 0) {
111
- return 0;
112
- }
113
-
114
- return round((invalidated / cached) * 100, 2);
115
- };
116
-
117
- export const getMetricAdded = (runs) => {
118
- const [current, baseline] = map(runs, 'value');
119
-
120
- return Boolean(current !== null && !baseline);
121
- };
122
-
123
- export const getMetricDeleted = (runs) => {
124
- const [current, baseline] = map(runs, 'value');
125
-
126
- return Boolean(baseline !== null && !current);
127
- };
128
-
129
- /**
130
- * Get webpack metric data
131
- *
132
- * @param {String} key - Webpack metric key
133
- * @return {Object} Metric data
134
- */
135
- export const getMetricType = createGetMetricType(metrics);
136
-
137
- /**
138
- * Get public package name from package id
139
- *
140
- * @param {String} packageId
141
- * @return {String} public package name
142
- */
143
- export const getPackagePublicName = (packageId) => {
144
- // Split packages
145
- const name = last(packageId.split(PACKAGES_SEPARATOR));
146
-
147
- // Strip package suffix (eg: ~1)
148
- return name.split(PACKAGE_ID_SEPARATOR)[0];
149
- };
150
-
151
- /**
152
- * @param {String|Number} chunkId
153
- * @return {String}
154
- */
155
- export const normalizeChunkId = (chunkId) => chunkId.toString();
@@ -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,35 +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 namespace METRIC_TYPES {
7
- namespace METRIC_TYPE_NUMERIC {
8
- export const biggerIsBetter: boolean;
9
- export { formatNumber as formatter };
10
- }
11
- namespace METRIC_TYPE_SCORE {
12
- const biggerIsBetter_1: boolean;
13
- export { biggerIsBetter_1 as biggerIsBetter };
14
- export { formatNumber as formatter };
15
- }
16
- namespace METRIC_TYPE_DURATION {
17
- const biggerIsBetter_2: boolean;
18
- export { biggerIsBetter_2 as biggerIsBetter };
19
- export { formatDuration as formatter };
20
- }
21
- namespace METRIC_TYPE_FILE_SIZE {
22
- const biggerIsBetter_3: boolean;
23
- export { biggerIsBetter_3 as biggerIsBetter };
24
- export { formatFileSize as formatter };
25
- }
26
- namespace METRIC_TYPE_PERCENTAGE {
27
- const biggerIsBetter_4: boolean;
28
- export { biggerIsBetter_4 as biggerIsBetter };
29
- export { formatPercentage as formatter };
30
- }
31
- }
32
- import { formatNumber } from "../utils/format";
33
- import { formatDuration } from "../utils/format";
34
- import { formatFileSize } from "../utils/format";
35
- import { formatPercentage } from "../utils/format";