@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,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
- export const metrics = {
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: 'The total size of the assets produced by webpack',
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: METRIC_TYPE_FILE_SIZE,
14
+ type: MetricTypes.FileSize,
15
15
  },
16
16
  [Metric.INITIAL_SIZE_JS]: {
17
17
  label: 'Initial JS',
18
- description: 'The total size of JavaScript initial chunks',
18
+ description: 'Total file size of the JavaScript initial chunks',
19
19
  url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
20
- type: METRIC_TYPE_FILE_SIZE,
20
+ type: MetricTypes.FileSize,
21
21
  },
22
22
  [Metric.INITIAL_SIZE_CSS]: {
23
23
  label: 'Initial CSS',
24
- description: 'The total size of CSS initial chunks',
24
+ description: 'Total file size of the CSS initial chunks',
25
25
  url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
26
- type: METRIC_TYPE_FILE_SIZE,
26
+ type: MetricTypes.FileSize,
27
27
  },
28
28
  [Metric.CACHE_INVALIDATION]: {
29
29
  label: 'Cache Invalidation',
30
- description: 'The ratio between the total changed assets and total assets size(Bundle Size)',
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: METRIC_TYPE_PERCENTAGE,
33
- biggerIsBetter: false,
33
+ type: MetricTypes.Percentage,
34
+ biggerIsBetter: null,
35
+ skipDelta: true,
34
36
  },
35
37
  [Metric.CHUNK_COUNT]: {
36
38
  label: 'Chunks',
37
- description: 'The total number of chunks',
39
+ description: 'Total number of chunks generated by the bundler',
38
40
  url: 'https://relative-ci.com/documentation/metrics-and-data#assets',
39
- type: METRIC_TYPE_NUMERIC,
40
- biggerIsBetter: false,
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: METRIC_TYPE_NUMERIC,
47
- biggerIsBetter: false,
48
+ type: MetricTypes.Numeric,
49
+ biggerIsBetter: null,
48
50
  },
49
51
  [Metric.MODULE_COUNT]: {
50
52
  label: 'Modules',
51
- description: 'The total number of modules bundled by webpack',
53
+ description: 'Total number of bundled modules',
52
54
  url: 'https://relative-ci.com/documentation/metrics-and-data#modules-1',
53
- type: METRIC_TYPE_NUMERIC,
54
- biggerIsBetter: false,
55
+ type: MetricTypes.Numeric,
56
+ biggerIsBetter: null,
55
57
  },
56
58
  [Metric.DUPLICATE_MODULES_COUNT]: {
57
59
  label: 'Duplicate Modules',
58
- description: 'The total number of modules that belong to more than one chunk',
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: METRIC_TYPE_NUMERIC,
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: METRIC_TYPE_PERCENTAGE,
68
- biggerIsBetter: false,
69
+ type: MetricTypes.Percentage,
70
+ biggerIsBetter: null,
69
71
  },
70
72
  [Metric.PACKAGE_COUNT]: {
71
73
  label: 'Packages',
72
- description: 'The total number of packages bundled by webpack',
74
+ description: 'The total number of bundled packages',
73
75
  url: 'https://relative-ci.com/documentation/metrics-and-data#packages',
74
- type: METRIC_TYPE_NUMERIC,
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: METRIC_TYPE_NUMERIC,
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: METRIC_TYPE_FILE_SIZE,
89
+ type: MetricTypes.FileSize,
88
90
  },
89
91
  [Metric.TOTAL_SIZE_CSS]: {
90
92
  label: FILE_TYPE_LABELS.CSS,
91
- type: METRIC_TYPE_FILE_SIZE,
93
+ type: MetricTypes.FileSize,
92
94
  },
93
95
  [Metric.TOTAL_SIZE_IMG]: {
94
96
  label: FILE_TYPE_LABELS.IMG,
95
- type: METRIC_TYPE_FILE_SIZE,
97
+ type: MetricTypes.FileSize,
96
98
  },
