@angular-devkit/build-angular 15.0.0-next.1 → 15.0.0-next.3

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 (75) hide show
  1. package/package.json +15 -17
  2. package/src/babel/presets/application.d.ts +1 -2
  3. package/src/babel/presets/application.js +1 -4
  4. package/src/babel/webpack-loader.js +8 -22
  5. package/src/builders/app-shell/index.js +16 -8
  6. package/src/builders/browser/index.d.ts +1 -1
  7. package/src/builders/browser/index.js +4 -16
  8. package/src/builders/browser/schema.d.ts +6 -2
  9. package/src/builders/browser/schema.json +18 -4
  10. package/src/builders/browser-esbuild/compiler-plugin.d.ts +1 -0
  11. package/src/builders/browser-esbuild/compiler-plugin.js +20 -17
  12. package/src/builders/browser-esbuild/experimental-warnings.js +0 -1
  13. package/src/builders/browser-esbuild/index.js +18 -5
  14. package/src/builders/browser-esbuild/options.js +6 -1
  15. package/src/builders/browser-esbuild/schema.d.ts +8 -6
  16. package/src/builders/browser-esbuild/schema.json +29 -34
  17. package/src/builders/browser-esbuild/stylesheets.d.ts +1 -0
  18. package/src/builders/browser-esbuild/stylesheets.js +1 -0
  19. package/src/builders/extract-i18n/index.js +1 -1
  20. package/src/builders/karma/find-tests-plugin.d.ts +19 -0
  21. package/src/builders/karma/{find-tests.js → find-tests-plugin.js} +49 -5
  22. package/src/builders/karma/index.js +40 -38
  23. package/src/builders/karma/schema.d.ts +7 -3
  24. package/src/builders/karma/schema.json +20 -5
  25. package/src/builders/server/index.d.ts +1 -1
  26. package/src/builders/server/index.js +42 -10
  27. package/src/builders/server/platform-server-exports-loader.d.ts +13 -0
  28. package/src/builders/server/platform-server-exports-loader.js +24 -0
  29. package/src/builders/server/schema.d.ts +0 -5
  30. package/src/builders/server/schema.json +0 -5
  31. package/src/sass/sass-service-legacy.d.ts +51 -0
  32. package/src/sass/sass-service-legacy.js +175 -0
  33. package/src/sass/sass-service.d.ts +6 -9
  34. package/src/sass/sass-service.js +69 -52
  35. package/src/{builders/karma/find-tests.d.ts → sass/worker-legacy.d.ts} +1 -1
  36. package/src/sass/worker-legacy.js +44 -0
  37. package/src/sass/worker.js +64 -14
  38. package/src/utils/build-options.d.ts +2 -4
  39. package/src/utils/environment-options.d.ts +1 -0
  40. package/src/utils/environment-options.js +11 -1
  41. package/src/utils/esbuild-targets.d.ts +12 -0
  42. package/src/utils/esbuild-targets.js +39 -0
  43. package/src/utils/i18n-inlining.d.ts +1 -1
  44. package/src/utils/i18n-inlining.js +3 -4
  45. package/src/utils/normalize-builder-schema.d.ts +3 -2
  46. package/src/utils/normalize-builder-schema.js +5 -4
  47. package/src/utils/normalize-polyfills.d.ts +8 -0
  48. package/src/utils/normalize-polyfills.js +24 -0
  49. package/src/utils/process-bundle.d.ts +0 -1
  50. package/src/utils/process-bundle.js +29 -57
  51. package/src/utils/supported-browsers.d.ts +2 -1
  52. package/src/utils/supported-browsers.js +18 -2
  53. package/src/utils/webpack-browser-config.d.ts +0 -2
  54. package/src/utils/webpack-browser-config.js +2 -8
  55. package/src/utils/webpack-diagnostics.d.ts +1 -1
  56. package/src/utils/webpack-diagnostics.js +2 -3
  57. package/src/webpack/configs/common.js +37 -24
  58. package/src/webpack/configs/dev-server.js +1 -1
  59. package/src/webpack/configs/styles.js +63 -80
  60. package/src/webpack/plugins/any-component-style-budget-checker.js +1 -1
  61. package/src/webpack/plugins/css-optimizer-plugin.d.ts +0 -1
  62. package/src/webpack/plugins/css-optimizer-plugin.js +3 -26
  63. package/src/webpack/plugins/hmr/hmr-loader.d.ts +1 -1
  64. package/src/webpack/plugins/hmr/hmr-loader.js +2 -5
  65. package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +4 -6
  66. package/src/webpack/plugins/javascript-optimizer-plugin.js +7 -16
  67. package/src/webpack/plugins/javascript-optimizer-worker.d.ts +3 -2
  68. package/src/webpack/plugins/javascript-optimizer-worker.js +21 -46
  69. package/src/webpack/plugins/karma/karma.js +4 -5
  70. package/src/webpack/plugins/transfer-size-plugin.js +2 -1
  71. package/src/webpack/plugins/typescript.js +14 -25
  72. package/src/webpack/utils/helpers.d.ts +0 -3
  73. package/src/webpack/utils/helpers.js +1 -36
  74. package/src/webpack/plugins/single-test-transform.d.ts +0 -27
  75. package/src/webpack/plugins/single-test-transform.js +0 -44
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "15.0.0-next.1",
3
+ "version": "15.0.0-next.3",
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": "2.2.0",
10
- "@angular-devkit/architect": "0.1500.0-next.1",
11
- "@angular-devkit/build-webpack": "0.1500.0-next.1",
12
- "@angular-devkit/core": "15.0.0-next.1",
13
- "@babel/core": "7.19.0",
14
- "@babel/generator": "7.19.0",
10
+ "@angular-devkit/architect": "0.1500.0-next.3",
11
+ "@angular-devkit/build-webpack": "0.1500.0-next.3",
12
+ "@angular-devkit/core": "15.0.0-next.3",
13
+ "@babel/core": "7.19.3",
14
+ "@babel/generator": "7.19.3",
15
15
  "@babel/helper-annotate-as-pure": "7.18.6",
