diff --git a/local-cli/server/util/attachHMRServer.js b/local-cli/server/util/attachHMRServer.js index eef673a8028209..da3ecf7597dc18 100644 --- a/local-cli/server/util/attachHMRServer.js +++ b/local-cli/server/util/attachHMRServer.js @@ -62,12 +62,16 @@ function attachHMRServer({httpServer, path, packagerServer}) { // map from module name to path const moduleToFilenameCache = Object.create(null); - deps.forEach(dep => moduleToFilenameCache[dep.name] = dep.path); + deps.forEach(dep => { + moduleToFilenameCache[dep.name] = dep.path; + }); // map that indicates the shallow dependency each file included on the // bundle has const shallowDependencies = Object.create(null); - deps.forEach(dep => shallowDependencies[dep.path] = dep.deps); + deps.forEach(dep => { + shallowDependencies[dep.path] = dep.deps; + }); // map from module name to the modules' dependencies the bundle entry // has @@ -128,8 +132,8 @@ function attachHMRServer({httpServer, path, packagerServer}) { `[Hot Module Replacement] File change detected (${time()})` ); - const blacklisted = blacklist.find(path => - filename.indexOf(path) !== -1 + const blacklisted = blacklist.find(blacklistedPath => + filename.indexOf(blacklistedPath) !== -1 ); if (blacklisted) { @@ -170,10 +174,10 @@ function attachHMRServer({httpServer, path, packagerServer}) { // dependencies we used to have with the one we now have return getDependencies(client.platform, client.bundleEntry) .then(({ - dependenciesCache, - dependenciesModulesCache, - shallowDependencies, - inverseDependenciesCache, + depsCache, + depsModulesCache, + shallowDeps, + inverseDepsCache, resolutionResponse, }) => { if (!client) { @@ -182,9 +186,9 @@ function attachHMRServer({httpServer, path, packagerServer}) { // build list of modules for which we'll send HMR updates const modulesToUpdate = [packagerServer.getModuleForPath(filename)]; - Object.keys(dependenciesModulesCache).forEach(module => { - if (!client.dependenciesModulesCache[module]) { - modulesToUpdate.push(dependenciesModulesCache[module]); + Object.keys(depsModulesCache).forEach(module => { + if (!client.depsModulesCache[module]) { + modulesToUpdate.push(depsModulesCache[module]); } }); @@ -199,9 +203,10 @@ function attachHMRServer({httpServer, path, packagerServer}) { modulesToUpdate.reverse(); // invalidate caches - client.dependenciesCache = dependenciesCache; - client.dependenciesModulesCache = dependenciesModulesCache; - client.shallowDependencies = shallowDependencies; + client.dependenciesCache = depsCache; + client.dependenciesModulesCache = depsModulesCache; + client.shallowDependencies = shallowDeps; + client.inverseDependenciesCache = inverseDepsCache; return resolutionResponse.copy({ dependencies: modulesToUpdate @@ -228,13 +233,11 @@ function attachHMRServer({httpServer, path, packagerServer}) { packagerHost = httpServerAddress.address; } - let packagerPort = httpServerAddress.port; - return packagerServer.buildBundleForHMR({ entryFile: client.bundleEntry, platform: client.platform, resolutionResponse, - }, packagerHost, packagerPort); + }, packagerHost, httpServerAddress.port); }) .then(bundle => { if (!client || !bundle || bundle.isEmpty()) { @@ -245,7 +248,7 @@ function attachHMRServer({httpServer, path, packagerServer}) { type: 'update', body: { modules: bundle.getModulesNamesAndCode(), - inverseDependencies: inverseDependenciesCache, + inverseDependencies: client.inverseDependenciesCache, sourceURLs: bundle.getSourceURLs(), sourceMappingURLs: bundle.getSourceMappingURLs(), },