Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit ac3851e

Browse files
JiaLiPassionIgorMinar
authored andcommitted
build: seperate zone.js into evergreen only and legacy included bundles.
1 parent ce9c2e0 commit ac3851e

34 files changed

+713
-324
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ script:
5656
- node_modules/.bin/gulp test/node -no-patch-clock
5757
- cp ./test/browser/custom-element.spec.js ./build/test/browser
5858
- node_modules/.bin/karma start karma-dist-sauce-jasmine.es6.conf.js --single-run
59+
- node_modules/.bin/karma start karma-evergreen-dist-sauce-jasmine.conf.js --single-run

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,38 @@ Starting from zone.js v0.8.9, you can choose which web API module you want to pa
5454
For more details, please
5555
see [MODULE.md](MODULE.md).
5656

57+
## Bundles
58+
There are several bundles under `dist` folder.
59+
60+
|Bundle|Summary|
61+
|---|---|
62+
|zone.js|the default bundle, contains the most used APIs such as `setTimeout/Promise/EventTarget...`, also this bundle supports all evergreen and legacy (IE/Legacy Firefox/Legacy Safari) Browsers|
63+
|zone-evergreen.js|the bundle for evergreen browsers, doesn't include the `patch` for `legacy` browsers such as `IE` or old versions of `Firefox/Safari`|
64+
|zone-legacy.js|the patch bundle for legacy browsers, only includes the `patch` for `legacy` browsers such as `IE` or old versions of `Firefox/Safari`. This bundle must be loaded after `zone-evergreen.js`, **`zone.js`=`zone-evergreen.js` + `zone-legacy.js`**|
65+
|zone-testing.js|the bundle for zone testing support, including `jasmine/mocha` support and `async/fakeAsync/sync` test utilities|
66+
|zone-externs.js|the API definitions for `closure compiler`|
67+
68+
And here are the additional optional patches not included in the main zone.js bundles
69+
70+
|Patch|Summary|
71+
|---|---|
72+
|webapis-media-query.js|patch for `MediaQuery APIs`|
73+
|webapis-notification.js|patch for `Notification APIs`|
74+
|webapis-rtc-peer-connection.js|patch for `RTCPeerConnection APIs`|
75+
|webapis-shadydom.js|patch for `Shady DOM APIs`|
76+
|zone-bluebird.js|patch for `Bluebird APIs`|
77+
|zone-error.js|patch for `Error Global Object`, supports remove `Zone StackTrace`|
78+
|zone-patch-canvas.js|patch for `Canvas API`|
79+
|zone-patch-cordova.js|patch for `Cordova API`|
80+
|zone-patch-electron.js|patch for `Electron API`|
81+
|zone-patch-fetch.js|patch for `Fetch API`|
82+
|zone-patch-jsonp.js|utility for `jsonp API`|
83+
|zone-patch-resize-observer.js|patch for `ResizeObserver API`|
84+
|zone-patch-rxjs.js|patch for `rxjs API`|
85+
|zone-patch-rxjs-fake-async.js|patch for `rxjs fakeasync test`|
86+
|zone-patch-socket-io.js|patch for `socket-io`|
87+
|zone-patch-user-media.js|patch for `UserMedia API`|
88+
5789
## Promise A+ test passed
5890
[![Promises/A+ 1.1 compliant](https://promisesaplus.com/assets/logo-small.png)](https://promisesaplus.com/)
5991

gulpfile.js

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ var path = require('path');
1616
var spawn = require('child_process').spawn;
1717
const os = require('os');
1818

19-
function generateScript(inFile, outFile, minify, callback) {
19+
function generateScript(inFile, outFile, minify, callback, format) {
20+
if (!format) {
21+
format = 'umd';
22+
}
2023
inFile = path.join('./build-esm/', inFile).replace(/\.ts$/, '.js');
2124
var parts = [
2225
gulp.src('./build-esm/lib/**/*.js')
@@ -30,7 +33,7 @@ function generateScript(inFile, outFile, minify, callback) {
3033
console.error(warning.message);
3134
},
3235
output: {
33-
format: 'umd',
36+
format: format,
3437
name: 'zone',
3538
banner: '/**\n' +
3639
'* @license\n' +
@@ -115,16 +118,39 @@ gulp.task('build/zone-node.js', ['compile-esm-node'], function(cb) {
115118

116119
// Zone for the browser.
117120
gulp.task('build/zone.js', ['compile-esm'], function(cb) {
118-
return generateScript('./lib/browser/rollup-main.ts', 'zone.js', false, cb);
121+
return generateScript('./lib/browser/rollup-legacy-main.ts', 'zone.js', false, cb);
119122
});
120123

121124
gulp.task('build/zone.min.js', ['compile-esm'], function(cb) {
122-
return generateScript('./lib/browser/rollup-main.ts', 'zone.min.js', true, cb);
125+
return generateScript('./lib/browser/rollup-legacy-main.ts', 'zone.min.js', true, cb);
126+
});
127+
128+
// Zone for the evergreen browser.
129+
gulp.task('build/zone-evergreen.js', ['compile-esm'], function(cb) {
130+
return generateScript('./lib/browser/rollup-main.ts', 'zone-evergreen.js', false, cb);
131+
});
132+
133+
gulp.task('build/zone-evergreen.min.js', ['compile-esm'], function(cb) {
134+
return generateScript('./lib/browser/rollup-main.ts', 'zone-evergreen.min.js', true, cb);
135+
});
136+
137+
// Zone legacy patch for the legacy browser.
138+
gulp.task('build/zone-legacy.js', ['compile-esm'], function(cb) {
139+
return generateScript('./lib/browser/browser-legacy.ts', 'zone-legacy.js', false, cb);
140+
});
141+
142+
gulp.task('build/zone-legacy.min.js', ['compile-esm'], function(cb) {
143+
return generateScript('./lib/browser/browser-legacy.ts', 'zone-legacy.min.js', true, cb);
123144
});
124145

125146
// Zone test bundle for the browser.
126147
gulp.task('build/zone-testing-bundle.js', ['compile-esm'], function(cb) {
127-
return generateScript('./lib/browser/rollup-test-main.ts', 'zone-testing-bundle.js', false, cb);
148+
return generateScript('./lib/browser/rollup-legacy-test-main.ts', 'zone-testing-bundle.js', false, cb);
149+
});
150+
151+
// Zone test bundle for the evergreen browser.
152+
gulp.task('build/zone-evergreen-testing-bundle.js', ['compile-esm'], function(cb) {
153+
return generateScript('./lib/browser/rollup-test-main.ts', 'zone-evergreen-testing-bundle.js', false, cb);
128154
});
129155

130156
// Zone test bundle for node.
@@ -150,6 +176,27 @@ gulp.task('build/zone-error.min.js', ['compile-esm'], function(cb) {
150176
return generateScript('./lib/common/error-rewrite.ts', 'zone-error.min.js', true, cb);
151177
});
152178

179+
gulp.task('build/zone-patch-canvas.js', ['compile-esm'], function(cb) {
180+
return generateScript(
181+
'./lib/browser/canvas.ts', 'zone-patch-canvas.js', false, cb);
182+
});
183+
184+
gulp.task('build/zone-patch-canvas.min.js', ['compile-esm'], function(cb) {
185+
return generateScript(
186+
'./lib/browser/canvas.ts', 'zone-patch-canvas.min.js', true, cb);
187+
});
188+
189+
gulp.task('build/zone-patch-fetch.js', ['compile-esm'], function(cb) {
190+
return generateScript(
191+
'./lib/common/fetch.ts', 'zone-patch-fetch.js', false, cb);
192+
});
193+
194+
gulp.task('build/zone-patch-fetch.min.js', ['compile-esm'], function(cb) {
195+
return generateScript(
196+
'./lib/common/fetch.ts', 'zone-patch-fetch.min.js', true, cb);
197+
});
198+
199+
153200
gulp.task('build/webapis-media-query.js', ['compile-esm'], function(cb) {
154201
return generateScript(
155202
'./lib/browser/webapis-media-query.ts', 'webapis-media-query.js', false, cb);
@@ -347,12 +394,21 @@ gulp.task('build', [
347394
'build/zone.js',
348395
'build/zone.js.d.ts',
349396
'build/zone.min.js',
397+
'build/zone-evergreen.js',
398+
'build/zone-evergreen.min.js',
399+
'build/zone-legacy.js',
400+
'build/zone-legacy.min.js',
350401
'build/zone-testing.js',
351402
'build/zone-testing-bundle.js',
403+
'build/zone-evergreen-testing-bundle.js',
352404
'build/zone-testing-node-bundle.js',
353405
'build/zone-error.js',
354406
'build/zone-error.min.js',
355407
'build/zone-node.js',
408+
'build/zone-patch-canvas.js',
409+
'build/zone-patch-canvas.min.js',
410+
'build/zone-patch-fetch.js',
411+
'build/zone-patch-fetch.min.js',
356412
'build/webapis-media-query.js',
357413
'build/webapis-media-query.min.js',
358414
'build/webapis-notification.js',
@@ -409,7 +465,6 @@ function nodeTest(specFiles, cb) {
409465
require('./build/test/test-env-setup-jasmine' + args[3]);
410466
}
411467
var JasmineRunner = require('jasmine');
412-
var JasmineRunner = require('jasmine');
413468
var jrunner = new JasmineRunner();
414469

415470
jrunner.configureDefaultReporter({showColors: true});

karma-dist.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module.exports = function(config) {
1212
config.files.push('build/test/test_fake_polyfill.js');
1313
config.files.push('build/test/custom_error.js');
1414
config.files.push('dist/zone.js');
15+
config.files.push('dist/zone-patch-fetch.js');
16+
config.files.push('dist/zone-patch-canvas.js');
1517
config.files.push('dist/webapis-media-query.js');
1618
config.files.push('dist/webapis-notification.js');
1719
config.files.push('dist/zone-patch-user-media.js');

karma-evergreen-dist-jasmine.conf.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
module.exports = function (config) {
3+
require('./karma-evergreen-dist.conf.js')(config);
4+
5+
config.plugins.push(require('karma-jasmine'));
6+
config.frameworks.push('jasmine');
7+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
module.exports = function (config) {
10+
require('./karma-evergreen-dist-jasmine.conf.js')(config);
11+
require('./sauce-evergreen.conf')(config);
12+
};

karma-evergreen-dist.conf.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
module.exports = function(config) {
10+
require('./karma-base.conf.js')(config);
11+
config.files.push('build/test/wtf_mock.js');
12+
config.files.push('build/test/test_fake_polyfill.js');
13+
config.files.push('build/test/custom_error.js');
14+
config.files.push('dist/zone-evergreen.js');
15+
config.files.push('dist/zone-patch-canvas.js');
16+
config.files.push('dist/zone-patch-fetch.js');
17+
config.files.push('dist/webapis-media-query.js');
18+
config.files.push('dist/webapis-notification.js');
19+
config.files.push('dist/zone-patch-user-media.js');
20+
config.files.push('dist/zone-patch-resize-observer.js');
21+
config.files.push('dist/task-tracking.js');
22+
config.files.push('dist/wtf.js');
23+
config.files.push('dist/zone-testing.js');
24+
config.files.push('build/test/main.js');
25+
};

lib/browser/api-util.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {bindArguments, patchMacroTask, patchMethod, patchOnProperties} from '../common/utils';
10+
11+
Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
12+
api.patchOnProperties = patchOnProperties;
13+
api.patchMethod = patchMethod;
14+
api.bindArguments = bindArguments;
15+
api.patchMacroTask = patchMacroTask;
16+
});

lib/browser/browser-legacy.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
/**
9+
* @fileoverview
10+
* @suppress {missingRequire}
11+
*/
12+
13+
import {eventTargetLegacyPatch} from './event-target-legacy';
14+
import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
15+
import {registerElementPatch} from './register-element';
16+
17+
Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
18+
registerElementPatch(global);
19+
});
20+
21+
Zone.__load_patch('EventTargetLegacy', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
22+
const SYMBOL_BLACK_LISTED_EVENTS = Zone.__symbol__('BLACK_LISTED_EVENTS');
23+
if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
24+
(Zone as any)[SYMBOL_BLACK_LISTED_EVENTS] = global[SYMBOL_BLACK_LISTED_EVENTS];
25+
}
26+
eventTargetLegacyPatch(global, api);
27+
propertyDescriptorLegacyPatch(api, global);
28+
});

lib/browser/browser.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212

1313
import {findEventTasks} from '../common/events';
1414
import {patchTimer} from '../common/timers';
15-
import {bindArguments, patchClass, patchMacroTask, patchMethod, patchOnProperties, patchPrototype, scheduleMacroTaskWithCurrentZone, ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, zoneSymbol} from '../common/utils';
15+
import {patchClass, patchMethod, patchPrototype, scheduleMacroTaskWithCurrentZone, ZONE_SYMBOL_ADD_EVENT_LISTENER, ZONE_SYMBOL_REMOVE_EVENT_LISTENER, zoneSymbol} from '../common/utils';
1616

17+
import {patchCustomElements} from './custom-elements';
1718
import {propertyPatch} from './define-property';
1819
import {eventTargetPatch, patchEvent} from './event-target';
1920
import {propertyDescriptorPatch} from './property-descriptor';
20-
import {patchCustomElements, registerElementPatch} from './register-element';
21-
22-
Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
23-
api.patchOnProperties = patchOnProperties;
24-
api.patchMethod = patchMethod;
25-
api.bindArguments = bindArguments;
26-
});
21+
import {registerElementPatch} from './register-element';
2722

2823
Zone.__load_patch('timers', (global: any) => {
2924
const set = 'set';
@@ -77,20 +72,9 @@ Zone.__load_patch('on_property', (global: any, Zone: ZoneType, api: _ZonePrivate
7772
});
7873

7974
Zone.__load_patch('customElements', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
80-
registerElementPatch(global);
8175
patchCustomElements(global);
8276
});
8377

84-
Zone.__load_patch('canvas', (global: any) => {
85-
const HTMLCanvasElement = global['HTMLCanvasElement'];
86-
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
87-
HTMLCanvasElement.prototype.toBlob) {
88-
patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', (self: any, args: any[]) => {
89-
return {name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args};
90-
});
91-
}
92-
});
93-
9478
Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
9579
// Treat XMLHttpRequest as a macrotask.
9680
patchXHR(global);

lib/browser/canvas.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
Zone.__load_patch('canvas', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
9+
const HTMLCanvasElement = global['HTMLCanvasElement'];
10+
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
11+
HTMLCanvasElement.prototype.toBlob) {
12+
api.patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', (self: any, args: any[]) => {
13+
return {name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args};
14+
});
15+
}
16+
});

