mirror of https://github.com/status-im/metro.git
packager: Module: gives global cache more retries
Reviewed By: cpojer Differential Revision: D4250880 fbshipit-source-id: c2d215d4dad10705bc24bec758aed85ef13607ba
This commit is contained in:
parent
6d26816cc6
commit
1b4bdf0bac
|
@ -74,7 +74,7 @@ class Module {
|
||||||
_readSourceCodePromise: Promise<string>;
|
_readSourceCodePromise: Promise<string>;
|
||||||
_readPromises: Map<string, Promise<ReadResult>>;
|
_readPromises: Map<string, Promise<ReadResult>>;
|
||||||
|
|
||||||
static _useGlobalCache: boolean;
|
static _globalCacheRetries: number;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
file,
|
file,
|
||||||
|
@ -235,21 +235,23 @@ class Module {
|
||||||
callback: (error: ?Error, result: ?TransformedCode) => void,
|
callback: (error: ?Error, result: ?TransformedCode) => void,
|
||||||
) {
|
) {
|
||||||
const globalCache = GlobalTransformCache.get();
|
const globalCache = GlobalTransformCache.get();
|
||||||
if (!Module._useGlobalCache || globalCache == null) {
|
if (Module._globalCacheRetries <= 0 || globalCache == null) {
|
||||||
this._transformCodeForCallback(cacheProps, callback);
|
this._transformCodeForCallback(cacheProps, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalCache.fetch(cacheProps, (globalCacheError, globalCachedResult) => {
|
globalCache.fetch(cacheProps, (globalCacheError, globalCachedResult) => {
|
||||||
if (globalCacheError != null && Module._useGlobalCache) {
|
if (globalCacheError != null && Module._globalCacheRetries > 0) {
|
||||||
console.log(chalk.red(
|
console.log(chalk.red(
|
||||||
'\nWarning: the global cache failed with error:',
|
'\nWarning: the global cache failed with error:',
|
||||||
));
|
));
|
||||||
console.log(chalk.red(globalCacheError.stack));
|
console.log(chalk.red(globalCacheError.stack));
|
||||||
|
Module._globalCacheRetries--;
|
||||||
|
if (Module._globalCacheRetries <= 0) {
|
||||||
console.log(chalk.red(
|
console.log(chalk.red(
|
||||||
'The global cache will be DISABLED for the ' +
|
'No more retries, the global cache will be disabled for the ' +
|
||||||
'remainder of the transformation.',
|
'remainder of the transformation.',
|
||||||
));
|
));
|
||||||
Module._useGlobalCache = false;
|
}
|
||||||
}
|
}
|
||||||
if (globalCacheError != null || globalCachedResult == null) {
|
if (globalCacheError != null || globalCachedResult == null) {
|
||||||
this._transformCodeForCallback(cacheProps, callback);
|
this._transformCodeForCallback(cacheProps, callback);
|
||||||
|
@ -353,7 +355,7 @@ class Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Module._useGlobalCache = true;
|
Module._globalCacheRetries = 4;
|
||||||
|
|
||||||
// use weak map to speed up hash creation of known objects
|
// use weak map to speed up hash creation of known objects
|
||||||
const knownHashes = new WeakMap();
|
const knownHashes = new WeakMap();
|
||||||
|
|
Loading…
Reference in New Issue