feat(ivy): add support for esm2015 and esm5 in ngcc PackageParser (#25406)

Since non-flat module formats (esm2015, esm5) have different structure
than their flat counterparts (and since we are operating on JS files
inside `node_modules/`, we need to configure TS to include deeply nested
JS files (by specifying a sufficiently high `maxNodeModuleJsDepth`).

Remains to be determined if this has any (noticeable) performance
implications.

PR Close #25406
This commit is contained in:
George Kalpakas
2018-07-24 16:53:23 +03:00
committed by Matias Niemelä
parent a7134dbc37
commit 3211432d2a
3 changed files with 25 additions and 5 deletions

View File

@ -10,12 +10,13 @@ import {PackageTransformer} from './transform/package_transformer';
export function mainNgcc(args: string[]): number {
const packagePath = resolve(args[0]);
const format = args[1] || 'fesm2015';
// TODO: find all the package tyoes to transform
// TODO: find all the package types to transform
// TODO: error/warning logging/handling etc
const transformer = new PackageTransformer();
transformer.transform(packagePath, 'fesm2015');
transformer.transform(packagePath, format);
return 0;
}

View File

@ -46,7 +46,12 @@ export class PackageTransformer {
const targetNodeModules = sourceNodeModules.replace(/node_modules$/, 'node_modules_ngtsc');
const entryPointPaths = getEntryPoints(packagePath, format);
entryPointPaths.forEach(entryPointPath => {
const options: ts.CompilerOptions = {allowJs: true, rootDir: entryPointPath};
const options: ts.CompilerOptions = {
allowJs: true,
maxNodeModuleJsDepth: Infinity,
rootDir: entryPointPath,
};
const host = ts.createCompilerHost(options);
const packageProgram = ts.createProgram([entryPointPath], options, host);
const entryPointFile = packageProgram.getSourceFile(entryPointPath) !;