Skip to content

Commit

Permalink
add support for importModule function and mode variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tarik02 committed Jun 5, 2023
1 parent 661143c commit 2abbbc3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/WorkerPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2abbbc3

Please sign in to comment.