From 35c5abf3eef35d0835cf4a7d3f0718c129dc9e29 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Fri, 11 May 2018 15:05:34 -0700 Subject: [PATCH] Make transformer result flow types generic all over the place Reviewed By: jeanlauliac Differential Revision: D7895095 fbshipit-source-id: df47f4b3e7a08e194fa1a2f874be87ead64ac198 --- packages/metro-cache/src/stores/FileStore.js | 8 ++---- packages/metro-cache/src/stores/HttpStore.js | 8 ++---- packages/metro/src/Bundler.js | 12 +++----- packages/metro/src/Config.js | 4 +-- packages/metro/src/DeltaBundler.js | 10 +++++-- .../DeltaBundler/Serializers/deltaJSBundle.js | 7 ++--- .../DeltaBundler/Serializers/getAllFiles.js | 5 ++-- .../src/DeltaBundler/Serializers/getAssets.js | 3 +- .../Serializers/getRamBundleInfo.js | 5 ++-- .../DeltaBundler/Serializers/helpers/js.js | 17 ++++++----- .../DeltaBundler/Serializers/hmrJSBundle.js | 11 ++++---- .../DeltaBundler/Serializers/plainJSBundle.js | 5 ++-- .../Serializers/sourceMapObject.js | 5 ++-- .../Serializers/sourceMapString.js | 5 ++-- packages/metro/src/DeltaBundler/types.flow.js | 19 +++++++++---- packages/metro/src/HmrServer.js | 4 +-- packages/metro/src/JSTransformer.js | 5 ++-- packages/metro/src/JSTransformer/worker.js | 28 +++++++++---------- packages/metro/src/Server.js | 24 +++++++--------- packages/metro/src/index.js | 4 +-- packages/metro/src/lib/getAppendScripts.js | 5 ++-- packages/metro/src/lib/getPrependedScripts.js | 8 +++--- packages/metro/src/lib/transformHelpers.js | 8 +++--- packages/metro/src/shared/types.flow.js | 8 ++---- 24 files changed, 105 insertions(+), 113 deletions(-) diff --git a/packages/metro-cache/src/stores/FileStore.js b/packages/metro-cache/src/stores/FileStore.js index 89b4763d..2b2e5714 100644 --- a/packages/metro-cache/src/stores/FileStore.js +++ b/packages/metro-cache/src/stores/FileStore.js @@ -15,13 +15,11 @@ const mkdirp = require('mkdirp'); const path = require('path'); const rimraf = require('rimraf'); -import type {TransformedCode} from 'metro/src/JSTransformer/worker'; - export type Options = {| root: string, |}; -class FileStore { +class FileStore { _root: string; constructor(options: Options) { @@ -29,7 +27,7 @@ class FileStore { this._createDirs(); } - get(key: Buffer): ?TransformedCode { + get(key: Buffer): ?T { try { return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf8')); } 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)); } diff --git a/packages/metro-cache/src/stores/HttpStore.js b/packages/metro-cache/src/stores/HttpStore.js index 052a566c..381b1cd4 100644 --- a/packages/metro-cache/src/stores/HttpStore.js +++ b/packages/metro-cache/src/stores/HttpStore.js @@ -15,8 +15,6 @@ const https = require('https'); const url = require('url'); const zlib = require('zlib'); -import type {TransformedCode} from 'metro/src/JSTransformer/worker'; - export type Options = {| endpoint: string, timeout?: number, @@ -26,7 +24,7 @@ const ZLIB_OPTIONS = { level: 9, }; -class HttpStore { +class HttpStore { _module: typeof http | typeof https; _timeout: number; @@ -63,7 +61,7 @@ class HttpStore { this._setAgent = new module.Agent(agentConfig); } - get(key: Buffer): Promise { + get(key: Buffer): Promise { return new Promise((resolve, reject) => { const options = { agent: this._getAgent, @@ -119,7 +117,7 @@ class HttpStore { }); } - set(key: Buffer, value: TransformedCode): Promise { + set(key: Buffer, value: T): Promise { return new Promise((resolve, reject) => { const gzip = zlib.createGzip(ZLIB_OPTIONS); diff --git a/packages/metro/src/Bundler.js b/packages/metro/src/Bundler.js index 705e953d..bbf0bfa9 100644 --- a/packages/metro/src/Bundler.js +++ b/packages/metro/src/Bundler.js @@ -22,11 +22,7 @@ const toLocalPath = require('./node-haste/lib/toLocalPath'); const {Cache, stableHash} = require('metro-cache'); import type {TransformResult} from './DeltaBundler'; -import type { - JsOutput, - WorkerOptions, - TransformedCode, -} from './JSTransformer/worker'; +import type {WorkerOptions} from './JSTransformer/worker'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; import type {Reporter} from './lib/reporting'; import type {BabelSourceMap} from '@babel/core'; @@ -72,7 +68,7 @@ export type Options = {| +assetRegistryPath: string, +asyncRequireModulePath: string, +blacklistRE?: RegExp, - +cacheStores: $ReadOnlyArray>, + +cacheStores: $ReadOnlyArray>>, +cacheVersion: string, +dynamicDepsInPackages: DynamicRequiresBehavior, +enableBabelRCLookup: boolean, @@ -100,7 +96,7 @@ const {hasOwnProperty} = Object.prototype; class Bundler { _opts: Options; - _cache: Cache; + _cache: Cache>; _baseHash: string; _transformer: Transformer; _depGraphPromise: Promise; @@ -218,7 +214,7 @@ class Bundler { async transformFile( filePath: string, transformCodeOptions: WorkerOptions, - ): Promise> { + ): Promise> { const cache = this._cache; const { diff --git a/packages/metro/src/Config.js b/packages/metro/src/Config.js index b86ca877..57819a34 100644 --- a/packages/metro/src/Config.js +++ b/packages/metro/src/Config.js @@ -21,7 +21,7 @@ import type { PostMinifyProcess, PostProcessBundleSourcemap, } from './Bundler'; -import type {TransformedCode} from './JSTransformer/worker'; +import type {TransformResult} from './DeltaBundler'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; import type {IncomingMessage, ServerResponse} from 'http'; import type {CacheStore} from 'metro-cache'; @@ -38,7 +38,7 @@ export type ConfigT = { /** * List of all store caches. */ - cacheStores: Array>, + cacheStores: Array>>, /** * Can be used to generate a key that will invalidate the whole metro cache diff --git a/packages/metro/src/DeltaBundler.js b/packages/metro/src/DeltaBundler.js index a0a6c0aa..1e232844 100644 --- a/packages/metro/src/DeltaBundler.js +++ b/packages/metro/src/DeltaBundler.js @@ -13,7 +13,13 @@ const DeltaCalculator = require('./DeltaBundler/DeltaCalculator'); 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 { DeltaResult, @@ -29,7 +35,7 @@ export type { * concurrent clients requesting their own deltas. This is done through the * `clientId` param (which maps a client to a specific delta transformer). */ -class DeltaBundler { +class DeltaBundler { _bundler: Bundler; _deltaCalculators: Map, DeltaCalculator> = new Map(); diff --git a/packages/metro/src/DeltaBundler/Serializers/deltaJSBundle.js b/packages/metro/src/DeltaBundler/Serializers/deltaJSBundle.js index 3b0d0cbc..642c14eb 100644 --- a/packages/metro/src/DeltaBundler/Serializers/deltaJSBundle.js +++ b/packages/metro/src/DeltaBundler/Serializers/deltaJSBundle.js @@ -15,7 +15,6 @@ const getAppendScripts = require('../../lib/getAppendScripts'); const {wrapModule} = require('./helpers/js'); const {getJsOutput, isJsModule} = require('./helpers/js'); -import type {JsOutput} from '../../JSTransformer/worker'; import type {DeltaResult, Graph, Module} from '../types.flow'; type Options = {| @@ -29,10 +28,10 @@ type Options = {| function deltaJSBundle( entryPoint: string, - pre: $ReadOnlyArray>, - delta: DeltaResult, + pre: $ReadOnlyArray>, + delta: DeltaResult<>, sequenceId: string, - graph: Graph, + graph: Graph<>, options: Options, ): string { const outputPre = []; diff --git a/packages/metro/src/DeltaBundler/Serializers/getAllFiles.js b/packages/metro/src/DeltaBundler/Serializers/getAllFiles.js index 7f45a267..f68c85c5 100644 --- a/packages/metro/src/DeltaBundler/Serializers/getAllFiles.js +++ b/packages/metro/src/DeltaBundler/Serializers/getAllFiles.js @@ -13,7 +13,6 @@ const {getAssetFiles} = require('../../Assets'); const {getJsOutput, isJsModule} = require('./helpers/js'); -import type {JsOutput} from '../../JSTransformer/worker'; import type {Graph, Module} from '../types.flow'; type Options = {| @@ -21,8 +20,8 @@ type Options = {| |}; async function getAllFiles( - pre: $ReadOnlyArray>, - graph: Graph, + pre: $ReadOnlyArray>, + graph: Graph<>, options: Options, ): Promise<$ReadOnlyArray> { const modules = graph.dependencies; diff --git a/packages/metro/src/DeltaBundler/Serializers/getAssets.js b/packages/metro/src/DeltaBundler/Serializers/getAssets.js index fd3a70a2..3a3364ec 100644 --- a/packages/metro/src/DeltaBundler/Serializers/getAssets.js +++ b/packages/metro/src/DeltaBundler/Serializers/getAssets.js @@ -16,7 +16,6 @@ const {getAssetData} = require('../../Assets'); const {getJsOutput, isJsModule} = require('./helpers/js'); import type {AssetData} from '../../Assets'; -import type {JsOutput} from '../../JSTransformer/worker'; import type {Graph} from '../types.flow'; type Options = {| @@ -26,7 +25,7 @@ type Options = {| |}; async function getAssets( - graph: Graph, + graph: Graph<>, options: Options, ): Promise<$ReadOnlyArray> { const promises = []; diff --git a/packages/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js b/packages/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js index 1e786052..91f1cbf5 100644 --- a/packages/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js +++ b/packages/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js @@ -20,7 +20,6 @@ const {createRamBundleGroups} = require('../../Bundler/util'); const {isJsModule, wrapModule} = require('./helpers/js'); import type {GetTransformOptions} from '../../Bundler'; -import type {JsOutput} from '../../JSTransformer/worker'; import type {ModuleTransportLike} from '../../shared/types.flow'; import type {Graph, Module} from '../types.flow'; @@ -45,8 +44,8 @@ export type RamBundleInfo = {| async function getRamBundleInfo( entryPoint: string, - pre: $ReadOnlyArray>, - graph: Graph, + pre: $ReadOnlyArray>, + graph: Graph<>, options: Options, ): Promise { const modules = [ diff --git a/packages/metro/src/DeltaBundler/Serializers/helpers/js.js b/packages/metro/src/DeltaBundler/Serializers/helpers/js.js index b5500c7c..11a31cd3 100644 --- a/packages/metro/src/DeltaBundler/Serializers/helpers/js.js +++ b/packages/metro/src/DeltaBundler/Serializers/helpers/js.js @@ -15,7 +15,7 @@ const invariant = require('fbjs/lib/invariant'); const path = require('path'); import type {JsOutput} from '../../../JSTransformer/worker'; -import type {Module} from '../../types.flow'; +import type {MixedOutput, Module} from '../../types.flow'; export type Options = { +createModuleId: string => number | string, @@ -27,8 +27,9 @@ export type Options = { // Make sure to set PRINT_REQUIRE_PATHS = true too, and restart Metro const PASS_MODULE_PATHS_TO_DEFINE = false; -function wrapModule(module: Module, options: Options) { +function wrapModule(module: Module<>, options: Options) { const output = getJsOutput(module); + if (output.type.startsWith('js/script')) { return output.data.code; } @@ -55,7 +56,7 @@ function wrapModule(module: Module, options: Options) { return addParamsToDefineCall(output.data.code, ...params); } -function getJsOutput(module: Module) { +function getJsOutput(module: Module<>): JsOutput { const jsModules = module.output.filter(({type}) => type.startsWith('js/')); invariant( @@ -65,13 +66,15 @@ function getJsOutput(module: Module) { } JS outputs.`, ); - return jsModules[0]; + return (jsModules[0]: any); } -function isJsModule(module: Module) { - const jsModules = module.output.filter(({type}) => type.startsWith('js/')); +function isJsModule(module: Module<>): boolean { + return module.output.filter(isJsOutput).length > 0; +} - return jsModules.length > 0; +function isJsOutput(output: MixedOutput): boolean %checks { + return output.type.startsWith('js/'); } module.exports = { diff --git a/packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js b/packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js index 2641bda4..accede19 100644 --- a/packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js +++ b/packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js @@ -14,7 +14,6 @@ const addParamsToDefineCall = require('../../lib/addParamsToDefineCall'); const {isJsModule, wrapModule} = require('./helpers/js'); -import type {JsOutput} from '../../JSTransformer/worker'; import type {DeltaResult, Graph, Module} from '../types.flow'; type Options = { @@ -31,8 +30,8 @@ export type Result = { }; function hmrJSBundle( - delta: DeltaResult, - graph: Graph, + delta: DeltaResult<>, + graph: Graph<>, options: Options, ): Result { const modules = []; @@ -54,8 +53,8 @@ function hmrJSBundle( } function _prepareModule( - module: Module, - graph: Graph, + module: Module<>, + graph: Graph<>, options: Options, ): {|+id: number, +code: string|} { const code = wrapModule(module, { @@ -87,7 +86,7 @@ function _prepareModule( */ function _getInverseDependencies( path: string, - graph: Graph, + graph: Graph<>, inverseDependencies: {[key: string]: Array} = {}, ): {[key: string]: Array} { // Dependency alredy traversed. diff --git a/packages/metro/src/DeltaBundler/Serializers/plainJSBundle.js b/packages/metro/src/DeltaBundler/Serializers/plainJSBundle.js index 496ccdb4..5eb35170 100644 --- a/packages/metro/src/DeltaBundler/Serializers/plainJSBundle.js +++ b/packages/metro/src/DeltaBundler/Serializers/plainJSBundle.js @@ -14,7 +14,6 @@ const getAppendScripts = require('../../lib/getAppendScripts'); const {isJsModule, wrapModule} = require('./helpers/js'); -import type {JsOutput} from '../../JSTransformer/worker'; import type {Graph, Module} from '../types.flow'; type Options = {| @@ -28,8 +27,8 @@ type Options = {| function plainJSBundle( entryPoint: string, - pre: $ReadOnlyArray>, - graph: Graph, + pre: $ReadOnlyArray>, + graph: Graph<>, options: Options, ): string { for (const module of graph.dependencies.values()) { diff --git a/packages/metro/src/DeltaBundler/Serializers/sourceMapObject.js b/packages/metro/src/DeltaBundler/Serializers/sourceMapObject.js index 1048b703..156285bb 100644 --- a/packages/metro/src/DeltaBundler/Serializers/sourceMapObject.js +++ b/packages/metro/src/DeltaBundler/Serializers/sourceMapObject.js @@ -13,13 +13,12 @@ const {isJsModule, getJsOutput} = require('./helpers/js'); const {fromRawMappings} = require('metro-source-map'); -import type {JsOutput} from '../../JSTransformer/worker'; import type {Graph, Module} from '../types.flow'; import type {BabelSourceMap} from '@babel/core'; function fullSourceMapObject( - pre: $ReadOnlyArray>, - graph: Graph, + pre: $ReadOnlyArray>, + graph: Graph<>, options: {|+excludeSource: boolean|}, ): BabelSourceMap { const modules = [...pre, ...graph.dependencies.values()] diff --git a/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js b/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js index d32c5d18..e03d2c49 100644 --- a/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js +++ b/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js @@ -13,12 +13,11 @@ const {isJsModule, getJsOutput} = require('./helpers/js'); const {fromRawMappings} = require('metro-source-map'); -import type {JsOutput} from '../../JSTransformer/worker'; import type {Graph, Module} from '../types.flow'; function fullSourceMap( - pre: $ReadOnlyArray>, - graph: Graph, + pre: $ReadOnlyArray>, + graph: Graph<>, options: {|+excludeSource: boolean|}, ): string { const modules = [...pre, ...graph.dependencies.values()] diff --git a/packages/metro/src/DeltaBundler/types.flow.js b/packages/metro/src/DeltaBundler/types.flow.js index 42b0afc5..cc86e820 100644 --- a/packages/metro/src/DeltaBundler/types.flow.js +++ b/packages/metro/src/DeltaBundler/types.flow.js @@ -12,12 +12,17 @@ import type {TransformResultDependency} from '../ModuleGraph/types.flow'; +export type MixedOutput = {| + +data: mixed, + +type: string, +|}; + export type Dependency = {| +absolutePath: string, +data: TransformResultDependency, |}; -export type Module = {| +export type Module = {| dependencies: Map, inverseDependencies: Set, output: $ReadOnlyArray, @@ -25,26 +30,28 @@ export type Module = {| getSource: () => string, |}; -export type Graph = {| +export type Graph = {| dependencies: Map>, entryPoints: $ReadOnlyArray, |}; -export type TransformResult = {| +export type TransformResult = {| dependencies: $ReadOnlyArray, output: $ReadOnlyArray, +getSource: () => string, |}; -export type TransformFn = string => Promise>; +export type TransformFn = string => Promise< + TransformResult, +>; -export type Options = {| +export type Options = {| resolve: (from: string, to: string) => string, transform: TransformFn, onProgress: ?(numProcessed: number, total: number) => mixed, |}; -export type DeltaResult = {| +export type DeltaResult = {| +modified: Map>, +deleted: Set, +reset: boolean, diff --git a/packages/metro/src/HmrServer.js b/packages/metro/src/HmrServer.js index fd3d8f34..0436ec10 100644 --- a/packages/metro/src/HmrServer.js +++ b/packages/metro/src/HmrServer.js @@ -21,11 +21,11 @@ const { Logger: {createActionStartEntry, createActionEndEntry, log}, } = require('metro-core'); -import type PackagerServer, {JsGraph} from './Server'; +import type PackagerServer, {OutputGraph} from './Server'; import type {Reporter} from './lib/reporting'; type Client = {| - graph: JsGraph, + graph: OutputGraph, sendFn: (data: string) => mixed, |}; diff --git a/packages/metro/src/JSTransformer.js b/packages/metro/src/JSTransformer.js index 0557b2f1..cfbe774c 100644 --- a/packages/metro/src/JSTransformer.js +++ b/packages/metro/src/JSTransformer.js @@ -16,7 +16,8 @@ const {Logger} = require('metro-core'); const debug = require('debug')('Metro:JStransformer'); 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 {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; @@ -32,7 +33,7 @@ type Reporters = { }; type TransformerResult = { - result: TransformedCode, + result: TransformResult<>, sha1: string, }; diff --git a/packages/metro/src/JSTransformer/worker.js b/packages/metro/src/JSTransformer/worker.js index 49f44359..59c2342f 100644 --- a/packages/metro/src/JSTransformer/worker.js +++ b/packages/metro/src/JSTransformer/worker.js @@ -84,26 +84,24 @@ export type WorkerOptions = {| +projectRoot: string, |}; -export type Data = { - result: TransformedCode, +export type JsOutput = {| + +data: {| + +code: string, + +map: Array, + |}, + +type: string, +|}; + +type Data = { + result: {| + output: $ReadOnlyArray, + dependencies: $ReadOnlyArray, + |}, sha1: string, transformFileStartLogEntry: LogEntry, transformFileEndLogEntry: LogEntry, }; -export type JsOutput = {| - data: { - +code: string, - +map: Array, - }, - type: string, -|}; - -export type TransformedCode = {| - output: $ReadOnlyArray, - dependencies: $ReadOnlyArray, -|}; - function getDynamicDepsBehavior( inPackages: DynamicRequiresBehavior, filename: string, diff --git a/packages/metro/src/Server.js b/packages/metro/src/Server.js index 7f1f9e43..cd404af4 100644 --- a/packages/metro/src/Server.js +++ b/packages/metro/src/Server.js @@ -42,7 +42,7 @@ const {getAsset} = require('./Assets'); const resolveSync: ResolveSync = require('resolve').sync; 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 {Reporter} from './lib/reporting'; 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 {Symbolicate} from './Server/symbolicate/symbolicate'; import type {AssetData} from './Assets'; -import type { - CustomTransformOptions, - JsOutput, - TransformedCode, -} from './JSTransformer/worker'; +import type {CustomTransformOptions} from './JSTransformer/worker'; const { Logger: {createActionStartEntry, createActionEndEntry, log}, @@ -70,8 +66,8 @@ const { type ResolveSync = (path: string, opts: ?{baseDir?: string}) => string; type GraphInfo = {| - graph: Graph, - prepend: $ReadOnlyArray>, + graph: Graph<>, + prepend: $ReadOnlyArray>, lastModified: Date, +sequenceId: string, |}; @@ -87,7 +83,7 @@ export type BuildGraphOptions = {| +type: 'module' | 'script', |}; -export type JsGraph = Graph; +export type OutputGraph = Graph<>; type DeltaOptions = BundleOptions & { deltaBundleId: ?string, @@ -108,7 +104,7 @@ class Server { _opts: { assetExts: Array, blacklistRE: void | RegExp, - cacheStores: $ReadOnlyArray>, + cacheStores: $ReadOnlyArray>>, cacheVersion: string, createModuleId: (path: string) => number, enableBabelRCLookup: boolean, @@ -145,7 +141,7 @@ class Server { _symbolicateInWorker: Symbolicate; _platforms: Set; _nextBundleBuildID: number; - _deltaBundler: DeltaBundler; + _deltaBundler: DeltaBundler<>; _graphs: Map> = new Map(); _deltaGraphs: Map> = new Map(); @@ -258,7 +254,7 @@ class Server { this._bundler.end(); } - getDeltaBundler(): DeltaBundler { + getDeltaBundler(): DeltaBundler<> { return this._deltaBundler; } @@ -288,7 +284,7 @@ class Server { async buildGraph( entryFiles: $ReadOnlyArray, options: BuildGraphOptions, - ): Promise { + ): Promise { entryFiles = entryFiles.map(entryFile => getAbsolutePath(entryFile, this._opts.projectRoots), ); @@ -447,7 +443,7 @@ class Server { async _getDeltaInfo( options: DeltaOptions, - ): Promise<{...GraphInfo, delta: DeltaResult}> { + ): Promise<{...GraphInfo, delta: DeltaResult<>}> { const id = this._optionsHash(options); let graphPromise = this._deltaGraphs.get(id); let graphInfo; diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index 51384e70..d43c1ef1 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -31,7 +31,7 @@ const {readFile} = require('fs-extra'); const {Terminal} = require('metro-core'); import type {ConfigT} from './Config'; -import type {JsGraph} from './Server'; +import type {Graph} from './DeltaBundler'; import type {Reporter} from './lib/reporting'; import type {RequestOptions, OutputOptions} from './shared/types.flow.js'; import type {Options as ServerOptions} from './shared/types.flow'; @@ -381,7 +381,7 @@ exports.buildGraph = async function({ platform = `web`, type = 'module', ...rest -}: BuildGraphOptions): Promise { +}: BuildGraphOptions): Promise> { const metroServer = await runMetro({ ...rest, config, diff --git a/packages/metro/src/lib/getAppendScripts.js b/packages/metro/src/lib/getAppendScripts.js index 3b580801..b8a66642 100644 --- a/packages/metro/src/lib/getAppendScripts.js +++ b/packages/metro/src/lib/getAppendScripts.js @@ -11,7 +11,6 @@ 'use strict'; import type {Graph, Module} from '../DeltaBundler'; -import type {JsOutput} from '../JSTransformer/worker'; type Options = { +createModuleId: string => T, @@ -23,9 +22,9 @@ type Options = { function getAppendScripts( entryPoint: string, - graph: Graph, + graph: Graph<>, options: Options, -): $ReadOnlyArray> { +): $ReadOnlyArray> { const output = []; if (options.runModule) { diff --git a/packages/metro/src/lib/getPrependedScripts.js b/packages/metro/src/lib/getPrependedScripts.js index 7a8432e9..80b09b26 100644 --- a/packages/metro/src/lib/getPrependedScripts.js +++ b/packages/metro/src/lib/getPrependedScripts.js @@ -16,7 +16,7 @@ const transformHelpers = require('./transformHelpers'); import type Bundler from '../Bundler'; import type DeltaBundler, {Module} from '../DeltaBundler'; -import type {CustomTransformOptions, JsOutput} from '../JSTransformer/worker'; +import type {CustomTransformOptions} from '../JSTransformer/worker'; type Options = { getPolyfills: ({platform: ?string}) => $ReadOnlyArray, @@ -35,8 +35,8 @@ async function getPrependedScripts( options: Options, bundleOptions: BundleOptions, bundler: Bundler, - deltaBundler: DeltaBundler, -): Promise>> { + deltaBundler: DeltaBundler<>, +): Promise<$ReadOnlyArray>> { // Get all the polyfills from the relevant option params (the // `getPolyfills()` method and the `polyfillModuleNames` variable). const polyfillModuleNames = options @@ -79,7 +79,7 @@ async function getPrependedScripts( ]; } -function _getPrelude({dev}: {dev: boolean}): Module { +function _getPrelude({dev}: {dev: boolean}): Module<> { const code = getPreludeCode({isDev: dev}); const name = '__prelude__'; diff --git a/packages/metro/src/lib/transformHelpers.js b/packages/metro/src/lib/transformHelpers.js index 04bebe11..9c8c760c 100644 --- a/packages/metro/src/lib/transformHelpers.js +++ b/packages/metro/src/lib/transformHelpers.js @@ -12,7 +12,7 @@ import type Bundler from '../Bundler'; import type DeltaBundler, {TransformFn} from '../DeltaBundler'; -import type {JsOutput, WorkerOptions} from '../JSTransformer/worker'; +import type {WorkerOptions} from '../JSTransformer/worker'; import type {BuildGraphOptions} from '../Server'; type InlineRequiresRaw = {+blacklist: {[string]: true}} | boolean; @@ -20,7 +20,7 @@ type InlineRequiresRaw = {+blacklist: {[string]: true}} | boolean; async function calcTransformerOptions( entryFiles: $ReadOnlyArray, bundler: Bundler, - deltaBundler: DeltaBundler, + deltaBundler: DeltaBundler<>, options: BuildGraphOptions, ): Promise<{...WorkerOptions, inlineRequires: InlineRequiresRaw}> { const { @@ -85,9 +85,9 @@ function removeInlineRequiresBlacklistFromOptions( async function getTransformFn( entryFiles: $ReadOnlyArray, bundler: Bundler, - deltaBundler: DeltaBundler, + deltaBundler: DeltaBundler<>, options: BuildGraphOptions, -): Promise> { +): Promise> { const {inlineRequires, ...transformerOptions} = await calcTransformerOptions( entryFiles, bundler, diff --git a/packages/metro/src/shared/types.flow.js b/packages/metro/src/shared/types.flow.js index 7e4081f3..a2294463 100644 --- a/packages/metro/src/shared/types.flow.js +++ b/packages/metro/src/shared/types.flow.js @@ -14,10 +14,8 @@ import type { PostMinifyProcess, PostProcessBundleSourcemap, } from '../Bundler'; -import type { - CustomTransformOptions, - TransformedCode, -} from '../JSTransformer/worker'; +import type {TransformResult} from '../DeltaBundler'; +import type {CustomTransformOptions} from '../JSTransformer/worker'; import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies'; import type {Reporter} from '../lib/reporting'; import type {CacheStore} from 'metro-cache'; @@ -80,7 +78,7 @@ export type Options = {| +asyncRequireModulePath: string, +assetRegistryPath: string, blacklistRE?: RegExp, - cacheStores: $ReadOnlyArray>, + cacheStores: $ReadOnlyArray>>, cacheVersion: string, createModuleIdFactory?: () => (path: string) => number, +dynamicDepsInPackages: DynamicRequiresBehavior,