mirror of
https://github.com/status-im/metro.git
synced 2025-03-02 11:40:55 +00:00
packager: Module: better type for transformOptions
Reviewed By: davidaurelio Differential Revision: D4237808 fbshipit-source-id: 8ca40bc9f8e7ec7cea2aaa8a8562dc63d423cea4
This commit is contained in:
parent
0b7a6d830f
commit
305c6ed6f9
@ -18,6 +18,7 @@ const path = require('path');
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
const toFixedHex = require('./toFixedHex');
|
const toFixedHex = require('./toFixedHex');
|
||||||
|
|
||||||
|
import type {Options as TransformOptions} from '../JSTransformer/worker/worker';
|
||||||
import type {CachedResult} from './TransformCache';
|
import type {CachedResult} from './TransformCache';
|
||||||
|
|
||||||
const SINGLE_REQUEST_MAX_KEYS = 100;
|
const SINGLE_REQUEST_MAX_KEYS = 100;
|
||||||
@ -32,7 +33,7 @@ type FetchProps = {
|
|||||||
filePath: string,
|
filePath: string,
|
||||||
sourceCode: string,
|
sourceCode: string,
|
||||||
transformCacheKey: string,
|
transformCacheKey: string,
|
||||||
transformOptions: mixed,
|
transformOptions: TransformOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
type FetchCallback = (error?: Error, resultURI?: ?CachedResult) => mixed;
|
type FetchCallback = (error?: Error, resultURI?: ?CachedResult) => mixed;
|
||||||
|
7
react-packager/src/lib/TransformCache.js
vendored
7
react-packager/src/lib/TransformCache.js
vendored
@ -28,6 +28,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync;
|
|||||||
const CACHE_NAME = 'react-native-packager-cache';
|
const CACHE_NAME = 'react-native-packager-cache';
|
||||||
|
|
||||||
type CacheFilePaths = {transformedCode: string, metadata: string};
|
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
|
* If packager is running for two different directories, we don't want the
|
||||||
@ -62,7 +63,7 @@ function hashSourceCode(props: {
|
|||||||
*/
|
*/
|
||||||
function getCacheFilePaths(props: {
|
function getCacheFilePaths(props: {
|
||||||
filePath: string,
|
filePath: string,
|
||||||
transformOptions: mixed,
|
transformOptions: TransformOptions,
|
||||||
}): CacheFilePaths {
|
}): CacheFilePaths {
|
||||||
const hasher = imurmurhash()
|
const hasher = imurmurhash()
|
||||||
.hash(props.filePath)
|
.hash(props.filePath)
|
||||||
@ -117,7 +118,7 @@ function writeSync(props: {
|
|||||||
filePath: string,
|
filePath: string,
|
||||||
sourceCode: string,
|
sourceCode: string,
|
||||||
transformCacheKey: string,
|
transformCacheKey: string,
|
||||||
transformOptions: mixed,
|
transformOptions: TransformOptions,
|
||||||
result: CachedResult,
|
result: CachedResult,
|
||||||
}): void {
|
}): void {
|
||||||
const cacheFilePath = getCacheFilePaths(props);
|
const cacheFilePath = getCacheFilePaths(props);
|
||||||
@ -275,7 +276,7 @@ function readMetadataFileSync(
|
|||||||
export type ReadTransformProps = {
|
export type ReadTransformProps = {
|
||||||
filePath: string,
|
filePath: string,
|
||||||
sourceCode: string,
|
sourceCode: string,
|
||||||
transformOptions: mixed,
|
transformOptions: TransformOptions,
|
||||||
transformCacheKey: string,
|
transformCacheKey: string,
|
||||||
cacheOptions: CacheOptions,
|
cacheOptions: CacheOptions,
|
||||||
};
|
};
|
||||||
|
12
react-packager/src/node-haste/Module.js
vendored
12
react-packager/src/node-haste/Module.js
vendored
@ -23,7 +23,7 @@ const jsonStableStringify = require('json-stable-stringify');
|
|||||||
|
|
||||||
const {join: joinPath, relative: relativePath, extname} = require('path');
|
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 {ReadTransformProps} from '../lib/TransformCache';
|
||||||
import type Cache from './Cache';
|
import type Cache from './Cache';
|
||||||
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||||
@ -40,7 +40,7 @@ type ReadResult = {
|
|||||||
export type TransformCode = (
|
export type TransformCode = (
|
||||||
module: Module,
|
module: Module,
|
||||||
sourceCode: string,
|
sourceCode: string,
|
||||||
transformOptions: mixed,
|
transformOptions: TransformOptions,
|
||||||
) => Promise<TransformedCode>;
|
) => Promise<TransformedCode>;
|
||||||
|
|
||||||
export type Options = {
|
export type Options = {
|
||||||
@ -118,11 +118,11 @@ class Module {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCode(transformOptions: Object) {
|
getCode(transformOptions: TransformOptions) {
|
||||||
return this.read(transformOptions).then(({code}) => code);
|
return this.read(transformOptions).then(({code}) => code);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMap(transformOptions: Object) {
|
getMap(transformOptions: TransformOptions) {
|
||||||
return this.read(transformOptions).then(({map}) => map);
|
return this.read(transformOptions).then(({map}) => map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ class Module {
|
|||||||
return this._moduleCache.getPackageForModule(this);
|
return this._moduleCache.getPackageForModule(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDependencies(transformOptions: Object) {
|
getDependencies(transformOptions: TransformOptions) {
|
||||||
return this.read(transformOptions).then(({dependencies}) => dependencies);
|
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
|
* 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.
|
* 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 key = stableObjectHash(transformOptions || {});
|
||||||
const promise = this._readPromises.get(key);
|
const promise = this._readPromises.get(key);
|
||||||
if (promise != null) {
|
if (promise != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user