16
- "@babel/plugin-proposal-async-generator-functions": "7.19.0",
16
+ "@babel/plugin-proposal-async-generator-functions": "7.19.1",
17
17
  "@babel/plugin-transform-async-to-generator": "7.18.6",
18
- "@babel/plugin-transform-runtime": "7.18.10",
19
- "@babel/preset-env": "7.19.0",
18
+ "@babel/plugin-transform-runtime": "7.19.1",
19
+ "@babel/preset-env": "7.19.3",
20
20
  "@babel/runtime": "7.19.0",
21
21
  "@babel/template": "7.18.10",
22
22
  "@discoveryjs/json-ext": "0.5.7",
23
- "@ngtools/webpack": "15.0.0-next.1",
23
+ "@ngtools/webpack": "15.0.0-next.3",
24
24
  "ansi-colors": "4.1.3",
25
- "autoprefixer": "10.4.10",
25
+ "autoprefixer": "10.4.12",
26
26
  "babel-loader": "8.2.5",
27
27
  "babel-plugin-istanbul": "6.1.1",
28
28
  "browserslist": "^4.9.1",
@@ -30,7 +30,7 @@
30
30
  "copy-webpack-plugin": "11.0.0",
31
31
  "critters": "0.0.16",
32
32
  "css-loader": "6.7.1",
33
- "esbuild-wasm": "0.15.7",
33
+ "esbuild-wasm": "0.15.9",
34
34
  "glob": "8.0.3",
35
35
  "https-proxy-agent": "5.0.1",
36
36
  "inquirer": "8.2.4",
@@ -52,25 +52,23 @@
52
52
  "regenerator-runtime": "0.13.9",
53
53
  "resolve-url-loader": "5.0.0",
54
54
  "rxjs": "6.6.7",
55
- "sass": "1.54.9",
55
+ "sass": "1.55.0",
56
56
  "sass-loader": "13.0.2",
57
57
  "semver": "7.3.7",
58
58
  "source-map-loader": "4.0.0",
59
59
  "source-map-support": "0.5.21",
60
- "stylus": "0.59.0",
61
- "stylus-loader": "7.0.0",
62
60
  "terser": "5.15.0",
63
61
  "text-table": "0.2.0",
64
62
  "tree-kill": "1.2.2",
65
63
  "tslib": "2.4.0",
66
64
  "webpack": "5.74.0",
67
65
  "webpack-dev-middleware": "5.3.3",
68
- "webpack-dev-server": "4.11.0",
66
+ "webpack-dev-server": "4.11.1",
69
67
  "webpack-merge": "5.8.0",
70
68
  "webpack-subresource-integrity": "5.1.0"
71
69
  },
72
70
  "optionalDependencies": {
73
- "esbuild": "0.15.7"
71
+ "esbuild": "0.15.9"
74
72
  },
75
73
  "peerDependencies": {
76
74
  "@angular/compiler-cli": "^15.0.0-next",
@@ -6,7 +6,7 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import type { ɵParsedTranslation } from '@angular/localize';
9
- import type { makeEs2015TranslatePlugin, makeEs5TranslatePlugin, makeLocalePlugin } from '@angular/localize/tools';
9
+ import type { makeEs2015TranslatePlugin, makeLocalePlugin } from '@angular/localize/tools';
10
10
  export declare type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: string) => void;
11
11
  /**
12
12
  * An interface representing the factory functions for the `@angular/localize` translation Babel plugins.
@@ -16,7 +16,6 @@ export declare type DiagnosticReporter = (type: 'error' | 'warning' | 'info', me
16
16
  */
