Skip to content

Commit 4d7388f

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 98c1bd6 commit 4d7388f

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.5.1",
1717
"browserslist": "4.5.5",
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.2",

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"
@@ -1823,20 +1823,10 @@ camelcase@^5.0.0:
18231823
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
18241824
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
18251825

1826-
1827-
version "3.0.0"
1828-
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-3.0.0.tgz#5e4d90e2274961d46291997df599e3ed008ee4c0"
1829-
integrity sha512-bsTwuIg/BZZK/vreVTYYbSWoe2F+71P7K5QGEX+pT250DZbfU1MQ5prOKpPR+LL6uWKK3KMwMCAS74QB3Um1uw==
1830-
dependencies:
1831-
browserslist "^4.0.0"
1832-
caniuse-lite "^1.0.0"
1833-
lodash.memoize "^4.1.2"
1834-
lodash.uniq "^4.5.0"
1835-
1836-
caniuse-lite@^1.0.0:
1837-
version "1.0.30000955"
1838-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000955.tgz#360fdb9a1e41d6dd996130411334e44a39e4446d"
1839-
integrity sha512-6AwmIKgqCYfDWWadRkAuZSHMQP4Mmy96xAXEdRBlN/luQhlRYOKgwOlZ9plpCOsVbBuqbTmGqDK3JUM/nlr8CA==
1826+
1827+
version "1.0.30000974"
1828+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000974.tgz#b7afe14ee004e97ce6dc73e3f878290a12928ad8"
1829+
integrity sha512-xc3rkNS/Zc3CmpMKuczWEdY2sZgx09BkAxfvkxlAEBTqcMHeL8QnPqhKse+5sRTi3nrw2pJwToD2WvKn1Uhvww==
18401830

18411831
caniuse-lite@^1.0.30000898:
18421832
version "1.0.30000903"
@@ -5700,11 +5690,6 @@ lodash.get@^4.4.2:
57005690
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
57015691
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
57025692

5703-
lodash.memoize@^4.1.2:
5704-
version "4.1.2"
5705-
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
5706-
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
5707-
57085693
lodash.tail@^4.1.1:
57095694
version "4.1.1"
57105695
resolved "https://registry.yarnpkg.com/lodash.tail/-/lodash.tail-4.1.1.tgz#d2333a36d9e7717c8ad2f7cacafec7c32b444664"
@@ -5725,11 +5710,6 @@ lodash.templatesettings@^4.0.0:
57255710
dependencies:
57265711
lodash._reinterpolate "~3.0.0"
57275712

5728-
lodash.uniq@^4.5.0:
5729-
version "4.5.0"
5730-
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
5731-
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
5732-
57335713
lodash@^4.16.6, lodash@^4.17.11, lodash@^4.17.5:
57345714
version "4.17.11"
57355715
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"

0 commit comments

Comments
 (0)