Skip to content

Commit 3468f7c

Browse files
committed
chore(build): Add WebWorker bundle.
Closes angular#3207 Closes angular#3881
1 parent be07390 commit 3468f7c

File tree

19 files changed

+111
-1840
lines changed

19 files changed

+111
-1840
lines changed

docs/typescript-definition-package/index.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
3939
readFilesProcessor.basePath = path.resolve(__dirname, '../..');
4040
readTypeScriptModules.sourceFiles = [
4141
'angular2/angular2.ts',
42+
'angular2/web_worker/worker.ts',
43+
'angular2/web_worker/ui.ts',
4244
'angular2/router.ts',
4345
'angular2/http.ts'
4446
];
@@ -48,24 +50,38 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
4850
{
4951
id: 'angular2/angular2',
5052
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
51-
namespace: 'ng',
5253
modules: {
53-
'angular2/angular2': 'angular2/angular2',
54+
'angular2/angular2': {
55+
namespace: 'ng',
56+
id: 'angular2/angular2'
57+
},
58+
'angular2/web_worker/worker': {
59+
namespace: 'ngWorker',
60+
id: 'angular2/web_worker/worker'
61+
},
62+
'angular2/web_worker/ui': {
63+
namespace: 'ngUi',
64+
id: 'angular2/web_worker/ui'
65+
}
5466
}
5567
},
5668
{
5769
id: 'angular2/router',
58-
namespace: 'ngRouter',
5970
references: ['./angular2.d.ts'],
6071
modules: {
61-
'angular2/router': 'angular2/router'
72+
'angular2/router': {
73+
namespace: 'ngRouter',
74+
id: 'angular2/router'
75+
}
6276
}
6377
},
6478
{
6579
id: 'angular2/http',
66-
namespace: 'ngHttp',
6780
modules: {
68-
'angular2/http':'angular2/http'
81+
'angular2/http': {
82+
namespace: 'ngHttp',
83+
id: 'angular2/http'
84+
}
6985
}
7086
}
7187
];
@@ -109,4 +125,4 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
109125
'${ doc.docType }.template.html',
110126
'common.template.html'
111127
];
112-
});
128+
});

docs/typescript-definition-package/processors/createTypeDefinitionFile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ module.exports = function createTypeDefinitionFile(log) {
3232
outputPath: docPath,
3333
// A type definition may include a number of top level modules
3434
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
35-
moduleDocs: _.transform(def.modules, function(moduleDocs, id, alias) {
36-
moduleDocs[id] = {
35+
moduleDocs: _.transform(def.modules, function(moduleDocs, props, alias) {
36+
moduleDocs[props.id] = {
3737
id: alias,
3838
doc: null,
39-
namespace: def.namespace,
39+
namespace: props.namespace,
4040
references: def.references
4141
};
4242
})

docs/typescript-definition-package/processors/createTypeDefinitionFile.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ describe('createTypeDefinitionFile processor', function() {
1414
// Initialize the processor
1515
processor.typeDefinitions = [{
1616
id: 'angular2/angular2',
17-
modules: { 'angular2/angular2': 'angular2/angular2' }
17+
modules: {
18+
'angular2/angular2': {
19+
id: 'angular2/angular2',
20+
namespace: 'ng'
21+
}
22+
}
1823
}];
1924
});
2025

@@ -45,4 +50,4 @@ describe('createTypeDefinitionFile processor', function() {
4550
});
4651
});
4752

48-
});
53+
});

docs/typescript-definition-package/templates/angular2/angular2.d.ts.template.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
interface Map<K,V> {}
66
interface StringMap<K,V> extends Map<K,V> {}
77

8-
declare module ng {
8+
{% for alias, module in doc.moduleDocs %}
9+
declare module {$ module.namespace $} {
910
// See https://github.com/Microsoft/TypeScript/issues/1168
1011
class BaseException /* extends Error */ {
1112
message: string;
@@ -14,4 +15,5 @@
1415
}
1516
interface InjectableReference {}
1617
}
18+
{% endfor %}
1719
{% endblock %}

gulpfile.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,27 @@ gulp.task('!bundle.js.dev', ['build.js.dev'], function() {
10731073
});
10741074
});
10751075

