packager: remove rogue terminal.log()
Reviewed By: cpojer Differential Revision: D4468825 fbshipit-source-id: 29320f50cabc6002401e470a9ac278e9cb6673d3
This commit is contained in:
parent
65513e501a
commit
48b86022fb
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -47,6 +47,8 @@ export type ReportableEvent = {
|
|||
} | {
|
||||
type: 'global_cache_disabled',
|
||||
reason: GlobalCacheDisabledReason,
|
||||
} | {
|
||||
type: 'transform_cache_reset',
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue