From 9d33905786ff0ecdd1f4bcba5479b8d039fe8d1e Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Mon, 14 Mar 2016 08:55:19 -0700 Subject: [PATCH] Move name resolution of inversed dependencies to HMR server Summary:Name resolution of inversed dependencies used to happen in node-haste, but that makes it difficult switiching to numeric module IDs. This moves the name resolution to the HMR server in order to be able to change the logic more easily. node-haste 2.9.0 provides a `Map` of modules to `Set`s that contain the modules that depend on the key. Reviewed By: martinbigio Differential Revision: D3047414 fb-gh-sync-id: b98accea901d4da209dc4434ab111eb07ce9e2a0 shipit-source-id: b98accea901d4da209dc4434ab111eb07ce9e2a0 --- local-cli/server/util/attachHMRServer.js | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/local-cli/server/util/attachHMRServer.js b/local-cli/server/util/attachHMRServer.js index 3c6d630a4..2071c7d2a 100644 --- a/local-cli/server/util/attachHMRServer.js +++ b/local-cli/server/util/attachHMRServer.js @@ -81,16 +81,24 @@ function attachHMRServer({httpServer, path, packagerServer}) { dependenciesModulesCache[depName] = dep; }); })).then(() => { - return getInverseDependencies(response) - .then(inverseDependenciesCache => { - return { - dependenciesCache, - dependenciesModulesCache, - shallowDependencies, - inverseDependenciesCache, - resolutionResponse: response, - }; - }); + const inverseDependencies = getInverseDependencies(response); + const inverseDependenciesCache = Object.create(null); + return Promise.all( + Array.from(inverseDependencies).map(([module, dependents]) => { + return Promise.all([ + module.getName(), + Promise.all(Array.from(dependents).map(m => m.getName())), + ]).then(([moduleName, dependentsNames]) => { + inverseDependenciesCache[moduleName] = dependentsNames; + }); + }) + ).then(() => ({ + dependenciesCache, + dependenciesModulesCache, + shallowDependencies, + inverseDependenciesCache, + resolutionResponse: response, + })); }); }); });