Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(umd): UMD now mirrors export schema for ESM and CJS #3426

Merged
merged 1 commit into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .make-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ fs.copySync('src/testing/package.json', PKG_ROOT + '/testing/package.json');
if (fs.existsSync(UMD_ROOT)) {
fs.copySync(UMD_ROOT, UMD_PKG);
// Add licenses to tops of bundles
addLicenseToFile('LICENSE.txt', UMD_PKG + 'Rx.js');
addLicenseTextToFile(license, UMD_PKG + 'Rx.min.js');
addLicenseToFile('LICENSE.txt', UMD_PKG + 'Rx.js');
addLicenseTextToFile(license, UMD_PKG + 'Rx.min.js');
addLicenseToFile('LICENSE.txt', UMD_PKG + 'rxjs.umd.js');
addLicenseTextToFile(license, UMD_PKG + 'rxjs.umd.min.js');
addLicenseToFile('LICENSE.txt', UMD_PKG + 'rxjs.umd.js');
addLicenseTextToFile(license, UMD_PKG + 'rxjs.umd.min.js');
}

function copySources(rootDir, packageDir, ignoreMissing) {
Expand Down
141 changes: 72 additions & 69 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,72 +69,75 @@ if (!messageConventionValid) {
markdown('> (' + errorCount + ') : RxJS uses conventional change log to generate changelog automatically. It seems some of commit messages are not following those, please check [contributing guideline](https://github.com/ReactiveX/rxjs/blob/master/CONTRIBUTING.md#commit-message-format) and update commit messages.');
}

function getKB(size) {
return (size / 1024).toFixed(1);
}

function getFormattedKB(size) {
if (size < 0) {
return '-' + size.toString();
} else if (size > 0) {
return '+' + size.toString();
}
return size.toString();
}

var globalFile = 'Rx.js';
var minFile = 'Rx.min.js';

function sizeDiffBadge(name, value) {
var color = 'lightgrey';
if (value > 0) {
color = 'red';
} else if (value < 0) {
color = 'green';
}
return 'https://img.shields.io/badge/' + name + '-' + getFormattedKB(getKB(value)) + 'KB-' + color + '.svg?style=flat-square';
}

//post size of build
schedule(new Promise(function (res) {
getSize('./dist/cjs', function (e, result) {
var localGlobalFile = path.resolve('./dist/global', globalFile);
var localMinFile = path.resolve('./dist/global', minFile);

//get sizes of PR build
var global = fs.statSync(localGlobalFile);
var global_gzip = gzipSize.sync(fs.readFileSync(localGlobalFile, 'utf8'));
var min = fs.statSync(localMinFile);
var min_gzip = gzipSize.sync(fs.readFileSync(localMinFile, 'utf8'));

//resolve path to release build
var releasePath = path.dirname(require.resolve(require.resolve('rxjs')));
var bundlePath = path.resolve(releasePath, 'bundles');
var bundleGlobalFile = path.resolve(bundlePath, globalFile);
var bundleMinFile = path.resolve(bundlePath, minFile);

var packagePath = path.resolve(releasePath, 'package.json');
var releaseVersion = require(packagePath).version;

//get sizes of release build
var bundleGlobal = fs.statSync(bundleGlobalFile);
var bundle_global_gzip = gzipSize.sync(fs.readFileSync(bundleGlobalFile, 'utf8'));
var bundleMin = fs.statSync(bundleMinFile);
var bundle_min_gzip = gzipSize.sync(fs.readFileSync(bundleMinFile, 'utf8'));

var sizeMessage = '<img src="https://img.shields.io/badge/Size%20Diff%20%28' + releaseVersion + '%29--lightgrey.svg?style=flat-square"/> ';
sizeMessage += '<img src="' + sizeDiffBadge('Global', global.size - bundleGlobal.size) + '"/> ';
sizeMessage += '<img src="' + sizeDiffBadge('Global(gzip)', global_gzip - bundle_global_gzip) + '"/> ';
sizeMessage += '<img src="' + sizeDiffBadge('Min', min.size - bundleMin.size) + '"/> ';
sizeMessage += '<img src="' + sizeDiffBadge('Min (gzip)', min_gzip - bundle_min_gzip) + '"/> ';
message(sizeMessage);

markdown('> CJS: **' + getKB(result) +
'**KB, global: **' + getKB(global.size) +
'**KB (gzipped: **' + getKB(global_gzip) +
'**KB), min: **' + getKB(min.size) +
'**KB (gzipped: **' + getKB(min_gzip) + '**KB)');

res();
});
}));
// TODO(benlesh): update script to run against proper global files
// The name has changed to `rxjs.umd.js` from `Rx.js`

// function getKB(size) {
// return (size / 1024).toFixed(1);
// }

// function getFormattedKB(size) {
// if (size < 0) {
// return '-' + size.toString();
// } else if (size > 0) {
// return '+' + size.toString();
// }
// return size.toString();
// }

// var globalFile = 'Rx.js';
// var minFile = 'Rx.min.js';

// function sizeDiffBadge(name, value) {
// var color = 'lightgrey';
// if (value > 0) {
// color = 'red';
// } else if (value < 0) {
// color = 'green';
// }
// return 'https://img.shields.io/badge/' + name + '-' + getFormattedKB(getKB(value)) + 'KB-' + color + '.svg?style=flat-square';
// }

// //post size of build
// schedule(new Promise(function (res) {
// getSize('./dist/cjs', function (e, result) {
// var localGlobalFile = path.resolve('./dist/global', globalFile);
// var localMinFile = path.resolve('./dist/global', minFile);

// //get sizes of PR build
// var global = fs.statSync(localGlobalFile);
// var global_gzip = gzipSize.sync(fs.readFileSync(localGlobalFile, 'utf8'));
// var min = fs.statSync(localMinFile);
// var min_gzip = gzipSize.sync(fs.readFileSync(localMinFile, 'utf8'));

// //resolve path to release build
// var releasePath = path.dirname(require.resolve(require.resolve('rxjs')));
// var bundlePath = path.resolve(releasePath, 'bundles');
// var bundleGlobalFile = path.resolve(bundlePath, globalFile);
// var bundleMinFile = path.resolve(bundlePath, minFile);

// var packagePath = path.resolve(releasePath, 'package.json');
// var releaseVersion = require(packagePath).version;

// //get sizes of release build
// var bundleGlobal = fs.statSync(bundleGlobalFile);
// var bundle_global_gzip = gzipSize.sync(fs.readFileSync(bundleGlobalFile, 'utf8'));
// var bundleMin = fs.statSync(bundleMinFile);
// var bundle_min_gzip = gzipSize.sync(fs.readFileSync(bundleMinFile, 'utf8'));

// var sizeMessage = '<img src="https://img.shields.io/badge/Size%20Diff%20%28' + releaseVersion + '%29--lightgrey.svg?style=flat-square"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Global', global.size - bundleGlobal.size) + '"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Global(gzip)', global_gzip - bundle_global_gzip) + '"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Min', min.size - bundleMin.size) + '"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Min (gzip)', min_gzip - bundle_min_gzip) + '"/> ';
// message(sizeMessage);

// markdown('> CJS: **' + getKB(result) +
// '**KB, global: **' + getKB(global.size) +
// '**KB (gzipped: **' + getKB(global_gzip) +
// '**KB), min: **' + getKB(min.size) +
// '**KB (gzipped: **' + getKB(min_gzip) + '**KB)');

// res();
// });
// }));
10 changes: 5 additions & 5 deletions src/internal/umd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
*/

/* rxjs */
export * from '../';
export * from '../index';

/* rxjs.operators */
import * as _operators from '../operators';
import * as _operators from '../operators/index';
export const operators = _operators;

/* rxjs.testing */
import * as _testing from '../testing';
import * as _testing from '../testing/index';
export const testing = _testing;

/* rxjs.ajax */
import * as _ajax from '../ajax';
import * as _ajax from '../ajax/index';
export const ajax = _ajax;

/* rxjs.websocket */
import * as _websocket from '../websocket';
import * as _websocket from '../websocket/index';
export const websocket = _websocket;
6 changes: 3 additions & 3 deletions tools/make-closure-core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var compiler = require('google-closure-compiler-js').compile;
var fs = require('fs');

var source = fs.readFileSync('dist/global/Rx.js', 'utf8');
var source = fs.readFileSync('dist/global/rxjs.umd.js', 'utf8');

var compilerFlags = {
jsCode: [{src: source}],
Expand All @@ -11,5 +11,5 @@ var compilerFlags = {

var output = compiler(compilerFlags);

fs.writeFileSync('dist/global/Rx.min.js', output.compiledCode, 'utf8');
fs.writeFileSync('dist/global/Rx.min.js.map', output.sourceMap, 'utf8');
fs.writeFileSync('dist/global/rxjs.umd.min.js', output.compiledCode, 'utf8');
fs.writeFileSync('dist/global/rxjs.umd.min.js.map', output.sourceMap, 'utf8');
8 changes: 4 additions & 4 deletions tools/make-umd-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var path = require('path');
var tslib = require('tslib');

rollup.rollup({
entry: 'dist/esm5_for_rollup/internal/Rx.js',
entry: 'dist/esm5_for_rollup/internal/umd.js',
plugins: [
rollupNodeResolve({
jsnext: true,
Expand All @@ -25,10 +25,10 @@ rollup.rollup({
}).then(function (bundle) {
var result = bundle.generate({
format: 'umd',
moduleName: 'Rx',
moduleName: 'rxjs',
sourceMap: true
});

fs.writeFileSync('dist/global/Rx.js', result.code);
fs.writeFileSync('dist/global/Rx.js.map', result.map);
fs.writeFileSync('dist/global/rxjs.umd.js', result.code);
fs.writeFileSync('dist/global/rxjs.umd.js.map', result.map);
});
5 changes: 4 additions & 1 deletion tsconfig/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

// legacy entry-points
"../dist/src/internal/Rx.ts",
"../dist/src/add/observable/of.ts"
"../dist/src/add/observable/of.ts",

// umd entry-point
"../dist/src/internal/umd.ts",
]
}