@angular-devkit/build-angular 15.0.0-next.0 → 15.0.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 (53) hide show
  1. package/package.json +13 -15
  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/browser/index.d.ts +1 -1
  6. package/src/builders/browser/index.js +4 -16
  7. package/src/builders/browser/schema.json +2 -2
  8. package/src/builders/browser-esbuild/compiler-plugin.d.ts +1 -0
  9. package/src/builders/browser-esbuild/compiler-plugin.js +20 -17
  10. package/src/builders/browser-esbuild/experimental-warnings.js +0 -1
  11. package/src/builders/browser-esbuild/index.js +18 -5
  12. package/src/builders/browser-esbuild/schema.d.ts +2 -4
  13. package/src/builders/browser-esbuild/schema.json +13 -32
  14. package/src/builders/browser-esbuild/stylesheets.d.ts +1 -0
  15. package/src/builders/browser-esbuild/stylesheets.js +1 -0
  16. package/src/builders/extract-i18n/index.js +1 -1
  17. package/src/builders/karma/schema.json +2 -2
  18. package/src/builders/server/index.d.ts +1 -1
  19. package/src/builders/server/index.js +42 -28
  20. package/src/builders/server/platform-server-exports-loader.d.ts +13 -0
  21. package/src/builders/server/platform-server-exports-loader.js +24 -0
  22. package/src/builders/server/schema.d.ts +1 -10
  23. package/src/builders/server/schema.js +1 -6
  24. package/src/builders/server/schema.json +1 -9
  25. package/src/utils/build-options.d.ts +1 -2
  26. package/src/utils/esbuild-targets.d.ts +12 -0
  27. package/src/utils/esbuild-targets.js +39 -0
  28. package/src/utils/i18n-inlining.d.ts +1 -1
  29. package/src/utils/i18n-inlining.js +3 -4
  30. package/src/utils/normalize-builder-schema.d.ts +2 -2
  31. package/src/utils/normalize-builder-schema.js +2 -2
  32. package/src/utils/process-bundle.d.ts +0 -1
  33. package/src/utils/process-bundle.js +29 -57
  34. package/src/utils/supported-browsers.d.ts +2 -1
  35. package/src/utils/supported-browsers.js +18 -2
  36. package/src/utils/webpack-browser-config.d.ts +0 -2
  37. package/src/utils/webpack-browser-config.js +2 -8
  38. package/src/webpack/configs/common.js +19 -12
  39. package/src/webpack/configs/dev-server.js +1 -1
  40. package/src/webpack/configs/styles.js +6 -28
  41. package/src/webpack/plugins/any-component-style-budget-checker.js +1 -1
  42. package/src/webpack/plugins/css-optimizer-plugin.d.ts +0 -1
  43. package/src/webpack/plugins/css-optimizer-plugin.js +3 -26
  44. package/src/webpack/plugins/hmr/hmr-loader.d.ts +1 -1
  45. package/src/webpack/plugins/hmr/hmr-loader.js +2 -5
  46. package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +4 -6
  47. package/src/webpack/plugins/javascript-optimizer-plugin.js +5 -14
  48. package/src/webpack/plugins/javascript-optimizer-worker.d.ts +3 -2
  49. package/src/webpack/plugins/javascript-optimizer-worker.js +21 -46
  50. package/src/webpack/plugins/typescript.js +14 -25
  51. package/src/webpack/utils/helpers.d.ts +0 -2
  52. package/src/webpack/utils/helpers.js +1 -17
  53. package/src/webpack/utils/stats.js +1 -1
@@ -37,7 +37,6 @@ exports.getCommonConfig = void 0;
37
37
  const webpack_1 = require("@ngtools/webpack");
38
38
  const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
39
39
  const path = __importStar(require("path"));
40
- const typescript_1 = require("typescript");
41
40
  const webpack_2 = require("webpack");
42
41
  const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
43
42
  const environment_options_1 = require("../../utils/environment-options");
@@ -47,14 +46,14 @@ const devtools_ignore_plugin_1 = require("../plugins/devtools-ignore-plugin");
47
46
  const named_chunks_plugin_1 = require("../plugins/named-chunks-plugin");
48
47
  const progress_plugin_1 = require("../plugins/progress-plugin");