lib/browser/custom-elements.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {attachOriginToPatched, isBrowser, isMix, ObjectGetOwnPropertyDescriptor, wrapWithCurrentZone} from '../common/utils';
10+
11+
import {_redefineProperty} from './define-property';
12+
13+
export function patchCallbacks(
14+
target: any, targetName: string, method: string, callbacks: string[]) {
15+
const symbol = Zone.__symbol__(method);
16+
if (target[symbol]) {
17+
return;
18+
}
19+
const nativeDelegate = target[symbol] = target[method];
20+
target[method] = function(name: any, opts: any, options?: any) {
21+
if (opts && opts.prototype) {
22+
callbacks.forEach(function(callback) {
23+
const source = `${targetName}.${method}::` + callback;
24+
const prototype = opts.prototype;
25+
if (prototype.hasOwnProperty(callback)) {
26+
const descriptor = ObjectGetOwnPropertyDescriptor(prototype, callback);
27+
if (descriptor && descriptor.value) {
28+
descriptor.value = wrapWithCurrentZone(descriptor.value, source);
29+
_redefineProperty(opts.prototype, callback, descriptor);
30+
} else if (prototype[callback]) {
31+
prototype[callback] = wrapWithCurrentZone(prototype[callback], source);
32+
}
33+
} else if (prototype[callback]) {
34+
prototype[callback] = wrapWithCurrentZone(prototype[callback], source);
35+
}
36+
});
37+
}
38+
39+
return nativeDelegate.call(target, name, opts, options);
40+
};
41+
42+
attachOriginToPatched(target[method], nativeDelegate);
43+
}
44+
45+
export function patchCustomElements(_global: any) {
46+
if ((!isBrowser && !isMix) || !('customElements' in _global)) {
47+
return;
48+
}
49+
50+
const callbacks =
51+
['connectedCallback', 'disconnectedCallback', 'adoptedCallback', 'attributeChangedCallback'];
52+
53+
patchCallbacks(_global.customElements, 'customElements', 'define', callbacks);
54+
}

0 commit comments

Comments
 (0)