diff --git a/packages/metro-bundler/src/Bundler/index.js b/packages/metro-bundler/src/Bundler/index.js index 90d19952..a3c22002 100644 --- a/packages/metro-bundler/src/Bundler/index.js +++ b/packages/metro-bundler/src/Bundler/index.js @@ -251,12 +251,9 @@ class Bundler { return this._assetServer; } - end() { + async end() { this._transformer.kill(); - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ - return this._resolverPromise.then(resolver => + await this._resolverPromise.then(resolver => resolver .getDependencyGraph() .getWatcher() @@ -353,7 +350,7 @@ class Bundler { }); } - _bundle({ + _bundle({ assetPlugins, bundle, dev, @@ -372,7 +369,7 @@ class Bundler { unbundle, }: { assetPlugins?: Array, - bundle: Bundle | HMRBundle, + bundle: T, dev: boolean, entryFile?: string, entryModuleOnly?: boolean, @@ -387,7 +384,7 @@ class Bundler { runBeforeMainModule?: Array, runModule?: boolean, unbundle?: boolean, - }) { + }): Promise { const onResolutionResponse = ( response: ResolutionResponse, ) => { @@ -463,7 +460,7 @@ class Bundler { }); } - _buildBundle({ + _buildBundle({ entryFile, dev, minify, @@ -479,7 +476,7 @@ class Bundler { onModuleTransformed = emptyFunction, finalizeBundle = emptyFunction, onProgress = emptyFunction, - }: *) { + }: *): Promise { const transformingFilesLogEntry = log( createActionStartEntry({ action_name: 'Transforming files', @@ -505,9 +502,6 @@ class Bundler { }); } - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ return Promise.all([ this._resolverPromise, resolutionResponse, @@ -683,10 +677,7 @@ class Bundler { +platform: string, +minify: boolean, +generateSourceMaps: boolean, - }) { - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ + }): Promise> { return this.getDependencies({ entryFile, rootEntryFile: entryFile, @@ -698,7 +689,8 @@ class Bundler { }).then(({dependencies}) => { const ret = []; const promises = []; - const placeHolder = {}; + /* $FlowFixMe: these are always removed */ + const placeHolder: string = {}; dependencies.forEach(dep => { if (dep.isAsset()) { const localPath = toLocalPath(this._projectRoots, dep.path); diff --git a/packages/metro-bundler/src/Bundler/util.js b/packages/metro-bundler/src/Bundler/util.js index 0328933a..b1039e17 100644 --- a/packages/metro-bundler/src/Bundler/util.js +++ b/packages/metro-bundler/src/Bundler/util.js @@ -256,11 +256,8 @@ function* filter(iterator, predicate) { } } -/* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.54 was deployed. To see the error delete this comment and - * run Flow. */ -class ArrayMap extends Map { - get(key) { +class ArrayMap extends Map> { + get(key: K): Array { let array = super.get(key); if (!array) { array = []; diff --git a/packages/metro-bundler/src/Config.js b/packages/metro-bundler/src/Config.js index 5dd94834..e5d6f29b 100644 --- a/packages/metro-bundler/src/Config.js +++ b/packages/metro-bundler/src/Config.js @@ -138,11 +138,8 @@ export type ConfigT = { runBeforeMainModule: Array, }; -/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.56 was deployed. To see the error delete this comment and - * run Flow. */ const DEFAULT = ({ - extraNodeModules: Object.create(null), + extraNodeModules: {}, getAssetExts: () => [], getBlacklistRE: () => blacklist(), getEnableBabelRCLookup: () => false, diff --git a/packages/metro-bundler/src/DeltaBundler/DeltaTransformer.js b/packages/metro-bundler/src/DeltaBundler/DeltaTransformer.js index f135302a..f3d55df5 100644 --- a/packages/metro-bundler/src/DeltaBundler/DeltaTransformer.js +++ b/packages/metro-bundler/src/DeltaBundler/DeltaTransformer.js @@ -50,7 +50,10 @@ export type DeltaTransformResponse = {| +pre: DeltaEntries, +post: DeltaEntries, +delta: DeltaEntries, - +inverseDependencies: {[key: string]: $ReadOnlyArray}, + +inverseDependencies: { + [key: string]: $ReadOnlyArray, + __proto__: null, + }, +reset: boolean, |}; @@ -317,7 +320,7 @@ class DeltaTransformer extends EventEmitter { */ _getInverseDependencies( dependencyEdges: DependencyEdges, - ): {[key: string]: $ReadOnlyArray} { + ): {[key: string]: $ReadOnlyArray, __proto__: null} { const output = Object.create(null); for (const [path, {inverseDependencies}] of dependencyEdges.entries()) { @@ -326,9 +329,6 @@ class DeltaTransformer extends EventEmitter { ).map(dep => this._getModuleId({path: dep})); } - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ return output; } diff --git a/packages/metro-bundler/src/JSTransformer/index.js b/packages/metro-bundler/src/JSTransformer/index.js index 8ea19988..00128764 100644 --- a/packages/metro-bundler/src/JSTransformer/index.js +++ b/packages/metro-bundler/src/JSTransformer/index.js @@ -21,7 +21,11 @@ const path = require('path'); const util = require('util'); const workerFarm = require('../worker-farm'); -import type {Data as TransformData, Options as WorkerOptions} from './worker'; +import type { + Data as TransformData, + Options as WorkerOptions, + TransformedCode, +} from './worker'; import type {LocalPath} from '../node-haste/lib/toLocalPath'; import type {MappingsMap} from '../lib/SourceMap'; import typeof { @@ -142,10 +146,7 @@ class Transformer { kill() { if (this._usesFarm && this._workers) { - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ - workerFarm.end(this._workers); + workerFarm.end(this._workers, () => {}); } } @@ -154,17 +155,12 @@ class Transformer { localPath: LocalPath, code: string, options: WorkerOptions, - ) { + ): Promise { if (!this._transform) { - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ return Promise.reject(new Error('No transform module')); } debug('transforming file', fileName); - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ + return this._transform( this._transformModulePath, fileName, diff --git a/packages/metro-bundler/src/Resolver/polyfills/require.js b/packages/metro-bundler/src/Resolver/polyfills/require.js index b6b2e8b1..164190e4 100644 --- a/packages/metro-bundler/src/Resolver/polyfills/require.js +++ b/packages/metro-bundler/src/Resolver/polyfills/require.js @@ -46,22 +46,19 @@ type ModuleDefinition = {| isInitialized: boolean, verboseName?: string, |}; -type ModuleMap = {[key: ModuleID]: ModuleDefinition}; +type ModuleMap = {[key: ModuleID]: ModuleDefinition, __proto__: null}; type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports; type VerboseModuleNameForDev = string; global.require = require; global.__d = define; -/* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.56 was deployed. To see the error delete this comment and - * run Flow. */ const modules: ModuleMap = Object.create(null); if (__DEV__) { - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.56 was deployed. To see the error delete this comment - * and run Flow. */ - var verboseNamesToModuleIds: {[key: string]: number} = Object.create(null); + var verboseNamesToModuleIds: { + [key: string]: number, + __proto__: null, + } = Object.create(null); } function define( diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 7d4437a3..8622288a 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -24,6 +24,7 @@ const formatBundlingError = require('../lib/formatBundlingError'); const getMaxWorkers = require('../lib/getMaxWorkers'); const getOrderedDependencyPaths = require('../lib/getOrderedDependencyPaths'); const mime = require('mime-types'); +const nullthrows = require('fbjs/lib/nullthrows'); const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); const path = require('path'); const symbolicate = require('./symbolicate'); @@ -175,7 +176,7 @@ class Server { workerPath: ?string, }; _projectRoots: $ReadOnlyArray; - _bundles: {}; + _bundles: {__proto__: null}; _bundleBuildInfos: WeakMap; _changeWatchers: Array<{ req: IncomingMessage, @@ -237,9 +238,6 @@ class Server { this._reporter = reporter; this._projectRoots = this._opts.projectRoots; - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ this._bundles = Object.create(null); this._bundleBuildInfos = new WeakMap(); this._changeWatchers = []; @@ -275,11 +273,9 @@ class Server { for (const key in this._bundles) { this._bundles[key] .then(bundle => { - const deps = bundleDeps.get(bundle); + const deps = nullthrows(bundleDeps.get(bundle)); filePaths.forEach(filePath => { - // $FlowFixMe(>=0.37.0) if (deps.files.has(filePath)) { - // $FlowFixMe(>=0.37.0) deps.outdated.add(filePath); } }); @@ -506,9 +502,6 @@ class Server { } _clearBundles() { - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ this._bundles = Object.create(null); } @@ -700,8 +693,7 @@ class Server { if (optionsJson in this._bundles) { return this._bundles[optionsJson].then(bundle => { - const deps = bundleDeps.get(bundle); - // $FlowFixMe(>=0.37.0) + const deps = nullthrows(bundleDeps.get(bundle)); const {dependencyPairs, files, idToIndex, outdated} = deps; if (outdated.size) { const updatingExistingBundleLogEntry = log( @@ -713,7 +705,6 @@ class Server { debug('Attempt to update existing bundle'); - // $FlowFixMe(>=0.37.0) deps.outdated = new Set(); const {platform, dev, minify, hot} = options; diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js index f41fe2a7..98ae408a 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -68,7 +68,7 @@ type Options = {| |}; class ResolutionRequest { - _immediateResolutionCache: {[key: string]: TModule}; + _immediateResolutionCache: {[key: string]: TModule, __proto__: null}; _options: Options; static AmbiguousModuleResolutionError: Class; @@ -146,7 +146,7 @@ class ResolutionRequest { transformOptions: TransformWorkerOptions, onProgress?: ?(finishedModules: number, totalModules: number) => mixed, recursive: boolean, - }) { + }): Promise { const entry = this._options.moduleCache.getModule(this._options.entryPath); response.pushDependency(entry); @@ -245,9 +245,6 @@ class ResolutionRequest { return promise.then(value => [key, value]); } - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ return Promise.all([ // kicks off recursive dependency discovery, but doesn't block until it's // done @@ -363,13 +360,10 @@ class ResolutionRequest { } _resetResolutionCache() { - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ this._immediateResolutionCache = Object.create(null); } - getResolutionCache(): {[key: string]: TModule} { + getResolutionCache(): {[key: string]: TModule, __proto__: null} { return this._immediateResolutionCache; } } diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionResponse.js b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionResponse.js index 590e7737..e136ce59 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionResponse.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionResponse.js @@ -24,7 +24,7 @@ class ResolutionResponse { // This is monkey-patched from Resolver. getModuleId: ?() => number; - _mappings: {[hash: string]: Array<[string, TModule]>}; + _mappings: {[hash: string]: Array<[string, TModule]>, __proto__: null}; _finalized: boolean; _mainModule: ?TModule; @@ -34,9 +34,6 @@ class ResolutionResponse { this.mocks = null; this.numPrependedDependencies = 0; this.options = options; - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ this._mappings = Object.create(null); this._finalized = false; } diff --git a/packages/metro-bundler/src/node-haste/Module.js b/packages/metro-bundler/src/node-haste/Module.js index 5a772d3b..21f7909f 100644 --- a/packages/metro-bundler/src/node-haste/Module.js +++ b/packages/metro-bundler/src/node-haste/Module.js @@ -144,18 +144,12 @@ class Module { return this._getHasteName() != null; } - getCode(transformOptions: WorkerOptions) { - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ - return this.read(transformOptions).then(({code}) => code); + async getCode(transformOptions: WorkerOptions): Promise { + return (await this.read(transformOptions)).code; } - getMap(transformOptions: WorkerOptions) { - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ - return this.read(transformOptions).then(({map}) => map); + async getMap(transformOptions: WorkerOptions) { + return (await this.read(transformOptions)).map; } getName(): string { @@ -186,11 +180,8 @@ class Module { return this._moduleCache.getPackageForModule(this); } - getDependencies(transformOptions: WorkerOptions) { - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ - return this.read(transformOptions).then(({dependencies}) => dependencies); + async getDependencies(transformOptions: WorkerOptions) { + return (await this.read(transformOptions)).dependencies; } /** diff --git a/packages/metro-bundler/src/node-haste/ModuleCache.js b/packages/metro-bundler/src/node-haste/ModuleCache.js index b8bd5002..903e2573 100644 --- a/packages/metro-bundler/src/node-haste/ModuleCache.js +++ b/packages/metro-bundler/src/node-haste/ModuleCache.js @@ -33,9 +33,9 @@ class ModuleCache { _getClosestPackage: GetClosestPackageFn; _getTransformCacheKey: GetTransformCacheKey; _globalTransformCache: ?GlobalTransformCache; - _moduleCache: {[filePath: string]: Module}; + _moduleCache: {[filePath: string]: Module, __proto__: null}; _moduleOptions: ModuleOptions; - _packageCache: {[filePath: string]: Package}; + _packageCache: {[filePath: string]: Package, __proto__: null}; _packageModuleMap: WeakMap; _platforms: Set; _transformCode: TransformCode; @@ -72,14 +72,8 @@ class ModuleCache { this._getTransformCacheKey = getTransformCacheKey; this._globalTransformCache = globalTransformCache; this._depGraphHelpers = depGraphHelpers; - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ this._moduleCache = Object.create(null); this._moduleOptions = moduleOptions; - /* $FlowFixMe(>=0.56.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.56 was deployed. To see the error delete this - * comment and run Flow. */ this._packageCache = Object.create(null); this._packageModuleMap = new WeakMap(); this._platforms = platforms; @@ -144,9 +138,8 @@ class ModuleCache { } getPackageForModule(module: Module): ?Package { - if (this._packageModuleMap.has(module)) { - const packagePath = this._packageModuleMap.get(module); - // $FlowFixMe(>=0.37.0) + let packagePath = this._packageModuleMap.get(module); + if (packagePath) { if (this._packageCache[packagePath]) { return this._packageCache[packagePath]; } else { @@ -154,7 +147,7 @@ class ModuleCache { } } - const packagePath = this._getClosestPackage(module.path); + packagePath = this._getClosestPackage(module.path); if (!packagePath) { return null; } diff --git a/packages/metro-bundler/src/node-haste/Polyfill.js b/packages/metro-bundler/src/node-haste/Polyfill.js index b4f68281..84ec03be 100644 --- a/packages/metro-bundler/src/node-haste/Polyfill.js +++ b/packages/metro-bundler/src/node-haste/Polyfill.js @@ -43,11 +43,8 @@ class Polyfill extends Module { return null; } - getDependencies() { - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ - return Promise.resolve(this._dependencies); + async getDependencies() { + return this._dependencies; } isJSON() { diff --git a/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js b/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js index 2aba0314..bf500dd3 100644 --- a/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js +++ b/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js @@ -40,10 +40,7 @@ function saveAsIndexedFile( bundle: RamBundleInfo, options: OutputOptions, log: (...args: Array) => void, - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.54 was deployed. To see the error delete this comment and - * run Flow. */ -): Promise<> { +): Promise { const { bundleOutput, bundleEncoding: encoding, diff --git a/packages/metro-bundler/src/shared/output/unbundle/index.js b/packages/metro-bundler/src/shared/output/unbundle/index.js index c53f90fa..f7304dfb 100644 --- a/packages/metro-bundler/src/shared/output/unbundle/index.js +++ b/packages/metro-bundler/src/shared/output/unbundle/index.js @@ -43,10 +43,7 @@ function saveUnbundle( // overhead when reading hundreds pf assets from disk return options.platform === 'android' && !options.indexedUnbundle ? asAssets(bundle, options, log) - : /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.54 was deployed. To see the error delete this - * comment and run Flow. */ - asIndexedFile(bundle, options, log); + : asIndexedFile(bundle, options, log); } exports.build = buildBundle; diff --git a/packages/metro-bundler/src/shared/output/unbundle/write-sourcemap.js b/packages/metro-bundler/src/shared/output/unbundle/write-sourcemap.js index 7d828d8a..c0c2af4d 100644 --- a/packages/metro-bundler/src/shared/output/unbundle/write-sourcemap.js +++ b/packages/metro-bundler/src/shared/output/unbundle/write-sourcemap.js @@ -17,10 +17,7 @@ function writeSourcemap( fileName: string, contents: string, log: (...args: Array) => void, - /* $FlowFixMe(>=0.54.0 site=react_native_fb) This comment suppresses an error - * found when Flow v0.54 was deployed. To see the error delete this comment and - * run Flow. */ -): Promise<> { +): Promise { if (!fileName) { return Promise.resolve(); }