Skip to content

Commit cdb404b

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): warn if using unsupported IE9/10 browsers
As of Angular v11, IE9 and IE10 are no longer officially supported. A warning will now be shown during builds if these browsers are requested in the project's browserslist configuration.
1 parent e64ea69 commit cdb404b

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ export function buildWebpackBrowser(
256256
`);
257257
}
258258

259+
const hasIE9 = buildBrowserFeatures.supportedBrowsers.includes('ie 9');
260+
const hasIE10 = buildBrowserFeatures.supportedBrowsers.includes('ie 10');
261+
if (hasIE9 || hasIE10) {
262+
const browsers =
263+
(hasIE9 ? 'IE 9' + (hasIE10 ? ' & ' : '') : '') + (hasIE10 ? 'IE 10' : '');
264+
context.logger.warn(
265+
`WARNING: Support was requested for ${browsers} in the project's browserslist configuration. ` +
266+
(hasIE9 && hasIE10 ? 'These browsers are' : 'This browser is') +
267+
' no longer officially supported with Angular v11 and higher.' +
268+
'\nFor additional information: https://v10.angular.io/guide/deprecations#ie-9-10-and-mobile',
269+
);
270+
}
271+
259272
return {
260273
...(await initialize(options, context, host, differentialLoadingMode, transforms.webpackConfiguration)),
261274
buildBrowserFeatures,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { Architect } from '@angular-devkit/architect';
9+
import { logging } from '@angular-devkit/core';
10+
import { createArchitect, host } from '../../test-utils';
11+
12+
describe('Browser Builder browser support', () => {
13+
const targetSpec = { project: 'app', target: 'build' };
14+
let architect: Architect;
15+
16+
beforeEach(async () => {
17+
await host.initialize().toPromise();
18+
architect = (await createArchitect(host.root())).architect;
19+
20+
// target ES5 to disable differential loading which is not needed for the tests
21+
host.replaceInFile('tsconfig.json', '"target": "es2015"', '"target": "es5"');
22+
});
23+
afterEach(async () => host.restore().toPromise());
24+
25+
it('warns when IE9 is present in browserslist', async () => {
26+
host.appendToFile('.browserslistrc', '\nIE 9');
27+
28+
const logger = new logging.Logger('');
29+
const logs: string[] = [];
30+
logger.subscribe((e) => logs.push(e.message));
31+
32+
const run = await architect.scheduleTarget(targetSpec, undefined, { logger });
33+
const output = await run.result;
34+
expect(output.success).toBe(true);
35+
36+
const fullLog = logs.join();
37+
expect(fullLog).toContain(
38+
"WARNING: Support was requested for IE 9 in the project's browserslist configuration.",
39+
);
40+
expect(fullLog).toContain('This browser is ');
41+
42+
await run.stop();
43+
});
44+
45+
it('warns when IE10 is present in browserslist', async () => {
46+
host.appendToFile('.browserslistrc', '\nIE 10');
47+
48+
const logger = new logging.Logger('');
49+
const logs: string[] = [];
50+
logger.subscribe((e) => logs.push(e.message));
51+
52+
const run = await architect.scheduleTarget(targetSpec, undefined, { logger });
53+
const output = await run.result;
54+
expect(output.success).toBe(true);
55+
56+
const fullLog = logs.join();
57+
expect(fullLog).toContain(
58+
"WARNING: Support was requested for IE 10 in the project's browserslist configuration.",
59+
);
60+
expect(fullLog).toContain('This browser is ');
61+
62+
await run.stop();
63+
});
64+
65+
it('warns when both IE9 & IE10 are present in browserslist', async () => {
66+
host.appendToFile('.browserslistrc', '\nIE 9-10');
67+
68+
const logger = new logging.Logger('');
69+
const logs: string[] = [];
70+
logger.subscribe((e) => logs.push(e.message));
71+
72+
const run = await architect.scheduleTarget(targetSpec, undefined, { logger });
73+
const output = await run.result;
74+
expect(output.success).toBe(true);
75+
76+
const fullLog = logs.join();
77+
expect(fullLog).toContain(
78+
"WARNING: Support was requested for IE 9 & IE 10 in the project's browserslist configuration.",
79+
);
80+
expect(fullLog).toContain('These browsers are ');
81+
82+
await run.stop();
83+
});
84+
});

0 commit comments

Comments
 (0)