From 36b56132b0b5b757a2e8dea338038df7a79fd913 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 18 Sep 2020 12:04:22 +0200 Subject: [PATCH] add TextEncoder/Decoder polyfill to legacy bundle --- package.json | 3 ++- scripts/post-install.mjs | 3 +++ src/legacy-polyfill.js | 7 +++++++ yarn.lock | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fcab6ed5..956e027b 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "another-json": "^0.2.0", "base64-arraybuffer": "^0.2.0", "bs58": "^4.0.1", - "olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz" + "olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz", + "text-encoding": "^0.7.0" } } diff --git a/scripts/post-install.mjs b/scripts/post-install.mjs index 703ab79f..41d233c7 100644 --- a/scripts/post-install.mjs +++ b/scripts/post-install.mjs @@ -87,6 +87,9 @@ async function populateLib() { path.join(modulesDir, 'base64-arraybuffer/lib/base64-arraybuffer.js'), path.join(libDir, "base64-arraybuffer/index.js") ); + // this probably should no go in here, we can just import "aes-js" from legacy-extras.js + // as that file is never loaded from a browser + // transpile aesjs to esm await fs.mkdir(path.join(libDir, "aes-js/")); await commonjsToESM( diff --git a/src/legacy-polyfill.js b/src/legacy-polyfill.js index a48416c7..80be7a61 100644 --- a/src/legacy-polyfill.js +++ b/src/legacy-polyfill.js @@ -18,6 +18,13 @@ limitations under the License. import "core-js/stable"; import "regenerator-runtime/runtime"; import "mdn-polyfills/Element.prototype.closest"; +// olm.init needs utf-16le, and this polyfill was +// the only one I could find supporting it. +// TODO: because the library sees a commonjs environment, +// it will also include the file supporting *all* the encodings, +// weighing a good extra 500kb :-( +import "text-encoding"; + // TODO: contribute this to mdn-polyfills if (!Element.prototype.remove) { Element.prototype.remove = function remove() { diff --git a/yarn.lock b/yarn.lock index 0d90c4ac..f1b9a4be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1864,6 +1864,11 @@ supports-color@^6.1.0: dependencies: has-flag "^3.0.0" +text-encoding@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.7.0.tgz#f895e836e45990624086601798ea98e8f36ee643" + integrity sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA== + to-fast-properties@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"