diff --git a/Dockerfile b/Dockerfile index be877208..2f4bb84a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -143,7 +143,7 @@ COPY package.json /usr/src/app/ RUN JOBS=MAX npm install --production --no-optional --unsafe-perm \ && npm dedupe -COPY webpack.config.js remove-hashbang-loader.js /usr/src/app/ +COPY webpack.config.js fix-jsonstream.js /usr/src/app/ COPY src /usr/src/app/src # Install devDependencies, build the coffeescript and then prune the deps diff --git a/fix-jsonstream.js b/fix-jsonstream.js new file mode 100644 index 00000000..9db46d79 --- /dev/null +++ b/fix-jsonstream.js @@ -0,0 +1,9 @@ +// JSONStream is a hybrid executable-library +// and has a #! /usr/bin/env node at the beginning of the file. +// This webpack loader removes it so that we have valid javascript for webpack to load. +// Also, JSONStream starts a pipe between stdin and stdout if module.parent is undefined. +// This pipe can fail throwing an uncaught exception, so we fake a module.parent to prevent this. +// See https://github.com/dominictarr/JSONStream/issues/129 +module.exports = function (source) { + return "module.parent = {};\n" + source.toString().replace(/^#! .*\n/, '') +} diff --git a/remove-hashbang-loader.js b/remove-hashbang-loader.js deleted file mode 100644 index 53f25bdd..00000000 --- a/remove-hashbang-loader.js +++ /dev/null @@ -1,6 +0,0 @@ -// Some of the dependencies (e.g. JSONStream) are hybrid executable-library -// and have a #! /usr/bin/env node at the beginning of the file. -// This webpack loader removes it so that we have valid javascript for webpack to load. -module.exports = function (source) { - return source.toString().replace(/^#! .*\n/, '') -} diff --git a/webpack.config.js b/webpack.config.js index 24c57b99..d2347d03 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -62,8 +62,8 @@ module.exports = { module: { rules: [ { - test: /\.js$/, - use: require.resolve('./remove-hashbang-loader') + test: /JSONStream\/index\.js$/, + use: require.resolve('./fix-jsonstream') }, { test: /\.coffee$/,