Skip to content

Commit

Permalink
packager: Module: better type for transformOptions
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D4237808

fbshipit-source-id: 8ca40bc9f8e7ec7cea2aaa8a8562dc63d423cea4
  • Loading branch information
Jean Lauliac authored and Facebook Github Bot committed Nov 29, 2016
1 parent c4046d6 commit c284e0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packager/react-packager/src/lib/GlobalTransformCache.js
Expand Up @@ -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;
Expand All @@ -32,7 +33,7 @@ type FetchProps = {
filePath: string,
sourceCode: string,
transformCacheKey: string,
transformOptions: mixed,
transformOptions: TransformOptions,
};

type FetchCallback = (error?: Error, resultURI?: ?CachedResult) => mixed;
Expand Down
7 changes: 4 additions & 3 deletions packager/react-packager/src/lib/TransformCache.js
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +63,7 @@ function hashSourceCode(props: {
*/
function getCacheFilePaths(props: {
filePath: string,
transformOptions: mixed,
transformOptions: TransformOptions,
}): CacheFilePaths {
const hasher = imurmurhash()
.hash(props.filePath)
Expand Down Expand Up @@ -117,7 +118,7 @@ function writeSync(props: {
filePath: string,
sourceCode: string,
transformCacheKey: string,
transformOptions: mixed,
transformOptions: TransformOptions,
result: CachedResult,
}): void {
const cacheFilePath = getCacheFilePaths(props);
Expand Down Expand Up @@ -275,7 +276,7 @@ function readMetadataFileSync(
export type ReadTransformProps = {
filePath: string,
sourceCode: string,
transformOptions: mixed,
transformOptions: TransformOptions,
transformCacheKey: string,
cacheOptions: CacheOptions,
};
Expand Down
12 changes: 6 additions & 6 deletions packager/react-packager/src/node-haste/Module.js
Expand Up @@ -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';
Expand All @@ -40,7 +40,7 @@ type ReadResult = {
export type TransformCode = (
module: Module,
sourceCode: string,
transformOptions: mixed,
transformOptions: TransformOptions,
) => Promise<TransformedCode>;

export type Options = {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ class Module {
return this._moduleCache.getPackageForModule(this);
}

getDependencies(transformOptions: Object) {
getDependencies(transformOptions: TransformOptions) {
return this.read(transformOptions).then(({dependencies}) => dependencies);
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c284e0c

Please sign in to comment.