49
48
  const transfer_size_plugin_1 = require("../plugins/transfer-size-plugin");
50
- const typescript_2 = require("../plugins/typescript");
49
+ const typescript_1 = require("../plugins/typescript");
51
50
  const watch_files_logs_plugin_1 = require("../plugins/watch-files-logs-plugin");
52
51
  const helpers_1 = require("../utils/helpers");
53
52
  const VENDORS_TEST = /[\\/]node_modules[\\/]/;
54
53
  // eslint-disable-next-line max-lines-per-function
55
54
  async function getCommonConfig(wco) {
56
55
  var _a, _b;
57
- const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot, tsConfigPath, scriptTarget, } = wco;
56
+ const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot, tsConfigPath } = wco;
58
57
  const { cache, codeCoverage, crossOrigin = 'none', platform = 'browser', aot = true, codeCoverageExclude = [], main, polyfills, sourceMap: { styles: stylesSourceMap, scripts: scriptsSourceMap, vendor: vendorSourceMap, hidden: hiddenSourceMap, }, optimization: { styles: stylesOptimization, scripts: scriptsOptimization }, commonChunk, vendorChunk, subresourceIntegrity, verbose, poll, webWorkerTsConfig, externalDependencies = [], allowedCommonJsDependencies, bundleDependencies, } = buildOptions;
59
58
  const isPlatformServer = buildOptions.platform === 'server';
60
59
  const extraPlugins = [];
@@ -185,17 +184,17 @@ async function getCommonConfig(wco) {
185
184
  /[\\/]node_modules[/\\](?:css-loader|mini-css-extract-plugin|webpack-dev-server|webpack)[/\\]/,
186
185
  ],
187
186
  });
188
- extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, aot, tsConfigPath));
187
+ extraPlugins.push((0, typescript_1.createIvyPlugin)(wco, aot, tsConfigPath));
189
188
  }
190
189
  if (webWorkerTsConfig) {
191
- extraPlugins.push((0, typescript_2.createIvyPlugin)(wco, false, path.resolve(wco.root, webWorkerTsConfig)));
190
+ extraPlugins.push((0, typescript_1.createIvyPlugin)(wco, false, path.resolve(wco.root, webWorkerTsConfig)));
192
191
  }
193
192
  const extraMinimizers = [];
