diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-27 22:55:52 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-27 22:55:52 +0200 |
commit | 478a089e521de81ca47fc54518bc6a241823d9ae (patch) | |
tree | 434360d5090263688950ae180184c96f590ab9ff /src/crypto/emscLoader.js | |
parent | 9a1b2c8ccc5f079dae4966dfd011f4076a53dc20 (diff) | |
download | wallet-core-478a089e521de81ca47fc54518bc6a241823d9ae.tar.xz |
fix module loading for node under fake web workers
Diffstat (limited to 'src/crypto/emscLoader.js')
-rw-r--r-- | src/crypto/emscLoader.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/crypto/emscLoader.js b/src/crypto/emscLoader.js index eebe20c02..190f007f1 100644 --- a/src/crypto/emscLoader.js +++ b/src/crypto/emscLoader.js @@ -31,6 +31,22 @@ * be globally available. Inside node, require is used. */ export function getLib() { + if (typeof require !== "undefined") { + // Make sure that TypeScript doesn't try + // to check the taler-emscripten-lib. + const indirectRequire = require; + const g = global as any; + // unavoidable hack, so that emscripten detects + // the environment as node even though importScripts + // is present. + const savedImportScripts = g.importScripts; + delete g.importScripts; + // Assume that the code is run from the build/ directory. + const lib = indirectRequire("../../../emscripten/taler-emscripten-lib.js"); + g.importScripts = savedImportScripts; + return lib; + } + if (typeof importScripts !== "undefined") { importScripts('/src/emscripten/taler-emscripten-lib.js') if (TalerEmscriptenLib) { @@ -39,14 +55,6 @@ export function getLib() { return TalerEmscriptenLib } - if (typeof require !== "undefined") { - // Make sure that TypeScript doesn't try - // to check the taler-emscripten-lib. - const fn = require; - // Assume that the code is run from the build/ directory. - return fn("../../../emscripten/taler-emscripten-lib.js"); - } - if (typeof window !== "undefined") { if (window.TalerEmscriptenLib) { return TalerEmscriptenLib; |