@angular-devkit/build-angular 13.1.0 → 13.1.4

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.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "13.1.0",
3
+ "version": "13.1.4",
4
4
  "description": "Angular Webpack Build Facade",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
7
7
  "builders": "builders.json",
8
8
  "dependencies": {
9
9
  "@ampproject/remapping": "1.0.2",
10
- "@angular-devkit/architect": "0.1301.0",
11
- "@angular-devkit/build-webpack": "0.1301.0",
12
- "@angular-devkit/core": "13.1.0",
10
+ "@angular-devkit/architect": "0.1301.4",
11
+ "@angular-devkit/build-webpack": "0.1301.4",
12
+ "@angular-devkit/core": "13.1.4",
13
13
  "@babel/core": "7.16.0",
14
14
  "@babel/generator": "7.16.0",
15
15
  "@babel/helper-annotate-as-pure": "7.16.0",
@@ -20,7 +20,7 @@
20
20
  "@babel/runtime": "7.16.3",
21
21
  "@babel/template": "7.16.0",
22
22
  "@discoveryjs/json-ext": "0.5.6",
23
- "@ngtools/webpack": "13.1.0",
23
+ "@ngtools/webpack": "13.1.4",
24
24
  "ansi-colors": "4.1.1",
25
25
  "babel-loader": "8.2.3",
26
26
  "babel-plugin-istanbul": "6.1.1",
@@ -29,9 +29,9 @@
29
29
  "circular-dependency-plugin": "5.2.2",
30
30
  "copy-webpack-plugin": "10.0.0",
31
31
  "core-js": "3.19.3",
32
- "critters": "0.0.15",
32
+ "critters": "0.0.16",
33
33
  "css-loader": "6.5.1",
34
- "esbuild-wasm": "0.14.2",
34
+ "esbuild-wasm": "0.14.11",
35
35
  "glob": "7.2.0",
36
36
  "https-proxy-agent": "5.0.0",
37
37
  "inquirer": "8.2.0",
@@ -50,7 +50,7 @@
50
50
  "postcss": "8.4.4",
51
51
  "postcss-import": "14.0.2",
52
52
  "postcss-loader": "6.2.1",
53
- "postcss-preset-env": "6.7.0",
53
+ "postcss-preset-env": "7.2.3",
54
54
  "regenerator-runtime": "0.13.9",
55
55
  "resolve-url-loader": "4.0.0",
56
56
  "rxjs": "6.6.7",
@@ -72,7 +72,7 @@
72
72
  "webpack-subresource-integrity": "5.0.0"
73
73
  },
74
74
  "optionalDependencies": {
75
- "esbuild": "0.14.2"
75
+ "esbuild": "0.14.11"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "@angular/compiler-cli": "^13.0.0 || ^13.1.0-next",
@@ -81,7 +81,7 @@
81
81
  "karma": "^6.3.0",
82
82
  "ng-packagr": "^13.0.0 || ^13.1.0-next",
83
83
  "protractor": "^7.0.0",
84
- "tailwindcss": "^2.0.0",
84
+ "tailwindcss": "^2.0.0 || ^3.0.0",
85
85
  "typescript": ">=4.4.3 <4.6"
86
86
  },
