@angular-devkit/build-angular 15.0.0-next.1 → 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 (49) 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 -10
  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/utils/build-options.d.ts +1 -2
  23. package/src/utils/esbuild-targets.d.ts +12 -0
  24. package/src/utils/esbuild-targets.js +39 -0
  25. package/src/utils/i18n-inlining.d.ts +1 -1
  26. package/src/utils/i18n-inlining.js +3 -4
  27. package/src/utils/normalize-builder-schema.d.ts +2 -2
  28. package/src/utils/normalize-builder-schema.js +2 -2
  29. package/src/utils/process-bundle.d.ts +0 -1
  30. package/src/utils/process-bundle.js +29 -57
  31. package/src/utils/supported-browsers.d.ts +2 -1
  32. package/src/utils/supported-browsers.js +18 -2
  33. package/src/utils/webpack-browser-config.d.ts +0 -2
  34. package/src/utils/webpack-browser-config.js +2 -8
  35. package/src/webpack/configs/common.js +10 -12
  36. package/src/webpack/configs/dev-server.js +1 -1
  37. package/src/webpack/configs/styles.js +0 -20
  38. package/src/webpack/plugins/any-component-style-budget-checker.js +1 -1
  39. package/src/webpack/plugins/css-optimizer-plugin.d.ts +0 -1
  40. package/src/webpack/plugins/css-optimizer-plugin.js +3 -26
  41. package/src/webpack/plugins/hmr/hmr-loader.d.ts +1 -1
  42. package/src/webpack/plugins/hmr/hmr-loader.js +2 -5
  43. package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +4 -6
  44. package/src/webpack/plugins/javascript-optimizer-plugin.js +5 -14
  45. package/src/webpack/plugins/javascript-optimizer-worker.d.ts +3 -2
  46. package/src/webpack/plugins/javascript-optimizer-worker.js +21 -46
  47. package/src/webpack/plugins/typescript.js +14 -25
  48. package/src/webpack/utils/helpers.d.ts +0 -2
  49. package/src/webpack/utils/helpers.js +1 -17
@@ -36,7 +36,6 @@ const build_webpack_1 = require("@angular-devkit/build-webpack");
36
36
  const path = __importStar(require("path"));
37
37
  const rxjs_1 = require("rxjs");
38
38
  const operators_1 = require("rxjs/operators");
39
- const typescript_1 = require("typescript");
40
39
  const utils_1 = require("../../utils");
41
40
  const i18n_inlining_1 = require("../../utils/i18n-inlining");
42
41
  const output_paths_1 = require("../../utils/output-paths");
