@angular-devkit/build-angular 13.2.0-next.1 → 13.2.0-next.2

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 (36) hide show
  1. package/package.json +27 -27
  2. package/src/babel/webpack-loader.js +2 -1
  3. package/src/builders/browser/index.d.ts +5 -0
  4. package/src/builders/browser/index.js +9 -1
  5. package/src/builders/browser/schema.d.ts +8 -2
  6. package/src/builders/browser/schema.js +9 -7
  7. package/src/builders/browser/schema.json +6 -0
  8. package/src/builders/dev-server/index.js +8 -3
  9. package/src/builders/extract-i18n/index.js +3 -0
  10. package/src/builders/karma/index.js +3 -0
  11. package/src/builders/ng-packagr/index.js +3 -0
  12. package/src/builders/server/index.js +3 -0
  13. package/src/builders/server/schema.d.ts +8 -2
  14. package/src/builders/server/schema.js +9 -7
  15. package/src/builders/server/schema.json +6 -0
  16. package/src/utils/build-options.d.ts +2 -2
  17. package/src/utils/i18n-inlining.js +0 -14
  18. package/src/utils/i18n-options.d.ts +2 -2
  19. package/src/utils/i18n-options.js +34 -9
  20. package/src/utils/index-file/inline-fonts.js +2 -2
  21. package/src/utils/normalize-cache.d.ts +4 -0
  22. package/src/utils/normalize-cache.js +4 -1
  23. package/src/utils/package-version.d.ts +8 -0
  24. package/src/utils/package-version.js +11 -0
  25. package/src/utils/purge-cache.d.ts +10 -0
  26. package/src/utils/purge-cache.js +41 -0
  27. package/src/webpack/configs/common.js +3 -2
  28. package/src/webpack/configs/dev-server.js +26 -14
  29. package/src/webpack/configs/styles.js +0 -3
  30. package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +14 -6
  31. package/src/webpack/plugins/javascript-optimizer-plugin.js +2 -1
  32. package/src/webpack/plugins/javascript-optimizer-worker.d.ts +45 -37
  33. package/src/webpack/plugins/javascript-optimizer-worker.js +7 -1
  34. package/src/webpack/plugins/karma/karma.js +2 -2
  35. package/src/webpack/utils/helpers.d.ts +1 -1
  36. package/src/webpack/utils/helpers.js +4 -4
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "13.2.0-next.1",
3
+ "version": "13.2.0-next.2",
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.1302.0-next.1",
11
- "@angular-devkit/build-webpack": "0.1302.0-next.1",
12
- "@angular-devkit/core": "13.2.0-next.1",
13
- "@babel/core": "7.16.5",
14
- "@babel/generator": "7.16.5",
15
- "@babel/helper-annotate-as-pure": "7.16.0",
16
- "@babel/plugin-proposal-async-generator-functions": "7.16.5",
17
- "@babel/plugin-transform-async-to-generator": "7.16.5",
18
- "@babel/plugin-transform-runtime": "7.16.5",
19
- "@babel/preset-env": "7.16.5",
20
- "@babel/runtime": "7.16.5",
21
- "@babel/template": "7.16.0",
10
+ "@angular-devkit/architect": "0.1302.0-next.2",
11
+ "@angular-devkit/build-webpack": "0.1302.0-next.2",
12
+ "@angular-devkit/core": "13.2.0-next.2",
13
+ "@babel/core": "7.16.7",
14
+ "@babel/generator": "7.16.8",
15
+ "@babel/helper-annotate-as-pure": "7.16.7",
16
+ "@babel/plugin-proposal-async-generator-functions": "7.16.8",
17
+ "@babel/plugin-transform-async-to-generator": "7.16.8",
18
+ "@babel/plugin-transform-runtime": "7.16.8",
19
+ "@babel/preset-env": "7.16.8",
20
+ "@babel/runtime": "7.16.7",
21
+ "@babel/template": "7.16.7",
22
22
  "@discoveryjs/json-ext": "0.5.6",
23
- "@ngtools/webpack": "13.2.0-next.1",
23
+ "@ngtools/webpack": "13.2.0-next.2",
24
24
  "ansi-colors": "4.1.1",
25
25
  "babel-loader": "8.2.3",
26
26
  "babel-plugin-istanbul": "6.1.1",
