forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
-sEXPORT_ES6
/*.mjs
on Node.js
As described in emscripten-core#11792, `require()` and `__dirname` doesn't exist in an ES6 module. Emscripten uses this to import built-in core Node.js modules. For example, the `node:fs` module is used for synchronously importing the `*.wasm` binary, when not linking with `-sSINGLE_FILE`. To work around this, ES6 modules on Node.js may import `createRequire()` from `node:module` to construct the `require()` function, allowing modules to be imported in a CommonJS manner. Emscripten targets a variety of environments, which can be categorized as: 1. Multi-environment builds, which is the default when `-sENVIRONMENT=*` is not specified at link time. 2. Single-environment, e.g. only web or Node.js as target. For use case (1), this commit ensures that an `async` function is emitted, allowing Node.js modules to be dynamically imported. This is necessary given that static import declarations cannot be put in conditionals. Inside the module, for Node.js only, it's using the above-mentioned `createRequire()`-construction. For use case (2), when only Node.js is targeted, a static import declaration utilize the same `createRequire()`-construction. For both use cases, `-sUSE_ES6_IMPORT_META=0` is not allowed, when Node.js is among the targets, since it is not possible to mimic `__dirname` when `import.meta` support is not available. This commit does not change anything for use case (2), when only the web is targeted (`-sENVIRONMENT=web`). Resolves: emscripten-core#11792.
- Loading branch information
Showing
9 changed files
with
146 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters