diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 3cc632309f..7b1796aa38 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -154,8 +154,7 @@ export function mainNgcc( // the property as processed even if its underlying format has been built already. if (!compiledFormats.has(formatPath) && (compileAllFormats || isFirstFormat)) { const bundle = makeEntryPointBundle( - fileSystem, entryPoint.path, formatPath, entryPoint.typings, isCore, property, format, - processDts, pathMappings); + fileSystem, entryPoint, formatPath, isCore, property, format, processDts, pathMappings); if (bundle) { logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`); const transformedFiles = transformer.transform(bundle); 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 a8d14a6704..363a644702 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts @@ -10,10 +10,9 @@ import {AbsoluteFsPath, FileSystem, absoluteFrom, resolve} from '../../../src/ng import {NgtscCompilerHost} from '../../../src/ngtsc/file_system/src/compiler_host'; import {PathMappings} from '../utils'; import {BundleProgram, makeBundleProgram} from './bundle_program'; -import {EntryPointFormat, EntryPointJsonProperty} from './entry_point'; +import {EntryPoint, EntryPointFormat, EntryPointJsonProperty} from './entry_point'; import {NgccSourcesCompilerHost} from './ngcc_compiler_host'; - /** * A bundle of files and paths (and TS programs) that correspond to a particular * format of a package entry-point. @@ -38,27 +37,27 @@ export interface EntryPointBundle { * @param transformDts Whether to transform the typings along with this bundle. */ export function makeEntryPointBundle( - fs: FileSystem, entryPointPath: string, formatPath: string, typingsPath: string, - isCore: boolean, formatProperty: EntryPointJsonProperty, format: EntryPointFormat, - transformDts: boolean, pathMappings?: PathMappings): EntryPointBundle|null { + fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean, + formatProperty: EntryPointJsonProperty, format: EntryPointFormat, transformDts: boolean, + pathMappings?: PathMappings): EntryPointBundle|null { // Create the TS program and necessary helpers. const options: ts.CompilerOptions = { allowJs: true, maxNodeModuleJsDepth: Infinity, noLib: true, - rootDir: entryPointPath, ...pathMappings + rootDir: entryPoint.path, ...pathMappings }; - const srcHost = new NgccSourcesCompilerHost(fs, options, entryPointPath); + const srcHost = new NgccSourcesCompilerHost(fs, options, entryPoint.path); const dtsHost = new NgtscCompilerHost(fs, options); - const rootDirs = [absoluteFrom(entryPointPath)]; + const rootDirs = [absoluteFrom(entryPoint.path)]; // Create the bundle programs, as necessary. const src = makeBundleProgram( - fs, isCore, resolve(entryPointPath, formatPath), 'r3_symbols.js', options, srcHost); - const dts = transformDts ? - makeBundleProgram( - fs, isCore, resolve(entryPointPath, typingsPath), 'r3_symbols.d.ts', options, dtsHost) : - null; + fs, isCore, resolve(entryPoint.path, formatPath), 'r3_symbols.js', options, srcHost); + const dts = transformDts ? makeBundleProgram( + fs, isCore, resolve(entryPoint.path, entryPoint.typings), + 'r3_symbols.d.ts', options, dtsHost) : + null; const isFlatCore = isCore && src.r3SymbolsFile === null; return {format, formatProperty, rootDirs, isCore, isFlatCore, src, dts}; 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 8e4714c654..9817784d7d 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 @@ -8,6 +8,7 @@ import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {loadTestFiles} from '../../../test/helpers'; +import {EntryPoint} from '../../src/packages/entry_point'; import {makeEntryPointBundle} from '../../src/packages/entry_point_bundle'; runInEachFileSystem(() => { @@ -128,8 +129,16 @@ runInEachFileSystem(() => { () => { setupMockFileSystem(); const fs = getFileSystem(); - const esm5bundle = makeEntryPointBundle( - fs, '/node_modules/test', './index.js', './index.d.ts', false, 'esm5', 'esm5', true) !; + const entryPoint: EntryPoint = { + name: 'test', + packageJson: {name: 'test'}, + package: absoluteFrom('/node_modules/test'), + path: absoluteFrom('/node_modules/test'), + typings: absoluteFrom('/node_modules/test/index.d.ts'), + compiledByAngular: true, + }; + const esm5bundle = + makeEntryPointBundle(fs, entryPoint, './index.js', false, 'esm5', 'esm5', true) !; expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) .toEqual(jasmine.arrayWithExactContents([ diff --git a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts index caca11c624..1432feea32 100644 --- a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts @@ -356,7 +356,7 @@ runInEachFileSystem(() => { fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty, format: EntryPointFormat): EntryPointBundle { return makeEntryPointBundle( - fs, entryPoint.path, entryPoint.packageJson[formatProperty] !, entryPoint.typings, false, - formatProperty, format, true) !; + fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, formatProperty, format, + true) !; } });