fix(compiler): make watch mode work with `declaration: false`

closes #19464
This commit is contained in:
Tobias Bosch 2017-09-28 11:44:05 -07:00 committed by Victor Berchet
parent 2f6ae527d1
commit 7c1d3e0f5a
2 changed files with 35 additions and 0 deletions

View File

@ -461,6 +461,13 @@ class AngularCompilerProgram implements Program {
sourceFile: baseFile,
});
this.emittedLibrarySummaries.push({fileName: genFile.genFileUrl, text: outData});
if (!this.options.declaration) {
// If we don't emit declarations, still record an empty .ngfactory.d.ts file,
// as we might need it lateron for resolving module names from summaries.
const ngFactoryDts =
genFile.genFileUrl.substring(0, genFile.genFileUrl.length - 15) + '.ngfactory.d.ts';
this.emittedLibrarySummaries.push({fileName: ngFactoryDts, text: ''});
}
} else if (outFileName.endsWith('.d.ts') && baseFile.fileName.endsWith('.d.ts')) {
const dtsSourceFilePath = genFile.genFileUrl.replace(/\.ts$/, '.d.ts');
// Note: Don't use sourceFiles here as the created .d.ts has a path in the outDir,

View File

@ -125,6 +125,34 @@ describe('ng program', () => {
.toBe(false);
});
// Note: this is the case for watch mode with declaration:false
it('should reuse generated code from libraries from old programs with declaration:false',
() => {
compileLib('lib');
testSupport.writeFiles({
'src/main.ts': createModuleAndCompSource('main'),
'src/index.ts': `
export * from './main';
export * from 'lib/index';
`
});
const p1 = compile(undefined, {declaration: false});
expect(p1.getTsProgram().getSourceFiles().some(
sf => /node_modules\/lib\/.*\.ngfactory\.ts$/.test(sf.fileName)))
.toBe(true);
expect(p1.getTsProgram().getSourceFiles().some(
sf => /node_modules\/lib2\/.*\.ngfactory.*$/.test(sf.fileName)))
.toBe(false);
const p2 = compile(p1, {declaration: false});
expect(p2.getTsProgram().getSourceFiles().some(
sf => /node_modules\/lib\/.*\.ngfactory.*$/.test(sf.fileName)))
.toBe(false);
expect(p2.getTsProgram().getSourceFiles().some(
sf => /node_modules\/lib2\/.*\.ngfactory.*$/.test(sf.fileName)))
.toBe(false);
});
it('should store library summaries on emit', () => {
compileLib('lib');
testSupport.writeFiles({