@bundle-stats/utils 3.4.0-alpha.5 → 3.4.0-beta.0

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.
@@ -3,10 +3,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getInfo = exports.INFO_MESSAGE_TEMPLATE = exports.getExtract = void 0;
6
+ exports.getExtract = void 0;
7
7
  const get_1 = __importDefault(require("lodash/get"));
8
+ const template_1 = __importDefault(require("lodash/template"));
8
9
  const constants_1 = require("../constants");
9
10
  const utils_1 = require("../utils");
11
+ const resolveType = (insights) => {
12
+ if (insights.find(([_, { type }]) => type === constants_1.InsightType.ERROR)) {
13
+ return constants_1.InsightType.ERROR;
14
+ }
15
+ if (insights.find(([_, { type }]) => type === constants_1.InsightType.WARNING)) {
16
+ return constants_1.InsightType.WARNING;
17
+ }
18
+ return constants_1.InsightType.SUCCESS;
19
+ };
20
+ const budgetInsightTemplate = (0, template_1.default)('<%= count %>/<%= total %> budget checks <%= status %>');
21
+ const resolveStatus = (failedCount, warningCount) => {
22
+ if (failedCount) {
23
+ return 'failed';
24
+ }
25
+ if (warningCount) {
26
+ return 'warned';
27
+ }
28
+ return 'passed';
29
+ };
30
+ const getMessage = (insights) => {
31
+ const total = insights.length;
32
+ const failedCount = insights.filter(([___, insight]) => insight.type === constants_1.InsightType.ERROR).length;
33
+ const warningCount = insights.filter(([___, insight]) => insight.type === constants_1.InsightType.WARNING).length;
34
+ const count = failedCount || warningCount || total;
35
+ const status = resolveStatus(failedCount, warningCount);
36
+ return {
37
+ text: budgetInsightTemplate({
38
+ count,
39
+ total,
40
+ status,
41
+ }),
42
+ md: budgetInsightTemplate({
43
+ count: `**${count}**`,
44
+ total: `**${total}**`,
45
+ status,
46
+ }),
47
+ };
48
+ };
49
+ const budgetInsightMetricTemplate = (0, template_1.default)('<%= metricLabel %> is <%= diffLabel %> budget \(<%= currentValue %> / <%= budgetValue %>\)');
50
+ const resolveDiffLabel = (metricBudgetInsight) => {
51
+ const { currentValue, budgetValue } = metricBudgetInsight;
52
+ if (currentValue > budgetValue) {
53
+ return 'above';
54
+ }
55
+ if (currentValue < budgetValue) {
56
+ return 'below';
57
+ }
58
+ return 'equal with';
59
+ };
60
+ const resolveBudgetInsightMetricType = (metricBudgetInsight) => {
61
+ if (metricBudgetInsight.failed) {
62
+ return constants_1.InsightType.ERROR;
63
+ }
64
+ if (metricBudgetInsight.currentValue === metricBudgetInsight.budgetValue) {
65
+ return constants_1.InsightType.WARNING;
66
+ }
67
+ return constants_1.InsightType.SUCCESS;
68
+ };
10
69
  const getExtract = (source) => (_, currentExtractedData, __, options = {}) => {
11
70
  const { budgets: budgetsOptions } = options;
12
71
  if (!budgetsOptions) {
@@ -14,72 +73,61 @@ const getExtract = (source) => (_, currentExtractedData, __, options = {}) => {
14
73
  }
15
74
  const insights = [];
16
75
  budgetsOptions.forEach((budgetOption) => {
17
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
18
- const currentValue = (0, get_1.default)(currentExtractedData, `metrics.${budgetMetricId}.value`);
19
- const metric = (0, utils_1.getGlobalMetricType)(`${source}.${budgetMetricId}`);
76
+ const { metric: sourceMetricId, value: budgetValue } = budgetOption;
77
+ const currentValue = (0, get_1.default)(currentExtractedData, `metrics.${sourceMetricId}.value`);
78
+ const metricData = (0, utils_1.getGlobalMetricType)(`${source}.${sourceMetricId}`);
20
79
  if (!currentValue) {
21
80
  return;
22
81
  }
23
82
  const isValueOverBudget = currentValue > budgetValue;
24
- const budgetInsight = {
83
+ const failed = metricData.biggerIsBetter ? !isValueOverBudget : isValueOverBudget;
84
+ const budgetInsightMetricData = {
25
85
  currentValue,
26
86
  budgetValue,
27
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
87
+ failed,
28
88
  };
29
- insights.push([budgetMetricId, budgetInsight]);
89
+ const diffLabel = resolveDiffLabel(budgetInsightMetricData);
90
+ const type = resolveBudgetInsightMetricType(budgetInsightMetricData);
91
+ const currentFormattedValue = metricData.formatter(currentValue);
92
+ const budgetFormattedValue = metricData.formatter(budgetValue);
93
+ const messageText = budgetInsightMetricTemplate({
94
+ metricLabel: metricData.label,
95
+ currentValue: currentFormattedValue,
96
+ diffLabel,
97
+ budgetValue: budgetFormattedValue,
98
+ });
99
+ const messageMd = budgetInsightMetricTemplate({
100
+ metricLabel: `**${metricData.label}**`,
101
+ currentValue: `**${currentFormattedValue}**`,
102
+ diffLabel,
103
+ budgetValue: `**${budgetFormattedValue}**`,
104
+ });
105
+ insights.push([
106
+ sourceMetricId,
107
+ {
108
+ type,
109
+ message: {
110
+ text: messageText,
111
+ md: messageMd,
112
+ },
113
+ data: budgetInsightMetricData,
114
+ },
115
+ ]);
30
116
  });
31
117
  if (insights.length === 0) {
32
118
  return null;
33
119
  }
120
+ const type = resolveType(insights);
121
+ const message = getMessage(insights);
34
122
  return {
35
123
  insights: {
36
- budgets: Object.fromEntries(insights),
37
- },
38
- };
39
- };
40
- exports.getExtract = getExtract;
41
- const resolveDiffLabel = (budgetInsight) => {
42
- const { currentValue, budgetValue } = budgetInsight;
43
- if (currentValue > budgetValue) {
44
- return 'over';
45
- }
46
- if (currentValue < budgetValue) {
47
- return 'under';
48
- }
49
- return 'equal with';
50
- };
51
- const resolveType = (budgetInsight) => {
52
- if (budgetInsight.failed) {
53
- return constants_1.InsightType.ERROR;
54
- }
55
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
56
- return constants_1.InsightType.WARNING;
57
- }
58
- return constants_1.InsightType.SUCCESS;
59
- };
60
- exports.INFO_MESSAGE_TEMPLATE = '<%= metricLabel %> value \(<%= currentValue %>\) is <%= diffLabel %> <%= budgetValue %> budget';
61
- const getInfo = (globalMetricId, budgetInsight) => {
62
- const metric = (0, utils_1.getGlobalMetricType)(globalMetricId);
63
- const diffLabel = resolveDiffLabel(budgetInsight);
64
- const type = resolveType(budgetInsight);
65
- const currentValue = metric.formatter(budgetInsight.currentValue);
66
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
67
- return {
68
- type,
69
- message: {
70
- template: exports.INFO_MESSAGE_TEMPLATE,
71
- data: {
72
- metricLabel: metric.label,
73
- diffLabel,
74
- currentValue,
75
- budgetValue,
124
+ budgets: {
125
+ type,
126
+ message,
127
+ data: Object.fromEntries(insights),
76
128
  },
77
129
  },
78
- source: {
79
- metricId: globalMetricId,
80
- budgetInsight,
81
- },
82
130
  };
83
131
  };
84
- exports.getInfo = getInfo;
132
+ exports.getExtract = getExtract;
85
133
  //# sourceMappingURL=budgets-insights.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"budgets-insights.js","sourceRoot":"","sources":["../../src/transformers/budgets-insights.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA6B;AAE7B,4CAA2C;AAC3C,oCAA+C;AAuCxC,MAAM,UAAU,GACrB,CAAC,MAAc,EAAE,EAAE,CAAC,CAClB,CAAU,EACV,oBAAyB,EACzB,EAAW,EACX,UAAmB,EAAE,EACS,EAAE;IAChC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAE5C,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAmC,EAAE,CAAC;IAEpD,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;QACtC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;QACpE,MAAM,YAAY,GAAG,IAAA,aAAG,EAAC,oBAAoB,EAAE,WAAW,cAAc,QAAQ,CAAC,CAAC;QAClF,MAAM,MAAM,GAAG,IAAA,2BAAmB,EAAC,GAAG,MAAM,IAAI,cAAc,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,MAAM,iBAAiB,GAAG,Y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,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC;aACnC;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAjFS,QAAA,UAAU,cAiFnB"}
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -4,16 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.extractAssets = void 0;
7
- const get_1 = __importDefault(require("lodash/get"));
8
7
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
9
8
  const utils_1 = require("../utils");
10
9
  const IGNORE_PATTERN = /\.(map|LICENSE\.txt)$/;
11
10
  const extractAssets = (webpackStats) => {
12
- const webpackAssets = (0, get_1.default)(webpackStats, 'assets', []);
13
- const webpackChunks = (0, get_1.default)(webpackStats, 'chunks', []);
14
- const webpackEntrypoints = (0, get_1.default)(webpackStats, 'entrypoints', {});
15
- const entryItems = Object.values(webpackEntrypoints)
16
- .map(({ assets: items }) => items)
11
+ const webpackAssets = (webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.assets) || [];
12
+ const webpackChunks = (webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.chunks) || [];
13
+ const webpackEntrypoints = (webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.entrypoints) || {};
14
+ const entrypointsAssets = Object.values(webpackEntrypoints)
15
+ .map(({ assets: items }) => items.map((item) => {
16
+ if (typeof item === 'object') {
17
+ return item.name;
18
+ }
19
+ return item;
20
+ }))
17
21
  .flat();
18
22
  const initialItems = webpackChunks
19
23
  .filter(({ initial }) => initial)
@@ -37,7 +41,7 @@ const extractAssets = (webpackStats) => {
37
41
  [normalizedName]: {
38
42
  name: baseName,
39
43
  value: size,
40
- isEntry: entryItems.includes(name),
44
+ isEntry: entrypointsAssets.includes(name),
41
45
  isInitial: initialItems.includes(name),
42
46
  isChunk: Boolean(assetChunk),
43
47
  ...(assetChunk ? { chunkId: assetChunk.id } : {}),
@@ -1 +1 @@
1
- {"version":3,"file":"assets.js","sourceRoot":"","sources":["../../../src/webpack/extract/assets.js"],"names":[],"mappings":";;;;;;AAAA,qDAA6B;AAC7B,6DAAqC;AAErC,oCAA0D;AAE1D,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAExC,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,EAAE;IAC5C,MAAM,aAAa,GAAG,IAAA,aAAG,EAAC,YAAY,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,aAAa,GAAG,IAAA,aAAG,EAAC,YAAY,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,kBAAkB,GAAG,IAAA,aAAG,EAAC,YAAY,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;IAEhE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;SACjD,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC;SACjC,IAAI,EAAE,CAAC;IAEV,MAAM,YAAY,GAAG,aAAa;SAC/B,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC;SAChC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC;SACzB,IAAI,EAAE,CAAC;IAEV,MAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACpE,EAAE,EAAE,IAAA,wBAAgB,EAAC,EAAE,CAAC;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,E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EAAE,CAAC;aAClD;SACF,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,OAAO,EAAE;YACP,MAAM;SACP;QACD,GAAG,CAAC,CAAC,IAAA,iBAAO,EAAC,gBAAgB,CAAC;YAC5B,CAAC,CAAC;gBACA,IAAI,EAAE;oBACJ,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;iBAC/D;aACF;YACD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC;AAhEW,QAAA,aAAa,iBAgExB"}
@@ -1,6 +1,65 @@
1
1
  import get from 'lodash/get';
2
+ import template from 'lodash/template';
2
3
  import { InsightType } from '../constants';
3
4
  import { getGlobalMetricType } from '../utils';
5
+ const resolveType = (insights) => {
6
+ if (insights.find(([_, { type }]) => type === InsightType.ERROR)) {
7
+ return InsightType.ERROR;
8
+ }
9
+ if (insights.find(([_, { type }]) => type === InsightType.WARNING)) {
10
+ return InsightType.WARNING;
11
+ }
12
+ return InsightType.SUCCESS;
13
+ };
14
+ const budgetInsightTemplate = template('<%= count %>/<%= total %> budget checks <%= status %>');
15
+ const resolveStatus = (failedCount, warningCount) => {
16
+ if (failedCount) {
17
+ return 'failed';
18
+ }
19
+ if (warningCount) {
20
+ return 'warned';
21
+ }
22
+ return 'passed';
23
+ };
24
+ const getMessage = (insights) => {
25
+ const total = insights.length;
26
+ const failedCount = insights.filter(([___, insight]) => insight.type === InsightType.ERROR).length;
27
+ const warningCount = insights.filter(([___, insight]) => insight.type === InsightType.WARNING).length;
28
+ const count = failedCount || warningCount || total;
29
+ const status = resolveStatus(failedCount, warningCount);
30
+ return {
31
+ text: budgetInsightTemplate({
32
+ count,
33
+ total,
34
+ status,
35
+ }),
36
+ md: budgetInsightTemplate({
37
+ count: `**${count}**`,
38
+ total: `**${total}**`,
39
+ status,
40
+ }),
41
+ };
42
+ };
43
+ const budgetInsightMetricTemplate = template('<%= metricLabel %> is <%= diffLabel %> budget \(<%= currentValue %> / <%= budgetValue %>\)');
44
+ const resolveDiffLabel = (metricBudgetInsight) => {
45
+ const { currentValue, budgetValue } = metricBudgetInsight;
46
+ if (currentValue > budgetValue) {
47
+ return 'above';
48
+ }
49
+ if (currentValue < budgetValue) {
50
+ return 'below';
51
+ }
52
+ return 'equal with';
53
+ };
54
+ const resolveBudgetInsightMetricType = (metricBudgetInsight) => {
55
+ if (metricBudgetInsight.failed) {
56
+ return InsightType.ERROR;
57
+ }
58
+ if (metricBudgetInsight.currentValue === metricBudgetInsight.budgetValue) {
59
+ return InsightType.WARNING;
60
+ }
61
+ return InsightType.SUCCESS;
62
+ };
4
63
  export const getExtract = (source) => (_, currentExtractedData, __, options = {}) => {
5
64
  const { budgets: budgetsOptions } = options;
6
65
  if (!budgetsOptions) {
@@ -8,70 +67,60 @@ export const getExtract = (source) => (_, currentExtractedData, __, options = {}
8
67
  }
9
68
  const insights = [];
10
69
  budgetsOptions.forEach((budgetOption) => {
11
- const { metric: budgetMetricId, value: budgetValue } = budgetOption;
12
- const currentValue = get(currentExtractedData, `metrics.${budgetMetricId}.value`);
13
- const metric = getGlobalMetricType(`${source}.${budgetMetricId}`);
70
+ const { metric: sourceMetricId, value: budgetValue } = budgetOption;
71
+ const currentValue = get(currentExtractedData, `metrics.${sourceMetricId}.value`);
72
+ const metricData = getGlobalMetricType(`${source}.${sourceMetricId}`);
14
73
  if (!currentValue) {
15
74
  return;
16
75
  }
17
76
  const isValueOverBudget = currentValue > budgetValue;
18
- const budgetInsight = {
77
+ const failed = metricData.biggerIsBetter ? !isValueOverBudget : isValueOverBudget;
78
+ const budgetInsightMetricData = {
19
79
  currentValue,
20
80
  budgetValue,
21
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
81
+ failed,
22
82
  };
23
- insights.push([budgetMetricId, budgetInsight]);
83
+ const diffLabel = resolveDiffLabel(budgetInsightMetricData);
84
+ const type = resolveBudgetInsightMetricType(budgetInsightMetricData);
85
+ const currentFormattedValue = metricData.formatter(currentValue);
86
+ const budgetFormattedValue = metricData.formatter(budgetValue);
87
+ const messageText = budgetInsightMetricTemplate({
88
+ metricLabel: metricData.label,
89
+ currentValue: currentFormattedValue,
90
+ diffLabel,
91
+ budgetValue: budgetFormattedValue,
92
+ });
93
+ const messageMd = budgetInsightMetricTemplate({
94
+ metricLabel: `**${metricData.label}**`,
95
+ currentValue: `**${currentFormattedValue}**`,
96
+ diffLabel,
97
+ budgetValue: `**${budgetFormattedValue}**`,
98
+ });
99
+ insights.push([
100
+ sourceMetricId,
101
+ {
102
+ type,
103
+ message: {
104
+ text: messageText,
105
+ md: messageMd,
106
+ },
107
+ data: budgetInsightMetricData,
108
+ },
109
+ ]);
24
110
  });
25
111
  if (insights.length === 0) {
26
112
  return null;
27
113
  }
114
+ const type = resolveType(insights);
115
+ const message = getMessage(insights);
28
116
  return {
29
117
  insights: {
30
- budgets: Object.fromEntries(insights),
31
- },
32
- };
33
- };
34
- const resolveDiffLabel = (budgetInsight) => {
35
- const { currentValue, budgetValue } = budgetInsight;
36
- if (currentValue > budgetValue) {
37
- return 'over';
38
- }
39
- if (currentValue < budgetValue) {
40
- return 'under';
41
- }
42
- return 'equal with';
43
- };
44
- const resolveType = (budgetInsight) => {
45
- if (budgetInsight.failed) {
46
- return InsightType.ERROR;
47
- }
48
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
49
- return InsightType.WARNING;
50
- }
51
- return InsightType.SUCCESS;
52
- };
53
- export const INFO_MESSAGE_TEMPLATE = '<%= metricLabel %> value \(<%= currentValue %>\) is <%= diffLabel %> <%= budgetValue %> budget';
54
- export const getInfo = (globalMetricId, budgetInsight) => {
55
- const metric = getGlobalMetricType(globalMetricId);
56
- const diffLabel = resolveDiffLabel(budgetInsight);
57
- const type = resolveType(budgetInsight);
58
- const currentValue = metric.formatter(budgetInsight.currentValue);
59
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
60
- return {
61
- type,
62
- message: {
63
- template: INFO_MESSAGE_TEMPLATE,
64
- data: {
65
- metricLabel: metric.label,
66
- diffLabel,
67
- currentValue,
68
- budgetValue,
118
+ budgets: {
119
+ type,
120
+ message,
121
+ data: Object.fromEntries(insights),
69
122
  },
70
123
  },
71
- source: {
72
- metricId: globalMetricId,
73
- budgetInsight,
74
- },
75
124
  };
76
125
  };
77
126
  //# sourceMappingURL=budgets-insights.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"budgets-insights.js","sourceRoot":"","sources":["../../src/transformers/budgets-insights.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAuC/C,MAAM,CAAC,MAAM,UAAU,GACrB,CAAC,MAAc,EAAE,EAAE,CAAC,CAClB,CAAU,EACV,oBAAyB,EACzB,EAAW,EACX,UAAmB,EAAE,EACS,EAAE;IAChC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAE5C,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAmC,EAAE,CAAC;IAEpD,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;QACtC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;QACpE,MAAM,YAAY,GAAG,GAAG,CAAC,oBAAoB,EAAE,WAAW,cAAc,QAAQ,CAAC,CAAC;QAClF,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,MAAM,IAAI,cAAc,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,MAAM,iBAAiB,GAAG,YAAY,GAAG,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I;gBACJ,OAAO;gBACP,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC;aACnC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,13 +1,17 @@
1
- import get from 'lodash/get';
2
1
  import isEmpty from 'lodash/isEmpty';
3
2
  import { getAssetName, normalizeChunkId } from '../utils';
4
3
  const IGNORE_PATTERN = /\.(map|LICENSE\.txt)$/;
5
4
  export const extractAssets = (webpackStats) => {
6
- const webpackAssets = get(webpackStats, 'assets', []);
7
- const webpackChunks = get(webpackStats, 'chunks', []);
8
- const webpackEntrypoints = get(webpackStats, 'entrypoints', {});
9
- const entryItems = Object.values(webpackEntrypoints)
10
- .map(({ assets: items }) => items)
5
+ const webpackAssets = (webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.assets) || [];
6
+ const webpackChunks = (webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.chunks) || [];
7
+ const webpackEntrypoints = (webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.entrypoints) || {};
8
+ const entrypointsAssets = Object.values(webpackEntrypoints)
9
+ .map(({ assets: items }) => items.map((item) => {
10
+ if (typeof item === 'object') {
11
+ return item.name;
12
+ }
13
+ return item;
14
+ }))
11
15
  .flat();
12
16
  const initialItems = webpackChunks
13
17
  .filter(({ initial }) => initial)
@@ -31,7 +35,7 @@ export const extractAssets = (webpackStats) => {
31
35
  [normalizedName]: {
32
36
  name: baseName,
33
37
  value: size,
34
- isEntry: entryItems.includes(name),
38
+ isEntry: entrypointsAssets.includes(name),
35
39
  isInitial: initialItems.includes(name),
36
40
  isChunk: Boolean(assetChunk),
37
41
  ...(assetChunk ? { chunkId: assetChunk.id } : {}),
@@ -1 +1 @@
1
- {"version":3,"file":"assets.js","sourceRoot":"","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AO,EAAE;YACP,MAAM;SACP;QACD,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAC5B,CAAC,CAAC;gBACA,IAAI,EAAE;oBACJ,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;iBAC/D;aACF;YACD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bundle-stats/utils",
3
- "version": "3.4.0-alpha.5",
3
+ "version": "3.4.0-beta.0",
4
4
  "description": "BundleStats utils",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -35,28 +35,28 @@
35
35
  },
36
36
  "homepage": "https://github.com/relative-ci/bundle-stats/blob/master/packages/utils#readme",
37
37
  "dependencies": {
38
- "@bundle-stats/plugin-webpack-filter": "^3.4.0-alpha.5",
39
- "@bundle-stats/plugin-webpack-validate": "^3.4.0-alpha.5",
38
+ "@bundle-stats/plugin-webpack-filter": "^3.4.0-beta.0",
39
+ "@bundle-stats/plugin-webpack-validate": "^3.4.0-beta.0",
40
40
  "convert-units": "3.0.0-beta.2",
41
- "query-string": "7.1.1",
42
- "serialize-query-params": "1.3.6"
41
+ "query-string": "^7.1.0",
42
+ "serialize-query-params": "^1.3.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/jest": "27.4.1",
46
- "@types/lodash": "4.14.180",
47
- "core-js": "3.20.2",
46
+ "@types/lodash": "4.14.181",
47
+ "core-js": "3.21.1",
48
48
  "jest": "27.5.1",
49
49
  "jest-cli": "27.5.1",
50
50
  "jest-date-mock": "1.0.8",
51
51
  "lodash": "4.17.21",
52
52
  "regenerator-runtime": "0.13.9",
53
53
  "rimraf": "3.0.2",
54
- "ts-jest": "27.1.3",
55
- "typescript": "4.6.2"
54
+ "ts-jest": "27.1.4",
55
+ "typescript": "4.6.3"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "core-js": "^3.0.0",
59
59
  "lodash": "^4.0.0"
60
60
  },
61
- "gitHead": "8cf4f784d15aed35e09a911a2fc9646a3fb9b06c"
61
+ "gitHead": "45774cba629c670df5528d72a67d3cfaddd8fed7"
62
62
  }
@@ -1,5 +1,7 @@
1
1
  import get from 'lodash/get';
2
+ import template from 'lodash/template';
2
3
 
4
+ import * as types from '../types';
3
5
  import { InsightType } from '../constants';
4
6
  import { getGlobalMetricType } from '../utils';
5
7
 
@@ -12,132 +14,199 @@ interface Options {
12
14
  budgets?: Array<OptionBudgetMetric>;
13
15
  }
14
16
 
15
- interface BudgetInsight {
17
+ interface BudgetInsightMetricData {
16
18
  currentValue: number;
17
19
  budgetValue: number;
18
20
  failed: boolean;
19
21
  }
20
22
 
21
- interface BudgetInsightInfo {
23
+ interface BudgetInsightMetric {
24
+ /** Metric budget insight type */
22
25
  type: InsightType;
23
26
  message: {
24
- template: string;
25
- data: Record<string, unknown>;
26
- };
27
- source: {
28
- metricId: string;
29
- budgetInsight: BudgetInsight;
27
+ text: string;
28
+ md: string;
30
29
  };
30
+ /** Metric budget check data */
31
+ data: BudgetInsightMetricData;
31
32
  }
32
33
 
33
- interface BudgetInsights {
34
- [metricId: string]: BudgetInsight;
34
+ interface BudgetInsight extends types.Insight {
35
+ data: {
36
+ [metricId: string]: BudgetInsightMetric;
37
+ };
35
38
  }
36
39
 
37
40
  interface BudgetsInsightsOutput {
38
41
  insights: {
39
- budgets: BudgetInsights;
42
+ budgets: BudgetInsight;
40
43
  };
41
44
  }
42
45
 
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;
46
+ const resolveType = (insights: Array<[string, BudgetInsightMetric]>): InsightType => {
47
+ if (insights.find(([_, { type }]) => type === InsightType.ERROR)) {
48
+ return InsightType.ERROR;
49
+ }
51
50
 
52
- if (!budgetsOptions) {
53
- return null;
54
- }
51
+ if (insights.find(([_, { type }]) => type === InsightType.WARNING)) {
52
+ return InsightType.WARNING;
53
+ }
55
54
 
56
- const insights: Array<[string, BudgetInsight]> = [];
55
+ return InsightType.SUCCESS;
56
+ };
57
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}`);
58
+ // 3/3 budget checks passed
59
+ // 2/3 budget checks failed
60
+ // 1 failed, 1 warning, 2 success
62
61
 
63
- if (!currentValue) {
64
- return;
65
- }
62
+ const budgetInsightTemplate = template(
63
+ '<%= count %>/<%= total %> budget checks <%= status %>'
64
+ );
66
65
 
67
- const isValueOverBudget = currentValue > budgetValue;
66
+ const resolveStatus = (failedCount: number, warningCount: number): string => {
67
+ if (failedCount) {
68
+ return 'failed';
69
+ }
68
70
 
69
- const budgetInsight = {
70
- currentValue,
71
- budgetValue,
72
- failed: metric.biggerIsBetter ? !isValueOverBudget : isValueOverBudget,
73
- };
71
+ if (warningCount) {
72
+ return 'warned';
73
+ }
74
74
 
75
- insights.push([budgetMetricId, budgetInsight]);
76
- });
75
+ return 'passed';
76
+ };
77
77
 
78
- if (insights.length === 0) {
79
- return null;
80
- }
78
+ const getMessage = (insights: Array<[string, BudgetInsightMetric]>) => {
79
+ const total = insights.length;
80
+ const failedCount = insights.filter(([___, insight]) => insight.type === InsightType.ERROR).length;
81
+ const warningCount = insights.filter(([___, insight]) => insight.type === InsightType.WARNING).length;
82
+ const count = failedCount || warningCount || total;
83
+ const status = resolveStatus(failedCount, warningCount);
81
84
 
82
- return {
83
- insights: {
84
- budgets: Object.fromEntries(insights),
85
- },
86
- };
85
+ return {
86
+ text: budgetInsightTemplate({
87
+ count,
88
+ total,
89
+ status,
90
+ }),
91
+ md: budgetInsightTemplate({
92
+ count: `**${count}**`,
93
+ total: `**${total}**`,
94
+ status,
95
+ }),
87
96
  };
97
+ };
98
+
99
+ const budgetInsightMetricTemplate = template(
100
+ // Add escapes for (|) to avoid lodash.template syntax errors
101
+ // eslint-disable-next-line no-useless-escape
102
+ '<%= metricLabel %> is <%= diffLabel %> budget \(<%= currentValue %> / <%= budgetValue %>\)',
103
+ );
88
104
 
89
- const resolveDiffLabel = (budgetInsight: BudgetInsight): string => {
90
- const { currentValue, budgetValue } = budgetInsight;
105
+ const resolveDiffLabel = (metricBudgetInsight: BudgetInsightMetricData): string => {
106
+ const { currentValue, budgetValue } = metricBudgetInsight;
91
107
 
92
108
  if (currentValue > budgetValue) {
93
- return 'over';
109
+ return 'above';
94
110
  }
95
111
 
96
112
  if (currentValue < budgetValue) {
97
- return 'under';
113
+ return 'below';
98
114
  }
99
115
 
100
116
  return 'equal with';
101
117
  };
102
118
 
103
- const resolveType = (budgetInsight: BudgetInsight): InsightType => {
104
- if (budgetInsight.failed) {
119
+ const resolveBudgetInsightMetricType = (metricBudgetInsight: BudgetInsightMetricData): InsightType => {
120
+ if (metricBudgetInsight.failed) {
105
121
  return InsightType.ERROR;
106
122
  }
107
123
 
108
- if (budgetInsight.currentValue === budgetInsight.budgetValue) {
124
+ if (metricBudgetInsight.currentValue === metricBudgetInsight.budgetValue) {
109
125
  return InsightType.WARNING;
110
126
  }
111
127
 
112
128
  return InsightType.SUCCESS;
113
129
  };
114
130
 
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';
131
+ export const getExtract =
132
+ (source: string) => (
133
+ _: unknown,
134
+ currentExtractedData: any,
135
+ __: unknown,
136
+ options: Options = {},
137
+ ): BudgetsInsightsOutput | null => {
138
+ const { budgets: budgetsOptions } = options;
139
+
140
+ if (!budgetsOptions) {
141
+ return null;
142
+ }
118
143
 
119
- export const getInfo = (globalMetricId: string, budgetInsight: BudgetInsight): BudgetInsightInfo => {
120
- const metric = getGlobalMetricType(globalMetricId);
144
+ const insights: Array<[string, BudgetInsightMetric]> = [];
121
145
 
122
- const diffLabel = resolveDiffLabel(budgetInsight);
123
- const type = resolveType(budgetInsight);
124
- const currentValue = metric.formatter(budgetInsight.currentValue);
125
- const budgetValue = metric.formatter(budgetInsight.budgetValue);
146
+ budgetsOptions.forEach((budgetOption) => {
147
+ const { metric: sourceMetricId, value: budgetValue } = budgetOption;
148
+ const currentValue = get(currentExtractedData, `metrics.${sourceMetricId}.value`);
149
+ const metricData = getGlobalMetricType(`${source}.${sourceMetricId}`);
126
150
 
127
- return {
128
- type,
129
- message: {
130
- template: INFO_MESSAGE_TEMPLATE,
131
- data: {
132
- metricLabel: metric.label,
133
- diffLabel,
151
+ if (!currentValue) {
152
+ return;
153
+ }
154
+
155
+ const isValueOverBudget = currentValue > budgetValue;
156
+ const failed = metricData.biggerIsBetter ? !isValueOverBudget : isValueOverBudget;
157
+
158
+ const budgetInsightMetricData = {
134
159
  currentValue,
135
160
  budgetValue,
161
+ failed,
162
+ };
163
+
164
+ // Message template data
165
+ const diffLabel = resolveDiffLabel(budgetInsightMetricData);
166
+ const type = resolveBudgetInsightMetricType(budgetInsightMetricData);
167
+ const currentFormattedValue = metricData.formatter(currentValue);
168
+ const budgetFormattedValue = metricData.formatter(budgetValue);
169
+
170
+ const messageText = budgetInsightMetricTemplate({
171
+ metricLabel: metricData.label,
172
+ currentValue: currentFormattedValue,
173
+ diffLabel,
174
+ budgetValue: budgetFormattedValue,
175
+ });
176
+ const messageMd = budgetInsightMetricTemplate({
177
+ metricLabel: `**${metricData.label}**`,
178
+ currentValue: `**${currentFormattedValue}**`,
179
+ diffLabel,
180
+ budgetValue: `**${budgetFormattedValue}**`,
181
+ });
182
+
183
+ insights.push([
184
+ sourceMetricId,
185
+ {
186
+ type,
187
+ message: {
188
+ text: messageText,
189
+ md: messageMd,
190
+ },
191
+ data: budgetInsightMetricData,
192
+ },
193
+ ]);
194
+ });
195
+
196
+ if (insights.length === 0) {
197
+ return null;
198
+ }
199
+
200
+ const type = resolveType(insights);
201
+ const message = getMessage(insights);
202
+
203
+ return {
204
+ insights: {
205
+ budgets: {
206
+ type,
207
+ message,
208
+ data: Object.fromEntries(insights),
209
+ },
136
210
  },
137
- },
138
- source: {
139
- metricId: globalMetricId,
140
- budgetInsight,
141
- },
211
+ };
142
212
  };
143
- };
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ import * as constants from './constants';
2
+
3
+ /** Insight v2 structure */
4
+ export interface Insight {
5
+ type: constants.InsightType;
6
+ message: {
7
+ /** Insight message text format */
8
+ text: string;
9
+ /** Insight message markdown format */
10
+ md: string;
11
+ };
12
+ /** Insight specific data */
13
+ data: unknown;
14
+ }
@@ -1,17 +1,46 @@
1
- import get from 'lodash/get';
2
1
  import isEmpty from 'lodash/isEmpty';
3
2
 
4
3
  import { getAssetName, normalizeChunkId } from '../utils';
5
4
 
6
5
  const IGNORE_PATTERN = /\.(map|LICENSE\.txt)$/;
7
6
 
8
- export const extractAssets = (webpackStats) => {
9
- const webpackAssets = get(webpackStats, 'assets', []);
10
- const webpackChunks = get(webpackStats, 'chunks', []);
11
- const webpackEntrypoints = get(webpackStats, 'entrypoints', {});
7
+ interface WebpackStatsAsset {
8
+ name: string;
9
+ size: number;
10
+ }
12
11
 
13
- const entryItems = Object.values(webpackEntrypoints)
14
- .map(({ assets: items }) => items)
12
+ interface WebpackStatsEntrypointAsset {
13
+ name: string;
14
+ }
15
+
16
+ interface WebpackStatsEntrypoint {
17
+ // Webpack 5 provides { name, size }
18
+ assets: Array<WebpackStatsEntrypointAsset | string>;
19
+ }
20
+
21
+ type WebpackStatsEntrypoints = Record<string, WebpackStatsEntrypoint>;
22
+
23
+ interface WebpackStatsChunk {
24
+ id: string;
25
+ entry: boolean;
26
+ initial: boolean;
27
+ files: Array<string>;
28
+ names: Array<string>;
29
+ }
30
+
31
+ export const extractAssets = (webpackStats: any) => {
32
+ const webpackAssets: Array<WebpackStatsAsset> = webpackStats?.assets || [];
33
+ const webpackChunks: Array<WebpackStatsChunk> = webpackStats?.chunks || [];
34
+ const webpackEntrypoints: WebpackStatsEntrypoints = webpackStats?.entrypoints || {};
35
+
36
+ const entrypointsAssets = Object.values(webpackEntrypoints)
37
+ .map(({ assets: items }) => items.map((item) => {
38
+ if (typeof item === 'object') {
39
+ return item.name;
40
+ }
41
+
42
+ return item;
43
+ }))
15
44
  .flat();
16
45
 
17
46
  const initialItems = webpackChunks
@@ -43,7 +72,7 @@ export const extractAssets = (webpackStats) => {
43
72
  [normalizedName]: {
44
73
  name: baseName,
45
74
  value: size,
46
- isEntry: entryItems.includes(name),
75
+ isEntry: entrypointsAssets.includes(name),
47
76
  isInitial: initialItems.includes(name),
48
77
  isChunk: Boolean(assetChunk),
49
78
  ...(assetChunk ? { chunkId: assetChunk.id } : {}),
@@ -57,10 +86,10 @@ export const extractAssets = (webpackStats) => {
57
86
  },
58
87
  ...(!isEmpty(normalizedChunks)
59
88
  ? {
60
- meta: {
61
- chunks: normalizedChunks.map(({ id, name }) => ({ id, name })),
62
- },
63
- }
89
+ meta: {
90
+ chunks: normalizedChunks.map(({ id, name }) => ({ id, name })),
91
+ },
92
+ }
64
93
  : {}),
65
94
  };
66
95
  };
@@ -1,3 +1,4 @@
1
+ import * as types from '../types';
1
2
  import { InsightType } from '../constants';
2
3
  interface OptionBudgetMetric {
3
4
  metric: string;
@@ -6,31 +7,28 @@ interface OptionBudgetMetric {
6
7
  interface Options {
7
8
  budgets?: Array<OptionBudgetMetric>;
8
9
  }
9
- interface BudgetInsight {
10
+ interface BudgetInsightMetricData {
10
11
  currentValue: number;
11
12
  budgetValue: number;
12
13
  failed: boolean;
13
14
  }
14
- interface BudgetInsightInfo {
15
+ interface BudgetInsightMetric {
15
16
  type: InsightType;
16
17
  message: {
17
- template: string;
18
- data: Record<string, unknown>;
19
- };
20
- source: {
21
- metricId: string;
22
- budgetInsight: BudgetInsight;
18
+ text: string;
19
+ md: string;
23
20
  };
21
+ data: BudgetInsightMetricData;
24
22
  }
25
- interface BudgetInsights {
26
- [metricId: string]: BudgetInsight;
23
+ interface BudgetInsight extends types.Insight {
24
+ data: {
25
+ [metricId: string]: BudgetInsightMetric;
26
+ };
27
27
  }
28
28
  interface BudgetsInsightsOutput {
29
29
  insights: {
30
- budgets: BudgetInsights;
30
+ budgets: BudgetInsight;
31
31
  };
32
32
  }
33
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
34
  export {};
@@ -0,0 +1,9 @@
1
+ import * as constants from './constants';
2
+ export interface Insight {
3
+ type: constants.InsightType;
4
+ message: {
5
+ text: string;
6
+ md: string;
7
+ };
8
+ data: unknown;
9
+ }
@@ -1,8 +1,11 @@
1
- export function extractAssets(webpackStats: any): {
1
+ export declare const extractAssets: (webpackStats: any) => {
2
2
  meta?: {
3
- chunks: any;
3
+ chunks: {
4
+ id: string;
5
+ name: string;
6
+ }[];
4
7
  } | undefined;
5
8
  metrics: {
6
- assets: any;
9
+ assets: {};
7
10
  };
8
11
  };