Skip to content

Commit

Permalink
fix(SystemJS): avoid node module resolution of pipeable operators (#3025
Browse files Browse the repository at this point in the history
)

Fixes #2971, #2996, #3011
  • Loading branch information
jasonaden authored and benlesh committed Nov 3, 2017
1 parent b4016cc commit d77e3d7
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 129 deletions.
33 changes: 12 additions & 21 deletions .make-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ const ESM2015_PKG = PKG_ROOT + '_esm2015/';
const UMD_PKG = PKG_ROOT + 'bundles/';
const TYPE_PKG = PKG_ROOT;

const EXPORT_FILE = 'index.js';


// License info for minified files
let licenseUrl = 'https://github.com/ReactiveX/RxJS/blob/master/LICENSE.txt';
let license = 'Apache License 2.0 ' + licenseUrl;
Expand All @@ -46,20 +43,29 @@ let rootPackageJson = Object.assign({}, pkg, {
typings: './Rx.d.ts'
});

// Get a list of the file names
// Get a list of the file names. Sort in reverse order so re-export files
// such as "operators.js" are AFTER their more specfic exports, such as
// "operators/map.js". This is due to a Webpack bug for node-resolved imports
// (rxjs/operators resolves to rxjs/operators.js), Webpack's "alias"
// functionality requires that the most broad mapping (rxjs/operators) be at
// the end of the alias mapping object. Created Webpack issue:
// https://github.com/webpack/webpack/issues/5870
const fileNames = klawSync(CJS_ROOT, {
nodir: true,
filter: function(item) {
return item.path.endsWith('.js');
}
})
.map(item => item.path)
.map(path => path.slice((`${__dirname}/${CJS_ROOT}`).length));
.map(path => path.slice((`${__dirname}/${CJS_ROOT}`).length))
.sort().reverse();

