Skip to content

Commit f7da70d

Browse files
committed
Inlines the p-* utilities from sindresorhus's github to avoid more complex build configurations.
1 parent 4750ee9 commit f7da70d

File tree

4 files changed

+53
-89
lines changed

4 files changed

+53
-89
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,5 @@
9696
"webpack-dev-middleware": "1.10.1",
9797
"webpack-hot-middleware": "2.17.1"
9898
},
99-
"dependencies": {
100-
"p-map-series": "^1.0.0"
101-
}
99+
"dependencies": {}
102100
}

src/index.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,43 @@
66

77
// eslint-disable-next-line import/no-extraneous-dependencies
88
import { Children } from 'react'
9-
import pMapSeries from 'p-map-series'
9+
10+
// Lifted from https://github.com/sindresorhus/p-reduce
11+
// Thanks @sindresorhus!
12+
const pReduce = (iterable, reducer, initVal) =>
13+
new Promise((resolve, reject) => {
14+
const iterator = iterable[Symbol.iterator]()
15+
let i = 0
16+
17+
const next = (total) => {
18+
const el = iterator.next()
19+
20+
if (el.done) {
21+
resolve(total)
22+
return
23+
}
24+
25+
Promise.all([total, el.value])
26+
.then((value) => {
27+
// eslint-disable-next-line no-plusplus
28+
next(reducer(value[0], value[1], i++))
29+
})
30+
.catch(reject)
31+
}
32+
33+
next(initVal)
34+
})
35+
36+
// Lifted from https://github.com/sindresorhus/p-map-series
37+
// Thanks @sindresorhus!
38+
const pMapSeries = (iterable, iterator) => {
39+
const ret = []
40+
41+
return pReduce(iterable, (a, b, i) =>
42+
Promise.resolve(iterator(b, i)).then((val) => {
43+
ret.push(val)
44+
})).then(() => ret)
45+
}
1046

1147
export const isPromise = x => x != null && typeof x.then === 'function'
1248

tools/webpack/configFactory.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { resolve as resolvePath } from 'path';
2-
import webpack from 'webpack';
3-
import appRootDir from 'app-root-dir';
4-
import { removeEmpty, ifElse } from '../utils';
1+
import { resolve as resolvePath } from 'path'
2+
import webpack from 'webpack'
3+
import appRootDir from 'app-root-dir'
4+
import { removeEmpty, ifElse } from '../utils'
55

66
function webpackConfigFactory({ target }) {
7-
const libraryName = 'react-tree-walker';
8-
const minimize = target === 'umd-min';
7+
const libraryName = 'react-tree-walker'
8+
const minimize = target === 'umd-min'
99

1010
return {
1111
entry: {
@@ -61,17 +61,11 @@ function webpackConfigFactory({ target }) {
6161
{
6262
test: /\.js$/,
6363
loader: 'babel-loader',
64-
include: [
65-
resolvePath(appRootDir.get(), './src'),
66-
resolvePath(appRootDir.get(), './node_modules/p-limit'),
67-
resolvePath(appRootDir.get(), './node_modules/p-locate'),
68-
resolvePath(appRootDir.get(), './node_modules/p-map-series'),
69-
resolvePath(appRootDir.get(), './node_modules/p-reduce'),
70-
],
64+
include: [resolvePath(appRootDir.get(), './src')],
7165
},
7266
],
7367
},
74-
};
68+
}
7569
}
7670

77-
module.exports = webpackConfigFactory;
71+
module.exports = webpackConfigFactory

yarn.lock

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,7 @@ [email protected]:
301301
babylon "^6.13.0"
302302
lodash.pickby "^4.6.0"
303303

304-
babel-generator@^6.18.0:
305-
version "6.23.0"
306-
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.23.0.tgz#6b8edab956ef3116f79d8c84c5a3c05f32a74bc5"
307-
dependencies:
308-
babel-messages "^6.23.0"
309-
babel-runtime "^6.22.0"
310-
babel-types "^6.23.0"
311-
detect-indent "^4.0.0"
312-
jsesc "^1.3.0"
313-
lodash "^4.2.0"
314-
source-map "^0.5.0"
315-
trim-right "^1.0.1"
316-
317-
babel-generator@^6.24.0:
304+
babel-generator@^6.18.0, babel-generator@^6.24.0:
318305
version "6.24.0"
319306
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.24.0.tgz#eba270a8cc4ce6e09a61be43465d7c62c1f87c56"
320307
dependencies:
@@ -370,17 +357,7 @@ babel-helper-explode-assignable-expression@^6.22.0:
370357
babel-traverse "^6.22.0"
371358
babel-types "^6.22.0"
372359

