1 |
3a515b92
|
cagy
|
/*
|
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 FileExistsPlugin {
|
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 |
|
|
const fs = resolver.fileSystem;
|
16 |
|
|
resolver.getHook(this.source).tapAsync("FileExistsPlugin", (request, resolveContext, callback) => {
|
17 |
|
|
const file = request.path;
|
18 |
|
|
fs.stat(file, (err, stat) => {
|
19 |
|
|
if(err || !stat) {
|
20 |
|
|
if(resolveContext.missing) resolveContext.missing.add(file);
|
21 |
|
|
if(resolveContext.log) resolveContext.log(file + " doesn't exist");
|
22 |
|
|
return callback();
|
23 |
|
|
}
|
24 |
|
|
if(!stat.isFile()) {
|
25 |
|
|
if(resolveContext.missing) resolveContext.missing.add(file);
|
26 |
|
|
if(resolveContext.log) resolveContext.log(file + " is not a file");
|
27 |
|
|
return callback();
|
28 |
|
|
}
|
29 |
|
|
resolver.doResolve(target, request, "existing file: " + file, resolveContext, callback);
|
30 |
|
|
});
|
31 |
|
|
});
|
32 |
|
|
}
|
33 |
|
|
};
|