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:
parent
0709ed4c2b
commit
b70746a113
|
@ -81,7 +81,7 @@ export class DependencyResolver {
|
||||||
|
|
||||||
let sortedEntryPointNodes: string[];
|
let sortedEntryPointNodes: string[];
|
||||||
if (target) {
|
if (target) {
|
||||||
if (target.compiledByAngular) {
|
if (target.compiledByAngular && graph.hasNode(target.path)) {
|
||||||
sortedEntryPointNodes = graph.dependenciesOf(target.path);
|
sortedEntryPointNodes = graph.dependenciesOf(target.path);
|
||||||
sortedEntryPointNodes.push(target.path);
|
sortedEntryPointNodes.push(target.path);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -179,6 +179,19 @@ runInEachFileSystem(() => {
|
||||||
expect(sorted.entryPoints).toEqual([fifth]);
|
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', () => {
|
it('should use the appropriate DependencyHost for each entry-point', () => {
|
||||||
const esm5Host = new EsmDependencyHost(fs, moduleResolver);
|
const esm5Host = new EsmDependencyHost(fs, moduleResolver);
|
||||||
const esm2015Host = new EsmDependencyHost(fs, moduleResolver);
|
const esm2015Host = new EsmDependencyHost(fs, moduleResolver);
|
||||||
|
|
Loading…
Reference in New Issue