diff --git a/src/WorkerPool.js b/src/WorkerPool.js index ba4bd72..44b202d 100644 --- a/src/WorkerPool.js +++ b/src/WorkerPool.js @@ -231,6 +231,33 @@ class PoolWorker { ], }); }); + + finalCallback(); + break; + } + case 'importModule': + { + const { + request, + options, + questionId + } = message; + const { + data + } = this.jobs[id]; + data.importModule(request, options) + .then(result => this.writeJson({ + type: 'result', + id: questionId, + error: null, + result + })) + .catch(error => this.writeJson({ + type: 'result', + id: questionId, + error + })); + finalCallback(); break; } diff --git a/src/index.js b/src/index.js index a5de5be..66e4ffa 100644 --- a/src/index.js +++ b/src/index.js @@ -37,12 +37,14 @@ function pitch() { this._compilation.options.devtool, }, }, + mode: this.mode, resourcePath: this.resourcePath, resource: this.resourcePath + (this.resourceQuery || ''), sourceMap: this.sourceMap, emitError: this.emitError, emitWarning: this.emitWarning, loadModule: this.loadModule, + importModule: this.importModule, resolve: this.resolve, getResolve: this.getResolve, target: this.target, diff --git a/src/worker.js b/src/worker.js index 7fe3d95..1010edf 100644 --- a/src/worker.js +++ b/src/worker.js @@ -141,6 +141,26 @@ const queue = asyncQueue(({ id, data }, taskCallback) => { }); nextQuestionId += 1; }, + importModule: (request, options) => { + const promise = new Promise((resolve, reject) => { + callbackMap[nextQuestionId] = (error, result) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }; + }); + writeJson({ + type: 'importModule', + id, + questionId: nextQuestionId, + request, + options + }); + nextQuestionId += 1; + return promise; + }, resolve: (context, request, callback) => { resolveWithOptions(context, request, callback); }, @@ -244,6 +264,7 @@ const queue = asyncQueue(({ id, data }, taskCallback) => { sourceMap: data.sourceMap, target: data.target, minimize: data.minimize, + mode: data.mode, resourceQuery: data.resourceQuery, rootContext: data.rootContext, // eslint-disable-next-line no-underscore-dangle