1
|
/*
|
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
Author Tobias Koppers @sokra
|
4
|
*/
|
5
|
"use strict";
|
6
|
|
7
|
module.exports = class ModuleKindPlugin {
|
8
|
constructor(source, target) {
|
9
|
this.source = source;
|
10
|
this.target = target;
|
11
|
}
|
12
|
|
13
|
apply(resolver) {
|
14
|
const target = resolver.ensureHook(this.target);
|
15
|
resolver.getHook(this.source).tapAsync("ModuleKindPlugin", (request, resolveContext, callback) => {
|
16
|
if(!request.module) return callback();
|
17
|
const obj = Object.assign({}, request);
|
18
|
delete obj.module;
|
19
|
resolver.doResolve(target, obj, "resolve as module", resolveContext, (err, result) => {
|
20
|
if(err) return callback(err);
|
21
|
|
22
|
// Don't allow other alternatives
|
23
|
if(result === undefined) return callback(null, null);
|
24
|
callback(null, result);
|
25
|
});
|
26
|
});
|
27
|
}
|
28
|
};
|