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

Commit

Permalink
build: seperate zone.js into evergreen only and legacy included bundles.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and IgorMinar committed Feb 24, 2019
1 parent ce9c2e0 commit ac3851e
Show file tree
Hide file tree
Showing 34 changed files with 713 additions and 324 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ script:
- node_modules/.bin/gulp test/node -no-patch-clock
- cp ./test/browser/custom-element.spec.js ./build/test/browser
- node_modules/.bin/karma start karma-dist-sauce-jasmine.es6.conf.js --single-run
- node_modules/.bin/karma start karma-evergreen-dist-sauce-jasmine.conf.js --single-run
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ Starting from zone.js v0.8.9, you can choose which web API module you want to pa
For more details, please
see [MODULE.md](MODULE.md).

## Bundles
There are several bundles under `dist` folder.

|Bundle|Summary|
|---|---|
|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|
|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`|
|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`**|
|zone-testing.js|the bundle for zone testing support, including `jasmine/mocha` support and `async/fakeAsync/sync` test utilities|
|zone-externs.js|the API definitions for `closure compiler`|

And here are the additional optional patches not included in the main zone.js bundles

|Patch|Summary|
|---|---|
|webapis-media-query.js|patch for `MediaQuery APIs`|
|webapis-notification.js|patch for `Notification APIs`|
|webapis-rtc-peer-connection.js|patch for `RTCPeerConnection APIs`|
|webapis-shadydom.js|patch for `Shady DOM APIs`|
|zone-bluebird.js|patch for `Bluebird APIs`|
|zone-error.js|patch for `Error Global Object`, supports remove `Zone StackTrace`|
|zone-patch-canvas.js|patch for `Canvas API`|
|zone-patch-cordova.js|patch for `Cordova API`|
|zone-patch-electron.js|patch for `Electron API`|
|zone-patch-fetch.js|patch for `Fetch API`|
|zone-patch-jsonp.js|utility for `jsonp API`|
|zone-patch-resize-observer.js|patch for `ResizeObserver API`|
|zone-patch-rxjs.js|patch for `rxjs API`|
|zone-patch-rxjs-fake-async.js|patch for `rxjs fakeasync test`|
|zone-patch-socket-io.js|patch for `socket-io`|
|zone-patch-user-media.js|patch for `UserMedia API`|

## Promise A+ test passed
[![Promises/A+ 1.1 compliant](https://promisesaplus.com/assets/logo-small.png)](https://promisesaplus.com/)

Expand Down
67 changes: 61 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ var path = require('path');
var spawn = require('child_process').spawn;
const os = require('os');

function generateScript(inFile, outFile, minify, callback) {
function generateScript(inFile, outFile, minify, callback, format) {
if (!format) {
format = 'umd';
}
inFile = path.join('./build-esm/', inFile).replace(/\.ts$/, '.js');
var parts = [
gulp.src('./build-esm/lib/**/*.js')
Expand All @@ -30,7 +33,7 @@ function generateScript(inFile, outFile, minify, callback) {
console.error(warning.message);
},
output: {
format: 'umd',
format: format,
name: 'zone',
banner: '/**\n' +
'* @license\n' +
Expand Down Expand Up @@ -115,16 +118,39 @@ gulp.task('build/zone-node.js', ['compile-esm-node'], function(cb) {

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

gulp.task('build/zone.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-main.ts', 'zone.min.js', true, cb);
return generateScript('./lib/browser/rollup-legacy-main.ts', 'zone.min.js', true, cb);
});

// Zone for the evergreen browser.
gulp.task('build/zone-evergreen.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-main.ts', 'zone-evergreen.js', false, cb);
});

gulp.task('build/zone-evergreen.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-main.ts', 'zone-evergreen.min.js', true, cb);
});

// Zone legacy patch for the legacy browser.
gulp.task('build/zone-legacy.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/browser-legacy.ts', 'zone-legacy.js', false, cb);
});

gulp.task('build/zone-legacy.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/browser-legacy.ts', 'zone-legacy.min.js', true, cb);
});

// Zone test bundle for the browser.
gulp.task('build/zone-testing-bundle.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-test-main.ts', 'zone-testing-bundle.js', false, cb);
return generateScript('./lib/browser/rollup-legacy-test-main.ts', 'zone-testing-bundle.js', false, cb);
});

