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 d0c2b068d7
commit 174f84cc8a
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
* 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.
*
* @flow
* @format
*/
'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);
return pairs
? pairs.map(([, dependencyModule]) => dependencyModule)
: [];
return pairs ? 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);
if (!dependents) {
dependents = new Set();
@ -27,7 +37,9 @@ function getModuleDependents(cache, module) {
/**
* 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();
resolutionResponse.dependencies.forEach(module => {