27
27
  "browserslist": "^4.9.1",
28
28
  "cacache": "15.3.0",
29
29
  "circular-dependency-plugin": "5.2.2",
30
- "copy-webpack-plugin": "10.1.0",
31
- "core-js": "3.19.3",
32
- "critters": "0.0.15",
30
+ "copy-webpack-plugin": "10.2.0",
31
+ "core-js": "3.20.2",
32
+ "critters": "0.0.16",
33
33
  "css-loader": "6.5.1",
34
- "esbuild-wasm": "0.14.5",
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",
@@ -41,7 +41,7 @@
41
41
  "less-loader": "10.2.0",
42
42
  "license-webpack-plugin": "4.0.0",
43
43
  "loader-utils": "3.2.0",
44
- "mini-css-extract-plugin": "2.4.5",
44
+ "mini-css-extract-plugin": "2.4.6",
45
45
  "minimatch": "3.0.4",
46
46
  "open": "8.4.0",
47
47
  "ora": "5.4.1",
@@ -50,29 +50,29 @@
50
50
  "postcss": "8.4.5",
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",
57
- "sass": "1.45.0",
57
+ "sass": "1.47.0",
58
58
  "sass-loader": "12.4.0",
59
59
  "semver": "7.3.5",
60
- "source-map-loader": "3.0.0",
60
+ "source-map-loader": "3.0.1",
61
61
  "source-map-support": "0.5.21",
62
- "stylus": "0.55.0",
62
+ "stylus": "0.56.0",
63
63
  "stylus-loader": "6.2.0",
64
64
  "terser": "5.10.0",
65
65
  "text-table": "0.2.0",
66
66
  "tree-kill": "1.2.2",
67
67
  "tslib": "2.3.1",
68
- "webpack": "5.65.0",
69
- "webpack-dev-middleware": "5.2.2",
70
- "webpack-dev-server": "4.6.0",
68
+ "webpack": "5.66.0",
69
+ "webpack-dev-middleware": "5.3.0",
70
+ "webpack-dev-server": "4.7.3",
71
71
  "webpack-merge": "5.8.0",
72
72
  "webpack-subresource-integrity": "5.0.0"
73
73
  },
74
74
  "optionalDependencies": {
75
- "esbuild": "0.14.5"
75
+ "esbuild": "0.14.11"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "@angular/compiler-cli": "^13.0.0 || ^13.1.0-next",
@@ -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)),
@@ -53,10 +53,14 @@ export interface Schema {
53
53
  * Replace compilation source files with other compilation source files in the build.
54
54
  */
55
55
  fileReplacements?: FileReplacement[];
56
+ /**
57
+ * How to handle duplicate translations for i18n.
58
+ */
59
+ i18nDuplicateTranslation?: I18NTranslation;
56
60
  /**
57
61
  * How to handle missing translations for i18n.
58
62
  */
59
- i18nMissingTranslation?: I18NMissingTranslation;
63
+ i18nMissingTranslation?: I18NTranslation;
60
64
  /**
61
65
  * Configures the generation of the application's HTML index.
62
66
  */
@@ -266,9 +270,11 @@ export interface FileReplacement {
266
270
  with?: string;
267
271
  }
268
272
  /**
273
+ * How to handle duplicate translations for i18n.
274
+ *
269
275
  * How to handle missing translations for i18n.
270
276
  */
271
- export declare enum I18NMissingTranslation {
277
+ export declare enum I18NTranslation {
272
278
  Error = "error",
273
279
  Ignore = "ignore",
274
280
  Warning = "warning"
@@ -2,7 +2,7 @@
2
2
  // THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
3
3
  // CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.OutputHashing = exports.InlineStyleLanguage = exports.I18NMissingTranslation = exports.CrossOrigin = exports.Type = void 0;
5
+ exports.OutputHashing = exports.InlineStyleLanguage = exports.I18NTranslation = exports.CrossOrigin = exports.Type = void 0;
6
6
  /**
7
7
  * The type of budget.
8
8
  */
@@ -26,14 +26,16 @@ var CrossOrigin;
26
26
  CrossOrigin["UseCredentials"] = "use-credentials";
27
27
  })(CrossOrigin = exports.CrossOrigin || (exports.CrossOrigin = {}));
28
28
  /**
29
+ * How to handle duplicate translations for i18n.
30
+ *
29
31
  * How to handle missing translations for i18n.
30
32
  */
31
- var I18NMissingTranslation;
32
- (function (I18NMissingTranslation) {
33
- I18NMissingTranslation["Error"] = "error";
34
- I18NMissingTranslation["Ignore"] = "ignore";
35
- I18NMissingTranslation["Warning"] = "warning";
36
- })(I18NMissingTranslation = exports.I18NMissingTranslation || (exports.I18NMissingTranslation = {}));
33
+ var I18NTranslation;
34
+ (function (I18NTranslation) {
35
+ I18NTranslation["Error"] = "error";
36
+ I18NTranslation["Ignore"] = "ignore";
37
+ I18NTranslation["Warning"] = "warning";
38
+ })(I18NTranslation = exports.I18NTranslation || (exports.I18NTranslation = {}));
37
39
  /**
38
40
  * The stylesheet language to use for the application's inline component styles.
39
41
  */
@@ -220,6 +220,12 @@
220
220
  "enum": ["warning", "error", "ignore"],
221
221
  "default": "warning"
222
222
  },
