Skip to content

Commit c284e0c

Browse files
Jean LauliacFacebook Github Bot
Jean Lauliac
authored and
Facebook Github Bot
committed
packager: Module: better type for transformOptions
Reviewed By: davidaurelio Differential Revision: D4237808 fbshipit-source-id: 8ca40bc9f8e7ec7cea2aaa8a8562dc63d423cea4
1 parent c4046d6 commit c284e0c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packager/react-packager/src/lib/GlobalTransformCache.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const path = require('path');
1818
const request = require('request');
1919
const toFixedHex = require('./toFixedHex');
2020

21+
import type {Options as TransformOptions} from '../JSTransformer/worker/worker';
2122
import type {CachedResult} from './TransformCache';
2223

2324
const SINGLE_REQUEST_MAX_KEYS = 100;
@@ -32,7 +33,7 @@ type FetchProps = {
3233
filePath: string,
3334
sourceCode: string,
3435
transformCacheKey: string,
35-
transformOptions: mixed,
36+
transformOptions: TransformOptions,
3637
};
3738

3839
type FetchCallback = (error?: Error, resultURI?: ?CachedResult) => mixed;

packager/react-packager/src/lib/TransformCache.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync;
2828
const CACHE_NAME = 'react-native-packager-cache';
2929

3030
type CacheFilePaths = {transformedCode: string, metadata: string};
31+
import type {Options as TransformOptions} from '../JSTransformer/worker/worker';
3132

3233
/**
3334
* If packager is running for two different directories, we don't want the
@@ -62,7 +63,7 @@ function hashSourceCode(props: {
6263
*/
6364
function getCacheFilePaths(props: {
6465
filePath: string,
65-
transformOptions: mixed,
66+
transformOptions: TransformOptions,
6667
}): CacheFilePaths {
6768
const hasher = imurmurhash()
6869
.hash(props.filePath)
@@ -117,7 +118,7 @@ function writeSync(props: {
117118
filePath: string,
118119
sourceCode: string,
119120
transformCacheKey: string,
120-
transformOptions: mixed,
121+
transformOptions: TransformOptions,
121122
result: CachedResult,
122123
}): void {
123124
const cacheFilePath = getCacheFilePaths(props);
@@ -275,7 +276,7 @@ function readMetadataFileSync(
275276
export type ReadTransformProps = {
276277
filePath: string,
277278
sourceCode: string,
278-
transformOptions: mixed,
279+
transformOptions: TransformOptions,
279280
transformCacheKey: string,
280281
cacheOptions: CacheOptions,
281282
};

packager/react-packager/src/node-haste/Module.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const jsonStableStringify = require('json-stable-stringify');
2323

2424
const {join: joinPath, relative: relativePath, extname} = require('path');
2525

26-
import type {TransformedCode} from '../JSTransformer/worker/worker';
26+
import type {TransformedCode, Options as TransformOptions} from '../JSTransformer/worker/worker';
2727
import type {ReadTransformProps} from '../lib/TransformCache';
2828
import type Cache from './Cache';
2929
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
@@ -40,7 +40,7 @@ type ReadResult = {
4040
export type TransformCode = (
4141
module: Module,
4242
sourceCode: string,
43-
transformOptions: mixed,
43+
transformOptions: TransformOptions,
4444
) => Promise<TransformedCode>;
4545

4646
export type Options = {
@@ -118,11 +118,11 @@ class Module {
118118
);
119119
}
120120

121-
getCode(transformOptions: Object) {
121+
getCode(transformOptions: TransformOptions) {
122122
return this.read(transformOptions).then(({code}) => code);
123123
}
124124

125-
getMap(transformOptions: Object) {
125+
getMap(transformOptions: TransformOptions) {
126126
return this.read(transformOptions).then(({map}) => map);
127127
}
128128

@@ -158,7 +158,7 @@ class Module {
158158
return this._moduleCache.getPackageForModule(this);
159159
}
160160

161-
getDependencies(transformOptions: Object) {
161+
getDependencies(transformOptions: TransformOptions) {
162162
return this.read(transformOptions).then(({dependencies}) => dependencies);
163163
}
164164

@@ -281,7 +281,7 @@ class Module {
281281
* dependencies, etc. The overall process is to read the cache first, and if
282282
* it's a miss, we let the worker write to the cache and read it again.
283283
*/
284-
read(transformOptions: Object): Promise<ReadResult> {
284+
read(transformOptions: TransformOptions): Promise<ReadResult> {
285285
const key = stableObjectHash(transformOptions || {});
286286
const promise = this._readPromises.get(key);
287287
if (promise != null) {

0 commit comments

Comments
 (0)