From c284e0cd7a1561e438335752e24559a8f18baea7 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 29 Nov 2016 04:28:10 -0800 Subject: [PATCH] packager: Module: better type for transformOptions Reviewed By: davidaurelio Differential Revision: D4237808 fbshipit-source-id: 8ca40bc9f8e7ec7cea2aaa8a8562dc63d423cea4 --- .../react-packager/src/lib/GlobalTransformCache.js | 3 ++- packager/react-packager/src/lib/TransformCache.js | 7 ++++--- packager/react-packager/src/node-haste/Module.js | 12 ++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packager/react-packager/src/lib/GlobalTransformCache.js b/packager/react-packager/src/lib/GlobalTransformCache.js index ef86993be55ecf..d6de72cc3561ce 100644 --- a/packager/react-packager/src/lib/GlobalTransformCache.js +++ b/packager/react-packager/src/lib/GlobalTransformCache.js @@ -18,6 +18,7 @@ const path = require('path'); const request = require('request'); const toFixedHex = require('./toFixedHex'); +import type {Options as TransformOptions} from '../JSTransformer/worker/worker'; import type {CachedResult} from './TransformCache'; const SINGLE_REQUEST_MAX_KEYS = 100; @@ -32,7 +33,7 @@ type FetchProps = { filePath: string, sourceCode: string, transformCacheKey: string, - transformOptions: mixed, + transformOptions: TransformOptions, }; type FetchCallback = (error?: Error, resultURI?: ?CachedResult) => mixed; diff --git a/packager/react-packager/src/lib/TransformCache.js b/packager/react-packager/src/lib/TransformCache.js index 07168629e2dfd6..69f48584c42251 100644 --- a/packager/react-packager/src/lib/TransformCache.js +++ b/packager/react-packager/src/lib/TransformCache.js @@ -28,6 +28,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync; const CACHE_NAME = 'react-native-packager-cache'; type CacheFilePaths = {transformedCode: string, metadata: string}; +import type {Options as TransformOptions} from '../JSTransformer/worker/worker'; /** * If packager is running for two different directories, we don't want the @@ -62,7 +63,7 @@ function hashSourceCode(props: { */ function getCacheFilePaths(props: { filePath: string, - transformOptions: mixed, + transformOptions: TransformOptions, }): CacheFilePaths { const hasher = imurmurhash() .hash(props.filePath) @@ -117,7 +118,7 @@ function writeSync(props: { filePath: string, sourceCode: string, transformCacheKey: string, - transformOptions: mixed, + transformOptions: TransformOptions, result: CachedResult, }): void { const cacheFilePath = getCacheFilePaths(props); @@ -275,7 +276,7 @@ function readMetadataFileSync( export type ReadTransformProps = { filePath: string, sourceCode: string, - transformOptions: mixed, + transformOptions: TransformOptions, transformCacheKey: string, cacheOptions: CacheOptions, }; diff --git a/packager/react-packager/src/node-haste/Module.js b/packager/react-packager/src/node-haste/Module.js index c1a2f19d094442..393de4e34f422b 100644 --- a/packager/react-packager/src/node-haste/Module.js +++ b/packager/react-packager/src/node-haste/Module.js @@ -23,7 +23,7 @@ const jsonStableStringify = require('json-stable-stringify'); const {join: joinPath, relative: relativePath, extname} = require('path'); -import type {TransformedCode} from '../JSTransformer/worker/worker'; +import type {TransformedCode, Options as TransformOptions} from '../JSTransformer/worker/worker'; import type {ReadTransformProps} from '../lib/TransformCache'; import type Cache from './Cache'; import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; @@ -40,7 +40,7 @@ type ReadResult = { export type TransformCode = ( module: Module, sourceCode: string, - transformOptions: mixed, + transformOptions: TransformOptions, ) => Promise; export type Options = { @@ -118,11 +118,11 @@ class Module { ); } - getCode(transformOptions: Object) { + getCode(transformOptions: TransformOptions) { return this.read(transformOptions).then(({code}) => code); } - getMap(transformOptions: Object) { + getMap(transformOptions: TransformOptions) { return this.read(transformOptions).then(({map}) => map); } @@ -158,7 +158,7 @@ class Module { return this._moduleCache.getPackageForModule(this); } - getDependencies(transformOptions: Object) { + getDependencies(transformOptions: TransformOptions) { return this.read(transformOptions).then(({dependencies}) => dependencies); } @@ -281,7 +281,7 @@ class Module { * dependencies, etc. The overall process is to read the cache first, and if * it's a miss, we let the worker write to the cache and read it again. */ - read(transformOptions: Object): Promise { + read(transformOptions: TransformOptions): Promise { const key = stableObjectHash(transformOptions || {}); const promise = this._readPromises.get(key); if (promise != null) {