enabled asmjs as additional build target, and added code to monero_utils/MyMoneroCoreBridge.js with preliminary wasm support detection and fallback to loading separated asm.js file (and different MyMoneroCoreCpp for ASMJS) to remove need for wasm users to load asmjs and asmjs loading code; the asm.js file is separated out from MyMoneroCoreCpp_ASMJS.js with --separate-asm to improve initial load time and, more importantly here, to enable bin/package_browser_js and other webpack like builds to keep the majority of the asmjs separate from the main mymonero_core.js (or e.g. mymonero_app_browser.js) bundle, so that wasm users don't have to load the asmjs along with the main app bundle - however, the overhead of bundling MyMoneroCoreCpp_ASMJS.js into such a main bundle does still exist. in near future, it would be nice to add an option to webpack.config.browser.common.js or bin/package_browser_js or possible just inheriting/alternate versions of those which can opt to remove asmjs support and throw an exception or alert if it's simply not supported - this is probably what MyMonero will move to within a year or two as legacy browsers fade from usage
@ -32,7 +32,7 @@ There is also a chain of build scripts which is capable of building a JS module
`monero_utils` contains Monero- and MyMonero-specific implementations, wrappers, and declarations, and the MyMonero JS and wasm implementations for the underlying cryptography behind Monero.
`monero_utils/MyMoneroCoreCpp.(js,wasm)` are produced by transpiling Monero core C++ code to JS via Emscripten (See *Building MyMoneroCoreCpp*). A Module instance is managed by `monero_utils/MyMoneroCoreBridge.js`.
`monero_utils/MyMoneroCoreCpp*` are produced by transpiling Monero core C++ code to JS via Emscripten (See *Building MyMoneroCoreCpp*). A Module instance is managed by `monero_utils/MyMoneroCoreBridge.js`.
A ready-made entrypoint for interacting with `MyMoneroCoreBridge` is located at `monero_utils/monero_utils.js` with usage `require("./monero_utils/monero_utils").then(function(monero_utils) { })`.
constENVIRONMENT_IS_NODE=typeofprocess==="object"&&process.browser!==true&&typeofrequire==="function"&&ENVIRONMENT_IS_WORKER==false;// we want this to be true for Electron but not for a WebView
if(lastPathComponent=="monero_utils"){// typical node or electron-main process
fullPath=path.format({
dir:this_scriptDirectory,
base:filename
})
}else{
console.warn("MyMoneroCoreBridge/locateFile() on node.js didn't find \"monero_utils\" (or possibly MyMoneroCoreBridge.js) itself in the expected location in the following path. The function may need to be expanded but it might in normal situations be likely to be another bug.",pathTo_cryptonoteUtilsDir)
}
}elseif(ENVIRONMENT_IS_WEB){
varpathTo_cryptonoteUtilsDir;
if(typeof__dirname!==undefined&&__dirname!=="/"){// looks like node running in browser.. (but not going to assume it's electron-renderer since that should be taken care of by monero_utils.js itself)
// but just in case it is... here's an attempt to support it
// have to check != "/" b/c webpack (I think) replaces __dirname
pathTo_cryptonoteUtilsDir="file://"+__dirname+"/"// prepending "file://" because it's going to try to stream it
}else{// actual web browser
pathTo_cryptonoteUtilsDir=this_scriptDirectory+"/mymonero_core_js/monero_utils/"// this works for the MyMonero browser build, and is quite general, at least
}
fullPath=pathTo_cryptonoteUtilsDir+filename
}
if(fullPath==null){
throw"Unable to derive fullPath. Please pass locateFile() to cryptonote_utils init."
constENVIRONMENT_IS_NODE=typeofprocess==="object"&&process.browser!==true&&typeofrequire==="function"&&ENVIRONMENT_IS_WORKER==false;// we want this to be true for Electron but not for a WebView
if(lastPathComponent=="monero_utils"){// typical node or electron-main process
fullPath=path.format({
dir:this_scriptDirectory,
base:filename
})
}else{
console.warn("MyMoneroCoreBridge/locateFile() on node.js didn't find \"monero_utils\" (or possibly MyMoneroCoreBridge.js) itself in the expected location in the following path. The function may need to be expanded but it might in normal situations be likely to be another bug.",pathTo_cryptonoteUtilsDir)
}
}elseif(ENVIRONMENT_IS_WEB){
varpathTo_cryptonoteUtilsDir;
if(typeof__dirname!==undefined&&__dirname!=="/"){// looks like node running in browser.. (but not going to assume it's electron-renderer since that should be taken care of by monero_utils.js itself)
// but just in case it is... here's an attempt to support it
// have to check != "/" b/c webpack (I think) replaces __dirname
pathTo_cryptonoteUtilsDir="file://"+__dirname+"/"// prepending "file://" because it's going to try to stream it
}else{// actual web browser
pathTo_cryptonoteUtilsDir=this_scriptDirectory+"/mymonero_core_js/monero_utils/"// this works for the MyMonero browser build, and is quite general, at least
}
fullPath=pathTo_cryptonoteUtilsDir+filename
}
if(fullPath==null){
throw"Unable to derive fullPath. Please pass locateFile() to cryptonote_utils init."
}
//
returnfullPath
}
Module_template["locateFile"]=locateFile
//
// NOTE: This requires src/module-post.js to be included as post-js in CMakeLists.txt under a wasm build
require('../monero_utils/MyMoneroCoreBridge')({asmjs:false}).then(function(instance)// this can be switched to manually test asmjs vs wasm - can be exposed to option