Skip to content

Commit 1d9c44b

Browse files
committed
build: add --projects a.k.a the turbo button
we can now filter build graph via --project flag to speed up build performance usage: gulp test.unit.js --project=angular2,angular2_material Closes angular#5272
1 parent 2ecbd0e commit 1d9c44b

6 files changed

Lines changed: 192 additions & 100 deletions

File tree

gulpfile.js

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,36 @@ var dartSdk = require('./tools/build/dart');
4646
var browserProvidersConf = require('./browser-providers.conf.js');
4747
var os = require('os');
4848

49-
require('./tools/check-environment')({
50-
requiredNpmVersion: '>=2.14.7',
51-
requiredNodeVersion: '>=4.2.1'
52-
});
49+
require('./tools/check-environment')(
50+
{requiredNpmVersion: '>=2.14.7', requiredNodeVersion: '>=4.2.1'});
51+
52+
var cliArgs = minimist(process.argv.slice(2));
53+
54+
if (cliArgs.projects) {
55+
// normalize for analytics
56+
cliArgs.projects.split(',').sort().join(',');
57+
}
58+
59+
// --projects=angular2,angular2_material => {angular2: true, angular2_material: true}
60+
var allProjects =
61+
'angular1_router,angular2,angular2_material,benchmarks,benchmarks_external,benchpress,playground';
62+
var cliArgsProjects = (cliArgs.projects || allProjects)
63+
.split(',')
64+
.reduce((map, projectName) => {
65+
map[projectName] = true;
66+
return map;
67+
}, {});
68+
69+
function printModulesWarning() {
70+
if (!cliArgs.projects && !process.env.CI) {
71+
// if users didn't specify projects to build, tell them why and how they should
72+
console.warn(
73+
"Pro Tip: Did you know that you can speed up your build by specifying project name(s)?");
74+
console.warn(" It's like pressing the turbo button in the old days, but better!");
75+
console.warn(" Examples: --project=angular2 or --project=angular2,angular2_material");
76+
}
77+
}
78+
5379

5480
// Make it easy to quiet down portions of the build.
5581
// --logs=all -> log everything (This is the default)
@@ -162,7 +188,7 @@ gulp.task('build/tree.dart', ['build/clean.dart', 'build.tools'],
162188

163189

164190
gulp.task('!build/tree.dart',
165-
function() { return angularBuilder.rebuildDartTree(); });
191+
function() { return angularBuilder.rebuildDartTree(cliArgsProjects); });
166192

167193

168194
// ------------
@@ -444,15 +470,19 @@ function getBrowsersFromCLI(provider) {
444470
}
445471

446472
gulp.task('test.unit.js', ['build.js.dev'], function(done) {
473+
printModulesWarning();
447474
runSequence('!test.unit.js/karma-server', function() {
448475
watch('modules/**', {ignoreInitial: true}, ['!broccoli.js.dev', '!test.unit.js/karma-run']);
449476
});
450477
});
451478

452-
gulp.task('watch.js.dev', ['build.js.dev'],
453-
function(done) { watch('modules/**', ['!broccoli.js.dev']); });
479+
gulp.task('watch.js.dev', ['build.js.dev'], function(done) {
480+
printModulesWarning();
481+
watch('modules/**', ['!broccoli.js.dev']);
482+
});
454483

