fix emscripten module loading in node
This commit is contained in:
parent
d381226f21
commit
592fd62402
@ -17,22 +17,41 @@
|
|||||||
|
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This module loads the emscripten library, and is written in unchecked
|
||||||
|
* JavaScript since it needs to do environment detection and dynamically select
|
||||||
|
* the right way to load the library.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the taler emscripten lib.
|
* Load the taler emscripten lib.
|
||||||
*
|
*
|
||||||
* If in a WebWorker, importScripts is used. Inside a browser,
|
* If in a WebWorker, importScripts is used. Inside a browser, the module must
|
||||||
* the module must be globally available.
|
* be globally available. Inside node, require is used.
|
||||||
*/
|
*/
|
||||||
export default function getLib() {
|
export function getLib() {
|
||||||
if (window.TalerEmscriptenLib) {
|
if (typeof importScripts !== "undefined") {
|
||||||
return TalerEmscriptenLib;
|
|
||||||
}
|
|
||||||
if (importScripts) {
|
|
||||||
importScripts('/src/emscripten/taler-emscripten-lib.js')
|
importScripts('/src/emscripten/taler-emscripten-lib.js')
|
||||||
if (TalerEmscriptenLib) {
|
if (TalerEmscriptenLib) {
|
||||||
throw Error("can't import TalerEmscriptenLib");
|
throw Error("can't import TalerEmscriptenLib");
|
||||||
}
|
}
|
||||||
return TalerEmscriptenLib
|
return TalerEmscriptenLib
|
||||||
}
|
}
|
||||||
throw Error("Can't find 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;
|
||||||
|
}
|
||||||
|
throw Error("Looks like running in browser, but TalerEmscriptenLib is not defined");
|
||||||
|
}
|
||||||
|
throw Error("Running in unsupported environment");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user