diff --git a/packages/compiler-cli/src/ngtsc/program.ts b/packages/compiler-cli/src/ngtsc/program.ts index 57e0e706fe..4c53cc12f2 100644 --- a/packages/compiler-cli/src/ngtsc/program.ts +++ b/packages/compiler-cli/src/ngtsc/program.ts @@ -116,7 +116,7 @@ export class NgtscProgram implements api.Program { rootFiles.push(this.typeCheckFilePath); let entryPoint: AbsoluteFsPath|null = null; - if (options.flatModuleOutFile !== undefined) { + if (options.flatModuleOutFile != null && options.flatModuleOutFile !== '') { entryPoint = findFlatIndexEntryPoint(normalizedRootNames); if (entryPoint === null) { // This error message talks specifically about having a single .ts file in "files". However diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index 445c70e569..cf274ab618 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -145,7 +145,8 @@ export class NgtscTestEnvironment { this.multiCompileHostExt.invalidate(absFilePath); } - tsconfig(extraOpts: {[key: string]: string | boolean} = {}, extraRootDirs?: string[]): void { + tsconfig(extraOpts: {[key: string]: string | boolean | null} = {}, extraRootDirs?: string[]): + void { const tsconfig: {[key: string]: any} = { extends: './tsconfig-base.json', angularCompilerOptions: {...extraOpts, enableIvy: true}, diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 018353e709..d1daf105f5 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -2967,6 +2967,35 @@ runInEachFileSystem(os => { expect(env.getContents('./public-api/index.js')).toContain(`export * from '../test';`); }); + it('should not throw if "flatModuleOutFile" is set to null', () => { + env.tsconfig({ + 'flatModuleOutFile': null, + }); + + env.write('test.ts', `export const SOME_EXPORT = 'some-export'`); + // The "driveMain" method automatically ensures that there is no + // exception and that the build succeeded. + env.driveMain(); + }); + + it('should not throw or produce flat module index if "flatModuleOutFile" is set to ' + + 'empty string', + () => { + env.tsconfig({ + 'flatModuleOutFile': '', + }); + + env.write('test.ts', `export const SOME_EXPORT = 'some-export'`); + // The "driveMain" method automatically ensures that there is no + // exception and that the build succeeded. + env.driveMain(); + // Previously ngtsc incorrectly tried generating a flat module index + // file if the "flatModuleOutFile" was set to an empty string. ngtsc + // just wrote the bundle file with an empty filename (just extension). + env.assertDoesNotExist('.js'); + env.assertDoesNotExist('.d.ts'); + }); + it('should report an error when a flat module index is requested but no entrypoint can be determined', () => { env.tsconfig({'flatModuleOutFile': 'flat.js'});