Skip to content

Commit 12931ba

Browse files
alan-agius4dgp1130
authored andcommitted
refactor(@angular-devkit/build-angular): remove deprecated ES5 support
Remove deprecated support for ES5 output. BREAKING CHANGE: Producing ES5 output is no longer possible. This was needed for Internet Explorer which is no longer supported. All browsers that Angular supports work with ES2015+
1 parent 1c21e47 commit 12931ba

22 files changed

+268
-589
lines changed

packages/angular_devkit/build_angular/src/babel/presets/application.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
DiagnosticHandlingStrategy,
1212
Diagnostics,
1313
makeEs2015TranslatePlugin,
14-
makeEs5TranslatePlugin,
1514
makeLocalePlugin,
1615
} from '@angular/localize/tools';
1716
import { strict as assert } from 'assert';
@@ -28,7 +27,6 @@ export type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: s
2827
*/
2928
export interface I18nPluginCreators {
3029
makeEs2015TranslatePlugin: typeof makeEs2015TranslatePlugin;
31-
makeEs5TranslatePlugin: typeof makeEs5TranslatePlugin;
3230
makeLocalePlugin: typeof makeLocalePlugin;
3331
}
3432

@@ -117,20 +115,14 @@ function createI18nPlugins(
117115
const diagnostics = createI18nDiagnostics(diagnosticReporter);
118116
const plugins = [];
119117

120-
const { makeEs5TranslatePlugin, makeEs2015TranslatePlugin, makeLocalePlugin } = pluginCreators;
118+
const { makeEs2015TranslatePlugin, makeLocalePlugin } = pluginCreators;
121119

122120
if (translation) {
123121
plugins.push(
124122
makeEs2015TranslatePlugin(diagnostics, translation, {
125123
missingTranslation: missingTranslationBehavior,
126124
}),
127125
);
128-
129-
plugins.push(
130-
makeEs5TranslatePlugin(diagnostics, translation, {
131-
missingTranslation: missingTranslationBehavior,
132-
}),
133-
);
134126
}
135127

136128
plugins.push(makeLocalePlugin(locale));

packages/angular_devkit/build_angular/src/babel/webpack-loader.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,7 @@ export default custom<ApplicationPresetOptions>(() => {
117117
const esTarget = scriptTarget as ScriptTarget | undefined;
118118
const isJsFile = /\.[cm]?js$/.test(this.resourcePath);
119119

120-
// The below should be dropped when we no longer support ES5 TypeScript output.
121-
if (esTarget === ScriptTarget.ES5) {
122-
// This is needed because when target is ES5 we change the TypeScript target to ES2015
123-
// because it simplifies build-optimization passes.
124-
// @see https://github.com/angular/angular-cli/blob/22af6520834171d01413d4c7e4a9f13fb752252e/packages/angular_devkit/build_angular/src/webpack/plugins/typescript.ts#L51-L56
125-
customOptions.forcePresetEnv = true;
126-
// Comparable behavior to tsconfig target of ES5
127-
customOptions.supportedBrowsers = ['IE 9'];
128-
} else if (isJsFile && customOptions.supportedBrowsers?.length) {
120+
if (isJsFile && customOptions.supportedBrowsers?.length) {
129121
// Applications code ES version can be controlled using TypeScript's `target` option.
130122
// However, this doesn't effect libraries and hence we use preset-env to downlevel ES fetaures
131123
// based on the supported browsers in browserlist.

packages/angular_devkit/build_angular/src/builders/browser/index.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
1010
import { EmittedFiles, WebpackLoggingCallback, runWebpack } from '@angular-devkit/build-webpack';
11-
import { logging } from '@angular-devkit/core';
1211
import * as fs from 'fs';
1312
import * as path from 'path';
1413
import { Observable, from } from 'rxjs';
1514
import { concatMap, map, switchMap } from 'rxjs/operators';
16-
import { ScriptTarget } from 'typescript';
1715
import webpack from 'webpack';
1816
import { ExecutionTransformer } from '../../transforms';
1917
import {
@@ -43,7 +41,6 @@ import { generateEntryPoints } from '../../utils/package-chunk-sort';
4341
import { purgeStaleBuildCache } from '../../utils/purge-cache';
4442
import { augmentAppWithServiceWorker } from '../../utils/service-worker';
4543
import { Spinner } from '../../utils/spinner';
46-
import { getSupportedBrowsers } from '../../utils/supported-browsers';
4744
import { assertCompatibleAngularVersion } from '../../utils/version';
4845
import {
4946
generateI18nBrowserWebpackConfigFromContext,
@@ -98,14 +95,13 @@ async function initialize(
9895
projectRoot: string;
9996
projectSourceRoot?: string;
10097
i18n: I18nOptions;
101-
target: ScriptTarget;
10298
}> {
10399
const originalOutputPath = options.outputPath;
104100

105101
// Assets are processed directly by the builder except when watching
106102
const adjustedOptions = options.watch ? options : { ...options, assets: [] };
107103

108-
const { config, projectRoot, projectSourceRoot, i18n, target } =
104+
const { config, projectRoot, projectSourceRoot, i18n } =
109105
await generateI18nBrowserWebpackConfigFromContext(adjustedOptions, context, (wco) => [
110106
getCommonConfig(wco),
111107
getStylesConfig(wco),
@@ -135,7 +131,7 @@ async function initialize(
135131
deleteOutputDir(context.workspaceRoot, originalOutputPath);
136132
}
137133

138-
return { config: transformedConfig || config, projectRoot, projectSourceRoot, i18n, target };
134+
return { config: transformedConfig || config, projectRoot, projectSourceRoot, i18n };
139135
}
140136

141137
/**
@@ -170,9 +166,6 @@ export function buildWebpackBrowser(
170166
// Initialize builder
171167
const initialization = await initialize(options, context, transforms.webpackConfiguration);
172168

173-
// Check and warn about IE browser support
174-
checkInternetExplorerSupport(initialization.projectRoot, context.logger);
175-
176169
// Add index file to watched files.
177170
if (options.watch) {
178171
const indexInputFile = path.join(context.workspaceRoot, getIndexInputFile(options.index));
@@ -193,7 +186,7 @@ export function buildWebpackBrowser(
193186
}),
194187
switchMap(
195188
// eslint-disable-next-line max-lines-per-function
196-
({ config, projectRoot, projectSourceRoot, i18n, target, cacheOptions }) => {
189+
({ config, projectRoot, projectSourceRoot, i18n, cacheOptions }) => {
197190
const normalizedOptimization = normalizeOptimization(options.optimization);
198191

199192
return runWebpack(config, context, {
@@ -255,7 +248,6 @@ export function buildWebpackBrowser(
255248
Array.from(outputPaths.values()),
256249
scriptsEntryPointName,
257250
webpackOutputPath,
258-
target <= ScriptTarget.ES5,
259251
options.i18nMissingTranslation,
260252
);
261253
if (!success) {
@@ -458,15 +450,4 @@ function mapEmittedFilesToFileInfo(files: EmittedFiles[] = []): FileInfo[] {
458450
return filteredFiles;
459451
}
460452

461-
function checkInternetExplorerSupport(projectRoot: string, logger: logging.LoggerApi): void {
462-
const supportedBrowsers = getSupportedBrowsers(projectRoot);
463-
if (supportedBrowsers.some((b) => b === 'ie 9' || b === 'ie 10' || b === 'ie 11')) {
464-
logger.warn(
465-
`Warning: Support was requested for Internet Explorer in the project's browserslist configuration. ` +
466-
'Internet Explorer is no longer officially supported.' +
467-
'\nFor more information, see https://angular.io/guide/browser-support',
468-
);
469-
}
470-
}
471-
472453
export default createBuilder<BrowserBuilderSchema>(buildWebpackBrowser);

packages/angular_devkit/build_angular/src/builders/browser/specs/allow-js_spec.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ describe('Browser Builder allow js', () => {
2929
'src/main.ts': `import { a } from './my-js-file'; console.log(a);`,
3030
});
3131

32-
host.replaceInFile('tsconfig.json', '"target": "es2020"', '"target": "es5", "allowJs": true');
32+
host.replaceInFile(
33+
'tsconfig.json',
34+
'"target": "es2020"',
35+
'"target": "es2020", "allowJs": true',
36+
);
3337

3438
const run = await architect.scheduleTarget(targetSpec);
3539
const output = (await run.result) as BrowserBuilderOutput;
@@ -39,7 +43,7 @@ describe('Browser Builder allow js', () => {
3943
await host.read(join(normalize(output.outputPath), 'main.js')).toPromise(),
4044
);
4145

42-
expect(content).toContain('var a = 2');
46+
expect(content).toContain('const a = 2');
4347

4448
await run.stop();
4549
});
@@ -50,7 +54,11 @@ describe('Browser Builder allow js', () => {
5054
'src/main.ts': `import { a } from './my-js-file'; console.log(a);`,
5155
});
5256

53-
host.replaceInFile('tsconfig.json', '"target": "es2020"', '"target": "es5", "allowJs": true');
57+
host.replaceInFile(
58+
'tsconfig.json',
59+
'"target": "es2020"',
60+
'"target": "es2020", "allowJs": true',
61+
);
5462

5563
const overrides = { aot: true };
5664

@@ -62,7 +70,7 @@ describe('Browser Builder allow js', () => {
6270
await host.read(join(normalize(output.outputPath), 'main.js')).toPromise(),
6371
);
6472

65-
expect(content).toContain('var a = 2');
73+
expect(content).toContain('const a = 2');
6674

6775
await run.stop();
6876
});
@@ -73,7 +81,11 @@ describe('Browser Builder allow js', () => {
7381
'src/main.ts': `import { a } from './my-js-file'; console.log(a);`,
7482
});
7583

76-
host.replaceInFile('tsconfig.json', '"target": "es2020"', '"target": "es5", "allowJs": true');
84+
host.replaceInFile(
85+
'tsconfig.json',
86+
'"target": "es2020"',
87+
'"target": "es2020", "allowJs": true',
88+
);
7789

7890
const overrides = { watch: true };
7991

@@ -88,13 +100,13 @@ describe('Browser Builder allow js', () => {
88100

89101
switch (buildCount) {
90102
case 1:
91-
expect(content).toContain('var a = 2');
103+
expect(content).toContain('const a = 2');
92104
host.writeMultipleFiles({
93105
'src/my-js-file.js': `console.log(1); export const a = 1;`,
94106
});
95107
break;
96108
case 2:
97-
expect(content).toContain('var a = 1');
109+
expect(content).toContain('const a = 1');
98110
break;
99111
}
100112

packages/angular_devkit/build_angular/src/builders/browser/specs/browser-support_spec.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/builders/browser/specs/optimization-level_spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ describe('Browser Builder optimization level', () => {
2626
expect(await files['main.js']).not.toContain('AppComponent');
2727
});
2828

29-
it('tsconfig target changes optimizations to use es2017', async () => {
30-
host.replaceInFile('tsconfig.json', '"target": "es5"', '"target": "es2017"');
31-
32-
const overrides = { optimization: true };
33-
const { files } = await browserBuild(architect, host, target, overrides);
34-
expect(await files['vendor.js']).toMatch(/class \w{1,3}{constructor\(\){/);
35-
});
36-
3729
it('supports styles only optimizations', async () => {
3830
const overrides = {
3931
optimization: {

packages/angular_devkit/build_angular/src/builders/browser/specs/resolve-json-module_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Browser Builder resolve json module', () => {
3030
host.replaceInFile(
3131
'tsconfig.json',
3232
'"target": "es2020"',
33-
'"target": "es5", "resolveJsonModule": true',
33+
'"target": "es2020", "resolveJsonModule": true',
3434
);
3535

3636
const overrides = { watch: true };

0 commit comments

Comments
 (0)