@angular-devkit/build-angular 13.1.0-next.1 → 13.1.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.
@@ -50,35 +50,81 @@ function formatSize(size) {
50
50
  exports.formatSize = formatSize;
51
51
  function generateBundleStats(info) {
52
52
  var _a, _b, _c;
53
- const size = typeof info.size === 'number' ? info.size : '-';
53
+ const rawSize = typeof info.rawSize === 'number' ? info.rawSize : '-';
54
+ const estimatedTransferSize = typeof info.estimatedTransferSize === 'number' ? info.estimatedTransferSize : '-';
54
55
  const files = (_b = (_a = info.files) === null || _a === void 0 ? void 0 : _a.filter((f) => !f.endsWith('.map')).map((f) => path.basename(f)).join(', ')) !== null && _b !== void 0 ? _b : '';
55
56
  const names = ((_c = info.names) === null || _c === void 0 ? void 0 : _c.length) ? info.names.join(', ') : '-';
56
57
  const initial = !!info.initial;
57
58
  return {
58
59
  initial,
59
- stats: [files, names, size],
60
+ stats: [files, names, rawSize, estimatedTransferSize],
60
61
  };
61
62
  }
62
63
  exports.generateBundleStats = generateBundleStats;
63
- function generateBuildStatsTable(data, colors, showTotalSize) {
64
+ function generateBuildStatsTable(data, colors, showTotalSize, showEstimatedTransferSize, budgetFailures) {
64
65
  const g = (x) => (colors ? color_1.colors.greenBright(x) : x);
65
66
  const c = (x) => (colors ? color_1.colors.cyanBright(x) : x);
67
+ const r = (x) => (colors ? color_1.colors.redBright(x) : x);
68
+ const y = (x) => (colors ? color_1.colors.yellowBright(x) : x);
66
69
  const bold = (x) => (colors ? color_1.colors.bold(x) : x);
67
70
  const dim = (x) => (colors ? color_1.colors.dim(x) : x);
71
+ const getSizeColor = (name, file, defaultColor = c) => {
72
+ const severity = budgets.get(name) || (file && budgets.get(file));
73
+ switch (severity) {
74
+ case 'warning':
75
+ return y;
76
+ case 'error':
77
+ return r;
78
+ default:
79
+ return defaultColor;
80
+ }
81
+ };
68
82
  const changedEntryChunksStats = [];
69
83
  const changedLazyChunksStats = [];
70
- let initialTotalSize = 0;
84
+ let initialTotalRawSize = 0;
85
+ let initialTotalEstimatedTransferSize;
86
+ const budgets = new Map();
87
+ if (budgetFailures) {
88
+ for (const { label, severity } of budgetFailures) {
89
+ // In some cases a file can have multiple budget failures.
90
+ // Favor error.
91
+ if (label && (!budgets.has(label) || budgets.get(label) === 'warning')) {
92
+ budgets.set(label, severity);
93
+ }
94
+ }
95
+ }
71
96
  for (const { initial, stats } of data) {
72
- const [files, names, size] = stats;
73
- const data = [
74
- g(files),
75
- names,
76
- c(typeof size === 'number' ? formatSize(size) : size),
77
- ];
97
+ const [files, names, rawSize, estimatedTransferSize] = stats;
98
+ const getRawSizeColor = getSizeColor(names, files);
99
+ let data;
100
+ if (showEstimatedTransferSize) {
101
+ data = [
102
+ g(files),
103
+ names,
104
+ getRawSizeColor(typeof rawSize === 'number' ? formatSize(rawSize) : rawSize),
105
+ c(typeof estimatedTransferSize === 'number'
106
+ ? formatSize(estimatedTransferSize)
107
+ : estimatedTransferSize),
108
+ ];
109
+ }
110
+ else {
111
+ data = [
112
+ g(files),
113
+ names,
114
+ getRawSizeColor(typeof rawSize === 'number' ? formatSize(rawSize) : rawSize),
115
+ '',
116
+ ];
117
+ }
78
118
  if (initial) {
79
119
  changedEntryChunksStats.push(data);
80
- if (typeof size === 'number') {
81
- initialTotalSize += size;
120
+ if (typeof rawSize === 'number') {
121
+ initialTotalRawSize += rawSize;
122
+ }
123
+ if (showEstimatedTransferSize && typeof estimatedTransferSize === 'number') {
124
+ if (initialTotalEstimatedTransferSize === undefined) {
125
+ initialTotalEstimatedTransferSize = 0;
126
+ }
127
+ initialTotalEstimatedTransferSize += estimatedTransferSize;
82
128
  }
83
129
  }
84
130
  else {
@@ -86,12 +132,29 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
86
132
  }
87
133
  }
88
134
  const bundleInfo = [];
135
+ const baseTitles = ['Names', 'Raw Size'];
136
+ const tableAlign = ['l', 'l', 'r'];
137
+ if (showEstimatedTransferSize) {
138
+ baseTitles.push('Estimated Transfer Size');
139
+ tableAlign.push('r');
140
+ }
89
141
  // Entry chunks
90
142
  if (changedEntryChunksStats.length) {
91
- bundleInfo.push(['Initial Chunk Files', 'Names', 'Size'].map(bold), ...changedEntryChunksStats);
143
+ bundleInfo.push(['Initial Chunk Files', ...baseTitles].map(bold), ...changedEntryChunksStats);
92
144
  if (showTotalSize) {
93
145
  bundleInfo.push([]);
94
- bundleInfo.push([' ', 'Initial Total', formatSize(initialTotalSize)].map(bold));
146
+ const initialSizeTotalColor = getSizeColor('bundle initial', undefined, (x) => x);
147
+ const totalSizeElements = [
148
+ ' ',
149
+ 'Initial Total',
150
+ initialSizeTotalColor(formatSize(initialTotalRawSize)),
151
+ ];
152
+ if (showEstimatedTransferSize) {
153
+ totalSizeElements.push(typeof initialTotalEstimatedTransferSize === 'number'
154
+ ? formatSize(initialTotalEstimatedTransferSize)
155
+ : '-');
156
+ }
157
+ bundleInfo.push(totalSizeElements.map(bold));
95
158
  }
96
159
  }
97
160
  // Seperator
@@ -100,12 +163,12 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
100
163
  }
101
164
  // Lazy chunks
102
165
  if (changedLazyChunksStats.length) {
103
- bundleInfo.push(['Lazy Chunk Files', 'Names', 'Size'].map(bold), ...changedLazyChunksStats);
166
+ bundleInfo.push(['Lazy Chunk Files', ...baseTitles].map(bold), ...changedLazyChunksStats);
104
167
  }
105
168
  return (0, text_table_1.default)(bundleInfo, {
106
169
  hsep: dim(' | '),
107
170
  stringLength: (s) => (0, color_1.removeColor)(s).length,
108
- align: ['l', 'l', 'r'],
171
+ align: tableAlign,
109
172
  });
110
173
  }
111
174
  function generateBuildStats(hash, time, colors) {
@@ -118,30 +181,45 @@ function generateBuildStats(hash, time, colors) {
118
181
  const runsCache = new Set();
119
182
  function statsToString(json,
120
183
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
- statsConfig, bundleState) {
184
+ statsConfig, budgetFailures) {
122
185
  var _a, _b;
123
186
  if (!((_a = json.chunks) === null || _a === void 0 ? void 0 : _a.length)) {
124
187
  return '';
125
188
  }
126
189
  const colors = statsConfig.colors;
127
190
  const rs = (x) => (colors ? color_1.colors.reset(x) : x);
128
- const changedChunksStats = bundleState !== null && bundleState !== void 0 ? bundleState : [];
191
+ const changedChunksStats = [];
129
192
  let unchangedChunkNumber = 0;
130
- if (!(bundleState === null || bundleState === void 0 ? void 0 : bundleState.length)) {
131
- const isFirstRun = !runsCache.has(json.outputPath || '');
132
- for (const chunk of json.chunks) {
133
- // During first build we want to display unchanged chunks
134
- // but unchanged cached chunks are always marked as not rendered.
135
- if (!isFirstRun && !chunk.rendered) {
136
- continue;
193
+ let hasEstimatedTransferSizes = false;
194
+ const isFirstRun = !runsCache.has(json.outputPath || '');
195
+ for (const chunk of json.chunks) {
196
+ // During first build we want to display unchanged chunks
197
+ // but unchanged cached chunks are always marked as not rendered.
198
+ if (!isFirstRun && !chunk.rendered) {
199
+ continue;
200
+ }
201
+ const assets = (_b = json.assets) === null || _b === void 0 ? void 0 : _b.filter((asset) => { var _a; return (_a = chunk.files) === null || _a === void 0 ? void 0 : _a.includes(asset.name); });
202
+ let rawSize = 0;
203
+ let estimatedTransferSize;
204
+ if (assets) {
205
+ for (const asset of assets) {
206
+ if (asset.name.endsWith('.map')) {
207
+ continue;
208
+ }
209
+ rawSize += asset.size;
210
+ if (typeof asset.info.estimatedTransferSize === 'number') {
211
+ if (estimatedTransferSize === undefined) {
212
+ estimatedTransferSize = 0;
213
+ hasEstimatedTransferSizes = true;
214
+ }
215
+ estimatedTransferSize += asset.info.estimatedTransferSize;
216
+ }
137
217
  }
138
- const assets = (_b = json.assets) === null || _b === void 0 ? void 0 : _b.filter((asset) => { var _a; return (_a = chunk.files) === null || _a === void 0 ? void 0 : _a.includes(asset.name); });
139
- const summedSize = assets === null || assets === void 0 ? void 0 : assets.filter((asset) => !asset.name.endsWith('.map')).reduce((total, asset) => total + asset.size, 0);
140
- changedChunksStats.push(generateBundleStats({ ...chunk, size: summedSize }));
141
218
  }
142
- unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
143
- runsCache.add(json.outputPath || '');
219
+ changedChunksStats.push(generateBundleStats({ ...chunk, rawSize, estimatedTransferSize }));
144
220
  }
221
+ unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
222
+ runsCache.add(json.outputPath || '');
145
223
  // Sort chunks by size in descending order
146
224
  changedChunksStats.sort((a, b) => {
147
225
  if (a.stats[2] > b.stats[2]) {
@@ -152,7 +230,7 @@ statsConfig, bundleState) {
152
230
  }
153
231
  return 0;
154
232
  });
155
- const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0);
233
+ const statsTable = generateBuildStatsTable(changedChunksStats, colors, unchangedChunkNumber === 0, hasEstimatedTransferSizes, budgetFailures);
156
234
  // In some cases we do things outside of webpack context
157
235
  // Such us index generation, service worker augmentation etc...
158
236
  // This will correct the time and include these.
@@ -274,8 +352,8 @@ function createWebpackLoggingCallback(options, logger) {
274
352
  };
275
353
  }
276
354
  exports.createWebpackLoggingCallback = createWebpackLoggingCallback;
277
- function webpackStatsLogger(logger, json, config, bundleStats) {
278
- logger.info(statsToString(json, config.stats, bundleStats));
355
+ function webpackStatsLogger(logger, json, config, budgetFailures) {
356
+ logger.info(statsToString(json, config.stats, budgetFailures));
279
357
  if (statsHasWarnings(json)) {
280
358
  logger.warn(statsWarningsToString(json, config.stats));
281
359
  }