mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
[react-packager] Recover and warn from corrupted cache file
This commit is contained in:
parent
b910d1142f
commit
535bdfcf87
@ -112,13 +112,23 @@ Cache.prototype._persistCache = function() {
|
|||||||
return this._persisting;
|
return this._persisting;
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadCacheSync(cacheFilepath) {
|
function loadCacheSync(cachePath) {
|
||||||
var ret = Object.create(null);
|
var ret = Object.create(null);
|
||||||
if (!fs.existsSync(cacheFilepath)) {
|
if (!fs.existsSync(cachePath)) {
|
||||||
return ret;
|
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.
|
// Filter outdated cache and convert to promises.
|
||||||
Object.keys(cacheOnDisk).forEach(function(key) {
|
Object.keys(cacheOnDisk).forEach(function(key) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user