From c422c91b66d66eeea711a9c844287122e832eff1 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 31 Oct 2017 13:15:25 -0700 Subject: [PATCH 1/2] 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 --- Dockerfile | 2 +- fix-jsonstream.js | 9 +++++++++ remove-hashbang-loader.js | 6 ------ webpack.config.js | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 fix-jsonstream.js delete mode 100644 remove-hashbang-loader.js 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$/, From 75034ab1b5ac3f63ec10d99abc4b0f83398fe7c8 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Tue, 31 Oct 2017 21:23:03 +0000 Subject: [PATCH 2/2] v6.3.10 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e23d4cb..eba5a82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v6.3.10 - 2017-10-31 + +* Use a custom webpack loader to avoid uncaught exceptions from JSONStream #517 [Pablo Carranza Velez] + ## v6.3.9 - 2017-10-30 * Avoid fetching an image when it might be available or when starting an app because it might not be necessary #507 [Pablo Carranza Velez] diff --git a/package.json b/package.json index c3de2db9..a4955daa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "resin-supervisor", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", - "version": "6.3.9", + "version": "6.3.10", "license": "Apache-2.0", "repository": { "type": "git",