@@ -54,7 +53,7 @@ function execute(options, context, transforms = {}) {
54
53
  (0, version_1.assertCompatibleAngularVersion)(root);
55
54
  const baseOutputPath = path.resolve(root, options.outputPath);
56
55
  let outputPaths;
57
- return (0, rxjs_1.from)(initialize(options, context, transforms.webpackConfiguration)).pipe((0, operators_1.concatMap)(({ config, i18n, target }) => {
56
+ return (0, rxjs_1.from)(initialize(options, context, transforms.webpackConfiguration)).pipe((0, operators_1.concatMap)(({ config, i18n }) => {
58
57
  return (0, build_webpack_1.runWebpack)(config, context, {
59
58
  webpackFactory: require('webpack'),
60
59
  logging: (stats, config) => {
@@ -70,7 +69,7 @@ function execute(options, context, transforms = {}) {
70
69
  let success = output.success;
71
70
  if (success && i18n.shouldInline) {
72
71
  outputPaths = (0, output_paths_1.ensureOutputPaths)(baseOutputPath, i18n);
73
- success = await (0, i18n_inlining_1.i18nInlineEmittedFiles)(context, emittedFiles, i18n, baseOutputPath, Array.from(outputPaths.values()), [], outputPath, target <= typescript_1.ScriptTarget.ES5, options.i18nMissingTranslation);
72
+ success = await (0, i18n_inlining_1.i18nInlineEmittedFiles)(context, emittedFiles, i18n, baseOutputPath, Array.from(outputPaths.values()), [], outputPath, options.i18nMissingTranslation);
74
73
  }
75
74
  (0, stats_1.webpackStatsLogger)(context.logger, webpackStats, config);
76
75
  return { ...output, success };
@@ -97,21 +96,54 @@ function execute(options, context, transforms = {}) {
97
96
  exports.execute = execute;
98
97
  exports.default = (0, architect_1.createBuilder)(execute);
99
98
  async function initialize(options, context, webpackConfigurationTransform) {
99
+ var _a;
100
100
  // Purge old build disk cache.
101
101
  await (0, purge_cache_1.purgeStaleBuildCache)(context);
102
+ const browserslist = (await Promise.resolve().then(() => __importStar(require('browserslist')))).default;
102
103
  const originalOutputPath = options.outputPath;
103
- const { config, i18n, target } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)({
104
+ const { config, i18n } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)({
104
105
  ...options,
105
106
  buildOptimizer: false,
106
107
  aot: true,
107
108
  platform: 'server',
108
- }, context, (wco) => [(0, configs_1.getCommonConfig)(wco), (0, configs_1.getStylesConfig)(wco)]);
109
- let transformedConfig;
110
- if (webpackConfigurationTransform) {
111
- transformedConfig = await webpackConfigurationTransform(config);
112
- }
109
+ }, context, (wco) => {
110
+ var _a;
111
+ var _b;
112
+ // We use the platform to determine the JavaScript syntax output.
113
+ (_a = (_b = wco.buildOptions).supportedBrowsers) !== null && _a !== void 0 ? _a : (_b.supportedBrowsers = []);
114
+ wco.buildOptions.supportedBrowsers.push(...browserslist('maintained node versions'));
115
+ return [getPlatformServerExportsConfig(wco), (0, configs_1.getCommonConfig)(wco), (0, configs_1.getStylesConfig)(wco)];
116
+ });
113
117
  if (options.deleteOutputPath) {
114
118
  (0, utils_1.deleteOutputDir)(context.workspaceRoot, originalOutputPath);
115
119
  }
116
- return { config: transformedConfig || config, i18n, target };
120
+ const transformedConfig = (_a = (await (webpackConfigurationTransform === null || webpackConfigurationTransform === void 0 ? void 0 : webpackConfigurationTransform(config)))) !== null && _a !== void 0 ? _a : config;
121
+ return { config: transformedConfig, i18n };
122
+ }
123
+ /**
124
+ * Add `@angular/platform-server` exports.
125
+ * This is needed so that DI tokens can be referenced and set at runtime outside of the bundle.
126
+ */
127
+ function getPlatformServerExportsConfig(wco) {
128
+ // Add `@angular/platform-server` exports.
129
+ // This is needed so that DI tokens can be referenced and set at runtime outside of the bundle.
130
+ try {
131
+ // Only add `@angular/platform-server` exports when it is installed.
132
+ // In some cases this builder is used when `@angular/platform-server` is not installed.
133
+ // Example: when using `@nguniversal/common/clover` which does not need `@angular/platform-server`.
134
+ require.resolve('@angular/platform-server', { paths: [wco.root] });
135
+ }
136
+ catch {
137
+ return {};
138
+ }
139
+ return {
140
+ module: {
141
+ rules: [
142
+ {
143
+ loader: require.resolve('./platform-server-exports-loader'),
144
+ include: [path.resolve(wco.root, wco.buildOptions.main)],
145
+ },
146
+ ],
147
+ },
148
+ };
117
149
  }
@@ -0,0 +1,13 @@
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
+ /**
9
+ * This loader is needed to add additional exports and is a workaround for a Webpack bug that doesn't
10
+ * allow exports from multiple files in the same entry.
11
+ * @see https://github.com/webpack/webpack/issues/15936.
12
+ */
13
+ export default function (this: import('webpack').LoaderContext<{}>, content: string, map: Parameters<import('webpack').LoaderDefinitionFunction>[1]): void;
@@ -0,0 +1,24 @@
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
+ /**
11
+ * This loader is needed to add additional exports and is a workaround for a Webpack bug that doesn't
12
+ * allow exports from multiple files in the same entry.
13
+ * @see https://github.com/webpack/webpack/issues/15936.
14
+ */
15
+ function default_1(content, map) {
16
+ const source = `${content}
17
+
18
+ // EXPORTS added by @angular-devkit/build-angular
19
+ export { renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';
20
+ `;
21
+ this.callback(null, source, map);
22
+ return;
23
+ }
24
+ exports.default = default_1;
@@ -60,7 +60,7 @@ export interface BuildOptions {
60
60
  cache: NormalizedCachedOptions;
61
61
  codeCoverage?: boolean;
62
62
  codeCoverageExclude?: string[];
63
- supportedBrowsers: string[];
63
+ supportedBrowsers?: string[];
64
64
  }
65
65
  export interface WebpackDevServerOptions extends BuildOptions, Omit<DevServerSchema, 'optimization' | 'sourceMap' | 'browserTarget'> {
66
66
  }
@@ -72,6 +72,5 @@ export interface WebpackConfigOptions<T = BuildOptions> {
72
72
  buildOptions: T;
73
73
  tsConfig: ParsedConfiguration;
74
74
  tsConfigPath: string;
75
- scriptTarget: import('typescript').ScriptTarget;
76
75
  projectName: string;
77
76
  }
@@ -0,0 +1,12 @@
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
+ /**
9
+ * Transform browserlists result to esbuild target.
10
+ * @see https://esbuild.github.io/api/#target
11
+ */
12
+ export declare function transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[];
@@ -0,0 +1,39 @@
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.transformSupportedBrowsersToTargets = void 0;
11
+ /**
12
+ * Transform browserlists result to esbuild target.
13
+ * @see https://esbuild.github.io/api/#target
14
+ */
15
+ function transformSupportedBrowsersToTargets(supportedBrowsers) {
16
+ const transformed = [];
17
+ // https://esbuild.github.io/api/#target
18
+ const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios', 'node']);
19
+ for (const browser of supportedBrowsers) {
20
+ let [browserName, version] = browser.split(' ');
21
+ // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
22
+ if (browserName === 'ios_saf') {
23
+ browserName = 'ios';
24
+ }
25
+ // browserslist uses ranges `15.2-15.3` versions but only the lowest is required
26
+ // to perform minimum supported feature checks. esbuild also expects a single version.
27
+ [version] = version.split('-');
28
+ if (esBuildSupportedBrowsers.has(browserName)) {
29
+ if (browserName === 'safari' && version === 'TP') {
30
+ // esbuild only supports numeric versions so `TP` is converted to a high number (999) since
31
+ // a Technology Preview (TP) of Safari is assumed to support all currently known features.
32
+ version = '999';
33
+ }
34
+ transformed.push(browserName + version);
35
+ }
36
+ }
37
+ return transformed;
38
+ }
39
+ exports.transformSupportedBrowsersToTargets = transformSupportedBrowsersToTargets;
@@ -8,4 +8,4 @@
8
8
  import { BuilderContext } from '@angular-devkit/architect';
9
9
  import { EmittedFiles } from '@angular-devkit/build-webpack';
10
10
  import { I18nOptions } from './i18n-options';
11
- export declare function i18nInlineEmittedFiles(context: BuilderContext, emittedFiles: EmittedFiles[], i18n: I18nOptions, baseOutputPath: string, outputPaths: string[], scriptsEntryPointName: string[], emittedPath: string, es5: boolean, missingTranslation: 'error' | 'warning' | 'ignore' | undefined): Promise<boolean>;
11
+ export declare function i18nInlineEmittedFiles(context: BuilderContext, emittedFiles: EmittedFiles[], i18n: I18nOptions, baseOutputPath: string, outputPaths: string[], scriptsEntryPointName: string[], emittedPath: string, missingTranslation: 'error' | 'warning' | 'ignore' | undefined): Promise<boolean>;
@@ -37,7 +37,7 @@ const action_executor_1 = require("./action-executor");
37
37
  const copy_assets_1 = require("./copy-assets");
38
38
  const error_1 = require("./error");
39
39
  const spinner_1 = require("./spinner");
40
- function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath, es5, missingTranslation, context) {
40
+ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath, missingTranslation, context) {
41
41
  const options = [];
42
42
  const originalFiles = [];
43
43
  for (const emittedFile of emittedFiles) {
@@ -50,7 +50,6 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
50
50
  const action = {
51
51
  filename: emittedFile.file,
52
52
  code: fs.readFileSync(originalPath, 'utf8'),
53
- es5,
54
53
  outputPath,
55
54
  missingTranslation,
56
55
  setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
@@ -72,13 +71,13 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
72
71
  }
73
72
  return { options, originalFiles };
74
73
  }
75
- async function i18nInlineEmittedFiles(context, emittedFiles, i18n, baseOutputPath, outputPaths, scriptsEntryPointName, emittedPath, es5, missingTranslation) {
74
+ async function i18nInlineEmittedFiles(context, emittedFiles, i18n, baseOutputPath, outputPaths, scriptsEntryPointName, emittedPath, missingTranslation) {
76
75
  const executor = new action_executor_1.BundleActionExecutor({ i18n });
77
76
  let hasErrors = false;
78
77
  const spinner = new spinner_1.Spinner();
79
78
  spinner.start('Generating localized bundles...');
80
79
  try {
81
- const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath, es5, missingTranslation, context);
80
+ const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath, missingTranslation, context);
82
81
  for await (const result of executor.inlineAll(options)) {
83
82
  context.logger.debug(`i18n file processed: ${result.file}`);
84
83
  for (const diagnostic of result.diagnostics) {
@@ -5,7 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { json } from '@angular-devkit/core';
8
+ import { json, logging } from '@angular-devkit/core';
9
9
  import { AssetPatternClass, Schema as BrowserBuilderSchema, SourceMapClass } from '../builders/browser/schema';
10
10
  import { BuildOptions } from './build-options';
11
11
  import { NormalizedFileReplacement } from './normalize-file-replacements';
@@ -19,4 +19,4 @@ export declare type NormalizedBrowserBuilderSchema = BrowserBuilderSchema & Buil
19
19
  fileReplacements: NormalizedFileReplacement[];
20
20
  optimization: NormalizedOptimizationOptions;
21
21
  };
22
- export declare function normalizeBrowserSchema(workspaceRoot: string, projectRoot: string, projectSourceRoot: string | undefined, options: BrowserBuilderSchema, metadata: json.JsonObject): NormalizedBrowserBuilderSchema;
22
+ export declare function normalizeBrowserSchema(workspaceRoot: string, projectRoot: string, projectSourceRoot: string | undefined, options: BrowserBuilderSchema, metadata: json.JsonObject, logger: logging.LoggerApi): NormalizedBrowserBuilderSchema;
@@ -14,7 +14,7 @@ const normalize_file_replacements_1 = require("./normalize-file-replacements");
14
14
  const normalize_optimization_1 = require("./normalize-optimization");
15
15
  const normalize_source_maps_1 = require("./normalize-source-maps");
16
16
  const supported_browsers_1 = require("./supported-browsers");
17
- function normalizeBrowserSchema(workspaceRoot, projectRoot, projectSourceRoot, options, metadata) {
17
+ function normalizeBrowserSchema(workspaceRoot, projectRoot, projectSourceRoot, options, metadata, logger) {
18
18
  const normalizedSourceMapOptions = (0, normalize_source_maps_1.normalizeSourceMaps)(options.sourceMap || false);
19
19
  return {
20
20
  ...options,
@@ -37,7 +37,7 @@ function normalizeBrowserSchema(workspaceRoot, projectRoot, projectSourceRoot, o
37
37
  // A value of 0 is falsy and will disable polling rather then enable
38
38
  // 500 ms is a sensible default in this case
39
39
  poll: options.poll === 0 ? 500 : options.poll,
40
- supportedBrowsers: (0, supported_browsers_1.getSupportedBrowsers)(projectRoot),
40
+ supportedBrowsers: (0, supported_browsers_1.getSupportedBrowsers)(projectRoot, logger),
41
41
  };
42
42
  }
43
43
  exports.normalizeBrowserSchema = normalizeBrowserSchema;
@@ -13,7 +13,6 @@ export interface InlineOptions {
13
13
  filename: string;
14
14
  code: string;
15
15
  map?: string;
16
- es5: boolean;
17
16
  outputPath: string;
18
17
  missingTranslation?: 'warning' | 'error' | 'ignore';
19
18
  setLocale?: boolean;
@@ -37,7 +37,7 @@ exports.inlineLocales = exports.createI18nPlugins = void 0;
37
37
  const remapping_1 = __importDefault(require("@ampproject/remapping"));
38
38
  const core_1 = require("@babel/core");
39
39
  const template_1 = __importDefault(require("@babel/template"));
40
- const fs = __importStar(require("fs"));
40
+ const fs = __importStar(require("fs/promises"));
41
41
  const path = __importStar(require("path"));
42
42
  const worker_threads_1 = require("worker_threads");
43
43
  const environment_options_1 = require("./environment-options");
@@ -73,7 +73,7 @@ async function loadLocalizeTools() {
73
73
  return (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
74
74
  }
75
75
  async function createI18nPlugins(locale, translation, missingTranslation, shouldInline, localeDataContent) {
76
- const { Diagnostics, makeEs2015TranslatePlugin, makeEs5TranslatePlugin, makeLocalePlugin } = await loadLocalizeTools();
76
+ const { Diagnostics, makeEs2015TranslatePlugin, makeLocalePlugin } = await loadLocalizeTools();
77
77
  const plugins = [];
78
78
  const diagnostics = new Diagnostics();
79
79
  if (shouldInline) {
@@ -82,11 +82,6 @@ async function createI18nPlugins(locale, translation, missingTranslation, should
82
82
  makeEs2015TranslatePlugin(diagnostics, (translation || {}), {
83
83
  missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
84
84
  }));
85
- plugins.push(
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- makeEs5TranslatePlugin(diagnostics, (translation || {}), {
88
- missingTranslation: translation === undefined ? 'ignore' : missingTranslation,
89
- }));
90
85
  }
91
86
  plugins.push(makeLocalePlugin(locale));
92
87
  if (localeDataContent) {
@@ -149,7 +144,7 @@ async function inlineLocales(options) {
149
144
  // If locale data is provided, load it and prepend to file
150
145
  const localeDataPath = (_a = i18n.locales[locale]) === null || _a === void 0 ? void 0 : _a.dataPath;
151
146
  if (localeDataPath) {
152
- localeDataContent = await loadLocaleData(localeDataPath, true, options.es5);
147
+ localeDataContent = await loadLocaleData(localeDataPath, true);
153
148
  }
154
149
  }
155
150
  const { diagnostics: localeDiagnostics, plugins } = await createI18nPlugins(locale, translations, isSourceLocale ? 'ignore' : options.missingTranslation || 'warning', true, localeDataContent);
@@ -170,10 +165,10 @@ async function inlineLocales(options) {
170
165
  throw new Error(`Unknown error occurred processing bundle for "${options.filename}".`);
171
166
  }
172
167
  const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
173
- fs.writeFileSync(outputPath, transformResult.code);
168
+ await fs.writeFile(outputPath, transformResult.code);
174
169
  if (options.map && transformResult.map) {
175
170
  const outputMap = (0, remapping_1.default)([transformResult.map, options.map], () => null);
176
- fs.writeFileSync(outputPath + '.map', JSON.stringify(outputMap));
171
+ await fs.writeFile(outputPath + '.map', JSON.stringify(outputMap));
177
172
  }
178
173
  }
179
174
  return { file: options.filename, diagnostics };
@@ -221,7 +216,7 @@ async function inlineLocalesDirect(ast, options) {
221
216
  let localeDataSource;
222
217
  const localeDataPath = i18n.locales[locale] && i18n.locales[locale].dataPath;
223
218
  if (localeDataPath) {
224
- const localeDataContent = await loadLocaleData(localeDataPath, true, options.es5);
219
+ const localeDataContent = await loadLocaleData(localeDataPath, true);
225
220
  localeDataSource = new OriginalSource(localeDataContent, path.basename(localeDataPath));
226
221
  }
227
222
  outputSource = localeDataSource
@@ -231,26 +226,26 @@ async function inlineLocalesDirect(ast, options) {
231
226
  }
232
227
  const { source: outputCode, map: outputMap } = outputSource.sourceAndMap();
233
228
  const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
234
- fs.writeFileSync(outputPath, outputCode);
229
+ await fs.writeFile(outputPath, outputCode);
235
230
  if (inputMap && outputMap) {
236
231
  outputMap.file = options.filename;
237
232
  if (mapSourceRoot) {
238
233
  outputMap.sourceRoot = mapSourceRoot;
239
234
  }
240
- fs.writeFileSync(outputPath + '.map', JSON.stringify(outputMap));
235
+ await fs.writeFile(outputPath + '.map', JSON.stringify(outputMap));
241
236
  }
242
237
  }
243
238
  return { file: options.filename, diagnostics: diagnostics.messages, count: positions.length };
244
239
  }
245
- function inlineCopyOnly(options) {
240
+ async function inlineCopyOnly(options) {
246
241
  if (!i18n) {
247
242
  throw new Error('i18n options are missing');
248
243
  }
249
244
  for (const locale of i18n.inlineLocales) {
250
245
  const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
251
- fs.writeFileSync(outputPath, options.code);
246
+ await fs.writeFile(outputPath, options.code);
252
247
  if (options.map) {
253
- fs.writeFileSync(outputPath + '.map', options.map);
248
+ await fs.writeFile(outputPath + '.map', options.map);
254
249
  }
255
250
  }
256
251
  return { file: options.filename, diagnostics: [], count: 0 };
@@ -260,43 +255,21 @@ function findLocalizePositions(ast, options, utils) {
260
255
  // Workaround to ensure a path hub is present for traversal
261
256
  const { File } = require('@babel/core');
262
257
  const file = new File({}, { code: options.code, ast });
263
- if (options.es5) {
264
- (0, core_1.traverse)(file.ast, {
265
- CallExpression(path) {
266
- const callee = path.get('callee');
267
- if (callee.isIdentifier() &&
268
- callee.node.name === localizeName &&
269
- utils.isGlobalIdentifier(callee)) {
270
- const [messageParts, expressions] = unwrapLocalizeCall(path, utils);
271
- positions.push({
272
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
273
- start: path.node.start,
274
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
275
- end: path.node.end,
276
- messageParts,
277
- expressions,
278
- });
279
- }
280
- },
281
- });
282
- }
283
- else {
284
- (0, core_1.traverse)(file.ast, {
285
- TaggedTemplateExpression(path) {
286
- if (core_1.types.isIdentifier(path.node.tag) && path.node.tag.name === localizeName) {
287
- const [messageParts, expressions] = unwrapTemplateLiteral(path, utils);
288
- positions.push({
289
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
290
- start: path.node.start,
291
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
292
- end: path.node.end,
293
- messageParts,
294
- expressions,
295
- });
296
- }
297
- },
298
- });
299
- }
258
+ (0, core_1.traverse)(file.ast, {
259
+ TaggedTemplateExpression(path) {
260
+ if (core_1.types.isIdentifier(path.node.tag) && path.node.tag.name === localizeName) {
261
+ const [messageParts, expressions] = unwrapTemplateLiteral(path, utils);
262
+ positions.push({
263
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
264
+ start: path.node.start,
265
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
266
+ end: path.node.end,
267
+ messageParts,
268
+ expressions,
269
+ });
270
+ }
271
+ },
272
+ });
300
273
  return positions;
301
274
  }
302
275
  function unwrapTemplateLiteral(path, utils) {
@@ -309,9 +282,9 @@ function unwrapLocalizeCall(path, utils) {
309
282
  const [expressions] = utils.unwrapSubstitutionsFromLocalizeCall(path);
310
283
  return [messageParts, expressions];
311
284
  }
312
- async function loadLocaleData(path, optimize, es5) {
285
+ async function loadLocaleData(path, optimize) {
313
286
  // The path is validated during option processing before the build starts
314
- const content = fs.readFileSync(path, 'utf8');
287
+ const content = await fs.readFile(path, 'utf8');
315
288
  // Downlevel and optimize the data
316
289
  const transformResult = await (0, core_1.transformAsync)(content, {
317
290
  filename: path,
@@ -325,8 +298,7 @@ async function loadLocaleData(path, optimize, es5) {
325
298
  require.resolve('@babel/preset-env'),
326
299
  {
327
300
  bugfixes: true,
328
- // IE 11 is the oldest supported browser
329
- targets: es5 ? { ie: '11' } : { esmodules: true },
301
+ targets: { esmodules: true },
330
302
  },
331
303
  ],
332
304
  ],
@@ -5,4 +5,5 @@
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 declare function getSupportedBrowsers(projectRoot: string): string[];
8
+ import { logging } from '@angular-devkit/core';
9
+ export declare function getSupportedBrowsers(projectRoot: string, logger: logging.LoggerApi): string[];
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.getSupportedBrowsers = void 0;
14
14
  const browserslist_1 = __importDefault(require("browserslist"));
15
- function getSupportedBrowsers(projectRoot) {
15
+ function getSupportedBrowsers(projectRoot, logger) {
16
16
  browserslist_1.default.defaults = [
17
17
  'last 1 Chrome version',
18
18
  'last 1 Firefox version',
@@ -21,6 +21,22 @@ function getSupportedBrowsers(projectRoot) {
21
21
  'last 2 iOS major versions',
22
22
  'Firefox ESR',
23
23
  ];
24
- return (0, browserslist_1.default)(undefined, { path: projectRoot });
24
+ // Get browsers from config or default.
25
+ const browsersFromConfigOrDefault = new Set((0, browserslist_1.default)(undefined, { path: projectRoot }));
26
+ // Get browsers that support ES6 modules.
27
+ const browsersThatSupportEs6 = new Set((0, browserslist_1.default)('supports es6-module'));
28
+ const unsupportedBrowsers = [];
29
+ for (const browser of browsersFromConfigOrDefault) {
30
+ if (!browsersThatSupportEs6.has(browser)) {
31
+ browsersFromConfigOrDefault.delete(browser);
32
+ unsupportedBrowsers.push(browser);
33
+ }
34
+ }
35
+ if (unsupportedBrowsers.length) {
36
+ logger.warn(`One or more browsers which are configured in the project's Browserslist configuration ` +
37
+ 'will be ignored as ES5 output is not supported by the Angular CLI.\n' +
38
+ `Ignored browsers: ${unsupportedBrowsers.join(', ')}`);
39
+ }
40
+ return Array.from(browsersFromConfigOrDefault);
25
41
  }
26
42
  exports.getSupportedBrowsers = getSupportedBrowsers;
@@ -7,7 +7,6 @@
7
7
  */
8
8
  import { BuilderContext } from '@angular-devkit/architect';
9
9
  import { logging } from '@angular-devkit/core';
10
- import { ScriptTarget } from 'typescript';
11
10
  import { Configuration } from 'webpack';
12
11
  import { Schema as BrowserBuilderSchema } from '../builders/browser/schema';
13
12
  import { NormalizedBrowserBuilderSchema } from '../utils';
@@ -21,7 +20,6 @@ export declare function generateI18nBrowserWebpackConfigFromContext(options: Bro
21
20
  projectRoot: string;
22
21
  projectSourceRoot?: string;
23
22
  i18n: I18nOptions;
24
- target: ScriptTarget;
25
23
  }>;
26
24
  export declare function generateBrowserWebpackConfigFromContext(options: BrowserBuilderSchema, context: BuilderContext, webpackPartialGenerator: WebpackPartialGenerator, extraBuildOptions?: Partial<NormalizedBrowserBuilderSchema>): Promise<{
27
25
  config: Configuration;
@@ -32,7 +32,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
33
  exports.getIndexInputFile = exports.getIndexOutputFile = exports.generateBrowserWebpackConfigFromContext = exports.generateI18nBrowserWebpackConfigFromContext = exports.generateWebpackConfig = void 0;
34
34
  const path = __importStar(require("path"));
35
- const typescript_1 = require("typescript");
36
35
  const webpack_1 = require("webpack");
37
36
  const webpack_merge_1 = require("webpack-merge");
38
37
  const utils_1 = require("../utils");
@@ -46,8 +45,6 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, pro
46
45
  }
47
46
  const tsConfigPath = path.resolve(workspaceRoot, options.tsConfig);
48
47
  const tsConfig = await (0, read_tsconfig_1.readTsconfig)(tsConfigPath);
49
- const ts = await Promise.resolve().then(() => __importStar(require('typescript')));
50
- const scriptTarget = tsConfig.options.target || ts.ScriptTarget.ES5;
51
48
  const buildOptions = { ...options, ...extraBuildOptions };
52
49
  const wco = {
53
50
  root: workspaceRoot,
@@ -58,7 +55,6 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, pro
58
55
  tsConfig,
59
56
  tsConfigPath,
60
57
  projectName,
61
- scriptTarget,
62
58
  };
63
59
  wco.buildOptions.progress = (0, utils_1.defaultProgress)(wco.buildOptions.progress);
64
60
  const partials = await Promise.all(webpackPartialGenerator(wco));
@@ -69,9 +65,7 @@ exports.generateWebpackConfig = generateWebpackConfig;
69
65
  async function generateI18nBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
70
66
  var _a;
71
67
  const { buildOptions, i18n } = await (0, i18n_options_1.configureI18nBuild)(context, options);
72
- let target = typescript_1.ScriptTarget.ES5;
73
68
  const result = await generateBrowserWebpackConfigFromContext(buildOptions, context, (wco) => {
74
- target = wco.scriptTarget;
75
69
  return webpackPartialGenerator(wco);
76
70
  }, extraBuildOptions);
77
71
  const config = result.config;
@@ -107,7 +101,7 @@ async function generateI18nBrowserWebpackConfigFromContext(options, context, web
107
101
  },
108
102
  });
109
103
  }
110
- return { ...result, i18n, target };
104
+ return { ...result, i18n };
111
105
  }
112
106
  exports.generateI18nBrowserWebpackConfigFromContext = generateI18nBrowserWebpackConfigFromContext;
113
107
  async function generateBrowserWebpackConfigFromContext(options, context, webpackPartialGenerator, extraBuildOptions = {}) {
@@ -121,7 +115,7 @@ async function generateBrowserWebpackConfigFromContext(options, context, webpack
121
115
  const projectRoot = path.join(workspaceRoot, (_a = projectMetadata.root) !== null && _a !== void 0 ? _a : '');
122
116
  const sourceRoot = projectMetadata.sourceRoot;
123
117
  const projectSourceRoot = sourceRoot ? path.join(workspaceRoot, sourceRoot) : undefined;
124
- const normalizedOptions = (0, utils_1.normalizeBrowserSchema)(workspaceRoot, projectRoot, projectSourceRoot, options, projectMetadata);
118
+ const normalizedOptions = (0, utils_1.normalizeBrowserSchema)(workspaceRoot, projectRoot, projectSourceRoot, options, projectMetadata, context.logger);
125
119
  const config = await generateWebpackConfig(workspaceRoot, projectRoot, projectSourceRoot, projectName, normalizedOptions, webpackPartialGenerator, context.logger, extraBuildOptions);
126
120
  // If builder watch support is present in the context, add watch plugin
127
121
  // This is internal only and currently only used for testing
@@ -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,
@@ -313,7 +312,6 @@ async function getCommonConfig(wco) {
313
312
  loader: require.resolve('../../babel/webpack-loader'),
314
313
  options: {
315
314
  cacheDirectory: (cache.enabled && path.join(cache.path, 'babel-webpack')) || false,
316
- scriptTarget,
317
315
  aot: buildOptions.aot,
318
316
  optimize: buildOptions.buildOptimizer,
319
317
  supportedBrowsers: buildOptions.supportedBrowsers,