Use a custom webpack loader to avoid uncaught exceptions from JSONStream

JSONStream is a hybrid executable-library that doesn't get along well with webpack: it tries to run its binary code
which can throw uncaught exceptions. So we use a custom loader for it - which replaces remove-hashbang-loader, as it only
affected JSONStream too.

(I tried replacing JSONStream altogether, but turns out dockerode uses it too)

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2017-10-31 13:15:25 -07:00
parent 0b86a60618
commit c422c91b66
4 changed files with 12 additions and 9 deletions

View File

@ -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

9
fix-jsonstream.js Normal file
View File

@ -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/, '')
}

View File

@ -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/, '')
}

View File

@ -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$/,