diff --git a/packages/compiler-cli/src/ngcc/src/main.ts b/packages/compiler-cli/src/ngcc/src/main.ts index fece2d1369..878507821c 100644 --- a/packages/compiler-cli/src/ngcc/src/main.ts +++ b/packages/compiler-cli/src/ngcc/src/main.ts @@ -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; } diff --git a/packages/compiler-cli/src/ngcc/src/transform/package_transformer.ts b/packages/compiler-cli/src/ngcc/src/transform/package_transformer.ts index ab974015c0..67f2658643 100644 --- a/packages/compiler-cli/src/ngcc/src/transform/package_transformer.ts +++ b/packages/compiler-cli/src/ngcc/src/transform/package_transformer.ts @@ -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) !; diff --git a/packages/compiler-cli/test/ngcc/ngcc_spec.ts b/packages/compiler-cli/test/ngcc/ngcc_spec.ts index aab460be00..bb8fcd8ff4 100644 --- a/packages/compiler-cli/test/ngcc/ngcc_spec.ts +++ b/packages/compiler-cli/test/ngcc/ngcc_spec.ts @@ -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); + }); });