packager: getInverseDependencies: @flow

Reviewed By: davidaurelio

Differential Revision: D5052190

fbshipit-source-id: ebfa2a698233e914b016fe50f790ee8aa758c4f2
This commit is contained in:
Jean Lauliac 2017-05-12 10:26:48 -07:00 committed by Facebook Github Bot
parent 02d57294fe
commit 2068e661a5
1 changed files with 18 additions and 6 deletions

View File

@ -5,17 +5,27 @@
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/ */
'use strict'; 'use strict';
function resolveModuleRequires(resolutionResponse, module) { import type ResolutionResponse from '../DependencyGraph/ResolutionResponse';
function resolveModuleRequires<TModule: {hash(): string}, TOptions>(
resolutionResponse: ResolutionResponse<TModule, TOptions>,
module: TModule,
) {
const pairs = resolutionResponse.getResolvedDependencyPairs(module); const pairs = resolutionResponse.getResolvedDependencyPairs(module);
return pairs return pairs ? pairs.map(([, dependencyModule]) => dependencyModule) : [];
? pairs.map(([, dependencyModule]) => dependencyModule)
: [];
} }
function getModuleDependents(cache, module) { function getModuleDependents<TModule>(
cache: Map<TModule, Set<TModule>>,
module: TModule,
): Set<TModule> {
let dependents = cache.get(module); let dependents = cache.get(module);
if (!dependents) { if (!dependents) {
dependents = new Set(); dependents = new Set();
@ -27,7 +37,9 @@ function getModuleDependents(cache, module) {
/** /**
* Returns an object that indicates in which module each module is required. * Returns an object that indicates in which module each module is required.
*/ */
function getInverseDependencies(resolutionResponse) { function getInverseDependencies<TModule: {hash(): string}, TOptions>(
resolutionResponse: ResolutionResponse<TModule, TOptions>,
): Map<TModule, Set<TModule>> {
const cache = new Map(); const cache = new Map();
resolutionResponse.dependencies.forEach(module => { resolutionResponse.dependencies.forEach(module => {