forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupported-browsers.ts
62 lines (52 loc) · 2.22 KB
/
supported-browsers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import browserslist from 'browserslist';
export function getSupportedBrowsers(
projectRoot: string,
logger: { warn(message: string): void },
): string[] {
// Read the browserslist configuration containing Angular's browser support policy.
const angularBrowserslist = browserslist(undefined, {
path: require.resolve('../../.browserslistrc'),
});
// Use Angular's configuration as the default.
browserslist.defaults = angularBrowserslist;
// Get the minimum set of browser versions supported by Angular.
const minimumBrowsers = new Set(angularBrowserslist);
// Get browsers from config or default.
const browsersFromConfigOrDefault = new Set(browserslist(undefined, { path: projectRoot }));
// Get browsers that support ES6 modules.
const browsersThatSupportEs6 = new Set(browserslist('supports es6-module'));
const nonEs6Browsers: string[] = [];
const unsupportedBrowsers: string[] = [];
for (const browser of browsersFromConfigOrDefault) {
if (!browsersThatSupportEs6.has(browser)) {
// Any browser which does not support ES6 is explicitly ignored, as Angular will not build successfully.
browsersFromConfigOrDefault.delete(browser);
nonEs6Browsers.push(browser);
} else if (!minimumBrowsers.has(browser)) {
// Any other unsupported browser we will attempt to use, but provide no support for.
unsupportedBrowsers.push(browser);
}
}
if (nonEs6Browsers.length) {
logger.warn(
`One or more browsers which are configured in the project's Browserslist configuration ` +
'will be ignored as ES5 output is not supported by the Angular CLI.\n' +
`Ignored browsers:\n${nonEs6Browsers.join(', ')}`,
);
}
if (unsupportedBrowsers.length) {
logger.warn(
`One or more browsers which are configured in the project's Browserslist configuration ` +
"fall outside Angular's browser support for this version.\n" +
`Unsupported browsers:\n${unsupportedBrowsers.join(', ')}`,
);
}
return Array.from(browsersFromConfigOrDefault);
}