// Execute build optimizer transforms on ESM5 files
fileNames.map(fileName => {
if (!bo) return fileName;
let fullPath = path.resolve(__dirname, ESM5_ROOT, fileName);
// The file won't exist when running build_test as we don't create the ESM5 sources
if (!fs.existsSync(fullPath)) return fileName;
let content = fs.readFileSync(fullPath).toString();
let transformed = bo.transformJavascript({
content: content,
Expand All @@ -70,29 +76,14 @@ fileNames.map(fileName => {
});

// Create an object hash mapping imports to file names
const fileMappings = fileNames.reduce((acc, fileName) => {
const importTargets = fileNames.reduce((acc, fileName) => {
// Get the name of the file to be the new directory
const directory = fileName.slice(0, fileName.length - 3);

acc[directory] = fileName;
return acc;
}, {});

// For node-resolved imports (rxjs/operators resolves to rxjs/operators/index.js), Webpack's "alias"
// functionality requires that the most broad mapping (rxjs/operators) be at the end of the alias
// mapping object. Created Webpack issue: https://github.com/webpack/webpack/issues/5870
const importTargets = Object.assign({}, fileMappings, fileNames.reduce((acc, fileName) => {
// If the fileName is index.js (re-export file), create another entry
// for the root of the export. Example:
// fileName = 'rxjs/operators/index.js'
// create entry:
// {'rxjs/operators': 'rxjs/operators/index.js'}
if (fileName.slice(fileName.length - EXPORT_FILE.length) === EXPORT_FILE) {
acc[fileName.slice(0, EXPORT_FILE.length + 1)] = fileName;
}
return acc;
}, {}));

createImportTargets(importTargets, "_esm5/", ESM5_PKG);
createImportTargets(importTargets, "_esm2015/", ESM2015_PKG);

Expand Down
108 changes: 108 additions & 0 deletions src/operators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
export { audit } from './operators/audit';
export { auditTime } from './operators/auditTime';
export { buffer } from './operators/buffer';
export { bufferCount } from './operators/bufferCount';
export { bufferTime } from './operators/bufferTime';
export { bufferToggle } from './operators/bufferToggle';
export { bufferWhen } from './operators/bufferWhen';
export { catchError } from './operators/catchError';
export { combineAll } from './operators/combineAll';
export { combineLatest } from './operators/combineLatest';
export { concat } from './operators/concat';
export { concatAll } from './operators/concatAll';
export { concatMap } from './operators/concatMap';
export { concatMapTo } from './operators/concatMapTo';
export { count } from './operators/count';
export { debounce } from './operators/debounce';
export { debounceTime } from './operators/debounceTime';
export { defaultIfEmpty } from './operators/defaultIfEmpty';
export { delay } from './operators/delay';
export { delayWhen } from './operators/delayWhen';
export { dematerialize } from './operators/dematerialize';
export { distinct } from './operators/distinct';
export { distinctUntilChanged } from './operators/distinctUntilChanged';
export { distinctUntilKeyChanged } from './operators/distinctUntilKeyChanged';
export { elementAt } from './operators/elementAt';
export { every } from './operators/every';
export { exhaust } from './operators/exhaust';
export { exhaustMap } from './operators/exhaustMap';
export { expand } from './operators/expand';
export { filter } from './operators/filter';
export { finalize } from './operators/finalize';
export { find } from './operators/find';
export { findIndex } from './operators/findIndex';
export { first } from './operators/first';
export { groupBy } from './operators/groupBy';
export { ignoreElements } from './operators/ignoreElements';
export { isEmpty } from './operators/isEmpty';
export { last } from './operators/last';
export { map } from './operators/map';
export { mapTo } from './operators/mapTo';
export { materialize } from './operators/materialize';
export { max } from './operators/max';
export { merge } from './operators/merge';
export { mergeAll } from './operators/mergeAll';
export { mergeMap } from './operators/mergeMap';
export { mergeMap as flatMap } from './operators/mergeMap';
export { mergeMapTo } from './operators/mergeMapTo';
export { mergeScan } from './operators/mergeScan';
export { min } from './operators/min';
export { multicast } from './operators/multicast';
export { observeOn } from './operators/observeOn';
export { onErrorResumeNext } from './operators/onErrorResumeNext';
export { pairwise } from './operators/pairwise';
export { partition } from './operators/partition';
export { pluck } from './operators/pluck';
export { publish } from './operators/publish';
export { publishBehavior } from './operators/publishBehavior';
export { publishLast } from './operators/publishLast';
export { publishReplay } from './operators/publishReplay';
export { race } from './operators/race';
export { reduce } from './operators/reduce';
export { repeat } from './operators/repeat';
export { repeatWhen } from './operators/repeatWhen';
export { retry } from './operators/retry';
export { retryWhen } from './operators/retryWhen';
export { refCount } from './operators/refCount';
export { sample } from './operators/sample';
export { sampleTime } from './operators/sampleTime';
export { scan } from './operators/scan';
export { sequenceEqual } from './operators/sequenceEqual';
export { share } from './operators/share';
export { shareReplay } from './operators/shareReplay';
export { single } from './operators/single';
export { skip } from './operators/skip';
export { skipLast } from './operators/skipLast';
export { skipUntil } from './operators/skipUntil';
export { skipWhile } from './operators/skipWhile';
export { startWith } from './operators/startWith';
/**
* TODO(https://github.com/ReactiveX/rxjs/issues/2900): Add back subscribeOn once it can be
* treeshaken. Currently if this export is added back, it
* forces apps to bring in asap scheduler along with
* Immediate, root, and other supporting code.
*/
// export { subscribeOn } from './operators/subscribeOn';
export { switchAll } from './operators/switchAll';
export { switchMap } from './operators/switchMap';
export { switchMapTo } from './operators/switchMapTo';
export { take } from './operators/take';
export { takeLast } from './operators/takeLast';
export { takeUntil } from './operators/takeUntil';
export { takeWhile } from './operators/takeWhile';
export { tap } from './operators/tap';
export { throttle } from './operators/throttle';
export { throttleTime } from './operators/throttleTime';
export { timeInterval } from './operators/timeInterval';
export { timeout } from './operators/timeout';
export { timeoutWith } from './operators/timeoutWith';
export { timestamp } from './operators/timestamp';
export { toArray } from './operators/toArray';
export { window } from './operators/window';
export { windowCount } from './operators/windowCount';
export { windowTime } from './operators/windowTime';
export { windowToggle } from './operators/windowToggle';
export { windowWhen } from './operators/windowWhen';
export { withLatestFrom } from './operators/withLatestFrom';
export { zip } from './operators/zip';
export { zipAll } from './operators/zipAll';
108 changes: 0 additions & 108 deletions src/operators/index.ts

This file was deleted.

0 comments on commit d77e3d7

Please sign in to comment.