17
17
  export interface I18nPluginCreators {
18
18
  makeEs2015TranslatePlugin: typeof makeEs2015TranslatePlugin;
19
- makeEs5TranslatePlugin: typeof makeEs5TranslatePlugin;
20
19
  makeLocalePlugin: typeof makeLocalePlugin;
21
20
  }
22
21
  export interface ApplicationPresetOptions {
@@ -67,14 +67,11 @@ function createI18nDiagnostics(reporter) {
67
67
  function createI18nPlugins(locale, translation, missingTranslationBehavior, diagnosticReporter, pluginCreators) {
68
68
  const diagnostics = createI18nDiagnostics(diagnosticReporter);
69
69
  const plugins = [];
70
- const { makeEs5TranslatePlugin, makeEs2015TranslatePlugin, makeLocalePlugin } = pluginCreators;
70
+ const { makeEs2015TranslatePlugin, makeLocalePlugin } = pluginCreators;
71
71
  if (translation) {
72
72
  plugins.push(makeEs2015TranslatePlugin(diagnostics, translation, {
73
73
  missingTranslation: missingTranslationBehavior,
74
74
  }));
75
- plugins.push(makeEs5TranslatePlugin(diagnostics, translation, {
76
- missingTranslation: missingTranslationBehavior,
77
- }));
78
75
  }
79
76
  plugins.push(makeLocalePlugin(locale));
80
77
  return plugins;
@@ -9,7 +9,6 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.requiresLinking = void 0;
11
11
  const babel_loader_1 = require("babel-loader");
12
- const typescript_1 = require("typescript");
13
12
  const load_esm_1 = require("../utils/load-esm");
14
13
  const package_version_1 = require("../utils/package-version");
15
14
  /**
@@ -53,7 +52,7 @@ exports.default = (0, babel_loader_1.custom)(() => {
53
52
  return {
54
53
  async customOptions(options, { source, map }) {
55
54
  var _a, _b, _c;
56
- const { i18n, scriptTarget, aot, optimize, instrumentCode, supportedBrowsers, ...rawOptions } = options;
55
+ const { i18n, aot, optimize, instrumentCode, supportedBrowsers, ...rawOptions } = options;
57
56
  // Must process file if plugins are added
58
57
  let shouldProcess = Array.isArray(rawOptions.plugins) && rawOptions.plugins.length > 0;
59
58
  const customOptions = {
@@ -78,31 +77,18 @@ exports.default = (0, babel_loader_1.custom)(() => {
78
77
  shouldProcess = true;
79
78
  }
80
79
  // Analyze for ES target processing
81
- const esTarget = scriptTarget;
82
- const isJsFile = /\.[cm]?js$/.test(this.resourcePath);
83
- // The below should be dropped when we no longer support ES5 TypeScript output.
84
- if (esTarget === typescript_1.ScriptTarget.ES5) {
85
- // This is needed because when target is ES5 we change the TypeScript target to ES2015
86
- // because it simplifies build-optimization passes.
87
- // @see https://github.com/angular/angular-cli/blob/22af6520834171d01413d4c7e4a9f13fb752252e/packages/angular_devkit/build_angular/src/webpack/plugins/typescript.ts#L51-L56
88
- customOptions.forcePresetEnv = true;
89
- // Comparable behavior to tsconfig target of ES5
90
- customOptions.supportedBrowsers = ['IE 9'];
91
- }
92
- else if (isJsFile && ((_a = customOptions.supportedBrowsers) === null || _a === void 0 ? void 0 : _a.length)) {
80
+ if ((_a = customOptions.supportedBrowsers) === null || _a === void 0 ? void 0 : _a.length) {
93
81
  // Applications code ES version can be controlled using TypeScript's `target` option.
94
82
  // However, this doesn't effect libraries and hence we use preset-env to downlevel ES fetaures
95
83
  // based on the supported browsers in browserlist.
96
84
  customOptions.forcePresetEnv = true;
97
85
  }
98
- if ((esTarget !== undefined && esTarget >= typescript_1.ScriptTarget.ES2017) || isJsFile) {
99
- // Application code (TS files) will only contain native async if target is ES2017+.
100
- // However, third-party libraries can regardless of the target option.
101
- // APF packages with code in [f]esm2015 directories is downlevelled to ES2015 and
102
- // will not have native async.
103
- customOptions.forceAsyncTransformation =
104
- !/[\\/][_f]?esm2015[\\/]/.test(this.resourcePath) && source.includes('async');
105
- }
86
+ // Application code (TS files) will only contain native async if target is ES2017+.
87
+ // However, third-party libraries can regardless of the target option.
88
+ // APF packages with code in [f]esm2015 directories is downlevelled to ES2015 and
89
+ // will not have native async.
90
+ customOptions.forceAsyncTransformation =
91
+ !/[\\/][_f]?esm2015[\\/]/.test(this.resourcePath) && source.includes('async');
106
92
  shouldProcess || (shouldProcess = customOptions.forceAsyncTransformation || customOptions.forcePresetEnv || false);
107
93
  // Analyze for i18n inlining
108
94
  if (i18n &&
@@ -29,8 +29,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  __setModuleDefault(result, mod);
30
30
  return result;
31
31
  };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
32
35
  Object.defineProperty(exports, "__esModule", { value: true });
33
36
  const architect_1 = require("@angular-devkit/architect");
37
+ const assert_1 = __importDefault(require("assert"));
34
38
  const fs = __importStar(require("fs"));
35
39
  const path = __importStar(require("path"));
36
40
  const utils_1 = require("../../utils");
@@ -67,17 +71,21 @@ async function _renderUniversal(options, context, browserResult, serverResult, s
67
71
  const browserIndexOutputPath = path.join(outputPath, 'index.html');
68
72
  const indexHtml = await fs.promises.readFile(browserIndexOutputPath, 'utf8');
69
73
  const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult, localeDirectory);
70
- const { AppServerModule, renderModule } = await Promise.resolve().then(() => __importStar(require(serverBundlePath)));
71
- const renderModuleFn = renderModule;
72
- if (!(renderModuleFn && AppServerModule)) {
73
- throw new Error(`renderModule method and/or AppServerModule were not exported from: ${serverBundlePath}.`);
74
- }
74
+ const { AppServerModule, renderModule, ɵSERVER_CONTEXT } = (await Promise.resolve().then(() => __importStar(require(serverBundlePath))));
75
+ (0, assert_1.default)(renderModule, `renderModule was not exported from: ${serverBundlePath}.`);
76
+ (0, assert_1.default)(AppServerModule, `AppServerModule was not exported from: ${serverBundlePath}.`);
77
+ (0, assert_1.default)(ɵSERVER_CONTEXT, `ɵSERVER_CONTEXT was not exported from: ${serverBundlePath}.`);
75
78
  // Load platform server module renderer
76
- const renderOpts = {
79
+ let html = await renderModule(AppServerModule, {
77
80
  document: indexHtml,
78
81
  url: options.route,
79
- };
80
- let html = await renderModuleFn(AppServerModule, renderOpts);
82
+ extraProviders: [
83
+ {
84
+ provide: ɵSERVER_CONTEXT,
85
+ useValue: 'app-shell',
86
+ },
87
+ ],
88
+ });
81
89
  // Overwrite the client index file.
82
90
  const outputIndexPath = options.outputIndexPath
83
91
  ? path.join(root, options.outputIndexPath)
@@ -44,5 +44,5 @@ export declare function buildWebpackBrowser(options: BrowserBuilderSchema, conte
44
44
  logging?: WebpackLoggingCallback;
45
45
  indexHtml?: IndexHtmlTransform;
46
46
  }): Observable<BrowserBuilderOutput>;
47
- declare const _default: import("@angular-devkit/architect/src/internal").Builder<BrowserBuilderSchema & import("@angular-devkit/core").JsonObject>;
47
+ declare const _default: import("@angular-devkit/architect/src/internal").Builder<BrowserBuilderSchema & import("../../../../core/src").JsonObject>;
48
48
  export default _default;
@@ -37,7 +37,6 @@ const fs = __importStar(require("fs"));
37
37
  const path = __importStar(require("path"));
38
38
  const rxjs_1 = require("rxjs");
39
39
  const operators_1 = require("rxjs/operators");
40
- const typescript_1 = require("typescript");
41
40
  const utils_1 = require("../../utils");
42
41
  const bundle_calculator_1 = require("../../utils/bundle-calculator");
43
42
  const color_1 = require("../../utils/color");
@@ -51,7 +50,6 @@ const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
51
50
  const purge_cache_1 = require("../../utils/purge-cache");
52
51
  const service_worker_1 = require("../../utils/service-worker");
53
52
  const spinner_1 = require("../../utils/spinner");
54
- const supported_browsers_1 = require("../../utils/supported-browsers");
55
53
  const version_1 = require("../../utils/version");
56
54
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
57
55
  const configs_1 = require("../../webpack/configs");
@@ -68,7 +66,7 @@ async function initialize(options, context, webpackConfigurationTransform) {
68
66
  const originalOutputPath = options.outputPath;
69
67
  // Assets are processed directly by the builder except when watching
70
68
  const adjustedOptions = options.watch ? options : { ...options, assets: [] };
71
- const { config, projectRoot, projectSourceRoot, i18n, target } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)(adjustedOptions, context, (wco) => [
69
+ const { config, projectRoot, projectSourceRoot, i18n } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)(adjustedOptions, context, (wco) => [
72
70
  (0, configs_1.getCommonConfig)(wco),
73
71
  (0, configs_1.getStylesConfig)(wco),
74
72
  (0, configs_1.getAnalyticsConfig)(wco, context),
@@ -88,7 +86,7 @@ async function initialize(options, context, webpackConfigurationTransform) {
88
86
  if (options.deleteOutputPath) {
89
87
  (0, utils_1.deleteOutputDir)(context.workspaceRoot, originalOutputPath);
90
88
  }
91
- return { config: transformedConfig || config, projectRoot, projectSourceRoot, i18n, target };
89
+ return { config: transformedConfig || config, projectRoot, projectSourceRoot, i18n };
92
90
  }
93
91
  /**
94
92
  * @experimental Direct usage of this function is considered experimental.
@@ -111,8 +109,6 @@ function buildWebpackBrowser(options, context, transforms = {}) {
111
109
  await (0, purge_cache_1.purgeStaleBuildCache)(context);
112
110
  // Initialize builder
113
111
  const initialization = await initialize(options, context, transforms.webpackConfiguration);
114
- // Check and warn about IE browser support
115
- checkInternetExplorerSupport(initialization.projectRoot, context.logger);
116
112
  // Add index file to watched files.
117
113
  if (options.watch) {
118
114
  const indexInputFile = path.join(context.workspaceRoot, (0, webpack_browser_config_1.getIndexInputFile)(options.index));
@@ -131,7 +127,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
131
127
  };
132
128
  }), (0, operators_1.switchMap)(
133
129
  // eslint-disable-next-line max-lines-per-function
134
- ({ config, projectRoot, projectSourceRoot, i18n, target, cacheOptions }) => {
130
+ ({ config, projectRoot, projectSourceRoot, i18n, cacheOptions }) => {
135
131
  const normalizedOptimization = (0, utils_1.normalizeOptimization)(options.optimization);
136
132
  return (0, build_webpack_1.runWebpack)(config, context, {
137
133
  webpackFactory: require('webpack'),
@@ -174,7 +170,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
174
170
  outputPaths = (0, output_paths_1.ensureOutputPaths)(baseOutputPath, i18n);
175
171
  const scriptsEntryPointName = (0, helpers_1.normalizeExtraEntryPoints)(options.scripts || [], 'scripts').map((x) => x.bundleName);
176
172
  if (i18n.shouldInline) {
177
- const success = await (0, i18n_inlining_1.i18nInlineEmittedFiles)(context, emittedFiles, i18n, baseOutputPath, Array.from(outputPaths.values()), scriptsEntryPointName, webpackOutputPath, target <= typescript_1.ScriptTarget.ES5, options.i18nMissingTranslation);
173
+ const success = await (0, i18n_inlining_1.i18nInlineEmittedFiles)(context, emittedFiles, i18n, baseOutputPath, Array.from(outputPaths.values()), scriptsEntryPointName, webpackOutputPath, options.i18nMissingTranslation);
178
174
  if (!success) {
179
175
  return { success: false };
180
176
  }
@@ -330,12 +326,4 @@ function mapEmittedFilesToFileInfo(files = []) {
330
326
  }
331
327
  return filteredFiles;
332
328
  }
333
- function checkInternetExplorerSupport(projectRoot, logger) {
334
- const supportedBrowsers = (0, supported_browsers_1.getSupportedBrowsers)(projectRoot);
335
- if (supportedBrowsers.some((b) => b === 'ie 9' || b === 'ie 10' || b === 'ie 11')) {
336
- logger.warn(`Warning: Support was requested for Internet Explorer in the project's browserslist configuration. ` +
337
- 'Internet Explorer is no longer officially supported.' +
338
- '\nFor more information, see https://angular.io/guide/browser-support');
339
- }
340
- }
341
329
  exports.default = (0, architect_1.createBuilder)(buildWebpackBrowser);
@@ -106,9 +106,9 @@ export interface Schema {
106
106
  */
107
107
  poll?: number;
108
108
  /**
109
- * The full path for the polyfills file, relative to the current workspace.
109
+ * Polyfills to be included in the build.
110
110
  */
111
- polyfills?: string;
111
+ polyfills?: Polyfills;
112
112
  /**
113
113
  * Do not use the real path when resolving modules. If unset then will default to `true` if
114
114
  * NodeJS option --preserve-symlinks is set.
@@ -359,6 +359,10 @@ export declare enum OutputHashing {
359
359
  Media = "media",
360
360
  None = "none"
361
361
  }
362
+ /**
363
+ * Polyfills to be included in the build.
364
+ */
365
+ export declare type Polyfills = string[] | string;
362
366
  export declare type ScriptElement = ScriptClass | string;
363
367
  export interface ScriptClass {
364
368
  /**
@@ -17,8 +17,22 @@
17
17
  "description": "The full path for the main entry point to the app, relative to the current workspace."
18
18
  },
19
19
  "polyfills": {
20
- "type": "string",
21
- "description": "The full path for the polyfills file, relative to the current workspace."
20
+ "description": "Polyfills to be included in the build.",
21
+ "oneOf": [
22
+ {
23
+ "type": "array",
24
+ "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.",
25
+ "items": {
26
+ "type": "string",
27
+ "uniqueItems": true
28
+ },
29
+ "default": []
30
+ },
31
+ {
32
+ "type": "string",
33
+ "description": "The full path for the polyfills file, relative to the current workspace or a module specifier. Example: 'zone.js'."
34
+ }
35
+ ]
22
36
  },
23
37
  "tsConfig": {
24
38
  "type": "string",
@@ -72,7 +86,7 @@
72
86
  "input": {
73
87
  "type": "string",
74
88
  "description": "The file to include.",
75
- "pattern": "\\.(?:css|scss|sass|less|styl)$"
89
+ "pattern": "\\.(?:css|scss|sass|less)$"
76
90
  },
77
91
  "bundleName": {
78
92
  "type": "string",
@@ -91,7 +105,7 @@
91
105
  {
92
106
  "type": "string",
93
107
  "description": "The file to include.",
94
- "pattern": "\\.(?:css|scss|sass|less|styl)$"
108
+ "pattern": "\\.(?:css|scss|sass|less)$"
95
109
  }
96
110
  ]
97
111
  }
@@ -12,4 +12,5 @@ export declare function createCompilerPlugin(pluginOptions: {
12
12
  tsconfig: string;
13
13
  advancedOptimizations?: boolean;
14
14
  thirdPartySourcemaps?: boolean;
15
+ fileReplacements?: Record<string, string>;
15
16
  }, styleOptions: BundleStylesheetOptions): Plugin;
@@ -113,15 +113,15 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
113
113
  name: 'angular-compiler',
114
114
  // eslint-disable-next-line max-lines-per-function
115
115
  async setup(build) {
116
- var _a;
117
- var _b;
116
+ var _a, _b;
117
+ var _c;
118
118
  // This uses a wrapped dynamic import to load `@angular/compiler-cli` which is ESM.
119
119
  // Once TypeScript provides support for retaining dynamic imports this workaround can be dropped.
120
120
  const compilerCli = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli');
121
121
  // Temporary deep import for transformer support
122
122
  const { mergeTransformers, replaceBootstrap, } = require('@ngtools/webpack/src/ivy/transformation');
123
123
  // Setup defines based on the values provided by the Angular compiler-cli
124
- (_a = (_b = build.initialOptions).define) !== null && _a !== void 0 ? _a : (_b.define = {});
124
+ (_a = (_c = build.initialOptions).define) !== null && _a !== void 0 ? _a : (_c.define = {});
125
125
  for (const [key, value] of Object.entries(compilerCli.GLOBAL_DEFS_FOR_TERSER_WITH_AOT)) {
126
126
  if (key in build.initialOptions.define) {
127
127
  // Skip keys that have been manually provided
@@ -148,16 +148,13 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
148
148
  annotationsAs: 'decorators',
149
149
  enableResourceInlining: false,
150
150
  });
151
- // Adjust the esbuild output target based on the tsconfig target
152
- if (compilerOptions.target === undefined ||
153
- compilerOptions.target <= typescript_1.default.ScriptTarget.ES2015) {
154
- build.initialOptions.target = 'es2015';
155
- }
156
- else if (compilerOptions.target >= typescript_1.default.ScriptTarget.ESNext) {
157
- build.initialOptions.target = 'esnext';
158
- }
159
- else {
160
- build.initialOptions.target = typescript_1.default.ScriptTarget[compilerOptions.target].toLowerCase();
151
+ if (compilerOptions.target === undefined || compilerOptions.target < typescript_1.default.ScriptTarget.ES2022) {
152
+ // If 'useDefineForClassFields' is already defined in the users project leave the value as is.
153
+ // Otherwise fallback to false due to https://github.com/microsoft/TypeScript/issues/45995
154
+ // which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
155
+ compilerOptions.target = typescript_1.default.ScriptTarget.ES2022;
156
+ (_b = compilerOptions.useDefineForClassFields) !== null && _b !== void 0 ? _b : (compilerOptions.useDefineForClassFields = false);
157
+ // TODO: show warning about this override when we have access to the logger.
161
158
  }
162
159
  // The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
163
160
  let fileEmitter;
@@ -204,6 +201,12 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
204
201
  stylesheetResourceFiles.push(...resourceFiles);
205
202
  return { content: contents };
206
203
  };
204
+ // Augment TypeScript Host for file replacements option
205
+ if (pluginOptions.fileReplacements) {
206
+ // Temporary deep import for file replacements support
207
+ const { augmentHostWithReplacements } = require('@ngtools/webpack/src/ivy/host');
208
+ augmentHostWithReplacements(host, pluginOptions.fileReplacements);
209
+ }
207
210
  // Create the Angular specific program that contains the Angular compiler
208
211
  const angularProgram = new compilerCli.NgtscProgram(rootNames, compilerOptions, host);
209
212
  const angularCompiler = angularProgram.compiler;
@@ -244,9 +247,9 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
244
247
  return result;
245
248
  });
246
249
  build.onLoad({ filter: compilerOptions.allowJs ? /\.[cm]?[jt]sx?$/ : /\.[cm]?tsx?$/ }, async (args) => {
247
- var _a, _b;
250
+ var _a, _b, _c, _d;
248
251
  assert.ok(fileEmitter, 'Invalid plugin execution order');
249
- const typescriptResult = await fileEmitter(args.path);
252
+ const typescriptResult = await fileEmitter((_b = (_a = pluginOptions.fileReplacements) === null || _a === void 0 ? void 0 : _a[args.path]) !== null && _b !== void 0 ? _b : args.path);
250
253
  if (!typescriptResult) {
251
254
  // No TS result indicates the file is not part of the TypeScript program.
252
255
  // If allowJs is enabled and the file is JS then defer to the next load hook.
@@ -268,7 +271,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
268
271
  ],
269
272
  };
270
273
  }
271
- const data = (_a = typescriptResult.content) !== null && _a !== void 0 ? _a : '';
274
+ const data = (_c = typescriptResult.content) !== null && _c !== void 0 ? _c : '';
272
275
  const forceAsyncTransformation = /async\s+function\s*\*/.test(data);
273
276
  const useInputSourcemap = pluginOptions.sourcemap &&
274
277
  (!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
@@ -302,7 +305,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
302
305
  ],
303
306
  });
304
307
  return {
305
- contents: (_b = babelResult === null || babelResult === void 0 ? void 0 : babelResult.code) !== null && _b !== void 0 ? _b : '',
308
+ contents: (_d = babelResult === null || babelResult === void 0 ? void 0 : babelResult.code) !== null && _d !== void 0 ? _d : '',
306
309
  loader: 'js',
307
310
  };
308
311
  });
