Skip to content

Commit

Permalink
fix(UnusedFilesWebpackPlugin): include emitted assets in fileDepsMap
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed May 22, 2015
1 parent eafb884 commit 896e8e2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ UnusedFilesWebpackPlugin.prototype._applyAfterEmit = function(compiler, compilat

glob(this.options.pattern, globOptions, onGlobResult);

var fileDepsBy = compilation.fileDependencies.reduce(function (acc, usedFilepath) {
acc[usedFilepath] = usedFilepath;
return acc;
}, {});
var fileDepsMap = this._getFileDepsMap(compilation);

var absolutePathResolver = Path.join.bind(Path, globOptions.cwd);

function onGlobResult (err, files) {
if (err) {
compilation.errors.push(err);
} else {
var unused = files.filter(function (filepath) {
return !(absolutePathResolver(filepath) in fileDepsBy);
return !(absolutePathResolver(filepath) in fileDepsMap);
});
if (unused.length) {
var errmsg = "UnusedFilesWebpackPlugin found some unused files:\n" + unused.join("\n");
Expand All @@ -51,5 +49,18 @@ UnusedFilesWebpackPlugin.prototype._applyAfterEmit = function(compiler, compilat
}
};

UnusedFilesWebpackPlugin.prototype._getFileDepsMap = function (compilation) {
var fileDepsBy = {};
compilation.fileDependencies.forEach(function (usedFilepath) {
fileDepsBy[usedFilepath] = usedFilepath;
});

Object.keys(compilation.assets).forEach(function (assetRelpath) {
var existsAt = this[assetRelpath].existsAt;
fileDepsBy[existsAt] = existsAt;
}, compilation.assets);

return fileDepsBy;
};

module.exports = UnusedFilesWebpackPlugin;

0 comments on commit 896e8e2

Please sign in to comment.