Skip to content

Commit 013e1fa

Browse files
committed
fix(build): support transpile to commonjs
1 parent fc1b791 commit 013e1fa

44 files changed

Lines changed: 189 additions & 112 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ to the preprocessor and run the tests without exiting karma
5656

5757
### Performance tests
5858

59-
1. `gulp build.cjs` (builds benchpress and tests into `dist/cjs` folder)
59+
1. `gulp build.js.cjs` (builds benchpress and tests into `dist/js/cjs` folder)
6060
2. `gulp serve.js.prod serve.js.dart2js` (runs local webserver)
6161
3. `protractor protractor-perf-js.conf.js`: JS performance tests
6262
4. `protractor protractor-perf-dart2js.conf.js`: Dart2JS performance tests

gulpfile.js

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var deps = require('./tools/build/deps');
99
var transpile = require('./tools/build/transpile');
1010
var html = require('./tools/build/html');
1111
var pubspec = require('./tools/build/pubspec');
12+
var linknodemodules = require('./tools/build/linknodemodules');
1213
var pubbuild = require('./tools/build/pubbuild');
1314
var dartanalyzer = require('./tools/build/dartanalyzer');
1415
var jsserve = require('./tools/build/jsserve');
@@ -32,18 +33,6 @@ var _COMPILER_CONFIG_JS_DEFAULT = {
3233
modules: 'instantiate'
3334
};
3435

35-
var CJS_COMPILER_OPTIONS = {
36-
sourceMaps: true,
37-
annotations: false, // parse annotations
38-
types: false, // parse types
39-
// TODO(tbosch): Right now, traceur generates imports that
40-
// rely on absolute paths. This is why we are not using this...
41-
script: true, // parse as a script
42-
memberVariables: false, // parse class fields
43-
typeAssertions: false,
44-
modules: null // not needed
45-
};
46-
4736
var _HTLM_DEFAULT_SCRIPTS_JS = [
4837
{src: '/deps/traceur-runtime.js', mimeType: 'text/javascript'},
4938
{src: '/rtts_assert/rtts_assert.js', mimeType: 'text/javascript'},
@@ -76,14 +65,10 @@ var CONFIG = {
7665
es6: 'dist/js/prod/es6',
7766
es5: 'dist/js/prod/es5'
7867
},
68+
cjs: 'dist/js/cjs',
7969
dart2js: 'dist/js/dart2js'
8070
},
8171
dart: 'dist/dart',
82-
cjs: {
83-
all: 'dist/cjs',
84-
tools: 'dist/cjs/tools',
85-
e2eTest: 'dist/cjs/e2e_test'
86-
},
8772
docs: 'dist/docs'
8873
},
8974
srcFolderInsertion: {
@@ -119,20 +104,12 @@ var CONFIG = {
119104
},
120105
transpile: {
121106
src: {
122-
js: ['modules/**/*.js', 'modules/**/*.es6', '!modules/**/e2e_test/**'],
123-
dart: ['modules/**/*.js', '!modules/**/e2e_test/**'],
124-
cjs: {
125-
tools: ['tools/**/*.es6', '!tools/transpiler/**'],
126-
e2eTest: ['modules/**/e2e_test/**/*.es6']
127-
}
107+
js: ['modules/**/*.js', 'modules/**/*.es6'],
108+
dart: ['modules/**/*.js'],
128109
},
129110
copy: {
130-
js: ['modules/**/*.es5', '!modules/**/e2e_test/**'],
111+
js: ['modules/**/*.es5'],
131112
dart: ['modules/**/*.dart', '!modules/**/e2e_test/**'],
132-
cjs: {
133-
tools: ['tools/**/*.es5', '!tools/transpiler/**'],
134-
e2eTest: ['modules/**/e2e_test/**/*.es5']
135-
}
136113
},
137114
options: {
138115
js: {
@@ -144,6 +121,11 @@ var CONFIG = {
144121
prod: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
145122
typeAssertions: false,
146123
outputLanguage: 'es6'
124+
}),
125+
cjs: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
126+
typeAssertionModule: 'rtts_assert/rtts_assert',
127+
typeAssertions: true,
128+
modules: 'commonjs'
147129
})
148130
},
149131
dart: {
@@ -153,8 +135,7 @@ var CONFIG = {
153135
script: false, // parse as a module
154136
memberVariables: true, // parse class fields
155137
outputLanguage: 'dart'
156-
},
157-
cjs: CJS_COMPILER_OPTIONS
138+
}
158139
}
159140
},
160141
copy: {
@@ -214,10 +195,6 @@ gulp.task('build/clean.dart', clean(gulp, gulpPlugins, {
214195
path: CONFIG.dest.dart
215196
}));
216197

217-
gulp.task('build/clean.cjs', clean(gulp, gulpPlugins, {
218-
path: CONFIG.dest.cjs.all
219-
}));
220-
221198
gulp.task('build/clean.docs', clean(gulp, gulpPlugins, {
222199
path: CONFIG.dest.docs
223200
}));
@@ -294,6 +271,15 @@ gulp.task('build/transpile.js.prod', function(done) {
294271
);
295272
});
296273

