From 48b86022fbf0895242bf3c16f3c8b043fc48d6bc Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Thu, 26 Jan 2017 10:41:24 -0800 Subject: [PATCH] packager: remove rogue terminal.log() Reviewed By: cpojer Differential Revision: D4468825 fbshipit-source-id: 29320f50cabc6002401e470a9ac278e9cb6673d3 --- packager/react-packager/src/lib/TerminalReporter.js | 3 +++ packager/react-packager/src/lib/TransformCache.js | 12 ++++++++---- packager/react-packager/src/lib/reporting.js | 2 ++ packager/react-packager/src/node-haste/Module.js | 5 ++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packager/react-packager/src/lib/TerminalReporter.js b/packager/react-packager/src/lib/TerminalReporter.js index 6bf7f3784..2edb63d36 100644 --- a/packager/react-packager/src/lib/TerminalReporter.js +++ b/packager/react-packager/src/lib/TerminalReporter.js @@ -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; } } diff --git a/packager/react-packager/src/lib/TransformCache.js b/packager/react-packager/src/lib/TransformCache.js index 7ff0b620a..9973e71c6 100644 --- a/packager/react-packager/src/lib/TransformCache.js +++ b/packager/react-packager/src/lib/TransformCache.js @@ -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; diff --git a/packager/react-packager/src/lib/reporting.js b/packager/react-packager/src/lib/reporting.js index 8e086dc07..77cb46ff4 100644 --- a/packager/react-packager/src/lib/reporting.js +++ b/packager/react-packager/src/lib/reporting.js @@ -47,6 +47,8 @@ export type ReportableEvent = { } | { type: 'global_cache_disabled', reason: GlobalCacheDisabledReason, +} | { + type: 'transform_cache_reset', }; /** diff --git a/packager/react-packager/src/node-haste/Module.js b/packager/react-packager/src/node-haste/Module.js index 69945c1da..ba0e60e38 100644 --- a/packager/react-packager/src/node-haste/Module.js +++ b/packager/react-packager/src/node-haste/Module.js @@ -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) {