Skip to content

Commit

Permalink
fix: Handle JS global in non-node environments (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jan 24, 2022
1 parent 02b358b commit 74e94fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/dune
Expand Up @@ -10,4 +10,4 @@
(names stubs))
(js_of_ocaml
(flags --no-sourcemap)
(javascript_files binaryen.es5.js postlude.js)))
(javascript_files prelude.js binaryen.es5.js postlude.js)))
4 changes: 2 additions & 2 deletions js/postlude.js
@@ -1,2 +1,2 @@
// Attach binaryen to our global
global.binaryen = module.exports;
// Attach binaryen to globalThis because JSOO wraps in an iife
globalThis.binaryen = module.exports;
11 changes: 11 additions & 0 deletions js/prelude.js
@@ -0,0 +1,11 @@
if (typeof module === 'undefined') {
module = {};
}

if (typeof exports === 'undefined') {
exports = {};
}

if (typeof module.exports === 'undefined') {
module.exports = exports;
}

0 comments on commit 74e94fe

Please sign in to comment.