X Tutup
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ tmp
*.js.deps
*.js.map

# Files created by the template compiler
**/*.ngfactory.ts

# Or type definitions we mirror from github
# (NB: these lines are removed in publish-build-artifacts.sh)
**/typings/**/*.d.ts
Expand Down
62 changes: 50 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,22 +452,40 @@ gulp.task('serve.e2e.dart', ['build.js.cjs'], function(neverDone) {
// ------------------
// CI tests suites

function runKarma(configFile, done) {
function execProcess(name, args, done) {
var exec = require('child_process').exec;

var cmd = process.platform === 'win32' ? 'node_modules\\.bin\\karma run ' :
'node node_modules/.bin/karma run ';
cmd += configFile;
exec(cmd, function(e, stdout) {
var cmd = process.platform === 'win32' ? 'node_modules\\.bin\\' + name + ' ' :
'node node_modules/.bin/' + name + ' ';
cmd += args;
exec(cmd, done);
}
function runKarma(configFile, done) {
execProcess('karma', 'run ' + configFile, function(e, stdout) {
// ignore errors, we don't want to fail the build in the interactive (non-ci) mode
// karma server will print all test failures
done();
});
}

// Gulp-typescript doesn't work with typescript@next:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does your PR still require typescript@next? If not, maybe use gulp-typescript?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I still use typescript@next to compile the compiler (it uses baseUrl/paths to resolve the 'angular2' imports)

Copy link
Copy Markdown
Contributor Author

@alexeagle alexeagle Apr 25, 2016

Choose a reason for hiding this comment

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

But, the issue referenced here is resolved, so it may be possible to use gulp-typescript instead.
(Not that it adds anything, I want the tsconfig.json to express everything).
Will try upgrading it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tried newer gulp-typescript, it is still broken. Filed a new issue and referenced in this comment.

Note that I think we should stop using gulp-typescript and store our configuration in tsconfig.json instead. Maybe in a followup PR I'll remove it :)

// https://github.com/ivogabe/gulp-typescript/issues/331
function runTsc(project, done) {
execProcess('tsc', '-p ' + project, function(e, stdout, stderr) {
if (e) {
console.log(stdout);
console.error(stderr);
done(e);
} else {
done();
}
});
}

gulp.task('test.js', function(done) {
runSequence('test.unit.tools/ci', 'test.transpiler.unittest', 'test.unit.js/ci',
'test.unit.cjs/ci', 'test.typings', 'check-public-api', sequenceComplete(done));
runSequence('test.compiler_cli', 'test.unit.tools/ci', 'test.transpiler.unittest',
'test.unit.js/ci', 'test.unit.cjs/ci', 'test.typings', 'check-public-api',
sequenceComplete(done));
});

gulp.task('test.dart', function(done) {
Expand Down Expand Up @@ -768,7 +786,7 @@ gulp.task('!checkAndReport.payload.js', function() {
{
failConditions: PAYLOAD_TESTS_CONFIG.ts[packaging].sizeLimits,
prefix: caseName + '_' + packaging
})
});
}

return PAYLOAD_TESTS_CONFIG.ts.cases.reduce(function(sizeReportingStreams, caseName) {
Expand Down Expand Up @@ -1026,6 +1044,26 @@ gulp.task('!test.typings',
gulp.task('test.typings', ['build.js.cjs'],
function(done) { runSequence('!test.typings', sequenceComplete(done)); });

gulp.task('!build.compiler_cli', ['build.js.cjs'],
function(done) { runTsc('tools/compiler_cli/src', done); });

gulp.task('!test.compiler_cli.codegen', function(done) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the difference between this task and !test.compiler_cli.jasmine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

try {
require('./dist/js/cjs/compiler_cli')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will prevent multiple calls to pick up changes.
You need to spawn a new node process each time you run the test (see the jasmine tests in https://github.com/angular/angular/blob/master/gulpfile.js#L108)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think I care about calling this multiple times in a single process. There is no watch mode for this end-to-end test. I'd rather keep this simple without fork unless there is a good reason?

.main("tools/compiler_cli/test")
.then(function() { done(); })
.catch(function(rej) { done(new Error(rej)); });
} catch (err) {
done(err);
}
});

// End-to-end test for compiler CLI.
// Calls the compiler using its command-line interface, then compiles the app with the codegen.
// TODO(alexeagle): wire up the playground tests with offline compilation, similar to dart.
gulp.task('test.compiler_cli', ['!build.compiler_cli'],
function(done) { runSequence('!test.compiler_cli.codegen', sequenceComplete(done)); });

// -----------------
// orchestrated targets

Expand Down Expand Up @@ -1091,7 +1129,7 @@ gulp.task('!build.tools', function() {
var sourcemaps = require('gulp-sourcemaps');
var tsc = require('gulp-typescript');

var stream = gulp.src(['tools/**/*.ts'])
var stream = gulp.src(['tools/**/*.ts', '!tools/compiler_cli/**'])
.pipe(sourcemaps.init())
.pipe(tsc({
target: 'ES5',
Expand Down Expand Up @@ -1512,7 +1550,7 @@ gulp.on('task_start', (e) => {
analytics.buildSuccess('gulp <startup>', process.uptime() * 1000);
}

analytics.buildStart('gulp ' + e.task)
analytics.buildStart('gulp ' + e.task);
});
gulp.on('task_stop', (e) => {analytics.buildSuccess('gulp ' + e.task, e.duration * 1000)});
gulp.on('task_err', (e) => {analytics.buildError('gulp ' + e.task, e.duration * 1000)});
gulp.on('task_stop', (e) => { analytics.buildSuccess('gulp ' + e.task, e.duration * 1000); });
gulp.on('task_err', (e) => { analytics.buildError('gulp ' + e.task, e.duration * 1000); });
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Directive, Renderer, ElementRef, Self, forwardRef, Provider} from 'angul
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor';
import {CONST_EXPR} from 'angular2/src/facade/lang';

const CHECKBOX_VALUE_ACCESSOR = CONST_EXPR(new Provider(
export const CHECKBOX_VALUE_ACCESSOR = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => CheckboxControlValueAccessor), multi: true}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Directive, ElementRef, Renderer, Self, forwardRef, Provider} from 'angul
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor';
import {isBlank, CONST_EXPR} from 'angular2/src/facade/lang';

const DEFAULT_VALUE_ACCESSOR = CONST_EXPR(new Provider(
export const DEFAULT_VALUE_ACCESSOR = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => DefaultValueAccessor), multi: true}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {Form} from './form_interface';
import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators';
import {AsyncValidatorFn, ValidatorFn} from './validators';

const controlGroupProvider =
export const controlGroupProvider =
CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgControlGroup)}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators';
import {ValidatorFn, AsyncValidatorFn} from './validators';


const controlNameBinding =
export const controlNameBinding =
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgControlName)}));

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/common/forms/directives/ng_form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {AbstractControl, ControlGroup, Control} from '../model';
import {setUpControl, setUpControlGroup, composeValidators, composeAsyncValidators} from './shared';
import {Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators';

const formDirectiveProvider =
export const formDirectiveProvider =
CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgForm)}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './shared';
import {ValidatorFn, AsyncValidatorFn} from './validators';

const formControlBinding =
export const formControlBinding =
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgFormControl)}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {Control, ControlGroup} from '../model';
import {setUpControl, setUpControlGroup, composeValidators, composeAsyncValidators} from './shared';
import {Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators';

const formDirectiveProvider =
export const formDirectiveProvider =
CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgFormModel)}));

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/common/forms/directives/ng_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './shared';
import {ValidatorFn, AsyncValidatorFn} from './validators';

