refactor(compiler_cli): move it into modules/@angular and integrate properly into the build

This also does no more depend on a version
on npm for the compiler_cli.

Also runs the tests for tools/metadata
This commit is contained in:
Tobias Bosch 2016-05-03 09:24:09 -07:00
parent 3cfe281790
commit eba6e7946d
41 changed files with 410 additions and 252 deletions

View File

@ -6,7 +6,7 @@ cd `dirname $0`
TSCONFIG=./modules/tsconfig.json TSCONFIG=./modules/tsconfig.json
echo "====== (all)COMPILING: \$(npm bin)/ng2tc -p ${TSCONFIG} =====" echo "====== (all)COMPILING: \$(npm bin)/tsc -p ${TSCONFIG} ====="
rm -rf ./dist/all/ rm -rf ./dist/all/
mkdir ./dist/all/ mkdir ./dist/all/
@ -27,8 +27,14 @@ ln -s ../../../../node_modules/angular/angular.js .
cd - cd -
# compile ts code # compile ts code
$(npm bin)/ng2tc -p ${TSCONFIG} # TODO: Right now we have a cycle in that the compiler_cli depends on Angular
# but we need it to compile Angular.
# The solution right now is to do 2 compilation runs.
# Fix this by separating the metadata extraction into a separate binary that does
# not depend on Angular.
$(npm bin)/tsc -p ${TSCONFIG}
NG_TC="node dist/all/@angular/compiler_cli/src/main"
$NG_TC -p modules/tsconfig.json
rm -rf ./dist/packages-dist rm -rf ./dist/packages-dist
@ -42,20 +48,20 @@ for PACKAGE in \
http \ http \
router \ router \
router-deprecated \ router-deprecated \
upgrade upgrade \
compiler_cli
do do
SRCDIR=./modules/@angular/${PACKAGE} SRCDIR=./modules/@angular/${PACKAGE}
DESTDIR=./dist/packages-dist/${PACKAGE} DESTDIR=./dist/packages-dist/${PACKAGE}
UMDES6PATH=${DESTDIR}/esm/${PACKAGE}.umd.js UMDES6PATH=${DESTDIR}/esm/${PACKAGE}.umd.js
UMDES5PATH=${DESTDIR}/${PACKAGE}.umd.js UMDES5PATH=${DESTDIR}/${PACKAGE}.umd.js
if [[ ${PACKAGE} == "router-deprecated" ]]; then if [[ ${PACKAGE} == "router-deprecated" ]]; then
echo "====== COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json =====" echo "====== COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json ====="
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json $(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json
else else
echo "====== COMPILING: \$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es5.json =====" echo "====== COMPILING: ${NG_TC} -p ${SRCDIR}/tsconfig-es5.json ====="
$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es5.json $NG_TC -p ${SRCDIR}/tsconfig-es5.json
fi fi
cp ${SRCDIR}/package.json ${DESTDIR}/ cp ${SRCDIR}/package.json ${DESTDIR}/
@ -71,42 +77,43 @@ do
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g' find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g'
fi fi
if [[ ${PACKAGE} != compiler_cli ]]; then
if [[ ${PACKAGE} == "router-deprecated" ]]; then
echo "====== (esm)COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json ====="
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json
else
echo "====== (esm)COMPILING: $NG_TC -p ${SRCDIR}/tsconfig-es2015.json ====="
$NG_TC -p ${SRCDIR}/tsconfig-es2015.json
fi
echo "====== BUNDLING: ${SRCDIR} ====="
(
cd ${SRCDIR}
echo "..." # here just to have grep match something and not exit with 1
../../../node_modules/.bin/rollup -c rollup.config.js
) 2>&1 | grep -v "as external dependency"
# workaround for https://github.com/rollup/rollup/issues/626
if [[ ${TRAVIS} ]]; then
sed -i "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
else
sed -i '' "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
fi
$(npm bin)/tsc \
--out ${UMDES5PATH} \
--target es5 \
--allowJs \
${UMDES6PATH} \
modules/\@angular/manual_typings/globals.d.ts \
modules/\@angular/typings/es6-collections/es6-collections.d.ts \
modules/\@angular/typings/es6-promise/es6-promise.d.ts
rm ${UMDES6PATH}
cat ./modules/@angular/license-banner.txt > ${UMDES5PATH}.tmp
cat ${UMDES5PATH} >> ${UMDES5PATH}.tmp
mv ${UMDES5PATH}.tmp ${UMDES5PATH}
if [[ ${PACKAGE} == "router-deprecated" ]]; then
echo "====== (esm)COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json ====="
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es2015.json
else
echo "====== (esm)COMPILING: \$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es2015.json ====="
$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es2015.json
fi fi
echo "====== BUNDLING: ${SRCDIR} ====="
(
cd ${SRCDIR}
echo "..." # here just to have grep match something and not exit with 1
../../../node_modules/.bin/rollup -c rollup.config.js
) 2>&1 | grep -v "as external dependency"
# workaround for https://github.com/rollup/rollup/issues/626
if [[ ${TRAVIS} ]]; then
sed -i "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
else
sed -i '' "s/ class exports\./ class /g" ${DESTDIR}/esm/${PACKAGE}.umd.js
fi
$(npm bin)/tsc \
--out ${UMDES5PATH} \
--target es5 \
--allowJs \
${UMDES6PATH} \
modules/\@angular/manual_typings/globals.d.ts \
modules/\@angular/typings/es6-collections/es6-collections.d.ts \
modules/\@angular/typings/es6-promise/es6-promise.d.ts
rm ${UMDES6PATH}
cat ./modules/@angular/license-banner.txt > ${UMDES5PATH}.tmp
cat ${UMDES5PATH} >> ${UMDES5PATH}.tmp
mv ${UMDES5PATH}.tmp ${UMDES5PATH}
done done

View File

@ -39,6 +39,7 @@ module.exports = function(config) {
exclude: [ exclude: [
'dist/all/@angular/**/e2e_test/**', 'dist/all/@angular/**/e2e_test/**',
'dist/all/@angular/examples/**', 'dist/all/@angular/examples/**',
'dist/all/@angular/compiler_cli/**',
'dist/all/angular1_router.js', 'dist/all/angular1_router.js',
'dist/all/@angular/platform-browser/testing/e2e_util.js' 'dist/all/@angular/platform-browser/testing/e2e_util.js'
], ],

View File

@ -1,5 +1,15 @@
import * as selector from './src/selector'; import * as selector from './src/selector';
import * as pathUtil from './src/output/path_util'; import * as path_util from './src/output/path_util';
import * as metadata_resolver from './src/metadata_resolver';
import * as html_parser from './src/html_parser';
import * as directive_normalizer from './src/directive_normalizer';
import * as lexer from './src/expression_parser/lexer';
import * as parser from './src/expression_parser/parser';
import * as template_parser from './src/template_parser';
import * as dom_element_schema_registry from './src/schema/dom_element_schema_registry';
import * as style_compiler from './src/style_compiler';
import * as view_compiler from './src/view_compiler/view_compiler';
import * as ts_emitter from './src/output/ts_emitter';
export namespace __compiler_private__ { export namespace __compiler_private__ {
export type SelectorMatcher = selector.SelectorMatcher; export type SelectorMatcher = selector.SelectorMatcher;
@ -8,9 +18,39 @@ export namespace __compiler_private__ {
export type CssSelector = selector.CssSelector; export type CssSelector = selector.CssSelector;
export var CssSelector = selector.CssSelector; export var CssSelector = selector.CssSelector;
export type AssetUrl = pathUtil.AssetUrl; export type AssetUrl = path_util.AssetUrl;
export var AssetUrl = pathUtil.AssetUrl; export var AssetUrl = path_util.AssetUrl;
export type ImportGenerator = pathUtil.ImportGenerator; export type ImportGenerator = path_util.ImportGenerator;
export var ImportGenerator = pathUtil.ImportGenerator; export var ImportGenerator = path_util.ImportGenerator;
export type CompileMetadataResolver = metadata_resolver.CompileMetadataResolver;
export var CompileMetadataResolver = metadata_resolver.CompileMetadataResolver;
export type HtmlParser = html_parser.HtmlParser;
export var HtmlParser = html_parser.HtmlParser;
export type DirectiveNormalizer = directive_normalizer.DirectiveNormalizer;
export var DirectiveNormalizer = directive_normalizer.DirectiveNormalizer;
export type Lexer = lexer.Lexer;
export var Lexer = lexer.Lexer;
export type Parser = parser.Parser;
export var Parser = parser.Parser;
export type TemplateParser = template_parser.TemplateParser;
export var TemplateParser = template_parser.TemplateParser;
export type DomElementSchemaRegistry = dom_element_schema_registry.DomElementSchemaRegistry;
export var DomElementSchemaRegistry = dom_element_schema_registry.DomElementSchemaRegistry;
export type StyleCompiler = style_compiler.StyleCompiler;
export var StyleCompiler = style_compiler.StyleCompiler;
export type ViewCompiler = view_compiler.ViewCompiler;
export var ViewCompiler = view_compiler.ViewCompiler;
export type TypeScriptEmitter = ts_emitter.TypeScriptEmitter;
export var TypeScriptEmitter = ts_emitter.TypeScriptEmitter;
} }

View File

@ -80,18 +80,17 @@ At a high level, this program
## For developers ## For developers
Run the compiler from source: Run the compiler from source:
``` ```
# Build angular2 # Build angular2 and the compiler
./build.sh ./node_modules/.bin/tsc -p modules
# Build the compiler
./node_modules/.bin/tsc -p tools/compiler_cli/src
# Run it on the test project # Run it on the test project
node ./dist/tools/compiler_cli/main.js -p tools/compiler_cli/test $ export NODE_PATH=$NODE_PATH:dist/all:dist/tools
$ node dist/packages-dist/compiler_cli/src/main -p modules/@angular/compiler_cli/integrationtest
``` ```
Release: Release:
``` ```
$ gulp test.compiler_cli $ node dist/tools/cjs-jasmine -- @angular/compiler_cli/integrationtest/**/*_spec.js
$ cp tools/compiler_cli/README.md tools/compiler_cli/package.json dist/tools/compiler_cli $ cp modules/@angular/compiler_cli/README.md modules/@angular/compiler_cli/package.json dist/all/@angular/compiler_cli
# npm login as angular # npm login as angular
$ npm publish dist/tools/compiler_cli/ --access=public $ npm publish dist/all/@angular/compiler_cli --access=public
``` ```

View File

@ -0,0 +1,3 @@
export {CodeGenerator} from './src/codegen';
export {NodeReflectorHost} from './src/reflector_host';
export {TsickleHost, MetadataWriterHost} from './src/compiler_host';

View File

@ -1,10 +1,8 @@
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
/// <reference path="../../typings/node/node.d.ts" />
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
describe("template codegen output", () => { describe("template codegen output", () => {
const outDir = path.join('dist', 'tools', 'compiler_cli', 'test', 'built'); const outDir = path.join('dist', 'all', '@angular', 'compiler_cli', 'integrationtest', 'src');
it("should lower Decorators without reflect-metadata", () => { it("should lower Decorators without reflect-metadata", () => {
const jsOutput = path.join(outDir, 'basic.js'); const jsOutput = path.join(outDir, 'basic.js');
@ -17,7 +15,7 @@ describe("template codegen output", () => {
expect(fs.existsSync(metadataOutput)).toBeTruthy(); expect(fs.existsSync(metadataOutput)).toBeTruthy();
const output = fs.readFileSync(metadataOutput, {encoding: 'utf-8'}); const output = fs.readFileSync(metadataOutput, {encoding: 'utf-8'});
expect(output).toContain('"decorators":'); expect(output).toContain('"decorators":');
expect(output).toContain('"name":"Component","module":"angular2/core"'); expect(output).toContain('"name":"Component","module":"@angular/core"');
}); });
it("should write .d.ts files", () => { it("should write .d.ts files", () => {

View File

@ -0,0 +1,23 @@
{
"angularCompilerOptions": {
// For TypeScript 1.8, we have to lay out generated files
// in the same source directory with your code.
"genDir": ".",
"legacyPackageLayout": false
},
"compilerOptions": {
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": false,
"moduleResolution": "node",
"outDir": "../../../../dist/all/@angular/compiler_cli/integrationtest",
"rootDir": "",
"declaration": true,
"baseUrl": ".",
"paths": {
"@angular/*": ["../../../../dist/all/@angular/*"]
}
}
}

View File

@ -0,0 +1,4 @@
/// <reference path="../../typings/es6-collections/es6-collections.d.ts" />
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
/// <reference path="../../typings/node/node.d.ts" />
/// <reference path="../../typings/jasmine/jasmine.d.ts" />

View File

@ -5,7 +5,7 @@
"main": "index.js", "main": "index.js",
"typings": "index.d.ts", "typings": "index.d.ts",
"bin": { "bin": {
"ngc": "./main.js" "ngc": "./src/main.js"
}, },
"dependencies": { "dependencies": {
"ts-metadata-collector": "^0.1.0", "ts-metadata-collector": "^0.1.0",

View File

@ -8,16 +8,11 @@ import * as path from 'path';
import * as compiler from '@angular/compiler'; import * as compiler from '@angular/compiler';
import {ViewEncapsulation} from '@angular/core'; import {ViewEncapsulation} from '@angular/core';
import {StaticReflector} from './static_reflector'; import {StaticReflector} from './static_reflector';
import {CompileMetadataResolver} from '@angular/compiler/src/metadata_resolver'; import {CompileMetadataResolver, HtmlParser, DirectiveNormalizer, Lexer, Parser,
import {HtmlParser} from '@angular/compiler/src/html_parser'; TemplateParser, DomElementSchemaRegistry, StyleCompiler,
import {DirectiveNormalizer} from '@angular/compiler/src/directive_normalizer'; ViewCompiler, TypeScriptEmitter
import {Lexer} from '@angular/compiler/src/expression_parser/lexer'; } from './compiler_private';
import {Parser} from '@angular/compiler/src/expression_parser/parser';
import {TemplateParser} from '@angular/compiler/src/template_parser';
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
import {StyleCompiler} from '@angular/compiler/src/style_compiler';
import {ViewCompiler} from '@angular/compiler/src/view_compiler/view_compiler';
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
import {Parse5DomAdapter} from '@angular/platform-server'; import {Parse5DomAdapter} from '@angular/platform-server';
import {MetadataCollector} from 'ts-metadata-collector'; import {MetadataCollector} from 'ts-metadata-collector';

View File

@ -0,0 +1,37 @@
import {__compiler_private__ as _c} from '@angular/compiler';
export var AssetUrl: typeof _c.AssetUrl = _c.AssetUrl;
export type AssetUrl = _c.AssetUrl;
export var ImportGenerator: typeof _c.ImportGenerator = _c.ImportGenerator;
export type ImportGenerator = _c.ImportGenerator;
export type CompileMetadataResolver = _c.CompileMetadataResolver;
export var CompileMetadataResolver: typeof _c.CompileMetadataResolver = _c.CompileMetadataResolver;
export type HtmlParser = _c.HtmlParser;
export var HtmlParser: typeof _c.HtmlParser = _c.HtmlParser;
export type DirectiveNormalizer = _c.DirectiveNormalizer;
export var DirectiveNormalizer: typeof _c.DirectiveNormalizer = _c.DirectiveNormalizer;
export type Lexer = _c.Lexer;
export var Lexer: typeof _c.Lexer = _c.Lexer;
export type Parser = _c.Parser;
export var Parser: typeof _c.Parser = _c.Parser;
export type TemplateParser = _c.TemplateParser;
export var TemplateParser: typeof _c.TemplateParser = _c.TemplateParser;
export type DomElementSchemaRegistry = _c.DomElementSchemaRegistry;
export var DomElementSchemaRegistry: typeof _c.DomElementSchemaRegistry = _c.DomElementSchemaRegistry;
export type StyleCompiler = _c.StyleCompiler;
export var StyleCompiler: typeof _c.StyleCompiler = _c.StyleCompiler;
export type ViewCompiler = _c.ViewCompiler;
export var ViewCompiler: typeof _c.ViewCompiler = _c.ViewCompiler;
export type TypeScriptEmitter = _c.TypeScriptEmitter;
export var TypeScriptEmitter: typeof _c.TypeScriptEmitter = _c.TypeScriptEmitter;

View File

@ -0,0 +1,4 @@
import {__core_private__ as r, __core_private_types__ as t} from '@angular/core';
export type ReflectorReader = t.ReflectorReader;
export var ReflectorReader: typeof t.ReflectorReader = r.ReflectorReader;

View File

@ -1,7 +1,4 @@
#!/usr/bin/env node #!/usr/bin/env node
// TODO(alexeagle): use --lib=node when available; remove this reference
// https://github.com/Microsoft/TypeScript/pull/7757#issuecomment-205644657
/// <reference path="../../typings/node/node.d.ts"/>
// Must be imported first, because angular2 decorators throws on load. // Must be imported first, because angular2 decorators throws on load.
import 'reflect-metadata'; import 'reflect-metadata';

View File

@ -1,12 +1,3 @@
import {StringMapWrapper, ListWrapper} from '@angular/core/src/facade/collection';
import {
isArray,
isPresent,
isBlank,
isPrimitive,
isStringMap,
FunctionWrapper
} from '@angular/core/src/facade/lang';
import { import {
AttributeMetadata, AttributeMetadata,
DirectiveMetadata, DirectiveMetadata,
@ -23,8 +14,7 @@ import {
ViewQueryMetadata, ViewQueryMetadata,
QueryMetadata, QueryMetadata,
} from '@angular/core'; } from '@angular/core';
import {ReflectorReader} from '@angular/core/src/reflection/reflector_reader'; import {ReflectorReader} from './core_private';
import {reflector} from '@angular/core';
import {Provider} from '@angular/core'; import {Provider} from '@angular/core';
import { import {
HostMetadata, HostMetadata,
@ -89,26 +79,26 @@ export class StaticReflector implements ReflectorReader {
public annotations(type: StaticSymbol): any[] { public annotations(type: StaticSymbol): any[] {
let annotations = this.annotationCache.get(type); let annotations = this.annotationCache.get(type);
if (!isPresent(annotations)) { if (!annotations) {
let classMetadata = this.getTypeMetadata(type); let classMetadata = this.getTypeMetadata(type);
if (isPresent(classMetadata['decorators'])) { if (classMetadata['decorators']) {
annotations = this.simplify(type, classMetadata['decorators']); annotations = this.simplify(type, classMetadata['decorators']);
} else { } else {
annotations = []; annotations = [];
} }
this.annotationCache.set(type, annotations.filter(ann => isPresent(ann))); this.annotationCache.set(type, annotations.filter(ann => !!ann));
} }
return annotations; return annotations;
} }
public propMetadata(type: StaticSymbol): {[key: string]: any} { public propMetadata(type: StaticSymbol): {[key: string]: any} {
let propMetadata = this.propertyCache.get(type); let propMetadata = this.propertyCache.get(type);
if (!isPresent(propMetadata)) { if (!propMetadata) {
let classMetadata = this.getTypeMetadata(type); let classMetadata = this.getTypeMetadata(type);
let members = isPresent(classMetadata) ? classMetadata['members'] : {}; let members = classMetadata ? classMetadata['members'] : {};
propMetadata = mapStringMap(members, (propData, propName) => { propMetadata = mapStringMap(members, (propData, propName) => {
let prop = (<any[]>propData).find(a => a['__symbolic'] == 'property'); let prop = (<any[]>propData).find(a => a['__symbolic'] == 'property');
if (isPresent(prop) && isPresent(prop['decorators'])) { if (prop && prop['decorators']) {
return this.simplify(type, prop['decorators']); return this.simplify(type, prop['decorators']);
} else { } else {
return []; return [];
@ -125,29 +115,29 @@ export class StaticReflector implements ReflectorReader {
} }
try { try {
let parameters = this.parameterCache.get(type); let parameters = this.parameterCache.get(type);
if (!isPresent(parameters)) { if (!parameters) {
let classMetadata = this.getTypeMetadata(type); let classMetadata = this.getTypeMetadata(type);
let members = isPresent(classMetadata) ? classMetadata['members'] : null; let members = classMetadata ? classMetadata['members'] : null;
let ctorData = isPresent(members) ? members['__ctor__'] : null; let ctorData = members ? members['__ctor__'] : null;
if (isPresent(ctorData)) { if (ctorData) {
let ctor = (<any[]>ctorData).find(a => a['__symbolic'] == 'constructor'); let ctor = (<any[]>ctorData).find(a => a['__symbolic'] == 'constructor');
let parameterTypes = <any[]>this.simplify(type, ctor['parameters']); let parameterTypes = <any[]>this.simplify(type, ctor['parameters']);
let parameterDecorators = <any[]>this.simplify(type, ctor['parameterDecorators']); let parameterDecorators = <any[]>this.simplify(type, ctor['parameterDecorators']);
parameters = []; parameters = [];
ListWrapper.forEachWithIndex(parameterTypes, (paramType, index) => { parameterTypes.forEach( (paramType, index) => {
let nestedResult: any[] = []; let nestedResult: any[] = [];
if (isPresent(paramType)) { if (paramType) {
nestedResult.push(paramType); nestedResult.push(paramType);
} }
let decorators = isPresent(parameterDecorators) ? parameterDecorators[index] : null; let decorators = parameterDecorators ? parameterDecorators[index] : null;
if (isPresent(decorators)) { if (decorators) {
ListWrapper.addAll(nestedResult, decorators); nestedResult.push(...decorators);
} }
parameters.push(nestedResult); parameters.push(nestedResult);
}); });
} }
if (!isPresent(parameters)) { if (!parameters) {
parameters = []; parameters = [];
} }
this.parameterCache.set(type, parameters); this.parameterCache.set(type, parameters);
@ -162,16 +152,18 @@ export class StaticReflector implements ReflectorReader {
private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void { private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void {
this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => { this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => {
let argValues: any[] = []; let argValues: any[] = [];
ListWrapper.forEachWithIndex(args, (arg, index) => { args.forEach( (arg, index) => {
let argValue: any; let argValue: any;
if (isStringMap(arg) && isBlank(arg['__symbolic'])) { if (typeof arg === 'object' && !arg['__symbolic']) {
argValue = mapStringMap(arg, (value, key) => this.simplify(context, value)); argValue = mapStringMap(arg, (value, key) => this.simplify(context, value));
} else { } else {
argValue = this.simplify(context, arg); argValue = this.simplify(context, arg);
} }
argValues.push(argValue); argValues.push(argValue);
}); });
return FunctionWrapper.apply(reflector.factory(ctor), argValues); var metadata = Object.create(ctor.prototype);
ctor.apply(metadata, argValues);
return metadata;
}); });
} }
@ -239,15 +231,15 @@ export class StaticReflector implements ReflectorReader {
if (isPrimitive(expression)) { if (isPrimitive(expression)) {
return expression; return expression;
} }
if (isArray(expression)) { if (expression instanceof Array) {
let result: any[] = []; let result: any[] = [];
for (let item of(<any>expression)) { for (let item of(<any>expression)) {
result.push(simplify(item)); result.push(simplify(item));
} }
return result; return result;
} }
if (isPresent(expression)) { if (expression) {
if (isPresent(expression['__symbolic'])) { if (expression['__symbolic']) {
let staticSymbol: StaticSymbol; let staticSymbol: StaticSymbol;
switch (expression['__symbolic']) { switch (expression['__symbolic']) {
case "binop": case "binop":
@ -312,15 +304,15 @@ export class StaticReflector implements ReflectorReader {
case "index": case "index":
let indexTarget = simplify(expression['expression']); let indexTarget = simplify(expression['expression']);
let index = simplify(expression['index']); let index = simplify(expression['index']);
if (isPresent(indexTarget) && isPrimitive(index)) return indexTarget[index]; if (indexTarget && isPrimitive(index)) return indexTarget[index];
return null; return null;
case "select": case "select":
let selectTarget = simplify(expression['expression']); let selectTarget = simplify(expression['expression']);
let member = simplify(expression['member']); let member = simplify(expression['member']);
if (isPresent(selectTarget) && isPrimitive(member)) return selectTarget[member]; if (selectTarget && isPrimitive(member)) return selectTarget[member];
return null; return null;
case "reference": case "reference":
if (isPresent(expression['module'])) { if (expression['module']) {
staticSymbol = _this.host.findDeclaration(expression['module'], expression['name'], staticSymbol = _this.host.findDeclaration(expression['module'], expression['name'],
context.filePath); context.filePath);
} else { } else {
@ -329,8 +321,8 @@ export class StaticReflector implements ReflectorReader {
let result = staticSymbol; let result = staticSymbol;
let moduleMetadata = _this.getModuleMetadata(staticSymbol.filePath); let moduleMetadata = _this.getModuleMetadata(staticSymbol.filePath);
let declarationValue = let declarationValue =
isPresent(moduleMetadata) ? moduleMetadata['metadata'][staticSymbol.name] : null; moduleMetadata ? moduleMetadata['metadata'][staticSymbol.name] : null;
if (isPresent(declarationValue)) { if (declarationValue) {
result = _this.simplify(staticSymbol, declarationValue); result = _this.simplify(staticSymbol, declarationValue);
} }
return result; return result;
@ -342,9 +334,9 @@ export class StaticReflector implements ReflectorReader {
staticSymbol = staticSymbol =
_this.host.findDeclaration(target['module'], target['name'], context.filePath); _this.host.findDeclaration(target['module'], target['name'], context.filePath);
let converter = _this.conversionMap.get(staticSymbol); let converter = _this.conversionMap.get(staticSymbol);
if (isPresent(converter)) { if (converter) {
let args = expression['arguments']; let args = expression['arguments'];
if (isBlank(args)) { if (!args) {
args = []; args = [];
} }
return converter(context, args); return converter(context, args);
@ -367,9 +359,9 @@ export class StaticReflector implements ReflectorReader {
*/ */
public getModuleMetadata(module: string): {[key: string]: any} { public getModuleMetadata(module: string): {[key: string]: any} {
let moduleMetadata = this.metadataCache.get(module); let moduleMetadata = this.metadataCache.get(module);
if (!isPresent(moduleMetadata)) { if (!moduleMetadata) {
moduleMetadata = this.host.getMetadataFor(module); moduleMetadata = this.host.getMetadataFor(module);
if (!isPresent(moduleMetadata)) { if (!moduleMetadata) {
moduleMetadata = {__symbolic: "module", module: module, metadata: {}}; moduleMetadata = {__symbolic: "module", module: module, metadata: {}};
} }
this.metadataCache.set(module, moduleMetadata); this.metadataCache.set(module, moduleMetadata);
@ -380,7 +372,7 @@ export class StaticReflector implements ReflectorReader {
private getTypeMetadata(type: StaticSymbol): {[key: string]: any} { private getTypeMetadata(type: StaticSymbol): {[key: string]: any} {
let moduleMetadata = this.getModuleMetadata(type.filePath); let moduleMetadata = this.getModuleMetadata(type.filePath);
let result = moduleMetadata['metadata'][type.name]; let result = moduleMetadata['metadata'][type.name];
if (!isPresent(result)) { if (!result) {
result = {__symbolic: "class"}; result = {__symbolic: "class"};
} }
return result; return result;
@ -389,8 +381,12 @@ export class StaticReflector implements ReflectorReader {
function mapStringMap(input: {[key: string]: any}, function mapStringMap(input: {[key: string]: any},
transform: (value: any, key: string) => any): {[key: string]: any} { transform: (value: any, key: string) => any): {[key: string]: any} {
if (isBlank(input)) return {}; if (!input) return {};
var result: {[key: string]: any} = {}; var result: {[key: string]: any} = {};
StringMapWrapper.keys(input).forEach((key) => { result[key] = transform(input[key], key); }); Object.keys(input).forEach((key) => { result[key] = transform(input[key], key); });
return result; return result;
} }
function isPrimitive(o: any):boolean {
return o === null || (typeof o !== "function" && typeof o !== "object");
}

View File

@ -1,5 +1,3 @@
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
import { import {
describe, describe,
it, it,
@ -11,7 +9,7 @@ import {
import {isBlank} from '@angular/facade/src/lang'; import {isBlank} from '@angular/facade/src/lang';
import {ListWrapper} from '@angular/facade/src/collection'; import {ListWrapper} from '@angular/facade/src/collection';
import {StaticReflector, StaticReflectorHost, StaticSymbol} from './static_reflector'; import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler_cli/src/static_reflector';
describe('StaticReflector', () => { describe('StaticReflector', () => {
let noContext = new StaticSymbol('', ''); let noContext = new StaticSymbol('', '');

View File

@ -0,0 +1,34 @@
{
"angularCompilerOptions": {
"skipTemplateCodegen": true
},
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"noImplicitAny": true,
"sourceMap": true,
"baseUrl": ".",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/common": ["../../../dist/packages-dist/common"],
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
"@angular/platform-server": ["../../../dist/packages-dist/platform-server"],
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
"ts-metadata-collector": ["dist/tools/metadata"]
},
"experimentalDecorators": true,
"rootDir": ".",
"sourceRoot": ".",
"outDir": "../../../dist/packages-dist/compiler_cli",
"declaration": true
},
"exclude": ["integrationtest"],
"files": [
"index.ts",
"src/main.ts",
"../typings/node/node.d.ts",
"../typings/jasmine/jasmine.d.ts",
"../../../node_modules/zone.js/dist/zone.js.d.ts"
]
}

View File

@ -1,7 +1,7 @@
import {__compiler_private__ as _} from '@angular/compiler'; import {__compiler_private__ as _c} from '@angular/compiler';
export type SelectorMatcher = typeof _.SelectorMatcher; export type SelectorMatcher = typeof _c.SelectorMatcher;
export var SelectorMatcher: typeof _.SelectorMatcher = _.SelectorMatcher; export var SelectorMatcher: typeof _c.SelectorMatcher = _c.SelectorMatcher;
export type CssSelector = typeof _.CssSelector; export type CssSelector = typeof _c.CssSelector;
export var CssSelector: typeof _.CssSelector = _.CssSelector; export var CssSelector: typeof _c.CssSelector = _c.CssSelector;

View File

@ -28,6 +28,7 @@
"payload_tests", "payload_tests",
"rollup-test", "rollup-test",
"upgrade-ts2dart.d.ts", "upgrade-ts2dart.d.ts",
"zone-ts2dart.d.ts" "zone-ts2dart.d.ts",
"@angular/compiler_cli/integrationtest"
] ]
} }

View File

@ -10,7 +10,16 @@ source ./env.sh
cd ../.. cd ../..
$(npm bin)/tsc -p ./tools/tsconfig.json $(npm bin)/tsc -p ./tools/tsconfig.json
$(npm bin)/ng2tc -p ./modules/tsconfig.json
$(npm bin)/tsc -p ./tools/compiler_cli/src/tsconfig.json # TODO: Right now we have a cycle in that the compiler_cli depends on Angular
# but we need it to compile Angular.
# The solution right now is to do 2 compilation runs.
# Fix this by separating the metadata extraction into a separate binary that does
# not depend on Angular.
$(npm bin)/tsc -p ./modules/tsconfig.json
node dist/all/@angular/compiler_cli/src/main -p modules/tsconfig.json
# Compile the compiler_cli integration tests
node dist/all/@angular/compiler_cli/src/main -p modules/@angular/compiler_cli/integrationtest
echo 'travis_fold:end:BUILD' echo 'travis_fold:end:BUILD'

View File

@ -41,7 +41,7 @@ fi
# Append dist/all to the NODE_PATH so that cjs module resolver finds find the packages that use # Append dist/all to the NODE_PATH so that cjs module resolver finds find the packages that use
# absolute module ids (e.g. @angular/core) # absolute module ids (e.g. @angular/core)
export NODE_PATH=${NODE_PATH}:$(pwd)/../../dist/all export NODE_PATH=${NODE_PATH}:$(pwd)/../../dist/all:$(pwd)/../../dist/tools
export LOGS_DIR=/tmp/angular-build/logs export LOGS_DIR=/tmp/angular-build/logs
if [[ ${TRAVIS} ]]; then if [[ ${TRAVIS} ]]; then

View File

@ -15,20 +15,33 @@ source ./env.sh
cd ../.. cd ../..
echo 'travis_fold:start:test.unit.tools'
# Run unit tests in tools
node ./dist/tools/tsc-watch/ tools triggerCmds
echo 'travis_fold:end:test.unit.tools'
echo 'travis_fold:start:test.unit.node' echo 'travis_fold:start:test.unit.node'
gulp test.compiler_cli
# Run unit tests in node # Run unit tests in node
node ./dist/tools/tsc-watch/ node node ./dist/tools/tsc-watch/ node triggerCmds
echo 'travis_fold:end:test.unit.node' echo 'travis_fold:end:test.unit.node'
echo 'travis_fold:start:test.compiler_cli.node'
echo 'travis_fold:start:test.unit.localChrome' # Run compiler_cli integration tests in node
node dist/tools/cjs-jasmine -- @angular/compiler_cli/integrationtest/**/*_spec.js
echo 'travis_fold:end:test.compiler_cli.node'
# rebuild since codegen has overwritten some files. # rebuild since codegen has overwritten some files.
$(npm bin)/ng2tc -p modules/tsconfig.json node dist/all/@angular/compiler_cli/src/main -p modules/tsconfig.json
echo 'travis_fold:start:test.unit.localChrome'
# Run unit tests in local chrome # Run unit tests in local chrome
if [[ ${TRAVIS} ]]; then if [[ ${TRAVIS} ]]; then

View File

@ -0,0 +1,51 @@
'use strict';
var glob = require('glob');
var JasmineRunner = require('jasmine');
var path = require('path');
// require('es6-shim/es6-shim.js');
require('zone.js/dist/zone-node.js');
require('zone.js/dist/long-stack-trace-zone.js');
require('zone.js/dist/async-test.js');
require('zone.js/dist/fake-async-test.js');
var jrunner = new JasmineRunner();
var toolsDir = process.cwd() + '/dist/tools';
function toolsDirRequire(moduleId) {
return require(path.join(toolsDir, moduleId));
}
// Tun on full stack traces in errors to help debugging
Error['stackTraceLimit'] = Infinity;
jrunner.jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
// Support passing multiple globs
var globsIndex = process.argv.indexOf('--');
var args;
if (globsIndex < 0) {
args = [process.argv[2]];
} else {
args = process.argv.slice(globsIndex + 1);
}
var specFiles =
args.map(function(globstr) {
return glob.sync(globstr, {
cwd: toolsDir
});
})
.reduce(function(specFiles, paths) { return specFiles.concat(paths); }, []);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') === -1});
jrunner.onComplete(function(passed) { process.exit(passed ? 0 : 1); });
jrunner.projectBaseDir = path.resolve(__dirname, '../../');
jrunner.specDir = '';
require('zone.js/dist/jasmine-patch.js');
specFiles.forEach((file) => {
toolsDirRequire(file);
});
jrunner.execute();

View File

@ -1,7 +0,0 @@
import {__compiler_private__ as _} from '@angular/compiler';
export var AssetUrl: typeof _.AssetUrl = _.AssetUrl;
export type AssetUrl = _.AssetUrl;
export var ImportGenerator: typeof _.ImportGenerator = _.ImportGenerator;
export type ImportGenerator = _.ImportGenerator;

View File

@ -1,3 +0,0 @@
export {CodeGenerator} from './codegen';
export {NodeReflectorHost} from './reflector_host';
export {TsickleHost, MetadataWriterHost} from './compiler_host';

View File

@ -1,22 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"noImplicitAny": true,
"sourceMap": true,
"baseUrl": "../../..",
"paths": {
"@angular/*": ["dist/all/@angular/*"],
"@angular/core": ["dist/all/@angular/core/"],
"@angular/compiler": ["dist/all/@angular/compiler/"],
"ts-metadata-collector": ["dist/tools/metadata"]
},
"experimentalDecorators": true,
"rootDir": ".",
// Write to a directory that has the node_modules symlink in a parent
"outDir": "../../../dist/tools/compiler_cli",
"declaration": true
},
"exclude": ["test"]
}

View File

@ -1,31 +0,0 @@
{
"angularCompilerOptions": {
// For TypeScript 1.8, we have to lay out generated files
// in the same source directory with your code.
"genDir": ".",
"legacyPackageLayout": false
},
"compilerOptions": {
"target": "es6",
"experimentalDecorators": true,
"noImplicitAny": false,
"moduleResolution": "node",
"outDir": "../../../dist/tools/compiler_cli/test/built",
"rootDir": "src",
"declaration": true,
/**
* These options are only needed because the test depends
* on locally-built sources, not NPM distributions.
*/
"baseUrl": "../../..",
"paths": {
"@angular/*": ["dist/all/@angular/*"],
"@angular/core": ["dist/all/@angular/core/"],
"@angular/compiler": ["dist/all/@angular/compiler/"],
"rxjs/*": ["node_modules/rxjs/*"],
"ts-metadata-collector": ["dist/tools/metadata"]
}
}
}

View File

@ -4,51 +4,49 @@ import {writeFileSync, mkdirSync, existsSync} from 'fs';
export * from './tsc_watch'; export * from './tsc_watch';
import 'reflect-metadata'; import 'reflect-metadata';
const OFFLINE_COMPILE = const OFFLINE_COMPILE = [
[ 'output/output_emitter_codegen_untyped',
'output/output_emitter_codegen_untyped', 'output/output_emitter_codegen_typed',
'output/output_emitter_codegen_typed', 'offline_compiler_codegen_untyped',
'offline_compiler_codegen_untyped', 'offline_compiler_codegen_typed'
'offline_compiler_codegen_typed' ];
]
function function processOutputEmitterCodeGen():
processOutputEmitterCodeGen(): Promise<number> {
Promise<number> { return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => { var outDir = 'dist/all/@angular/compiler/test/';
var outDir = 'dist/all/@angular/compiler/test/'; var promises = [];
var promises = []; console.log('Processing codegen...');
console.log('Processing codegen...'); OFFLINE_COMPILE.forEach((file: string) => {
OFFLINE_COMPILE.forEach((file: string) => { var codegen = require('../../all/@angular/compiler/test/' + file + '.js');
var codegen = require('../../all/@angular/compiler/test/' + file + '.js'); if (codegen.emit) {
if (codegen.emit) { console.log(` ${file} has changed, regenerating...`);
console.log(` ${file} has changed, regenerating...`); promises.push(
promises.push( Promise.resolve(codegen.emit())
Promise.resolve(codegen.emit()) .then((code) => { writeFileSync(outDir + file + '.ts', code); }));
.then((code) => { writeFileSync(outDir + file + '.ts', code); })); }
} });
}); if (promises.length) {
if (promises.length) { Promise.all(promises)
Promise.all(promises) .then(() => {
.then(() => { var args = [
var args = [ '--project',
'--project', 'tools/cjs-jasmine/tsconfig-output_emitter_codegen.json'
'tools/cjs-jasmine/tsconfig-output_emitter_codegen.json' ];
]; console.log(' compiling changes: tsc ' + args.join(' '));
console.log(' compiling changes: tsc ' + args.join(' ')); var tsc = spawn(TSC, args, {stdio: 'pipe'});
var tsc = spawn(TSC, args, {stdio: 'pipe'}); tsc.stdout.on('data', (data) => process.stdout.write(data));
tsc.stdout.on('data', (data) => process.stdout.write(data)); tsc.stderr.on('data', (data) => process.stderr.write(data));
tsc.stderr.on('data', (data) => process.stderr.write(data)); tsc.on('close', (code) => code ? reject('Tsc exited with: ' + code) :
tsc.on('close', (code) => code ? reject('Tsc exited with: ' + code) : resolve(code));
resolve(code)); })
}) .catch(reportError);
.catch(reportError); } else {
} else { resolve(0);
resolve(0); }
} })
}) .catch(reportError);
.catch(reportError); }
}
function md(dir: string, folders: string[]) { function md(dir: string, folders: string[]) {
if (folders.length) { if (folders.length) {
@ -63,7 +61,7 @@ function md(dir: string, folders: string[]) {
var tscWatch: TscWatch = null; var tscWatch: TscWatch = null;
var platform = process.argv.length >= 3 ? process.argv[2] : null; var platform = process.argv.length >= 3 ? process.argv[2] : null;
var watch: boolean = process.argv.length >= 4 ? !!process.argv[3] : false; var runMode: string = process.argv.length >= 4 ? process.argv[3] : null;
if (platform == 'node') { if (platform == 'node') {
tscWatch = new TscWatch({ tscWatch = new TscWatch({
@ -73,7 +71,7 @@ if (platform == 'node') {
complete: 'Compilation complete. Watching for file changes.', complete: 'Compilation complete. Watching for file changes.',
onChangeCmds: [ onChangeCmds: [
processOutputEmitterCodeGen, processOutputEmitterCodeGen,
['node', 'dist/tools/cjs-jasmine', '--', '{@angular,benchpress}/**/*_spec.js'] ['node', 'dist/tools/cjs-jasmine', '--', '{@angular,benchpress}/**/*_spec.js', '@angular/compiler_cli/test/**/*_spec.js']
] ]
}); });
} else if (platform == 'browser') { } else if (platform == 'browser') {
@ -86,6 +84,24 @@ if (platform == 'node') {
[['node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', 'karma-js.conf.js']], [['node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', 'karma-js.conf.js']],
onChangeCmds: [['node', 'node_modules/karma/bin/karma', 'run', 'karma-js.conf.js']] onChangeCmds: [['node', 'node_modules/karma/bin/karma', 'run', 'karma-js.conf.js']]
}); });
} else if (platform == 'tools') {
tscWatch = new TscWatch({
tsconfig: 'tools/tsconfig.json',
start: 'File change detected. Starting incremental compilation...',
error: 'error',
complete: 'Compilation complete. Watching for file changes.',
onChangeCmds: [
// TODO: fix and enable tests for public_api_spec again!
// ['node', 'dist/tools/cjs-jasmine/index-tools', '--', '{metadata,public_api_guard}/**/*{_,.}spec.js']
['node', 'dist/tools/cjs-jasmine/index-tools', '--', 'metadata/**/*{_,.}spec.js']
]
});
} }
watch ? tscWatch.watch() : tscWatch.run(); if (runMode === 'watch') {
tscWatch.watch();
} else if (runMode === 'triggerCmds') {
tscWatch.triggerCmds();
} else {
tscWatch.run();
}

View File

@ -8,7 +8,6 @@ enum State {
} }
export const TSC = 'node_modules/typescript/bin/tsc'; export const TSC = 'node_modules/typescript/bin/tsc';
export const NG2TC = 'node_modules/.bin/ng2tc';
export type Command = (stdIn, stdErr) => Promise<number>; export type Command = (stdIn, stdErr) => Promise<number>;
export class TscWatch { export class TscWatch {
@ -40,10 +39,7 @@ export class TscWatch {
} }
watch() { watch() {
// TODO(tbosch): We don't support ng2tc in watch mode yet, var args = [TSC, '--project', this.tsconfig];
// so we fall back to plain tsc. However, we don't use
// the preprocessing of tsickle regarding decorators...
var args = [this.runOnce ? NG2TC : TSC, '--project', this.tsconfig];
if (!this.runOnce) args.push('--watch'); if (!this.runOnce) args.push('--watch');
var tsc = var tsc =
this.runCmd(args, {}, (d) => this.consumeLine(d, false), (d) => this.consumeLine(d, true)); this.runCmd(args, {}, (d) => this.consumeLine(d, false), (d) => this.consumeLine(d, true));

View File

@ -15,7 +15,6 @@
"target": "es5" "target": "es5"
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules"
"compiler_cli"
] ]
} }