Skip to content

Commit

Permalink
packager: Module: gives global cache more retries
Browse files Browse the repository at this point in the history
Reviewed By: cpojer

Differential Revision: D4250880

fbshipit-source-id: c2d215d4dad10705bc24bec758aed85ef13607ba
  • Loading branch information
Jean Lauliac authored and Facebook Github Bot committed Nov 30, 2016
1 parent cb254d1 commit 59873d7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packager/react-packager/src/node-haste/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Module {
_readSourceCodePromise: Promise<string>;
_readPromises: Map<string, Promise<ReadResult>>;

static _useGlobalCache: boolean;
static _globalCacheRetries: number;

constructor({
file,
Expand Down Expand Up @@ -235,21 +235,23 @@ class Module {
callback: (error: ?Error, result: ?TransformedCode) => void,
) {
const globalCache = GlobalTransformCache.get();
if (!Module._useGlobalCache || globalCache == null) {
if (Module._globalCacheRetries <= 0 || globalCache == null) {
this._transformCodeForCallback(cacheProps, callback);
return;
}
globalCache.fetch(cacheProps, (globalCacheError, globalCachedResult) => {
if (globalCacheError != null && Module._useGlobalCache) {
if (globalCacheError != null && Module._globalCacheRetries > 0) {
console.log(chalk.red(
'\nWarning: the global cache failed with error:',
));
console.log(chalk.red(globalCacheError.stack));
console.log(chalk.red(
'The global cache will be DISABLED for the ' +
'remainder of the transformation.',
));
Module._useGlobalCache = false;
Module._globalCacheRetries--;
if (Module._globalCacheRetries <= 0) {
console.log(chalk.red(
'No more retries, the global cache will be disabled for the ' +
'remainder of the transformation.',
));
}
}
if (globalCacheError != null || globalCachedResult == null) {
this._transformCodeForCallback(cacheProps, callback);
Expand Down Expand Up @@ -353,7 +355,7 @@ class Module {
}
}

Module._useGlobalCache = true;
Module._globalCacheRetries = 4;

// use weak map to speed up hash creation of known objects
const knownHashes = new WeakMap();
Expand Down

0 comments on commit 59873d7

Please sign in to comment.