// Zone test bundle for the evergreen browser.
gulp.task('build/zone-evergreen-testing-bundle.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-test-main.ts', 'zone-evergreen-testing-bundle.js', false, cb);
});

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

gulp.task('build/zone-patch-canvas.js', ['compile-esm'], function(cb) {
return generateScript(
'./lib/browser/canvas.ts', 'zone-patch-canvas.js', false, cb);
});

gulp.task('build/zone-patch-canvas.min.js', ['compile-esm'], function(cb) {
return generateScript(
'./lib/browser/canvas.ts', 'zone-patch-canvas.min.js', true, cb);
});

gulp.task('build/zone-patch-fetch.js', ['compile-esm'], function(cb) {
return generateScript(
'./lib/common/fetch.ts', 'zone-patch-fetch.js', false, cb);
});

gulp.task('build/zone-patch-fetch.min.js', ['compile-esm'], function(cb) {
return generateScript(
'./lib/common/fetch.ts', 'zone-patch-fetch.min.js', true, cb);
});


gulp.task('build/webapis-media-query.js', ['compile-esm'], function(cb) {
return generateScript(
'./lib/browser/webapis-media-query.ts', 'webapis-media-query.js', false, cb);
Expand Down Expand Up @@ -347,12 +394,21 @@ gulp.task('build', [
'build/zone.js',
'build/zone.js.d.ts',
'build/zone.min.js',
'build/zone-evergreen.js',
'build/zone-evergreen.min.js',
'build/zone-legacy.js',
'build/zone-legacy.min.js',
'build/zone-testing.js',
'build/zone-testing-bundle.js',
'build/zone-evergreen-testing-bundle.js',
'build/zone-testing-node-bundle.js',
'build/zone-error.js',
'build/zone-error.min.js',
'build/zone-node.js',
'build/zone-patch-canvas.js',
'build/zone-patch-canvas.min.js',
'build/zone-patch-fetch.js',
'build/zone-patch-fetch.min.js',
'build/webapis-media-query.js',
'build/webapis-media-query.min.js',
'build/webapis-notification.js',
Expand Down Expand Up @@ -409,7 +465,6 @@ function nodeTest(specFiles, cb) {
require('./build/test/test-env-setup-jasmine' + args[3]);
}
var JasmineRunner = require('jasmine');
var JasmineRunner = require('jasmine');
var jrunner = new JasmineRunner();

jrunner.configureDefaultReporter({showColors: true});
Expand Down
2 changes: 2 additions & 0 deletions karma-dist.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = function(config) {
config.files.push('build/test/test_fake_polyfill.js');
config.files.push('build/test/custom_error.js');
config.files.push('dist/zone.js');
config.files.push('dist/zone-patch-fetch.js');
config.files.push('dist/zone-patch-canvas.js');
config.files.push('dist/webapis-media-query.js');
config.files.push('dist/webapis-notification.js');
config.files.push('dist/zone-patch-user-media.js');
Expand Down
7 changes: 7 additions & 0 deletions karma-evergreen-dist-jasmine.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

module.exports = function (config) {
require('./karma-evergreen-dist.conf.js')(config);

config.plugins.push(require('karma-jasmine'));
config.frameworks.push('jasmine');
};
12 changes: 12 additions & 0 deletions karma-evergreen-dist-sauce-jasmine.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
require('./karma-evergreen-dist-jasmine.conf.js')(config);
require('./sauce-evergreen.conf')(config);
};
25 changes: 25 additions & 0 deletions karma-evergreen-dist.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function(config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('build/test/test_fake_polyfill.js');
config.files.push('build/test/custom_error.js');
config.files.push('dist/zone-evergreen.js');
config.files.push('dist/zone-patch-canvas.js');
config.files.push('dist/zone-patch-fetch.js');
config.files.push('dist/webapis-media-query.js');
config.files.push('dist/webapis-notification.js');
config.files.push('dist/zone-patch-user-media.js');
config.files.push('dist/zone-patch-resize-observer.js');
config.files.push('dist/task-tracking.js');
config.files.push('dist/wtf.js');
config.files.push('dist/zone-testing.js');
config.files.push('build/test/main.js');
};
16 changes: 16 additions & 0 deletions lib/browser/api-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {bindArguments, patchMacroTask, patchMethod, patchOnProperties} from '../common/utils';

Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api.patchOnProperties = patchOnProperties;
api.patchMethod = patchMethod;
api.bindArguments = bindArguments;
api.patchMacroTask = patchMacroTask;
});
28 changes: 28 additions & 0 deletions lib/browser/browser-legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @fileoverview
* @suppress {missingRequire}
*/

import {eventTargetLegacyPatch} from './event-target-legacy';
import {propertyDescriptorLegacyPatch} from './property-descriptor-legacy';
import {registerElementPatch} from './register-element';

Zone.__load_patch('registerElement', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
registerElementPatch(global);
});

Zone.__load_patch('EventTargetLegacy', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
const SYMBOL_BLACK_LISTED_EVENTS = Zone.__symbol__('BLACK_LISTED_EVENTS');
if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
(Zone as any)[SYMBOL_BLACK_LISTED_EVENTS] = global[SYMBOL_BLACK_LISTED_EVENTS];
}
eventTargetLegacyPatch(global, api);
propertyDescriptorLegacyPatch(api, global);
});
22 changes: 3 additions & 19 deletions lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@

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

