packager: Module: better type for transformOptions

Reviewed By: davidaurelio

Differential Revision: D4237808

fbshipit-source-id: 8ca40bc9f8e7ec7cea2aaa8a8562dc63d423cea4
This commit is contained in:
Jean Lauliac 2016-11-29 04:28:10 -08:00 committed by Facebook Github Bot
parent 0b7a6d830f
commit 305c6ed6f9
3 changed files with 12 additions and 10 deletions

View File

@ -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;

View File

@ -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,
};

View File

@ -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<TransformedCode>;
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<ReadResult> {
read(transformOptions: TransformOptions): Promise<ReadResult> {
const key = stableObjectHash(transformOptions || {});
const promise = this._readPromises.get(key);
if (promise != null) {