From 16df7675c13bdc1fa598ba0d4f6466c138d37825 Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Thu, 11 May 2023 01:47:10 +0000 Subject: [PATCH] Redefine browser requirements for modern (latest) builds --- .browserslistrc | 29 ++++---- build-scripts/bundle.cjs | 9 ++- build-scripts/gulp/entry-html.js | 5 ++ cast/src/html/faq.html.template | 8 +-- cast/src/html/index.html.template | 10 +-- cast/src/html/media.html.template | 10 +-- demo/src/html/index.html.template | 11 +--- hassio/src/entrypoint.js.template | 10 +-- package.json | 1 + src/html/_js_base.html.template | 2 +- ....template => _script_loader.html.template} | 8 +++ src/html/authorize.html.template | 9 +-- src/html/index.html.template | 3 +- src/html/onboarding.html.template | 9 +-- yarn.lock | 66 ++++++++++++++++++- 15 files changed, 116 insertions(+), 74 deletions(-) rename src/html/{_script_load_es5.html.template => _script_loader.html.template} (65%) diff --git a/.browserslistrc b/.browserslistrc index 516fec9cec5e..1fae163d7531 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -1,24 +1,21 @@ [modern] -# Support for dynamic import is the main litmus test for serving modern builds. -# Although officially a ES2020 feature, browsers implemented it early, so this -# enables all of ES2017 and some features in ES2018. -supports es6-module-dynamic-import - -# Exclude Safari 11-12 because of a bug in tagged template literals -# https://bugs.webkit.org/show_bug.cgi?id=190756 -# Note: Dropping version 11 also enables several more ES2018 features -not Safari < 13 -not iOS < 13 - -# Exclude KaiOS, QQ, and UC browsers due to lack of sufficient feature support data -# Babel ignores these automatically, but we need here for Webpack to output ESM with dynamic imports +# Modern builds target recent browsers supporting the latest features to minimize transpilation, polyfills,etc. +# It is served to browsers meeting the following requirements: +# - last 2 released + current alpha/beta versionss of all major browsers +# - Firefox extended support release (ESR) +# - browsers with global utilization above 0.5% +# - must support dynamic import of ES modules +# - exclude browsers no longer being maintained +# - exclude KaiOS, QQ, and UC browsers due to lack of sufficient feature support data +unreleased versions +last 2 versions +Firefox ESR +> 0.5% and supports es6-module-dynamic-import +not dead not KaiOS > 0 not QQAndroid > 0 not UCAndroid > 0 -# Exclude unsupported browsers -not dead - [legacy] # Legacy builds are served when modern requirements are not met and support browsers: # - released in the last 7 years + current alpha/beta versionss diff --git a/build-scripts/bundle.cjs b/build-scripts/bundle.cjs index 622527f194a0..c05ccdf9a9da 100644 --- a/build-scripts/bundle.cjs +++ b/build-scripts/bundle.cjs @@ -137,8 +137,13 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({ "@babel/plugin-transform-runtime", { version: require("../package.json").dependencies["@babel/runtime"] }, ], - // Support some proposals still in TC39 process - ["@babel/plugin-proposal-decorators", { decoratorsBeforeExport: true }], + // Transpile decorators (still in TC39 process) + // Modern browsers support class fields, but transform is required with the older decorator version dictated by Lit + [ + "@babel/plugin-proposal-decorators", + { version: "2018-09", decoratorsBeforeExport: true }, + ], + "@babel/plugin-proposal-class-properties", ].filter(Boolean), exclude: [ // \\ for Windows, / for Mac OS and Linux diff --git a/build-scripts/gulp/entry-html.js b/build-scripts/gulp/entry-html.js index dd6285c3103a..0645dcfaf916 100644 --- a/build-scripts/gulp/entry-html.js +++ b/build-scripts/gulp/entry-html.js @@ -1,5 +1,6 @@ // Tasks to generate entry HTML +import { getUserAgentRegex } from "browserslist-useragent-regexp"; import fs from "fs-extra"; import gulp from "gulp"; import { minify } from "html-minifier-terser"; @@ -17,6 +18,10 @@ const renderTemplate = (templateFile, data = {}) => { ...data, useRollup: env.useRollup(), useWDS: env.useWDS(), + modernRegex: getUserAgentRegex({ + env: "modern", + allowHigherVersions: true, + }).toString(), // Resolve any child/nested templates relative to the parent and pass the same data renderTemplate: (childTemplate) => renderTemplate( diff --git a/cast/src/html/faq.html.template b/cast/src/html/faq.html.template index c67a5b477a95..a3760d11e4a1 100644 --- a/cast/src/html/faq.html.template +++ b/cast/src/html/faq.html.template @@ -36,13 +36,7 @@ <%= renderTemplate("../../../src/html/_js_base.html.template") %> - - <%= renderTemplate("../../../src/html/_script_load_es5.html.template") %> + <%= renderTemplate("../../../src/html/_script_loader.html.template") %>