From 84187a6dc84f91d89d2fc9c878d9e85fdeb14fb7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 15 Oct 2019 12:15:46 +0200 Subject: [PATCH] lib: show stderr when getting project from npm fails (#753) --- lib/grab-project.js | 16 +++++++++++----- test/test-grab-project.js | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/grab-project.js b/lib/grab-project.js index 638add881..25f46451c 100644 --- a/lib/grab-project.js +++ b/lib/grab-project.js @@ -32,11 +32,9 @@ async function grabProject(context) { `Downloading project: ${packageName}` ); let options = createOptions(context.path, context); - options.stdio = ['ignore', 'pipe', 'ignore']; + options.stdio = ['ignore', 'pipe', 'pipe']; const proc = spawn('npm', ['pack', packageName], options); - let filename = ''; - // Default timeout to 10 minutes if not provided const timeout = setTimeout( cleanup, @@ -56,10 +54,18 @@ async function grabProject(context) { reject(new Error('Download Timed Out')); } + let filename = ''; + proc.stdout.setEncoding('utf8'); proc.stdout.on('data', (chunk) => { filename += chunk; }); + let stderr = ''; + proc.stderr.setEncoding('utf8'); + proc.stderr.on('data', (chunk) => { + stderr += chunk; + }); + proc.on('error', (err) => { bailed = true; clearTimeout(timeout); @@ -70,7 +76,7 @@ async function grabProject(context) { if (bailed) return; clearTimeout(timeout); if (code > 0) { - return reject(new Error('Failure getting project from npm')); + return reject(new Error(`Failure getting project from npm\n${stderr}`)); } filename = filename.trim(); if (context.module.type === 'directory') { @@ -78,7 +84,7 @@ async function grabProject(context) { filename = filename.pop(); } if (filename === '') { - return reject(new Error('No project downloaded')); + return reject(new Error(`No project downloaded\n${stderr}`)); } context.emit( 'data', diff --git a/test/test-grab-project.js b/test/test-grab-project.js index a36d4142e..449b17c51 100644 --- a/test/test-grab-project.js +++ b/test/test-grab-project.js @@ -89,7 +89,7 @@ test('grab-project: local', async (t) => { }); test('grab-project: module does not exist', async (t) => { - t.plan(1); + t.plan(2); const context = { emit: function() {}, path: sandbox, @@ -101,7 +101,8 @@ test('grab-project: module does not exist', async (t) => { try { await grabProject(context); } catch (err) { - t.equals(err && err.message, 'Failure getting project from npm'); + t.ok(err); + t.match(err.message, /^Failure getting project from npm/); } });