refactor(compiler-cli): remove tsickle from dependencies (#25649)

Users can still install tsickle if they want closure-compatible output.

PR Close #25649
This commit is contained in:
Alex Eagle 2018-08-27 11:04:48 -07:00 committed by Matias Niemelä
parent a22fb91e1a
commit 29761ea5f8
3 changed files with 35 additions and 23 deletions

View File

@ -12,7 +12,6 @@
"dependencies": { "dependencies": {
"reflect-metadata": "^0.1.2", "reflect-metadata": "^0.1.2",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"tsickle": "^0.32.1",
"chokidar": "^1.4.2", "chokidar": "^1.4.2",
"convert-source-map": "^1.5.1", "convert-source-map": "^1.5.1",
"magic-string": "^0.25.0", "magic-string": "^0.25.0",

View File

@ -11,11 +11,8 @@
import 'reflect-metadata'; import 'reflect-metadata';
import * as ts from 'typescript'; import * as ts from 'typescript';
import * as fs from 'fs';
import * as path from 'path';
import * as tsickle from 'tsickle'; import * as tsickle from 'tsickle';
import * as api from './transformers/api'; import * as api from './transformers/api';
import * as ngc from './transformers/entry_points';
import {GENERATED_FILES} from './transformers/util'; import {GENERATED_FILES} from './transformers/util';
import {exitCodeFromResult, performCompilation, readConfiguration, formatDiagnostics, Diagnostics, ParsedConfiguration, PerformCompilationResult, filterErrorsAndWarnings} from './perform_compile'; 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, convertIndexImportShorthand: false, transformDecorators, transformTypesToClosure,
}; };
return ({ if (options.annotateForClosureCompiler || options.annotationsAs === 'static fields') {
program, return ({
targetSourceFile, program,
writeFile, targetSourceFile,
cancellationToken, writeFile,
emitOnlyDtsFiles, cancellationToken,
customTransformers = {}, emitOnlyDtsFiles,
host, customTransformers = {},
options host,
}) => options
tsickle.emitWithTsickle( }) =>
program, {...tsickleHost, options, host}, host, options, targetSourceFile, // tslint:disable-next-line:no-require-imports only depend on tsickle if requested
writeFile, cancellationToken, emitOnlyDtsFiles, { require('tsickle').emitWithTsickle(
beforeTs: customTransformers.before, program, {...tsickleHost, options, host}, host, options, targetSourceFile, writeFile,
afterTs: customTransformers.after, 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; } export interface NgcParsedConfiguration extends ParsedConfiguration { watch?: boolean; }

View File

@ -554,10 +554,10 @@ describe('ngc transformer command-line', () => {
}); });
describe('closure', () => { describe('closure', () => {
it('should not generate closure specific code by default', () => { it('should not run tsickle by default', () => {
writeConfig(`{ writeConfig(`{
"extends": "./tsconfig-base.json", "extends": "./tsconfig-base.json",
"files": ["mymodule.ts"] "files": ["mymodule.ts"],
}`); }`);
write('mymodule.ts', ` write('mymodule.ts', `
import {NgModule, Component} from '@angular/core'; import {NgModule, Component} from '@angular/core';
@ -575,7 +575,8 @@ describe('ngc transformer command-line', () => {
const mymodulejs = path.resolve(outDir, 'mymodule.js'); const mymodulejs = path.resolve(outDir, 'mymodule.js');
const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8'); const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8');
expect(mymoduleSource).not.toContain('@fileoverview added by tsickle'); 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', () => { it('should add closure annotations', () => {