194
193
  if (scriptsOptimization) {
195
194
  extraMinimizers.push(new plugins_1.JavaScriptOptimizerPlugin({
196
195
  define: buildOptions.aot ? GLOBAL_DEFS_FOR_TERSER_WITH_AOT : GLOBAL_DEFS_FOR_TERSER,
197
196
  sourcemap: scriptsSourceMap,
198
- target: scriptTarget,
197
+ supportedBrowsers: buildOptions.supportedBrowsers,
199
198
  keepIdentifierNames: !environment_options_1.allowMangle || isPlatformServer,
200
199
  keepNames: isPlatformServer,
201
200
  removeLicenses: buildOptions.extractLicenses,
@@ -219,17 +218,17 @@ async function getCommonConfig(wco) {
219
218
  return {
220
219
  mode: scriptsOptimization || stylesOptimization.minify ? 'production' : 'development',
221
220
  devtool: false,
222
- target: [
223
- isPlatformServer ? 'node' : 'web',
224
- scriptTarget === typescript_1.ScriptTarget.ES5 ? 'es5' : 'es2015',
225
- ],
221
+ target: [isPlatformServer ? 'node' : 'web', 'es2015'],
226
222
  profile: buildOptions.statsJson,
227
223
  resolve: {
228
224
  roots: [projectRoot],
229
225
  extensions: ['.ts', '.tsx', '.mjs', '.js'],
230
226
  symlinks: !buildOptions.preserveSymlinks,
231
227
  modules: [tsConfig.options.baseUrl || projectRoot, 'node_modules'],
232
- ...(0, helpers_1.getMainFieldsAndConditionNames)(scriptTarget, isPlatformServer),
228
+ mainFields: isPlatformServer
229
+ ? ['es2020', 'es2015', 'module', 'main']
230
+ : ['es2020', 'es2015', 'browser', 'module', 'main'],
231
+ conditionNames: ['es2020', 'es2015', '...'],
233
232
  },
234
233
  resolveLoader: {
235
234
  symlinks: !buildOptions.preserveSymlinks,
@@ -253,8 +252,17 @@ async function getCommonConfig(wco) {
253
252
  watch: buildOptions.watch,
254
253
  watchOptions: {
255
254
  poll,
255
+ // The below is needed as when preserveSymlinks is enabled we disable `resolve.symlinks`.
256
+ followSymlinks: buildOptions.preserveSymlinks,
256
257
  ignored: poll === undefined ? undefined : '**/node_modules/**',
257
258
  },
259
+ snapshot: {
260
+ module: {
261
+ // Use hash of content instead of timestamp because the timestamp of the symlink will be used
262
+ // instead of the referenced files which causes changes in symlinks not to be picked up.
263
+ hash: buildOptions.preserveSymlinks,
264
+ },
265
+ },
258
266
  performance: {
259
267
  hints: false,
260
268
  },
@@ -304,7 +312,6 @@ async function getCommonConfig(wco) {
304
312
  loader: require.resolve('../../babel/webpack-loader'),
305
313
  options: {
306
314
  cacheDirectory: (cache.enabled && path.join(cache.path, 'babel-webpack')) || false,
307
- scriptTarget,
308
315
  aot: buildOptions.aot,
309
316
  optimize: buildOptions.buildOptimizer,
310
317
  supportedBrowsers: buildOptions.supportedBrowsers,
@@ -46,7 +46,7 @@ async function getDevServerConfig(wco) {
46
46
  if (hmr) {
47
47
  extraRules.push({
48
48
  loader: hmr_loader_1.HmrLoader,
49
- include: [main].map((p) => (0, path_1.resolve)(wco.root, p)),
49
+ include: [(0, path_1.resolve)(wco.root, main)],
50
50
  });
51
51
  }
52
52
  const extraPlugins = [];
@@ -83,8 +83,6 @@ exports.resolveGlobalStyles = resolveGlobalStyles;
83
83
  // eslint-disable-next-line max-lines-per-function
84
84
  function getStylesConfig(wco) {
85
85
  var _a, _b, _c;
86
- const postcssImports = require('postcss-import');
87
- const postcssPresetEnv = require('postcss-preset-env');
88
86
  const { root, buildOptions } = wco;
89
87
  const extraPlugins = [];
90
88
  extraPlugins.push(new plugins_1.AnyComponentStyleBudgetChecker(buildOptions.budgets));
@@ -99,10 +97,6 @@ function getStylesConfig(wco) {
99
97
  // Add plugin to remove hashes from lazy styles.
100
98
  extraPlugins.push(new plugins_1.RemoveHashPlugin({ chunkNames: noInjectNames, hashFormat }));
101
99
  }
102
- if (globalStylePaths.some((p) => p.endsWith('.styl'))) {
103
- wco.logger.warn('Stylus usage is deprecated and will be removed in a future major version. ' +
104
- 'To opt-out of the deprecated behaviour, please migrate to another stylesheet language.');
105
- }
106
100
  const sassImplementation = new sass_service_1.SassWorkerImplementation();
107
101
  const sassTildeUsageMessage = new Set();
108
102
  extraPlugins.push({
@@ -140,11 +134,8 @@ function getStylesConfig(wco) {
140
134
  extraPostcssPlugins.push(require(tailwindPackagePath)({ config: tailwindConfigPath }));
141
135
  }
142
136
  }
143
- const postcssPresetEnvPlugin = postcssPresetEnv({
144
- browsers: buildOptions.supportedBrowsers,
145
- autoprefixer: true,
146
- stage: 3,
147
- });
137
+ const postcssImports = require('postcss-import');
138
+ const autoprefixer = require('autoprefixer');
148
139
  const postcssOptionsCreator = (inlineSourcemaps, extracted) => {
149
140
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
150
141
  const optionGenerator = (loader) => ({
@@ -180,7 +171,10 @@ function getStylesConfig(wco) {
180
171
  extracted,
181
172
  }),
182
173
  ...extraPostcssPlugins,
183
- postcssPresetEnvPlugin,
174
+ autoprefixer({
175
+ ignoreUnknownVersions: true,
176
+ overrideBrowserslist: buildOptions.supportedBrowsers,
177
+ }),
184
178
  ],
185
179
  });
186
180
  // postcss-loader fails when trying to determine configuration files for data URIs
@@ -331,22 +325,6 @@ function getStylesConfig(wco) {
331
325
  },
332
326
  ],
333
327
  },
334
- {
335
- extensions: ['styl'],
336
- use: [
337
- {
338
- loader: require.resolve('stylus-loader'),
339
- options: {
340
- sourceMap: cssSourceMap,
341
- stylusOptions: {
342
- compress: false,
343
- sourceMap: { comment: false },
344
- paths: includePaths,
345
- },
346
- },
347
- },
348
- ],
349
- },
350
328
  ];
351
329
  return {
352
330
  entry: entryPoints,
@@ -59,7 +59,7 @@ class AnyComponentStyleBudgetChecker {
59
59
  if (!compilation.compiler.parentCompilation) {
60
60
  return;
61
61
  }
62
- const cssExtensions = ['.css', '.scss', '.less', '.styl', '.sass'];
62
+ const cssExtensions = ['.css', '.scss', '.less', '.sass'];
63
63
  const componentStyles = Object.keys(compilation.assets)
64
64
  .filter((name) => cssExtensions.includes(path.extname(name)))
65
65
  .map((name) => ({
@@ -32,5 +32,4 @@ export declare class CssOptimizerPlugin {
32
32
  */
33
33
  private optimize;
34
34
  private addWarnings;
35
- private transformSupportedBrowsersToTargets;
36
35
  }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.CssOptimizerPlugin = void 0;
11
+ const esbuild_targets_1 = require("../../utils/esbuild-targets");
11
12
  const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
12
13
  const esbuild_executor_1 = require("./esbuild-executor");
13
14
  /**
@@ -24,7 +25,7 @@ class CssOptimizerPlugin {
24
25
  constructor(options) {
25
26
  this.esbuild = new esbuild_executor_1.EsbuildExecutor();
26
27
  if (options === null || options === void 0 ? void 0 : options.supportedBrowsers) {
27
- this.targets = this.transformSupportedBrowsersToTargets(options.supportedBrowsers);
28
+ this.targets = (0, esbuild_targets_1.transformSupportedBrowsersToTargets)(options.supportedBrowsers);
28
29
  }
29
30
  }
30
31
  apply(compiler) {
@@ -38,7 +39,7 @@ class CssOptimizerPlugin {
38
39
  const cache = compilation.options.cache && compilation.getCache(PLUGIN_NAME);
39
40
  logger.time('optimize css assets');
40
41
  for (const assetName of Object.keys(compilationAssets)) {
41
- if (!/\.(?:css|scss|sass|less|styl)$/.test(assetName)) {
42
+ if (!/\.(?:css|scss|sass|less)$/.test(assetName)) {
42
43
  continue;
43
44
  }
44
45
  const asset = compilation.getAsset(assetName);
@@ -117,29 +118,5 @@ class CssOptimizerPlugin {
117
118
  }
118
119
  }
119
120
  }
120
- transformSupportedBrowsersToTargets(supportedBrowsers) {
121
- const transformed = [];
122
- // https://esbuild.github.io/api/#target
123
- const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);
124
- for (const browser of supportedBrowsers) {
125
- let [browserName, version] = browser.split(' ');
126
- // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
127
- if (browserName === 'ios_saf') {
128
- browserName = 'ios';
129
- }
130
- // browserslist uses ranges `15.2-15.3` versions but only the lowest is required
131
- // to perform minimum supported feature checks. esbuild also expects a single version.
132
- [version] = version.split('-');
133
- if (esBuildSupportedBrowsers.has(browserName)) {
134
- if (browserName === 'safari' && version === 'TP') {
135
- // esbuild only supports numeric versions so `TP` is converted to a high number (999) since
136
- // a Technology Preview (TP) of Safari is assumed to support all currently known features.
137
- version = '999';
138
- }
139
- transformed.push(browserName + version);
140
- }
141
- }
142
- return transformed.length ? transformed : undefined;
143
- }
144
121
  }
145
122
  exports.CssOptimizerPlugin = CssOptimizerPlugin;
@@ -6,4 +6,4 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  export declare const HmrLoader: string;
9
- export default function (this: any, content: string, map: any): void;
9
+ export default function localizeExtractLoader(this: import('webpack').LoaderContext<{}>, content: string, map: Parameters<import('webpack').LoaderDefinitionFunction>[1]): void;
@@ -11,10 +11,7 @@ exports.HmrLoader = void 0;
11
11
  const path_1 = require("path");
12
12
  exports.HmrLoader = __filename;
13
13
  const hmrAcceptPath = (0, path_1.join)(__dirname, './hmr-accept.js').replace(/\\/g, '/');
14
- function default_1(content,
15
- // Source map types are broken in the webpack type definitions
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- map) {
14
+ function localizeExtractLoader(content, map) {
18
15
  const source = `${content}
19
16
 
20
17
  // HMR Accept Code
@@ -24,4 +21,4 @@ map) {
24
21
  this.callback(null, source, map);
25
22
  return;
26
23
  }
27
- exports.default = default_1;
24
+ exports.default = localizeExtractLoader;
@@ -5,7 +5,6 @@
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 { ScriptTarget } from 'typescript';
9
8
  import type { Compiler } from 'webpack';
10
9
  /**
11
10
  * The options used to configure the {@link JavaScriptOptimizerPlugin}.
@@ -29,11 +28,9 @@ export interface JavaScriptOptimizerOptions {
29
28
  */
30
29
  sourcemap?: boolean;
31
30
  /**
32
- * The ECMAScript version that should be used when generating output code.
33
- * The optimizer will not adjust the output code with features present in newer
34
- * ECMAScript versions.
31
+ * A list of supported browsers that is used for output code.
35
32
  */
36
- target: ScriptTarget;
33
+ supportedBrowsers?: string[];
37
34
  /**
38
35
  * Enables the retention of identifier names and ensures that function and class names are
39
36
  * present in the output code.
@@ -61,7 +58,8 @@ export interface JavaScriptOptimizerOptions {
61
58
  * optimizations not yet implemented by `esbuild`.
62
59
  */
63
60
  export declare class JavaScriptOptimizerPlugin {
64
- options: JavaScriptOptimizerOptions;
61
+ private options;
62
+ private targets;
65
63
  constructor(options: JavaScriptOptimizerOptions);
66
64
  apply(compiler: Compiler): void;
67
65
  }
@@ -12,8 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.JavaScriptOptimizerPlugin = void 0;
14
14
  const piscina_1 = __importDefault(require("piscina"));
15
- const typescript_1 = require("typescript");
16
15
  const environment_options_1 = require("../../utils/environment-options");
16
+ const esbuild_targets_1 = require("../../utils/esbuild-targets");
17
17
  const esbuild_executor_1 = require("./esbuild-executor");
18
18
  /**
19
19
  * The maximum number of Workers that will be created to execute optimize tasks.
@@ -34,6 +34,9 @@ const PLUGIN_NAME = 'angular-javascript-optimizer';
34
34
  class JavaScriptOptimizerPlugin {
35
35
  constructor(options) {
36
36
  this.options = options;
37
+ if (options.supportedBrowsers) {
38
+ this.targets = (0, esbuild_targets_1.transformSupportedBrowsersToTargets)(options.supportedBrowsers);
39
+ }
37
40
  }
38
41
  apply(compiler) {
39
42
  const { OriginalSource, SourceMapSource } = compiler.webpack.sources;
@@ -90,25 +93,13 @@ class JavaScriptOptimizerPlugin {
90
93
  define[key] = String(value);
91
94
  }
92
95
  }
93
- let target = 2017;
94
- if (this.options.target) {
95
- if (this.options.target <= typescript_1.ScriptTarget.ES5) {
96
- target = 5;
97
- }
98
- else if (this.options.target === typescript_1.ScriptTarget.ESNext) {
99
- target = 'next';
100
- }
101
- else {
102
- target = Number(typescript_1.ScriptTarget[this.options.target].slice(2));
103
- }
104
- }
105
96
  // Setup the options used by all worker tasks
106
97
  const optimizeOptions = {
107
98
  sourcemap: this.options.sourcemap,
108
99
  define,
109
100
  keepNames: this.options.keepNames,
110
101
  keepIdentifierNames: this.options.keepIdentifierNames,
111
- target,
102
+ target: this.targets,
112
103
  removeLicenses: this.options.removeLicenses,
113
104
  advanced: this.options.advanced,
114
105
  // Perform a single native esbuild support check.
@@ -39,9 +39,10 @@ export interface OptimizeRequestOptions {
39
39
  */
40
40
  sourcemap?: boolean;
41
41
  /**
42
- * Specifies the target ECMAScript version for the output code.
42
+ * Specifies the list of supported esbuild targets.
43
+ * @see: https://esbuild.github.io/api/#target
43
44
  */
44
- target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 'next';
45
+ target?: string[];
45
46
  /**
46
47
  * Controls whether esbuild should only use the WASM-variant instead of trying to
47
48
  * use the native variant. Some platforms may not support the native-variant and
@@ -26,9 +26,7 @@ async function default_1({ asset, options }) {
26
26
  // esbuild is used as a first pass
27
27
  const esbuildResult = await optimizeWithEsbuild(asset.code, asset.name, options);
28
28
  // terser is used as a second pass
29
- const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap,
30
- // Terser only supports up to ES2020.
31
- options.target === 'next' ? 2020 : options.target, options.advanced);
29
+ const terserResult = await optimizeWithTerser(asset.name, esbuildResult.code, options.sourcemap, options.advanced);
32
30
  // Merge intermediate sourcemaps with input sourcemap if enabled
33
31
  let fullSourcemap;
34
32
  if (options.sourcemap) {
@@ -56,49 +54,26 @@ exports.default = default_1;
56
54
  * @returns A promise that resolves with the optimized code, source map, and any warnings.
57
55
  */
58
56
  async function optimizeWithEsbuild(content, name, options) {
59
- var _a;
60
57
  if (!esbuild) {
61
58
  esbuild = new esbuild_executor_1.EsbuildExecutor(options.alwaysUseWasm);
62
59
  }
63
- let result;
64
- try {
65
- result = await esbuild.transform(content, {
66
- minifyIdentifiers: !options.keepIdentifierNames,
67
- minifySyntax: true,
68
- // NOTE: Disabling whitespace ensures unused pure annotations are kept
69
- minifyWhitespace: false,
70
- pure: ['forwardRef'],
71
- legalComments: options.removeLicenses ? 'none' : 'inline',
72
- sourcefile: name,
73
- sourcemap: options.sourcemap && 'external',
74
- define: options.define,
75
- // This option should always be disabled for browser builds as we don't rely on `.name`
76
- // and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
77
- // We enable `keepNames` only for server builds as Domino relies on `.name`.
78
- // Once we no longer rely on Domino for SSR we should be able to remove this.
79
- keepNames: options.keepNames,
80
- target: `es${options.target}`,
81
- });
82
- }
83
- catch (error) {
84
- const failure = error;
85
- // If esbuild fails with only ES5 support errors, fallback to just terser.
86
- // This will only happen if ES5 is the output target and a global script contains ES2015+ syntax.
87
- // In that case, the global script is technically already invalid for the target environment but
88
- // this is and has been considered a configuration issue. Global scripts must be compatible with
89
- // the target environment.
90
- if ((_a = failure.errors) === null || _a === void 0 ? void 0 : _a.every((error) => error.text.includes('to the configured target environment ("es5") is not supported yet'))) {
91
- result = {
92
- code: content,
93
- map: '',
94
- warnings: [],
95
- };
96
- }
97
- else {
98
- throw error;
99
- }
100
- }
101
- return result;
60
+ return esbuild.transform(content, {
61
+ minifyIdentifiers: !options.keepIdentifierNames,
62
+ minifySyntax: true,
63
+ // NOTE: Disabling whitespace ensures unused pure annotations are kept
64
+ minifyWhitespace: false,
65
+ pure: ['forwardRef'],
66
+ legalComments: options.removeLicenses ? 'none' : 'inline',
67
+ sourcefile: name,
68
+ sourcemap: options.sourcemap && 'external',
69
+ define: options.define,
70
+ // This option should always be disabled for browser builds as we don't rely on `.name`
71
+ // and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
72
+ // We enable `keepNames` only for server builds as Domino relies on `.name`.
73
+ // Once we no longer rely on Domino for SSR we should be able to remove this.
74
+ keepNames: options.keepNames,
75
+ target: options.target,
76
+ });
102
77
  }
103
78
  /**
104
79
  * Optimizes a JavaScript asset using terser.
@@ -106,17 +81,17 @@ async function optimizeWithEsbuild(content, name, options) {
106
81
  * @param name The name of the JavaScript asset. Used to generate source maps.
107
82
  * @param code The JavaScript asset source content to optimize.
108
83
  * @param sourcemaps If true, generate an output source map for the optimized code.
109
- * @param target Specifies the target ECMAScript version for the output code.
110
84
  * @param advanced Controls advanced optimizations.
111
85
  * @returns A promise that resolves with the optimized code and source map.
112
86
  */
113
- async function optimizeWithTerser(name, code, sourcemaps, target, advanced) {
87
+ async function optimizeWithTerser(name, code, sourcemaps, advanced) {
114
88
  const result = await (0, terser_1.minify)({ [name]: code }, {
115
89
  compress: {
116
90
  passes: advanced ? 2 : 1,
117
91
  pure_getters: advanced,
118
92
  },
119
- ecma: target,
93
+ // terser only supports up to ES2020
94
+ ecma: 2020,
120
95
  // esbuild in the first pass is used to minify identifiers instead of mangle here
121
96
  mangle: false,
122
97
  // esbuild in the first pass is used to minify function names
@@ -11,52 +11,41 @@ exports.createIvyPlugin = void 0;
11
11
  const webpack_1 = require("@ngtools/webpack");
12
12
  const typescript_1 = require("typescript");
13
13
  function createIvyPlugin(wco, aot, tsconfig) {
14
- const { buildOptions } = wco;
14
+ var _a, _b;
15
+ var _c;
16
+ const { buildOptions, tsConfig } = wco;
15
17
  const optimize = buildOptions.optimization.scripts;
16
18
  const compilerOptions = {
17
19
  sourceMap: buildOptions.sourceMap.scripts,
18
20
  declaration: false,
19
21
  declarationMap: false,
20
22
  };
23
+ if (tsConfig.options.target === undefined || tsConfig.options.target < typescript_1.ScriptTarget.ES2022) {
24
+ tsConfig.options.target = typescript_1.ScriptTarget.ES2022;
25
+ // If 'useDefineForClassFields' is already defined in the users project leave the value as is.
26
+ // Otherwise fallback to false due to https://github.com/microsoft/TypeScript/issues/45995
27
+ // which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
28
+ (_a = (_c = tsConfig.options).useDefineForClassFields) !== null && _a !== void 0 ? _a : (_c.useDefineForClassFields = false);
29
+ wco.logger.warn('TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and ' +
30
+ '"false" respectively by the Angular CLI. To control ECMA version and features use the Browerslist configuration. ' +
31
+ 'For more information, see https://github.com/browserslist/browserslist');
32
+ }
21
33
  if (buildOptions.preserveSymlinks !== undefined) {
22
34
  compilerOptions.preserveSymlinks = buildOptions.preserveSymlinks;
23
35
  }
24
- // Outputting ES2015 from TypeScript is the required minimum for the build optimizer passes.
25
- // Downleveling to ES5 will occur after the build optimizer passes via babel which is the same
26
- // as for third-party libraries. This greatly reduces the complexity of static analysis.
27
- if (wco.scriptTarget < typescript_1.ScriptTarget.ES2015) {
28
- compilerOptions.target = typescript_1.ScriptTarget.ES2015;
29
- wco.logger.warn('DEPRECATED: ES5 output is deprecated. Please update TypeScript `target` compiler option to ES2015 or later.');
30
- }
31
36
  const fileReplacements = {};
32
37
  if (buildOptions.fileReplacements) {
33
38
  for (const replacement of buildOptions.fileReplacements) {
34
39
  fileReplacements[replacement.replace] = replacement.with;
35
40
  }
36
41
  }
37
- let inlineStyleFileExtension;
38
- switch (buildOptions.inlineStyleLanguage) {
39
- case 'less':
40
- inlineStyleFileExtension = 'less';
41
- break;
42
- case 'sass':
43
- inlineStyleFileExtension = 'sass';
44
- break;
45
- case 'scss':
46
- inlineStyleFileExtension = 'scss';
47
- break;
48
- case 'css':
49
- default:
50
- inlineStyleFileExtension = 'css';
51
- break;
52
- }
53
42
  return new webpack_1.AngularWebpackPlugin({
54
43
  tsconfig,
55
44
  compilerOptions,
56
45
  fileReplacements,
57
46
  jitMode: !aot,
58
47
  emitNgModuleScope: !optimize,
59
- inlineStyleFileExtension,
48
+ inlineStyleFileExtension: (_b = buildOptions.inlineStyleLanguage) !== null && _b !== void 0 ? _b : 'css',
60
49
  });
61
50
  }
62
51
  exports.createIvyPlugin = createIvyPlugin;
@@ -6,7 +6,6 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import type { ObjectPattern } from 'copy-webpack-plugin';
9
- import { ScriptTarget } from 'typescript';
10
9
  import type { Configuration, WebpackOptionsNormalized } from 'webpack';
11
10
  import { AssetPatternClass, OutputHashing, ScriptElement, StyleElement } from '../../builders/browser/schema';
12
11
  import { WebpackConfigOptions } from '../../utils/build-options';
@@ -31,4 +30,3 @@ export declare function globalScriptsByBundleName(root: string, scripts: ScriptE
31
30
  export declare function assetPatterns(root: string, assets: AssetPatternClass[]): ObjectPattern[];
32
31
  export declare function externalizePackages(context: string, request: string | undefined, callback: (error?: Error, result?: string) => void): void;
33
32
  export declare function getStatsOptions(verbose?: boolean): WebpackStatsOptions;
34
- export declare function getMainFieldsAndConditionNames(target: ScriptTarget, platformServer: boolean): Pick<WebpackOptionsNormalized['resolve'], 'mainFields' | 'conditionNames'>;
@@ -33,12 +33,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  return (mod && mod.__esModule) ? mod : { "default": mod };
34
34
  };
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getMainFieldsAndConditionNames = exports.getStatsOptions = exports.externalizePackages = exports.assetPatterns = exports.globalScriptsByBundleName = exports.getCacheSettings = exports.getInstrumentationExcludedPaths = exports.assetNameTemplateFactory = exports.normalizeExtraEntryPoints = exports.getOutputHashFormat = void 0;
36
+ exports.getStatsOptions = exports.externalizePackages = exports.assetPatterns = exports.globalScriptsByBundleName = exports.getCacheSettings = exports.getInstrumentationExcludedPaths = exports.assetNameTemplateFactory = exports.normalizeExtraEntryPoints = exports.getOutputHashFormat = void 0;
37
37
  const crypto_1 = require("crypto");
38
38
  const fs_1 = require("fs");
39
39
  const glob_1 = __importDefault(require("glob"));
40
40
  const path = __importStar(require("path"));
41
- const typescript_1 = require("typescript");
42
41
  const schema_1 = require("../../builders/browser/schema");
43
42
  const package_version_1 = require("../../utils/package-version");
44
43
  function getOutputHashFormat(outputHashing = schema_1.OutputHashing.None, length = 20) {
@@ -288,18 +287,3 @@ function getStatsOptions(verbose = false) {
288
287
  : webpackOutputOptions;
289
288
  }
290
289
  exports.getStatsOptions = getStatsOptions;
291
- function getMainFieldsAndConditionNames(target, platformServer) {
292
- const mainFields = platformServer
293
- ? ['es2015', 'module', 'main']
294
- : ['es2015', 'browser', 'module', 'main'];
295
- const conditionNames = ['es2015', '...'];
296
- if (target >= typescript_1.ScriptTarget.ES2020) {
297
- mainFields.unshift('es2020');
298
- conditionNames.unshift('es2020');
299
- }
300
- return {
301
- mainFields,
302
- conditionNames,
303
- };
304
- }
305
- exports.getMainFieldsAndConditionNames = getMainFieldsAndConditionNames;
@@ -331,7 +331,7 @@ function statsErrorsToString(json, statsConfig) {
331
331
  // See: https://github.com/webpack/webpack/issues/15980
332
332
  const message = statsConfig.errorStack
333
333
  ? error.message
334
- : (_b = (_a = /[\s\S]+?(?=[\n\s]+at)/.exec(error.message)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : error.message;
334
+ : (_b = (_a = /[\s\S]+?(?=\n+\s+at\s)/.exec(error.message)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : error.message;
335
335
  if (!/^error/i.test(message)) {
336
336
  output += r('Error: ');
337
337
  }