@angular-devkit/build-angular 12.1.0-next.3 → 12.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.
Files changed (95) hide show
  1. package/package.json +40 -39
  2. package/src/app-shell/index.js +28 -8
  3. package/src/babel/plugins/adjust-static-class-members.d.ts +25 -0
  4. package/src/babel/plugins/adjust-static-class-members.js +251 -0
  5. package/src/babel/plugins/adjust-typescript-enums.d.ts +21 -0
  6. package/src/babel/plugins/adjust-typescript-enums.js +123 -0
  7. package/src/babel/plugins/elide-angular-metadata.d.ts +21 -0
  8. package/src/babel/plugins/elide-angular-metadata.js +68 -0
  9. package/src/babel/plugins/pure-toplevel-functions.d.ts +14 -0
  10. package/src/babel/plugins/pure-toplevel-functions.js +86 -0
  11. package/src/babel/presets/application.d.ts +1 -0
  12. package/src/babel/presets/application.js +23 -3
  13. package/src/babel/webpack-loader.js +39 -1
  14. package/src/browser/index.d.ts +1 -4
  15. package/src/browser/index.js +26 -36
  16. package/src/browser/schema.d.ts +1 -1
  17. package/src/browser/schema.json +1 -1
  18. package/src/dev-server/index.d.ts +1 -1
  19. package/src/dev-server/index.js +68 -47
  20. package/src/dev-server/tests/execute-fetch.js +4 -1
  21. package/src/extract-i18n/empty-loader.d.ts +8 -0
  22. package/src/extract-i18n/empty-loader.js +13 -0
  23. package/src/extract-i18n/index.d.ts +1 -1
  24. package/src/extract-i18n/index.js +46 -18
  25. package/src/extract-i18n/ivy-extract-loader.js +20 -1
  26. package/src/karma/find-tests.js +20 -1
  27. package/src/karma/index.js +21 -1
  28. package/src/karma/schema.d.ts +1 -1
  29. package/src/karma/schema.json +1 -1
  30. package/src/karma/tests/setup.d.ts +18 -0
  31. package/src/karma/tests/setup.js +29 -0
  32. package/src/ng-packagr/index.js +21 -2
  33. package/src/protractor/index.js +21 -2
  34. package/src/sass/sass-service.d.ts +0 -3
  35. package/src/sass/sass-service.js +8 -9
  36. package/src/sass/worker.js +4 -2
  37. package/src/server/index.d.ts +1 -1
  38. package/src/server/index.js +20 -1
  39. package/src/server/schema.d.ts +1 -1
  40. package/src/server/schema.json +1 -1
  41. package/src/tslint/index.js +22 -3
  42. package/src/typings.d.ts +6 -0
  43. package/src/utils/action-cache.js +21 -2
  44. package/src/utils/action-executor.js +21 -2
  45. package/src/utils/build-browser-features.js +25 -3
  46. package/src/utils/cache-path.js +5 -2
  47. package/src/utils/check-port.js +20 -1
  48. package/src/utils/color.js +20 -1
  49. package/src/utils/copy-assets.js +26 -4
  50. package/src/utils/copy-file.js +20 -1
  51. package/src/utils/delete-output-dir.js +2 -2
  52. package/src/utils/environment-options.d.ts +1 -0
  53. package/src/utils/environment-options.js +26 -2
  54. package/src/utils/find-up.js +20 -1
  55. package/src/utils/i18n-inlining.js +21 -2
  56. package/src/utils/i18n-options.js +23 -5
  57. package/src/utils/index-file/html-rewriting-stream.js +20 -1
  58. package/src/utils/index-file/index-html-generator.js +20 -1
  59. package/src/utils/index-file/inline-critical-css.js +20 -1
  60. package/src/utils/index-file/inline-fonts.js +27 -5
  61. package/src/utils/is-directory.js +20 -1
  62. package/src/utils/load-translations.js +26 -7
  63. package/src/utils/process-bundle.js +34 -12
  64. package/src/utils/read-tsconfig.js +20 -1
  65. package/src/utils/service-worker.js +21 -2
  66. package/src/utils/spinner.d.ts +2 -0
  67. package/src/utils/spinner.js +18 -2
  68. package/src/utils/webpack-browser-config.js +21 -2
  69. package/src/webpack/configs/analytics.d.ts +11 -0
  70. package/src/webpack/configs/analytics.js +29 -0
  71. package/src/webpack/configs/common.js +96 -45
  72. package/src/webpack/configs/dev-server.js +20 -1
  73. package/src/webpack/configs/index.d.ts +1 -0
  74. package/src/webpack/configs/index.js +1 -0
  75. package/src/webpack/configs/server.js +8 -0
  76. package/src/webpack/configs/stats.d.ts +6 -14
  77. package/src/webpack/configs/stats.js +5 -8
  78. package/src/webpack/configs/styles.js +28 -2
  79. package/src/webpack/configs/test.js +32 -3
  80. package/src/webpack/configs/typescript.d.ts +2 -9
  81. package/src/webpack/configs/typescript.js +16 -14
  82. package/src/webpack/plugins/any-component-style-budget-checker.js +20 -1
  83. package/src/webpack/plugins/builder-watch-plugin.d.ts +0 -2
  84. package/src/webpack/plugins/builder-watch-plugin.js +2 -7
  85. package/src/webpack/plugins/index.js +4 -1
  86. package/src/webpack/plugins/karma/karma-context.html +1 -1
  87. package/src/webpack/plugins/karma/karma-debug.html +1 -1
  88. package/src/webpack/plugins/karma/karma.js +27 -5
  89. package/src/webpack/plugins/postcss-cli-resources.js +21 -2
  90. package/src/webpack/plugins/scripts-webpack-plugin.js +20 -1
  91. package/src/webpack/utils/async-chunks.js +9 -5
  92. package/src/webpack/utils/helpers.js +20 -1
  93. package/src/webpack/utils/stats.d.ts +2 -3
  94. package/src/webpack/utils/stats.js +50 -15
  95. package/src/extract-i18n/empty-export-default.js +0 -1
