@parcel/utils 2.0.0-beta.3 → 2.0.0-dev.1510
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +37516 -542
- package/lib/index.js.map +1 -0
- package/package.json +41 -18
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +13 -0
- package/src/alternatives.js +21 -6
- package/src/ansi-html.js +1 -1
- package/src/blob.js +1 -0
- package/src/collection.js +35 -3
- package/src/config.js +77 -22
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +5 -5
- package/src/getExisting.js +1 -4
- package/src/getModuleParts.js +23 -0
- package/src/glob.js +26 -3
- package/src/hash.js +49 -0
- package/src/http-server.js +19 -7
- package/src/index.js +25 -10
- package/src/path.js +11 -1
- package/src/prettyDiagnostic.js +90 -40
- package/src/progress-message.js +22 -0
- package/src/replaceBundleReferences.js +49 -25
- package/src/schema.js +20 -19
- package/src/shared-buffer.js +23 -0
- package/src/sourcemap.js +13 -7
- package/src/urlJoin.js +3 -1
- package/test/DefaultMap.test.js +7 -4
- package/test/PromiseQueue.test.js +28 -0
- package/test/collection.test.js +13 -1
- package/test/config.test.js +98 -0
- package/test/input/config/.testrc +3 -0
- package/test/input/config/config.cjs +3 -0
- package/test/input/config/config.js +3 -0
- package/test/input/config/config.json +3 -0
- package/test/input/config/empty.json +0 -0
- package/test/input/config/empty.toml +0 -0
- package/test/replaceBundleReferences.test.js +88 -4
- package/test/throttle.test.js +1 -1
- package/test/urlJoin.test.js +11 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -34
- package/lib/PromiseQueue.js +0 -144
- package/lib/TapStream.js +0 -46
- package/lib/alternatives.js +0 -151
- package/lib/ansi-html.js +0 -32
- package/lib/blob.js +0 -47
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -51
- package/lib/config.js +0 -159
- package/lib/countLines.js +0 -18
- package/lib/debounce.js +0 -20
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -24
- package/lib/generateBuildMetrics.js +0 -156
- package/lib/generateCertificate.js +0 -149
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -31
- package/lib/getRootDir.js +0 -74
- package/lib/glob.js +0 -118
- package/lib/http-server.js +0 -110
- package/lib/is-url.js +0 -27
- package/lib/isDirectoryInside.js +0 -24
- package/lib/md5.js +0 -61
- package/lib/objectHash.js +0 -34
- package/lib/openInBrowser.js +0 -94
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -44
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -119
- package/lib/relativeBundlePath.js +0 -38
- package/lib/relativeUrl.js +0 -32
- package/lib/replaceBundleReferences.js +0 -184
- package/lib/schema.js +0 -391
- package/lib/sourcemap.js +0 -155
- package/lib/stream.js +0 -86
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -43
- package/src/.babelrc +0 -3
- package/src/md5.js +0 -56
package/test/collection.test.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
3
|
import assert from 'assert';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
objectSortedEntries,
|
|
6
|
+
objectSortedEntriesDeep,
|
|
7
|
+
setDifference,
|
|
8
|
+
} from '../src/collection';
|
|
5
9
|
|
|
6
10
|
describe('objectSortedEntries', () => {
|
|
7
11
|
it('returns a sorted list of key/value tuples', () => {
|
|
@@ -38,3 +42,11 @@ describe('objectSortedEntriesDeep', () => {
|
|
|
38
42
|
);
|
|
39
43
|
});
|
|
40
44
|
});
|
|
45
|
+
describe('setDifference', () => {
|
|
46
|
+
it('returns a setDifference of two sets of T type', () => {
|
|
47
|
+
assert.deepEqual(
|
|
48
|
+
setDifference(new Set([1, 2, 3]), new Set([3, 4, 5])),
|
|
49
|
+
new Set([1, 2, 4, 5]),
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import {loadConfig} from '../src/config';
|
|
5
|
+
import {inputFS as fs} from '@parcel/test-utils';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
|
|
8
|
+
describe('loadConfig', () => {
|
|
9
|
+
it('load config with json', async () => {
|
|
10
|
+
assert.deepEqual(
|
|
11
|
+
(
|
|
12
|
+
await loadConfig(
|
|
13
|
+
fs,
|
|
14
|
+
path.join(__dirname, './input/config/config.json'),
|
|
15
|
+
['config.json'],
|
|
16
|
+
path.join(__dirname, './input/config/'),
|
|
17
|
+
)
|
|
18
|
+
)?.config,
|
|
19
|
+
{
|
|
20
|
+
hoge: 'fuga',
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should throw error with empty string json', async () => {
|
|
26
|
+
// $FlowFixMe[prop-missing]
|
|
27
|
+
await assert.rejects(async () => {
|
|
28
|
+
await loadConfig(
|
|
29
|
+
fs,
|
|
30
|
+
path.join(__dirname, './input/config/empty.json'),
|
|
31
|
+
['empty.json'],
|
|
32
|
+
path.join(__dirname, './input/config/'),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should load with empty string config toml', async () => {
|
|
38
|
+
assert.deepEqual(
|
|
39
|
+
(
|
|
40
|
+
await loadConfig(
|
|
41
|
+
fs,
|
|
42
|
+
path.join(__dirname, './input/config/empty.toml'),
|
|
43
|
+
['empty.toml'],
|
|
44
|
+
path.join(__dirname, './input/config/'),
|
|
45
|
+
)
|
|
46
|
+
)?.config,
|
|
47
|
+
{},
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should load with js', async () => {
|
|
52
|
+
assert.deepEqual(
|
|
53
|
+
(
|
|
54
|
+
await loadConfig(
|
|
55
|
+
fs,
|
|
56
|
+
path.join(__dirname, './input/config/config.js'),
|
|
57
|
+
['config.js'],
|
|
58
|
+
path.join(__dirname, './input/config/'),
|
|
59
|
+
)
|
|
60
|
+
)?.config,
|
|
61
|
+
{
|
|
62
|
+
hoge: 'fuga',
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should load with cjs', async () => {
|
|
68
|
+
assert.deepEqual(
|
|
69
|
+
(
|
|
70
|
+
await loadConfig(
|
|
71
|
+
fs,
|
|
72
|
+
path.join(__dirname, './input/config/config.cjs'),
|
|
73
|
+
['config.cjs'],
|
|
74
|
+
path.join(__dirname, './input/config/'),
|
|
75
|
+
)
|
|
76
|
+
)?.config,
|
|
77
|
+
{
|
|
78
|
+
hoge: 'fuga',
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should load without an extension as json', async () => {
|
|
84
|
+
assert.deepEqual(
|
|
85
|
+
(
|
|
86
|
+
await loadConfig(
|
|
87
|
+
fs,
|
|
88
|
+
path.join(__dirname, './input/config/.testrc'),
|
|
89
|
+
['.testrc'],
|
|
90
|
+
path.join(__dirname, './input/config/'),
|
|
91
|
+
)
|
|
92
|
+
)?.config,
|
|
93
|
+
{
|
|
94
|
+
hoge: 'fuga',
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
File without changes
|
|
File without changes
|
|
@@ -33,7 +33,8 @@ describe('replace bundle references', () => {
|
|
|
33
33
|
// $FlowFixMe
|
|
34
34
|
let dependency: Dependency = {
|
|
35
35
|
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
36
|
-
|
|
36
|
+
specifier: 'url:./image.jpg?as=webp',
|
|
37
|
+
specifierType: 'esm',
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
let result = getURLReplacement({
|
|
@@ -77,7 +78,8 @@ describe('replace bundle references', () => {
|
|
|
77
78
|
// $FlowFixMe
|
|
78
79
|
let dependency: Dependency = {
|
|
79
80
|
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
80
|
-
|
|
81
|
+
specifier: 'url:./image.jpg?as=webp',
|
|
82
|
+
specifierType: 'esm',
|
|
81
83
|
};
|
|
82
84
|
|
|
83
85
|
let result = getURLReplacement({
|
|
@@ -121,7 +123,8 @@ describe('replace bundle references', () => {
|
|
|
121
123
|
// $FlowFixMe
|
|
122
124
|
let dependency: Dependency = {
|
|
123
125
|
id: '074b36596e314797845a8ad17ceb5c9b',
|
|
124
|
-
|
|
126
|
+
specifier: './image.jpg',
|
|
127
|
+
specifierType: 'esm',
|
|
125
128
|
};
|
|
126
129
|
|
|
127
130
|
let result = getURLReplacement({
|
|
@@ -165,7 +168,8 @@ describe('replace bundle references', () => {
|
|
|
165
168
|
// $FlowFixMe
|
|
166
169
|
let dependency: Dependency = {
|
|
167
170
|
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
168
|
-
|
|
171
|
+
specifier: 'url:./image.jpg?as=webp',
|
|
172
|
+
specifierType: 'esm',
|
|
169
173
|
};
|
|
170
174
|
|
|
171
175
|
let result = getURLReplacement({
|
|
@@ -181,4 +185,84 @@ describe('replace bundle references', () => {
|
|
|
181
185
|
);
|
|
182
186
|
assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
|
|
183
187
|
});
|
|
188
|
+
|
|
189
|
+
it('should work with bundle names with colons, relative', () => {
|
|
190
|
+
// $FlowFixMe
|
|
191
|
+
let fromBundle: NamedBundle = {
|
|
192
|
+
filePath: '/user/dist/reformat.html',
|
|
193
|
+
name: 'reformat.html',
|
|
194
|
+
// $FlowFixMe
|
|
195
|
+
target: {
|
|
196
|
+
distDir: '/user/dist',
|
|
197
|
+
publicUrl: '/',
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// $FlowFixMe
|
|
202
|
+
let toBundle: NamedBundle = {
|
|
203
|
+
filePath: '/user/dist/a:b:c.html',
|
|
204
|
+
name: 'a:b:c.html',
|
|
205
|
+
// $FlowFixMe
|
|
206
|
+
target: {
|
|
207
|
+
distDir: '/user/dist',
|
|
208
|
+
publicUrl: '/',
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// $FlowFixMe
|
|
213
|
+
let dependency: Dependency = {
|
|
214
|
+
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
215
|
+
specifier: './a:b:c.html',
|
|
216
|
+
specifierType: 'esm',
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
let result = getURLReplacement({
|
|
220
|
+
dependency,
|
|
221
|
+
fromBundle,
|
|
222
|
+
toBundle,
|
|
223
|
+
relative: true,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
assert.equal(result.to, './a:b:c.html');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('should work with bundle names with colons, absolute', () => {
|
|
230
|
+
// $FlowFixMe
|
|
231
|
+
let fromBundle: NamedBundle = {
|
|
232
|
+
filePath: '/user/dist/reformat.html',
|
|
233
|
+
name: 'reformat.html',
|
|
234
|
+
// $FlowFixMe
|
|
235
|
+
target: {
|
|
236
|
+
distDir: '/user/dist',
|
|
237
|
+
publicUrl: '/',
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// $FlowFixMe
|
|
242
|
+
let toBundle: NamedBundle = {
|
|
243
|
+
filePath: '/user/dist/a:b:c.html',
|
|
244
|
+
name: 'a:b:c.html',
|
|
245
|
+
// $FlowFixMe
|
|
246
|
+
target: {
|
|
247
|
+
distDir: '/user/dist',
|
|
248
|
+
publicUrl: '/',
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// $FlowFixMe
|
|
253
|
+
let dependency: Dependency = {
|
|
254
|
+
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
255
|
+
specifier: './a:b:c.html',
|
|
256
|
+
specifierType: 'esm',
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
let result = getURLReplacement({
|
|
260
|
+
dependency,
|
|
261
|
+
fromBundle,
|
|
262
|
+
toBundle,
|
|
263
|
+
relative: false,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
assert.equal(result.to, '/a:b:c.html');
|
|
267
|
+
});
|
|
184
268
|
});
|
package/test/throttle.test.js
CHANGED
package/test/urlJoin.test.js
CHANGED
|
@@ -23,4 +23,15 @@ describe('urlJoin', () => {
|
|
|
23
23
|
let joinedUrl = urlJoin('/static', '.\\image.jpeg?test=test');
|
|
24
24
|
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
|
|
25
25
|
});
|
|
26
|
+
|
|
27
|
+
it('should support paths with colons', () => {
|
|
28
|
+
let joinedUrl = urlJoin('/static', 'a:b:c.html');
|
|
29
|
+
assert.equal(joinedUrl, '/static/a:b:c.html');
|
|
30
|
+
|
|
31
|
+
joinedUrl = urlJoin('/static', '/a:b:c.html');
|
|
32
|
+
assert.equal(joinedUrl, '/static/a:b:c.html');
|
|
33
|
+
|
|
34
|
+
joinedUrl = urlJoin('/static', './a:b:c.html');
|
|
35
|
+
assert.equal(joinedUrl, '/static/a:b:c.html');
|
|
36
|
+
});
|
|
26
37
|
});
|
package/lib/DefaultMap.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DefaultWeakMap = exports.DefaultMap = void 0;
|
|
7
|
-
|
|
8
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
|
|
10
|
-
class DefaultMap extends Map {
|
|
11
|
-
constructor(getDefault, entries) {
|
|
12
|
-
super(entries);
|
|
13
|
-
|
|
14
|
-
_defineProperty(this, "_getDefault", void 0);
|
|
15
|
-
|
|
16
|
-
this._getDefault = getDefault;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get(key) {
|
|
20
|
-
let ret;
|
|
21
|
-
|
|
22
|
-
if (this.has(key)) {
|
|
23
|
-
ret = super.get(key);
|
|
24
|
-
} else {
|
|
25
|
-
ret = this._getDefault(key);
|
|
26
|
-
this.set(key, ret);
|
|
27
|
-
} // $FlowFixMe
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return ret;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
} // Duplicated from DefaultMap implementation for Flow
|
|
34
|
-
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
exports.DefaultMap = DefaultMap;
|
|
38
|
-
|
|
39
|
-
class DefaultWeakMap extends WeakMap {
|
|
40
|
-
constructor(getDefault, entries) {
|
|
41
|
-
super(entries);
|
|
42
|
-
|
|
43
|
-
_defineProperty(this, "_getDefault", void 0);
|
|
44
|
-
|
|
45
|
-
this._getDefault = getDefault;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get(key) {
|
|
49
|
-
let ret;
|
|
50
|
-
|
|
51
|
-
if (this.has(key)) {
|
|
52
|
-
ret = super.get(key);
|
|
53
|
-
} else {
|
|
54
|
-
ret = this._getDefault(key);
|
|
55
|
-
this.set(key, ret);
|
|
56
|
-
} // $FlowFixMe
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return ret;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
exports.DefaultWeakMap = DefaultWeakMap;
|
package/lib/Deferred.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.makeDeferredWithPromise = makeDeferredWithPromise;
|
|
7
|
-
|
|
8
|
-
function _assert() {
|
|
9
|
-
const data = _interopRequireDefault(require("assert"));
|
|
10
|
-
|
|
11
|
-
_assert = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function makeDeferredWithPromise() {
|
|
21
|
-
let deferred;
|
|
22
|
-
let promise = new Promise((resolve, reject) => {
|
|
23
|
-
deferred = {
|
|
24
|
-
resolve,
|
|
25
|
-
reject
|
|
26
|
-
};
|
|
27
|
-
}); // Promise constructor callback executes synchronously, so this is defined
|
|
28
|
-
|
|
29
|
-
(0, _assert().default)(deferred != null);
|
|
30
|
-
return {
|
|
31
|
-
deferred,
|
|
32
|
-
promise
|
|
33
|
-
};
|
|
34
|
-
}
|
package/lib/PromiseQueue.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _Deferred() {
|
|
9
|
-
const data = require("./Deferred");
|
|
10
|
-
|
|
11
|
-
_Deferred = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
-
|
|
20
|
-
class PromiseQueue {
|
|
21
|
-
constructor(opts = {
|
|
22
|
-
maxConcurrent: Infinity
|
|
23
|
-
}) {
|
|
24
|
-
_defineProperty(this, "_deferred", void 0);
|
|
25
|
-
|
|
26
|
-
_defineProperty(this, "_maxConcurrent", void 0);
|
|
27
|
-
|
|
28
|
-
_defineProperty(this, "_numRunning", 0);
|
|
29
|
-
|
|
30
|
-
_defineProperty(this, "_queue", []);
|
|
31
|
-
|
|
32
|
-
_defineProperty(this, "_runPromise", null);
|
|
33
|
-
|
|
34
|
-
_defineProperty(this, "_error", void 0);
|
|
35
|
-
|
|
36
|
-
_defineProperty(this, "_count", 0);
|
|
37
|
-
|
|
38
|
-
_defineProperty(this, "_results", []);
|
|
39
|
-
|
|
40
|
-
if (opts.maxConcurrent <= 0) {
|
|
41
|
-
throw new TypeError('maxConcurrent must be a positive, non-zero value');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this._maxConcurrent = opts.maxConcurrent;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getNumWaiting() {
|
|
48
|
-
return this._queue.length;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
add(fn) {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
let i = this._count++;
|
|
54
|
-
|
|
55
|
-
this._queue.push(() => fn().then(result => {
|
|
56
|
-
this._results[i] = result;
|
|
57
|
-
resolve(result);
|
|
58
|
-
}, err => {
|
|
59
|
-
reject(err);
|
|
60
|
-
throw err;
|
|
61
|
-
}));
|
|
62
|
-
|
|
63
|
-
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
64
|
-
this._next();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
run() {
|
|
70
|
-
if (this._runPromise != null) {
|
|
71
|
-
return this._runPromise;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (this._queue.length === 0) {
|
|
75
|
-
return Promise.resolve([]);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let {
|
|
79
|
-
deferred,
|
|
80
|
-
promise
|
|
81
|
-
} = (0, _Deferred().makeDeferredWithPromise)();
|
|
82
|
-
this._deferred = deferred;
|
|
83
|
-
this._runPromise = promise;
|
|
84
|
-
|
|
85
|
-
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
86
|
-
this._next();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return promise;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async _next() {
|
|
93
|
-
let fn = this._queue.shift();
|
|
94
|
-
|
|
95
|
-
await this._runFn(fn);
|
|
96
|
-
|
|
97
|
-
if (this._queue.length) {
|
|
98
|
-
this._next();
|
|
99
|
-
} else if (this._numRunning === 0) {
|
|
100
|
-
this._done();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async _runFn(fn) {
|
|
105
|
-
this._numRunning++;
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
await fn();
|
|
109
|
-
} catch (e) {
|
|
110
|
-
// Only store the first error that occurs.
|
|
111
|
-
// We don't reject immediately so that any other concurrent
|
|
112
|
-
// requests have time to complete.
|
|
113
|
-
if (this._error == null) {
|
|
114
|
-
this._error = e;
|
|
115
|
-
}
|
|
116
|
-
} finally {
|
|
117
|
-
this._numRunning--;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
_resetState() {
|
|
122
|
-
this._queue = [];
|
|
123
|
-
this._count = 0;
|
|
124
|
-
this._results = [];
|
|
125
|
-
this._runPromise = null;
|
|
126
|
-
this._numRunning = 0;
|
|
127
|
-
this._deferred = null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
_done() {
|
|
131
|
-
if (this._deferred != null) {
|
|
132
|
-
if (this._error != null) {
|
|
133
|
-
this._deferred.reject(this._error);
|
|
134
|
-
} else {
|
|
135
|
-
this._deferred.resolve(this._results);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
this._resetState();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
exports.default = PromiseQueue;
|
package/lib/TapStream.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _stream() {
|
|
9
|
-
const data = require("stream");
|
|
10
|
-
|
|
11
|
-
_stream = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* "Taps" into the contents of a flowing stream, yielding chunks to the passed
|
|
22
|
-
* callback. Continues to pass data chunks down the stream.
|
|
23
|
-
*/
|
|
24
|
-
class TapStream extends _stream().Transform {
|
|
25
|
-
constructor(tap, options) {
|
|
26
|
-
super({ ...options
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
_defineProperty(this, "_tap", void 0);
|
|
30
|
-
|
|
31
|
-
this._tap = tap;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
_transform(chunk, encoding, callback) {
|
|
35
|
-
try {
|
|
36
|
-
this._tap(Buffer.from(chunk));
|
|
37
|
-
|
|
38
|
-
callback(null, chunk);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
callback(err);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.default = TapStream;
|