Skip to content

fix(preprocessor): support electron with node context #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@
// we are building with MODULARIZE option,
// which pre-generates module object in preprocessor context - simply use it


// Electron's renderer process is special environment that emscripten can't detect correctly if module loader
// would like to use node.js context (overriding context via ENVIRONMENT==='NODE' but doesn't provide endpoint via locateFile override)
// cause emscripten's getBinaryPromise simply checks existence of `fetch` api. In here, do global object patching while init module
// if given config is set to use NODE but process is actually Electron.
var originalFetch = null;
if (Module["ENVIRONMENT"] === "NODE" && !!window && !!window.process && !!window.require && !!window.fetch) {
originalFetch = window.fetch;
window.fetch = null;
}

// expose filesystem api selectively
Module["preRun"] = function () {
//restore fetch context once wasm binary is loaded
if (!!originalFetch) {
window.fetch = originalFetch;
originalFetch = null;
}

Module.FS = {
filesystems: FS.filesystems,
stat: FS.stat,
Expand Down