@@ -12,7 +12,6 @@ const UNSUPPORTED_OPTIONS = [
12
12
  'allowedCommonJsDependencies',
13
13
  'budgets',
14
14
  'extractLicenses',
15
- 'fileReplacements',
16
15
  'progress',
17
16
  'scripts',
18
17
  'statsJson',
@@ -38,9 +38,11 @@ const path = __importStar(require("path"));
38
38
  const utils_1 = require("../../utils");
39
39
  const copy_assets_1 = require("../../utils/copy-assets");
40
40
  const error_1 = require("../../utils/error");
41
+ const esbuild_targets_1 = require("../../utils/esbuild-targets");
41
42
  const index_html_generator_1 = require("../../utils/index-file/index-html-generator");
42
43
  const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
43
44
  const service_worker_1 = require("../../utils/service-worker");
45
+ const supported_browsers_1 = require("../../utils/supported-browsers");
44
46
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
45
47
  const configs_1 = require("../../webpack/configs");
46
48
  const compiler_plugin_1 = require("./compiler-plugin");
@@ -86,11 +88,12 @@ async function buildEsbuildBrowser(options, context) {
86
88
  context.logger.error('Unable to create output directory: ' + e.message);
87
89
  return { success: false };
88
90
  }
91
+ const target = (0, esbuild_targets_1.transformSupportedBrowsersToTargets)((0, supported_browsers_1.getSupportedBrowsers)(projectRoot, context.logger));
89
92
  const [codeResults, styleResults] = await Promise.all([
90
93
  // Execute esbuild to bundle the application code
91
- bundleCode(workspaceRoot, entryPoints, outputNames, options, optimizationOptions, sourcemapOptions, tsconfig),
94
+ bundleCode(workspaceRoot, entryPoints, outputNames, options, optimizationOptions, sourcemapOptions, tsconfig, target),
92
95
  // Execute esbuild to bundle the global stylesheets
93
- bundleGlobalStylesheets(workspaceRoot, outputNames, options, optimizationOptions, sourcemapOptions),
96
+ bundleGlobalStylesheets(workspaceRoot, outputNames, options, optimizationOptions, sourcemapOptions, target),
94
97
  ]);
95
98
  // Log all warnings and errors generated during bundling
96
99
  await (0, esbuild_1.logMessages)(context, {
@@ -195,8 +198,15 @@ function createOutputFileFromText(path, text) {
195
198
  },
196
199
  };
197
200
  }
198
- async function bundleCode(workspaceRoot, entryPoints, outputNames, options, optimizationOptions, sourcemapOptions, tsconfig) {
201
+ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, optimizationOptions, sourcemapOptions, tsconfig, target) {
199
202
  var _a;
203
+ let fileReplacements;
204
+ if (options.fileReplacements) {
205
+ for (const replacement of options.fileReplacements) {
206
+ fileReplacements !== null && fileReplacements !== void 0 ? fileReplacements : (fileReplacements = {});
207
+ fileReplacements[path.join(workspaceRoot, replacement.replace)] = path.join(workspaceRoot, replacement.with);
208
+ }
209
+ }
200
210
  return (0, esbuild_1.bundle)({
201
211
  absWorkingDir: workspaceRoot,
202
212
  bundle: true,
@@ -204,7 +214,7 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
204
214
  entryPoints,
205
215
  entryNames: outputNames.bundles,
206
216
  assetNames: outputNames.media,
207
- target: 'es2020',
217
+ target,
208
218
  supported: {
209
219
  // Native async/await is not supported with Zone.js. Disabling support here will cause
210
220
  // esbuild to downlevel async/await and for await...of to a Zone.js supported form. However, esbuild
@@ -236,6 +246,7 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
236
246
  thirdPartySourcemaps: sourcemapOptions.vendor,
237
247
  tsconfig,
238
248
  advancedOptimizations: options.buildOptimizer,
249
+ fileReplacements,
239
250
  },
240
251
  // Component stylesheet options
241
252
  {
@@ -249,6 +260,7 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
249
260
  outputNames,
250
261
  includePaths: (_a = options.stylePreprocessorOptions) === null || _a === void 0 ? void 0 : _a.includePaths,
251
262
  externalDependencies: options.externalDependencies,
263
+ target,
252
264
  }),
253
265
  ],
254
266
  define: {
@@ -257,7 +269,7 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
257
269
  },
258
270
  });
