From aa67a3429de76b41057d4e462a50f3f360e1fc61 Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Fri, 11 Dec 2020 12:53:49 +0200 Subject: [PATCH] Reject npm install on failure using the process exit code. Signed-off-by: Panu Horsmalahti --- src/extensions/extension-installer.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/extensions/extension-installer.ts b/src/extensions/extension-installer.ts index 59f416d4e3..75b30d0b9a 100644 --- a/src/extensions/extension-installer.ts +++ b/src/extensions/extension-installer.ts @@ -33,14 +33,24 @@ export class ExtensionInstaller { installDependencies(): Promise { return new Promise((resolve, reject) => { logger.info(`${logModule} installing dependencies at ${extensionPackagesRoot()}`); - const child = child_process.fork(this.npmPath, ["install", "--silent", "--no-audit", "--only=prod", "--prefer-offline", "--no-package-lock"], { + const child = child_process.fork(this.npmPath, ["install", "--no-audit", "--only=prod", "--prefer-offline", "--no-package-lock"], { cwd: extensionPackagesRoot(), silent: true }); + let stderr = ""; - child.on("close", () => { - resolve(); + child.stderr.on("data", data => { + stderr += String(data); }); + + child.on("close", (code) => { + if (code !== 0) { + reject(new Error(stderr)); + } else { + resolve(); + } + }); + child.on("error", error => { reject(error); });