fix(ngc): don't codegen foo.d.ngfactory.ts from foo.d.ts (#10833)

This commit is contained in:
Alex Eagle 2016-08-18 10:11:06 -07:00 committed by Kara
parent 292ccf882a
commit cd8cbd3762
4 changed files with 18 additions and 4 deletions

View File

@ -9,6 +9,7 @@
import {ApplicationRef, NgModule} from '@angular/core'; import {ApplicationRef, NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {MdButtonModule} from '@angular2-material/button';
import {AnimateCmp} from './animate'; import {AnimateCmp} from './animate';
import {BasicComp} from './basic'; import {BasicComp} from './basic';
@ -25,7 +26,10 @@ import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
CompWithReferences, CompUsingPipes CompWithReferences, CompUsingPipes
], ],
imports: [BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements], imports: [
BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements,
MdButtonModule
],
providers: [SomeService], providers: [SomeService],
entryComponents: [ entryComponents: [
AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider, AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,

View File

@ -36,6 +36,12 @@ describe('template codegen output', () => {
expect(fs.readFileSync(dtsOutput, {encoding: 'utf-8'})).toContain('Basic'); expect(fs.readFileSync(dtsOutput, {encoding: 'utf-8'})).toContain('Basic');
}); });
it('should write .ngfactory.ts for .d.ts inputs', () => {
const factoryOutput =
path.join('node_modules', '@angular2-material', 'button', 'button.ngfactory.ts');
expect(fs.existsSync(factoryOutput)).toBeTruthy();
});
it('should be able to create the basic component', () => { it('should be able to create the basic component', () => {
var compFixture = createComponent(BasicComp); var compFixture = createComponent(BasicComp);
expect(compFixture.componentInstance).toBeTruthy(); expect(compFixture.componentInstance).toBeTruthy();

View File

@ -58,7 +58,7 @@ export class OfflineCompiler {
compile( compile(
moduleUrl: string, ngModulesSummary: NgModulesSummary, components: StaticSymbol[], moduleUrl: string, ngModulesSummary: NgModulesSummary, components: StaticSymbol[],
ngModules: StaticSymbol[]): Promise<SourceModule[]> { ngModules: StaticSymbol[]): Promise<SourceModule[]> {
let fileSuffix = _splitLastSuffix(moduleUrl)[1]; let fileSuffix = _splitTypescriptSuffix(moduleUrl)[1];
let statements: o.Statement[] = []; let statements: o.Statement[] = [];
let exportedVars: string[] = []; let exportedVars: string[] = [];
let outputSourceModules: SourceModule[] = []; let outputSourceModules: SourceModule[] = [];
@ -203,7 +203,7 @@ function _resolveStyleStatements(
} }
function _ngfactoryModuleUrl(compUrl: string): string { function _ngfactoryModuleUrl(compUrl: string): string {
var urlWithSuffix = _splitLastSuffix(compUrl); var urlWithSuffix = _splitTypescriptSuffix(compUrl);
return `${urlWithSuffix[0]}.ngfactory${urlWithSuffix[1]}`; return `${urlWithSuffix[0]}.ngfactory${urlWithSuffix[1]}`;
} }
@ -221,7 +221,10 @@ function _assertComponent(meta: CompileDirectiveMetadata) {
} }
} }
function _splitLastSuffix(path: string): string[] { function _splitTypescriptSuffix(path: string): string[] {
if (/\.d\.ts$/.test(path)) {
return [path.substring(0, path.length - 5), '.ts'];
}
let lastDot = path.lastIndexOf('.'); let lastDot = path.lastIndexOf('.');
if (lastDot !== -1) { if (lastDot !== -1) {
return [path.substring(0, lastDot), path.substring(lastDot)]; return [path.substring(0, lastDot), path.substring(lastDot)];

View File

@ -13,6 +13,7 @@ PKGS=(
rxjs rxjs
@types/{node,jasmine} @types/{node,jasmine}
jasmine jasmine
@angular2-material/{core,button}
) )
TMPDIR=${TMPDIR:-.} TMPDIR=${TMPDIR:-.}