Skip to content

Commit

Permalink
Fix asset thawing relating to pre-emptive compiler
Browse files Browse the repository at this point in the history
Dependency and module invalidation means the plugin needs to parse
un-parsed modules from the file cache. Trying to keep work delayed
until needed, but mostly just lots of reworking, left the assets for a
module from being correctly stood up. This wasn't an obvious bug
because dependency invalidation was invalidating modules with loaders
like file-loader, causing rebuilds. This change fixes the asset setup
and the overzealous dependency invalidation for non-request
dependencies.
  • Loading branch information
mzgoddard committed Sep 6, 2016
1 parent 7af3d6a commit 1da9546
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,22 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
// Remove the out of date cache modules.
Object.keys(moduleCache).forEach(function(key) {
if (key === 'fileDependencies') {return;}
var module = moduleCache[key];
if (!module) {return;}
if (typeof module === 'string') {
module = JSON.parse(module);
moduleCache[key] = module;
var cacheItem = moduleCache[key];
if (!cacheItem) {return;}
if (typeof cacheItem === 'string') {
cacheItem = JSON.parse(cacheItem);
moduleCache[key] = cacheItem;
}
var validDepends = true;
walkDependencyBlock(module, function(cacheDependency) {
walkDependencyBlock(cacheItem, function(cacheDependency) {
if (
!cacheDependency || typeof cacheDependency.request === 'undefined'
) {
return;
}

var resolveId = JSON.stringify(
[module.context, cacheDependency.request]
[cacheItem.context, cacheDependency.request]
);
var resolveItem = resolveCache[resolveId];
validDepends = validDepends &&
Expand All @@ -304,7 +310,7 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
fileTs[resolveItem.userRequest] !== 0;
});
if (!validDepends) {
module.invalid = true;
cacheItem.invalid = true;
moduleCache[key] = null;
}
});
Expand Down Expand Up @@ -458,12 +464,14 @@ HardSourceWebpackPlugin.prototype.apply = function(compiler) {
var cacheItem = moduleCache[result.request];
if (typeof cacheItem === 'string') {
cacheItem = JSON.parse(cacheItem);
moduleCache[result.request] = cacheItem;
}
if (Array.isArray(cacheItem.assets)) {
cacheItem.assets = (cacheItem.assets || [])
.reduce(function(carry, key) {
carry[key] = assets[requestHash(key)];
return carry;
}, {});
moduleCache[result.request] = cacheItem;
}
if (!HardModule.needRebuild(
cacheItem.buildTimestamp,
Expand Down

0 comments on commit 1da9546

Please sign in to comment.