Skip to content

Commit

Permalink
fix: ix allSettled polyfill for node 10
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 10, 2020
1 parent 3d136f2 commit e91e8c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function loadAllSettled() {
values: Iterable<T>
): Promise<PromiseSettledResult<T extends PromiseLike<infer U> ? U : T>[]> {
return Promise.all(
Array(values).map(promise => {
Array.from(values).map(promise => {
if (promise instanceof Promise) {
return promise
.then(value => ({
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import _esm from 'esm'
import _glob from 'glob'
import { loadFromEntries } from './polyfills'
import { loadAllSettled, loadFromEntries } from './polyfills'

const esm = _esm(module)

if (!Object.fromEntries) loadFromEntries()
if (!Promise.allSettled) loadAllSettled()

export const glob = (pattern: string) =>
new Promise<string[]>((resolve, reject) =>
Expand Down Expand Up @@ -63,7 +64,7 @@ export const includeIf = <T>(test: any, item: T) => (test ? [item] : [])
export const runInParallel = async <T, R extends any>(
items: T[],
cb: (item: T) => Promise<R>
) => Promise.all(items.map(async item => cb(item)))
) => Promise.allSettled(items.map(async item => cb(item)))

export const asArray = <T>(item: T | T[] | undefined): T[] =>
item !== undefined ? (Array.isArray(item) ? item : [item]) : []

0 comments on commit e91e8c8

Please sign in to comment.