diff options
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; |