97
99
  [Metric.TOTAL_SIZE_MEDIA]: {
98
100
  label: FILE_TYPE_LABELS.MEDIA,
99
- type: METRIC_TYPE_FILE_SIZE,
101
+ type: MetricTypes.FileSize,
100
102
  },
101
103
  [Metric.TOTAL_SIZE_FONT]: {
102
104
  label: FILE_TYPE_LABELS.FONT,
103
- type: METRIC_TYPE_FILE_SIZE,
105
+ type: MetricTypes.FileSize,
104
106
  },
105
107
  [Metric.TOTAL_SIZE_HTML]: {
106
108
  label: FILE_TYPE_LABELS.HTML,
107
- type: METRIC_TYPE_FILE_SIZE,
109
+ type: MetricTypes.FileSize,
108
110
  },
109
111
  [Metric.TOTAL_SIZE_OTHER]: {
110
112
  label: FILE_TYPE_LABELS.OTHER,
111
- type: METRIC_TYPE_FILE_SIZE,
113
+ type: MetricTypes.FileSize,
112
114
  },
113
115
  },
114
116
  };
@@ -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((agg, [key, value]) => ({
30
- ...agg,
31
- [`webpack.${key}`]: value,
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((agg, key) => ({
51
- ...agg,
52
- [`webpack.sizes.${key}`]: metrics[key],
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) => get(job, 'metrics.webpack.modules', {});
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
  *
@@ -29,7 +29,7 @@ export interface MetaChunk {
29
29
  name: string;
30
30
  }
31
31
 
32
- export interface Asset extends MetricRun {
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, Asset>;
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
- chunkIds: Array<String>;
54
- duplicated: boolean;
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("../report/types").ReportRow[];
1
+ export function compare(jobs: any): import("..").ReportMetricRow[];
@@ -1,107 +1,127 @@
1
1
  export namespace metrics {
2
2
  namespace firstPaint {
3
- export const label: string;
4
- export { METRIC_TYPE_DURATION as type };
3
+ let label: string;
4
+ let type: MetricTypes;
5
5
  }
6
6
  namespace fullyLoaded {
7
- const label_1: string;
7
+ let label_1: string;
8
8
  export { label_1 as label };
9
- export { METRIC_TYPE_DURATION as type };
9
+ let type_1: MetricTypes;
10
+ export { type_1 as type };
10
11
  }
11
12
  namespace backEndTime {
12
- const label_2: string;
13
+ let label_2: string;
13
14
  export { label_2 as label };
14
- export { METRIC_TYPE_DURATION as type };
15
+ let type_2: MetricTypes;
16
+ export { type_2 as type };
15
17
  }
16
18
  namespace domContentLoadedTime {
17
- const label_3: string;
19
+ let label_3: string;
18
20
  export { label_3 as label };
19
- export { METRIC_TYPE_DURATION as type };
21
+ let type_3: MetricTypes;
22
+ export { type_3 as type };
20
23
  }
21
24
  namespace domInteractiveTime {
22
- const label_4: string;
25
+ let label_4: string;
23
26
  export { label_4 as label };
24
- export { METRIC_TYPE_DURATION as type };
27
+ let type_4: MetricTypes;
28
+ export { type_4 as type };
25
29
  }
26
30
  namespace domainLookupTime {
27
- const label_5: string;
31
+ let label_5: string;
28
32
  export { label_5 as label };
29
- export { METRIC_TYPE_DURATION as type };
33
+ let type_5: MetricTypes;
34
+ export { type_5 as type };
30
35
  }
31
36
  namespace frontEndTime {
32
- const label_6: string;
37
+ let label_6: string;
33
38
  export { label_6 as label };
34
- export { METRIC_TYPE_DURATION as type };
39
+ let type_6: MetricTypes;
40
+ export { type_6 as type };
35
41
  }
36
42
  namespace pageDownloadTime {
37
- const label_7: string;
43
+ let label_7: string;
38
44
  export { label_7 as label };
39
- export { METRIC_TYPE_DURATION as type };
45
+ let type_7: MetricTypes;
46
+ export { type_7 as type };
40
47
  }
41
48
  namespace pageLoadTime {
42
- const label_8: string;
49
+ let label_8: string;
43
50
  export { label_8 as label };
44
- export { METRIC_TYPE_DURATION as type };
51
+ let type_8: MetricTypes;
52
+ export { type_8 as type };
45
53
  }
46
54
  namespace redirectionTime {
47
- const label_9: string;
55
+ let label_9: string;
48
56
  export { label_9 as label };
49
- export { METRIC_TYPE_DURATION as type };
57
+ let type_9: MetricTypes;
58
+ export { type_9 as type };
50
59
  }
51
60
  namespace serverConnectionTime {
52
- const label_10: string;
61
+ let label_10: string;
53
62
  export { label_10 as label };
54
- export { METRIC_TYPE_DURATION as type };
63
+ let type_10: MetricTypes;
64
+ export { type_10 as type };
55
65
  }
56
66
  namespace serverResponseTime {
57
- const label_11: string;
67
+ let label_11: string;
58
68
  export { label_11 as label };
59
- export { METRIC_TYPE_DURATION as type };
69
+ let type_11: MetricTypes;
70
+ export { type_11 as type };
60
71
  }
61
72
  namespace firstContentfulPaint {
62
- const label_12: string;
73
+ let label_12: string;
63
74
  export { label_12 as label };
64
- export { METRIC_TYPE_DURATION as type };
75
+ let type_12: MetricTypes;
76
+ export { type_12 as type };
65
77
  }
66
78
  namespace rumSpeedIndex {
67
- const label_13: string;
79
+ let label_13: string;
68
80
  export { label_13 as label };
69
- export { METRIC_TYPE_DURATION as type };
81
+ let type_13: MetricTypes;
82
+ export { type_13 as type };
70
83
  }
71
84
  namespace firstVisualChange {
72
- const label_14: string;
85
+ let label_14: string;
73
86
  export { label_14 as label };
74
- export { METRIC_TYPE_DURATION as type };
87
+ let type_14: MetricTypes;
88
+ export { type_14 as type };
75
89
  }
76
90
  namespace lastVisualChange {
77
- const label_15: string;
91
+ let label_15: string;
78
92
  export { label_15 as label };
79
- export { METRIC_TYPE_DURATION as type };
93
+ let type_15: MetricTypes;
94
+ export { type_15 as type };
80
95
  }
81
96
  namespace perceptualSpeedIndex {
82
- const label_16: string;
97
+ let label_16: string;
83
98
  export { label_16 as label };
84
- export { METRIC_TYPE_DURATION as type };
99
+ let type_16: MetricTypes;
100
+ export { type_16 as type };
85
101
  }
86
102
  namespace speedIndex {
87
- const label_17: string;
103
+ let label_17: string;
88
104
  export { label_17 as label };
89
- export { METRIC_TYPE_DURATION as type };
105
+ let type_17: MetricTypes;
106
+ export { type_17 as type };
90
107
  }
91
108
  namespace visualComplete85 {
92
- const label_18: string;
109
+ let label_18: string;
93
110
  export { label_18 as label };
94
- export { METRIC_TYPE_DURATION as type };
111
+ let type_18: MetricTypes;
112
+ export { type_18 as type };
95
113
  }
96
114
  namespace visualComplete95 {
97
- const label_19: string;
115
+ let label_19: string;
98
116
  export { label_19 as label };
99
- export { METRIC_TYPE_DURATION as type };
117
+ let type_19: MetricTypes;
118
+ export { type_19 as type };
100
119
  }
101
120
  namespace visualComplete99 {
102
- const label_20: string;
121
+ let label_20: string;
103
122
  export { label_20 as label };
104
- export { METRIC_TYPE_DURATION as type };
123
+ let type_20: MetricTypes;
124
+ export { type_20 as type };
105
125
  }
106
126
  }
107
- import { METRIC_TYPE_DURATION } from "../config/metrics";
127
+ import { MetricTypes } from '../constants';