fix(ivy): ngcc - don't crash if entry-points have multiple invalid dependencies (#31276)
If an entry-point has missing dependencies then it cannot be processed and is marked as invalid. Similarly, if an entry-point has dependencies that have been marked as invalid then that entry-point too is invalid. In all these cases, ngcc should quietly ignore these entry-points and continue processing what it can. Previously, if an entry-point had more than one entry-point that was transitively invalid then ngcc was crashing rather than ignoring the entry-point. PR Close #31276
This commit is contained in:
parent
32c760f5e7
commit
3788ebb714
|
@ -130,12 +130,13 @@ export class DependencyResolver {
|
|||
removeNodes(entryPoint, Array.from(missing));
|
||||
} else {
|
||||
dependencies.forEach(dependencyPath => {
|
||||
if (graph.hasNode(dependencyPath)) {
|
||||
if (graph.hasNode(entryPoint.path)) {
|
||||
// The entry-point is still valid (i.e. has no missing dependencies) and
|
||||
// the dependency maps to an entry point that exists in the graph so add it
|
||||
graph.addDependency(entryPoint.path, dependencyPath);
|
||||
}
|
||||
if (!graph.hasNode(entryPoint.path)) {
|
||||
// The entry-point has already been identified as invalid so we don't need
|
||||
// to do any further work on it.
|
||||
} else if (graph.hasNode(dependencyPath)) {
|
||||
// The entry-point is still valid (i.e. has no missing dependencies) and
|
||||
// the dependency maps to an entry point that exists in the graph so add it
|
||||
graph.addDependency(entryPoint.path, dependencyPath);
|
||||
} else if (invalidEntryPoints.some(i => i.entryPoint.path === dependencyPath)) {
|
||||
// The dependency path maps to an entry-point that was previously removed
|
||||
// from the graph, so remove this entry-point as well.
|
||||
|
|
|
@ -125,6 +125,21 @@ runInEachFileSystem(() => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('should cope with entry points having multiple indirect missing dependencies', () => {
|
||||
spyOn(host, 'findDependencies').and.callFake(createFakeComputeDependencies({
|
||||
[_('/first/index.js')]: {resolved: [], missing: ['/missing1']},
|
||||
[_('/second/sub/index.js')]: {resolved: [], missing: ['/missing2']},
|
||||
[_('/third/index.js')]: {resolved: [first.path, second.path], missing: []},
|
||||
}));
|
||||
const result = resolver.sortEntryPointsByDependency([first, second, third]);
|
||||
expect(result.entryPoints).toEqual([]);
|
||||
expect(result.invalidEntryPoints).toEqual([
|
||||
{entryPoint: first, missingDependencies: ['/missing1']},
|
||||
{entryPoint: second, missingDependencies: ['/missing2']},
|
||||
{entryPoint: third, missingDependencies: [first.path]},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should error if the entry point does not have a suitable format', () => {
|
||||
expect(() => resolver.sortEntryPointsByDependency([
|
||||
{ path: '/first', packageJson: {}, compiledByAngular: true } as EntryPoint
|
||||
|
|
Loading…
Reference in New Issue