diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index 1f926637dc..edb982f027 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -12,7 +12,6 @@ "dependencies": { "reflect-metadata": "^0.1.2", "minimist": "^1.2.0", - "tsickle": "^0.32.1", "chokidar": "^1.4.2", "convert-source-map": "^1.5.1", "magic-string": "^0.25.0", diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index 1e17fc9d62..4210b715f1 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -11,11 +11,8 @@ import 'reflect-metadata'; import * as ts from 'typescript'; -import * as fs from 'fs'; -import * as path from 'path'; import * as tsickle from 'tsickle'; import * as api from './transformers/api'; -import * as ngc from './transformers/entry_points'; import {GENERATED_FILES} from './transformers/util'; import {exitCodeFromResult, performCompilation, readConfiguration, formatDiagnostics, Diagnostics, ParsedConfiguration, PerformCompilationResult, filterErrorsAndWarnings} from './perform_compile'; @@ -66,22 +63,37 @@ function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|un convertIndexImportShorthand: false, transformDecorators, transformTypesToClosure, }; - return ({ - program, - targetSourceFile, - writeFile, - cancellationToken, - emitOnlyDtsFiles, - customTransformers = {}, - host, - options - }) => - tsickle.emitWithTsickle( - program, {...tsickleHost, options, host}, host, options, targetSourceFile, - writeFile, cancellationToken, emitOnlyDtsFiles, { - beforeTs: customTransformers.before, - afterTs: customTransformers.after, - }); + if (options.annotateForClosureCompiler || options.annotationsAs === 'static fields') { + return ({ + program, + targetSourceFile, + writeFile, + cancellationToken, + emitOnlyDtsFiles, + customTransformers = {}, + host, + options + }) => + // tslint:disable-next-line:no-require-imports only depend on tsickle if requested + require('tsickle').emitWithTsickle( + program, {...tsickleHost, options, host}, host, options, targetSourceFile, writeFile, + cancellationToken, emitOnlyDtsFiles, { + beforeTs: customTransformers.before, + afterTs: customTransformers.after, + }); + } else { + return ({ + program, + targetSourceFile, + writeFile, + cancellationToken, + emitOnlyDtsFiles, + customTransformers = {}, + }) => + program.emit( + targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, + {after: customTransformers.after, before: customTransformers.before}); + } } export interface NgcParsedConfiguration extends ParsedConfiguration { watch?: boolean; } diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index 239c188ee6..f532ae9564 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -554,10 +554,10 @@ describe('ngc transformer command-line', () => { }); describe('closure', () => { - it('should not generate closure specific code by default', () => { + it('should not run tsickle by default', () => { writeConfig(`{ "extends": "./tsconfig-base.json", - "files": ["mymodule.ts"] + "files": ["mymodule.ts"], }`); write('mymodule.ts', ` import {NgModule, Component} from '@angular/core'; @@ -575,7 +575,8 @@ describe('ngc transformer command-line', () => { const mymodulejs = path.resolve(outDir, 'mymodule.js'); const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8'); expect(mymoduleSource).not.toContain('@fileoverview added by tsickle'); - expect(mymoduleSource).toContain('MyComp.decorators = ['); + expect(mymoduleSource).toContain('MyComp = __decorate'); + expect(mymoduleSource).not.toContain('MyComp.decorators = ['); }); it('should add closure annotations', () => {