Skip to content

Commit

Permalink
Remove module cache entries that are out of date
Browse files Browse the repository at this point in the history
When an resolved value in the resolve becomes invalid any hard source
pointing to that is also invalid. We require recordsPath to be set and
ID records persist between builds, and so the IDs cached in the hard
source will continue to point at the now invalid resolution. By busting
that entry in the cache, webpack will build a fresh one pointing to the
new resolution.
  • Loading branch information
mzgoddard committed Aug 21, 2016
1 parent a6fe14f commit 8d35ff0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,40 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
fs.stat(file, function(err, stat) {
if(err) {
fileTs[file] = 0;

// Invalidate modules that depend on this userRequest.
var walkDependencyBlock = function(block, callback) {
// console.log(block);
block.dependencies.forEach(callback);
block.variables.forEach(function(variable) {
variable.dependencies.forEach(callback);
});
block.blocks.forEach(function(block) {
walkDependencyBlock(block, callback);
});
};
// Remove the out of date cache modules.
Object.keys(moduleCache).forEach(function(key) {
if (key === 'fileDependencies') {return;}
var module = moduleCache[key];
if (typeof module === 'string') {
module = JSON.parse(module);
moduleCache[key] = module;
}
var dependsOnRequest = false;
walkDependencyBlock(module, function(cacheDependency) {
var resolveId = JSON.stringify(
[module.context, cacheDependency.request]
);
var resolveItem = resolveCache[resolveId];
dependsOnRequest = dependsOnRequest ||
resolveItem && resolveItem.userRequest === file;
});
if (dependsOnRequest) {
moduleCache[key] = null;
}
});

if(err.code === "ENOENT") return callback();
return callback(err);
}
Expand Down

0 comments on commit 8d35ff0

Please sign in to comment.