259
271
  }
260
- async function bundleGlobalStylesheets(workspaceRoot, outputNames, options, optimizationOptions, sourcemapOptions) {
272
+ async function bundleGlobalStylesheets(workspaceRoot, outputNames, options, optimizationOptions, sourcemapOptions, target) {
261
273
  var _a;
262
274
  const outputFiles = [];
263
275
  const initialFiles = [];
@@ -281,6 +293,7 @@ async function bundleGlobalStylesheets(workspaceRoot, outputNames, options, opti
281
293
  includePaths: (_a = options.stylePreprocessorOptions) === null || _a === void 0 ? void 0 : _a.includePaths,
282
294
  preserveSymlinks: options.preserveSymlinks,
283
295
  externalDependencies: options.externalDependencies,
296
+ target,
284
297
  });
285
298
  errors.push(...sheetResult.errors);
286
299
  warnings.push(...sheetResult.warnings);
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  exports.normalizeOptions = void 0;
34
34
  const path = __importStar(require("path"));
35
35
  const utils_1 = require("../../utils");
36
+ const normalize_polyfills_1 = require("../../utils/normalize-polyfills");
36
37
  const schema_1 = require("../browser/schema");
37
38
  /**
38
39
  * Normalize the user provided options by creating full paths for all path based options
@@ -52,7 +53,11 @@ async function normalizeOptions(context, projectName, options) {
52
53
  const projectSourceRoot = path.join(workspaceRoot, (_b = projectMetadata.sourceRoot) !== null && _b !== void 0 ? _b : 'src');
53
54
  // Normalize options
54
55
  const mainEntryPoint = path.join(workspaceRoot, options.main);
55
- const polyfillsEntryPoint = options.polyfills && path.join(workspaceRoot, options.polyfills);
56
+ // Currently esbuild do not support multiple files per entry-point
57
+ const [polyfillsEntryPoint, ...remainingPolyfills] = (0, normalize_polyfills_1.normalizePolyfills)(options.polyfills, workspaceRoot);
58
+ if (remainingPolyfills.length) {
59
+ context.logger.warn(`The 'polyfills' option currently does not support multiple entries by this experimental builder. The first entry will be used.`);
60
+ }
56
61
  const tsconfig = path.join(workspaceRoot, options.tsConfig);
57
62
  const outputPath = path.join(workspaceRoot, options.outputPath);
58
63
  const optimizationOptions = (0, utils_1.normalizeOptimization)(options.optimization);
@@ -111,9 +111,9 @@ export interface Schema {
111
111
  */
112
112
  poll?: number;
113
113
  /**
114
- * The full path for the polyfills file, relative to the current workspace.
114
+ * Polyfills to be included in the build.
115
115
  */
116
- polyfills?: string;
116
+ polyfills?: Polyfills;
117
117
  /**
118
118
  * Do not use the real path when resolving modules. If unset then will default to `true` if
119
119
  * NodeJS option --preserve-symlinks is set.
@@ -262,10 +262,8 @@ export declare enum CrossOrigin {
262
262
  UseCredentials = "use-credentials"
263
263
  }
264
264
  export interface FileReplacement {
265
- replace?: string;
266
- replaceWith?: string;
267
- src?: string;
268
- with?: string;
265
+ replace: string;
266
+ with: string;
269
267
  }
270
268
  /**
271
269
  * How to handle duplicate translations for i18n.
@@ -364,6 +362,10 @@ export declare enum OutputHashing {
364
362
  Media = "media",
365
363
  None = "none"
366
364
  }
365
+ /**
366
+ * Polyfills to be included in the build.
367
+ */
368
+ export declare type Polyfills = string[] | string;
367
369
  export declare type ScriptElement = ScriptClass | string;
368
370
  export interface ScriptClass {
369
371
  /**