From 4b129d94e419fe6a0c3ea35d9c5baa358e4046de Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 24 Jan 2018 22:40:42 +0000 Subject: [PATCH] Move node install to spawn to allow for big stdout Fixes #1488 --- red/runtime/nodes/registry/installer.js | 77 +++++++++++++------------ 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/red/runtime/nodes/registry/installer.js b/red/runtime/nodes/registry/installer.js index 4a5347bcb..4c180a785 100644 --- a/red/runtime/nodes/registry/installer.js +++ b/red/runtime/nodes/registry/installer.js @@ -70,7 +70,6 @@ function checkExistingModule(module,version) { } return false; } - function installModule(module,version) { //TODO: ensure module is 'safe' return when.promise(function(resolve,reject) { @@ -98,44 +97,50 @@ function installModule(module,version) { } var installDir = settings.userDir || process.env.NODE_RED_HOME || "."; - var child = child_process.execFile(npmCommand,['install','--save','--save-prefix="~"','--production',installName], - { - cwd: installDir - }, - function(err, stdin, stdout) { - if (err) { - var e; - var lookFor404 = new RegExp(" 404 .*"+module+"$","m"); - var lookForVersionNotFound = new RegExp("version not found: "+module+"@"+version,"m"); - if (lookFor404.test(stdout)) { - log.warn(log._("server.install.install-failed-not-found",{name:module})); - e = new Error("Module not found"); - e.code = 404; - reject(e); - } else if (isUpgrade && lookForVersionNotFound.test(stdout)) { - log.warn(log._("server.install.upgrade-failed-not-found",{name:module})); - e = new Error("Module not found"); - e.code = 404; - reject(e); - } else { - log.warn(log._("server.install.install-failed-long",{name:module})); - log.warn("------------------------------------------"); - log.warn(err.toString()); - log.warn("------------------------------------------"); - reject(new Error(log._("server.install.install-failed"))); - } + var child = child_process.spawn(npmCommand,['install','--save','--save-prefix="~"','--production',installName],{ + cwd: installDir, + shell: true + }); + var output = ""; + child.stdout.on('data', (data) => { + output += data; + }); + child.stderr.on('data', (data) => { + output += data; + }); + child.on('close', (code) => { + if (code !== 0) { + var e; + var lookFor404 = new RegExp(" 404 .*"+module,"m"); + var lookForVersionNotFound = new RegExp("version not found: "+module+"@"+version,"m"); + if (lookFor404.test(output)) { + log.warn(log._("server.install.install-failed-not-found",{name:module})); + e = new Error("Module not found"); + e.code = 404; + reject(e); + } else if (isUpgrade && lookForVersionNotFound.test(output)) { + log.warn(log._("server.install.upgrade-failed-not-found",{name:module})); + e = new Error("Module not found"); + e.code = 404; + reject(e); } else { - if (!isUpgrade) { - log.info(log._("server.install.installed",{name:module})); - resolve(require("./index").addModule(module).then(reportAddedModules)); - } else { - log.info(log._("server.install.upgraded",{name:module, version:version})); - events.emit("runtime-event",{id:"restart-required",payload:{type:"warning",text:"notification.warnings.restartRequired"},retain:true}); - resolve(require("./registry").setModulePendingUpdated(module,version)); - } + log.warn(log._("server.install.install-failed-long",{name:module})); + log.warn("------------------------------------------"); + log.warn(output); + log.warn("------------------------------------------"); + reject(new Error(log._("server.install.install-failed"))); + } + } else { + if (!isUpgrade) { + log.info(log._("server.install.installed",{name:module})); + resolve(require("./index").addModule(module).then(reportAddedModules)); + } else { + log.info(log._("server.install.upgraded",{name:module, version:version})); + events.emit("runtime-event",{id:"restart-required",payload:{type:"warning",text:"notification.warnings.restartRequired"},retain:true}); + resolve(require("./registry").setModulePendingUpdated(module,version)); } } - ); + }); }); }