diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts index bc369b5ada..dd770ae792 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts @@ -47,15 +47,14 @@ export function makeEntryPointBundle( mirrorDtsFromSrc: boolean = false, enableI18nLegacyMessageIdFormat: boolean = true): EntryPointBundle { // Create the TS program and necessary helpers. + const rootDir = entryPoint.package; const options: ts.CompilerOptions = { allowJs: true, maxNodeModuleJsDepth: Infinity, - noLib: true, - rootDir: entryPoint.path, ...pathMappings + noLib: true, rootDir, ...pathMappings }; const srcHost = new NgccSourcesCompilerHost(fs, options, entryPoint.path); const dtsHost = new NgtscCompilerHost(fs, options); - const rootDirs = [absoluteFrom(entryPoint.path)]; // Create the bundle programs, as necessary. const absFormatPath = fs.resolve(entryPoint.path, formatPath); @@ -71,8 +70,11 @@ export function makeEntryPointBundle( null; const isFlatCore = isCore && src.r3SymbolsFile === null; - return {entryPoint, format, rootDirs, isCore, - isFlatCore, src, dts, enableI18nLegacyMessageIdFormat}; + return { + entryPoint, + format, + rootDirs: [rootDir], isCore, isFlatCore, src, dts, enableI18nLegacyMessageIdFormat + }; } function computePotentialDtsFilesFromJsFiles( diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts index 285a219e6f..67bfa6a76c 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts @@ -148,6 +148,16 @@ runInEachFileSystem(() => { name: _('/node_modules/internal/esm2015/src/internal.js'), contents: 'export function internal();' }, + + // A package with a secondary entry-point that has source files in a different tree + { + name: _('/node_modules/primary/secondary/index.d.ts'), + contents: 'export declare function secondary();' + }, + { + name: _('/node_modules/primary/esm2015/secondary/index.js'), + contents: 'export function secondary();' + }, ]); } @@ -268,5 +278,24 @@ runInEachFileSystem(() => { expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName)) .not.toContain(absoluteFrom('/node_modules/test/internal.d.ts')); }); + + it('should set the `rootDir` to the package path not the entry-point path', () => { + setupMockFileSystem(); + const fs = getFileSystem(); + const entryPoint: EntryPoint = { + name: 'secondary', + packageJson: {name: 'secondary'}, + package: absoluteFrom('/node_modules/primary'), + path: absoluteFrom('/node_modules/primary/secondary'), + typings: absoluteFrom('/node_modules/primary/secondary/index.d.ts'), + compiledByAngular: true, + ignoreMissingDependencies: false, + generateDeepReexports: false, + }; + const bundle = makeEntryPointBundle( + fs, entryPoint, './index.js', false, 'esm2015', /* transformDts */ true, + /* pathMappings */ undefined, /* mirrorDtsFromSrc */ true); + expect(bundle.rootDirs).toEqual([absoluteFrom('/node_modules/primary')]); + }); }); });