packager: remove rogue terminal.log()

Reviewed By: cpojer

Differential Revision: D4468825

fbshipit-source-id: 29320f50cabc6002401e470a9ac278e9cb6673d3
This commit is contained in:
Jean Lauliac 2017-01-26 10:41:24 -08:00 committed by Christoph Pojer
parent ec5cd2a59a
commit 7883debebc
4 changed files with 17 additions and 5 deletions

View File

@ -158,6 +158,9 @@ class TerminalReporter {
case 'global_cache_disabled':
this._logCacheDisabled(event.reason);
break;
case 'transform_cache_reset':
reporting.logWarning(terminal, 'the transform cache was reset.');
break;
}
}

View File

@ -32,6 +32,7 @@ const CACHE_NAME = 'react-native-packager-cache';
type CacheFilePaths = {transformedCode: string, metadata: string};
import type {Options as TransformOptions} from '../JSTransformer/worker/worker';
import type {SourceMap} from './SourceMap';
import type {Reporter} from './reporting';
/**
* If packager is running for two different directories, we don't want the
@ -143,7 +144,10 @@ function writeSync(props: {
]));
}
export type CacheOptions = {resetCache?: boolean};
export type CacheOptions = {
reporter: Reporter,
resetCache?: boolean,
};
/* 1 day */
const GARBAGE_COLLECTION_PERIOD = 24 * 60 * 60 * 1000;
@ -204,16 +208,16 @@ const GARBAGE_COLLECTOR = new (class GarbageCollector {
this._lastCollected = Date.now();
}
_resetCache() {
_resetCache(reporter: Reporter) {
rimraf.sync(getCacheDirPath());
terminal.log('Warning: The transform cache was reset.');
reporter.update({type: 'transform_cache_reset'});
this._cacheWasReset = true;
this._lastCollected = Date.now();
}
collectIfNecessarySync(options: CacheOptions) {
if (options.resetCache && !this._cacheWasReset) {
this._resetCache();
this._resetCache(options.reporter);
return;
}
const lastCollected = this._lastCollected;

View File

@ -47,6 +47,8 @@ export type ReportableEvent = {
} | {
type: 'global_cache_disabled',
reason: GlobalCacheDisabledReason,
} | {
type: 'transform_cache_reset',
};
/**

View File

@ -326,7 +326,10 @@ class Module {
sourceCode,
transformCacheKey,
transformOptions,
cacheOptions: this._options,
cacheOptions: {
resetCache: this._options.resetCache,
reporter: this._reporter,
},
};
const cachedResult = TransformCache.readSync(cacheProps);
if (cachedResult) {