import {patchCustomElements} from './custom-elements';
import {propertyPatch} from './define-property';
import {eventTargetPatch, patchEvent} from './event-target';
import {propertyDescriptorPatch} from './property-descriptor';
import {patchCustomElements, registerElementPatch} from './register-element';

Zone.__load_patch('util', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
api.patchOnProperties = patchOnProperties;
api.patchMethod = patchMethod;
api.bindArguments = bindArguments;
});
import {registerElementPatch} from './register-element';

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

Zone.__load_patch('customElements', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
registerElementPatch(global);
patchCustomElements(global);
});

Zone.__load_patch('canvas', (global: any) => {
const HTMLCanvasElement = global['HTMLCanvasElement'];
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
HTMLCanvasElement.prototype.toBlob) {
patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', (self: any, args: any[]) => {
return {name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args};
});
}
});

Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => {
// Treat XMLHttpRequest as a macrotask.
patchXHR(global);
Expand Down
16 changes: 16 additions & 0 deletions lib/browser/canvas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Zone.__load_patch('canvas', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
const HTMLCanvasElement = global['HTMLCanvasElement'];
if (typeof HTMLCanvasElement !== 'undefined' && HTMLCanvasElement.prototype &&
HTMLCanvasElement.prototype.toBlob) {
api.patchMacroTask(HTMLCanvasElement.prototype, 'toBlob', (self: any, args: any[]) => {
return {name: 'HTMLCanvasElement.toBlob', target: self, cbIdx: 0, args: args};
});
}
});
54 changes: 54 additions & 0 deletions lib/browser/custom-elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {attachOriginToPatched, isBrowser, isMix, ObjectGetOwnPropertyDescriptor, wrapWithCurrentZone} from '../common/utils';

import {_redefineProperty} from './define-property';

export function patchCallbacks(
target: any, targetName: string, method: string, callbacks: string[]) {
const symbol = Zone.__symbol__(method);
if (target[symbol]) {
return;
}
const nativeDelegate = target[symbol] = target[method];
target[method] = function(name: any, opts: any, options?: any) {
if (opts && opts.prototype) {
callbacks.forEach(function(callback) {
const source = `${targetName}.${method}::` + callback;
const prototype = opts.prototype;
if (prototype.hasOwnProperty(callback)) {
const descriptor = ObjectGetOwnPropertyDescriptor(prototype, callback);
if (descriptor && descriptor.value) {
descriptor.value = wrapWithCurrentZone(descriptor.value, source);
_redefineProperty(opts.prototype, callback, descriptor);
} else if (prototype[callback]) {
prototype[callback] = wrapWithCurrentZone(prototype[callback], source);
}
} else if (prototype[callback]) {
prototype[callback] = wrapWithCurrentZone(prototype[callback], source);
}
});
}

return nativeDelegate.call(target, name, opts, options);
};

attachOriginToPatched(target[method], nativeDelegate);
}

export function patchCustomElements(_global: any) {
if ((!isBrowser && !isMix) || !('customElements' in _global)) {
return;
}

const callbacks =
['connectedCallback', 'disconnectedCallback', 'adoptedCallback', 'attributeChangedCallback'];

patchCallbacks(_global.customElements, 'customElements', 'define', callbacks);
}
Loading

0 comments on commit ac3851e

Please sign in to comment.