223
+ "i18nDuplicateTranslation": {
224
+ "type": "string",
225
+ "description": "How to handle duplicate translations for i18n.",
226
+ "enum": ["warning", "error", "ignore"],
227
+ "default": "warning"
228
+ },
223
229
  "localize": {
224
230
  "description": "Translate the bundles in one or more locales.",
225
231
  "oneOf": [
@@ -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.
@@ -192,11 +195,12 @@ function serveWebpackBrowser(options, context, transforms = {}) {
192
195
  }).pipe((0, operators_1.concatMap)(async (buildEvent, index) => {
193
196
  var _a, _b;
194
197
  // Resolve serve address.
198
+ const publicPath = (_b = (_a = webpackConfig.devServer) === null || _a === void 0 ? void 0 : _a.devMiddleware) === null || _b === void 0 ? void 0 : _b.publicPath;
195
199
  const serverAddress = url.format({
196
200
  protocol: options.ssl ? 'https' : 'http',
197
201
  hostname: options.host === '0.0.0.0' ? 'localhost' : options.host,
198
202
  port: buildEvent.port,
199
- pathname: (_b = (_a = webpackConfig.devServer) === null || _a === void 0 ? void 0 : _a.devMiddleware) === null || _b === void 0 ? void 0 : _b.publicPath,
203
+ pathname: typeof publicPath === 'string' ? publicPath : undefined,
200
204
  });
201
205
  if (index === 0) {
202
206
  logger.info('\n' +
@@ -286,6 +290,7 @@ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheO
286
290
  webpackConfig.plugins.push({
287
291
  apply: (compiler) => {
288
292
  compiler.hooks.thisCompilation.tap('build-angular', (compilation) => {
293
+ var _a;
289
294
  if (i18n.shouldInline && i18nLoaderOptions.translation === undefined) {
290
295
  // Reload translations
291
296
  (0, i18n_options_1.loadTranslations)(locale, localeDescription, context.workspaceRoot, loader, {
@@ -295,8 +300,8 @@ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheO
295
300
  error(message) {
296
301
  (0, webpack_diagnostics_1.addError)(compilation, message);
297
302
  },
298
- });
299
- i18nLoaderOptions.translation = localeDescription.translation;
303
+ }, undefined, browserOptions.i18nDuplicateTranslation);
304
+ i18nLoaderOptions.translation = (_a = localeDescription.translation) !== null && _a !== void 0 ? _a : {};
300
305
  }
301
306
  compilation.hooks.finishModules.tap('build-angular', () => {
302
307
  // 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,
@@ -28,10 +28,14 @@ export interface Schema {
28
28
  * Replace compilation source files with other compilation source files in the build.
29
29
  */
30
30
  fileReplacements?: FileReplacement[];
31
+ /**
32
+ * How to handle duplicate translations for i18n.
33
+ */
34
+ i18nDuplicateTranslation?: I18NTranslation;
31
35
  /**
32
36
  * How to handle missing translations for i18n.
33
37
  */
34
- i18nMissingTranslation?: I18NMissingTranslation;
38
+ i18nMissingTranslation?: I18NTranslation;
35
39
  /**
36
40
  * The stylesheet language to use for the application's inline component styles.
37
41
  */
@@ -128,9 +132,11 @@ export interface FileReplacement {
128
132
  with?: string;
129
133
  }
130
134
  /**
135
+ * How to handle duplicate translations for i18n.
136
+ *
131
137
  * How to handle missing translations for i18n.
132
138
  */
133
- export declare enum I18NMissingTranslation {
139
+ export declare enum I18NTranslation {
134
140
  Error = "error",
135
141
  Ignore = "ignore",
136
142
  Warning = "warning"
@@ -2,21 +2,23 @@
2
2
  // THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
3
3
  // CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.OutputHashing = exports.InlineStyleLanguage = exports.I18NMissingTranslation = exports.BundleDependenciesEnum = void 0;
5
+ exports.OutputHashing = exports.InlineStyleLanguage = exports.I18NTranslation = exports.BundleDependenciesEnum = void 0;
6
6
  var BundleDependenciesEnum;
7
7
  (function (BundleDependenciesEnum) {
8
8
  BundleDependenciesEnum["All"] = "all";
9
9
  BundleDependenciesEnum["None"] = "none";
10
10
  })(BundleDependenciesEnum = exports.BundleDependenciesEnum || (exports.BundleDependenciesEnum = {}));
11
11
  /**
12
+ * How to handle duplicate translations for i18n.
13
+ *
12
14
  * How to handle missing translations for i18n.
13
15
  */
14
- var I18NMissingTranslation;
15
- (function (I18NMissingTranslation) {
16
- I18NMissingTranslation["Error"] = "error";
17
- I18NMissingTranslation["Ignore"] = "ignore";
18
- I18NMissingTranslation["Warning"] = "warning";
19
- })(I18NMissingTranslation = exports.I18NMissingTranslation || (exports.I18NMissingTranslation = {}));
16
+ var I18NTranslation;
17
+ (function (I18NTranslation) {
18
+ I18NTranslation["Error"] = "error";
19
+ I18NTranslation["Ignore"] = "ignore";
20
+ I18NTranslation["Warning"] = "warning";
21
+ })(I18NTranslation = exports.I18NTranslation || (exports.I18NTranslation = {}));
20
22
  /**
21
23
  * The stylesheet language to use for the application's inline component styles.
22
24
  */
@@ -133,6 +133,12 @@
133
133
  "enum": ["warning", "error", "ignore"],
134
134
  "default": "warning"
135
135
  },
136
+ "i18nDuplicateTranslation": {
137
+ "type": "string",
138
+ "description": "How to handle duplicate translations for i18n.",
139
+ "enum": ["warning", "error", "ignore"],
140
+ "default": "warning"
141
+ },
136
142
  "localize": {
137
143
  "description": "Translate the bundles in one or more locales.",
138
144
  "oneOf": [
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { logging } from '@angular-devkit/core';
9
9
  import type { ParsedConfiguration } from '@angular/compiler-cli';
10
- import { AssetPatternClass, Budget, CrossOrigin, ExtraEntryPoint, I18NMissingTranslation, IndexUnion, InlineStyleLanguage, Localize, SourceMapClass } from '../builders/browser/schema';
10
+ import { AssetPatternClass, Budget, CrossOrigin, ExtraEntryPoint, I18NTranslation, IndexUnion, InlineStyleLanguage, Localize, SourceMapClass } from '../builders/browser/schema';
11
11
  import { Schema as DevServerSchema } from '../builders/dev-server/schema';
12
12
  import { NormalizedCachedOptions } from './normalize-cache';
13
13
  import { NormalizedFileReplacement } from './normalize-file-replacements';
@@ -26,7 +26,7 @@ export interface BuildOptions {
26
26
  verbose?: boolean;
27
27
  progress?: boolean;
28
28
  localize?: Localize;
29
- i18nMissingTranslation?: I18NMissingTranslation;
29
+ i18nMissingTranslation?: I18NTranslation;
30
30
  bundleDependencies?: boolean;
31
31
  externalDependencies?: string[];
32
32
  watch?: boolean;
@@ -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') {
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { BuilderContext } from '@angular-devkit/architect';
9
9
  import { json } from '@angular-devkit/core';
10
- import { Schema as BrowserBuilderSchema } from '../builders/browser/schema';
10
+ import { Schema as BrowserBuilderSchema, I18NTranslation } from '../builders/browser/schema';
11
11
  import { Schema as ServerBuilderSchema } from '../builders/server/schema';
12
12
  import { TranslationLoader } from './load-translations';
13
13
  export interface LocaleDescription {
@@ -36,4 +36,4 @@ export declare function configureI18nBuild<T extends BrowserBuilderSchema | Serv
36
36
  export declare function loadTranslations(locale: string, desc: LocaleDescription, workspaceRoot: string, loader: TranslationLoader, logger: {
37
37
  warn: (message: string) => void;
38
38
  error: (message: string) => void;
39
- }, usedFormats?: Set<string>): void;
39
+ }, usedFormats?: Set<string>, duplicateTranslation?: I18NTranslation): void;
@@ -16,6 +16,7 @@ const fs_1 = __importDefault(require("fs"));
16
16
  const module_1 = __importDefault(require("module"));
17
17
  const os_1 = __importDefault(require("os"));
18
18
  const path_1 = __importDefault(require("path"));
19
+ const schema_1 = require("../builders/browser/schema");
19
20
  const read_tsconfig_1 = require("../utils/read-tsconfig");
20
21
  const load_translations_1 = require("./load-translations");
21
22
  /**
@@ -166,7 +167,7 @@ async function configureI18nBuild(context, options) {
166
167
  error(message) {
167
168
  throw new Error(message);
168
169
  },
169
- }, usedFormats);
170
+ }, usedFormats, buildOptions.i18nDuplicateTranslation);
170
171
  if (usedFormats.size > 1 && tsConfig.options.enableI18nLegacyMessageIdFormat !== false) {
171
172
  // This limitation is only for legacy message id support (defaults to true as of 9.0)
172
173
  throw new Error('Localization currently only supports using one type of translation file format for the entire application.');
@@ -176,12 +177,11 @@ async function configureI18nBuild(context, options) {
176
177
  if (i18n.shouldInline) {
177
178
  const tempPath = fs_1.default.mkdtempSync(path_1.default.join(fs_1.default.realpathSync(os_1.default.tmpdir()), 'angular-cli-i18n-'));
178
179
  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 { }
180
+ process.on('exit', () => deleteTempDirectory(tempPath));
181
+ process.once('SIGINT', () => {
182
+ deleteTempDirectory(tempPath);
183
+ // Needed due to `ora` as otherwise process will not terminate.
184
+ process.kill(process.pid, 'SIGINT');
185
185
  });
186
186
  }
187
187
  return { buildOptions, i18n };
@@ -201,7 +201,21 @@ function findLocaleDataPath(locale, resolver) {
201
201
  return null;
202
202
  }
203
203
  }
204
- function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats) {
204
+ /** Remove temporary directory used for i18n processing. */
205
+ function deleteTempDirectory(tempPath) {
206
+ // The below should be removed and replaced with just `rmSync` when support for Node.Js 12 is removed.
207
+ const { rmSync, rmdirSync } = fs_1.default;
208
+ try {
209
+ if (rmSync) {
210
+ rmSync(tempPath, { force: true, recursive: true, maxRetries: 3 });
211
+ }
212
+ else {
213
+ rmdirSync(tempPath, { recursive: true, maxRetries: 3 });
214
+ }
215
+ }
216
+ catch { }
217
+ }
218
+ function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats, duplicateTranslation) {
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) {
@@ -222,7 +236,18 @@ function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedForma
222
236
  // Merge translations
223
237
  for (const [id, message] of Object.entries(loadResult.translations)) {
224
238
  if (desc.translation[id] !== undefined) {
225
- logger.warn(`WARNING [${file.path}]: Duplicate translations for message '${id}' when merging`);
239
+ const duplicateTranslationMessage = `[${file.path}]: Duplicate translations for message '${id}' when merging.`;
240
+ switch (duplicateTranslation) {
241
+ case schema_1.I18NTranslation.Ignore:
242
+ break;
243
+ case schema_1.I18NTranslation.Error:
244
+ logger.error(`ERROR ${duplicateTranslationMessage}`);
245
+ break;
246
+ case schema_1.I18NTranslation.Warning:
247
+ default:
248
+ logger.warn(`WARNING ${duplicateTranslationMessage}`);
249
+ break;
250
+ }
226
251
  }
227
252
  desc.translation[id] = message;
228
253
  }
@@ -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
  }));
@@ -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) {
@@ -129,9 +129,6 @@ function getStylesConfig(wco) {
129
129
  ` To enable Tailwind CSS, please install the 'tailwindcss' package.`);
130
130
  }
131
131
  if (tailwindPackagePath) {
132
- if (process.env['TAILWIND_MODE'] === undefined) {
133
- process.env['TAILWIND_MODE'] = buildOptions.watch ? 'watch' : 'build';
134
- }
135
132
  extraPostcssPlugins.push(require(tailwindPackagePath)({ config: tailwindConfigPath }));
136
133
  }
137
134
  }
@@ -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) {
@@ -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;
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
  */
@@ -61,7 +61,7 @@ async function optimizeWithEsbuild(content, name, options) {
61
61
  let result;
62
62
  try {
63
63
  result = await esbuild.transform(content, {
64
- minifyIdentifiers: !options.keepNames,
64
+ minifyIdentifiers: !options.keepIdentifierNames,
65
65
  minifySyntax: true,
66
66
  // NOTE: Disabling whitespace ensures unused pure annotations are kept
67
67
  minifyWhitespace: false,
@@ -70,6 +70,10 @@ async function optimizeWithEsbuild(content, name, options) {
70
70
  sourcefile: name,
71
71
  sourcemap: options.sourcemap && 'external',
72
72
  define: options.define,
73
+ // This option should always be disabled for browser builds as we don't rely on `.name`
74
+ // and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
75
+ // We enable `keepNames` only for server builds as Domino relies on `.name`.
76
+ // Once we no longer rely on Domino for SSR we should be able to remove this.
73
77
  keepNames: options.keepNames,
74
78
  target: `es${options.target}`,
75
79
  });
@@ -113,6 +117,8 @@ async function optimizeWithTerser(name, code, sourcemaps, target, advanced) {
113
117
  ecma: target,
114
118
  // esbuild in the first pass is used to minify identifiers instead of mangle here
115
119
  mangle: false,
120
+ // esbuild in the first pass is used to minify function names
121
+ keep_fnames: true,
116
122
  format: {
117
123
  // ASCII output is enabled here as well to prevent terser from converting back to UTF-8
118
124
  ascii_only: true,
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  const path = __importStar(require("path"));
33
33
  const glob = __importStar(require("glob"));
34
34
  const webpack_1 = __importDefault(require("webpack"));
35
- const webpackDevMiddleware = require('webpack-dev-middleware');
35
+ const webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
36
36
  const stats_1 = require("../../utils/stats");
37
37
  const node_1 = require("@angular-devkit/core/node");
38
38
  const index_1 = require("../../../utils/index");
@@ -172,7 +172,7 @@ const init = (config, emitter) => {
172
172
  }
173
173
  unblock();
174
174
  });
175
- webpackMiddleware = webpackDevMiddleware(compiler, webpackMiddlewareConfig);
175
+ webpackMiddleware = (0, webpack_dev_middleware_1.default)(compiler, webpackMiddlewareConfig);
176
176
  emitter.on('exit', (done) => {
177
177
  webpackMiddleware.close();
178
178
  done();
@@ -5,7 +5,7 @@
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
- import type { ObjectPattern } from 'copy-webpack-plugin/types/index';
8
+ import type { ObjectPattern } from 'copy-webpack-plugin';
9
9
  import { ScriptTarget } from 'typescript';
10
10
  import type { Configuration, WebpackOptionsNormalized } from 'webpack';
11
11
  import { AssetPatternClass, ExtraEntryPoint, ExtraEntryPointClass } from '../../builders/browser/schema';
@@ -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,7 +114,6 @@ 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
119
  profile: wco.buildOptions.verbose,
@@ -124,7 +124,7 @@ function getCacheSettings(wco, angularVersion) {
124
124
  // None of which are "named".
125
125
  name: (0, crypto_1.createHash)('sha1')
126
126
  .update(angularVersion)
127
- .update(packageVersion)
127
+ .update(package_version_1.VERSION)
128
128
  .update(wco.projectRoot)
129
129
  .update(JSON.stringify(wco.tsConfig))
130
130
  .update(JSON.stringify({