Skip to content

Commit 556c904

Browse files
authored
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.
1 parent 1b69bd6 commit 556c904

File tree

6 files changed

+92
-86
lines changed

6 files changed

+92
-86
lines changed

.make-packages.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ fs.copySync('src/testing/package.json', PKG_ROOT + '/testing/package.json');
112112
if (fs.existsSync(UMD_ROOT)) {
113113
fs.copySync(UMD_ROOT, UMD_PKG);
114114
// Add licenses to tops of bundles
115-
addLicenseToFile('LICENSE.txt', UMD_PKG + 'Rx.js');
116-
addLicenseTextToFile(license, UMD_PKG + 'Rx.min.js');
117-
addLicenseToFile('LICENSE.txt', UMD_PKG + 'Rx.js');
118-
addLicenseTextToFile(license, UMD_PKG + 'Rx.min.js');
115+
addLicenseToFile('LICENSE.txt', UMD_PKG + 'rxjs.umd.js');
116+
addLicenseTextToFile(license, UMD_PKG + 'rxjs.umd.min.js');
117+
addLicenseToFile('LICENSE.txt', UMD_PKG + 'rxjs.umd.js');
118+
addLicenseTextToFile(license, UMD_PKG + 'rxjs.umd.min.js');
119119
}
120120

121121
function copySources(rootDir, packageDir, ignoreMissing) {

dangerfile.js

Lines changed: 72 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -69,72 +69,75 @@ if (!messageConventionValid) {
6969
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.');
7070
}
7171

72-
function getKB(size) {
73-
return (size / 1024).toFixed(1);
74-
}
75-
76-
function getFormattedKB(size) {
77-
if (size < 0) {
78-
return '-' + size.toString();
79-
} else if (size > 0) {
80-
return '+' + size.toString();
81-
}
82-
return size.toString();
83-
}
84-
85-
var globalFile = 'Rx.js';
86-
var minFile = 'Rx.min.js';
87-
88-
function sizeDiffBadge(name, value) {
89-
var color = 'lightgrey';
90-
if (value > 0) {
91-
color = 'red';
92-
} else if (value < 0) {
93-
color = 'green';
94-
}
95-
return 'https://img.shields.io/badge/' + name + '-' + getFormattedKB(getKB(value)) + 'KB-' + color + '.svg?style=flat-square';
96-
}
97-
98-
//post size of build
99-
schedule(new Promise(function (res) {
100-
getSize('./dist/cjs', function (e, result) {
101-
var localGlobalFile = path.resolve('./dist/global', globalFile);
102-
var localMinFile = path.resolve('./dist/global', minFile);
103-
104-
//get sizes of PR build
105-
var global = fs.statSync(localGlobalFile);
106-
var global_gzip = gzipSize.sync(fs.readFileSync(localGlobalFile, 'utf8'));
107-
var min = fs.statSync(localMinFile);
108-
var min_gzip = gzipSize.sync(fs.readFileSync(localMinFile, 'utf8'));
109-
110-
//resolve path to release build
111-
var releasePath = path.dirname(require.resolve(require.resolve('rxjs')));
112-
var bundlePath = path.resolve(releasePath, 'bundles');
113-
var bundleGlobalFile = path.resolve(bundlePath, globalFile);
114-
var bundleMinFile = path.resolve(bundlePath, minFile);
115-
116-
var packagePath = path.resolve(releasePath, 'package.json');
117-
var releaseVersion = require(packagePath).version;
118-
119-
//get sizes of release build
120-
var bundleGlobal = fs.statSync(bundleGlobalFile);
121-
var bundle_global_gzip = gzipSize.sync(fs.readFileSync(bundleGlobalFile, 'utf8'));
122-
var bundleMin = fs.statSync(bundleMinFile);
123-
var bundle_min_gzip = gzipSize.sync(fs.readFileSync(bundleMinFile, 'utf8'));
124-
125-
var sizeMessage = '<img src="https://img.shields.io/badge/Size%20Diff%20%28' + releaseVersion + '%29--lightgrey.svg?style=flat-square"/> ';
126-
sizeMessage += '<img src="' + sizeDiffBadge('Global', global.size - bundleGlobal.size) + '"/> ';
127-
sizeMessage += '<img src="' + sizeDiffBadge('Global(gzip)', global_gzip - bundle_global_gzip) + '"/> ';
128-
sizeMessage += '<img src="' + sizeDiffBadge('Min', min.size - bundleMin.size) + '"/> ';
129-
sizeMessage += '<img src="' + sizeDiffBadge('Min (gzip)', min_gzip - bundle_min_gzip) + '"/> ';
130-
message(sizeMessage);
131-
132-
markdown('> CJS: **' + getKB(result) +
133-
'**KB, global: **' + getKB(global.size) +
134-
'**KB (gzipped: **' + getKB(global_gzip) +
135-
'**KB), min: **' + getKB(min.size) +
136-
'**KB (gzipped: **' + getKB(min_gzip) + '**KB)');
137-
138-
res();
139-
});
140-
}));
72+
// TODO(benlesh): update script to run against proper global files
73+
// The name has changed to `rxjs.umd.js` from `Rx.js`
74+
75+
// function getKB(size) {
76+
// return (size / 1024).toFixed(1);
77+
// }
78+
79+
// function getFormattedKB(size) {
80+
// if (size < 0) {
81+
// return '-' + size.toString();
82+
// } else if (size > 0) {
83+
// return '+' + size.toString();
84+
// }
85+
// return size.toString();
86+
// }
87+
88+
// var globalFile = 'Rx.js';
89+
// var minFile = 'Rx.min.js';
90+
91+
// function sizeDiffBadge(name, value) {
92+
// var color = 'lightgrey';
93+
// if (value > 0) {
94+
// color = 'red';
95+
// } else if (value < 0) {
96+
// color = 'green';
97+
// }
98+
// return 'https://img.shields.io/badge/' + name + '-' + getFormattedKB(getKB(value)) + 'KB-' + color + '.svg?style=flat-square';
99+
// }
100+
101+
// //post size of build
102+
// schedule(new Promise(function (res) {
103+
// getSize('./dist/cjs', function (e, result) {
104+
// var localGlobalFile = path.resolve('./dist/global', globalFile);
105+
// var localMinFile = path.resolve('./dist/global', minFile);
106+
107+
// //get sizes of PR build
108+
// var global = fs.statSync(localGlobalFile);
109+
// var global_gzip = gzipSize.sync(fs.readFileSync(localGlobalFile, 'utf8'));
110+
// var min = fs.statSync(localMinFile);
111+
// var min_gzip = gzipSize.sync(fs.readFileSync(localMinFile, 'utf8'));
112+
113+
// //resolve path to release build
114+
// var releasePath = path.dirname(require.resolve(require.resolve('rxjs')));
115+
// var bundlePath = path.resolve(releasePath, 'bundles');
116+
// var bundleGlobalFile = path.resolve(bundlePath, globalFile);
117+
// var bundleMinFile = path.resolve(bundlePath, minFile);
118+
119+
// var packagePath = path.resolve(releasePath, 'package.json');
120+
// var releaseVersion = require(packagePath).version;
121+
122+
// //get sizes of release build
123+
// var bundleGlobal = fs.statSync(bundleGlobalFile);
124+
// var bundle_global_gzip = gzipSize.sync(fs.readFileSync(bundleGlobalFile, 'utf8'));
125+
// var bundleMin = fs.statSync(bundleMinFile);
126+
// var bundle_min_gzip = gzipSize.sync(fs.readFileSync(bundleMinFile, 'utf8'));
127+
128+
// var sizeMessage = '<img src="https://img.shields.io/badge/Size%20Diff%20%28' + releaseVersion + '%29--lightgrey.svg?style=flat-square"/> ';
129+
// sizeMessage += '<img src="' + sizeDiffBadge('Global', global.size - bundleGlobal.size) + '"/> ';
130+
// sizeMessage += '<img src="' + sizeDiffBadge('Global(gzip)', global_gzip - bundle_global_gzip) + '"/> ';
131+
// sizeMessage += '<img src="' + sizeDiffBadge('Min', min.size - bundleMin.size) + '"/> ';
132+
// sizeMessage += '<img src="' + sizeDiffBadge('Min (gzip)', min_gzip - bundle_min_gzip) + '"/> ';
133+
// message(sizeMessage);
134+
135+
// markdown('> CJS: **' + getKB(result) +
136+
// '**KB, global: **' + getKB(global.size) +
137+
// '**KB (gzipped: **' + getKB(global_gzip) +
138+
// '**KB), min: **' + getKB(min.size) +
139+
// '**KB (gzipped: **' + getKB(min_gzip) + '**KB)');
140+
141+
// res();
142+
// });
143+
// }));

src/internal/umd.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
*/
44

55
/* rxjs */
6-
export * from '../';
6+
export * from '../index';
77

88
/* rxjs.operators */
9-
import * as _operators from '../operators';
9+
import * as _operators from '../operators/index';
1010
export const operators = _operators;
1111

1212
/* rxjs.testing */
13-
import * as _testing from '../testing';
13+
import * as _testing from '../testing/index';
1414
export const testing = _testing;
1515

1616
/* rxjs.ajax */
17-
import * as _ajax from '../ajax';
17+
import * as _ajax from '../ajax/index';
1818
export const ajax = _ajax;
1919

2020
/* rxjs.websocket */
21-
import * as _websocket from '../websocket';
21+
import * as _websocket from '../websocket/index';
2222
export const websocket = _websocket;

tools/make-closure-core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var compiler = require('google-closure-compiler-js').compile;
22
var fs = require('fs');
33

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

66
var compilerFlags = {
77
jsCode: [{src: source}],
@@ -11,5 +11,5 @@ var compilerFlags = {
1111

1212
var output = compiler(compilerFlags);
1313

14-
fs.writeFileSync('dist/global/Rx.min.js', output.compiledCode, 'utf8');
15-
fs.writeFileSync('dist/global/Rx.min.js.map', output.sourceMap, 'utf8');
14+
fs.writeFileSync('dist/global/rxjs.umd.min.js', output.compiledCode, 'utf8');
15+
fs.writeFileSync('dist/global/rxjs.umd.min.js.map', output.sourceMap, 'utf8');

tools/make-umd-bundle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var path = require('path');
1010
var tslib = require('tslib');
1111

1212
rollup.rollup({
13-
entry: 'dist/esm5_for_rollup/internal/Rx.js',
13+
entry: 'dist/esm5_for_rollup/internal/umd.js',
1414
plugins: [
1515
rollupNodeResolve({
1616
jsnext: true,
@@ -25,10 +25,10 @@ rollup.rollup({
2525
}).then(function (bundle) {
2626
var result = bundle.generate({
2727
format: 'umd',
28-
moduleName: 'Rx',
28+
moduleName: 'rxjs',
2929
sourceMap: true
3030
});
3131

32-
fs.writeFileSync('dist/global/Rx.js', result.code);
33-
fs.writeFileSync('dist/global/Rx.js.map', result.map);
32+
fs.writeFileSync('dist/global/rxjs.umd.js', result.code);
33+
fs.writeFileSync('dist/global/rxjs.umd.js.map', result.map);
3434
});

tsconfig/tsconfig.base.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
// legacy entry-points
1515
"../dist/src/internal/Rx.ts",
16-
"../dist/src/add/observable/of.ts"
16+
"../dist/src/add/observable/of.ts",
17+
18+
// umd entry-point
19+
"../dist/src/internal/umd.ts",
1720
]
1821
}

0 commit comments

Comments
 (0)