fix(ivy): ngcc - report an error if a target has missing dependencies (#31872)
Previously, we either crashed with an obscure error or silently did nothing. Now we throw an exception but with a helpful message. PR Close #31872
This commit is contained in:
parent
57e15fc08b
commit
961d663fbe
|
@ -193,6 +193,13 @@ function getTargetedEntryPoints(
|
||||||
const finder = new TargetedEntryPointFinder(
|
const finder = new TargetedEntryPointFinder(
|
||||||
fs, config, logger, resolver, basePath, absoluteTargetEntryPointPath, pathMappings);
|
fs, config, logger, resolver, basePath, absoluteTargetEntryPointPath, pathMappings);
|
||||||
const entryPointInfo = finder.findEntryPoints();
|
const entryPointInfo = finder.findEntryPoints();
|
||||||
|
const invalidTarget = entryPointInfo.invalidEntryPoints.find(
|
||||||
|
i => i.entryPoint.path === absoluteTargetEntryPointPath);
|
||||||
|
if (invalidTarget !== undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`The target entry-point "${invalidTarget.entryPoint.name}" has missing dependencies:\n` +
|
||||||
|
invalidTarget.missingDependencies.map(dep => ` - ${dep}\n`));
|
||||||
|
}
|
||||||
if (entryPointInfo.entryPoints.length === 0) {
|
if (entryPointInfo.entryPoints.length === 0) {
|
||||||
markNonAngularPackageAsProcessed(fs, absoluteTargetEntryPointPath);
|
markNonAngularPackageAsProcessed(fs, absoluteTargetEntryPointPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,14 @@ runInEachFileSystem(() => {
|
||||||
// was not processed.
|
// was not processed.
|
||||||
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toBeUndefined();
|
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should report an error if a dependency of the target does not exist', () => {
|
||||||
|
expect(() => {
|
||||||
|
mainNgcc({basePath: '/node_modules', targetEntryPointPath: 'invalid-package'});
|
||||||
|
})
|
||||||
|
.toThrowError(
|
||||||
|
'The target entry-point "invalid-package" has missing dependencies:\n - @angular/missing\n');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('early skipping of target entry-point', () => {
|
describe('early skipping of target entry-point', () => {
|
||||||
|
@ -536,6 +544,30 @@ runInEachFileSystem(() => {
|
||||||
contents: `export declare class AppComponent {};`
|
contents: `export declare class AppComponent {};`
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// An Angular package that has a missing dependency
|
||||||
|
loadTestFiles([
|
||||||
|
{
|
||||||
|
name: _('/node_modules/invalid-package/package.json'),
|
||||||
|
contents: '{"name": "invalid-package", "es2015": "./index.js", "typings": "./index.d.ts"}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: _('/node_modules/invalid-package/index.js'),
|
||||||
|
contents: `
|
||||||
|
import {AppModule} from "@angular/missing";
|
||||||
|
import {Component} from '@angular/core';
|
||||||
|
export class AppComponent {};
|
||||||
|
AppComponent.decorators = [
|
||||||
|
{ type: Component, args: [{selector: 'app', template: '<h2>Hello</h2>'}] }
|
||||||
|
];
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: _('/node_modules/invalid-package/index.d.ts'),
|
||||||
|
contents: `export declare class AppComponent {}`
|
||||||
|
},
|
||||||
|
{name: _('/node_modules/invalid-package/index.metadata.json'), contents: 'DUMMY DATA'},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue