1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Move node install to spawn to allow for big stdout

Fixes #1488
This commit is contained in:
Nick O'Leary 2018-01-24 22:40:42 +00:00
parent e7960d1d44
commit 4b129d94e4
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -70,7 +70,6 @@ function checkExistingModule(module,version) {
} }
return false; return false;
} }
function installModule(module,version) { function installModule(module,version) {
//TODO: ensure module is 'safe' //TODO: ensure module is 'safe'
return when.promise(function(resolve,reject) { return when.promise(function(resolve,reject) {
@ -98,21 +97,28 @@ function installModule(module,version) {
} }
var installDir = settings.userDir || process.env.NODE_RED_HOME || "."; var installDir = settings.userDir || process.env.NODE_RED_HOME || ".";
var child = child_process.execFile(npmCommand,['install','--save','--save-prefix="~"','--production',installName], var child = child_process.spawn(npmCommand,['install','--save','--save-prefix="~"','--production',installName],{
{ cwd: installDir,
cwd: installDir shell: true
}, });
function(err, stdin, stdout) { var output = "";
if (err) { child.stdout.on('data', (data) => {
output += data;
});
child.stderr.on('data', (data) => {
output += data;
});
child.on('close', (code) => {
if (code !== 0) {
var e; var e;
var lookFor404 = new RegExp(" 404 .*"+module+"$","m"); var lookFor404 = new RegExp(" 404 .*"+module,"m");
var lookForVersionNotFound = new RegExp("version not found: "+module+"@"+version,"m"); var lookForVersionNotFound = new RegExp("version not found: "+module+"@"+version,"m");
if (lookFor404.test(stdout)) { if (lookFor404.test(output)) {
log.warn(log._("server.install.install-failed-not-found",{name:module})); log.warn(log._("server.install.install-failed-not-found",{name:module}));
e = new Error("Module not found"); e = new Error("Module not found");
e.code = 404; e.code = 404;
reject(e); reject(e);
} else if (isUpgrade && lookForVersionNotFound.test(stdout)) { } else if (isUpgrade && lookForVersionNotFound.test(output)) {
log.warn(log._("server.install.upgrade-failed-not-found",{name:module})); log.warn(log._("server.install.upgrade-failed-not-found",{name:module}));
e = new Error("Module not found"); e = new Error("Module not found");
e.code = 404; e.code = 404;
@ -120,7 +126,7 @@ function installModule(module,version) {
} else { } else {
log.warn(log._("server.install.install-failed-long",{name:module})); log.warn(log._("server.install.install-failed-long",{name:module}));
log.warn("------------------------------------------"); log.warn("------------------------------------------");
log.warn(err.toString()); log.warn(output);
log.warn("------------------------------------------"); log.warn("------------------------------------------");
reject(new Error(log._("server.install.install-failed"))); reject(new Error(log._("server.install.install-failed")));
} }
@ -134,8 +140,7 @@ function installModule(module,version) {
resolve(require("./registry").setModulePendingUpdated(module,version)); resolve(require("./registry").setModulePendingUpdated(module,version));
} }
} }
} });
);
}); });
} }