From 556c904ea61a8424e5d24f170b20eadbc05d01f0 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 13 Mar 2018 00:19:32 -0700 Subject: [PATCH] feat(umd): UMD now mirrors export schema for ESM and CJS (#3426) For example, if you want to do the same thing as but using the global file, you would use , If you wanted to do , that will be available at . Thus making the import/access points more predictable between the UMD and the ESM and CJS versions. --- .make-packages.js | 8 +- dangerfile.js | 141 ++++++++++++++++++------------------ src/internal/umd.ts | 10 +-- tools/make-closure-core.js | 6 +- tools/make-umd-bundle.js | 8 +- tsconfig/tsconfig.base.json | 5 +- 6 files changed, 92 insertions(+), 86 deletions(-) diff --git a/.make-packages.js b/.make-packages.js index f6eb8d0524..617fb8a81b 100644 --- a/.make-packages.js +++ b/.make-packages.js @@ -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) { diff --git a/dangerfile.js b/dangerfile.js index 4a2d0b1167..68488ea84e 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -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 = ' '; - sizeMessage += ' '; - sizeMessage += ' '; - sizeMessage += ' '; - sizeMessage += ' '; - 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 = ' '; +// sizeMessage += ' '; +// sizeMessage += ' '; +// sizeMessage += ' '; +// sizeMessage += ' '; +// 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(); +// }); +// })); diff --git a/src/internal/umd.ts b/src/internal/umd.ts index 4c96246dc5..04454f3088 100644 --- a/src/internal/umd.ts +++ b/src/internal/umd.ts @@ -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; diff --git a/tools/make-closure-core.js b/tools/make-closure-core.js index f507a0bf1e..41d94d836b 100644 --- a/tools/make-closure-core.js +++ b/tools/make-closure-core.js @@ -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}], @@ -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'); \ No newline at end of file +fs.writeFileSync('dist/global/rxjs.umd.min.js', output.compiledCode, 'utf8'); +fs.writeFileSync('dist/global/rxjs.umd.min.js.map', output.sourceMap, 'utf8'); \ No newline at end of file diff --git a/tools/make-umd-bundle.js b/tools/make-umd-bundle.js index 85a740584e..e76faf6c23 100644 --- a/tools/make-umd-bundle.js +++ b/tools/make-umd-bundle.js @@ -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, @@ -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); }); diff --git a/tsconfig/tsconfig.base.json b/tsconfig/tsconfig.base.json index ba995654ee..74674baaa7 100644 --- a/tsconfig/tsconfig.base.json +++ b/tsconfig/tsconfig.base.json @@ -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", ] }