From 759d5c7be44139c5c6734615b43ca16fb7e884a1 Mon Sep 17 00:00:00 2001 From: Jason Aden Date: Mon, 30 Oct 2017 15:25:05 -0700 Subject: [PATCH] build: move index.ts to operators.ts to avoid node module resolution in SystemJS Fixes #2971, #2996, #3011 --- .make-packages.js | 33 +++++-------- src/operators.ts | 108 +++++++++++++++++++++++++++++++++++++++++ src/operators/index.ts | 108 ----------------------------------------- 3 files changed, 120 insertions(+), 129 deletions(-) create mode 100644 src/operators.ts delete mode 100644 src/operators/index.ts diff --git a/.make-packages.js b/.make-packages.js index 983b075ff7..8a0adac635 100644 --- a/.make-packages.js +++ b/.make-packages.js @@ -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; @@ -46,7 +43,13 @@ 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) { @@ -54,12 +57,15 @@ const fileNames = klawSync(CJS_ROOT, { } }) .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, @@ -70,7 +76,7 @@ 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); @@ -78,21 +84,6 @@ const fileMappings = fileNames.reduce((acc, 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); diff --git a/src/operators.ts b/src/operators.ts new file mode 100644 index 0000000000..798e525000 --- /dev/null +++ b/src/operators.ts @@ -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'; diff --git a/src/operators/index.ts b/src/operators/index.ts deleted file mode 100644 index 1d4ef82e4c..0000000000 --- a/src/operators/index.ts +++ /dev/null @@ -1,108 +0,0 @@ -export { audit } from './audit'; -export { auditTime } from './auditTime'; -export { buffer } from './buffer'; -export { bufferCount } from './bufferCount'; -export { bufferTime } from './bufferTime'; -export { bufferToggle } from './bufferToggle'; -export { bufferWhen } from './bufferWhen'; -export { catchError } from './catchError'; -export { combineAll } from './combineAll'; -export { combineLatest } from './combineLatest'; -export { concat } from './concat'; -export { concatAll } from './concatAll'; -export { concatMap } from './concatMap'; -export { concatMapTo } from './concatMapTo'; -export { count } from './count'; -export { debounce } from './debounce'; -export { debounceTime } from './debounceTime'; -export { defaultIfEmpty } from './defaultIfEmpty'; -export { delay } from './delay'; -export { delayWhen } from './delayWhen'; -export { dematerialize } from './dematerialize'; -export { distinct } from './distinct'; -export { distinctUntilChanged } from './distinctUntilChanged'; -export { distinctUntilKeyChanged } from './distinctUntilKeyChanged'; -export { elementAt } from './elementAt'; -export { every } from './every'; -export { exhaust } from './exhaust'; -export { exhaustMap } from './exhaustMap'; -export { expand } from './expand'; -export { filter } from './filter'; -export { finalize } from './finalize'; -export { find } from './find'; -export { findIndex } from './findIndex'; -export { first } from './first'; -export { groupBy } from './groupBy'; -export { ignoreElements } from './ignoreElements'; -export { isEmpty } from './isEmpty'; -export { last } from './last'; -export { map } from './map'; -export { mapTo } from './mapTo'; -export { materialize } from './materialize'; -export { max } from './max'; -export { merge } from './merge'; -export { mergeAll } from './mergeAll'; -export { mergeMap } from './mergeMap'; -export { mergeMap as flatMap } from './mergeMap'; -export { mergeMapTo } from './mergeMapTo'; -export { mergeScan } from './mergeScan'; -export { min } from './min'; -export { multicast } from './multicast'; -export { observeOn } from './observeOn'; -export { onErrorResumeNext } from './onErrorResumeNext'; -export { pairwise } from './pairwise'; -export { partition } from './partition'; -export { pluck } from './pluck'; -export { publish } from './publish'; -export { publishBehavior } from './publishBehavior'; -export { publishLast } from './publishLast'; -export { publishReplay } from './publishReplay'; -export { race } from './race'; -export { reduce } from './reduce'; -export { repeat } from './repeat'; -export { repeatWhen } from './repeatWhen'; -export { retry } from './retry'; -export { retryWhen } from './retryWhen'; -export { refCount } from './refCount'; -export { sample } from './sample'; -export { sampleTime } from './sampleTime'; -export { scan } from './scan'; -export { sequenceEqual } from './sequenceEqual'; -export { share } from './share'; -export { shareReplay } from './shareReplay'; -export { single } from './single'; -export { skip } from './skip'; -export { skipLast } from './skipLast'; -export { skipUntil } from './skipUntil'; -export { skipWhile } from './skipWhile'; -export { startWith } from './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 './subscribeOn'; -export { switchAll } from './switchAll'; -export { switchMap } from './switchMap'; -export { switchMapTo } from './switchMapTo'; -export { take } from './take'; -export { takeLast } from './takeLast'; -export { takeUntil } from './takeUntil'; -export { takeWhile } from './takeWhile'; -export { tap } from './tap'; -export { throttle } from './throttle'; -export { throttleTime } from './throttleTime'; -export { timeInterval } from './timeInterval'; -export { timeout } from './timeout'; -export { timeoutWith } from './timeoutWith'; -export { timestamp } from './timestamp'; -export { toArray } from './toArray'; -export { window } from './window'; -export { windowCount } from './windowCount'; -export { windowTime } from './windowTime'; -export { windowToggle } from './windowToggle'; -export { windowWhen } from './windowWhen'; -export { withLatestFrom } from './withLatestFrom'; -export { zip } from './zip'; -export { zipAll } from './zipAll';