Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compiler_cli tests work again #8429

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
93 changes: 50 additions & 43 deletions build.sh
Expand Up @@ -6,7 +6,7 @@ cd `dirname $0`


TSCONFIG=./modules/tsconfig.json
echo "====== (all)COMPILING: \$(npm bin)/ng2tc -p ${TSCONFIG} ====="
echo "====== (all)COMPILING: \$(npm bin)/tsc -p ${TSCONFIG} ====="
rm -rf ./dist/all/
mkdir ./dist/all/

Expand All @@ -27,8 +27,14 @@ ln -s ../../../../node_modules/angular/angular.js .
cd -

# 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

Expand All @@ -42,20 +48,20 @@ for PACKAGE in \
http \
router \
router-deprecated \
upgrade
upgrade \
compiler_cli
do
SRCDIR=./modules/@angular/${PACKAGE}
DESTDIR=./dist/packages-dist/${PACKAGE}
UMDES6PATH=${DESTDIR}/esm/${PACKAGE}.umd.js
UMDES5PATH=${DESTDIR}/${PACKAGE}.umd.js


if [[ ${PACKAGE} == "router-deprecated" ]]; then
echo "====== COMPILING: \$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json ====="
$(npm bin)/tsc -p ${SRCDIR}/tsconfig-es5.json
else
echo "====== COMPILING: \$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es5.json ====="
$(npm bin)/ng2tc -p ${SRCDIR}/tsconfig-es5.json
echo "====== COMPILING: ${NG_TC} -p ${SRCDIR}/tsconfig-es5.json ====="
$NG_TC -p ${SRCDIR}/tsconfig-es5.json
fi

