Make transformer result flow types generic all over the place

Reviewed By: jeanlauliac

Differential Revision: D7895095

fbshipit-source-id: df47f4b3e7a08e194fa1a2f874be87ead64ac198
This commit is contained in:
Rafael Oleza 2018-05-11 15:05:34 -07:00 committed by Facebook Github Bot
parent 06c8b6b7a6
commit 35c5abf3ee
24 changed files with 105 additions and 113 deletions

View File

@ -15,13 +15,11 @@ const mkdirp = require('mkdirp');
const path = require('path'); const path = require('path');
const rimraf = require('rimraf'); const rimraf = require('rimraf');
import type {TransformedCode} from 'metro/src/JSTransformer/worker';
export type Options = {| export type Options = {|
root: string, root: string,
|}; |};
class FileStore { class FileStore<T> {
_root: string; _root: string;
constructor(options: Options) { constructor(options: Options) {
@ -29,7 +27,7 @@ class FileStore {
this._createDirs(); this._createDirs();
} }
get(key: Buffer): ?TransformedCode { get(key: Buffer): ?T {
try { try {
return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf8')); return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf8'));
} catch (err) { } catch (err) {
@ -41,7 +39,7 @@ class FileStore {
} }
} }
set(key: Buffer, value: TransformedCode): void { set(key: Buffer, value: T): void {
fs.writeFileSync(this._getFilePath(key), JSON.stringify(value)); fs.writeFileSync(this._getFilePath(key), JSON.stringify(value));
} }

View File

@ -15,8 +15,6 @@ const https = require('https');
const url = require('url'); const url = require('url');
const zlib = require('zlib'); const zlib = require('zlib');
import type {TransformedCode} from 'metro/src/JSTransformer/worker';
export type Options = {| export type Options = {|
endpoint: string, endpoint: string,
timeout?: number, timeout?: number,
@ -26,7 +24,7 @@ const ZLIB_OPTIONS = {
level: 9, level: 9,
}; };
class HttpStore { class HttpStore<T> {
_module: typeof http | typeof https; _module: typeof http | typeof https;
_timeout: number; _timeout: number;
@ -63,7 +61,7 @@ class HttpStore {
this._setAgent = new module.Agent(agentConfig); this._setAgent = new module.Agent(agentConfig);
} }
get(key: Buffer): Promise<?TransformedCode> { get(key: Buffer): Promise<?T> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const options = { const options = {
agent: this._getAgent, agent: this._getAgent,
@ -119,7 +117,7 @@ class HttpStore {
}); });
} }
set(key: Buffer, value: TransformedCode): Promise<void> { set(key: Buffer, value: T): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const gzip = zlib.createGzip(ZLIB_OPTIONS); const gzip = zlib.createGzip(ZLIB_OPTIONS);

View File

@ -22,11 +22,7 @@ const toLocalPath = require('./node-haste/lib/toLocalPath');
const {Cache, stableHash} = require('metro-cache'); const {Cache, stableHash} = require('metro-cache');
import type {TransformResult} from './DeltaBundler'; import type {TransformResult} from './DeltaBundler';
import type { import type {WorkerOptions} from './JSTransformer/worker';
JsOutput,
WorkerOptions,
TransformedCode,
} from './JSTransformer/worker';
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
import type {Reporter} from './lib/reporting'; import type {Reporter} from './lib/reporting';
import type {BabelSourceMap} from '@babel/core'; import type {BabelSourceMap} from '@babel/core';
@ -72,7 +68,7 @@ export type Options = {|
+assetRegistryPath: string, +assetRegistryPath: string,
+asyncRequireModulePath: string, +asyncRequireModulePath: string,
+blacklistRE?: RegExp, +blacklistRE?: RegExp,
+cacheStores: $ReadOnlyArray<CacheStore<TransformedCode>>, +cacheStores: $ReadOnlyArray<CacheStore<TransformResult<>>>,
+cacheVersion: string, +cacheVersion: string,
+dynamicDepsInPackages: DynamicRequiresBehavior, +dynamicDepsInPackages: DynamicRequiresBehavior,
+enableBabelRCLookup: boolean, +enableBabelRCLookup: boolean,
@ -100,7 +96,7 @@ const {hasOwnProperty} = Object.prototype;
class Bundler { class Bundler {
_opts: Options; _opts: Options;
_cache: Cache<TransformedCode>; _cache: Cache<TransformResult<>>;
_baseHash: string; _baseHash: string;
_transformer: Transformer; _transformer: Transformer;
_depGraphPromise: Promise<DependencyGraph>; _depGraphPromise: Promise<DependencyGraph>;
@ -218,7 +214,7 @@ class Bundler {
async transformFile( async transformFile(
filePath: string, filePath: string,
transformCodeOptions: WorkerOptions, transformCodeOptions: WorkerOptions,
): Promise<TransformResult<JsOutput>> { ): Promise<TransformResult<>> {
const cache = this._cache; const cache = this._cache;
const { const {

View File

@ -21,7 +21,7 @@ import type {
PostMinifyProcess, PostMinifyProcess,
PostProcessBundleSourcemap, PostProcessBundleSourcemap,
} from './Bundler'; } from './Bundler';
import type {TransformedCode} from './JSTransformer/worker'; import type {TransformResult} from './DeltaBundler';
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
import type {CacheStore} from 'metro-cache'; import type {CacheStore} from 'metro-cache';
@ -38,7 +38,7 @@ export type ConfigT = {
/** /**
* List of all store caches. * List of all store caches.
*/ */
cacheStores: Array<CacheStore<TransformedCode>>, cacheStores: Array<CacheStore<TransformResult<>>>,
/** /**
* Can be used to generate a key that will invalidate the whole metro cache * Can be used to generate a key that will invalidate the whole metro cache

View File

@ -13,7 +13,13 @@
const DeltaCalculator = require('./DeltaBundler/DeltaCalculator'); const DeltaCalculator = require('./DeltaBundler/DeltaCalculator');
import type Bundler from './Bundler'; import type Bundler from './Bundler';
import type {DeltaResult, Graph, Options} from './DeltaBundler/types.flow'; import type {
DeltaResult,
Graph,
// eslint-disable-next-line no-unused-vars
MixedOutput,
Options,
} from './DeltaBundler/types.flow';
export type { export type {
DeltaResult, DeltaResult,
@ -29,7 +35,7 @@ export type {
* concurrent clients requesting their own deltas. This is done through the * concurrent clients requesting their own deltas. This is done through the
* `clientId` param (which maps a client to a specific delta transformer). * `clientId` param (which maps a client to a specific delta transformer).
*/ */
class DeltaBundler<T> { class DeltaBundler<T = MixedOutput> {
_bundler: Bundler; _bundler: Bundler;
_deltaCalculators: Map<Graph<T>, DeltaCalculator<T>> = new Map(); _deltaCalculators: Map<Graph<T>, DeltaCalculator<T>> = new Map();

View File

@ -15,7 +15,6 @@ const getAppendScripts = require('../../lib/getAppendScripts');
const {wrapModule} = require('./helpers/js'); const {wrapModule} = require('./helpers/js');
const {getJsOutput, isJsModule} = require('./helpers/js'); const {getJsOutput, isJsModule} = require('./helpers/js');
import type {JsOutput} from '../../JSTransformer/worker';
import type {DeltaResult, Graph, Module} from '../types.flow'; import type {DeltaResult, Graph, Module} from '../types.flow';
type Options = {| type Options = {|
@ -29,10 +28,10 @@ type Options = {|
function deltaJSBundle( function deltaJSBundle(
entryPoint: string, entryPoint: string,
pre: $ReadOnlyArray<Module<JsOutput>>, pre: $ReadOnlyArray<Module<>>,
delta: DeltaResult<JsOutput>, delta: DeltaResult<>,
sequenceId: string, sequenceId: string,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): string { ): string {
const outputPre = []; const outputPre = [];

View File

@ -13,7 +13,6 @@
const {getAssetFiles} = require('../../Assets'); const {getAssetFiles} = require('../../Assets');
const {getJsOutput, isJsModule} = require('./helpers/js'); const {getJsOutput, isJsModule} = require('./helpers/js');
import type {JsOutput} from '../../JSTransformer/worker';
import type {Graph, Module} from '../types.flow'; import type {Graph, Module} from '../types.flow';
type Options = {| type Options = {|
@ -21,8 +20,8 @@ type Options = {|
|}; |};
async function getAllFiles( async function getAllFiles(
pre: $ReadOnlyArray<Module<JsOutput>>, pre: $ReadOnlyArray<Module<>>,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): Promise<$ReadOnlyArray<string>> { ): Promise<$ReadOnlyArray<string>> {
const modules = graph.dependencies; const modules = graph.dependencies;

View File

@ -16,7 +16,6 @@ const {getAssetData} = require('../../Assets');
const {getJsOutput, isJsModule} = require('./helpers/js'); const {getJsOutput, isJsModule} = require('./helpers/js');
import type {AssetData} from '../../Assets'; import type {AssetData} from '../../Assets';
import type {JsOutput} from '../../JSTransformer/worker';
import type {Graph} from '../types.flow'; import type {Graph} from '../types.flow';
type Options = {| type Options = {|
@ -26,7 +25,7 @@ type Options = {|
|}; |};
async function getAssets( async function getAssets(
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): Promise<$ReadOnlyArray<AssetData>> { ): Promise<$ReadOnlyArray<AssetData>> {
const promises = []; const promises = [];

View File

@ -20,7 +20,6 @@ const {createRamBundleGroups} = require('../../Bundler/util');
const {isJsModule, wrapModule} = require('./helpers/js'); const {isJsModule, wrapModule} = require('./helpers/js');
import type {GetTransformOptions} from '../../Bundler'; import type {GetTransformOptions} from '../../Bundler';
import type {JsOutput} from '../../JSTransformer/worker';
import type {ModuleTransportLike} from '../../shared/types.flow'; import type {ModuleTransportLike} from '../../shared/types.flow';
import type {Graph, Module} from '../types.flow'; import type {Graph, Module} from '../types.flow';
@ -45,8 +44,8 @@ export type RamBundleInfo = {|
async function getRamBundleInfo( async function getRamBundleInfo(
entryPoint: string, entryPoint: string,
pre: $ReadOnlyArray<Module<JsOutput>>, pre: $ReadOnlyArray<Module<>>,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): Promise<RamBundleInfo> { ): Promise<RamBundleInfo> {
const modules = [ const modules = [

View File

@ -15,7 +15,7 @@ const invariant = require('fbjs/lib/invariant');
const path = require('path'); const path = require('path');
import type {JsOutput} from '../../../JSTransformer/worker'; import type {JsOutput} from '../../../JSTransformer/worker';
import type {Module} from '../../types.flow'; import type {MixedOutput, Module} from '../../types.flow';
export type Options = { export type Options = {
+createModuleId: string => number | string, +createModuleId: string => number | string,
@ -27,8 +27,9 @@ export type Options = {
// Make sure to set PRINT_REQUIRE_PATHS = true too, and restart Metro // Make sure to set PRINT_REQUIRE_PATHS = true too, and restart Metro
const PASS_MODULE_PATHS_TO_DEFINE = false; const PASS_MODULE_PATHS_TO_DEFINE = false;
function wrapModule(module: Module<JsOutput>, options: Options) { function wrapModule(module: Module<>, options: Options) {
const output = getJsOutput(module); const output = getJsOutput(module);
if (output.type.startsWith('js/script')) { if (output.type.startsWith('js/script')) {
return output.data.code; return output.data.code;
} }
@ -55,7 +56,7 @@ function wrapModule(module: Module<JsOutput>, options: Options) {
return addParamsToDefineCall(output.data.code, ...params); return addParamsToDefineCall(output.data.code, ...params);
} }
function getJsOutput(module: Module<JsOutput>) { function getJsOutput(module: Module<>): JsOutput {
const jsModules = module.output.filter(({type}) => type.startsWith('js/')); const jsModules = module.output.filter(({type}) => type.startsWith('js/'));
invariant( invariant(
@ -65,13 +66,15 @@ function getJsOutput(module: Module<JsOutput>) {
} JS outputs.`, } JS outputs.`,
); );
return jsModules[0]; return (jsModules[0]: any);
} }
function isJsModule(module: Module<JsOutput>) { function isJsModule(module: Module<>): boolean {
const jsModules = module.output.filter(({type}) => type.startsWith('js/')); return module.output.filter(isJsOutput).length > 0;
}
return jsModules.length > 0; function isJsOutput(output: MixedOutput): boolean %checks {
return output.type.startsWith('js/');
} }
module.exports = { module.exports = {

View File

@ -14,7 +14,6 @@ const addParamsToDefineCall = require('../../lib/addParamsToDefineCall');
const {isJsModule, wrapModule} = require('./helpers/js'); const {isJsModule, wrapModule} = require('./helpers/js');
import type {JsOutput} from '../../JSTransformer/worker';
import type {DeltaResult, Graph, Module} from '../types.flow'; import type {DeltaResult, Graph, Module} from '../types.flow';
type Options = { type Options = {
@ -31,8 +30,8 @@ export type Result = {
}; };
function hmrJSBundle( function hmrJSBundle(
delta: DeltaResult<JsOutput>, delta: DeltaResult<>,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): Result { ): Result {
const modules = []; const modules = [];
@ -54,8 +53,8 @@ function hmrJSBundle(
} }
function _prepareModule( function _prepareModule(
module: Module<JsOutput>, module: Module<>,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): {|+id: number, +code: string|} { ): {|+id: number, +code: string|} {
const code = wrapModule(module, { const code = wrapModule(module, {
@ -87,7 +86,7 @@ function _prepareModule(
*/ */
function _getInverseDependencies( function _getInverseDependencies(
path: string, path: string,
graph: Graph<JsOutput>, graph: Graph<>,
inverseDependencies: {[key: string]: Array<string>} = {}, inverseDependencies: {[key: string]: Array<string>} = {},
): {[key: string]: Array<string>} { ): {[key: string]: Array<string>} {
// Dependency alredy traversed. // Dependency alredy traversed.

View File

@ -14,7 +14,6 @@ const getAppendScripts = require('../../lib/getAppendScripts');
const {isJsModule, wrapModule} = require('./helpers/js'); const {isJsModule, wrapModule} = require('./helpers/js');
import type {JsOutput} from '../../JSTransformer/worker';
import type {Graph, Module} from '../types.flow'; import type {Graph, Module} from '../types.flow';
type Options = {| type Options = {|
@ -28,8 +27,8 @@ type Options = {|
function plainJSBundle( function plainJSBundle(
entryPoint: string, entryPoint: string,
pre: $ReadOnlyArray<Module<JsOutput>>, pre: $ReadOnlyArray<Module<>>,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options, options: Options,
): string { ): string {
for (const module of graph.dependencies.values()) { for (const module of graph.dependencies.values()) {

View File

@ -13,13 +13,12 @@
const {isJsModule, getJsOutput} = require('./helpers/js'); const {isJsModule, getJsOutput} = require('./helpers/js');
const {fromRawMappings} = require('metro-source-map'); const {fromRawMappings} = require('metro-source-map');
import type {JsOutput} from '../../JSTransformer/worker';
import type {Graph, Module} from '../types.flow'; import type {Graph, Module} from '../types.flow';
import type {BabelSourceMap} from '@babel/core'; import type {BabelSourceMap} from '@babel/core';
function fullSourceMapObject( function fullSourceMapObject(
pre: $ReadOnlyArray<Module<JsOutput>>, pre: $ReadOnlyArray<Module<>>,
graph: Graph<JsOutput>, graph: Graph<>,
options: {|+excludeSource: boolean|}, options: {|+excludeSource: boolean|},
): BabelSourceMap { ): BabelSourceMap {
const modules = [...pre, ...graph.dependencies.values()] const modules = [...pre, ...graph.dependencies.values()]

View File

@ -13,12 +13,11 @@
const {isJsModule, getJsOutput} = require('./helpers/js'); const {isJsModule, getJsOutput} = require('./helpers/js');
const {fromRawMappings} = require('metro-source-map'); const {fromRawMappings} = require('metro-source-map');
import type {JsOutput} from '../../JSTransformer/worker';
import type {Graph, Module} from '../types.flow'; import type {Graph, Module} from '../types.flow';
function fullSourceMap( function fullSourceMap(
pre: $ReadOnlyArray<Module<JsOutput>>, pre: $ReadOnlyArray<Module<>>,
graph: Graph<JsOutput>, graph: Graph<>,
options: {|+excludeSource: boolean|}, options: {|+excludeSource: boolean|},
): string { ): string {
const modules = [...pre, ...graph.dependencies.values()] const modules = [...pre, ...graph.dependencies.values()]

View File

@ -12,12 +12,17 @@
import type {TransformResultDependency} from '../ModuleGraph/types.flow'; import type {TransformResultDependency} from '../ModuleGraph/types.flow';
export type MixedOutput = {|
+data: mixed,
+type: string,
|};
export type Dependency = {| export type Dependency = {|
+absolutePath: string, +absolutePath: string,
+data: TransformResultDependency, +data: TransformResultDependency,
|}; |};
export type Module<T> = {| export type Module<T = MixedOutput> = {|
dependencies: Map<string, Dependency>, dependencies: Map<string, Dependency>,
inverseDependencies: Set<string>, inverseDependencies: Set<string>,
output: $ReadOnlyArray<T>, output: $ReadOnlyArray<T>,
@ -25,26 +30,28 @@ export type Module<T> = {|
getSource: () => string, getSource: () => string,
|}; |};
export type Graph<T> = {| export type Graph<T = MixedOutput> = {|
dependencies: Map<string, Module<T>>, dependencies: Map<string, Module<T>>,
entryPoints: $ReadOnlyArray<string>, entryPoints: $ReadOnlyArray<string>,
|}; |};
export type TransformResult<T> = {| export type TransformResult<T = MixedOutput> = {|
dependencies: $ReadOnlyArray<TransformResultDependency>, dependencies: $ReadOnlyArray<TransformResultDependency>,
output: $ReadOnlyArray<T>, output: $ReadOnlyArray<T>,
+getSource: () => string, +getSource: () => string,
|}; |};
export type TransformFn<T> = string => Promise<TransformResult<T>>; export type TransformFn<T = MixedOutput> = string => Promise<
TransformResult<T>,
>;
export type Options<T> = {| export type Options<T = MixedOutput> = {|
resolve: (from: string, to: string) => string, resolve: (from: string, to: string) => string,
transform: TransformFn<T>, transform: TransformFn<T>,
onProgress: ?(numProcessed: number, total: number) => mixed, onProgress: ?(numProcessed: number, total: number) => mixed,
|}; |};
export type DeltaResult<T> = {| export type DeltaResult<T = MixedOutput> = {|
+modified: Map<string, Module<T>>, +modified: Map<string, Module<T>>,
+deleted: Set<string>, +deleted: Set<string>,
+reset: boolean, +reset: boolean,

View File

@ -21,11 +21,11 @@ const {
Logger: {createActionStartEntry, createActionEndEntry, log}, Logger: {createActionStartEntry, createActionEndEntry, log},
} = require('metro-core'); } = require('metro-core');
import type PackagerServer, {JsGraph} from './Server'; import type PackagerServer, {OutputGraph} from './Server';
import type {Reporter} from './lib/reporting'; import type {Reporter} from './lib/reporting';
type Client = {| type Client = {|
graph: JsGraph, graph: OutputGraph,
sendFn: (data: string) => mixed, sendFn: (data: string) => mixed,
|}; |};

View File

@ -16,7 +16,8 @@ const {Logger} = require('metro-core');
const debug = require('debug')('Metro:JStransformer'); const debug = require('debug')('Metro:JStransformer');
const Worker = require('jest-worker').default; const Worker = require('jest-worker').default;
import type {TransformedCode, WorkerOptions} from './JSTransformer/worker'; import type {TransformResult} from './DeltaBundler';
import type {WorkerOptions} from './JSTransformer/worker';
import type {LocalPath} from './node-haste/lib/toLocalPath'; import type {LocalPath} from './node-haste/lib/toLocalPath';
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
@ -32,7 +33,7 @@ type Reporters = {
}; };
type TransformerResult = { type TransformerResult = {
result: TransformedCode, result: TransformResult<>,
sha1: string, sha1: string,
}; };

View File

@ -84,26 +84,24 @@ export type WorkerOptions = {|
+projectRoot: string, +projectRoot: string,
|}; |};
export type Data = { export type JsOutput = {|
result: TransformedCode, +data: {|
+code: string,
+map: Array<MetroSourceMapSegmentTuple>,
|},
+type: string,
|};
type Data = {
result: {|
output: $ReadOnlyArray<JsOutput>,
dependencies: $ReadOnlyArray<TransformResultDependency>,
|},
sha1: string, sha1: string,
transformFileStartLogEntry: LogEntry, transformFileStartLogEntry: LogEntry,
transformFileEndLogEntry: LogEntry, transformFileEndLogEntry: LogEntry,
}; };
export type JsOutput = {|
data: {
+code: string,
+map: Array<MetroSourceMapSegmentTuple>,
},
type: string,
|};
export type TransformedCode = {|
output: $ReadOnlyArray<JsOutput>,
dependencies: $ReadOnlyArray<TransformResultDependency>,
|};
function getDynamicDepsBehavior( function getDynamicDepsBehavior(
inPackages: DynamicRequiresBehavior, inPackages: DynamicRequiresBehavior,
filename: string, filename: string,

View File

@ -42,7 +42,7 @@ const {getAsset} = require('./Assets');
const resolveSync: ResolveSync = require('resolve').sync; const resolveSync: ResolveSync = require('resolve').sync;
import type {CustomError} from './lib/formatBundlingError'; import type {CustomError} from './lib/formatBundlingError';
import type {DeltaResult, Graph, Module} from './DeltaBundler'; import type {DeltaResult, Graph, Module, TransformResult} from './DeltaBundler';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
import type {Reporter} from './lib/reporting'; import type {Reporter} from './lib/reporting';
import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo'; import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
@ -57,11 +57,7 @@ import type {CustomResolver} from 'metro-resolver';
import type {MetroSourceMap} from 'metro-source-map'; import type {MetroSourceMap} from 'metro-source-map';
import type {Symbolicate} from './Server/symbolicate/symbolicate'; import type {Symbolicate} from './Server/symbolicate/symbolicate';
import type {AssetData} from './Assets'; import type {AssetData} from './Assets';
import type { import type {CustomTransformOptions} from './JSTransformer/worker';
CustomTransformOptions,
JsOutput,
TransformedCode,
} from './JSTransformer/worker';
const { const {
Logger: {createActionStartEntry, createActionEndEntry, log}, Logger: {createActionStartEntry, createActionEndEntry, log},
@ -70,8 +66,8 @@ const {
type ResolveSync = (path: string, opts: ?{baseDir?: string}) => string; type ResolveSync = (path: string, opts: ?{baseDir?: string}) => string;
type GraphInfo = {| type GraphInfo = {|
graph: Graph<JsOutput>, graph: Graph<>,
prepend: $ReadOnlyArray<Module<JsOutput>>, prepend: $ReadOnlyArray<Module<>>,
lastModified: Date, lastModified: Date,
+sequenceId: string, +sequenceId: string,
|}; |};
@ -87,7 +83,7 @@ export type BuildGraphOptions = {|
+type: 'module' | 'script', +type: 'module' | 'script',
|}; |};
export type JsGraph = Graph<JsOutput>; export type OutputGraph = Graph<>;
type DeltaOptions = BundleOptions & { type DeltaOptions = BundleOptions & {
deltaBundleId: ?string, deltaBundleId: ?string,
@ -108,7 +104,7 @@ class Server {
_opts: { _opts: {
assetExts: Array<string>, assetExts: Array<string>,
blacklistRE: void | RegExp, blacklistRE: void | RegExp,
cacheStores: $ReadOnlyArray<CacheStore<TransformedCode>>, cacheStores: $ReadOnlyArray<CacheStore<TransformResult<>>>,
cacheVersion: string, cacheVersion: string,
createModuleId: (path: string) => number, createModuleId: (path: string) => number,
enableBabelRCLookup: boolean, enableBabelRCLookup: boolean,
@ -145,7 +141,7 @@ class Server {
_symbolicateInWorker: Symbolicate; _symbolicateInWorker: Symbolicate;
_platforms: Set<string>; _platforms: Set<string>;
_nextBundleBuildID: number; _nextBundleBuildID: number;
_deltaBundler: DeltaBundler<JsOutput>; _deltaBundler: DeltaBundler<>;
_graphs: Map<string, Promise<GraphInfo>> = new Map(); _graphs: Map<string, Promise<GraphInfo>> = new Map();
_deltaGraphs: Map<string, Promise<GraphInfo>> = new Map(); _deltaGraphs: Map<string, Promise<GraphInfo>> = new Map();
@ -258,7 +254,7 @@ class Server {
this._bundler.end(); this._bundler.end();
} }
getDeltaBundler(): DeltaBundler<JsOutput> { getDeltaBundler(): DeltaBundler<> {
return this._deltaBundler; return this._deltaBundler;
} }
@ -288,7 +284,7 @@ class Server {
async buildGraph( async buildGraph(
entryFiles: $ReadOnlyArray<string>, entryFiles: $ReadOnlyArray<string>,
options: BuildGraphOptions, options: BuildGraphOptions,
): Promise<JsGraph> { ): Promise<OutputGraph> {
entryFiles = entryFiles.map(entryFile => entryFiles = entryFiles.map(entryFile =>
getAbsolutePath(entryFile, this._opts.projectRoots), getAbsolutePath(entryFile, this._opts.projectRoots),
); );
@ -447,7 +443,7 @@ class Server {
async _getDeltaInfo( async _getDeltaInfo(
options: DeltaOptions, options: DeltaOptions,
): Promise<{...GraphInfo, delta: DeltaResult<JsOutput>}> { ): Promise<{...GraphInfo, delta: DeltaResult<>}> {
const id = this._optionsHash(options); const id = this._optionsHash(options);
let graphPromise = this._deltaGraphs.get(id); let graphPromise = this._deltaGraphs.get(id);
let graphInfo; let graphInfo;

View File

@ -31,7 +31,7 @@ const {readFile} = require('fs-extra');
const {Terminal} = require('metro-core'); const {Terminal} = require('metro-core');
import type {ConfigT} from './Config'; import type {ConfigT} from './Config';
import type {JsGraph} from './Server'; import type {Graph} from './DeltaBundler';
import type {Reporter} from './lib/reporting'; import type {Reporter} from './lib/reporting';
import type {RequestOptions, OutputOptions} from './shared/types.flow.js'; import type {RequestOptions, OutputOptions} from './shared/types.flow.js';
import type {Options as ServerOptions} from './shared/types.flow'; import type {Options as ServerOptions} from './shared/types.flow';
@ -381,7 +381,7 @@ exports.buildGraph = async function({
platform = `web`, platform = `web`,
type = 'module', type = 'module',
...rest ...rest
}: BuildGraphOptions): Promise<JsGraph> { }: BuildGraphOptions): Promise<Graph<>> {
const metroServer = await runMetro({ const metroServer = await runMetro({
...rest, ...rest,
config, config,

View File

@ -11,7 +11,6 @@
'use strict'; 'use strict';
import type {Graph, Module} from '../DeltaBundler'; import type {Graph, Module} from '../DeltaBundler';
import type {JsOutput} from '../JSTransformer/worker';
type Options<T: number | string> = { type Options<T: number | string> = {
+createModuleId: string => T, +createModuleId: string => T,
@ -23,9 +22,9 @@ type Options<T: number | string> = {
function getAppendScripts<T: number | string>( function getAppendScripts<T: number | string>(
entryPoint: string, entryPoint: string,
graph: Graph<JsOutput>, graph: Graph<>,
options: Options<T>, options: Options<T>,
): $ReadOnlyArray<Module<JsOutput>> { ): $ReadOnlyArray<Module<>> {
const output = []; const output = [];
if (options.runModule) { if (options.runModule) {

View File

@ -16,7 +16,7 @@ const transformHelpers = require('./transformHelpers');
import type Bundler from '../Bundler'; import type Bundler from '../Bundler';
import type DeltaBundler, {Module} from '../DeltaBundler'; import type DeltaBundler, {Module} from '../DeltaBundler';
import type {CustomTransformOptions, JsOutput} from '../JSTransformer/worker'; import type {CustomTransformOptions} from '../JSTransformer/worker';
type Options = { type Options = {
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>, getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
@ -35,8 +35,8 @@ async function getPrependedScripts(
options: Options, options: Options,
bundleOptions: BundleOptions, bundleOptions: BundleOptions,
bundler: Bundler, bundler: Bundler,
deltaBundler: DeltaBundler<JsOutput>, deltaBundler: DeltaBundler<>,
): Promise<Array<Module<JsOutput>>> { ): Promise<$ReadOnlyArray<Module<>>> {
// Get all the polyfills from the relevant option params (the // Get all the polyfills from the relevant option params (the
// `getPolyfills()` method and the `polyfillModuleNames` variable). // `getPolyfills()` method and the `polyfillModuleNames` variable).
const polyfillModuleNames = options const polyfillModuleNames = options
@ -79,7 +79,7 @@ async function getPrependedScripts(
]; ];
} }
function _getPrelude({dev}: {dev: boolean}): Module<JsOutput> { function _getPrelude({dev}: {dev: boolean}): Module<> {
const code = getPreludeCode({isDev: dev}); const code = getPreludeCode({isDev: dev});
const name = '__prelude__'; const name = '__prelude__';

View File

@ -12,7 +12,7 @@
import type Bundler from '../Bundler'; import type Bundler from '../Bundler';
import type DeltaBundler, {TransformFn} from '../DeltaBundler'; import type DeltaBundler, {TransformFn} from '../DeltaBundler';
import type {JsOutput, WorkerOptions} from '../JSTransformer/worker'; import type {WorkerOptions} from '../JSTransformer/worker';
import type {BuildGraphOptions} from '../Server'; import type {BuildGraphOptions} from '../Server';
type InlineRequiresRaw = {+blacklist: {[string]: true}} | boolean; type InlineRequiresRaw = {+blacklist: {[string]: true}} | boolean;
@ -20,7 +20,7 @@ type InlineRequiresRaw = {+blacklist: {[string]: true}} | boolean;
async function calcTransformerOptions( async function calcTransformerOptions(
entryFiles: $ReadOnlyArray<string>, entryFiles: $ReadOnlyArray<string>,
bundler: Bundler, bundler: Bundler,
deltaBundler: DeltaBundler<JsOutput>, deltaBundler: DeltaBundler<>,
options: BuildGraphOptions, options: BuildGraphOptions,
): Promise<{...WorkerOptions, inlineRequires: InlineRequiresRaw}> { ): Promise<{...WorkerOptions, inlineRequires: InlineRequiresRaw}> {
const { const {
@ -85,9 +85,9 @@ function removeInlineRequiresBlacklistFromOptions(
async function getTransformFn( async function getTransformFn(
entryFiles: $ReadOnlyArray<string>, entryFiles: $ReadOnlyArray<string>,
bundler: Bundler, bundler: Bundler,
deltaBundler: DeltaBundler<JsOutput>, deltaBundler: DeltaBundler<>,
options: BuildGraphOptions, options: BuildGraphOptions,
): Promise<TransformFn<JsOutput>> { ): Promise<TransformFn<>> {
const {inlineRequires, ...transformerOptions} = await calcTransformerOptions( const {inlineRequires, ...transformerOptions} = await calcTransformerOptions(
entryFiles, entryFiles,
bundler, bundler,

View File

@ -14,10 +14,8 @@ import type {
PostMinifyProcess, PostMinifyProcess,
PostProcessBundleSourcemap, PostProcessBundleSourcemap,
} from '../Bundler'; } from '../Bundler';
import type { import type {TransformResult} from '../DeltaBundler';
CustomTransformOptions, import type {CustomTransformOptions} from '../JSTransformer/worker';
TransformedCode,
} from '../JSTransformer/worker';
import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from '../lib/reporting';
import type {CacheStore} from 'metro-cache'; import type {CacheStore} from 'metro-cache';
@ -80,7 +78,7 @@ export type Options = {|
+asyncRequireModulePath: string, +asyncRequireModulePath: string,
+assetRegistryPath: string, +assetRegistryPath: string,
blacklistRE?: RegExp, blacklistRE?: RegExp,
cacheStores: $ReadOnlyArray<CacheStore<TransformedCode>>, cacheStores: $ReadOnlyArray<CacheStore<TransformResult<>>>,
cacheVersion: string, cacheVersion: string,
createModuleIdFactory?: () => (path: string) => number, createModuleIdFactory?: () => (path: string) => number,
+dynamicDepsInPackages: DynamicRequiresBehavior, +dynamicDepsInPackages: DynamicRequiresBehavior,