Skip to content

Commit 69e47c2

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/build-angular): browsers that partially support ES6 modules are being marked as not supported
`caniuse-api` only returns `true` for a feature when it's fully supported. This might causes redundant ES5 builds if users opt to support only browsers which do support ES6 modules but either require polyfills such as Safari 10.1 or when both bundles will be downloaded such as `Edge 18` See: https://github.com/Nyalab/caniuse-api/blob/1b74c10257e36877709da4f6630513db10203a78/src/index.js#L49 and Nyalab/caniuse-api#82 Fixes #14580
1 parent 36d9e93 commit 69e47c2

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"@bazel/typescript": "~0.26.0",
8989
"@ngtools/json-schema": "^1.1.0",
9090
"@types/browserslist": "^4.4.0",
91-
"@types/caniuse-api": "^3.0.0",
91+
"@types/caniuse-lite": "^1.0.0",
9292
"@types/copy-webpack-plugin": "^4.4.1",
9393
"@types/express": "^4.16.0",
9494
"@types/glob": "^7.0.0",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ajv": "6.10.0",
1616
"autoprefixer": "9.6.0",
1717
"browserslist": "4.6.2",
18-
"caniuse-api": "3.0.0",
18+
"caniuse-lite": "1.0.30000974",
1919
"circular-dependency-plugin": "5.0.2",
2020
"clean-css": "4.2.1",
2121
"copy-webpack-plugin": "5.0.3",

packages/angular_devkit/build_angular/src/utils/build-browser-features.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class BuildBrowserFeatures {
3434
* True, when one or more browsers requires ES5 support
3535
*/
3636
isEs5SupportNeeded(): boolean {
37-
return !caniuse.isSupported('es6-module', this._supportedBrowsers.join(', '));
37+
return !this.isFeatureSupported('es6-module');
3838
}
3939

4040
/**
@@ -55,4 +55,33 @@ export class BuildBrowserFeatures {
5555

5656
return this._supportedBrowsers.some(browser => safariBrowsers.includes(browser));
5757
}
58+
59+
/**
60+
* True, when a browser feature is supported partially or fully.
61+
*/
62+
isFeatureSupported(featureId: string): boolean {
63+
// y: feature is fully available
64+
// n: feature is unavailable
65+
// a: feature is partially supported
66+
// x: feature is prefixed
67+
const criteria = [
68+
'y',
69+
'a',
70+
];
71+
72+
const data = feature(features[featureId]);
73+
74+
return !this._supportedBrowsers
75+
.some(browser => {
76+
const [agentId, version] = browser.split(' ');
77+
78+
const browserData = data.stats[agentId];
79+
const featureStatus = (browserData && browserData[version]) as string | undefined;
80+
81+
// We are only interested in the first character
82+
// Ex: when 'a #4 #5', we only need to check for 'a'
83+
// as for such cases we should polyfill these features as needed
84+
return !featureStatus || !criteria.includes(featureStatus.charAt(0));
85+
});
86+
}
5887
}

yarn.lock

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@
300300
resolved "https://registry.yarnpkg.com/@types/browserslist/-/browserslist-4.4.0.tgz#e2a5f7f8c7e97afb39f50812a77e5230d3ca2353"
301301
integrity sha512-hrIjWSu7Hh96/rKlpChe58qHEwIZ0+F5Zf4QNdvSVP5LUXbaJM04g9tBjo702VTNqPZr5znEJeqNR3nAV3vJPg==
302302

303-
"@types/caniuse-api@^3.0.0":
304-
version "3.0.0"
305-
resolved "https://registry.yarnpkg.com/@types/caniuse-api/-/caniuse-api-3.0.0.tgz#af31cc52062be0ab24583be072fd49b634dcc2fe"
306-
integrity sha512-wT1VfnScjAftZsvLYaefu/UuwYJdYBwD2JDL2OQd01plGmuAoir5V6HnVHgrfh7zEwcasoiyO2wQ+W58sNh2sw==
303+
"@types/caniuse-lite@^1.0.0":
304+
version "1.0.0"
305+
resolved "https://registry.yarnpkg.com/@types/caniuse-lite/-/caniuse-lite-1.0.0.tgz#6506ed4b3f8d19def130d19419062960e86cc3bc"
306+
integrity sha512-g28510gzJpFL0xqvuGAlI+dfIr3qvUcZQVFc7f7u2VlWVqI1oBkWhGLYh3fXfoflR7HRnU4w0NRux0pPJQ7VVg==
307307

308308
"@types/caseless@*":
309309
version "0.12.1"
@@ -1871,20 +1871,10 @@ camelcase@^5.0.0:
18711871
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
18721872
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
18731873

1874-
caniuse-api@3.0.0:
1875-
version "3.0.0"
1876-
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-3.0.0.tgz#5e4d90e2274961d46291997df599e3ed008ee4c0"
1877-
integrity sha512-bsTwuIg/BZZK/vreVTYYbSWoe2F+71P7K5QGEX+pT250DZbfU1MQ5prOKpPR+LL6uWKK3KMwMCAS74QB3Um1uw==
1878-
dependencies:
1879-
browserslist "^4.0.0"
1880-
caniuse-lite "^1.0.0"
1881-
lodash.memoize "^4.1.2"
1882-
lodash.uniq "^4.5.0"
1883-
1884-
caniuse-lite@^1.0.0:
1885-
version "1.0.30000955"
1886-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000955.tgz#360fdb9a1e41d6dd996130411334e44a39e4446d"
1887-
integrity sha512-6AwmIKgqCYfDWWadRkAuZSHMQP4Mmy96xAXEdRBlN/luQhlRYOKgwOlZ9plpCOsVbBuqbTmGqDK3JUM/nlr8CA==
1874+
caniuse-lite@1.0.30000974:
1875+
version "1.0.30000974"
1876+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000974.tgz#b7afe14ee004e97ce6dc73e3f878290a12928ad8"
1877+
integrity sha512-xc3rkNS/Zc3CmpMKuczWEdY2sZgx09BkAxfvkxlAEBTqcMHeL8QnPqhKse+5sRTi3nrw2pJwToD2WvKn1Uhvww==
18881878

18891879
caniuse-lite@^1.0.30000898:
18901880
version "1.0.30000903"
@@ -5870,11 +5860,6 @@ lodash.get@^4.4.2:
58705860
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
58715861
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
58725862

5873-
lodash.memoize@^4.1.2:
5874-
version "4.1.2"
5875-
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
5876-
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
5877-
58785863
lodash.tail@^4.1.1:
58795864
version "4.1.1"
58805865
resolved "https://registry.yarnpkg.com/lodash.tail/-/lodash.tail-4.1.1.tgz#d2333a36d9e7717c8ad2f7cacafec7c32b444664"
@@ -5895,11 +5880,6 @@ lodash.templatesettings@^4.0.0:
58955880
dependencies:
58965881
lodash._reinterpolate "~3.0.0"
58975882

5898-
lodash.uniq@^4.5.0:
5899-
version "4.5.0"
5900-
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
5901-
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
5902-
59035883
lodash@^4.16.6, lodash@^4.17.11, lodash@^4.17.5:
59045884
version "4.17.11"
59055885
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"

0 commit comments

Comments
 (0)