Skip to content

Commit

Permalink
refactor(compiler-cli): remove tsickle from dependencies
Browse files Browse the repository at this point in the history
Users can still install tsickle if they want closure-compatible output.
  • Loading branch information
alexeagle committed Aug 27, 2018
1 parent 241decb commit 363339b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
1 change: 0 additions & 1 deletion packages/compiler-cli/package.json
Expand Up @@ -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",
Expand Down
50 changes: 31 additions & 19 deletions packages/compiler-cli/src/main.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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; }
Expand Down
7 changes: 4 additions & 3 deletions packages/compiler-cli/test/ngc_spec.ts
Expand Up @@ -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';
Expand All @@ -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', () => {
Expand Down

0 comments on commit 363339b

Please sign in to comment.