Skip to content

Commit

Permalink
feat(compat): set up correct imports & get build working for rxjs-comapt
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonaden committed Mar 15, 2018
1 parent 70e562b commit 1a0dc97
Show file tree
Hide file tree
Showing 139 changed files with 618 additions and 516 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typings/

# Generated
dist/
dist-compat/
tmp/
coverage/
img/
Expand Down
53 changes: 53 additions & 0 deletions .make-compat-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";

let pkg = require('./compat/package.json');
let fs = require('fs-extra');
let mkdirp = require('mkdirp');
let path = require('path');
let klawSync = require('klaw-sync');
let licenseTool = require('./tools/add-license-to-file');
let addLicenseToFile = licenseTool.addLicenseToFile;
let addLicenseTextToFile = licenseTool.addLicenseTextToFile;

const ROOT = 'dist-compat/';
const CJS_ROOT = ROOT + 'cjs/compat/';
const ESM5_ROOT = ROOT + 'esm5/compat/';
const ESM2015_ROOT = ROOT + 'esm2015/compat/';
const TYPE_ROOT = ROOT + 'typings/compat/';
const PKG_ROOT = ROOT + 'package/';
const CJS_PKG = PKG_ROOT + '';
const ESM5_PKG = PKG_ROOT + '_esm5/';
const ESM2015_PKG = PKG_ROOT + '_esm2015/';
const UMD_PKG = PKG_ROOT + 'bundles/';
const TYPE_PKG = PKG_ROOT;

// License info for minified files
let licenseUrl = 'https://github.com/ReactiveX/RxJS/blob/master/LICENSE.txt';
let license = 'Apache License 2.0 ' + licenseUrl;

// Recreate the distribution folder
fs.removeSync(PKG_ROOT);
mkdirp.sync(PKG_ROOT);

// Copy over the sources
fs.copySync(TYPE_ROOT, TYPE_PKG);
copySources(CJS_ROOT, CJS_PKG);
copySources(ESM5_ROOT, ESM5_PKG, true);
copySources(ESM2015_ROOT, ESM2015_PKG, true);

fs.copySync('compat/package.json', PKG_ROOT + '/package.json');

function copySources(rootDir, packageDir, ignoreMissing) {
// If we are ignoring missing directories, early return when source doesn't exist
if (!fs.existsSync(rootDir)) {
if (ignoreMissing) {
return;
} else {
throw "Source root dir does not exist!";
}
}
// Copy over the CommonJS files
fs.copySync(rootDir, packageDir);
fs.copySync('./LICENSE.txt', packageDir + 'LICENSE.txt');
fs.copySync('./compat/README.md', packageDir + 'README.md');
}
15 changes: 15 additions & 0 deletions compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# RxJS Compatibility Package

This package is required to get backwards compatibility with RxJS pervious to version 6. It contains the imports to add operators to `Observable.prototype` and creation methods to `Observable`. This is what allows, for instance, dot-chaining:

```
Observable.interval(1)
.map(i => i * i)
```

vs

