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 ParsePlugin {
|
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("ParsePlugin", (request, resolveContext, callback) => {
|
16
|
const parsed = resolver.parse(request.request);
|
17
|
const obj = Object.assign({}, request, parsed);
|
18
|
if(request.query && !parsed.query) {
|
19
|
obj.query = request.query;
|
20
|
}
|
21
|
if(parsed && resolveContext.log) {
|
22
|
if(parsed.module)
|
23
|
resolveContext.log("Parsed request is a module");
|
24
|
if(parsed.directory)
|
25
|
resolveContext.log("Parsed request is a directory");
|
26
|
}
|
27
|
resolver.doResolve(target, obj, null, resolveContext, callback);
|
28
|
});
|
29
|
}
|
30
|
};
|