refactor(ivy): ngcc - tidy up DependencyResolver helper method (#29643)

This method was poorly named for what it does, and did not have a
return type.

PR Close #29643
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:47:56 +01:00 committed by Andrew Kushnir
parent 78b5bd5174
commit 4c03208537

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {resolve} from 'canonical-path';
import {DepGraph} from 'dependency-graph'; import {DepGraph} from 'dependency-graph';
import {resolve} from 'path';
import {AbsoluteFsPath} from '../../../src/ngtsc/path'; import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {Logger} from '../logging/logger'; import {Logger} from '../logging/logger';
@ -48,6 +48,11 @@ export interface IgnoredDependency {
dependencyPath: string; dependencyPath: string;
} }
export interface DependencyDiagnostics {
invalidEntryPoints: InvalidEntryPoint[];
ignoredDependencies: IgnoredDependency[];
}
/** /**
* A list of entry-points, sorted by their dependencies. * A list of entry-points, sorted by their dependencies.
* *
@ -57,11 +62,7 @@ export interface IgnoredDependency {
* Some entry points or their dependencies may be have been ignored. These are captured for * Some entry points or their dependencies may be have been ignored. These are captured for
* diagnostic purposes in `invalidEntryPoints` and `ignoredDependencies` respectively. * diagnostic purposes in `invalidEntryPoints` and `ignoredDependencies` respectively.
*/ */
export interface SortedEntryPointsInfo { export interface SortedEntryPointsInfo extends DependencyDiagnostics { entryPoints: EntryPoint[]; }
entryPoints: EntryPoint[];
invalidEntryPoints: InvalidEntryPoint[];
ignoredDependencies: IgnoredDependency[];
}
/** /**
* A class that resolves dependencies between entry-points. * A class that resolves dependencies between entry-points.
@ -77,7 +78,8 @@ export class DependencyResolver {
*/ */
sortEntryPointsByDependency(entryPoints: EntryPoint[], target?: EntryPoint): sortEntryPointsByDependency(entryPoints: EntryPoint[], target?: EntryPoint):
SortedEntryPointsInfo { SortedEntryPointsInfo {
const {invalidEntryPoints, ignoredDependencies, graph} = this.createDependencyInfo(entryPoints); const {invalidEntryPoints, ignoredDependencies, graph} =
this.computeDependencyGraph(entryPoints);
let sortedEntryPointNodes: string[]; let sortedEntryPointNodes: string[];
if (target) { if (target) {
@ -100,7 +102,7 @@ export class DependencyResolver {
* The graph only holds entry-points that ngcc cares about and whose dependencies * The graph only holds entry-points that ngcc cares about and whose dependencies
* (direct and transitive) all exist. * (direct and transitive) all exist.
*/ */
private createDependencyInfo(entryPoints: EntryPoint[]) { private computeDependencyGraph(entryPoints: EntryPoint[]): DependencyGraph {
const invalidEntryPoints: InvalidEntryPoint[] = []; const invalidEntryPoints: InvalidEntryPoint[] = [];
const ignoredDependencies: IgnoredDependency[] = []; const ignoredDependencies: IgnoredDependency[] = [];
const graph = new DepGraph<EntryPoint>(); const graph = new DepGraph<EntryPoint>();
@ -167,3 +169,7 @@ function getEntryPointPath(entryPoint: EntryPoint): AbsoluteFsPath {
} }
throw new Error(`There is no format with import statements in '${entryPoint.path}' entry-point.`); throw new Error(`There is no format with import statements in '${entryPoint.path}' entry-point.`);
} }
interface DependencyGraph extends DependencyDiagnostics {
graph: DepGraph<EntryPoint>;
}