From efceeacd77674ec88bc45be9413d777f0dd61d3c Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Wed, 22 Nov 2017 03:36:57 -0800 Subject: [PATCH] Move Option types from Server to shared/types.flow Reviewed By: davidaurelio Differential Revision: D6384292 fbshipit-source-id: 58cba889f549cbd7a8c82856d5283048f4f2a8c5 --- .../src/DeltaBundler/DeltaCalculator.js | 2 +- .../src/DeltaBundler/Serializers.js | 2 +- .../metro-bundler/src/DeltaBundler/index.js | 2 +- packages/metro-bundler/src/Server/index.js | 53 +--------------- packages/metro-bundler/src/index.js | 2 +- packages/metro-bundler/src/legacy.js | 3 +- .../metro-bundler/src/lib/TerminalReporter.js | 2 +- packages/metro-bundler/src/lib/reporting.js | 2 +- .../metro-bundler/src/shared/types.flow.js | 61 +++++++++++++++++++ 9 files changed, 70 insertions(+), 59 deletions(-) diff --git a/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js b/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js index 74692b48..08e03ab0 100644 --- a/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js @@ -20,9 +20,9 @@ const {EventEmitter} = require('events'); import type Bundler from '../Bundler'; import type {Options as JSTransformerOptions} from '../JSTransformer/worker'; -import type {BundleOptions} from '../Server'; import type DependencyGraph from '../node-haste/DependencyGraph'; import type Module from '../node-haste/Module'; +import type {BundleOptions} from '../shared/types.flow'; export type DeltaResult = {| +modified: Map, diff --git a/packages/metro-bundler/src/DeltaBundler/Serializers.js b/packages/metro-bundler/src/DeltaBundler/Serializers.js index 4d711ecf..7d476dfe 100644 --- a/packages/metro-bundler/src/DeltaBundler/Serializers.js +++ b/packages/metro-bundler/src/DeltaBundler/Serializers.js @@ -18,8 +18,8 @@ const {fromRawMappings} = require('../Bundler/source-map'); const {createRamBundleGroups} = require('../Bundler/util'); import type {AssetData} from '../AssetServer'; -import type {BundleOptions} from '../Server'; import type {MappingsMap} from '../lib/SourceMap'; +import type {BundleOptions} from '../shared/types.flow'; import type {ModuleTransportLike} from '../shared/types.flow'; import type DeltaBundler, {Options as BuildOptions} from './'; import type DeltaTransformer, { diff --git a/packages/metro-bundler/src/DeltaBundler/index.js b/packages/metro-bundler/src/DeltaBundler/index.js index 462bf024..9abee34d 100644 --- a/packages/metro-bundler/src/DeltaBundler/index.js +++ b/packages/metro-bundler/src/DeltaBundler/index.js @@ -15,7 +15,7 @@ const DeltaTransformer = require('./DeltaTransformer'); import type Bundler from '../Bundler'; -import type {BundleOptions} from '../Server'; +import type {BundleOptions} from '../shared/types.flow'; import type {DeltaEntry} from './DeltaTransformer'; export type PostProcessModules = ( diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index e42cec8a..c7d886b5 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -33,13 +33,13 @@ import type {HasteImpl} from '../node-haste/Module'; import type {IncomingMessage, ServerResponse} from 'http'; import type {Reporter} from '../lib/reporting'; import type {Options as DeltaBundlerOptions} from '../DeltaBundler/Serializers'; +import type {BundleOptions, Options} from '../shared/types.flow'; import type { GetTransformOptions, PostMinifyProcess, PostProcessBundleSourcemap, } from '../Bundler'; import type {TransformCache} from '../lib/TransformCaching'; -import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {SourceMap, Symbolicate} from './symbolicate'; import type {AssetData} from '../AssetServer'; import type {RamBundleInfo} from '../DeltaBundler/Serializers'; @@ -64,57 +64,6 @@ function debounceAndBatch(fn, delay) { }; } -export type Options = {| - assetExts?: Array, - +assetRegistryPath: string, - blacklistRE?: RegExp, - cacheVersion?: string, - enableBabelRCLookup?: boolean, - extraNodeModules?: {}, - getPolyfills: ({platform: ?string}) => $ReadOnlyArray, - getTransformOptions?: GetTransformOptions, - globalTransformCache: ?GlobalTransformCache, - hasteImpl?: HasteImpl, - maxWorkers?: number, - moduleFormat?: string, - platforms?: Array, - polyfillModuleNames?: Array, - postProcessModules?: PostProcessModules, - postMinifyProcess: PostMinifyProcess, - postProcessBundleSourcemap: PostProcessBundleSourcemap, - projectRoots: $ReadOnlyArray, - providesModuleNodeModules?: Array, - reporter?: Reporter, - resetCache?: boolean, - +getModulesRunBeforeMainModule: (entryPoint: string) => Array, - silent?: boolean, - +sourceExts: ?Array, - +transformCache: TransformCache, - transformModulePath?: string, - watch?: boolean, - workerPath: ?string, -|}; - -export type BundleOptions = { - +assetPlugins: Array, - dev: boolean, - entryFile: string, - +entryModuleOnly: boolean, - +excludeSource: boolean, - +generateSourceMaps: boolean, - +hot: boolean, - +inlineSourceMap: boolean, - +isolateModuleIDs: boolean, - minify: boolean, - onProgress: ?(doneCont: number, totalCount: number) => mixed, - +platform: ?string, - +resolutionResponse: ?{}, - +runBeforeMainModule: Array, - +runModule: boolean, - sourceMapUrl: ?string, - unbundle: boolean, -}; - const FILES_CHANGED_COUNT_HEADER = 'X-Metro-Files-Changed-Count'; class Server { diff --git a/packages/metro-bundler/src/index.js b/packages/metro-bundler/src/index.js index ae11ee5a..4d6bc54e 100644 --- a/packages/metro-bundler/src/index.js +++ b/packages/metro-bundler/src/index.js @@ -40,7 +40,7 @@ import type {Server as HttpServer} from 'http'; import type {Server as HttpsServer} from 'https'; import type {ConfigT} from './Config'; -import type {Options as ServerOptions} from './Server'; +import type {Options as ServerOptions} from './shared/types.flow'; import type {RequestOptions, OutputOptions} from './shared/types.flow.js'; export type {ConfigT} from './Config'; diff --git a/packages/metro-bundler/src/legacy.js b/packages/metro-bundler/src/legacy.js index 9487f1eb..7d8b6df3 100644 --- a/packages/metro-bundler/src/legacy.js +++ b/packages/metro-bundler/src/legacy.js @@ -23,8 +23,9 @@ const invariant = require('fbjs/lib/invariant'); const {fromRawMappings, compactMapping} = require('./Bundler/source-map'); import type {ConfigT as MetroConfig} from './Config'; -import type Server, {Options as ServerOptions} from './Server'; +import type Server from './Server'; import type {TransformCache} from './lib/TransformCaching'; +import type {Options as ServerOptions} from './shared/types.flow'; exports.createBlacklist = blacklist; exports.sourceMaps = {fromRawMappings, compactMapping}; diff --git a/packages/metro-bundler/src/lib/TerminalReporter.js b/packages/metro-bundler/src/lib/TerminalReporter.js index b738e679..b86ef38a 100644 --- a/packages/metro-bundler/src/lib/TerminalReporter.js +++ b/packages/metro-bundler/src/lib/TerminalReporter.js @@ -23,7 +23,7 @@ const { AmbiguousModuleResolutionError, } = require('../node-haste/DependencyGraph/ResolutionRequest'); -import type {BundleOptions} from '../Server'; +import type {BundleOptions} from '../shared/types.flow'; import type Terminal from './Terminal'; import type {ReportableEvent, GlobalCacheDisabledReason} from './reporting'; diff --git a/packages/metro-bundler/src/lib/reporting.js b/packages/metro-bundler/src/lib/reporting.js index 2d1dc63e..eef89521 100644 --- a/packages/metro-bundler/src/lib/reporting.js +++ b/packages/metro-bundler/src/lib/reporting.js @@ -15,7 +15,7 @@ const chalk = require('chalk'); const util = require('util'); -import type {BundleOptions} from '../Server'; +import type {BundleOptions} from '../shared/types.flow'; import type Terminal from './Terminal'; export type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses'; diff --git a/packages/metro-bundler/src/shared/types.flow.js b/packages/metro-bundler/src/shared/types.flow.js index e1d27e67..9719c76a 100644 --- a/packages/metro-bundler/src/shared/types.flow.js +++ b/packages/metro-bundler/src/shared/types.flow.js @@ -12,10 +12,40 @@ 'use strict'; import type {RawMapping} from '../Bundler/source-map'; +import type { + GetTransformOptions, + PostMinifyProcess, + PostProcessBundleSourcemap, +} from '../Bundler'; +import type {PostProcessModules} from '../DeltaBundler'; +import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {SourceMap} from '../lib/SourceMap'; +import type {TransformCache} from '../lib/TransformCaching'; +import type {Reporter} from '../lib/reporting'; +import type {HasteImpl} from '../node-haste/Module'; type SourceMapOrMappings = SourceMap | Array; +export type BundleOptions = { + +assetPlugins: Array, + dev: boolean, + entryFile: string, + +entryModuleOnly: boolean, + +excludeSource: boolean, + +generateSourceMaps: boolean, + +hot: boolean, + +inlineSourceMap: boolean, + +isolateModuleIDs: boolean, + minify: boolean, + onProgress: ?(doneCont: number, totalCount: number) => mixed, + +platform: ?string, + +resolutionResponse: ?{}, + +runBeforeMainModule: Array, + +runModule: boolean, + sourceMapUrl: ?string, + unbundle: boolean, +}; + export type ModuleGroups = {| groups: Map>, modulesById: Map, @@ -30,6 +60,37 @@ export type ModuleTransportLike = { +sourcePath: string, }; +export type Options = {| + assetExts?: Array, + +assetRegistryPath: string, + blacklistRE?: RegExp, + cacheVersion?: string, + enableBabelRCLookup?: boolean, + extraNodeModules?: {}, + getPolyfills: ({platform: ?string}) => $ReadOnlyArray, + getTransformOptions?: GetTransformOptions, + globalTransformCache: ?GlobalTransformCache, + hasteImpl?: HasteImpl, + maxWorkers?: number, + moduleFormat?: string, + platforms?: Array, + polyfillModuleNames?: Array, + postProcessModules?: PostProcessModules, + postMinifyProcess: PostMinifyProcess, + postProcessBundleSourcemap: PostProcessBundleSourcemap, + projectRoots: $ReadOnlyArray, + providesModuleNodeModules?: Array, + reporter?: Reporter, + resetCache?: boolean, + +getModulesRunBeforeMainModule: (entryPoint: string) => Array, + silent?: boolean, + +sourceExts: ?Array, + +transformCache: TransformCache, + transformModulePath?: string, + watch?: boolean, + workerPath: ?string, +|}; + export type OutputOptions = { bundleOutput: string, bundleEncoding?: 'utf8' | 'utf16le' | 'ascii',