Skip to content

Commit

Permalink
fix(cache): reset corrupted caches (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzgoddard authored Jun 5, 2018
1 parent 3a924aa commit 33cc986
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,15 @@ class HardSourceWebpackPlugin {
contextNormalModuleId,
copyWithDeser,
}),
]).then(() => {
// console.log('cache in', Date.now() - start);
});
])
.catch(error => {
logMessages.serialBadCache(compiler, error);

return rimraf(cacheDirPath);
})
.then(() => {
// console.log('cache in', Date.now() - start);
});
});
}

Expand Down
10 changes: 10 additions & 0 deletions lib/util/log-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ exports.cacheNoParity = (compiler, { parityRoot }) => {
);
};

exports.serialBadCache = (compiler, error) => {
const loggerSerial = new LoggerFactory(compiler).create().from('serial');
loggerSerial.error(
{
id: 'serialzation--bad-cache',
},
['Cache is corrupted.', error.stack || error.message || error].join('\n'),
);
};

const logCore = compiler => new LoggerFactory(compiler).create().from('core');

exports.configHashSetButNotUsed = (compiler, { cacheDirectory }) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/serializer-append-2-base-1dep-bad-cache/fib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(n) {
return n + (n > 0 ? n - 1 : 0);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var fib = require('./fib');

console.log(fib(3));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var HardSourceWebpackPlugin = require('../../..');
var SerializerAppend2Plugin = require('../../../lib/SerializerAppend2Plugin');

module.exports = {
context: __dirname,
entry: './index.js',
output: {
path: __dirname + '/tmp',
filename: 'main.js',
},
plugins: [
new HardSourceWebpackPlugin({
cacheDirectory: 'cache',
environmentHash: {
root: __dirname + '/../../..',
},
}),
new SerializerAppend2Plugin(),
],
};
6 changes: 6 additions & 0 deletions tests/serializers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@ describe('hard source serializers - serializer abilities', function() {
});
});

itCompilesChange('serializer-append-2-base-1dep-bad-cache', {}, {
'tmp/cache/module/log0000': '',
}, function(output) {
expect(output.run2).to.eql(output.run2);
});

});

0 comments on commit 33cc986

Please sign in to comment.