87
87
  "peerDependenciesMeta": {
@@ -14,6 +14,7 @@ const remapping_1 = __importDefault(require("@ampproject/remapping"));
14
14
  const babel_loader_1 = require("babel-loader");
15
15
  const typescript_1 = require("typescript");
16
16
  const load_esm_1 = require("../utils/load-esm");
17
+ const package_version_1 = require("../utils/package-version");
17
18
  /**
18
19
  * Cached instance of the compiler-cli linker's needsLinking function.
19
20
  */
@@ -151,7 +152,7 @@ exports.default = (0, babel_loader_1.custom)(() => {
151
152
  ...baseOptions,
152
153
  ...rawOptions,
153
154
  cacheIdentifier: JSON.stringify({
154
- buildAngular: require('../../package.json').version,
155
+ buildAngular: package_version_1.VERSION,
155
156
  customOptions,
156
157
  baseOptions,
157
158
  rawOptions,
@@ -24,6 +24,11 @@ export declare type BrowserBuilderOutput = json.JsonObject & BuilderOutput & {
24
24
  */
25
25
  outputPath: string;
26
26
  };
27
+ /**
28
+ * Maximum time in milliseconds for single build/rebuild
29
+ * This accounts for CI variability.
30
+ */
31
+ export declare const BUILD_TIMEOUT = 30000;
27
32
  /**
28
33
  * @experimental Direct usage of this function is considered experimental.
29
34
  */
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.buildWebpackBrowser = void 0;
29
+ exports.buildWebpackBrowser = exports.BUILD_TIMEOUT = void 0;
30
30
  const architect_1 = require("@angular-devkit/architect");
31
31
  const build_webpack_1 = require("@angular-devkit/build-webpack");
32
32
  const core_1 = require("@angular-devkit/core");
@@ -44,6 +44,7 @@ const index_html_generator_1 = require("../../utils/index-file/index-html-genera
44
44
  const normalize_cache_1 = require("../../utils/normalize-cache");
45
45
  const output_paths_1 = require("../../utils/output-paths");
46
46
  const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
47
+ const purge_cache_1 = require("../../utils/purge-cache");
47
48
  const service_worker_1 = require("../../utils/service-worker");
48
49
  const spinner_1 = require("../../utils/spinner");
49
50
  const supported_browsers_1 = require("../../utils/supported-browsers");
@@ -53,6 +54,11 @@ const configs_1 = require("../../webpack/configs");
53
54
  const async_chunks_1 = require("../../webpack/utils/async-chunks");
54
55
  const helpers_1 = require("../../webpack/utils/helpers");
55
56
  const stats_1 = require("../../webpack/utils/stats");
57
+ /**
58
+ * Maximum time in milliseconds for single build/rebuild
59
+ * This accounts for CI variability.
60
+ */
61
+ exports.BUILD_TIMEOUT = 30000;
56
62
  async function initialize(options, context, webpackConfigurationTransform) {
57
63
  var _a, _b;
58
64
  const originalOutputPath = options.outputPath;
@@ -98,6 +104,8 @@ function buildWebpackBrowser(options, context, transforms = {}) {
98
104
  return (0, rxjs_1.from)(context.getProjectMetadata(projectName)).pipe((0, operators_1.switchMap)(async (projectMetadata) => {
99
105
  var _a;
100
106
  const sysProjectRoot = (0, core_1.getSystemPath)((0, core_1.resolve)((0, core_1.normalize)(context.workspaceRoot), (0, core_1.normalize)((_a = projectMetadata.root) !== null && _a !== void 0 ? _a : '')));
107
+ // Purge old build disk cache.
108
+ await (0, purge_cache_1.purgeStaleBuildCache)(context);
101
109
  checkInternetExplorerSupport(sysProjectRoot, context.logger);
102
110
  return {
103
111
  ...(await initialize(options, context, transforms.webpackConfiguration)),
@@ -41,6 +41,7 @@ const i18n_options_1 = require("../../utils/i18n-options");
41
41
  const load_translations_1 = require("../../utils/load-translations");
42
42
  const normalize_cache_1 = require("../../utils/normalize-cache");
43
43
  const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
44
+ const purge_cache_1 = require("../../utils/purge-cache");
44
45
  const version_1 = require("../../utils/version");
45
46
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
46
47
  const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
@@ -69,6 +70,8 @@ function serveWebpackBrowser(options, context, transforms = {}) {
69
70
  if (!projectName) {
70
71
  throw new Error('The builder requires a target.');
71
72
  }
73
+ // Purge old build disk cache.
74
+ await (0, purge_cache_1.purgeStaleBuildCache)(context);
72
75
  options.port = await (0, check_port_1.checkPort)((_b = options.port) !== null && _b !== void 0 ? _b : 4200, options.host || 'localhost');
73
76
  if (options.hmr) {
74
77
  logger.warn(core_1.tags.stripIndents `NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.
@@ -286,6 +289,7 @@ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheO
286
289
  webpackConfig.plugins.push({
287
290
  apply: (compiler) => {
288
291
  compiler.hooks.thisCompilation.tap('build-angular', (compilation) => {
292
+ var _a;
289
293
  if (i18n.shouldInline && i18nLoaderOptions.translation === undefined) {
290
294
  // Reload translations
291
295
  (0, i18n_options_1.loadTranslations)(locale, localeDescription, context.workspaceRoot, loader, {
@@ -296,7 +300,7 @@ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheO
296
300
  (0, webpack_diagnostics_1.addError)(compilation, message);
297
301
  },
298
302
  });
299
- i18nLoaderOptions.translation = localeDescription.translation;
303
+ i18nLoaderOptions.translation = (_a = localeDescription.translation) !== null && _a !== void 0 ? _a : {};
300
304
  }
301
305
  compilation.hooks.finishModules.tap('build-angular', () => {
302
306
  // After loaders are finished, clear out the now unneeded translations
@@ -37,6 +37,7 @@ const path = __importStar(require("path"));
37
37
  const webpack_1 = __importDefault(require("webpack"));
38
38
  const i18n_options_1 = require("../../utils/i18n-options");
39
39
  const load_esm_1 = require("../../utils/load-esm");
40
+ const purge_cache_1 = require("../../utils/purge-cache");
40
41
  const version_1 = require("../../utils/version");
41
42
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
42
43
  const configs_1 = require("../../webpack/configs");
@@ -119,6 +120,8 @@ async function execute(options, context, transforms) {
119
120
  var _a;
120
121
  // Check Angular version.
121
122
  (0, version_1.assertCompatibleAngularVersion)(context.workspaceRoot);
123
+ // Purge old build disk cache.
124
+ await (0, purge_cache_1.purgeStaleBuildCache)(context);
122
125
  const browserTarget = (0, architect_1.targetFromTargetString)(options.browserTarget);
123
126
  const browserOptions = await context.validateOptions(await context.getTargetOptions(browserTarget), await context.getBuilderNameForTarget(browserTarget));
124
127
  const format = normalizeFormatOption(options);
@@ -32,6 +32,7 @@ const core_1 = require("@angular-devkit/core");
32
32
  const path_1 = require("path");
33
33
  const rxjs_1 = require("rxjs");
34
34
  const operators_1 = require("rxjs/operators");
35
+ const purge_cache_1 = require("../../utils/purge-cache");
35
36
  const version_1 = require("../../utils/version");
36
37
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
37
38
  const configs_1 = require("../../webpack/configs");
@@ -39,6 +40,8 @@ const single_test_transform_1 = require("../../webpack/plugins/single-test-trans
39
40
  const schema_1 = require("../browser/schema");
40
41
  const find_tests_1 = require("./find-tests");
41
42
  async function initialize(options, context, webpackConfigurationTransformer) {
43
+ // Purge old build disk cache.
44
+ await (0, purge_cache_1.purgeStaleBuildCache)(context);
42
45
  const { config } = await (0, webpack_browser_config_1.generateBrowserWebpackConfigFromContext)(
43
46
  // only two properties are missing:
44
47
  // * `outputPath` which is fixed for tests
@@ -32,12 +32,15 @@ const path_1 = require("path");
32
32
  const rxjs_1 = require("rxjs");
33
33
  const operators_1 = require("rxjs/operators");
34
34
  const normalize_cache_1 = require("../../utils/normalize-cache");
35
+ const purge_cache_1 = require("../../utils/purge-cache");
35
36
  /**
36
37
  * @experimental Direct usage of this function is considered experimental.
37
38
  */
38
39
  function execute(options, context) {
39
40
  return (0, rxjs_1.from)((async () => {
40
41
  var _a;
42
+ // Purge old build disk cache.
43
+ await (0, purge_cache_1.purgeStaleBuildCache)(context);
41
44
  const root = context.workspaceRoot;
42
45
  const packager = (await Promise.resolve().then(() => __importStar(require('ng-packagr')))).ngPackagr();
43
46
  packager.forProject((0, path_1.resolve)(root, options.project));
@@ -37,6 +37,7 @@ const typescript_1 = require("typescript");
37
37
  const utils_1 = require("../../utils");
38
38
  const i18n_inlining_1 = require("../../utils/i18n-inlining");
39
39
  const output_paths_1 = require("../../utils/output-paths");
40
+ const purge_cache_1 = require("../../utils/purge-cache");
40
41
  const version_1 = require("../../utils/version");
41
42
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
42
43
  const configs_1 = require("../../webpack/configs");
@@ -103,6 +104,8 @@ function execute(options, context, transforms = {}) {
103
104
  exports.execute = execute;
104
105
  exports.default = (0, architect_1.createBuilder)(execute);
105
106
  async function initialize(options, context, webpackConfigurationTransform) {
107
+ // Purge old build disk cache.
108
+ await (0, purge_cache_1.purgeStaleBuildCache)(context);
106
109
  const originalOutputPath = options.outputPath;
107
110
  const { config, i18n, target } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)({
108
111
  ...options,
@@ -51,24 +51,10 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
51
51
  setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
52
52
  };
53
53
  originalFiles.push(originalPath);
54
- // Remove temporary original file as the content has now been read
55
- try {
56
- fs.unlinkSync(originalPath);
57
- }
58
- catch (e) {
59
- context.logger.debug(`Unable to delete i18n temporary file [${originalPath}]: ${e.toString()}`);
60
- }
61
54
  try {
62
55
  const originalMapPath = originalPath + '.map';
63
56
  action.map = fs.readFileSync(originalMapPath, 'utf8');
64
57
  originalFiles.push(originalMapPath);
65
- // Remove temporary original map file as the content has now been read
66
- try {
67
- fs.unlinkSync(originalMapPath);
68
- }
69
- catch (e) {
70
- context.logger.debug(`Unable to delete i18n temporary file [${originalMapPath}]: ${e.toString()}`);
71
- }
72
58
  }
73
59
  catch (err) {
74
60
  if (err.code !== 'ENOENT') {
@@ -176,12 +176,11 @@ async function configureI18nBuild(context, options) {
176
176
  if (i18n.shouldInline) {
177
177
  const tempPath = fs_1.default.mkdtempSync(path_1.default.join(fs_1.default.realpathSync(os_1.default.tmpdir()), 'angular-cli-i18n-'));
178
178
  buildOptions.outputPath = tempPath;
179
- // Remove temporary directory used for i18n processing
180
- process.on('exit', () => {
181
- try {
182
- fs_1.default.rmdirSync(tempPath, { recursive: true, maxRetries: 3 });
183
- }
184
- catch { }
179
+ process.on('exit', () => deleteTempDirectory(tempPath));
180
+ process.once('SIGINT', () => {
181
+ deleteTempDirectory(tempPath);
182
+ // Needed due to `ora` as otherwise process will not terminate.
183
+ process.kill(process.pid, 'SIGINT');
185
184
  });
186
185
  }
187
186
  return { buildOptions, i18n };
@@ -201,7 +200,22 @@ function findLocaleDataPath(locale, resolver) {
201
200
  return null;
202
201
  }
203
202
  }
203
+ /** Remove temporary directory used for i18n processing. */
204
+ function deleteTempDirectory(tempPath) {
205
+ // The below should be removed and replaced with just `rmSync` when support for Node.Js 12 is removed.
206
+ const { rmSync, rmdirSync } = fs_1.default;
207
+ try {
208
+ if (rmSync) {
209
+ rmSync(tempPath, { force: true, recursive: true, maxRetries: 3 });
210
+ }
211
+ else {
212
+ rmdirSync(tempPath, { recursive: true, maxRetries: 3 });
213
+ }
214
+ }
215
+ catch { }
216
+ }
204
217
  function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats) {
218
+ let translations = undefined;
205
219
  for (const file of desc.files) {
206
220
  const loadResult = loader(path_1.default.join(workspaceRoot, file.path));
207
221
  for (const diagnostics of loadResult.diagnostics.messages) {
@@ -218,19 +232,20 @@ function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedForma
218
232
  usedFormats === null || usedFormats === void 0 ? void 0 : usedFormats.add(loadResult.format);
219
233
  file.format = loadResult.format;
220
234
  file.integrity = loadResult.integrity;
221
- if (desc.translation) {
235
+ if (translations) {
222
236
  // Merge translations
223
237
  for (const [id, message] of Object.entries(loadResult.translations)) {
224
- if (desc.translation[id] !== undefined) {
238
+ if (translations[id] !== undefined) {
225
239
  logger.warn(`WARNING [${file.path}]: Duplicate translations for message '${id}' when merging`);
226
240
  }
227
- desc.translation[id] = message;
241
+ translations[id] = message;
228
242
  }
229
243
  }
230
244
  else {
231
245
  // First or only translation file
232
- desc.translation = loadResult.translations;
246
+ translations = loadResult.translations;
233
247
  }
234
248
  }
249
+ desc.translation = translations;
235
250
  }
236
251
  exports.loadTranslations = loadTranslations;
@@ -36,8 +36,8 @@ const https = __importStar(require("https"));
36
36
  const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
37
37
  const path_1 = require("path");
38
38
  const url_1 = require("url");
39
+ const package_version_1 = require("../package-version");
39
40
  const html_rewriting_stream_1 = require("./html-rewriting-stream");
40
- const packageVersion = require('../../../package.json').version;
41
41
  const SUPPORTED_PROVIDERS = {
42
42
  'fonts.googleapis.com': {
43
43
  preconnectUrl: 'https://fonts.gstatic.com',
@@ -146,7 +146,7 @@ class InlineFontsProcessor {
146
146
  }
147
147
  async getResponse(url) {
148
148
  var _a;
149
- const key = `${packageVersion}|${url}`;
149
+ const key = `${package_version_1.VERSION}|${url}`;
150
150
  if (this.cachePath) {
151
151
  const entry = await cacache.get.info(this.cachePath, key);
152
152
  if (entry) {
@@ -7,7 +7,11 @@
7
7
  */
8
8
  import { json } from '@angular-devkit/core';
9
9
  export interface NormalizedCachedOptions {
10
+ /** Whether disk cache is enabled. */
10
11
  enabled: boolean;
12
+ /** Disk cache path. Example: `/.angular/cache/v12.0.0`. */
11
13
  path: string;
14
+ /** Disk cache base path. Example: `/.angular/cache`. */
15
+ basePath: string;
12
16
  }
13
17
  export declare function normalizeCacheOptions(metadata: json.JsonObject, worspaceRoot: string): NormalizedCachedOptions;
@@ -11,6 +11,7 @@ exports.normalizeCacheOptions = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
12
  const path_1 = require("path");
13
13
  const environment_options_1 = require("./environment-options");
14
+ const package_version_1 = require("./package-version");
14
15
  function normalizeCacheOptions(metadata, worspaceRoot) {
15
16
  var _a;
16
17
  const cacheMetadata = core_1.json.isJsonObject(metadata.cli) && core_1.json.isJsonObject(metadata.cli.cache)
@@ -32,9 +33,11 @@ function normalizeCacheOptions(metadata, worspaceRoot) {
32
33
  break;
33
34
  }
34
35
  }
36
+ const cacheBasePath = (0, path_1.resolve)(worspaceRoot, path);
35
37
  return {
36
38
  enabled: cacheEnabled,
37
- path: (0, path_1.resolve)(worspaceRoot, path),
39
+ basePath: cacheBasePath,
40
+ path: (0, path_1.join)(cacheBasePath, package_version_1.VERSION),
38
41
  };
39
42
  }
40
43
  exports.normalizeCacheOptions = normalizeCacheOptions;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export declare const VERSION: string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.VERSION = void 0;
11
+ exports.VERSION = require('../../package.json').version;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { BuilderContext } from '@angular-devkit/architect';
9
+ /** Delete stale cache directories used by previous versions of build-angular. */
10
+ export declare function purgeStaleBuildCache(context: BuilderContext): Promise<void>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.purgeStaleBuildCache = void 0;
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ const normalize_cache_1 = require("./normalize-cache");
14
+ /** Delete stale cache directories used by previous versions of build-angular. */
15
+ async function purgeStaleBuildCache(context) {
16
+ var _a;
17
+ const projectName = (_a = context.target) === null || _a === void 0 ? void 0 : _a.project;
18
+ if (!projectName) {
19
+ return;
20
+ }
21
+ const metadata = await context.getProjectMetadata(projectName);
22
+ const { basePath, path, enabled } = (0, normalize_cache_1.normalizeCacheOptions)(metadata, context.workspaceRoot);
23
+ if (!enabled || !(0, fs_1.existsSync)(basePath)) {
24
+ return;
25
+ }
26
+ // The below should be removed and replaced with just `rm` when support for Node.Js 12 is removed.
27
+ const { rm, rmdir } = fs_1.promises;
28
+ const entriesToDelete = (await fs_1.promises.readdir(basePath, { withFileTypes: true }))
29
+ .filter((d) => (0, path_1.join)(basePath, d.name) !== path && d.isDirectory())
30
+ .map((d) => {
31
+ const subPath = (0, path_1.join)(basePath, d.name);
32
+ try {
33
+ return rm
34
+ ? rm(subPath, { force: true, recursive: true, maxRetries: 3 })
35
+ : rmdir(subPath, { recursive: true, maxRetries: 3 });
36
+ }
37
+ catch { }
38
+ });
39
+ await Promise.all(entriesToDelete);
40
+ }
41
+ exports.purgeStaleBuildCache = purgeStaleBuildCache;
@@ -81,7 +81,7 @@ async function getCommonConfig(wco) {
81
81
  }
82
82
  }
83
83
  if (!buildOptions.aot) {
84
- const jitPolyfills = 'core-js/proposals/reflect-metadata';
84
+ const jitPolyfills = require.resolve('core-js/proposals/reflect-metadata');
85
85
  if (entryPoints['polyfills']) {
86
86
  entryPoints['polyfills'].push(jitPolyfills);
87
87
  }
@@ -198,7 +198,8 @@ async function getCommonConfig(wco) {
198
198
  define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
199
199
  sourcemap: scriptsSourceMap,
200
200
  target: scriptTarget,
201
- keepNames: !environment_options_1.allowMangle || isPlatformServer,
201
+ keepIdentifierNames: !environment_options_1.allowMangle || isPlatformServer,
202
+ keepNames: isPlatformServer,
202
203
  removeLicenses: buildOptions.extractLicenses,
203
204
  advanced: buildOptions.buildOptimizer,
204
205
  }));
@@ -271,14 +272,14 @@ async function getCommonConfig(wco) {
271
272
  module: {
272
273
  // Show an error for missing exports instead of a warning.
273
274
  strictExportPresence: true,
274
- parser: webWorkerTsConfig === undefined
275
- ? {
276
- javascript: {
277
- worker: false,
278
- url: false,
279
- },
280
- }
281
- : undefined,
275
+ parser: {
276
+ javascript: {
277
+ // Disable auto URL asset module creation. This doesn't effect `new Worker(new URL(...))`
278
+ // https://webpack.js.org/guides/asset-modules/#url-assets
279
+ url: false,
280
+ worker: !!webWorkerTsConfig,
281
+ },
282
+ },
282
283
  rules: [
283
284
  {
284
285
  test: /\.?(svg|html)$/,
@@ -58,7 +58,6 @@ async function getDevServerConfig(wco) {
58
58
  },
59
59
  });
60
60
  }
61
- const webSocketPath = path_1.posix.join(servePath, 'ws');
62
61
  return {
63
62
  plugins: extraPlugins,
64
63
  module: {
@@ -82,11 +81,6 @@ async function getDevServerConfig(wco) {
82
81
  },
83
82
  ],
84
83
  },
85
- webSocketServer: {
86
- options: {
87
- path: webSocketPath,
88
- },
89
- },
90
84
  compress: false,
91
85
  static: false,
92
86
  server: getServerConfig(root, wco.buildOptions),
@@ -98,14 +92,7 @@ async function getDevServerConfig(wco) {
98
92
  liveReload,
99
93
  hot: hmr && !liveReload ? 'only' : hmr,
100
94
  proxy: await addProxyConfig(root, proxyConfig),
101
- client: {
102
- logging: 'info',
103
- webSocketURL: getPublicHostOptions(wco.buildOptions, webSocketPath),
104
- overlay: {
105
- errors: true,
106
- warnings: false,
107
- },
108
- },
95
+ ...getWebSocketSettings(wco.buildOptions, servePath),
109
96
  },
110
97
  };
111
98
  }
@@ -271,6 +258,31 @@ function getAllowedHostsConfig(options) {
271
258
  }
272
259
  return undefined;
273
260
  }
261
+ function getWebSocketSettings(options, servePath) {
262
+ const { hmr, liveReload } = options;
263
+ if (!hmr && !liveReload) {
264
+ return {
265
+ webSocketServer: false,
266
+ client: undefined,
267
+ };
268
+ }
269
+ const webSocketPath = path_1.posix.join(servePath, 'ws');
270
+ return {
271
+ webSocketServer: {
272
+ options: {
273
+ path: webSocketPath,
274
+ },
275
+ },
276
+ client: {
277
+ logging: 'info',
278
+ webSocketURL: getPublicHostOptions(options, webSocketPath),
279
+ overlay: {
280
+ errors: true,
281
+ warnings: false,
282
+ },
283
+ },
284
+ };
285
+ }
274
286
  function getPublicHostOptions(options, webSocketPath) {
275
287
  let publicHost = options.publicHost;
276
288
  if (publicHost) {
@@ -340,17 +340,17 @@ function getStylesConfig(wco) {
340
340
  // Setup processing rules for global and component styles
341
341
  {
342
342
  oneOf: [
343
- // Component styles are all styles except defined global styles
344
- {
345
- use: componentStyleLoaders,
346
- resourceQuery: /\?ngResource/,
347
- type: 'asset/source',
348
- },
349
343
  // Global styles are only defined global styles
350
344
  {
351
345
  use: globalStyleLoaders,
346
+ include: globalStylePaths,
352
347
  resourceQuery: { not: [/\?ngResource/] },
353
348
  },
349
+ // Component styles are all styles except defined global styles
350
+ {
351
+ use: componentStyleLoaders,
352
+ type: 'asset/source',
353
+ },
354
354
  ],
355
355
  },
356
356
  { use },
@@ -47,6 +47,10 @@ class AnyComponentStyleBudgetChecker {
47
47
  name: PLUGIN_NAME,
48
48
  stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
49
49
  }, () => {
50
+ // No budgets.
51
+ if (this.budgets.length === 0) {
52
+ return;
53
+ }
50
54
  // In AOT compilations component styles get processed in child compilations.
51
55
  if (!compilation.compiler.parentCompilation) {
52
56
  return;
@@ -13,10 +13,10 @@ import type { Compiler } from 'webpack';
13
13
  export interface JavaScriptOptimizerOptions {
14
14
  /**
15
15
  * Enables advanced optimizations in the underlying JavaScript optimizers.
16
- * This currently increases the `terser` passes to 3 and enables the `pure_getters`
16
+ * This currently increases the `terser` passes to 2 and enables the `pure_getters`
17
17
  * option for `terser`.
18
18
  */
19
- advanced: boolean;
19
+ advanced?: boolean;
20
20
  /**
21
21
  * An object record of string keys that will be replaced with their respective values when found
22
22
  * within the code during optimization.
@@ -27,7 +27,7 @@ export interface JavaScriptOptimizerOptions {
27
27
  * The output sourcemap will be a full sourcemap containing the merge of the input sourcemap and
28
28
  * all intermediate sourcemaps.
29
29
  */
30
- sourcemap: boolean;
30
+ sourcemap?: boolean;
31
31
  /**
32
32
  * The ECMAScript version that should be used when generating output code.
33
33
  * The optimizer will not adjust the output code with features present in newer
@@ -37,12 +37,20 @@ export interface JavaScriptOptimizerOptions {
37
37
  /**
38
38
  * Enables the retention of identifier names and ensures that function and class names are
39
39
  * present in the output code.
40
+ *
41
+ * **Note**: in some cases symbols are still renamed to avoid collisions.
42
+ */
43
+ keepIdentifierNames: boolean;
44
+ /**
45
+ * Enables the retention of original name of classes and functions.
46
+ *
47
+ * **Note**: this causes increase of bundle size as it causes dead-code elimination to not work fully.
40
48
  */
41
49
  keepNames: boolean;
42
50
  /**
43
51
  * Enables the removal of all license comments from the output code.
44
52
  */
45
- removeLicenses: boolean;
53
+ removeLicenses?: boolean;
46
54
  }
47
55
  /**
48
56
  * A Webpack plugin that provides JavaScript optimization capabilities.
@@ -53,7 +61,7 @@ export interface JavaScriptOptimizerOptions {
53
61
  * optimizations not yet implemented by `esbuild`.
54
62
  */
55
63
  export declare class JavaScriptOptimizerPlugin {
56
- options: Partial<JavaScriptOptimizerOptions>;
57
- constructor(options?: Partial<JavaScriptOptimizerOptions>);
64
+ options: JavaScriptOptimizerOptions;
65
+ constructor(options: JavaScriptOptimizerOptions);
58
66
  apply(compiler: Compiler): void;
59
67
  }
@@ -32,7 +32,7 @@ const PLUGIN_NAME = 'angular-javascript-optimizer';
32
32
  * optimizations not yet implemented by `esbuild`.
33
33
  */
34
34
  class JavaScriptOptimizerPlugin {
35
- constructor(options = {}) {
35
+ constructor(options) {
36
36
  this.options = options;
37
37
  }
38
38
  apply(compiler) {
@@ -91,11 +91,11 @@ class JavaScriptOptimizerPlugin {
91
91
  if (this.options.target <= typescript_1.ScriptTarget.ES5) {
92
92
  target = 5;
93
93
  }
94
- else if (this.options.target < typescript_1.ScriptTarget.ESNext) {
95
- target = Number(typescript_1.ScriptTarget[this.options.target].slice(2));
94
+ else if (this.options.target === typescript_1.ScriptTarget.ESNext) {
95
+ target = 'next';
96
96
  }
97
97
  else {
98
- target = 2020;
98
+ target = Number(typescript_1.ScriptTarget[this.options.target].slice(2));
99
99
  }
100
100
  }
101
101
  // Setup the options used by all worker tasks
@@ -103,6 +103,7 @@ class JavaScriptOptimizerPlugin {
103
103
  sourcemap: this.options.sourcemap,
104
104
  define,
105
105
  keepNames: this.options.keepNames,
106
+ keepIdentifierNames: this.options.keepIdentifierNames,
106
107
  target,
107
108
  removeLicenses: this.options.removeLicenses,
108
109
  advanced: this.options.advanced,
@@ -5,6 +5,50 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
+ /**
9
+ * The options to use when optimizing.
10
+ */
11
+ export interface OptimizeRequestOptions {
12
+ /**
13
+ * Controls advanced optimizations.
14
+ * Currently these are only terser related:
15
+ * * terser compress passes are set to 2
16
+ * * terser pure_getters option is enabled
17
+ */
18
+ advanced?: boolean;
19
+ /**
20
+ * Specifies the string tokens that should be replaced with a defined value.
21
+ */
22
+ define?: Record<string, string>;
23
+ /**
24
+ * Controls whether class, function, and variable names should be left intact
25
+ * throughout the output code.
26
+ */
27
+ keepIdentifierNames: boolean;
28
+ /**
29
+ * Controls whether to retain the original name of classes and functions.
30
+ */
31
+ keepNames: boolean;
32
+ /**
33
+ * Controls whether license text is removed from the output code.
34
+ * Within the CLI, this option is linked to the license extraction functionality.
35
+ */
36
+ removeLicenses?: boolean;
37
+ /**
38
+ * Controls whether source maps should be generated.
39
+ */
40
+ sourcemap?: boolean;
41
+ /**
42
+ * Specifies the target ECMAScript version for the output code.
43
+ */
44
+ target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 'next';
45
+ /**
46
+ * Controls whether esbuild should only use the WASM-variant instead of trying to
47
+ * use the native variant. Some platforms may not support the native-variant and
48
+ * this option allows one support test to be conducted prior to all the workers starting.
49
+ */
50
+ alwaysUseWasm: boolean;
51
+ }
8
52
  /**
9
53
  * A request to optimize JavaScript using the supplied options.
10
54
  */
@@ -12,43 +56,7 @@ interface OptimizeRequest {
12
56
  /**
13
57
  * The options to use when optimizing.
14
58
  */
15
- options: {
16
- /**
17
- * Controls advanced optimizations.
18
- * Currently these are only terser related:
19
- * * terser compress passes are set to 2
20
- * * terser pure_getters option is enabled
21
- */
22
- advanced: boolean;
23
- /**
24
- * Specifies the string tokens that should be replaced with a defined value.
25
- */
26
- define?: Record<string, string>;
27
- /**
28
- * Controls whether class, function, and variable names should be left intact
29
- * throughout the output code.
30
- */
31
- keepNames: boolean;
32
- /**
33
- * Controls whether license text is removed from the output code.
34
- * Within the CLI, this option is linked to the license extraction functionality.
35
- */
36
- removeLicenses: boolean;
37
- /**
38
- * Controls whether source maps should be generated.
39
- */
40
- sourcemap: boolean;
41
- /**
42
- * Specifies the target ECMAScript version for the output code.
43
- */
44
- target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
45
- /**
46
- * Controls whether esbuild should only use the WASM-variant instead of trying to
47
- * use the native variant. Some platforms may not support the native-variant and
48
- * this option allows one support test to be conducted prior to all the workers starting.
49
- */
50
- alwaysUseWasm: boolean;
51
- };
59
+ options: OptimizeRequestOptions;
52
60
  /**
53
61
  * The JavaScript asset to optimize.
54
62
  */
@@ -26,7 +26,9 @@ async function default_1({ asset, options }) {
26
26
  // esbuild is used as a first pass
27
27
  const esbuildResult = await optimizeWithEsbuild(asset.code, asset.name, options);
28
28
  // terser is used as a second pass
29
- const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap, options.target, options.advanced);
29
+ const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap,
30
+ // Terser only supports up to ES2020.
31
+ options.target === 'next' ? 2020 : options.target, options.advanced);
30
32
  // Merge intermediate sourcemaps with input sourcemap if enabled
31
33
  let fullSourcemap;
32
34
  if (options.sourcemap) {
@@ -61,7 +63,7 @@ async function optimizeWithEsbuild(content, name, options) {
61
63
  let result;
62
64
  try {
63
65
  result = await esbuild.transform(content, {
64
- minifyIdentifiers: !options.keepNames,
66
+ minifyIdentifiers: !options.keepIdentifierNames,
65
67
  minifySyntax: true,
66
68
  // NOTE: Disabling whitespace ensures unused pure annotations are kept
67
69
  minifyWhitespace: false,
@@ -70,6 +72,10 @@ async function optimizeWithEsbuild(content, name, options) {
70
72
  sourcefile: name,
71
73
  sourcemap: options.sourcemap && 'external',
72
74
  define: options.define,
75
+ // This option should always be disabled for browser builds as we don't rely on `.name`
76
+ // and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
77
+ // We enable `keepNames` only for server builds as Domino relies on `.name`.
78
+ // Once we no longer rely on Domino for SSR we should be able to remove this.
73
79
  keepNames: options.keepNames,
74
80
  target: `es${options.target}`,
75
81
  });
@@ -113,6 +119,8 @@ async function optimizeWithTerser(name, code, sourcemaps, target, advanced) {
113
119
  ecma: target,
114
120
  // esbuild in the first pass is used to minify identifiers instead of mangle here
115
121
  mangle: false,
122
+ // esbuild in the first pass is used to minify function names
123
+ keep_fnames: true,
116
124
  format: {
117
125
  // ASCII output is enabled here as well to prevent terser from converting back to UTF-8
118
126
  ascii_only: true,
@@ -35,18 +35,19 @@ const fs_1 = require("fs");
35
35
  const glob_1 = __importDefault(require("glob"));
36
36
  const path = __importStar(require("path"));
37
37
  const typescript_1 = require("typescript");
38
+ const package_version_1 = require("../../utils/package-version");
38
39
  function getOutputHashFormat(option, length = 20) {
39
40
  const hashFormats = {
40
41
  none: { chunk: '', extract: '', file: '', script: '' },
41
42
  media: { chunk: '', extract: '', file: `.[hash:${length}]`, script: '' },
42
43
  bundles: {
43
- chunk: `.[chunkhash:${length}]`,
44
+ chunk: `.[contenthash:${length}]`,
44
45
  extract: `.[contenthash:${length}]`,
45
46
  file: '',
46
47
  script: `.[hash:${length}]`,
47
48
  },
48
49
  all: {
49
- chunk: `.[chunkhash:${length}]`,
50
+ chunk: `.[contenthash:${length}]`,
50
51
  extract: `.[contenthash:${length}]`,
51
52
  file: `.[hash:${length}]`,
52
53
  script: `.[hash:${length}]`,
@@ -113,9 +114,9 @@ exports.getInstrumentationExcludedPaths = getInstrumentationExcludedPaths;
113
114
  function getCacheSettings(wco, angularVersion) {
114
115
  const { enabled, path: cacheDirectory } = wco.buildOptions.cache;
115
116
  if (enabled) {
116
- const packageVersion = require('../../../package.json').version;
117
117
  return {
118
118
  type: 'filesystem',
119
+ profile: wco.buildOptions.verbose,
119
120
  cacheDirectory: path.join(cacheDirectory, 'angular-webpack'),
120
121
  maxMemoryGenerations: 1,
121
122
  // We use the versions and build options as the cache name. The Webpack configurations are too
@@ -123,7 +124,7 @@ function getCacheSettings(wco, angularVersion) {
123
124
  // None of which are "named".
124
125
  name: (0, crypto_1.createHash)('sha1')
125
126
  .update(angularVersion)
126
- .update(packageVersion)
127
+ .update(package_version_1.VERSION)
127
128
  .update(wco.projectRoot)
128
129
  .update(JSON.stringify(wco.tsConfig))
129
130
  .update(JSON.stringify({