274+
gulp.task('build/transpile.js.cjs', transpile(gulp, gulpPlugins, {
275+
src: CONFIG.transpile.src.js.concat(['tools/benchp*/**/*.es6']),
276+
copy: CONFIG.transpile.copy.js,
277+
dest: CONFIG.dest.js.cjs,
278+
outputExt: 'js',
279+
options: CONFIG.transpile.options.js.cjs,
280+
srcFolderInsertion: CONFIG.srcFolderInsertion.js
281+
}));
282+
297283
gulp.task('build/transpile.dart', transpile(gulp, gulpPlugins, {
298284
src: CONFIG.transpile.src.dart,
299285
copy: CONFIG.transpile.copy.dart,
@@ -303,24 +289,6 @@ gulp.task('build/transpile.dart', transpile(gulp, gulpPlugins, {
303289
srcFolderInsertion: CONFIG.srcFolderInsertion.dart
304290
}));
305291

306-
gulp.task('build/transpile/tools.cjs', transpile(gulp, gulpPlugins, {
307-
src: CONFIG.transpile.src.cjs.tools,
308-
copy: CONFIG.transpile.copy.cjs.tools,
309-
dest: CONFIG.dest.cjs.tools,
310-
outputExt: 'js',
311-
options: CONFIG.transpile.options.cjs,
312-
srcFolderInsertion: CONFIG.srcFolderInsertion.js
313-
}));
314-
315-
gulp.task('build/transpile/e2eTest.cjs', transpile(gulp, gulpPlugins, {
316-
src: CONFIG.transpile.src.cjs.e2eTest,
317-
copy: CONFIG.transpile.copy.cjs.e2eTest,
318-
dest: CONFIG.dest.cjs.e2eTest,
319-
outputExt: 'js',
320-
options: CONFIG.transpile.options.cjs,
321-
srcFolderInsertion: CONFIG.srcFolderInsertion.js
322-
}));
323-
324292
// ------------
325293
// html
326294

@@ -394,6 +362,13 @@ gulp.task('build/pubspec.dart', pubspec(gulp, gulpPlugins, {
394362
command: DART_SDK.PUB
395363
}));
396364

365+
// ------------
366+
// linknodemodules
367+
368+
gulp.task('build/linknodemodules.js.cjs', linknodemodules(gulp, gulpPlugins, {
369+
dir: CONFIG.dest.js.cjs
370+
}));
371+
397372
// ------------
398373
// dartanalyzer
399374

@@ -571,15 +546,16 @@ gulp.task('build.js.prod', function(done) {
571546
);
572547
});
573548

574-
gulp.task('build.cjs', function(done) {
549+
gulp.task('build.js.cjs', function(done) {
575550
runSequence(
576-
['build/transpile/tools.cjs', 'build/transpile/e2eTest.cjs'],
551+
'build/transpile.js.cjs',
552+
'build/linknodemodules.js.cjs',
577553
done
578-
);
554+
);;
579555
});
580556

581-
gulp.task('build.js', ['build.js.dev', 'build.js.prod']);
557+
gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs']);
582558

583-
gulp.task('clean', ['build/clean.js', 'build/clean.dart', 'build/clean.cjs', 'build/clean.docs']);
559+
gulp.task('clean', ['build/clean.js', 'build/clean.dart', 'build/clean.docs']);
584560

585-
gulp.task('build', ['build.js', 'build.dart', 'build.cjs']);
561+
gulp.task('build', ['build.js', 'build.dart']);

modules/angular2/e2e_test/perf_util.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var benchpress = require('../../../tools/benchpress/index.js');
1+
var benchpress = require('benchpress/index.js');
22
var webdriver = require('protractor/node_modules/selenium-webdriver');
33

44
module.exports = {

modules/angular2/e2e_test/test_util.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var benchpress = require('../../../tools/benchpress/index.js');
1+
var benchpress = require('benchpress/index.js');
22

33
module.exports = {
44
verifyNoBrowserErrors: benchpress.verifyNoBrowserErrors,

modules/angular2/src/core/zone/vm_turn_zone.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
2-
import {normalizeBlank, isPresent} from 'angular2/src/facade/lang';
2+
import {normalizeBlank, isPresent, global} from 'angular2/src/facade/lang';
33

44
export class VmTurnZone {
55
_outerZone;
@@ -17,7 +17,7 @@ export class VmTurnZone {
1717
this._onTurnDone = null;
1818
this._onErrorHandler = null;
1919

20-
this._outerZone = window.zone;
20+
this._outerZone = global.zone;
2121
this._innerZone = this._createInnerZone(this._outerZone, enableLongStackTrace);
2222
}
2323

modules/angular2/src/facade/async.es6

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {int} from 'angular2/src/facade/lang';
1+
import {int, global} from 'angular2/src/facade/lang';
22
import {List} from 'angular2/src/facade/collection';
3-
export var Promise = window.Promise;
3+
4+
export var Promise = global.Promise;
45

56
export class PromiseWrapper {
67
static resolve(obj):Promise {
@@ -37,7 +38,7 @@ export class PromiseWrapper {
3738
}
3839

3940
static setTimeout(fn:Function, millis:int) {
40-
window.setTimeout(fn, millis);
41+
global.setTimeout(fn, millis);
4142
}
4243

4344
static isPromise(maybePromise):boolean {

modules/angular2/src/facade/collection.es6

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {int, isJsObject} from 'angular2/src/facade/lang';
1+
import {int, isJsObject, global} from 'angular2/src/facade/lang';
22

3-
export var List = window.Array;
4-
export var Map = window.Map;
5-
export var Set = window.Set;
3+
export var List = global.Array;
4+
export var Map = global.Map;
5+
export var Set = global.Set;
66

77
export class MapWrapper {
88
static create():Map { return new Map(); }

modules/angular2/src/facade/dom.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
2+
13
export var window = frames.window;
24
export var DocumentFragment = window.DocumentFragment;
35
export var Node = window.Node;
@@ -10,8 +12,6 @@ export var document = window.document;
1012
export var location = window.location;
1113
export var gc = window.gc ? () => window.gc() : () => null;
1214

13-
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
14-
1515
export class DOM {
1616
static query(selector) {
1717
return document.querySelector(selector);

modules/angular2/src/facade/lang.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library angular.core.facade.lang;
22

3-
export 'dart:core' show Type, RegExp;
3+
export 'dart:core' show Type, RegExp, print;
44
import 'dart:math' as math;
55

66
class Math {

modules/angular2/src/facade/lang.es6

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
export {proxy} from 'rtts_assert/rtts_assert';
22

3+
var _global = typeof window === 'undefined' ? global : window;
4+
export {_global as global};
5+
36
export var Type = Function;
4-
export var Math = window.Math;
7+
export var Math = _global.Math;
58

69
var assertionsEnabled_ = typeof assert !== 'undefined';
710

811
var int;
912
// global assert support, as Dart has it...
1013
// TODO: `assert` calls need to be removed in production code!
1114
if (assertionsEnabled_) {
12-
window.assert = assert;
15+
_global.assert = assert;
1316
// `int` is not a valid JS type
1417
int = assert.define('int', function(value) {
1518
return typeof value === 'number' && value%1 === 0;
1619
});
1720
} else {
1821
int = {};
19-
window.assert = function() {};
22+
_global.assert = function() {};
2023
}
2124
export {int};
2225

@@ -173,8 +176,8 @@ var RegExp;
173176
if (assertionsEnabled_) {
174177
RegExp = assert.define('RegExp', function(obj) {
175178
assert(obj).is(assert.structure({
176-
single: window.RegExp,
177-
multiple: window.RegExp
179+
single: _global.RegExp,
180+
multiple: _global.RegExp
178181
}));
179182
});
180183
} else {
@@ -185,8 +188,8 @@ export class RegExpWrapper {
185188
static create(regExpStr, flags:string = ''):RegExp {
186189
flags = flags.replace(/g/g, '');
187190
return {
188-
multiple: new window.RegExp(regExpStr, flags + 'g'),
189-
single: new window.RegExp(regExpStr, flags)
191+
multiple: new _global.RegExp(regExpStr, flags + 'g'),
192+
single: new _global.RegExp(regExpStr, flags)
190193
};
191194
}
192195
static firstMatch(regExp, input) {

0 commit comments

Comments
 (0)