455484
gulp.task('test.unit.js.sauce', ['build.js.dev'], function(done) {
485+
printModulesWarning();
456486
var browserConf = getBrowsersFromCLI('SL');
457487
if (browserConf.isProvider) {
458488
launchKarmaWithExternalBrowsers(['dots'], browserConf.browsersToRun, done);
@@ -462,6 +492,7 @@ gulp.task('test.unit.js.sauce', ['build.js.dev'], function(done) {
462492
});
463493

464494
gulp.task('test.unit.js.browserstack', ['build.js.dev'], function(done) {
495+
printModulesWarning();
465496
var browserConf = getBrowsersFromCLI('BS');
466497
if (browserConf.isProvider) {
467498
launchKarmaWithExternalBrowsers(['dots'], browserConf.browsersToRun, done);
@@ -535,6 +566,7 @@ gulp.task('!test.unit.router/karma-run', function(done) {
535566
gulp.task('buildRouter.dev', function() { buildRouter(); });
536567

537568
gulp.task('test.unit.dart', function(done) {
569+
printModulesWarning();
538570
runSequence('build/tree.dart', 'build/pure-packages.dart', '!build/pubget.angular2.dart',
539571
'!build/change_detect.dart', '!build/remove-pub-symlinks', 'build.dart.material.css',
540572
'!test.unit.dart/karma-server', '!test.unit.dart/karma-run', function(error) {
@@ -632,12 +664,9 @@ gulp.task('test.unit.cjs/ci', function(done) {
632664

633665

634666
gulp.task('test.unit.cjs', ['build/clean.js', 'build.tools'], function(neverDone) {
635-
667+
printModulesWarning();
636668
treatTestErrorsAsFatal = false;
637-
638-
var buildAndTest = ['!build.js.cjs', 'test.unit.cjs/ci'];
639-
640-
watch('modules/**', buildAndTest);
669+
watch('modules/**', ['!build.js.cjs', 'test.unit.cjs/ci']);
641670
});
642671

643672
// Use this target to continuously run dartvm unit-tests (such as transformer
@@ -812,12 +841,11 @@ gulp.task('!build.tools', function() {
812841
gulp.task('broccoli.js.dev', ['build.tools'],
813842
function(done) { runSequence('!broccoli.js.dev', sequenceComplete(done)); });
814843

815-
gulp.task('!broccoli.js.dev', () => {
816-
return angularBuilder.rebuildBrowserDevTree();
817-
});
844+
gulp.task('!broccoli.js.dev',
845+
() => { return angularBuilder.rebuildBrowserDevTree(cliArgsProjects); });
818846

819847
gulp.task('!broccoli.js.prod',
820-
function() { return angularBuilder.rebuildBrowserProdTree(); });
848+
function() { return angularBuilder.rebuildBrowserProdTree(cliArgsProjects); });
821849

822850
gulp.task('build.js.dev', ['build/clean.js'], function(done) {
823851
runSequence('broccoli.js.dev', 'build.css.material', sequenceComplete(done));
@@ -840,7 +868,7 @@ var firstBuildJsCjs = true;
840868
* private task
841869
*/
842870
gulp.task('!build.js.cjs', function() {
843-
return angularBuilder.rebuildNodeTree()
871+
return angularBuilder.rebuildNodeTree(cliArgsProjects)
844872
.then(function() {
845873
if (firstBuildJsCjs) {
846874
firstBuildJsCjs = false;

modules/angular2/manual_typings/globals-es6.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
/// <reference path="../typings/hammerjs/hammerjs.d.ts"/>
99
/// <reference path="../typings/jasmine/jasmine.d.ts"/>
1010
/// <reference path="../typings/angular-protractor/angular-protractor.d.ts"/>
11+
12+
// TODO: ideally the node.d.ts reference should be scoped only for files that need and not to all
13+
// the code including client code
14+
/// <reference path="../typings/node/node.d.ts" />
15+
1116
declare var assert: any;
1217

18+
1319
interface BrowserNodeGlobal {
1420
Object: typeof Object;
1521
Array: typeof Array;

tools/broccoli/angular_builder.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ var path = require('path');
77
var printSlowTrees = require('broccoli-slow-trees');
88
var Q = require('q');
99

10+
type ProjectMap = {
11+
[key: string]: boolean
12+
};
13+
1014
/**
1115
* BroccoliBuilder facade for all of our build pipelines.
1216
*/
@@ -21,26 +25,26 @@ export class AngularBuilder {
2125
constructor(public options: AngularBuilderOptions) { this.outputPath = options.outputPath; }
2226

2327

24-
public rebuildBrowserDevTree(): Promise<BuildResult> {
25-
this.browserDevBuilder = this.browserDevBuilder || this.makeBrowserDevBuilder();
28+
public rebuildBrowserDevTree(projects: ProjectMap): Promise<BuildResult> {
29+
this.browserDevBuilder = this.browserDevBuilder || this.makeBrowserDevBuilder(projects);
2630
return this.rebuild(this.browserDevBuilder, 'js.dev');
2731
}
2832

2933

30-
public rebuildBrowserProdTree(): Promise<BuildResult> {
31-
this.browserProdBuilder = this.browserProdBuilder || this.makeBrowserProdBuilder();
34+
public rebuildBrowserProdTree(projects: ProjectMap): Promise<BuildResult> {
35+
this.browserProdBuilder = this.browserProdBuilder || this.makeBrowserProdBuilder(projects);
3236
return this.rebuild(this.browserProdBuilder, 'js.prod');
3337
}
3438

3539

36-
public rebuildNodeTree(): Promise<BuildResult> {
37-
this.nodeBuilder = this.nodeBuilder || this.makeNodeBuilder();
40+
public rebuildNodeTree(projects: ProjectMap): Promise<BuildResult> {
41+
this.nodeBuilder = this.nodeBuilder || this.makeNodeBuilder(projects);
3842
return this.rebuild(this.nodeBuilder, 'js.cjs');
3943
}
4044

4145

42-
public rebuildDartTree(): Promise<BuildResult> {
43-
this.dartBuilder = this.dartBuilder || this.makeDartBuilder();
46+
public rebuildDartTree(projects: ProjectMap): Promise<BuildResult> {
47+
this.dartBuilder = this.dartBuilder || this.makeDartBuilder(projects);
4448
return this.rebuild(this.dartBuilder, 'dart');
4549
}
4650

@@ -54,31 +58,32 @@ export class AngularBuilder {
5458
}
5559

5660

57-
private makeBrowserDevBuilder(): BroccoliBuilder {
58-
let tree = makeBrowserTree({name: 'dev', typeAssertions: true},
61+
private makeBrowserDevBuilder(projects: ProjectMap): BroccoliBuilder {
62+
let tree = makeBrowserTree({name: 'dev', typeAssertions: true, projects: projects},
5963
path.join(this.outputPath, 'js', 'dev'));
6064
return new broccoli.Builder(tree);
6165
}
6266

6367

64-
private makeBrowserProdBuilder(): BroccoliBuilder {
65-
let tree = makeBrowserTree({name: 'prod', typeAssertions: false},
68+
private makeBrowserProdBuilder(projects: ProjectMap): BroccoliBuilder {
69+
let tree = makeBrowserTree({name: 'prod', typeAssertions: false, projects: projects},
6670
path.join(this.outputPath, 'js', 'prod'));
6771
return new broccoli.Builder(tree);
6872
}
6973

7074

71-
private makeNodeBuilder(): BroccoliBuilder {
72-
let tree = makeNodeTree(path.join(this.outputPath, 'js', 'cjs'));
75+
private makeNodeBuilder(projects: ProjectMap): BroccoliBuilder {
76+
let tree = makeNodeTree(projects, path.join(this.outputPath, 'js', 'cjs'));
7377
return new broccoli.Builder(tree);
7478
}
7579

7680

77-
private makeDartBuilder(): BroccoliBuilder {
81+
private makeDartBuilder(projects: ProjectMap): BroccoliBuilder {
7882
let options = {
7983
outputPath: path.join(this.outputPath, 'dart'),
8084
dartSDK: this.options.dartSDK,
81-
logs: this.options.logs
85+
logs: this.options.logs,
86+
projects: projects
8287
};
8388
let tree = makeDartTree(options);
8489
return new broccoli.Builder(tree);

tools/broccoli/broccoli-typescript.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
4747
// in tsc 1.7.x this api was renamed to parseJsonConfigFileContent
4848
// the conversion is a bit awkward, see https://github.com/Microsoft/TypeScript/issues/5276
4949
this.tsOpts = ts.parseConfigFile({compilerOptions: options, files: []}, null, null).options;
50+
51+
// TODO: the above turns rootDir set to './' into an empty string - looks like a tsc bug
52+
// check back when we upgrade to 1.7.x
53+
if (this.tsOpts.rootDir === '') {
54+
this.tsOpts.rootDir = './';
55+
}
5056
this.tsOpts.outDir = this.cachePath;
5157

5258
this.tsServiceHost = new CustomLanguageServiceHost(this.tsOpts, this.rootFilePaths,

0 commit comments

Comments
 (0)