fix(ivy): ngcc - prevent crash when analyzed target is ignored (#31872)

ngcc analyzes the dependency structure of the entrypoints it needs to
process, as the compilation of entrypoints is ordering sensitive: any
dependent upon entrypoint must be compiled before its dependees. As part
of the analysis of the dependency graph, it is detected when a
dependency of entrypoint is not installed, in which case that entrypoint
will be marked as ignored.

When a target entrypoint to compile is provided, it could occur that
given target is considered ignored because one of its dependencies might
be missing. This situation was not dealt with currently, instead
resulting in a crash of ngcc.

This commit prevents the crash by taking the above scenario into account.

PR Close #31872
This commit is contained in:
JoostK 2019-07-27 21:02:04 +02:00 committed by Alex Rickabaugh
parent 0709ed4c2b
commit b70746a113
2 changed files with 14 additions and 1 deletions

View File

@ -81,7 +81,7 @@ export class DependencyResolver {
let sortedEntryPointNodes: string[];
if (target) {
if (target.compiledByAngular) {
if (target.compiledByAngular && graph.hasNode(target.path)) {
sortedEntryPointNodes = graph.dependenciesOf(target.path);
sortedEntryPointNodes.push(target.path);
} else {

View File

@ -179,6 +179,19 @@ runInEachFileSystem(() => {
expect(sorted.entryPoints).toEqual([fifth]);
});
it('should not process the provided target if it has missing dependencies', () => {
spyOn(host, 'findDependencies').and.callFake(createFakeComputeDependencies({
[_('/first/index.js')]: {resolved: [], missing: ['/missing']},
}));
const entryPoints = [first];
let sorted: SortedEntryPointsInfo;
sorted = resolver.sortEntryPointsByDependency(entryPoints, first);
expect(sorted.entryPoints).toEqual([]);
expect(sorted.invalidEntryPoints[0].entryPoint).toEqual(first);
expect(sorted.invalidEntryPoints[0].missingDependencies).toEqual(['/missing']);
});
it('should use the appropriate DependencyHost for each entry-point', () => {
const esm5Host = new EsmDependencyHost(fs, moduleResolver);
const esm2015Host = new EsmDependencyHost(fs, moduleResolver);