@bundle-stats/utils 3.3.0-alpha.1 → 3.3.1-beta.12

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 (125) hide show
  1. package/CHANGELOG.md +29 -12
  2. package/lib/browsertime/index.js +5 -1
  3. package/lib/browsertime/index.js.map +1 -1
  4. package/lib/config/component-links.js +1 -0
  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 +5 -1
  9. package/lib/config/index.js.map +1 -1
  10. package/lib/constants.js +1 -8
  11. package/lib/constants.js.map +1 -1
  12. package/lib/i18n.js +2 -1
  13. package/lib/i18n.js.map +1 -1
  14. package/lib/index.js +5 -16
  15. package/lib/index.js.map +1 -1
  16. package/lib/jobs/create-job.js +7 -3
  17. package/lib/jobs/create-job.js.map +1 -1
  18. package/lib/jobs/create-jobs.js +2 -2
  19. package/lib/jobs/create-jobs.js.map +1 -1
  20. package/lib/jobs/index.js +5 -1
  21. package/lib/jobs/index.js.map +1 -1
  22. package/lib/lighthouse/index.js +5 -1
  23. package/lib/lighthouse/index.js.map +1 -1
  24. package/lib/report/create.js +5 -1
  25. package/lib/report/create.js.map +1 -1
  26. package/lib/report/index.js +5 -1
  27. package/lib/report/index.js.map +1 -1
  28. package/lib/utils/component-links.js +15 -1
  29. package/lib/utils/component-links.js.map +1 -1
  30. package/lib/utils/format.js +5 -1
  31. package/lib/utils/format.js.map +1 -1
  32. package/lib/utils/index.js +5 -1
  33. package/lib/utils/index.js.map +1 -1
  34. package/lib/webpack/constants.js +14 -26
  35. package/lib/webpack/constants.js.map +1 -1
  36. package/lib/webpack/extract/assets-size-total-insight.js +4 -4
  37. package/lib/webpack/extract/assets-size-total-insight.js.map +1 -1
  38. package/lib/webpack/extract/assets-size.js +4 -3
  39. package/lib/webpack/extract/assets-size.js.map +1 -1
  40. package/lib/webpack/extract/index.js +1 -22
  41. package/lib/webpack/extract/index.js.map +1 -1
  42. package/lib/webpack/extract/modules-packages-duplicate.js +2 -2
  43. package/lib/webpack/extract/modules-packages-duplicate.js.map +1 -1
  44. package/lib/webpack/extract/modules.js +29 -2
  45. package/lib/webpack/extract/modules.js.map +1 -1
  46. package/lib/webpack/index.js +5 -1
  47. package/lib/webpack/index.js.map +1 -1
  48. package/lib/webpack/metrics.js +30 -27
  49. package/lib/webpack/metrics.js.map +1 -1
  50. package/lib-esm/config/component-links.js +1 -0
  51. package/lib-esm/config/component-links.js.map +1 -1
  52. package/lib-esm/config/file-types.js +3 -3
  53. package/lib-esm/config/file-types.js.map +1 -1
  54. package/lib-esm/constants.js +0 -7
  55. package/lib-esm/constants.js.map +1 -1
  56. package/lib-esm/i18n.js +2 -1
  57. package/lib-esm/i18n.js.map +1 -1
  58. package/lib-esm/index.js +0 -3
  59. package/lib-esm/index.js.map +1 -1
  60. package/lib-esm/jobs/create-job.js +2 -2
  61. package/lib-esm/jobs/create-job.js.map +1 -1
  62. package/lib-esm/jobs/create-jobs.js +2 -2
  63. package/lib-esm/jobs/create-jobs.js.map +1 -1
  64. package/lib-esm/utils/component-links.js +14 -0
  65. package/lib-esm/utils/component-links.js.map +1 -1
  66. package/lib-esm/webpack/constants.js +13 -25
  67. package/lib-esm/webpack/constants.js.map +1 -1
  68. package/lib-esm/webpack/extract/assets-size-total-insight.js +4 -4
  69. package/lib-esm/webpack/extract/assets-size-total-insight.js.map +1 -1
  70. package/lib-esm/webpack/extract/assets-size.js +4 -3
  71. package/lib-esm/webpack/extract/assets-size.js.map +1 -1
  72. package/lib-esm/webpack/extract/index.js +1 -3
  73. package/lib-esm/webpack/extract/index.js.map +1 -1
  74. package/lib-esm/webpack/extract/modules-packages-duplicate.js +2 -2
  75. package/lib-esm/webpack/extract/modules-packages-duplicate.js.map +1 -1
  76. package/lib-esm/webpack/extract/modules.js +29 -2
  77. package/lib-esm/webpack/extract/modules.js.map +1 -1
  78. package/lib-esm/webpack/metrics.js +30 -27
  79. package/lib-esm/webpack/metrics.js.map +1 -1
  80. package/package.json +16 -16
  81. package/src/config/component-links.js +1 -0
  82. package/src/config/file-types.js +3 -3
  83. package/src/constants.ts +3 -7
  84. package/src/i18n.js +2 -1
  85. package/src/index.js +0 -2
  86. package/src/jobs/create-job.js +2 -2
  87. package/src/jobs/create-jobs.js +2 -2
  88. package/src/utils/component-links.js +23 -7
  89. package/src/webpack/constants.js +91 -0
  90. package/src/webpack/extract/assets-size-total-insight.js +4 -4
  91. package/src/webpack/extract/assets-size.js +5 -3
  92. package/src/webpack/extract/index.js +5 -7
  93. package/src/webpack/extract/modules-packages-duplicate.js +2 -2
  94. package/src/webpack/extract/modules.ts +35 -4
  95. package/src/webpack/{metrics.ts → metrics.js} +30 -27
  96. package/types/config/component-links.d.ts +1 -0
  97. package/types/constants.d.ts +3 -6
  98. package/types/i18n.d.ts +1 -0
  99. package/types/index.d.ts +0 -2
  100. package/types/jobs/create-job.d.ts +1 -1
  101. package/types/jobs/create-jobs.d.ts +1 -1
  102. package/types/utils/component-links.d.ts +26 -12
  103. package/types/webpack/constants.d.ts +9 -31
  104. package/types/webpack/extract/index.d.ts +1 -1
  105. package/types/webpack/extract/modules-packages-duplicate.d.ts +1 -2
  106. package/types/webpack/metrics.d.ts +153 -102
  107. package/lib/transformers/budgets-insights.js +0 -85
  108. package/lib/transformers/budgets-insights.js.map +0 -1
  109. package/lib/transformers/index.js +0 -24
  110. package/lib/transformers/index.js.map +0 -1
  111. package/lib/webpack/extract/budgets-insights.js +0 -39
  112. package/lib/webpack/extract/budgets-insights.js.map +0 -1
  113. package/lib-esm/transformers/budgets-insights.js +0 -77
  114. package/lib-esm/transformers/budgets-insights.js.map +0 -1
  115. package/lib-esm/transformers/index.js +0 -3
  116. package/lib-esm/transformers/index.js.map +0 -1
  117. package/lib-esm/webpack/extract/budgets-insights.js +0 -33
  118. package/lib-esm/webpack/extract/budgets-insights.js.map +0 -1
  119. package/src/transformers/budgets-insights.ts +0 -143
  120. package/src/transformers/index.ts +0 -1
  121. package/src/webpack/constants.ts +0 -96
  122. package/src/webpack/extract/budgets-insights.ts +0 -73
  123. package/types/transformers/budgets-insights.d.ts +0 -36
  124. package/types/transformers/index.d.ts +0 -1
  125. package/types/webpack/extract/budgets-insights.d.ts +0 -22