373-
babel-helper-function-name@^6.22.0:
374-
version "6.22.0"
375-
resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.22.0.tgz#51f1bdc4bb89b15f57a9b249f33d742816dcbefc"
376-
dependencies:
377-
babel-helper-get-function-arity "^6.22.0"
378-
babel-runtime "^6.22.0"
379-
babel-template "^6.22.0"
380-
babel-traverse "^6.22.0"
381-
babel-types "^6.22.0"
382-
383-
babel-helper-function-name@^6.23.0:
360+
babel-helper-function-name@^6.22.0, babel-helper-function-name@^6.23.0:
384361
version "6.23.0"
385362
resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.23.0.tgz#25742d67175c8903dbe4b6cb9d9e1fcb8dcf23a6"
386363
dependencies:
@@ -404,13 +381,6 @@ babel-helper-hoist-variables@^6.22.0:
404381
babel-runtime "^6.22.0"
405382
babel-types "^6.22.0"
406383

407-
babel-helper-optimise-call-expression@^6.22.0:
408-
version "6.22.0"
409-
resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.22.0.tgz#f8d5d4b40a6e2605a6a7f9d537b581bea3756d15"
410-
dependencies:
411-
babel-runtime "^6.22.0"
412-
babel-types "^6.22.0"
413-
414384
babel-helper-optimise-call-expression@^6.23.0:
415385
version "6.23.0"
416386
resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.23.0.tgz#f3ee7eed355b4282138b33d02b78369e470622f5"
@@ -436,18 +406,7 @@ babel-helper-remap-async-to-generator@^6.22.0:
436406
babel-traverse "^6.22.0"
437407
babel-types "^6.22.0"
438408

439-
babel-helper-replace-supers@^6.22.0:
440-
version "6.22.0"
441-
resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.22.0.tgz#1fcee2270657548908c34db16bcc345f9850cf42"
442-
dependencies:
443-
babel-helper-optimise-call-expression "^6.22.0"
444-
babel-messages "^6.22.0"
445-
babel-runtime "^6.22.0"
446-
babel-template "^6.22.0"
447-
babel-traverse "^6.22.0"
448-
babel-types "^6.22.0"
449-
450-
babel-helper-replace-supers@^6.23.0:
409+
babel-helper-replace-supers@^6.22.0, babel-helper-replace-supers@^6.23.0:
451410
version "6.23.0"
452411
resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.23.0.tgz#eeaf8ad9b58ec4337ca94223bacdca1f8d9b4bfd"
453412
dependencies:
@@ -482,7 +441,7 @@ [email protected]:
482441
mkdirp "^0.5.1"
483442
object-assign "^4.0.1"
484443

485-
babel-messages@^6.22.0, babel-messages@^6.23.0:
444+
babel-messages@^6.23.0:
486445
version "6.23.0"
487446
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e"
488447
dependencies:
@@ -642,16 +601,7 @@ babel-plugin-transform-es2015-modules-amd@^6.24.0:
642601
babel-runtime "^6.22.0"
643602
babel-template "^6.22.0"
644603

645-
babel-plugin-transform-es2015-modules-commonjs@^6.22.0:
646-
version "6.22.0"
647-
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.22.0.tgz#6ca04e22b8e214fb50169730657e7a07dc941145"
648-
dependencies:
649-
babel-plugin-transform-strict-mode "^6.22.0"
650-
babel-runtime "^6.22.0"
651-
babel-template "^6.22.0"
652-
babel-types "^6.22.0"
653-
654-
babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.0:
604+
babel-plugin-transform-es2015-modules-commonjs@^6.22.0, babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.0:
655605
version "6.24.0"
656606
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.24.0.tgz#e921aefb72c2cc26cb03d107626156413222134f"
657607
dependencies:
@@ -983,14 +933,10 @@ babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22
983933
lodash "^4.2.0"
984934
to-fast-properties "^1.0.1"
985935

986-
[email protected], babylon@^6.11.0, babylon@^6.15.0:
936+
[email protected], babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0:
987937
version "6.15.0"
988938
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e"
989939

990-
babylon@^6.13.0:
991-
version "6.14.1"
992-
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.14.1.tgz#956275fab72753ad9b3435d7afe58f8bf0a29815"
993-
994940
balanced-match@^0.4.1:
995941
version "0.4.2"
996942
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
@@ -3689,16 +3635,6 @@ p-locate@^2.0.0:
36893635
dependencies:
36903636
p-limit "^1.1.0"
36913637

3692-
p-map-series@^1.0.0:
3693-
version "1.0.0"
3694-
resolved "https://registry.yarnpkg.com/p-map-series/-/p-map-series-1.0.0.tgz#bf98fe575705658a9e1351befb85ae4c1f07bdca"
3695-
dependencies:
3696-
p-reduce "^1.0.0"
3697-
3698-
p-reduce@^1.0.0:
3699-
version "1.0.0"
3700-
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"
3701-
37023638
pako@~0.2.0:
37033639
version "0.2.9"
37043640
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"

0 commit comments

Comments
 (0)