mirror of
https://github.com/status-im/metro.git
synced 2025-02-28 02:30:29 +00:00
[react-packager] Recover and warn from corrupted cache file
This commit is contained in:
parent
37cab152b5
commit
41743e5987
16
react-packager/src/JSTransformer/Cache.js
vendored
16
react-packager/src/JSTransformer/Cache.js
vendored
@ -112,13 +112,23 @@ Cache.prototype._persistCache = function() {
|
||||
return this._persisting;
|
||||
};
|
||||
|
||||
function loadCacheSync(cacheFilepath) {
|
||||
function loadCacheSync(cachePath) {
|
||||
var ret = Object.create(null);
|
||||
if (!fs.existsSync(cacheFilepath)) {
|
||||
if (!fs.existsSync(cachePath)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
var cacheOnDisk = JSON.parse(fs.readFileSync(cacheFilepath));
|
||||
var cacheOnDisk;
|
||||
try {
|
||||
cacheOnDisk = JSON.parse(fs.readFileSync(cachePath));
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.warn('Unable to parse cache file. Will clear and continue.');
|
||||
fs.unlinkSync(cachePath);
|
||||
return ret;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Filter outdated cache and convert to promises.
|
||||
Object.keys(cacheOnDisk).forEach(function(key) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user