@parcel/utils 2.0.0-beta.1 → 2.0.0-nightly.1002
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/.eslintrc.js +6 -6
- package/lib/index.js +35850 -337
- package/lib/index.js.map +1 -0
- package/package.json +42 -20
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +143 -0
- package/src/ansi-html.js +2 -2
- package/src/blob.js +2 -1
- package/src/bundle-url.js +1 -1
- package/src/collection.js +14 -14
- package/src/config.js +93 -53
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +5 -5
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getRootDir.js +1 -2
- package/src/glob.js +36 -5
- package/src/hash.js +34 -0
- package/src/http-server.js +4 -11
- package/src/index.js +47 -20
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +4 -1
- package/src/openInBrowser.js +3 -1
- package/src/path.js +17 -2
- package/src/prettyDiagnostic.js +39 -27
- package/src/relativeBundlePath.js +5 -7
- package/src/replaceBundleReferences.js +50 -34
- package/src/schema.js +96 -42
- package/src/shared-buffer.js +24 -0
- package/src/sourcemap.js +84 -10
- package/src/urlJoin.js +3 -1
- package/test/DefaultMap.test.js +7 -4
- package/test/config.test.js +50 -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/input/sourcemap/referenced-min.js +1 -1
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +5 -9
- package/test/throttle.test.js +1 -2
- package/test/urlJoin.test.js +37 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -26
- package/lib/PromiseQueue.js +0 -133
- package/lib/TapStream.js +0 -38
- package/lib/ansi-html.js +0 -16
- package/lib/blob.js +0 -31
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -62
- package/lib/config.js +0 -109
- 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/escape-markdown.js +0 -15
- package/lib/generateBuildMetrics.js +0 -124
- package/lib/generateCertificate.js +0 -124
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -23
- package/lib/getRootDir.js +0 -55
- package/lib/glob.js +0 -69
- package/lib/http-server.js +0 -81
- package/lib/is-url.js +0 -17
- package/lib/isDirectoryInside.js +0 -16
- package/lib/md5.js +0 -40
- package/lib/objectHash.js +0 -26
- package/lib/openInBrowser.js +0 -70
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -30
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -75
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -18
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -166
- package/lib/resolve.js +0 -108
- package/lib/schema.js +0 -321
- package/lib/serializeObject.js +0 -28
- package/lib/sourcemap.js +0 -58
- package/lib/stream.js +0 -78
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/escape-markdown.js +0 -10
- package/src/md5.js +0 -49
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -216
- package/src/serializeObject.js +0 -22
- package/test/escapeMarkdown.test.js +0 -29
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import type {NamedBundle, Dependency} from '@parcel/types';
|
|
4
|
+
|
|
5
|
+
import assert from 'assert';
|
|
6
|
+
import {getURLReplacement} from '../src/replaceBundleReferences';
|
|
7
|
+
|
|
8
|
+
describe('replace bundle references', () => {
|
|
9
|
+
it('Query params and named pipeline, relative', () => {
|
|
10
|
+
// $FlowFixMe
|
|
11
|
+
let fromBundle: NamedBundle = {
|
|
12
|
+
filePath: '/user/dist/reformat.html',
|
|
13
|
+
name: 'reformat.html',
|
|
14
|
+
// $FlowFixMe
|
|
15
|
+
target: {
|
|
16
|
+
distDir: '/user/dist',
|
|
17
|
+
publicUrl: '/',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// $FlowFixMe
|
|
22
|
+
let toBundle: NamedBundle = {
|
|
23
|
+
filePath:
|
|
24
|
+
'/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
25
|
+
name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
26
|
+
// $FlowFixMe
|
|
27
|
+
target: {
|
|
28
|
+
distDir: '/user/dist',
|
|
29
|
+
publicUrl: '/',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// $FlowFixMe
|
|
34
|
+
let dependency: Dependency = {
|
|
35
|
+
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
36
|
+
specifier: 'url:./image.jpg?as=webp',
|
|
37
|
+
specifierType: 'esm',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let result = getURLReplacement({
|
|
41
|
+
dependency,
|
|
42
|
+
fromBundle,
|
|
43
|
+
toBundle,
|
|
44
|
+
relative: true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
assert.equal(
|
|
48
|
+
result.to,
|
|
49
|
+
'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
50
|
+
);
|
|
51
|
+
assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('Query params and named pipeline, absolute', () => {
|
|
55
|
+
// $FlowFixMe
|
|
56
|
+
let fromBundle: NamedBundle = {
|
|
57
|
+
filePath: '/user/dist/reformat.html',
|
|
58
|
+
name: 'reformat.html',
|
|
59
|
+
// $FlowFixMe
|
|
60
|
+
target: {
|
|
61
|
+
distDir: '/user/dist',
|
|
62
|
+
publicUrl: '/',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// $FlowFixMe
|
|
67
|
+
let toBundle: NamedBundle = {
|
|
68
|
+
filePath:
|
|
69
|
+
'/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
70
|
+
name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
71
|
+
// $FlowFixMe
|
|
72
|
+
target: {
|
|
73
|
+
distDir: '/user/dist',
|
|
74
|
+
publicUrl: '/',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// $FlowFixMe
|
|
79
|
+
let dependency: Dependency = {
|
|
80
|
+
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
81
|
+
specifier: 'url:./image.jpg?as=webp',
|
|
82
|
+
specifierType: 'esm',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let result = getURLReplacement({
|
|
86
|
+
dependency,
|
|
87
|
+
fromBundle,
|
|
88
|
+
toBundle,
|
|
89
|
+
relative: false,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
assert.equal(
|
|
93
|
+
result.to,
|
|
94
|
+
'/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
95
|
+
);
|
|
96
|
+
assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('Custom Public URL', () => {
|
|
100
|
+
// $FlowFixMe
|
|
101
|
+
let fromBundle: NamedBundle = {
|
|
102
|
+
filePath: '/user/dist/reformat.html',
|
|
103
|
+
name: 'reformat.html',
|
|
104
|
+
// $FlowFixMe
|
|
105
|
+
target: {
|
|
106
|
+
distDir: '/user/dist',
|
|
107
|
+
publicUrl: 'https://test.com/static',
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// $FlowFixMe
|
|
112
|
+
let toBundle: NamedBundle = {
|
|
113
|
+
filePath:
|
|
114
|
+
'/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
115
|
+
name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
116
|
+
// $FlowFixMe
|
|
117
|
+
target: {
|
|
118
|
+
distDir: '/user/dist',
|
|
119
|
+
publicUrl: 'https://test.com/static',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// $FlowFixMe
|
|
124
|
+
let dependency: Dependency = {
|
|
125
|
+
id: '074b36596e314797845a8ad17ceb5c9b',
|
|
126
|
+
specifier: './image.jpg',
|
|
127
|
+
specifierType: 'esm',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
let result = getURLReplacement({
|
|
131
|
+
dependency,
|
|
132
|
+
fromBundle,
|
|
133
|
+
toBundle,
|
|
134
|
+
relative: false,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
assert.equal(
|
|
138
|
+
result.to,
|
|
139
|
+
'https://test.com/static/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
140
|
+
);
|
|
141
|
+
assert.equal(result.from, '074b36596e314797845a8ad17ceb5c9b');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('Relative with folders in between', () => {
|
|
145
|
+
// $FlowFixMe
|
|
146
|
+
let fromBundle: NamedBundle = {
|
|
147
|
+
filePath: '/user/dist/reformat.html',
|
|
148
|
+
name: 'reformat.html',
|
|
149
|
+
// $FlowFixMe
|
|
150
|
+
target: {
|
|
151
|
+
distDir: '/user/dist',
|
|
152
|
+
publicUrl: 'https://test.com/static',
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// $FlowFixMe
|
|
157
|
+
let toBundle: NamedBundle = {
|
|
158
|
+
filePath:
|
|
159
|
+
'/user/dist/assets/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
160
|
+
name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
161
|
+
// $FlowFixMe
|
|
162
|
+
target: {
|
|
163
|
+
distDir: '/user/dist/assets',
|
|
164
|
+
publicUrl: 'https://test.com/static',
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// $FlowFixMe
|
|
169
|
+
let dependency: Dependency = {
|
|
170
|
+
id: '074b36596e3147e900a8ad17ceb5c90b',
|
|
171
|
+
specifier: 'url:./image.jpg?as=webp',
|
|
172
|
+
specifierType: 'esm',
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
let result = getURLReplacement({
|
|
176
|
+
dependency,
|
|
177
|
+
fromBundle,
|
|
178
|
+
toBundle,
|
|
179
|
+
relative: true,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
assert.equal(
|
|
183
|
+
result.to,
|
|
184
|
+
'assets/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
|
|
185
|
+
);
|
|
186
|
+
assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
|
|
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
|
+
});
|
|
268
|
+
});
|
package/test/sourcemap.test.js
CHANGED
|
@@ -46,10 +46,10 @@ describe('loadSourceMap', () => {
|
|
|
46
46
|
let contents = fs.readFileSync(filename, 'utf-8');
|
|
47
47
|
|
|
48
48
|
let foundMap = await loadSourceMapUrl(fs, filename, contents);
|
|
49
|
-
assert.equal(foundMap.url, 'referenced-min.js.map');
|
|
49
|
+
assert.equal(foundMap.url, 'file://referenced-min.js.map');
|
|
50
50
|
assert.equal(
|
|
51
51
|
foundMap.filename,
|
|
52
|
-
path.join(
|
|
52
|
+
path.join(__dirname, 'input/sourcemap/referenced-min.js.map'),
|
|
53
53
|
);
|
|
54
54
|
assert.deepEqual(foundMap.map, {
|
|
55
55
|
version: 3,
|
|
@@ -91,9 +91,7 @@ describe('loadSourceMap', () => {
|
|
|
91
91
|
assert(!!map);
|
|
92
92
|
|
|
93
93
|
let parsedMap = map.getMap();
|
|
94
|
-
assert.deepEqual(parsedMap.sources, [
|
|
95
|
-
path.normalize('input/sourcemap/referenced.js'),
|
|
96
|
-
]);
|
|
94
|
+
assert.deepEqual(parsedMap.sources, ['input/sourcemap/referenced.js']);
|
|
97
95
|
assert.deepEqual(parsedMap.names, ['hello', 'l', 'o', 'console', 'log']);
|
|
98
96
|
assert.deepEqual(parsedMap.mappings, [
|
|
99
97
|
{
|
|
@@ -189,9 +187,7 @@ describe('loadSourceMap', () => {
|
|
|
189
187
|
assert(!!map);
|
|
190
188
|
|
|
191
189
|
let parsedMap = map.getMap();
|
|
192
|
-
assert.deepEqual(parsedMap.sources, [
|
|
193
|
-
path.normalize('input/sourcemap/referenced.js'),
|
|
194
|
-
]);
|
|
190
|
+
assert.deepEqual(parsedMap.sources, ['input/sourcemap/referenced.js']);
|
|
195
191
|
});
|
|
196
192
|
|
|
197
193
|
it('Should remap sources when using sourceRoot', async () => {
|
|
@@ -206,6 +202,6 @@ describe('loadSourceMap', () => {
|
|
|
206
202
|
assert(!!map);
|
|
207
203
|
|
|
208
204
|
let parsedMap = map.getMap();
|
|
209
|
-
assert.deepEqual(parsedMap.sources, [
|
|
205
|
+
assert.deepEqual(parsedMap.sources, ['input/source.js']);
|
|
210
206
|
});
|
|
211
207
|
});
|
package/test/throttle.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
|
|
3
3
|
import assert from 'assert';
|
|
4
|
-
// $FlowFixMe
|
|
5
4
|
import sinon from 'sinon';
|
|
6
5
|
import throttle from '../src/throttle';
|
|
7
6
|
|
|
@@ -35,7 +34,7 @@ describe('throttle', () => {
|
|
|
35
34
|
|
|
36
35
|
it('preserves the `this` when throttled functions are invoked', () => {
|
|
37
36
|
let result;
|
|
38
|
-
let throttled = throttle(function() {
|
|
37
|
+
let throttled = throttle(function () {
|
|
39
38
|
result = this.bar;
|
|
40
39
|
}, 100);
|
|
41
40
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import urlJoin from '../src/urlJoin';
|
|
5
|
+
|
|
6
|
+
describe('urlJoin', () => {
|
|
7
|
+
it('Should join two paths', () => {
|
|
8
|
+
let joinedUrl = urlJoin('/', './image.jpeg?test=test');
|
|
9
|
+
assert.equal(joinedUrl, '/image.jpeg?test=test');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('Should join two paths with longer publicUrl', () => {
|
|
13
|
+
let joinedUrl = urlJoin('/static', './image.jpeg?test=test');
|
|
14
|
+
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('Should join two paths with longer publicUrl', () => {
|
|
18
|
+
let joinedUrl = urlJoin('/static', 'image.jpeg?test=test');
|
|
19
|
+
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Should turn windows path into posix', () => {
|
|
23
|
+
let joinedUrl = urlJoin('/static', '.\\image.jpeg?test=test');
|
|
24
|
+
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
|
|
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
|
+
});
|
|
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,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.makeDeferredWithPromise = makeDeferredWithPromise;
|
|
7
|
-
|
|
8
|
-
var _assert = _interopRequireDefault(require("assert"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function makeDeferredWithPromise() {
|
|
13
|
-
let deferred;
|
|
14
|
-
let promise = new Promise((resolve, reject) => {
|
|
15
|
-
deferred = {
|
|
16
|
-
resolve,
|
|
17
|
-
reject
|
|
18
|
-
};
|
|
19
|
-
}); // Promise constructor callback executes synchronously, so this is defined
|
|
20
|
-
|
|
21
|
-
(0, _assert.default)(deferred != null);
|
|
22
|
-
return {
|
|
23
|
-
deferred,
|
|
24
|
-
promise
|
|
25
|
-
};
|
|
26
|
-
}
|
package/lib/PromiseQueue.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Deferred = require("./Deferred");
|
|
9
|
-
|
|
10
|
-
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; }
|
|
11
|
-
|
|
12
|
-
class PromiseQueue {
|
|
13
|
-
constructor(opts = {
|
|
14
|
-
maxConcurrent: Infinity
|
|
15
|
-
}) {
|
|
16
|
-
_defineProperty(this, "_deferred", void 0);
|
|
17
|
-
|
|
18
|
-
_defineProperty(this, "_maxConcurrent", void 0);
|
|
19
|
-
|
|
20
|
-
_defineProperty(this, "_numRunning", 0);
|
|
21
|
-
|
|
22
|
-
_defineProperty(this, "_queue", []);
|
|
23
|
-
|
|
24
|
-
_defineProperty(this, "_runPromise", null);
|
|
25
|
-
|
|
26
|
-
_defineProperty(this, "_count", 0);
|
|
27
|
-
|
|
28
|
-
_defineProperty(this, "_results", []);
|
|
29
|
-
|
|
30
|
-
if (opts.maxConcurrent <= 0) {
|
|
31
|
-
throw new TypeError('maxConcurrent must be a positive, non-zero value');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
this._maxConcurrent = opts.maxConcurrent;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getNumWaiting() {
|
|
38
|
-
return this._queue.length;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
add(fn) {
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
let i = this._count++;
|
|
44
|
-
|
|
45
|
-
this._queue.push(() => fn().then(result => {
|
|
46
|
-
this._results[i] = result;
|
|
47
|
-
resolve(result);
|
|
48
|
-
}, err => {
|
|
49
|
-
reject(err);
|
|
50
|
-
throw err;
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
54
|
-
this._next();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
run() {
|
|
60
|
-
if (this._runPromise != null) {
|
|
61
|
-
return this._runPromise;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (this._queue.length === 0) {
|
|
65
|
-
return Promise.resolve([]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let {
|
|
69
|
-
deferred,
|
|
70
|
-
promise
|
|
71
|
-
} = (0, _Deferred.makeDeferredWithPromise)();
|
|
72
|
-
this._deferred = deferred;
|
|
73
|
-
this._runPromise = promise;
|
|
74
|
-
|
|
75
|
-
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
76
|
-
this._next();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return promise;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async _next() {
|
|
83
|
-
let fn = this._queue.shift();
|
|
84
|
-
|
|
85
|
-
await this._runFn(fn);
|
|
86
|
-
|
|
87
|
-
if (this._queue.length) {
|
|
88
|
-
this._next();
|
|
89
|
-
} else if (this._numRunning === 0) {
|
|
90
|
-
this._resolve();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async _runFn(fn) {
|
|
95
|
-
this._numRunning++;
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
await fn();
|
|
99
|
-
this._numRunning--;
|
|
100
|
-
} catch (e) {
|
|
101
|
-
this._reject(e); // rejecting resets state so numRunning is reset to 0 here
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
_resetState() {
|
|
107
|
-
this._queue = [];
|
|
108
|
-
this._count = 0;
|
|
109
|
-
this._results = [];
|
|
110
|
-
this._runPromise = null;
|
|
111
|
-
this._numRunning = 0;
|
|
112
|
-
this._deferred = null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
_reject(err) {
|
|
116
|
-
if (this._deferred != null) {
|
|
117
|
-
this._deferred.reject(err);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this._resetState();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
_resolve() {
|
|
124
|
-
if (this._deferred != null) {
|
|
125
|
-
this._deferred.resolve(this._results);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this._resetState();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
exports.default = PromiseQueue;
|
package/lib/TapStream.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _stream = require("stream");
|
|
9
|
-
|
|
10
|
-
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; }
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* "Taps" into the contents of a flowing stream, yielding chunks to the passed
|
|
14
|
-
* callback. Continues to pass data chunks down the stream.
|
|
15
|
-
*/
|
|
16
|
-
class TapStream extends _stream.Transform {
|
|
17
|
-
constructor(tap, options) {
|
|
18
|
-
super({ ...options
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "_tap", void 0);
|
|
22
|
-
|
|
23
|
-
this._tap = tap;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_transform(chunk, encoding, callback) {
|
|
27
|
-
try {
|
|
28
|
-
this._tap(Buffer.from(chunk));
|
|
29
|
-
|
|
30
|
-
callback(null, chunk);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
callback(err);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
exports.default = TapStream;
|
package/lib/ansi-html.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ansiHtml = ansiHtml;
|
|
7
|
-
|
|
8
|
-
var _ansiHtml = _interopRequireDefault(require("ansi-html"));
|
|
9
|
-
|
|
10
|
-
var _escapeHtml = require("./escape-html");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function ansiHtml(ansi) {
|
|
15
|
-
return (0, _ansiHtml.default)((0, _escapeHtml.escapeHTML)(ansi));
|
|
16
|
-
}
|
package/lib/blob.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blobToBuffer = blobToBuffer;
|
|
7
|
-
exports.blobToString = blobToString;
|
|
8
|
-
|
|
9
|
-
var _ = require("../");
|
|
10
|
-
|
|
11
|
-
var _stream = require("stream");
|
|
12
|
-
|
|
13
|
-
function blobToBuffer(blob) {
|
|
14
|
-
if (blob instanceof _stream.Readable) {
|
|
15
|
-
return (0, _.bufferStream)(blob);
|
|
16
|
-
} else if (blob instanceof Buffer) {
|
|
17
|
-
return Promise.resolve(Buffer.from(blob));
|
|
18
|
-
} else {
|
|
19
|
-
return Promise.resolve(Buffer.from(blob, 'utf8'));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function blobToString(blob) {
|
|
24
|
-
if (blob instanceof _stream.Readable) {
|
|
25
|
-
return (await (0, _.bufferStream)(blob)).toString();
|
|
26
|
-
} else if (blob instanceof Buffer) {
|
|
27
|
-
return blob.toString();
|
|
28
|
-
} else {
|
|
29
|
-
return blob;
|
|
30
|
-
}
|
|
31
|
-
}
|