1076+
// WebWorker build
1077+
gulp.task("!bundle.web_worker.js.dev", ["build.js.dev"], function() {
1078+
var devBundleConfig = merge(true, bundleConfig);
1079+
devBundleConfig.paths =
1080+
merge(true, devBundleConfig.paths, {
1081+
"*": "dist/js/dev/es6/*.js"
1082+
});
1083+
return bundler.bundle(
1084+
devBundleConfig,
1085+
'angular2/web_worker/ui',
1086+
'./dist/build/web_worker/ui.dev.js',
1087+
{ sourceMaps: true }).
1088+
then(function() {
1089+
return bundler.bundle(
1090+
devBundleConfig,
1091+
'angular2/web_worker/worker',
1092+
'./dist/build/web_worker/worker.dev.js',
1093+
{ sourceMaps: true});
1094+
});
1095+
});
1096+
10761097
gulp.task('!router.bundle.js.dev', ['build.js.dev'], function() {
10771098
var devBundleConfig = merge(true, bundleConfig);
10781099
devBundleConfig.paths =
@@ -1165,16 +1186,19 @@ function insertRXLicense(source) {
11651186
}
11661187
}
11671188

1189+
function addDevDependencies(outputFile) {
1190+
return bundler.modify(
1191+
JS_DEV_DEPS.concat(['dist/build/' + outputFile]),
1192+
outputFile)
1193+
.pipe(insert.transform(insertRXLicense))
1194+
.pipe(gulp.dest('dist/js/bundle'));
1195+
}
1196+
11681197
gulp.task('!bundle.js.dev.deps', ['!bundle.js.dev'], function() {
1169-
return merge2(
1170-
bundler.modify(
1171-
JS_DEV_DEPS.concat(['dist/build/angular2.dev.js']),
1172-
'angular2.dev.js')
1173-
.pipe(insert.transform(insertRXLicense))
1174-
.pipe(gulp.dest('dist/js/bundle')),
1175-
bundler.modify(
1176-
['dist/build/http.dev.js'], 'http.dev.js')
1177-
.pipe(gulp.dest('dist/js/bundle')));
1198+
var bundle = addDevDependencies('angular2.dev.js');
1199+
return merge2(bundle, bundler.modify(
1200+
['dist/build/http.dev.js'], 'http.dev.js')
1201+
.pipe(gulp.dest('dist/js/bundle')));
11781202
});
11791203

11801204
gulp.task('!bundle.js.sfx.dev.deps', ['!bundle.js.sfx.dev'], function() {
@@ -1187,10 +1211,16 @@ gulp.task('!bundle.js.sfx.dev.deps', ['!bundle.js.sfx.dev'], function() {
11871211
.pipe(gulp.dest('dist/js/bundle')));
11881212
});
11891213

1214+
gulp.task('!bundle.web_worker.js.dev.deps', ['!bundle.web_worker.js.dev'], function() {
1215+
return merge2(addDevDependencies("web_worker/ui.dev.js",
1216+
addDevDependencies("web_worker/worker.dev.js")));
1217+
});
1218+
11901219
gulp.task('bundles.js', [
11911220
'!bundle.js.prod.deps',
11921221
'!bundle.js.dev.deps',
11931222
'!bundle.js.min.deps',
1223+
'!bundle.web_worker.js.dev.deps',
11941224
'!bundle.js.sfx.dev.deps',
11951225
'!router.bundle.js.dev',
11961226
'!test.bundle.js.dev']);

modules/angular2/angular2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './directives';
1414
export * from './forms';
1515
export * from './render';
1616
export * from './profile';
17+
export {bootstrap} from 'angular2/src/core/application';

modules/angular2/angular2_exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './directives';
66
export * from './forms';
77
export * from './render';
88
export * from './profile';
9+
export {bootstrap} from 'angular2/src/core/application';

modules/angular2/core.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Define angular core API here.
55
*/
66
export {APP_COMPONENT} from 'angular2/src/core/application_tokens';
7-
export {commonBootstrap as bootstrap} from 'angular2/src/core/application_common';
87
export {Type} from 'angular2/src/core/facade/lang';
98
export {ApplicationRef} from 'angular2/src/core/application_ref';
109

modules/angular2/src/core/facade/lang.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
/// <reference path="../../../globals.d.ts" />
2-
var _global: BrowserNodeGlobal = <any>(typeof window === 'undefined' ? global : window);
2+
3+
// TODO(jteplitz602): Load WorkerGlobalScope from lib.webworker.d.ts file #3492
4+
declare var WorkerGlobalScope;
5+
var globalScope: BrowserNodeGlobal;
6+
if (typeof window === 'undefined') {
7+
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
8+
// TODO: Replace any with WorkerGlobalScope from lib.webworker.d.ts #3492
9+
globalScope = <any>self;
10+
} else {
11+
globalScope = <any>global;
12+
}
13+
} else {
14+
globalScope = <any>window;
15+
};
16+
17+
// Need to declare a new variable for global here since TypeScript
18+
// exports the original value of the symbol.
19+
var _global: BrowserNodeGlobal = globalScope;
20+
321
export {_global as global};
422

523
export var Type = Function;

modules/angular2/src/web_workers/shared/message_bus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {EventEmitter} from 'angular2/src/core/facade/async';
22
import {BaseException} from 'angular2/src/core/facade/lang';
3+
export {EventEmitter, Observable} from 'angular2/src/core/facade/async';
34

45
function _abstract() {
56
throw new BaseException("This method is abstract");

0 commit comments

Comments
 (0)