mirror of
https://github.com/home-assistant/frontend.git
synced 2026-09-28 07:58:45 +01:00
* Remove web components polyfills and ES5 custom elements adapter All supported browsers (legacy floor: Chrome 59, Safari/iOS 12, Firefox 94) have native shadow DOM and custom elements, so the webcomponents bundle, ShadyCSS branch, and lit polyfill-support are unreachable. The legacy build now emits ES2017 classes, so custom-elements-es5-adapter and the window.loadES5Adapter hook (no known third-party consumers) are removed. Also stops shipping the never-loaded dialog-polyfill css and drops both now-unused dependencies. * Remove keyed-es5 Terser workaround The custom keyed directive existed because Terser with ecma: 5 miscompiled the destructured update() parameters (#28732). The legacy build now minifies with ecma: 2017, so the stock lit-html keyed directive works in both builds. * Remove old-browser JS shims and stale ES5 build references Drops the IE-only navigator.msMaxTouchPoints check, replaces the toggleAttribute helper with the native method (polyfilled automatically for Chrome < 69 in the legacy build), and removes babel excludes for the uninstalled proxy-polyfill and unfetch packages. Updates comments that still described the legacy build as ES5. * Remove vendor prefixes for no-longer-supported browsers Deletes -ms- prefixes (IE/EdgeHTML only) and -webkit-/-moz- prefixed declarations that every supported browser understands unprefixed, or that Lightning CSS re-adds automatically from the unprefixed property in production builds. Blocks that only had prefixed user-select now use the standard property (previously Firefox got no user-select there at all). Converts the four -webkit-linear-gradient() declarations - the sole gradient syntax on those sliders - to standard linear-gradient(). * Remove dead html_url custom panel support html_url pointed to an HTML Import, a Polymer-era feature removed from Chrome in 2019 and never shipped elsewhere. The loader has not handled the html type for years (it fell through to a rejection), and core's panel_custom integration no longer accepts the option, so the branch was unreachable. Also drops the ha-panel-${name} legacy tag naming that was keyed on html_url. * Repair list-plugins-and-polyfills script for Babel 8 The audit script died at startup since the Babel 8 update: preset-env no longer exposes lib/debug.js (logPlugin is now inlined locally, built on the public getInclusionReasons helper) and babel-plugin-polyfill-corejs3 v1 no longer ships lib/shipped-proposals.js (list inlined). Instead of invoking the preset with a hand-mocked plugin API - the part that kept drifting - the plugin listing now runs a real transform of an empty file with preset-env in debug mode, declaring the same caller capabilities as babel-loader. The polyfill listing now passes the configured core-js version to core-js-compat, mirroring the provider's own filtering so the report cannot list modules the installed core-js lacks. Output is byte-identical to the direct-invocation approach. Also documents the script in the build-scripts README. * Correct macOS floor for Safari 26 in companion app UA regex Safari 26 ships for macOS 14 Sonoma and 15 Sequoia, not only macOS 26, so the SAFARI_TO_MACOS entry breaking the minimum-supported-macOS pattern would have sent updated macOS 14/15 companion apps to the legacy build once the modern floor reaches Safari 26. * Remove orphaned values left behind by vendor prefix removal * Require macOS 14.6 for Safari 26 in companion app UA regex
125 lines
4.3 KiB
JavaScript
Executable File
125 lines
4.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// Script to print Babel plugins and Core JS polyfills that will be used by browserslist environments
|
|
|
|
import { transformSync } from "@babel/core";
|
|
import compilationTargets, {
|
|
getInclusionReasons,
|
|
} from "@babel/helper-compilation-targets";
|
|
import coreJSCompat from "core-js-compat";
|
|
import { babelOptions } from "./bundle.cjs";
|
|
|
|
const detailsOpen = (heading) =>
|
|
`<details>\n<summary><h4>${heading}</h4></summary>\n`;
|
|
const detailsClose = "</details>\n";
|
|
|
|
// Copied from @babel/preset-env's internal `logPlugin`, which Babel 8 no
|
|
// longer exposes (the package rolls up into lib/index.js and exports nothing
|
|
// but the preset). Prints an item with the targets that require it.
|
|
const logPlugin = (item, targetVersions, list) => {
|
|
const filteredList = getInclusionReasons(item, targetVersions, list);
|
|
const support = list[item];
|
|
if (!support) {
|
|
console.log(` ${item}`);
|
|
return;
|
|
}
|
|
let formattedTargets = `{`;
|
|
let first = true;
|
|
for (const target of Object.keys(filteredList)) {
|
|
if (!first) formattedTargets += `,`;
|
|
first = false;
|
|
formattedTargets += ` ${target}`;
|
|
if (support[target]) formattedTargets += ` < ${support[target]}`;
|
|
}
|
|
formattedTargets += ` }`;
|
|
console.log(` ${item} ${formattedTargets}`);
|
|
};
|
|
|
|
// Copied from babel-plugin-polyfill-corejs3's generated
|
|
// corejs3ShippedProposalsList, which v1 no longer exposes (it is inlined in
|
|
// the package's rolled-up bundle).
|
|
const shippedProposalsList = new Set([
|
|
"esnext.array.group",
|
|
"esnext.array.group-to-map",
|
|
"esnext.iterator.zip",
|
|
"esnext.iterator.zip-keyed",
|
|
"esnext.symbol.metadata",
|
|
]);
|
|
|
|
// Generate filter function based on proposal/method inputs
|
|
// Copied and adapted from babel-plugin-polyfill-corejs3/esm/index.mjs
|
|
const polyfillFilter = (method, proposals, shippedProposals) => (name) => {
|
|
if (proposals || method === "entry-global") return true;
|
|
if (shippedProposals && shippedProposalsList.has(name)) {
|
|
return true;
|
|
}
|
|
if (name.startsWith("esnext.")) {
|
|
const esName = `es.${name.slice(7)}`;
|
|
// If its imaginative esName is not in latest compat data, it means the proposal is not stage 4
|
|
return esName in coreJSCompat.data;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
// Log the plugins and polyfills for each build environment
|
|
for (const buildType of ["Modern", "Legacy"]) {
|
|
const browserslistEnv = buildType.toLowerCase();
|
|
const babelOpts = babelOptions({ latestBuild: browserslistEnv === "modern" });
|
|
const presetEnvOpts = babelOpts.presets.find(
|
|
(preset) => Array.isArray(preset) && preset[0] === "@babel/preset-env"
|
|
)?.[1];
|
|
// Core-JS polyfills are injected by babel-plugin-polyfill-corejs3 (Babel 8
|
|
// removed preset-env's `useBuiltIns`), so read its options here.
|
|
const corejsOpts = babelOpts.plugins.find(
|
|
(plugin) =>
|
|
Array.isArray(plugin) && plugin[0] === "babel-plugin-polyfill-corejs3"
|
|
)?.[1];
|
|
|
|
// Transforming an empty file with preset-env in debug mode logs the included
|
|
// plugins. The caller declares the same capabilities babel-loader does, so
|
|
// plugins gated on bundler support (e.g. transform-export-namespace-from)
|
|
// match the build.
|
|
presetEnvOpts.debug = true;
|
|
console.log(detailsOpen(`${buildType} Build Babel Plugins`));
|
|
transformSync("", {
|
|
...babelOpts,
|
|
configFile: false,
|
|
filename: "audit.js",
|
|
caller: {
|
|
name: "list-plugins-and-polyfills",
|
|
supportsStaticESM: true,
|
|
supportsDynamicImport: true,
|
|
supportsTopLevelAwait: true,
|
|
supportsExportNamespaceFrom: true,
|
|
},
|
|
});
|
|
console.log(detailsClose);
|
|
|
|
// Manually log the Core-JS polyfills using the same technique
|
|
if (corejsOpts) {
|
|
console.log(detailsOpen(`${buildType} Build Core-JS Polyfills`));
|
|
const targets = compilationTargets(babelOpts.targets, {
|
|
browserslistEnv,
|
|
});
|
|
// `version` limits the list to modules the installed core-js ships,
|
|
// mirroring the provider's own filtering.
|
|
const polyfillList = coreJSCompat({
|
|
targets,
|
|
version: corejsOpts.version,
|
|
}).list.filter(
|
|
polyfillFilter(
|
|
corejsOpts.method,
|
|
corejsOpts.proposals,
|
|
corejsOpts.shippedProposals
|
|
)
|
|
);
|
|
console.log(
|
|
"The following %i polyfills may be injected by Babel:\n",
|
|
polyfillList.length
|
|
);
|
|
for (const polyfill of polyfillList) {
|
|
logPlugin(polyfill, targets, coreJSCompat.data);
|
|
}
|
|
console.log(detailsClose);
|
|
}
|
|
}
|