@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,10 +6,29 @@
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
+ };
9
28
  Object.defineProperty(exports, "__esModule", { value: true });
10
29
  exports.createTranslationLoader = void 0;
11
30
  const crypto_1 = require("crypto");
12
- const fs = require("fs");
31
+ const fs = __importStar(require("fs"));
13
32
  async function createTranslationLoader() {
14
33
  const { parsers, diagnostics } = await importParsers();
15
34
  return (path) => {
@@ -48,15 +67,15 @@ async function createTranslationLoader() {
48
67
  exports.createTranslationLoader = createTranslationLoader;
49
68
  async function importParsers() {
50
69
  try {
51
- const localizeDiag = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/diagnostics'));
70
+ const localizeDiag = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics')));
52
71
  const diagnostics = new localizeDiag.Diagnostics();
53
72
  const parsers = {
54
- arb: new (await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser'))).ArbTranslationParser(),
55
- json: new (await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser'))).SimpleJsonTranslationParser(),
56
- xlf: new (await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser'))).Xliff1TranslationParser(),
57
- xlf2: new (await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser'))).Xliff2TranslationParser(),
73
+ arb: new (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser')))).ArbTranslationParser(),
74
+ json: new (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser')))).SimpleJsonTranslationParser(),
75
+ xlf: new (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser')))).Xliff1TranslationParser(),
76
+ xlf2: new (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser')))).Xliff2TranslationParser(),
58
77
  // The name ('xmb') needs to match the AOT compiler option
59
- xmb: new (await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xtb_translation_parser'))).XtbTranslationParser(),
78
+ xmb: new (await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xtb_translation_parser')))).XtbTranslationParser(),
60
79
  };
61
80
  return { parsers, diagnostics };
62
81
  }
@@ -6,17 +6,39 @@
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
32
  exports.inlineLocales = exports.createI18nPlugins = exports.process = exports.setup = void 0;
11
33
  const core_1 = require("@babel/core");
12
- const template_1 = require("@babel/template");
13
- const cacache = require("cacache");
34
+ const template_1 = __importDefault(require("@babel/template"));
35
+ const cacache = __importStar(require("cacache"));
14
36
  const crypto_1 = require("crypto");
15
- const fs = require("fs");
16
- const path = require("path");
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
17
39
  const source_map_1 = require("source-map");
18
40
  const terser_1 = require("terser");
19
- const v8 = require("v8");
41
+ const v8 = __importStar(require("v8"));
20
42
  const webpack_1 = require("webpack");
21
43
  const environment_options_1 = require("./environment-options");
22
44
  const { ConcatSource, OriginalSource, ReplaceSource, SourceMapSource } = webpack_1.sources;
@@ -359,23 +381,23 @@ function createIifeWrapperPlugin() {
359
381
  const USE_LOCALIZE_PLUGINS = false;
360
382
  async function createI18nPlugins(locale, translation, missingTranslation, shouldInline, localeDataContent) {
361
383
  const plugins = [];
362
- const localizeDiag = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/diagnostics'));
384
+ const localizeDiag = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics')));
363
385
  const diagnostics = new localizeDiag.Diagnostics();
364
386
  if (shouldInline) {
365
- const es2015 = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/source_files/es2015_translate_plugin'));
387
+ const es2015 = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/es2015_translate_plugin')));
366
388
  plugins.push(
367
389
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
368
390
  es2015.makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
369
391
  missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
370
392
  }));
371
- const es5 = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/source_files/es5_translate_plugin'));
393
+ const es5 = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/es5_translate_plugin')));
372
394
  plugins.push(
373
395
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
374
396
  es5.makeEs5TranslatePlugin(diagnostics, (translation || {}), {
375
397
  missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
376
398
  }));
377
399
  }
378
- const inlineLocale = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/translate/source_files/locale_plugin'));
400
+ const inlineLocale = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/translate/source_files/locale_plugin')));
379
401
  plugins.push(inlineLocale.makeLocalePlugin(locale));
380
402
  if (localeDataContent) {
381
403
  plugins.push({
@@ -472,9 +494,9 @@ async function inlineLocalesDirect(ast, options) {
472
494
  if (!i18n || i18n.inlineLocales.size === 0) {
473
495
  return { file: options.filename, diagnostics: [], count: 0 };
474
496
  }
475
- const { default: generate } = await Promise.resolve().then(() => require('@babel/generator'));
476
- const utils = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/source_file_utils'));
477
- const localizeDiag = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/diagnostics'));
497
+ const { default: generate } = await Promise.resolve().then(() => __importStar(require('@babel/generator')));
498
+ const utils = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/source_file_utils')));
499
+ const localizeDiag = await Promise.resolve().then(() => __importStar(require('@angular/localize/src/tools/src/diagnostics')));
478
500
  const diagnostics = new localizeDiag.Diagnostics();
479
501
  const positions = findLocalizePositions(ast, options, utils);
480
502
  if (positions.length === 0 && !options.setLocale) {
@@ -6,9 +6,28 @@
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
+ };
9
28
  Object.defineProperty(exports, "__esModule", { value: true });
10
29
  exports.readTsconfig = void 0;
11
- const path = require("path");
30
+ const path = __importStar(require("path"));
12
31
  /**
13
32
  * Reads and parses a given TsConfig file.
14
33
  *
@@ -6,12 +6,31 @@
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
+ };
9
28
  Object.defineProperty(exports, "__esModule", { value: true });
10
29
  exports.augmentAppWithServiceWorker = void 0;
11
30
  const core_1 = require("@angular-devkit/core");
12
- const crypto = require("crypto");
31
+ const crypto = __importStar(require("crypto"));
13
32
  const fs_1 = require("fs");
14
- const path = require("path");
33
+ const path = __importStar(require("path"));
15
34
  const stream_1 = require("stream");
16
35
  class CliFilesystem {
17
36
  constructor(base) {
@@ -6,11 +6,13 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  export declare class Spinner {
9
+ #private;
9
10
  private readonly spinner;
10
11
  /** When false, only fail messages will be displayed. */
11
12
  enabled: boolean;
12
13
  constructor(text?: string);
13
14
  set text(text: string);
15
+ get isSpinning(): boolean;
14
16
  succeed(text?: string): void;
15
17
  fail(text?: string): void;
16
18
  stop(): void;
@@ -6,25 +6,40 @@
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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
10
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
11
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
12
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ var _Spinner_isTTY;
9
18
  Object.defineProperty(exports, "__esModule", { value: true });
10
19
  exports.Spinner = void 0;
11
- const ora = require("ora");
20
+ const ora_1 = __importDefault(require("ora"));
12
21
  const color_1 = require("./color");
22
+ const tty_1 = require("./tty");
13
23
  class Spinner {
14
24
  constructor(text) {
15
25
  /** When false, only fail messages will be displayed. */
16
26
  this.enabled = true;
17
- this.spinner = ora({
27
+ _Spinner_isTTY.set(this, tty_1.isTTY());
28
+ this.spinner = ora_1.default({
18
29
  text,
19
30
  // The below 2 options are needed because otherwise CTRL+C will be delayed
20
31
  // when the underlying process is sync.
21
32
  hideCursor: false,
22
33
  discardStdin: false,
34
+ isEnabled: __classPrivateFieldGet(this, _Spinner_isTTY, "f"),
23
35
  });
24
36
  }
25
37
  set text(text) {
26
38
  this.spinner.text = text;
27
39
  }
40
+ get isSpinning() {
41
+ return this.spinner.isSpinning || !__classPrivateFieldGet(this, _Spinner_isTTY, "f");
42
+ }
28
43
  succeed(text) {
29
44
  if (this.enabled) {
30
45
  this.spinner.succeed(text);
@@ -43,3 +58,4 @@ class Spinner {
43
58
  }
44
59
  }
45
60
  exports.Spinner = Spinner;
61
+ _Spinner_isTTY = new WeakMap();
@@ -6,10 +6,29 @@
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
+ };
9
28
  Object.defineProperty(exports, "__esModule", { value: true });
10
29
  exports.getIndexInputFile = exports.getIndexOutputFile = exports.generateBrowserWebpackConfigFromContext = exports.generateI18nBrowserWebpackConfigFromContext = exports.generateWebpackConfig = void 0;
11
30
  const core_1 = require("@angular-devkit/core");
12
- const path = require("path");
31
+ const path = __importStar(require("path"));
13
32
  const webpack_1 = require("webpack");
14
33
  const webpack_merge_1 = require("webpack-merge");
15
34
  const utils_1 = require("../utils");
@@ -23,7 +42,7 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, opt
23
42
  }
24
43
  const tsConfigPath = path.resolve(workspaceRoot, options.tsConfig);
25
44
  const tsConfig = read_tsconfig_1.readTsconfig(tsConfigPath);
26
- const ts = await Promise.resolve().then(() => require('typescript'));
45
+ const ts = await Promise.resolve().then(() => __importStar(require('typescript')));
27
46
  const scriptTarget = tsConfig.options.target || ts.ScriptTarget.ES5;
28
47
  const buildOptions = { ...options, ...extraBuildOptions };
29
48
  const wco = {
@@ -0,0 +1,11 @@
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
+ import { Configuration } from 'webpack';
10
+ import { WebpackConfigOptions } from '../../utils/build-options';
11
+ export declare function getAnalyticsConfig(wco: WebpackConfigOptions, context: BuilderContext): Configuration;
@@ -0,0 +1,29 @@
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.getAnalyticsConfig = void 0;
11
+ const analytics_1 = require("../plugins/analytics");
12
+ function getAnalyticsConfig(wco, context) {
13
+ if (!context.analytics) {
14
+ return {};
15
+ }
16
+ // If there's analytics, add our plugin. Otherwise no need to slow down the build.
17
+ let category = 'build';
18
+ if (context.builder) {
19
+ // We already vetted that this is a "safe" package, otherwise the analytics would be noop.
20
+ category = context.builder.builderName.split(':')[1] || context.builder.builderName || 'build';
21
+ }
22
+ // The category is the builder name if it's an angular builder.
23
+ return {
24
+ plugins: [
25
+ new analytics_1.NgBuildAnalyticsPlugin(wco.projectRoot, context.analytics, category, !!wco.tsConfig.options.enableIvy),
26
+ ],
27
+ };
28
+ }
29
+ exports.getAnalyticsConfig = getAnalyticsConfig;
@@ -6,12 +6,36 @@
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
32
  exports.getCommonConfig = void 0;
11
33
  const build_optimizer_1 = require("@angular-devkit/build-optimizer");
12
- const CopyWebpackPlugin = require("copy-webpack-plugin");
34
+ const compiler_cli_1 = require("@angular/compiler-cli");
35
+ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
36
+ const crypto_1 = require("crypto");
13
37
  const fs_1 = require("fs");
14
- const path = require("path");
38
+ const path = __importStar(require("path"));
15
39
  const typescript_1 = require("typescript");
16
40
  const webpack_1 = require("webpack");
17
41
  const utils_1 = require("../../utils");
@@ -22,10 +46,9 @@ const spinner_1 = require("../../utils/spinner");
22
46
  const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
23
47
  const plugins_1 = require("../plugins");
24
48
  const helpers_1 = require("../utils/helpers");
25
- const stats_1 = require("../utils/stats");
26
49
  // eslint-disable-next-line max-lines-per-function
27
50
  function getCommonConfig(wco) {
28
- var _a;
51
+ var _a, _b;
29
52
  const { root, projectRoot, buildOptions, tsConfig } = wco;
30
53
  const { platform = 'browser', sourceMap: { styles: stylesSourceMap, scripts: scriptsSourceMap, vendor: vendorSourceMap }, optimization: { styles: stylesOptimization, scripts: scriptsOptimization }, } = buildOptions;
31
54
  const extraPlugins = [];
@@ -35,6 +58,28 @@ function getCommonConfig(wco) {
35
58
  const hashFormat = helpers_1.getOutputHashFormat(buildOptions.outputHashing || 'none');
36
59
  const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot);
37
60
  const targetInFileName = helpers_1.getEsVersionForFileName(tsConfig.options.target, buildOptions.differentialLoadingNeeded);
61
+ if (buildOptions.progress) {
62
+ const spinner = new spinner_1.Spinner();
63
+ spinner.start(`Generating ${platform} application bundles (phase: setup)...`);
64
+ extraPlugins.push(new webpack_1.ProgressPlugin({
65
+ handler: (percentage, message) => {
66
+ const phase = message ? ` (phase: ${message})` : '';
67
+ spinner.text = `Generating ${platform} application bundles${phase}...`;
68
+ switch (percentage) {
69
+ case 1:
70
+ if (spinner.isSpinning) {
71
+ spinner.succeed(`${platform.replace(/^\w/, (s) => s.toUpperCase())} application bundle generation complete.`);
72
+ }
73
+ break;
74
+ case 0:
75
+ if (!spinner.isSpinning) {
76
+ spinner.start();
77
+ }
78
+ break;
79
+ }
80
+ },
81
+ }));
82
+ }
38
83
  if (buildOptions.main) {
39
84
  const mainPath = path.resolve(root, buildOptions.main);
40
85
  entryPoints['main'] = [mainPath];
@@ -157,36 +202,10 @@ function getCommonConfig(wco) {
157
202
  },
158
203
  };
159
204
  });
160
- extraPlugins.push(new CopyWebpackPlugin({
205
+ extraPlugins.push(new copy_webpack_plugin_1.default({
161
206
  patterns: copyWebpackPluginPatterns,
162
207
  }));
163
208
  }
164
- if (buildOptions.progress) {
165
- const spinner = new spinner_1.Spinner();
166
- let previousPercentage;
167
- extraPlugins.push(new webpack_1.ProgressPlugin({
168
- handler: (percentage, message) => {
169
- if (previousPercentage === 1 && percentage !== 0) {
170
- // In some scenarios in Webpack 5 percentage goes from 1 back to 0.99.
171
- // Ex: 0.99 -> 1 -> 0.99 -> 1
172
- // This causes the "complete" message to be displayed multiple times.
173
- return;
174
- }
175
- switch (percentage) {
176
- case 0:
177
- spinner.start(`Generating ${platform} application bundles...`);
178
- break;
179
- case 1:
180
- spinner.succeed(`${platform.replace(/^\w/, (s) => s.toUpperCase())} application bundle generation complete.`);
181
- break;
182
- default:
183
- spinner.text = `Generating ${platform} application bundles (phase: ${message})...`;
184
- break;
185
- }
186
- previousPercentage = percentage;
187
- },
188
- }));
189
- }
190
209
  if (buildOptions.showCircularDependencies) {
191
210
  const CircularDependencyPlugin = require('circular-dependency-plugin');
192
211
  extraPlugins.push(new CircularDependencyPlugin({
@@ -197,7 +216,7 @@ function getCommonConfig(wco) {
197
216
  extraPlugins.push(new (class {
198
217
  apply(compiler) {
199
218
  compiler.hooks.done.tapPromise('angular-cli-stats', async (stats) => {
200
- const { stringifyStream } = await Promise.resolve().then(() => require('@discoveryjs/json-ext'));
219
+ const { stringifyStream } = await Promise.resolve().then(() => __importStar(require('@discoveryjs/json-ext')));
201
220
  const data = stats.toJson('verbose');
202
221
  const statsOutputPath = path.resolve(root, buildOptions.outputPath, 'stats.json');
203
222
  try {
@@ -223,7 +242,7 @@ function getCommonConfig(wco) {
223
242
  });
224
243
  }
225
244
  let buildOptimizerUseRule = [];
226
- if (buildOptions.buildOptimizer) {
245
+ if (buildOptions.buildOptimizer && wco.scriptTarget < typescript_1.ScriptTarget.ES2015) {
227
246
  extraPlugins.push(new build_optimizer_1.BuildOptimizerWebpackPlugin());
228
247
  buildOptimizerUseRule = [
229
248
  {
@@ -235,10 +254,9 @@ function getCommonConfig(wco) {
235
254
  const extraMinimizers = [];
236
255
  if (scriptsOptimization) {
237
256
  const TerserPlugin = require('terser-webpack-plugin');
238
- const { GLOBAL_DEFS_FOR_TERSER, GLOBAL_DEFS_FOR_TERSER_WITH_AOT, } = require('@angular/compiler-cli');
239
257
  const angularGlobalDefinitions = buildOptions.aot
240
- ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT
241
- : GLOBAL_DEFS_FOR_TERSER;
258
+ ? compiler_cli_1.GLOBAL_DEFS_FOR_TERSER_WITH_AOT
259
+ : compiler_cli_1.GLOBAL_DEFS_FOR_TERSER;
242
260
  // TODO: Investigate why this fails for some packages: wco.supportES2015 ? 6 : 5;
243
261
  const terserEcma = 5;
244
262
  const terserOptions = {
@@ -326,9 +344,9 @@ function getCommonConfig(wco) {
326
344
  context: root,
327
345
  entry: entryPoints,
328
346
  output: {
329
- clean: buildOptions.deleteOutputPath,
347
+ clean: (_a = buildOptions.deleteOutputPath) !== null && _a !== void 0 ? _a : true,
330
348
  path: path.resolve(root, buildOptions.outputPath),
331
- publicPath: (_a = buildOptions.deployUrl) !== null && _a !== void 0 ? _a : '',
349
+ publicPath: (_b = buildOptions.deployUrl) !== null && _b !== void 0 ? _b : '',
332
350
  filename: ({ chunk }) => {
333
351
  if ((chunk === null || chunk === void 0 ? void 0 : chunk.name) === 'polyfills-es5') {
334
352
  return `polyfills-es5${hashFormat.chunk}.js`;
@@ -337,14 +355,22 @@ function getCommonConfig(wco) {
337
355
  return `[name]${targetInFileName}${hashFormat.chunk}.js`;
338
356
  }
339
357
  },
340
- chunkFilename: `[id]${targetInFileName}${hashFormat.chunk}.js`,
358
+ chunkFilename: `[name]${targetInFileName}${hashFormat.chunk}.js`,
341
359
  },
342
360
  watch: buildOptions.watch,
343
361
  watchOptions: helpers_1.getWatchOptions(buildOptions.poll),
344
362
  performance: {
345
363
  hints: false,
346
364
  },
347
- ignoreWarnings: stats_1.IGNORE_WARNINGS,
365
+ ignoreWarnings: [
366
+ // Webpack 5+ has no facility to disable this warning.
367
+ // System.import is used in @angular/core for deprecated string-form lazy routes
368
+ /System.import\(\) is deprecated and will be removed soon/i,
369
+ // https://github.com/webpack-contrib/source-map-loader/blob/b2de4249c7431dd8432da607e08f0f65e9d64219/src/index.js#L83
370
+ /Failed to parse source map from/,
371
+ // https://github.com/webpack-contrib/postcss-loader/blob/bd261875fdf9c596af4ffb3a1a73fe3c549befda/src/index.js#L153-L158
372
+ /Add postcss as project dependency/,
373
+ ],
348
374
  module: {
349
375
  // Show an error for missing exports instead of a warning.
350
376
  strictExportPresence: true,
@@ -374,6 +400,7 @@ function getCommonConfig(wco) {
374
400
  cacheDirectory: cache_path_1.findCachePath('babel-webpack'),
375
401
  scriptTarget: wco.scriptTarget,
376
402
  aot: buildOptions.aot,
403
+ optimize: buildOptions.buildOptimizer && wco.scriptTarget >= typescript_1.ScriptTarget.ES2015,
377
404
  },
378
405
  },
379
406
  ...buildOptimizerUseRule,
@@ -386,11 +413,7 @@ function getCommonConfig(wco) {
386
413
  syncWebAssembly: true,
387
414
  asyncWebAssembly: true,
388
415
  },
389
- cache: !!buildOptions.watch &&
390
- !environment_options_1.cachingDisabled && {
391
- type: 'memory',
392
- maxGenerations: 1,
393
- },
416
+ cache: getCacheSettings(wco, buildBrowserFeatures.supportedBrowsers),
394
417
  optimization: {
395
418
  minimizer: extraMinimizers,
396
419
  moduleIds: 'deterministic',
@@ -407,3 +430,31 @@ function getCommonConfig(wco) {
407
430
  };
408
431
  }
409
432
  exports.getCommonConfig = getCommonConfig;
433
+ function getCacheSettings(wco, supportedBrowsers) {
434
+ if (environment_options_1.persistentBuildCacheEnabled) {
435
+ const packageVersion = require('../../../package.json').version;
436
+ return {
437
+ type: 'filesystem',
438
+ cacheDirectory: cache_path_1.findCachePath('angular-webpack'),
439
+ maxMemoryGenerations: 1,
440
+ // We use the versions and build options as the cache name. The Webpack configurations are too
441
+ // dynamic and shared among different build types: test, build and serve.
442
+ // None of which are "named".
443
+ name: crypto_1.createHash('sha1')
444
+ .update(compiler_cli_1.VERSION.full)
445
+ .update(packageVersion)
446
+ .update(wco.projectRoot)
447
+ .update(JSON.stringify(wco.tsConfig))
448
+ .update(JSON.stringify(wco.buildOptions))
449
+ .update(supportedBrowsers.join(''))
450
+ .digest('base64'),
451
+ };
452
+ }
453
+ if (wco.buildOptions.watch && !environment_options_1.cachingDisabled) {
454
+ return {
455
+ type: 'memory',
456
+ maxGenerations: 1,
457
+ };
458
+ }
459
+ return false;
460
+ }
@@ -6,12 +6,31 @@
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
+ };
9
28
  Object.defineProperty(exports, "__esModule", { value: true });
10
29
  exports.buildServePath = exports.getDevServerConfig = void 0;
11
30
  const core_1 = require("@angular-devkit/core");
12
31
  const fs_1 = require("fs");
13
32
  const path_1 = require("path");
14
- const url = require("url");
33
+ const url = __importStar(require("url"));
15
34
  const utils_1 = require("../../utils");
16
35
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
17
36
  const hmr_loader_1 = require("../plugins/hmr/hmr-loader");
@@ -5,6 +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
+ export * from './analytics';
8
9
  export * from './browser';
9
10
  export * from './common';
10
11
  export * from './dev-server';
@@ -17,6 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./analytics"), exports);
20
21
  __exportStar(require("./browser"), exports);
21
22
  __exportStar(require("./common"), exports);
22
23
  __exportStar(require("./dev-server"), exports);
@@ -34,6 +34,14 @@ function getServerConfig(wco) {
34
34
  output: {
35
35
  libraryTarget: 'commonjs',
36
36
  },
37
+ module: {
38
+ parser: {
39
+ javascript: {
40
+ worker: false,
41
+ url: false,
42
+ },
43
+ },
44
+ },
37
45
  plugins: [
38
46
  // Fixes Critical dependency: the request of a dependency is an expression
39
47
  new webpack_1.ContextReplacementPlugin(/@?hapi(\\|\/)/),