Skip to content

Commit bd8b97d

Browse files
authored
Merge pull request #3 from kwonoj/feat-electron-preamble
feat(preamble): support node.js getBinary on Electron renderer
2 parents 90cb5cc + 2622054 commit bd8b97d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Dockerfile

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
FROM ojkwon/arch-nvm-node:4032238-node7.9-npm4
1+
FROM ojkwon/arch-nvm-node:7b0d30e-node8.4-npm5.4.1
22
MAINTAINER OJ Kwon <[email protected]>
33

44
# Build time args
55
ARG BUILD_TARGET=""
66

7+
# Upgrade system
8+
RUN pacman --noconfirm -Syyu
9+
710
# Install dependencies
8-
RUN pacman --noconfirm -Syu \
11+
RUN pacman --noconfirm -S \
912
emscripten \
1013
unzip \
1114
python \
@@ -16,6 +19,12 @@ RUN pacman --noconfirm -Syu \
1619
# Change subsequent execution shell to bash
1720
SHELL ["/bin/bash", "-l", "-c"]
1821

22+
# Patch preamble.js to support Electron's renderer process with node.js environment
23+
# Refer https://github.com/kripken/emscripten/pull/5577 for detail.
24+
# TODO: remove based on upstream PR status
25+
COPY ./preamble.patch $TMPDIR/
26+
RUN patch /usr/lib/emscripten/src/preamble.js $TMPDIR/preamble.patch
27+
1928
# Initialize emcc
2029
RUN emcc
2130

@@ -28,7 +37,7 @@ RUN if [[ "${BUILD_TARGET}" == "protobuf" ]]; then \
2837
echo "installing protobuf 3.1 dependency" && \
2938
mkdir $TMPDIR/proto31 && cd $TMPDIR/proto31 && \
3039
curl "https://git.archlinux.org/svntogit/packages.git/plain/trunk/PKGBUILD?h=packages/protobuf&id=fa8b9da391b26b6ace1941e9871a6416db74d67b" > ./PKGBUILD && \
31-
makepkg && sudo pacman --noconfirm -U *.pkg.tar.xz && \
40+
makepkg --skipchecksums && sudo pacman --noconfirm -U *.pkg.tar.xz && \
3241
cd $TMPDIR && git clone https://github.com/kwonoj/protobuf-emscripten && \
3342
cd $TMPDIR/protobuf-emscripten/3.1.0 && \
3443
sh autogen.sh && emconfigure ./configure && emmake make && \

preamble.patch

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/src/preamble.js b/src/preamble.js
2+
index 70145dc0f..50b8e73c0 100644
3+
--- a/src/preamble.js
4+
+++ b/src/preamble.js
5+
@@ -2231,7 +2231,9 @@ function integrateWasmJS(Module) {
6+
7+
function getBinaryPromise() {
8+
// if we don't have the binary yet, and have the Fetch api, use that
9+
- if (!Module['wasmBinary'] && typeof fetch === 'function') {
10+
+ // if Module overridded its environment to Node in Electron's renderer process, do not use fetch
11+
+ var electronNodeContext = Module["ENVIRONMENT"] === "NODE" && !!window.process && !!window.require;
12+
+ if (!Module['wasmBinary'] && typeof fetch === 'function' && !electronNodeContext) {
13+
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
14+
if (!response['ok']) {
15+
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";

0 commit comments

Comments
 (0)