From 7ccbcc5ebc994028053bf45377f72c6b9d1ca413 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Fri, 8 Sep 2017 06:33:17 -0700 Subject: [PATCH] metro-bundler: fix Flow errors in OSS Reviewed By: cpojer Differential Revision: D5775151 fbshipit-source-id: 730ab160fdf5ea35f8047eb55a7e2844ba7a7c14 --- .../src/ModuleGraph/worker/optimize-module.js | 16 ++++++++-------- packages/metro-bundler/src/Resolver/index.js | 6 +++++- packages/metro-bundler/src/Server/index.js | 2 +- packages/metro-bundler/yarn.lock | 14 +++++++------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/metro-bundler/src/ModuleGraph/worker/optimize-module.js b/packages/metro-bundler/src/ModuleGraph/worker/optimize-module.js index f99bc2f0..2359bcd8 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/optimize-module.js +++ b/packages/metro-bundler/src/ModuleGraph/worker/optimize-module.js @@ -47,13 +47,13 @@ function optimizeModule( const result = {...details, transformed: {}}; const {postMinifyProcess} = optimizationOptions; - Object.entries( - transformed, - /* $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. */ - ).forEach(([k, t: TransformResult]: [*, TransformResult]) => { - const optimized = optimize(t, file, code, optimizationOptions); + Object.entries(transformed).forEach(([k, t: TransformResult]) => { + const optimized = optimize( + (t: $FlowFixMe), + file, + code, + optimizationOptions, + ); const processed = postMinifyProcess({ code: optimized.code, map: optimized.map, @@ -66,7 +66,7 @@ function optimizeModule( return {type: 'code', details: result}; } -function optimize(transformed, file, originalCode, options) { +function optimize(transformed: TransformResult, file, originalCode, options) { const {code, dependencyMapName, map} = transformed; const optimized = optimizeCode(code, map, file, options); diff --git a/packages/metro-bundler/src/Resolver/index.js b/packages/metro-bundler/src/Resolver/index.js index 77041e2f..5386daaf 100644 --- a/packages/metro-bundler/src/Resolver/index.js +++ b/packages/metro-bundler/src/Resolver/index.js @@ -130,7 +130,10 @@ class Resolver { ): Promise> { const {platform, recursive = true, prependPolyfills} = options; - const resolutionResponse = await this._depGraph.getDependencies({ + const resolutionResponse: ResolutionResponse< + Module, + T, + > = await this._depGraph.getDependencies({ entryPath, platform, options: bundlingOptions, @@ -144,6 +147,7 @@ class Resolver { .forEach(polyfill => resolutionResponse.prependDependency(polyfill)); } + /* $FlowFixMe: monkey patching */ resolutionResponse.getModuleId = getModuleId; return resolutionResponse.finalize(); } diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 99c034d3..feccdb92 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -668,7 +668,7 @@ class Server { }), Promise.all(Array.from(outdated, this.getModuleForPath, this)), ]) - .then(([response, changedModules]) => { + .then(([response, changedModules]: [$FlowFixMe, *]) => { debug('Update bundle: rebuild shallow bundle'); changedModules.forEach(m => { diff --git a/packages/metro-bundler/yarn.lock b/packages/metro-bundler/yarn.lock index 4ddf6d8e..9de6dac7 100644 --- a/packages/metro-bundler/yarn.lock +++ b/packages/metro-bundler/yarn.lock @@ -1163,17 +1163,17 @@ isstream@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" -jest-docblock@20.1.0-echo.1: - version "20.1.0-echo.1" - resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-20.1.0-echo.1.tgz#be02f43ee019f97e6b83267c746ac7b40d290fe8" +jest-docblock@^21, jest-docblock@^21.0.0: + version "21.0.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.0.0.tgz#7dd57568543aec98910f749540afc15fab53a27f" -jest-haste-map@20.1.0-echo.1: - version "20.1.0-echo.1" - resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-20.1.0-echo.1.tgz#6dfd0c97bb51a68a35dd98326e04f994157dce81" +jest-haste-map@^21: + version "21.0.0" + resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-21.0.0.tgz#1f099ff6aedb52ec55fa9773ce26e4bbb00b0580" dependencies: fb-watchman "^2.0.0" graceful-fs "^4.1.11" - jest-docblock "20.1.0-echo.1" + jest-docblock "^21.0.0" micromatch "^2.3.11" sane "^2.0.0" worker-farm "^1.3.1"