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) !;

View File

@ -72,11 +72,11 @@ describe('ngcc behavioral tests', () => {
setupNodeModules(support);
});
it('should run ngcc without errors', () => {
it('should run ngcc without errors for fesm2015', () => {
const nodeModulesPath = path.join(basePath, 'node_modules');
console.error(nodeModulesPath);
const commonPath = path.join(nodeModulesPath, '@angular/common');
const exitCode = mainNgcc([commonPath]);
const exitCode = mainNgcc([commonPath, 'fesm2015']);
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
@ -85,4 +85,18 @@ describe('ngcc behavioral tests', () => {
expect(exitCode).toBe(0);
});
it('should run ngcc without errors for esm2015', () => {
const nodeModulesPath = path.join(basePath, 'node_modules');
console.error(nodeModulesPath);
const commonPath = path.join(nodeModulesPath, '@angular/common');
const exitCode = mainNgcc([commonPath, 'esm2015']);
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
console.warn(cat('node_modules_ngtsc/@angular/common/esm2015/src/directives/ng_if.js').stdout);
console.warn(cat('node_modules_ngtsc/@angular/common/esm2015/http/src/module.js').stdout);
expect(exitCode).toBe(0);
});
});