```
Observable.interval(1)
.pipe(map(i => i * i))
```
38 changes: 18 additions & 20 deletions compat/index.ts → compat/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,21 @@ export {

export {TestScheduler} from 'rxjs/testing';

export {Operator} from 'rxjs/internal/Operator';
export {Subscriber} from 'rxjs/internal/Subscriber';
export {AsyncSubject} from 'rxjs/internal/AsyncSubject';
export {ConnectableObservable} from 'rxjs/internal/observable/ConnectableObservable';
export {TimeoutError} from 'rxjs/internal/util/TimeoutError';
export {TimeInterval} from 'rxjs/internal/patching/operator/timeInterval';
export {Timestamp} from 'rxjs/internal/operators/timestamp';
export {VirtualTimeScheduler} from 'rxjs/internal/scheduler/VirtualTimeScheduler';
export {AjaxRequest, AjaxResponse, AjaxError, AjaxTimeoutError} from 'rxjs/internal/observable/dom/AjaxObservable';
export { Operator } from 'rxjs/internal/Operator';
export { Subscriber } from 'rxjs/internal/Subscriber';
export { AsyncSubject } from 'rxjs/internal/AsyncSubject';
export { ConnectableObservable } from 'rxjs/internal/observable/ConnectableObservable';
export { TimeoutError } from 'rxjs/internal/util/TimeoutError';
export { TimeInterval } from 'rxjs/internal/patching/operator/timeInterval';
export { Timestamp } from 'rxjs/internal/operators/timestamp';
export { VirtualTimeScheduler } from 'rxjs/internal/scheduler/VirtualTimeScheduler';
export { AjaxRequest, AjaxResponse, AjaxError, AjaxTimeoutError } from 'rxjs/internal/observable/dom/AjaxObservable';
import { AsapScheduler } from 'rxjs/internal/scheduler/AsapScheduler';
import { AsyncScheduler } from 'rxjs/internal/scheduler/AsyncScheduler';
import { QueueScheduler } from 'rxjs/internal/scheduler/QueueScheduler';
import { AnimationFrameScheduler } from 'rxjs/internal/scheduler/AnimationFrameScheduler';

import {
asapScheduler as asap,
asyncScheduler as async,
queueScheduler as queue,
animationFrameScheduler as animationFrame,

} from 'rxjs';
import { asapScheduler, asyncScheduler, queueScheduler, animationFrameScheduler } from 'rxjs';

import { rxSubscriber } from 'rxjs/internal/symbol/rxSubscriber';
import { iterator } from 'rxjs/internal/symbol/iterator';
Expand All @@ -199,10 +197,10 @@ export const operators = _operators;
* Use this for synchronizing with the platform's painting
*/
let Scheduler = {
asap,
queue,
animationFrame,
async
asap: asapScheduler,
queue: queueScheduler,
animationFrame: animationFrameScheduler,
async: asyncScheduler
};

/**
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/bindCallback.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { bindCallback as staticBindCallback } from '../../internal/observable/bindCallback';
import { Observable, bindCallback as staticBindCallback } from 'rxjs';

Observable.bindCallback = staticBindCallback;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let bindCallback: typeof staticBindCallback;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/bindNodeCallback.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { bindNodeCallback as staticBindNodeCallback } from '../../internal/observable/bindNodeCallback';
import { Observable, bindNodeCallback as staticBindNodeCallback } from 'rxjs';

Observable.bindNodeCallback = staticBindNodeCallback;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let bindNodeCallback: typeof staticBindNodeCallback;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/combineLatest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { combineLatest as combineLatestStatic } from '../../internal/observable/combineLatest';
import { Observable, combineLatest as combineLatestStatic } from 'rxjs';

Observable.combineLatest = combineLatestStatic;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let combineLatest: typeof combineLatestStatic;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/concat.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { concat as concatStatic } from '../../internal/observable/concat';
import { Observable, concat as concatStatic } from 'rxjs';

Observable.concat = concatStatic;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let concat: typeof concatStatic;
}
Expand Down
6 changes: 3 additions & 3 deletions compat/add/observable/defer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Observable } from '../../internal/Observable';
import { defer as staticDefer } from '../../internal/observable/defer';
import { Observable } from 'rxjs';
import { defer as staticDefer } from 'rxjs/observable/defer';

Observable.defer = staticDefer;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let defer: typeof staticDefer;
}
Expand Down
8 changes: 4 additions & 4 deletions compat/add/observable/dom/ajax.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Observable } from '../../../internal/Observable';
import { ajax as staticAjax } from '../../../internal/observable/dom/ajax';
import { AjaxCreationMethod } from '../../../internal/observable/dom/AjaxObservable';
import { Observable } from 'rxjs';
import { ajax as staticAjax } from 'rxjs/ajax';
import { AjaxCreationMethod } from 'rxjs/internal/observable/dom/AjaxObservable';

Observable.ajax = staticAjax;

declare module '../../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let ajax: AjaxCreationMethod;
}
Expand Down
6 changes: 3 additions & 3 deletions compat/add/observable/dom/webSocket.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Observable } from '../../../internal/Observable';
import { webSocket as staticWebSocket } from '../../../internal/observable/dom/webSocket';
import { Observable } from 'rxjs';
import { websocket as staticWebSocket } from 'rxjs/websocket';

Observable.webSocket = staticWebSocket;

declare module '../../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let webSocket: typeof staticWebSocket;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/empty.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { empty as staticEmpty } from '../../internal/observable/empty';
import { Observable, empty as staticEmpty } from 'rxjs';

Observable.empty = staticEmpty;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let empty: typeof staticEmpty;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/forkJoin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { forkJoin as staticForkJoin } from '../../internal/observable/forkJoin';
import { Observable, forkJoin as staticForkJoin } from 'rxjs';

Observable.forkJoin = staticForkJoin;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let forkJoin: typeof staticForkJoin;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/from.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { from as staticFrom } from '../../internal/observable/from';
import { Observable, from as staticFrom } from 'rxjs';

Observable.from = staticFrom;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let from: typeof staticFrom;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/fromEvent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { fromEvent as staticFromEvent } from '../../internal/observable/fromEvent';
import { Observable, fromEvent as staticFromEvent } from 'rxjs';

Observable.fromEvent = staticFromEvent;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let fromEvent: typeof staticFromEvent;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/fromEventPattern.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { fromEventPattern as staticFromEventPattern } from '../../internal/observable/fromEventPattern';
import { Observable, fromEventPattern as staticFromEventPattern } from 'rxjs';

Observable.fromEventPattern = staticFromEventPattern;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let fromEventPattern: typeof staticFromEventPattern;
}
Expand Down
8 changes: 4 additions & 4 deletions compat/add/observable/fromPromise.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Observable } from '../../internal/Observable';
import { fromPromise as staticFromPromise } from '../../internal/observable/fromPromise';
import { Observable } from 'rxjs';
import { fromPromise as staticFromPromise } from 'rxjs/internal/observable/fromPromise';

Observable.fromPromise = staticFromPromise;
(Observable as any).fromPromise = staticFromPromise;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let fromPromise: typeof staticFromPromise;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/generate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { generate as staticGenerate } from '../../internal/observable/generate';
import { Observable, generate as staticGenerate } from 'rxjs';

Observable.generate = staticGenerate;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let generate: typeof staticGenerate;
}
Expand Down
3 changes: 1 addition & 2 deletions compat/add/observable/if.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Observable } from '../../internal/Observable';
import { iif } from '../../internal/observable/iif';
import { Observable, iif } from 'rxjs';

//tslint:disable-next-line:no-any TypeScript doesn't like `if`
(Observable as any).if = iif;
5 changes: 2 additions & 3 deletions compat/add/observable/interval.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { interval as staticInterval } from '../../internal/observable/interval';
import { Observable, interval as staticInterval } from 'rxjs';

Observable.interval = staticInterval;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let interval: typeof staticInterval;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/merge.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { merge as mergeStatic } from '../../internal/observable/merge';
import { Observable, merge as mergeStatic } from 'rxjs';

Observable.merge = mergeStatic;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let merge: typeof mergeStatic;
}
Expand Down
6 changes: 3 additions & 3 deletions compat/add/observable/never.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Observable } from '../../internal/Observable';
import { NEVER } from '../../internal/observable/never';
import { Observable, interval } from 'rxjs';
import { NEVER } from 'rxjs/internal/observable/never';

export function staticNever() {
return NEVER;
}

Observable.never = staticNever;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let never: typeof staticNever;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/of.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { of as staticOf } from '../../internal/observable/of';
import { Observable, of as staticOf } from 'rxjs';

Observable.of = staticOf;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let of: typeof staticOf; //formOf an iceberg!
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/onErrorResumeNext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { onErrorResumeNext as staticOnErrorResumeNext } from '../../internal/observable/onErrorResumeNext';
import { Observable, onErrorResumeNext as staticOnErrorResumeNext } from 'rxjs';

Observable.onErrorResumeNext = staticOnErrorResumeNext;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let onErrorResumeNext: typeof staticOnErrorResumeNext;
}
Expand Down
5 changes: 2 additions & 3 deletions compat/add/observable/pairs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from '../../internal/Observable';
import { pairs as staticPairs } from '../../internal/observable/pairs';
import { Observable, pairs as staticPairs } from 'rxjs';

Observable.pairs = staticPairs;

declare module '../../internal/Observable' {
declare module 'rxjs/internal/Observable' {
namespace Observable {
export let pairs: typeof staticPairs;
}
Expand Down
Loading

0 comments on commit 1a0dc97

Please sign in to comment.