mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 09:46:19 +00:00
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:
parent
0b86a60618
commit
c422c91b66
@ -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
9
fix-jsonstream.js
Normal 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/, '')
|
||||
}
|
@ -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/, '')
|
||||
}
|
@ -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$/,
|
||||
|
Loading…
x
Reference in New Issue
Block a user