cp ${SRCDIR}/package.json ${DESTDIR}/
Expand All @@ -71,42 +77,43 @@ do
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g'
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


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
1 change: 1 addition & 0 deletions karma-js.conf.js
Expand Up @@ -39,6 +39,7 @@ module.exports = function(config) {
exclude: [
'dist/all/@angular/**/e2e_test/**',
'dist/all/@angular/examples/**',
'dist/all/@angular/compiler_cli/**',
'dist/all/angular1_router.js',
'dist/all/@angular/platform-browser/testing/e2e_util.js'
],
Expand Down
50 changes: 45 additions & 5 deletions modules/@angular/compiler/private_export.ts
@@ -1,5 +1,15 @@
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 type SelectorMatcher = selector.SelectorMatcher;
Expand All @@ -8,9 +18,39 @@ export namespace __compiler_private__ {
export type CssSelector = selector.CssSelector;
export var CssSelector = selector.CssSelector;

export type AssetUrl = pathUtil.AssetUrl;
export var AssetUrl = pathUtil.AssetUrl;
export type AssetUrl = path_util.AssetUrl;
export var AssetUrl = path_util.AssetUrl;

export type ImportGenerator = pathUtil.ImportGenerator;
export var ImportGenerator = pathUtil.ImportGenerator;
export type ImportGenerator = path_util.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;
}
Expand Up @@ -80,18 +80,17 @@ At a high level, this program
## For developers
Run the compiler from source:
```
# Build angular2
./build.sh
# Build the compiler
./node_modules/.bin/tsc -p tools/compiler_cli/src
# Build angular2 and the compiler
./node_modules/.bin/tsc -p modules
# 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:
```
$ gulp test.compiler_cli
$ cp tools/compiler_cli/README.md tools/compiler_cli/package.json dist/tools/compiler_cli
$ node dist/tools/cjs-jasmine -- @angular/compiler_cli/integrationtest/**/*_spec.js
$ cp modules/@angular/compiler_cli/README.md modules/@angular/compiler_cli/package.json dist/all/@angular/compiler_cli
# npm login as angular
$ npm publish dist/tools/compiler_cli/ --access=public
$ npm publish dist/all/@angular/compiler_cli --access=public
```
3 changes: 3 additions & 0 deletions modules/@angular/compiler_cli/index.ts
@@ -0,0 +1,3 @@
export {CodeGenerator} from './src/codegen';
export {NodeReflectorHost} from './src/reflector_host';
export {TsickleHost, MetadataWriterHost} from './src/compiler_host';
@@ -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 path from 'path';

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", () => {
const jsOutput = path.join(outDir, 'basic.js');
Expand All @@ -17,7 +15,7 @@ describe("template codegen output", () => {
expect(fs.existsSync(metadataOutput)).toBeTruthy();
const output = fs.readFileSync(metadataOutput, {encoding: 'utf-8'});
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", () => {
Expand Down
23 changes: 23 additions & 0 deletions modules/@angular/compiler_cli/integrationtest/tsconfig.json
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may as well remove (false is the default and maybe we should just drop this option - no one should be using ngc with a beta version)

},

"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/*"]
}
}
}
4 changes: 4 additions & 0 deletions modules/@angular/compiler_cli/integrationtest/typings.d.ts
@@ -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" />
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"typings": "index.d.ts",
"bin": {
"ngc": "./main.js"
"ngc": "./src/main.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? why is bin pointing under a different path than main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's two different files... Nobody should use main via require, only index.

},
"dependencies": {
"ts-metadata-collector": "^0.1.0",
Expand Down
Expand Up @@ -8,16 +8,11 @@ import * as path from 'path';
import * as compiler from '@angular/compiler';
import {ViewEncapsulation} from '@angular/core';
import {StaticReflector} from './static_reflector';
import {CompileMetadataResolver} from '@angular/compiler/src/metadata_resolver';
import {HtmlParser} from '@angular/compiler/src/html_parser';
import {DirectiveNormalizer} from '@angular/compiler/src/directive_normalizer';
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
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 {CompileMetadataResolver, HtmlParser, DirectiveNormalizer, Lexer, Parser,
TemplateParser, DomElementSchemaRegistry, StyleCompiler,
ViewCompiler, TypeScriptEmitter
} from './compiler_private';

import {Parse5DomAdapter} from '@angular/platform-server';

import {MetadataCollector} from 'ts-metadata-collector';
Expand Down
Expand Up @@ -4,11 +4,6 @@ import {convertDecorators} from 'tsickle';
import {NodeReflectorHost} from './reflector_host';
import {AngularCompilerOptions} from './codegen';

const DEBUG = false;
function debug(msg: string, ...o: any[]) {
if (DEBUG) console.log(msg, ...o);
}

/**
* Implementation of CompilerHost that forwards all methods to another instance.
* Useful for partial implementations to override only methods they care about.
Expand Down Expand Up @@ -37,11 +32,12 @@ export abstract class DelegatingHost implements ts.CompilerHost {
export class TsickleHost extends DelegatingHost {
// Additional diagnostics gathered by pre- and post-emit transformations.
public diagnostics: ts.Diagnostic[] = [];
private TSICKLE_SUPPORT = `interface DecoratorInvocation {
type: Function;
args?: any[];
}
`;
private TSICKLE_SUPPORT = `
interface DecoratorInvocation {
type: Function;
args?: any[];
}
`;
constructor(delegate: ts.CompilerHost, private options: ts.CompilerOptions) { super(delegate); }

getSourceFile =
Expand All @@ -53,8 +49,7 @@ export class TsickleHost extends DelegatingHost {
if (converted.diagnostics) {
this.diagnostics.push(...converted.diagnostics);
}
newContent = this.TSICKLE_SUPPORT + converted.output;
debug(newContent);
newContent = converted.output + this.TSICKLE_SUPPORT;
}
return ts.createSourceFile(fileName, newContent, languageVersion, true);
}
Expand Down
37 changes: 37 additions & 0 deletions modules/@angular/compiler_cli/src/compiler_private.ts
@@ -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;
4 changes: 4 additions & 0 deletions modules/@angular/compiler_cli/src/core_private.ts
@@ -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;