@@ -6,13 +6,37 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
9
31
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.webpackStatsLogger = exports.createWebpackLoggingCallback = exports.statsHasWarnings = exports.statsHasErrors = exports.statsErrorsToString = exports.statsWarningsToString = exports.IGNORE_WARNINGS = exports.generateBundleStats = exports.formatSize = void 0;
32
+ exports.webpackStatsLogger = exports.createWebpackLoggingCallback = exports.statsHasWarnings = exports.statsHasErrors = exports.statsErrorsToString = exports.statsWarningsToString = exports.generateBundleStats = exports.formatSize = void 0;
11
33
  const core_1 = require("@angular-devkit/core");
12
- const path = require("path");
13
- const textTable = require("text-table");
34
+ const path = __importStar(require("path"));
35
+ const text_table_1 = __importDefault(require("text-table"));
14
36
  const color_1 = require("../../utils/color");
15
37
  const stats_1 = require("../configs/stats");
38
+ const async_chunks_1 = require("./async-chunks");
39
+ const helpers_1 = require("./helpers");
16
40
  function formatSize(size) {
17
41
  if (size <= 0) {
18
42
  return '0 bytes';
@@ -30,7 +54,7 @@ function generateBundleStats(info) {
30
54
  const size = typeof info.size === 'number' ? info.size : '-';
31
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 : '';
32
56
  const names = ((_c = info.names) === null || _c === void 0 ? void 0 : _c.length) ? info.names.join(', ') : '-';
33
- const initial = !!(info.entry || info.initial);
57
+ const initial = !!info.initial;
34
58
  const chunkType = info.chunkType || 'unknown';
35
59
  return {
36
60
  chunkType,
@@ -103,7 +127,7 @@ function generateBuildStatsTable(data, colors, showTotalSize) {
103
127
  if (changedLazyChunksStats.length) {
104
128
  bundleInfo.push(['Lazy Chunk Files', 'Names', 'Size'].map(bold), ...changedLazyChunksStats);
105
129
  }
106
- return textTable(bundleInfo, {
130
+ return text_table_1.default(bundleInfo, {
107
131
  hsep: dim(' | '),
108
132
  stringLength: (s) => color_1.removeColor(s).length,
109
133
  align: ['l', 'l', 'r'],
@@ -113,6 +137,10 @@ function generateBuildStats(hash, time, colors) {
113
137
  const w = (x) => (colors ? color_1.colors.bold.white(x) : x);
114
138
  return `Build at: ${w(new Date().toISOString())} - Hash: ${w(hash)} - Time: ${w('' + time)}ms`;
115
139
  }
140
+ // We use this cache because we can have multiple builders running in the same process,
141
+ // where each builder has different output path.
142
+ // Ideally, we should create the logging callback as a factory, but that would need a refactoring.
143
+ const runsCache = new Set();
116
144
  function statsToString(json,
117
145
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
146
  statsConfig, bundleState) {
@@ -125,8 +153,11 @@ statsConfig, bundleState) {
125
153
  const changedChunksStats = bundleState !== null && bundleState !== void 0 ? bundleState : [];
126
154
  let unchangedChunkNumber = 0;
127
155
  if (!(bundleState === null || bundleState === void 0 ? void 0 : bundleState.length)) {
156
+ const isFirstRun = !runsCache.has(json.outputPath || '');
128
157
  for (const chunk of json.chunks) {
129
- if (!chunk.rendered) {
158
+ // During first build we want to display unchanged chunks
159
+ // but unchanged cached chunks are always marked as not rendered.
160
+ if (!isFirstRun && !chunk.rendered) {
130
161
  continue;
131
162
  }
132
163
  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); });
@@ -134,6 +165,7 @@ statsConfig, bundleState) {
134
165
  changedChunksStats.push(generateBundleStats({ ...chunk, size: summedSize }));
135
166
  }
136
167
  unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
168
+ runsCache.add(json.outputPath || '');
137
169
  }
138
170
  // Sort chunks by size in descending order
139
171
  changedChunksStats.sort((a, b) => {
@@ -172,13 +204,6 @@ statsConfig, bundleState) {
172
204
  `));
173
205
  }
174
206
  }
175
- exports.IGNORE_WARNINGS = [
176
- // Webpack 5+ has no facility to disable this warning.
177
- // System.import is used in @angular/core for deprecated string-form lazy routes
178
- /System.import\(\) is deprecated and will be removed soon/i,
179
- // https://github.com/webpack-contrib/source-map-loader/blob/b2de4249c7431dd8432da607e08f0f65e9d64219/src/index.js#L83
180
- /Failed to parse source map from/,
181
- ];
182
207
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
208
  function statsWarningsToString(json, statsConfig) {
184
209
  const colors = statsConfig.colors;
@@ -255,12 +280,22 @@ function statsHasWarnings(json) {
255
280
  return !!(((_a = json.warnings) === null || _a === void 0 ? void 0 : _a.length) || ((_b = json.children) === null || _b === void 0 ? void 0 : _b.some((c) => { var _a; return (_a = c.warnings) === null || _a === void 0 ? void 0 : _a.length; })));
256
281
  }
257
282
  exports.statsHasWarnings = statsHasWarnings;
258
- function createWebpackLoggingCallback(verbose, logger) {
283
+ function createWebpackLoggingCallback(options, logger) {
284
+ const { verbose = false, scripts = [], styles = [] } = options;
285
+ const extraEntryPoints = [
286
+ ...helpers_1.normalizeExtraEntryPoints(styles, 'styles'),
287
+ ...helpers_1.normalizeExtraEntryPoints(scripts, 'scripts'),
288
+ ];
259
289
  return (stats, config) => {
260
290
  if (verbose) {
261
291
  logger.info(stats.toString(config.stats));
262
292
  }
263
- webpackStatsLogger(logger, stats.toJson(stats_1.getWebpackStatsConfig(false)), config);
293
+ const rawStats = stats.toJson(stats_1.getWebpackStatsConfig(false));
294
+ const webpackStats = {
295
+ ...rawStats,
296
+ chunks: async_chunks_1.markAsyncChunksNonInitial(rawStats, extraEntryPoints),
297
+ };
298
+ webpackStatsLogger(logger, webpackStats, config);
264
299
  };
265
300
  }
266
301
  exports.createWebpackLoggingCallback = createWebpackLoggingCallback;
@@ -1 +0,0 @@
1
- export default '';