-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): remove unnecessary dependencies from @nrwl/react
- If Vite is used, then Webpack and Jest are not needed - If e2e is not used, then Cypress is not needed - Trims down on the amount of packages that are downloaded
- Loading branch information
Showing
40 changed files
with
734 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/devkit/src/utils/async-iterable/combine-async-iteratable-iterators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export async function* combineAsyncIterableIterators( | ||
...iterators: { 0: AsyncIterableIterator<any> } & AsyncIterableIterator<any>[] | ||
) { | ||
let [options] = iterators; | ||
if (typeof options.next === 'function') { | ||
options = Object.create(null); | ||
} else { | ||
iterators.shift(); | ||
} | ||
|
||
const getNextAsyncIteratorValue = getNextAsyncIteratorFactory(options); | ||
|
||
try { | ||
const asyncIteratorsValues = new Map( | ||
iterators.map((it, idx) => [idx, getNextAsyncIteratorValue(it, idx)]) | ||
); | ||
|
||
do { | ||
const { iterator, index } = await Promise.race( | ||
asyncIteratorsValues.values() | ||
); | ||
if (iterator.done) { | ||
asyncIteratorsValues.delete(index); | ||
} else { | ||
yield iterator.value; | ||
asyncIteratorsValues.set( | ||
index, | ||
getNextAsyncIteratorValue(iterators[index], index) | ||
); | ||
} | ||
} while (asyncIteratorsValues.size > 0); | ||
} finally { | ||
await Promise.allSettled(iterators.map((it) => it.return())); | ||
} | ||
} | ||
|
||
function getNextAsyncIteratorFactory(options) { | ||
return async (asyncIterator, index) => { | ||
try { | ||
const iterator = await asyncIterator.next(); | ||
|
||
return { index, iterator }; | ||
} catch (err) { | ||
if (options.errorCallback) { | ||
options.errorCallback(err, index); | ||
} | ||
return Promise.reject(err); | ||
} | ||
}; | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/devkit/src/utils/async-iterable/combine-async-iteratables-iterators.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { combineAsyncIterableIterators } from './combine-async-iteratable-iterators'; | ||
|
||
function delay(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
describe('combineAsyncIterators', () => { | ||
it('should merge iterators', async () => { | ||
async function* a() { | ||
await delay(20); | ||
yield 'a'; | ||
} | ||
|
||
async function* b() { | ||
await delay(0); | ||
yield 'b'; | ||
} | ||
|
||
const c = combineAsyncIterableIterators(a(), b()); | ||
const results = []; | ||
|
||
for await (const x of c) { | ||
results.push(x); | ||
} | ||
|
||
expect(results).toEqual(['b', 'a']); | ||
}); | ||
|
||
it('should throw when one iterator throws', async () => { | ||
async function* a() { | ||
await delay(20); | ||
yield 'a'; | ||
} | ||
|
||
async function* b() { | ||
throw new Error('threw in b'); | ||
} | ||
|
||
const c = combineAsyncIterableIterators(a(), b()); | ||
|
||
async function* d() { | ||
yield* c; | ||
} | ||
|
||
try { | ||
for await (const x of d()) { | ||
} | ||
throw new Error('should not reach here'); | ||
} catch (e) { | ||
expect(e.message).toMatch(/threw in b/); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.