@@ -1,143 +0,0 @@
1
- import get from 'lodash/get';
2
-
3
- import { InsightType } from '../constants';
4
- import { getGlobalMetricType } from '../utils';
5
-
6
- interface OptionBudgetMetric {
7
- metric: string;
8
- value: number;
9
- }
10
-
11
- interface Options {
12
- budgets?: Array<OptionBudgetMetric>;
13
- }
14
-
15
- interface BudgetInsight {
16
- currentValue: number;
17
- budgetValue: number;
18
- failed: boolean;
19
- }
20
-
21
- interface BudgetInsightInfo {
22
- type: InsightType;
23
- message: {
24
- template: string;
25
- data: Record<string, unknown>;
26
- };
27
- source: {
28
- metricId: string;
29
- budgetInsight: BudgetInsight;
30
- };
31
- }
32
-
33
- interface BudgetInsights {
34
- [metricId: string]: BudgetInsight;
35
- }
36
-
37
- interface BudgetsInsightsOutput {
38
- insights: {
39
- budgets: BudgetInsights;
40
- };
41
- }
42
-
43
- export const getExtract =
44
- (source: string) => (
45
- _: unknown,
46
- currentExtractedData: any,
47
- __: unknown,
48
- options: Options = {},
49
- ): BudgetsInsightsOutput | null => {
50
- const { budgets: budgetsOptions } = options;
51
-
52
- if (!budgetsOptions) {
53
- return null;
54
- }
55
-
56
- const insights: Array<[string, BudgetInsight]> = [];
57
-
58
- budgetsOptions.forEach((budgetOption) => {
59
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
60
- const currentValue = get(currentExtractedData, `metrics.${budgetMetricId}.value`);
61
- const metric = getGlobalMetricType(`${source}.${budgetMetricId}`);
62
-
63
- if (!currentValue) {
64
- return;
65
- }
66
-
67
- const isValueOverBudget = currentValue > budgetValue;
68
-
69
- const budgetInsight = {
70
- currentValue,
71
- budgetValue,
72
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
73
- };
74
-
75
- insights.push([budgetMetricId, budgetInsight]);
76
- });
77
-
78
- if (insights.length === 0) {
79
- return null;
80
- }
81
-
82
- return {
83
- insights: {
84
- budgets: Object.fromEntries(insights),
85
- },
86
- };
87
- };
88
-
89
- const resolveDiffLabel = (budgetInsight: BudgetInsight): string => {
90
- const { currentValue, budgetValue } = budgetInsight;
91
-
92
- if (currentValue > budgetValue) {
93
- return 'over';
94
- }
95
-
96
- if (currentValue < budgetValue) {
97
- return 'under';
98
- }
99
-
100
- return 'equal with';
101
- };
102
-
103
- const resolveType = (budgetInsight: BudgetInsight): InsightType => {
104
- if (budgetInsight.failed) {
105
- return InsightType.ERROR;
106
- }
107
-
108
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
109
- return InsightType.WARNING;
110
- }
111
-
112
- return InsightType.SUCCESS;
113
- };
114
-
115
- // Add escapes for (|) to avoid lodash.template syntax errors
116
- // eslint-disable-next-line no-useless-escape
117
- export const INFO_MESSAGE_TEMPLATE = '<%= metricLabel %> value \(<%= currentValue %>\) is <%= diffLabel %> <%= budgetValue %> budget';
118
-
119
- export const getInfo = (globalMetricId: string, budgetInsight: BudgetInsight): BudgetInsightInfo => {
120
- const metric = getGlobalMetricType(globalMetricId);
121
-
122
- const diffLabel = resolveDiffLabel(budgetInsight);
123
- const type = resolveType(budgetInsight);
124
- const currentValue = metric.formatter(budgetInsight.currentValue);
125
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
126
-
127
- return {
128
- type,
129
- message: {
130
- template: INFO_MESSAGE_TEMPLATE,
131
- data: {
132
- metricLabel: metric.label,
133
- diffLabel,
134
- currentValue,
135
- budgetValue,
136
- },
137
- },
138
- source: {
139
- metricId: globalMetricId,
140
- budgetInsight,
141
- },
142
- };
143
- };
@@ -1 +0,0 @@
1
- export * as budgetInsights from './budgets-insights';
@@ -1,96 +0,0 @@
1
- export const SECTION_WEBPACK_STATS = 'stats';
2
- export const SECTION_WEBPACK_SIZES = 'sizes';
3
- export const SECTION_WEBPACK_ASSETS = 'assets';
4
- export const SECTION_WEBPACK_MODULES = 'modules';
5
- export const SECTION_WEBPACK_PACKAGES = 'packages';
6
-
7
- export const SECTIONS = [
8
- SECTION_WEBPACK_STATS,
9
- SECTION_WEBPACK_SIZES,
10
- SECTION_WEBPACK_ASSETS,
11
- SECTION_WEBPACK_MODULES,
12
- SECTION_WEBPACK_PACKAGES,
13
- ];
14
-
15
- export enum MetricId {
16
- BundleSize = 'totalSizeByTypeALL',
17
- TotalInitialSizeJS = 'totalInitialSizeJS',
18
- TotalInitialSizeCSS = 'totalInitialSizeCSS',
19
- CacheInvalidation = 'cacheInvalidation',
20
- ModuleName = 'moduleCount',
21
- ChunkCount = 'chunkCount',
22
- AssetCount = 'assetCount',
23
- PackageCount = 'packageCount',
24
- DuplicatePackagesCount = 'duplicatePackagesCount',
25
- }
26
-
27
- export const SIZE_BY_TYPE_METRIC_ID_ALL = 'ALL';
28
- export const SIZE_BY_TYPE_METRIC_ID_PREFIX = 'totalSizeByType';
29
-
30
- export enum SizeByTypeMetricId {
31
- JS = 'totalSizeByTypeJS',
32
- CSS = 'totalSizeByTypeCSS',
33
- IMG = 'totalSizeByTypeIMG',
34
- Media = 'totalSizeByTypeMEDIA',
35
- Font = 'totalSizeByTypeFONT',
36
- HTML = 'totalSizeByTypeHTML',
37
- Other = 'totalSizeByTypeOTHER',
38
- }
39
-
40
- export const SUMMARY_METRIC_PATHS = Object.values(MetricId);
41
-
42
- const PACKAGE_PREFIX = /(?:node_modules|~)(?:\/\.pnpm)?/;
43
- const PACKAGE_SLUG = /[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*/;
44
- const VERSION = /@[\w|\-|_|.]+/;
45
-
46
- // Extract package paths from module path
47
- // https://regex101.com/r/22Leep/6
48
- /* eslint-disable prettier/prettier, @typescript-eslint/indent */
49
- export const MODULE_PATH_PACKAGES = new RegExp([
50
- // match dependency directory (eg: `node_modules/`, `node_modules/.pnpm/`)
51
- `(?:${PACKAGE_PREFIX.source}/)`,
52
- // match package name
53
- '(?:',
54
- // match `@organization/` or `@organization+`(pnpm)
55
- `(?:@${PACKAGE_SLUG.source}[/|+])?`,
56
- // match github.com+organization+
57
- `(?:${PACKAGE_SLUG.source}\\+)*`,
58
- // match package name
59
- `(?:${PACKAGE_SLUG.source})`,
60
- // match version
61
- `(?:${VERSION.source})?`,
62
- ')',
63
-
64
- // Match pnpm peer dependencies (eg: package-a@version_package-b@version)
65
- '(?:_',
66
- `(?:@${PACKAGE_SLUG.source}[/|+])?`,
67
- `(?:${PACKAGE_SLUG.source})`,
68
- `(?:@${PACKAGE_SLUG.source})?`,
69
- ')*',
70
- '/',
71
- ].join(''), 'g');
72
-
73
- // Extract package name from package path
74
- // https://regex101.com/r/tTlU0W/6
75
- export const PACKAGE_PATH_NAME = new RegExp([
76
- `(?:${PACKAGE_PREFIX.source}/)`,
77
- // match dependency
78
- '(?:',
79
- '(',
80
- `(?:@${PACKAGE_SLUG.source}[/|+])?`,
81
- `(?:(?:${PACKAGE_SLUG.source}\\+)*)`,
82
- `(?:${PACKAGE_SLUG.source})`,
83
- ')',
84
- `(?:${VERSION.source})?`,
85
- ')',
86
- // match peer dependency
87
- '(?:_',
88
- '(',
89
- `(?:@${PACKAGE_SLUG.source}[/|+])?`,
90
- `(?:${PACKAGE_SLUG.source})`,
91
- ')',
92
- `(?:@${PACKAGE_SLUG.source})`,
93
- ')*',
94
- '/',
95
- ].join(''), 'g');
96
- /* eslint-enable prettier/prettier, @typescript-eslint/indent */
@@ -1,73 +0,0 @@
1
- import get from 'lodash/get';
2
-
3
- import { getMetricType } from '../utils';
4
-
5
- interface OptionBudgetMetric {
6
- metric: string;
7
- value: number;
8
- }
9
-
10
- interface Options {
11
- budgets?: Array<OptionBudgetMetric>;
12
- }
13
-
14
- interface BudgetInsight {
15
- currentValue: number;
16
- budgetValue: number;
17
- failed: boolean;
18
- }
19
-
20
- interface BudgetsInsights {
21
- [metricId: string]: BudgetInsight;
22
- }
23
-
24
- interface ExtractBudgetsInsights {
25
- insights: {
26
- budgets: BudgetsInsights;
27
- };
28
- }
29
-
30
- export default function extractBudgetsInsights(
31
- _: unknown,
32
- currentExtractedData: any,
33
- __: unknown,
34
- options: Options = {}
35
- ): ExtractBudgetsInsights | null {
36
- const { budgets: budgetsOptions } = options;
37
-
38
- if (!budgetsOptions) {
39
- return null;
40
- }
41
-
42
- const insights: Array<[string, BudgetInsight]> = [];
43
-
44
- budgetsOptions.forEach((budgetOption) => {
45
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
46
- const currentValue = get(currentExtractedData, `metrics.${budgetMetricId}.value`);
47
- const metric = getMetricType(budgetMetricId);
48
-
49
- if (!currentValue) {
50
- return;
51
- }
52
-
53
- const isValueOverBudget = currentValue > budgetValue;
54
-
55
- const budgetInsight = {
56
- currentValue,
57
- budgetValue,
58
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
59
- };
60
-
61
- insights.push([budgetMetricId, budgetInsight]);
62
- });
63
-
64
- if (insights.length === 0) {
65
- return null;
66
- }
67
-
68
- return {
69
- insights: {
70
- budgets: Object.fromEntries(insights),
71
- },
72
- };
73
- }
@@ -1,36 +0,0 @@
1
- import { InsightType } from '../constants';
2
- interface OptionBudgetMetric {
3
- metric: string;
4
- value: number;
5
- }
6
- interface Options {
7
- budgets?: Array<OptionBudgetMetric>;
8
- }
9
- interface BudgetInsight {
10
- currentValue: number;
11
- budgetValue: number;
12
- failed: boolean;
13
- }
14
- interface BudgetInsightInfo {
15
- type: InsightType;
16
- message: {
17
- template: string;
18
- data: Record<string, unknown>;
19
- };
20
- source: {
21
- metricId: string;
22
- budgetInsight: BudgetInsight;
23
- };
24
- }
25
- interface BudgetInsights {
26
- [metricId: string]: BudgetInsight;
27
- }
28
- interface BudgetsInsightsOutput {
29
- insights: {
30
- budgets: BudgetInsights;
31
- };
32
- }
33
- export declare const getExtract: (source: string) => (_: unknown, currentExtractedData: any, __: unknown, options?: Options) => BudgetsInsightsOutput | null;
34
- export declare const INFO_MESSAGE_TEMPLATE = "<%= metricLabel %> value (<%= currentValue %>) is <%= diffLabel %> <%= budgetValue %> budget";
35
- export declare const getInfo: (globalMetricId: string, budgetInsight: BudgetInsight) => BudgetInsightInfo;
36
- export {};
@@ -1 +0,0 @@
1
- export * as budgetInsights from './budgets-insights';
@@ -1,22 +0,0 @@
1
- interface OptionBudgetMetric {
2
- metric: string;
3
- value: number;
4
- }
5
- interface Options {
6
- budgets?: Array<OptionBudgetMetric>;
7
- }
8
- interface BudgetInsight {
9
- currentValue: number;
10
- budgetValue: number;
11
- failed: boolean;
12
- }
13
- interface BudgetsInsights {
14
- [metricId: string]: BudgetInsight;
15
- }
16
- interface ExtractBudgetsInsights {
17
- insights: {
18
- budgets: BudgetsInsights;
19
- };
20
- }
21
- export default function extractBudgetsInsights(_: unknown, currentExtractedData: any, __: unknown, options?: Options): ExtractBudgetsInsights | null;
22
- export {};