Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build-scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ module.exports.babelOptions = ({ latestBuild }) => ({
presets: [
!latestBuild && [
require("@babel/preset-env").default,
{ modules: false, useBuiltIns: "entry", corejs: 3 },
{
modules: false,
useBuiltIns: "entry",
corejs: "3.6",
},
],
require("@babel/preset-typescript").default,
].filter(Boolean),
Expand All @@ -66,7 +70,8 @@ module.exports.babelOptions = ({ latestBuild }) => ({
],
// Only support the syntax, Webpack will handle it.
"@babel/plugin-syntax-import-meta",
"@babel/syntax-dynamic-import",
"@babel/plugin-syntax-dynamic-import",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to only load syntax because webpack dealt with the processing. What do we gain from adding this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this just a typo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still the plugin for the syntax

"@babel/plugin-syntax-top-level-await",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
[
Expand Down
21 changes: 20 additions & 1 deletion build-scripts/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const createWebpackConfig = ({
module: {
rules: [
{
test: /\.js$|\.ts$/,
test: /\.m?js$|\.ts$/,
exclude: bundle.babelExclude(),
use: {
loader: "babel-loader",
Expand All @@ -53,6 +53,9 @@ const createWebpackConfig = ({
}),
],
},
experiments: {
topLevelAwait: true,
},
plugins: [
new ManifestPlugin({
// Only include the JS of entrypoints
Expand Down Expand Up @@ -108,6 +111,22 @@ const createWebpackConfig = ({
}
return `${chunk.name}.${chunk.hash.substr(0, 8)}.js`;
},
environment: {
// The environment supports arrow functions ('() => { ... }').
arrowFunction: latestBuild,
// The environment supports BigInt as literal (123n).
bigIntLiteral: false,
// The environment supports const and let for variable declarations.
const: latestBuild,
// The environment supports destructuring ('{ a, b } = obj').
destructuring: latestBuild,
// The environment supports an async import() function to import EcmaScript modules.
dynamicImport: latestBuild,
// The environment supports 'for of' iteration ('for (const x of array) { ... }').
forOf: latestBuild,
// The environment supports ECMAScript Module syntax to import ECMAScript modules (import ... from '...').
module: latestBuild,
},
chunkFilename:
isProdBuild && !isStatsBuild
? "chunk.[chunkhash].js"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
"license": "Apache-2.0",
"dependencies": {
"@formatjs/intl-pluralrules": "^1.5.8",
"@formatjs/intl-getcanonicallocales": "^1.4.6",
"@formatjs/intl-pluralrules": "^3.4.10",
"@fullcalendar/common": "5.1.0",
"@fullcalendar/core": "5.1.0",
"@fullcalendar/daygrid": "5.1.0",
Expand Down Expand Up @@ -138,6 +139,7 @@
"@babel/plugin-proposal-optional-chaining": "^7.11.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-syntax-top-level-await": "^7.10.4",
"@babel/preset-env": "^7.11.5",
"@babel/preset-typescript": "^7.10.4",
"@rollup/plugin-commonjs": "^11.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/common/translations/localize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import IntlMessageFormat from "intl-messageformat";
import { shouldPolyfill } from "@formatjs/intl-pluralrules/should-polyfill";
import { Resources } from "../../types";

export type LocalizeFunc = (key: string, ...args: any[]) => string;
Expand All @@ -12,8 +13,8 @@ export interface FormatsType {
time: FormatType;
}

if (!Intl.PluralRules) {
import("@formatjs/intl-pluralrules/polyfill-locales");
if (shouldPolyfill()) {
await import("@formatjs/intl-pluralrules/polyfill-locales");
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/components/ha-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ class HaSidebar extends LitElement {
width: 64px;
}
:host([expanded]) {
width: 256px;
width: calc(256px + env(safe-area-inset-left));
}
:host([rtl]) {
Expand Down
1 change: 0 additions & 1 deletion src/html/_js_base.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
"content" in document.createElement("template"))) {
document.write("<script src='/static/polyfills/webcomponents-bundle.js'><"+"/script>");
}
var isS101 = /\s+Version\/10\.1(?:\.\d+)?\s+Safari\//.test(navigator.userAgent);
</script>
2 changes: 1 addition & 1 deletion src/html/_preload_roboto.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
el.type = "font/woff2";
el.href = src;
el.crossOrigin = "anonymous";
document.head.append(el);
document.head.appendChild(el);
}
_pf("/static/fonts/roboto/Roboto-Regular.woff2");
_pf("/static/fonts/roboto/Roboto-Medium.woff2");
Expand Down
12 changes: 6 additions & 6 deletions src/html/authorize.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
<%= renderTemplate('_js_base') %>
<%= renderTemplate('_preload_roboto') %>

<script type="module" crossorigin="use-credentials">
import "<%= latestPageJS %>";
<script crossorigin="use-credentials">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this PR any more? #7318

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope that's all in this one

import("<%= latestPageJS %>");
window.latestJS = true;
window.providersPromise = fetch("/auth/providers", {
credentials: "same-origin",
});
</script>

<script nomodule>
<script>
(function() {
// Safari 10.1 supports type=module but ignores nomodule, so we add this check.
if (!isS101) {
if (!window.latestJS) {
<% if (useRollup) { %>
_ls("/static/js/s.min.js").onload = function() {
System.import("<%= es5PageJS %>");
Expand All @@ -66,4 +66,4 @@
})();
</script>
</body>
</html>
</html>
12 changes: 6 additions & 6 deletions src/html/onboarding.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@
<%= renderTemplate('_js_base') %>
<%= renderTemplate('_preload_roboto') %>

<script type="module" crossorigin="use-credentials">
import "<%= latestPageJS %>";
<script crossorigin="use-credentials">
import("<%= latestPageJS %>");
window.latestJS = true;
window.stepsPromise = fetch("/api/onboarding", {
credentials: "same-origin",
});
</script>

<script nomodule>
<script>
(function() {
// Safari 10.1 supports type=module but ignores nomodule, so we add this check.
if (!isS101) {
if (!window.latestJS) {
<% if (useRollup) { %>
_ls("/static/js/s.min.js").onload = function() {
System.import("<%= es5PageJS %>");
Expand All @@ -74,4 +74,4 @@
})();
</script>
</body>
</html>
</html>
28 changes: 28 additions & 0 deletions src/resources/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,31 @@ import "regenerator-runtime/runtime";
import "unfetch/polyfill";
// To use comlink under ES5
import "proxy-polyfill";
// For localize
import "@formatjs/intl-getcanonicallocales/polyfill";

// Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
(function (arr) {
arr.forEach(function (item) {
if (Object.prototype.hasOwnProperty.call(item, "append")) {
return;
}
Object.defineProperty(item, "append", {
configurable: true,
enumerable: true,
writable: true,
value: function append(...argArr) {
const docFrag = document.createDocumentFragment();

argArr.forEach(function (argItem) {
const isNode = argItem instanceof Node;
docFrag.appendChild(
isNode ? argItem : document.createTextNode(String(argItem))
);
});

this.appendChild(docFrag);
},
});
});
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);
2 changes: 1 addition & 1 deletion src/state/themes-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
);
}
const themeColor =
headerColor.trim() ||
headerColor?.trim() ||
(themeMeta.getAttribute("default-content") as string);
themeMeta.setAttribute("content", themeColor);
}
Expand Down
41 changes: 31 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1777,12 +1777,28 @@
lodash "^4.17.13"
to-fast-properties "^2.0.0"

"@formatjs/intl-pluralrules@^1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@formatjs/intl-pluralrules/-/intl-pluralrules-1.5.8.tgz#ad8dd9ec669b8dac0e284d51772a65d92efa4ef9"
integrity sha512-OtL/rgKSSGljpxk2lRUC92ZqmzZjabwXO5zbBh2Bj8OM+z4U3H1Q5iK+ZY4k7a6EAoY7hWCr3F4k7EL8tcnQow==
"@formatjs/ecma402-abstract@^1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-1.2.5.tgz#5a61ac1990ff2df8d1348ab12e186c1ca2a2bd71"
integrity sha512-k0fqS3LBNOHueAoMdgig8Ni6TchsH+zbzWBzX2gTFm50X9mxHwnuXdCk0XLlCIbvgVVlzcO254Men/mHAheMbg==
dependencies:
tslib "^2.0.1"

"@formatjs/intl-getcanonicallocales@^1.4.6":
version "1.4.6"
resolved "https://registry.yarnpkg.com/@formatjs/intl-getcanonicallocales/-/intl-getcanonicallocales-1.4.6.tgz#348a0b8dd87f2b0513a4942a6273c937dd91ead0"
integrity sha512-V54a+Ks02vke2CSmuGJ4GCvrdWfN105GSH7oZRoW5QSiwuac+fmxb5Qpu4002HetuRu0rrRTm+NMUTfZ1VB2xw==
dependencies:
cldr-core "36.0.0"
tslib "^2.0.1"

"@formatjs/intl-pluralrules@^3.4.10":
version "3.4.10"
resolved "https://registry.yarnpkg.com/@formatjs/intl-pluralrules/-/intl-pluralrules-3.4.10.tgz#7ed3b03190971f21d482cb0e46791d90783a74d3"
integrity sha512-KcZZv38bu0pho9+9pMUOsCAi9/Kayh4+V5QZ/I9ps5OFSQlQaFMP5sX/zHBp41SsT6HxTfrPw5CHWpGrS75NQQ==
dependencies:
"@formatjs/intl-utils" "^2.2.5"
"@formatjs/ecma402-abstract" "^1.2.5"
tslib "^2.0.1"

"@formatjs/intl-unified-numberformat@^3.3.5":
version "3.3.5"
Expand All @@ -1796,11 +1812,6 @@
resolved "https://registry.yarnpkg.com/@formatjs/intl-utils/-/intl-utils-2.2.4.tgz#fe62a96799d1f7dbe621fd38a4bd2e5a6a16cb0e"
integrity sha512-83fsJywew0o9wQsW3VuEp33HRiFd0qbQDyFFnwZCwk59eLZ33CtKyJ5ofKMrU2KK6hk1zaIdzisrZeoNfmI3Tw==

"@formatjs/intl-utils@^2.2.5":
version "2.2.5"
resolved "https://registry.yarnpkg.com/@formatjs/intl-utils/-/intl-utils-2.2.5.tgz#eaafd94df3d102ee13e54e80f992a33868a6b1e8"
integrity sha512-p7gcmazKROteL4IECCp03Qrs790fZ8tbemUAjQu0+K0AaAlK49rI1SIFFq3LzDUAqXIshV95JJhRe/yXxkal5g==

"@fullcalendar/common@5.1.0", "@fullcalendar/common@~5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@fullcalendar/common/-/common-5.1.0.tgz#a45e01ebdcf00654f4d45f0457926cf2f5909820"
Expand Down Expand Up @@ -5414,6 +5425,11 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"

cldr-core@36.0.0:
version "36.0.0"
resolved "https://registry.yarnpkg.com/cldr-core/-/cldr-core-36.0.0.tgz#1d2148ed6802411845baeeb21432d7bbfde7d4f7"
integrity sha512-QLnAjt20rZe38c8h8OJ9jPND+O4o5O8Nw0TK/P3KpNn1cmOhMu0rk6Kc3ap96c5OStQ9gAngs9+Be2sum26NOw==

clean-css@^4.2.1:
version "4.2.3"
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.3.tgz#507b5de7d97b48ee53d84adb0160ff6216380f78"
Expand Down Expand Up @@ -13896,6 +13912,11 @@ tslib@^2.0.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.0.tgz#18d13fc2dce04051e20f074cc8387fd8089ce4f3"
integrity sha512-lTqkx847PI7xEDYJntxZH89L2/aXInsyF2luSafe/+0fHOMjlBNXdH6th7f70qxLDhul7KZK0zC8V5ZIyHl0/g==

tslib@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.3.tgz#8e0741ac45fc0c226e58a17bfc3e64b9bc6ca61c"
integrity sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==

tsutils@^3.17.1:
version "3.17.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"
Expand Down