From e3581c82604cc4f35e6279af39c3bb7ecd189e43 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 28 Sep 2020 15:27:38 +0200 Subject: [PATCH] use our fork of es6-promise with flush exposed as the promise polyfill --- package.json | 1 + scripts/post-install.mjs | 9 +++++++++ src/legacy-polyfill.js | 2 +- src/worker-polyfill.js | 5 +++++ yarn.lock | 4 ++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f42783cc..1a92abcb 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "xxhashjs": "^0.2.2" }, "dependencies": { + "es6-promise": "https://github.com/bwindels/es6-promise.git#bwindels/expose-flush", "aes-js": "^3.1.2", "another-json": "^0.2.0", "base64-arraybuffer": "^0.2.0", diff --git a/scripts/post-install.mjs b/scripts/post-install.mjs index 41d233c7..c5bf029d 100644 --- a/scripts/post-install.mjs +++ b/scripts/post-install.mjs @@ -96,6 +96,15 @@ async function populateLib() { path.join(modulesDir, 'aes-js/index.js'), path.join(libDir, "aes-js/index.js") ); + // es6-promise is already written as an es module, + // but it does need to be babelified, and current we don't babelify + // anything in node_modules in the build script, so make a bundle that + // is conveniently not placed in node_modules rather than symlinking. + await fs.mkdir(path.join(libDir, "es6-promise/")); + await commonjsToESM( + path.join(modulesDir, 'es6-promise/lib/es6-promise/promise.js'), + path.join(libDir, "es6-promise/index.js") + ); } populateLib(); diff --git a/src/legacy-polyfill.js b/src/legacy-polyfill.js index 1bd7b793..75276384 100644 --- a/src/legacy-polyfill.js +++ b/src/legacy-polyfill.js @@ -26,8 +26,8 @@ import "mdn-polyfills/Element.prototype.closest"; // it will also include the file supporting *all* the encodings, // weighing a good extra 500kb :-( import "text-encoding"; -import Promise from "../lib/es6-promise/lib/es6-promise/promise.js"; import {checkNeedsSyncPromise} from "./matrix/storage/idb/utils.js"; +import Promise from "../lib/es6-promise/index.js"; const flush = Promise._flush; Promise._flush = function() { diff --git a/src/worker-polyfill.js b/src/worker-polyfill.js index 7d9f9521..ad13df3a 100644 --- a/src/worker-polyfill.js +++ b/src/worker-polyfill.js @@ -48,3 +48,8 @@ import "core-js/modules/es.typed-array.to-locale-string"; import "core-js/modules/es.typed-array.to-string"; import "core-js/modules/es.typed-array.iterator"; import "core-js/modules/es.object.to-string"; + +import Promise from "../lib/es6-promise/index.js"; +// not calling checkNeedsSyncPromise from here as we don't do any idb in the worker, +// mainly because IE doesn't handle multiple concurrent connections well +self.Promise = Promise; diff --git a/yarn.lock b/yarn.lock index f1b9a4be..232f948c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1205,6 +1205,10 @@ entities@^2.0.0: resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.0.tgz#68d6084cab1b079767540d80e56a39b423e4abf4" integrity sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw== +"es6-promise@https://github.com/bwindels/es6-promise.git#bwindels/expose-flush": + version "4.2.8" + resolved "https://github.com/bwindels/es6-promise.git#112f78f5829e627055b0ff56a52fecb63f6003b1" + escalade@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.0.2.tgz#6a580d70edb87880f22b4c91d0d56078df6962c4"