fix(ngcc): use path-mappings from tsconfig in dependency resolution (#36180)

When computing the dependencies between packages which are not in
node_modules, we may need to rely upon path-mappings to find the path
to the imported entry-point.

This commit allows ngcc to use the path-mappings from a tsconfig
file to find dependencies. By default any tsconfig.json file in the directory
above the `basePath` is loaded but it is possible to use a path to a
specific file by providing the `tsConfigPath` property to mainNgcc,
or to turn off loading any tsconfig file by setting `tsConfigPath` to `null`.
At the command line this is controlled via the `--tsconfig` option.

Fixes #36119

PR Close #36180
This commit is contained in:
Pete Bacon Darwin
2020-03-20 22:09:40 +00:00
committed by Misko Hevery
parent 4f9717331d
commit 380de1e7b4
4 changed files with 217 additions and 17 deletions

View File

@ -92,6 +92,13 @@ if (require.main === module) {
type: 'boolean',
default: false,
})
.option('tsconfig', {
describe:
'A path to a tsconfig.json file that will be used to configure the Angular compiler and module resolution used by ngcc.\n' +
'If not provided, ngcc will attempt to read a `tsconfig.json` file from the folder above that given by the `-s` option.\n' +
'Set to false (via `--no-tsconfig`) if you do not want ngcc to use any `tsconfig.json` file.',
type: 'string',
})
.strict()
.help()
.parse(args);
@ -113,6 +120,10 @@ if (require.main === module) {
const enableI18nLegacyMessageIdFormat = options['legacy-message-ids'];
const invalidateEntryPointManifest = options['invalidate-entry-point-manifest'];
const errorOnFailedEntryPoint = options['error-on-failed-entry-point'];
// yargs is not so great at mixed string+boolean types, so we have to test tsconfig against a
// string "false" to capture the `tsconfig=false` option.
// And we have to convert the option to a string to handle `no-tsconfig`, which will be `false`.
const tsConfigPath = `${options['tsconfig']}` === 'false' ? null : options['tsconfig'];
(async() => {
try {
@ -126,7 +137,7 @@ if (require.main === module) {
createNewEntryPointFormats,
logger,
enableI18nLegacyMessageIdFormat,
async: options['async'], invalidateEntryPointManifest, errorOnFailedEntryPoint,
async: options['async'], invalidateEntryPointManifest, errorOnFailedEntryPoint, tsConfigPath
});
if (logger) {