-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.11 (d3432e7)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 0f0079c29da4b4d5bbd43dced1db9ad6c6d11008)
Target: wasm32-unknown-emscripten
Thread model: posix
Since I've updated from Emscripten version 3.1.68 to 4.011, I can't use a small workaround I found to execute my application inside Electron and run all my system tests, just like any native application, by comparing generated screenshots and other metrics. This was the workaround added to any --pre-js JavaScript file:
// Workaround for https://github.com/emscripten-core/emscripten/pull/22619
ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';// && process.type != 'renderer';
Since pull request 22619, using Electron and NodeFS together has become more complicated. In the latest version of Emscripten (4.0.11) the workaround requires modifying the internal file emsdk/upstream/emscripten/src/parseTools.mjs with this change:
function nodeDetectionCode() {
//return "typeof process == 'object' && process.versions?.node && process.type != 'renderer'";
return "typeof process == 'object' && process.versions?.node"; // NEBULA-CHANGE: to be able to exeute in Electron
}
Why is it needed to check the process.type != 'renderer'?
I've found that my previous workaround is not working because the global variable ENVIRONMENT_IS_NODE is rechecked like this:
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
#if ENVIRONMENT.length && ASSERTIONS
const isNode = {{{ nodeDetectionCode() }}};
if (!isNode) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
#endif
Is that necessary? ENVIRONMENT_IS_NODE is already assigned to the same expression nodeDetectionCode(), so this is redundant, right?
I'm probably missing something, but this gives me headaches every time I want to update Emscripten.
Does anyone know how to use NodeFS and Electron properly without any workarounds?