Skip to content

Commit d2abd1e

Browse files
committed
Require Node.js 12 and move to ESM
1 parent ea9c277 commit d2abd1e

File tree

8 files changed

+48
-53
lines changed

8 files changed

+48
-53
lines changed

.github/funding.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
1616
steps:
1717
- uses: actions/checkout@v2
18-
- uses: actions/setup-node@v1
18+
- uses: actions/setup-node@v2
1919
with:
2020
node-version: ${{ matrix.node-version }}
2121
- run: npm install

index.d.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
declare namespace pAll {
2-
type Options = import('p-map').Options;
1+
import {Options} from 'p-map';
32

4-
type PromiseFactory<T> = () => PromiseLike<T>;
3+
type PromiseFactory<T> = () => PromiseLike<T>;
54

6-
// From: https://github.com/microsoft/TypeScript/blob/4f5b3299fee9a54b692aba9df7a9e894bd86e81d/src/lib/es2015.promise.d.ts#L1
7-
type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T;
8-
}
5+
// From: https://github.com/microsoft/TypeScript/blob/4f5b3299fee9a54b692aba9df7a9e894bd86e81d/src/lib/es2015.promise.d.ts#L1
6+
type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T;
97

10-
// TODO: Refactor the whole definition back to multiple overloaded functions
118
/**
129
Run promise-returning & async functions concurrently with optional limited concurrency.
1310
@@ -16,24 +13,24 @@ Run promise-returning & async functions concurrently with optional limited concu
1613
1714
@example
1815
```
19-
import pAll = require('p-all');
20-
import got = require('got');
21-
22-
(async () => {
23-
const actions = [
24-
() => got('https://sindresorhus.com'),
25-
() => got('https://ava.li'),
26-
() => checkSomething(),
27-
() => doSomethingElse()
28-
];
29-
30-
console.log(await pAll(actions, {concurrency: 2}));
31-
})();
16+
import pAll from 'p-all';
17+
import got from 'got';
18+
19+
const actions = [
20+
() => got('https://sindresorhus.com'),
21+
() => got('https://avajs.dev'),
22+
() => checkSomething(),
23+
() => doSomethingElse()
24+
];
25+
26+
console.log(await pAll(actions, {concurrency: 2}));
3227
```
3328
*/
34-
declare const pAll: <Task extends Array<pAll.PromiseFactory<unknown>>>(
29+
export default function pAll<Task extends Array<PromiseFactory<unknown>>>(
3530
tasks: readonly [...Task],
36-
options?: pAll.Options,
37-
) => Promise<{ [P in keyof Task]: Task[P] extends () => unknown ? pAll.Awaited<ReturnType<Task[P]>> : Task[P] }>;
31+
options?: Options,
32+
): Promise<{
33+
[P in keyof Task]: Task[P] extends () => unknown ? Awaited<ReturnType<Task[P]>> : Task[P]
34+
}>;
3835

39-
export = pAll;
36+
export {Options};

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
'use strict';
2-
const pMap = require('p-map');
1+
import pMap from 'p-map';
32

4-
module.exports = (iterable, options) => pMap(iterable, element => element(), options);
3+
export default async function pAll(iterable, options) {
4+
return pMap(iterable, element => element(), options);
5+
}

index.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectType} from 'tsd';
2-
import pAll = require('.');
2+
import pAll from './index.js';
33

44
const actions: [
55
() => Promise<string>,
@@ -8,7 +8,7 @@ const actions: [
88
() => Promise<number>
99
] = [
1010
async () => Promise.resolve('https://sindresorhus.com'),
11-
async () => Promise.resolve('https://ava.li'),
11+
async () => Promise.resolve('https://avajs.dev'),
1212
async () => Promise.resolve(),
1313
async () => Promise.resolve(1)
1414
];

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"email": "[email protected]",
1111
"url": "https://sindresorhus.com"
1212
},
13+
"type": "module",
14+
"exports": "./index.js",
1315
"engines": {
14-
"node": ">=10"
16+
"node": ">=12.20"
1517
},
1618
"scripts": {
1719
"test": "xo && ava && tsd"
@@ -44,12 +46,12 @@
4446
"bluebird"
4547
],
4648
"dependencies": {
47-
"p-map": "^4.0.0"
49+
"p-map": "^5.0.0"
4850
},
4951
"devDependencies": {
50-
"ava": "^1.4.1",
51-
"delay": "^4.1.0",
52+
"ava": "^3.15.0",
53+
"delay": "^5.0.0",
5254
"tsd": "^0.16.0",
53-
"xo": "^0.28.0"
55+
"xo": "^0.40.1"
5456
}
5557
}

readme.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ $ npm install p-all
1717
## Usage
1818

1919
```js
20-
const pAll = require('p-all');
21-
const got = require('got');
22-
23-
(async () => {
24-
const actions = [
25-
() => got('https://sindresorhus.com'),
26-
() => got('https://ava.li'),
27-
() => checkSomething(),
28-
() => doSomethingElse()
29-
];
30-
31-
console.log(await pAll(actions, {concurrency: 2}));
32-
})();
20+
import pAll from 'p-all';
21+
import got from 'got';
22+
23+
const actions = [
24+
() => got('https://sindresorhus.com'),
25+
() => got('https://avajs.dev'),
26+
() => checkSomething(),
27+
() => doSomethingElse()
28+
];
29+
30+
console.log(await pAll(actions, {concurrency: 2}));
3331
```
3432

3533
## API

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22
import delay from 'delay';
3-
import pAll from '.';
3+
import pAll from './index.js';
44

55
// See `p-map` for more comprehensive tests.
66
test('main', async t => {

0 commit comments

Comments
 (0)