From 19832ecae27cc944c6eb45f2f0231df00c6da7c1 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 28 Aug 2017 15:06:06 +0200 Subject: [PATCH] fix(deps): pass along result for dependencies --- src/WorkerPool.js | 30 ++++++++++++++++-------------- src/index.js | 6 ++++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/WorkerPool.js b/src/WorkerPool.js index 5788f79..17bb761 100644 --- a/src/WorkerPool.js +++ b/src/WorkerPool.js @@ -103,7 +103,7 @@ class PoolWorker { this.activeJobs -= 1; this.onJobDone(); if (err) { - jobCallback(err instanceof Error ? err : new Error(err)); + jobCallback(err instanceof Error ? err : new Error(err), arg); } else { jobCallback(null, arg); } @@ -114,22 +114,24 @@ class PoolWorker { callback(eachErr); return; } + let bufferPosition = 0; + if (result.result) { + result.result = result.result.map((r) => { + if (r.buffer) { + const buffer = buffers[bufferPosition]; + bufferPosition += 1; + if (r.string) { + return buffer.toString('utf-8'); + } + return buffer; + } + return r.data; + }); + } if (error) { - callback(this.fromErrorObj(error)); + callback(this.fromErrorObj(error), result); return; } - let bufferPosition = 0; - result.result = result.result.map((r) => { - if (r.buffer) { - const buffer = buffers[bufferPosition]; - bufferPosition += 1; - if (r.string) { - return buffer.toString('utf-8'); - } - return buffer; - } - return r.data; - }); callback(null, result); }); break; diff --git a/src/index.js b/src/index.js index 2ec9b6c..4af5015 100644 --- a/src/index.js +++ b/src/index.js @@ -20,12 +20,14 @@ function pitch() { resolve: this.resolve, optionsContext: this.options.context, }, (err, r) => { + if (r) { + r.fileDependencies.forEach(d => this.addDependency(d)); + r.contextDependencies.forEach(d => this.addContextDependency(d)); + } if (err) { callback(err); return; } - r.fileDependencies.forEach(d => this.addDependency(d)); - r.contextDependencies.forEach(d => this.addContextDependency(d)); callback(null, ...r.result); }); }