const formControlBinding =
export const formControlBinding =
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgModel)}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Directive, ElementRef, Renderer, Self, forwardRef, Provider} from 'angul
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor';
import {isBlank, CONST_EXPR, NumberWrapper} from 'angular2/src/facade/lang';

const NUMBER_VALUE_ACCESSOR = CONST_EXPR(new Provider(
export const NUMBER_VALUE_ACCESSOR = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => NumberValueAccessor), multi: true}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {NgControl} from 'angular2/src/common/forms/directives/ng_control';
import {CONST_EXPR, looseIdentical, isPresent} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';

const RADIO_VALUE_ACCESSOR = CONST_EXPR(new Provider(
export const RADIO_VALUE_ACCESSOR = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => RadioControlValueAccessor), multi: true}));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {

import {MapWrapper} from 'angular2/src/facade/collection';

const SELECT_VALUE_ACCESSOR = CONST_EXPR(new Provider(
export const SELECT_VALUE_ACCESSOR = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => SelectControlValueAccessor), multi: true}));

function _buildValueString(id: string, value: any): string {
Expand Down
8 changes: 4 additions & 4 deletions modules/angular2/src/common/forms/directives/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface Validator { validate(c: modelModule.AbstractControl): {[key: st

const REQUIRED = Validators.required;

const REQUIRED_VALIDATOR =
export const REQUIRED_VALIDATOR =
CONST_EXPR(new Provider(NG_VALIDATORS, {useValue: REQUIRED, multi: true}));

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ export interface AsyncValidatorFn {
*
* {@example common/forms/ts/validators/validators.ts region='min'}
*/
const MIN_LENGTH_VALIDATOR = CONST_EXPR(
export const MIN_LENGTH_VALIDATOR = CONST_EXPR(
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MinLengthValidator), multi: true}));

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ export class MinLengthValidator implements Validator {
*
* {@example common/forms/ts/validators/validators.ts region='max'}
*/
const MAX_LENGTH_VALIDATOR = CONST_EXPR(
export const MAX_LENGTH_VALIDATOR = CONST_EXPR(
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => MaxLengthValidator), multi: true}));

/**
Expand Down Expand Up @@ -121,7 +121,7 @@ export class MaxLengthValidator implements Validator {
* <input [ngControl]="fullName" pattern="[a-zA-Z ]*">
* ```
*/
const PATTERN_VALIDATOR = CONST_EXPR(
export const PATTERN_VALIDATOR = CONST_EXPR(
new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => PatternValidator), multi: true}));
@Directive({
selector: '[pattern][ngControl],[pattern][ngFormControl],[pattern][ngModel]',
Expand Down
14 changes: 10 additions & 4 deletions modules/angular2/src/compiler/compile_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,20 +468,24 @@ export class CompileTemplateMetadata {
styles: string[];
styleUrls: string[];
ngContentSelectors: string[];
constructor({encapsulation, template, templateUrl, styles, styleUrls, ngContentSelectors}: {
baseUrl: string;
constructor({encapsulation, template, templateUrl, styles, styleUrls, ngContentSelectors,
baseUrl}: {
encapsulation?: ViewEncapsulation,
template?: string,
templateUrl?: string,
styles?: string[],
styleUrls?: string[],
ngContentSelectors?: string[]
ngContentSelectors?: string[],
baseUrl?: string
} = {}) {
this.encapsulation = isPresent(encapsulation) ? encapsulation : ViewEncapsulation.Emulated;
this.template = template;
this.templateUrl = templateUrl;
this.styles = isPresent(styles) ? styles : [];
this.styleUrls = isPresent(styleUrls) ? styleUrls : [];
this.ngContentSelectors = isPresent(ngContentSelectors) ? ngContentSelectors : [];
this.baseUrl = baseUrl;
}

static fromJson(data: {[key: string]: any}): CompileTemplateMetadata {
Expand All @@ -493,7 +497,8 @@ export class CompileTemplateMetadata {
templateUrl: data['templateUrl'],
styles: data['styles'],
styleUrls: data['styleUrls'],
ngContentSelectors: data['ngContentSelectors']
ngContentSelectors: data['ngContentSelectors'],
baseUrl: data['baseUrl']
});
}

Expand All @@ -505,7 +510,8 @@ export class CompileTemplateMetadata {
'templateUrl': this.templateUrl,
'styles': this.styles,
'styleUrls': this.styleUrls,
'ngContentSelectors': this.ngContentSelectors
'ngContentSelectors': this.ngContentSelectors,
'baseUrl': this.baseUrl
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/compiler/directive_normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class DirectiveNormalizer {
template: CompileTemplateMetadata): Promise<CompileTemplateMetadata> {
if (isPresent(template.template)) {
return PromiseWrapper.resolve(this.normalizeLoadedTemplate(
directiveType, template, template.template, directiveType.moduleUrl));
directiveType, template, template.template, template.baseUrl));
} else if (isPresent(template.templateUrl)) {
var sourceAbsUrl = this._urlResolver.resolve(directiveType.moduleUrl, template.templateUrl);
var sourceAbsUrl = this._urlResolver.resolve(template.baseUrl, template.templateUrl);
return this._xhr.get(sourceAbsUrl)
.then(templateContent => this.normalizeLoadedTemplate(directiveType, template,
templateContent, sourceAbsUrl));
Expand All @@ -93,7 +93,7 @@ export class DirectiveNormalizer {
visitor.styleUrls.filter(isStyleUrlResolvable)
.map(url => this._urlResolver.resolve(templateAbsUrl, url))
.concat(templateMeta.styleUrls.filter(isStyleUrlResolvable)
.map(url => this._urlResolver.resolve(directiveType.moduleUrl, url)));
.map(url => this._urlResolver.resolve(templateMeta.baseUrl, url)));

var allResolvedStyles = allStyles.map(style => {
var styleWithImports = extractStyleUrls(this._urlResolver, templateAbsUrl, style);
Expand Down
24 changes: 14 additions & 10 deletions modules/angular2/src/compiler/metadata_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,22 @@ export class CompileMetadataResolver {
var meta = this._directiveCache.get(directiveType);
if (isBlank(meta)) {
var dirMeta = this._directiveResolver.resolve(directiveType);
var moduleUrl = staticTypeModuleUrl(directiveType);
var templateMeta = null;
var changeDetectionStrategy = null;
var viewProviders = [];

if (dirMeta instanceof md.ComponentMetadata) {
assertArrayOfStrings('styles', dirMeta.styles);
var cmpMeta = <md.ComponentMetadata>dirMeta;
moduleUrl = calcModuleUrl(this._reflector, directiveType, cmpMeta);
var viewMeta = this._viewResolver.resolve(directiveType);
assertArrayOfStrings('styles', viewMeta.styles);
templateMeta = new cpl.CompileTemplateMetadata({
encapsulation: viewMeta.encapsulation,
template: viewMeta.template,
templateUrl: viewMeta.templateUrl,
styles: viewMeta.styles,
styleUrls: viewMeta.styleUrls
styleUrls: viewMeta.styleUrls,
baseUrl: calcTemplateBaseUrl(this._reflector, directiveType, cmpMeta)
});
changeDetectionStrategy = cmpMeta.changeDetection;
if (isPresent(dirMeta.viewProviders)) {
Expand All @@ -114,7 +113,7 @@ export class CompileMetadataResolver {
selector: dirMeta.selector,
exportAs: dirMeta.exportAs,
isComponent: isPresent(templateMeta),
type: this.getTypeMetadata(directiveType, moduleUrl),
type: this.getTypeMetadata(directiveType, staticTypeModuleUrl(directiveType)),
template: templateMeta,
changeDetection: changeDetectionStrategy,
inputs: dirMeta.inputs,
Expand Down Expand Up @@ -399,14 +398,19 @@ function staticTypeModuleUrl(value: any): string {
return isStaticType(value) ? value['moduleId'] : null;
}

function calcModuleUrl(reflector: ReflectorReader, type: Type,
cmpMetadata: md.ComponentMetadata): string {
var moduleId = cmpMetadata.moduleId;
if (isPresent(moduleId)) {

function calcTemplateBaseUrl(reflector: ReflectorReader, type: any,
cmpMetadata: md.ComponentMetadata): string {
if (isStaticType(type)) {
return type['filePath'];
}

if (isPresent(cmpMetadata.moduleId)) {
var moduleId = cmpMetadata.moduleId;
var scheme = getUrlScheme(moduleId);
return isPresent(scheme) && scheme.length > 0 ? moduleId :
`package:${moduleId}${MODULE_SUFFIX}`;
} else {
return reflector.importUri(type);
}

return reflector.importUri(type);
}
Loading
X Tutup