@parcel/utils 2.0.0-nightly.977 → 2.0.0-nightly.991
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 +35876 -411
- package/lib/index.js.map +1 -0
- package/package.json +28 -15
- package/src/config.js +2 -2
- package/src/glob.js +14 -3
- package/src/index.js +1 -1
- package/src/replaceBundleReferences.js +3 -1
- package/lib/DefaultMap.js +0 -56
- package/lib/Deferred.js +0 -34
- package/lib/PromiseQueue.js +0 -124
- package/lib/TapStream.js +0 -41
- package/lib/alternatives.js +0 -134
- package/lib/ansi-html.js +0 -24
- package/lib/blob.js +0 -49
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -65
- package/lib/config.js +0 -198
- 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 -148
- package/lib/generateCertificate.js +0 -149
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -31
- package/lib/getRootDir.js +0 -66
- package/lib/glob.js +0 -110
- package/lib/hash.js +0 -44
- package/lib/http-server.js +0 -102
- package/lib/is-url.js +0 -27
- package/lib/isDirectoryInside.js +0 -24
- package/lib/objectHash.js +0 -34
- package/lib/openInBrowser.js +0 -94
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -49
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -139
- package/lib/relativeBundlePath.js +0 -30
- package/lib/relativeUrl.js +0 -32
- package/lib/replaceBundleReferences.js +0 -207
- package/lib/schema.js +0 -391
- package/lib/shared-buffer.js +0 -31
- package/lib/sourcemap.js +0 -147
- package/lib/stream.js +0 -86
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -46
package/lib/schema.js
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fuzzySearch = fuzzySearch;
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
|
|
9
|
-
function _diagnostic() {
|
|
10
|
-
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
11
|
-
|
|
12
|
-
_diagnostic = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _nullthrows() {
|
|
20
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
21
|
-
|
|
22
|
-
_nullthrows = function () {
|
|
23
|
-
return data;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function _fastestLevenshtein() {
|
|
30
|
-
const data = _interopRequireDefault(require("fastest-levenshtein"));
|
|
31
|
-
|
|
32
|
-
_fastestLevenshtein = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
40
|
-
|
|
41
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
42
|
-
|
|
43
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
44
|
-
|
|
45
|
-
// flowlint-next-line untyped-import:off
|
|
46
|
-
function validateSchema(schema, data) {
|
|
47
|
-
function walk(schemaAncestors, dataNode, dataPath) {
|
|
48
|
-
let [schemaNode] = schemaAncestors;
|
|
49
|
-
|
|
50
|
-
if (schemaNode.type) {
|
|
51
|
-
let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
|
|
52
|
-
|
|
53
|
-
if (schemaNode.type !== type) {
|
|
54
|
-
return {
|
|
55
|
-
type: 'type',
|
|
56
|
-
dataType: 'value',
|
|
57
|
-
dataPath,
|
|
58
|
-
expectedTypes: [schemaNode.type],
|
|
59
|
-
ancestors: schemaAncestors,
|
|
60
|
-
prettyType: schemaNode.__type
|
|
61
|
-
};
|
|
62
|
-
} else {
|
|
63
|
-
switch (schemaNode.type) {
|
|
64
|
-
case 'array':
|
|
65
|
-
{
|
|
66
|
-
if (schemaNode.items) {
|
|
67
|
-
let results = []; // $FlowFixMe type was already checked
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < dataNode.length; i++) {
|
|
70
|
-
let result = walk([schemaNode.items].concat(schemaAncestors), // $FlowFixMe type was already checked
|
|
71
|
-
dataNode[i], dataPath + '/' + i);
|
|
72
|
-
if (result) results.push(result);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
case 'string':
|
|
82
|
-
{
|
|
83
|
-
// $FlowFixMe type was already checked
|
|
84
|
-
let value = dataNode;
|
|
85
|
-
|
|
86
|
-
if (schemaNode.enum) {
|
|
87
|
-
if (!schemaNode.enum.includes(value)) {
|
|
88
|
-
return {
|
|
89
|
-
type: 'enum',
|
|
90
|
-
dataType: 'value',
|
|
91
|
-
dataPath,
|
|
92
|
-
expectedValues: schemaNode.enum,
|
|
93
|
-
actualValue: value,
|
|
94
|
-
ancestors: schemaAncestors
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
} else if (schemaNode.__validate) {
|
|
98
|
-
let validationError = schemaNode.__validate(value);
|
|
99
|
-
|
|
100
|
-
if (typeof validationError == 'string') {
|
|
101
|
-
return {
|
|
102
|
-
type: 'other',
|
|
103
|
-
dataType: 'value',
|
|
104
|
-
dataPath,
|
|
105
|
-
message: validationError,
|
|
106
|
-
actualValue: value,
|
|
107
|
-
ancestors: schemaAncestors
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
case 'number':
|
|
116
|
-
{
|
|
117
|
-
// $FlowFixMe type was already checked
|
|
118
|
-
let value = dataNode;
|
|
119
|
-
|
|
120
|
-
if (schemaNode.enum) {
|
|
121
|
-
if (!schemaNode.enum.includes(value)) {
|
|
122
|
-
return {
|
|
123
|
-
type: 'enum',
|
|
124
|
-
dataType: 'value',
|
|
125
|
-
dataPath,
|
|
126
|
-
expectedValues: schemaNode.enum,
|
|
127
|
-
actualValue: value,
|
|
128
|
-
ancestors: schemaAncestors
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
case 'object':
|
|
137
|
-
{
|
|
138
|
-
let results = [];
|
|
139
|
-
let invalidProps;
|
|
140
|
-
|
|
141
|
-
if (schemaNode.__forbiddenProperties) {
|
|
142
|
-
// $FlowFixMe type was already checked
|
|
143
|
-
let keys = Object.keys(dataNode);
|
|
144
|
-
invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
|
|
145
|
-
results.push(...invalidProps.map(k => ({
|
|
146
|
-
type: 'forbidden-prop',
|
|
147
|
-
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
148
|
-
dataType: 'key',
|
|
149
|
-
prop: k,
|
|
150
|
-
expectedProps: Object.keys(schemaNode.properties),
|
|
151
|
-
actualProps: keys,
|
|
152
|
-
ancestors: schemaAncestors
|
|
153
|
-
})));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (schemaNode.required) {
|
|
157
|
-
// $FlowFixMe type was already checked
|
|
158
|
-
let keys = Object.keys(dataNode);
|
|
159
|
-
let missingKeys = schemaNode.required.filter(val => !keys.includes(val));
|
|
160
|
-
results.push(...missingKeys.map(k => ({
|
|
161
|
-
type: 'missing-prop',
|
|
162
|
-
dataPath,
|
|
163
|
-
dataType: 'value',
|
|
164
|
-
prop: k,
|
|
165
|
-
expectedProps: schemaNode.required,
|
|
166
|
-
actualProps: keys,
|
|
167
|
-
ancestors: schemaAncestors
|
|
168
|
-
})));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (schemaNode.properties) {
|
|
172
|
-
let {
|
|
173
|
-
additionalProperties = true
|
|
174
|
-
} = schemaNode; // $FlowFixMe type was already checked
|
|
175
|
-
|
|
176
|
-
for (let k in dataNode) {
|
|
177
|
-
if (invalidProps && invalidProps.includes(k)) {
|
|
178
|
-
// Don't check type on forbidden props
|
|
179
|
-
continue;
|
|
180
|
-
} else if (k in schemaNode.properties) {
|
|
181
|
-
let result = walk([schemaNode.properties[k]].concat(schemaAncestors), // $FlowFixMe type was already checked
|
|
182
|
-
dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
183
|
-
if (result) results.push(result);
|
|
184
|
-
} else {
|
|
185
|
-
if (typeof additionalProperties === 'boolean') {
|
|
186
|
-
if (!additionalProperties) {
|
|
187
|
-
results.push({
|
|
188
|
-
type: 'enum',
|
|
189
|
-
dataType: 'key',
|
|
190
|
-
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
191
|
-
expectedValues: Object.keys(schemaNode.properties).filter( // $FlowFixMe type was already checked
|
|
192
|
-
p => !(p in dataNode)),
|
|
193
|
-
actualValue: k,
|
|
194
|
-
ancestors: schemaAncestors,
|
|
195
|
-
prettyType: schemaNode.__type
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
let result = walk([additionalProperties].concat(schemaAncestors), // $FlowFixMe type was already checked
|
|
200
|
-
dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
201
|
-
if (result) results.push(result);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
case 'boolean':
|
|
212
|
-
// NOOP, type was checked already
|
|
213
|
-
break;
|
|
214
|
-
|
|
215
|
-
default:
|
|
216
|
-
throw new Error(`Unimplemented schema type ${type}?`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
if (schemaNode.enum && !schemaNode.enum.includes(dataNode)) {
|
|
221
|
-
return {
|
|
222
|
-
type: 'enum',
|
|
223
|
-
dataType: 'value',
|
|
224
|
-
dataPath: dataPath,
|
|
225
|
-
expectedValues: schemaNode.enum,
|
|
226
|
-
actualValue: schemaNode,
|
|
227
|
-
ancestors: schemaAncestors
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (schemaNode.oneOf || schemaNode.allOf) {
|
|
232
|
-
let list = schemaNode.oneOf || schemaNode.allOf;
|
|
233
|
-
let results = [];
|
|
234
|
-
|
|
235
|
-
for (let f of list) {
|
|
236
|
-
let result = walk([f].concat(schemaAncestors), dataNode, dataPath);
|
|
237
|
-
if (result) results.push(result);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (schemaNode.oneOf ? results.length == schemaNode.oneOf.length : results.length > 0) {
|
|
241
|
-
// return the result with more values / longer key
|
|
242
|
-
results.sort((a, b) => Array.isArray(a) || Array.isArray(b) ? Array.isArray(a) && !Array.isArray(b) ? -1 : !Array.isArray(a) && Array.isArray(b) ? 1 : Array.isArray(a) && Array.isArray(b) ? b.length - a.length : 0 : b.dataPath.length - a.dataPath.length);
|
|
243
|
-
return results[0];
|
|
244
|
-
}
|
|
245
|
-
} else if (schemaNode.not) {
|
|
246
|
-
let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
|
|
247
|
-
|
|
248
|
-
if (!result || result.length == 0) {
|
|
249
|
-
return {
|
|
250
|
-
type: 'other',
|
|
251
|
-
dataPath,
|
|
252
|
-
dataType: null,
|
|
253
|
-
message: schemaNode.__message,
|
|
254
|
-
actualValue: dataNode,
|
|
255
|
-
ancestors: schemaAncestors
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return undefined;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
let result = walk([schema], data, '');
|
|
265
|
-
return Array.isArray(result) ? result : result ? [result] : [];
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
var _default = validateSchema;
|
|
269
|
-
exports.default = _default;
|
|
270
|
-
|
|
271
|
-
function fuzzySearch(expectedValues, actualValue) {
|
|
272
|
-
let result = expectedValues.map(exp => [exp, _fastestLevenshtein().default.distance(exp, actualValue)]).filter( // Remove if more than half of the string would need to be changed
|
|
273
|
-
([, d]) => d * 2 < actualValue.length);
|
|
274
|
-
result.sort(([, a], [, b]) => a - b);
|
|
275
|
-
return result.map(([v]) => v);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
279
|
-
var _data$data;
|
|
280
|
-
|
|
281
|
-
if ('source' in data && 'data' in data && typeof data.source !== 'string' && !data) {
|
|
282
|
-
throw new Error('At least one of data.source and data.source must be defined!');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
let object = data.map ? data.map.data : // $FlowFixMe we can assume it's a JSON object
|
|
286
|
-
(_data$data = data.data) !== null && _data$data !== void 0 ? _data$data : JSON.parse(data.source);
|
|
287
|
-
let errors = validateSchema(schema, object);
|
|
288
|
-
|
|
289
|
-
if (errors.length) {
|
|
290
|
-
var _data$filePath;
|
|
291
|
-
|
|
292
|
-
let keys = errors.map(e => {
|
|
293
|
-
let message;
|
|
294
|
-
|
|
295
|
-
if (e.type === 'enum') {
|
|
296
|
-
let {
|
|
297
|
-
actualValue
|
|
298
|
-
} = e;
|
|
299
|
-
let expectedValues = e.expectedValues.map(String);
|
|
300
|
-
let likely = actualValue != null ? fuzzySearch(expectedValues, String(actualValue)) : [];
|
|
301
|
-
|
|
302
|
-
if (likely.length > 0) {
|
|
303
|
-
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
304
|
-
} else if (expectedValues.length > 0) {
|
|
305
|
-
message = `Possible values: ${expectedValues.map(v => JSON.stringify(v)).join(', ')}`;
|
|
306
|
-
} else {
|
|
307
|
-
message = 'Unexpected value';
|
|
308
|
-
}
|
|
309
|
-
} else if (e.type === 'forbidden-prop') {
|
|
310
|
-
let {
|
|
311
|
-
prop,
|
|
312
|
-
expectedProps,
|
|
313
|
-
actualProps
|
|
314
|
-
} = e;
|
|
315
|
-
let likely = fuzzySearch(expectedProps, prop).filter(v => !actualProps.includes(v));
|
|
316
|
-
|
|
317
|
-
if (likely.length > 0) {
|
|
318
|
-
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
319
|
-
} else {
|
|
320
|
-
message = 'Unexpected property';
|
|
321
|
-
}
|
|
322
|
-
} else if (e.type === 'missing-prop') {
|
|
323
|
-
let {
|
|
324
|
-
prop,
|
|
325
|
-
actualProps
|
|
326
|
-
} = e;
|
|
327
|
-
let likely = fuzzySearch(actualProps, prop);
|
|
328
|
-
|
|
329
|
-
if (likely.length > 0) {
|
|
330
|
-
message = `Did you mean ${JSON.stringify(prop)}?`;
|
|
331
|
-
e.dataPath += '/' + likely[0];
|
|
332
|
-
e.dataType = 'key';
|
|
333
|
-
} else {
|
|
334
|
-
message = `Missing property ${prop}`;
|
|
335
|
-
}
|
|
336
|
-
} else if (e.type === 'type') {
|
|
337
|
-
if (e.prettyType != null) {
|
|
338
|
-
message = `Expected ${e.prettyType}`;
|
|
339
|
-
} else {
|
|
340
|
-
message = `Expected type ${e.expectedTypes.join(', ')}`;
|
|
341
|
-
}
|
|
342
|
-
} else {
|
|
343
|
-
message = e.message;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return {
|
|
347
|
-
key: e.dataPath,
|
|
348
|
-
type: e.dataType,
|
|
349
|
-
message
|
|
350
|
-
};
|
|
351
|
-
});
|
|
352
|
-
let map, code;
|
|
353
|
-
|
|
354
|
-
if (data.map) {
|
|
355
|
-
map = data.map;
|
|
356
|
-
code = data.source;
|
|
357
|
-
} else {
|
|
358
|
-
var _data$source;
|
|
359
|
-
|
|
360
|
-
// $FlowFixMe we can assume that data is valid JSON
|
|
361
|
-
map = (_data$source = data.source) !== null && _data$source !== void 0 ? _data$source : JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
|
|
362
|
-
code = map;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
let codeFrames = [{
|
|
366
|
-
filePath: (_data$filePath = data.filePath) !== null && _data$filePath !== void 0 ? _data$filePath : undefined,
|
|
367
|
-
language: 'json',
|
|
368
|
-
code,
|
|
369
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(map, keys.map(({
|
|
370
|
-
key,
|
|
371
|
-
type,
|
|
372
|
-
message
|
|
373
|
-
}) => {
|
|
374
|
-
var _data$prependKey;
|
|
375
|
-
|
|
376
|
-
return {
|
|
377
|
-
key: ((_data$prependKey = data.prependKey) !== null && _data$prependKey !== void 0 ? _data$prependKey : '') + key,
|
|
378
|
-
type: type,
|
|
379
|
-
message: message != null ? (0, _diagnostic().escapeMarkdown)(message) : message
|
|
380
|
-
};
|
|
381
|
-
}))
|
|
382
|
-
}];
|
|
383
|
-
throw new (_diagnostic().default)({
|
|
384
|
-
diagnostic: {
|
|
385
|
-
message: message,
|
|
386
|
-
origin,
|
|
387
|
-
codeFrames
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
};
|
package/lib/shared-buffer.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SharedBuffer = void 0;
|
|
7
|
-
|
|
8
|
-
/* global MessageChannel:readonly */
|
|
9
|
-
let SharedBuffer; // $FlowFixMe[prop-missing]
|
|
10
|
-
|
|
11
|
-
exports.SharedBuffer = SharedBuffer;
|
|
12
|
-
|
|
13
|
-
if (process.browser) {
|
|
14
|
-
exports.SharedBuffer = SharedBuffer = ArrayBuffer; // Safari has removed the constructor
|
|
15
|
-
|
|
16
|
-
if (typeof SharedArrayBuffer !== 'undefined') {
|
|
17
|
-
let channel = new MessageChannel();
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
// Firefox might throw when sending the Buffer over a MessagePort
|
|
21
|
-
channel.port1.postMessage(new SharedArrayBuffer(0));
|
|
22
|
-
exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
|
|
23
|
-
} catch (_) {// NOOP
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
channel.port1.close();
|
|
27
|
-
channel.port2.close();
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
|
|
31
|
-
}
|
package/lib/sourcemap.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.matchSourceMappingURL = matchSourceMappingURL;
|
|
7
|
-
exports.loadSourceMapUrl = loadSourceMapUrl;
|
|
8
|
-
exports.loadSourceMap = loadSourceMap;
|
|
9
|
-
exports.remapSourceLocation = remapSourceLocation;
|
|
10
|
-
exports.SOURCEMAP_EXTENSIONS = exports.SOURCEMAP_RE = void 0;
|
|
11
|
-
|
|
12
|
-
function _sourceMap() {
|
|
13
|
-
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
14
|
-
|
|
15
|
-
_sourceMap = function () {
|
|
16
|
-
return data;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function _path() {
|
|
23
|
-
const data = _interopRequireDefault(require("path"));
|
|
24
|
-
|
|
25
|
-
_path = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var _path2 = require("./path");
|
|
33
|
-
|
|
34
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
-
|
|
36
|
-
const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
|
|
37
|
-
exports.SOURCEMAP_RE = SOURCEMAP_RE;
|
|
38
|
-
const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
|
|
39
|
-
const SOURCEMAP_EXTENSIONS = new Set(['css', 'es', 'es6', 'js', 'jsx', 'mjs', 'ts', 'tsx']);
|
|
40
|
-
exports.SOURCEMAP_EXTENSIONS = SOURCEMAP_EXTENSIONS;
|
|
41
|
-
|
|
42
|
-
function matchSourceMappingURL(contents) {
|
|
43
|
-
return contents.match(SOURCEMAP_RE);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function loadSourceMapUrl(fs, filename, contents) {
|
|
47
|
-
let match = matchSourceMappingURL(contents);
|
|
48
|
-
|
|
49
|
-
if (match) {
|
|
50
|
-
let url = match[1].trim();
|
|
51
|
-
let dataURLMatch = url.match(DATA_URL_RE);
|
|
52
|
-
let mapFilePath;
|
|
53
|
-
|
|
54
|
-
if (dataURLMatch) {
|
|
55
|
-
mapFilePath = filename;
|
|
56
|
-
} else {
|
|
57
|
-
mapFilePath = url.replace(/^file:\/\//, '');
|
|
58
|
-
mapFilePath = (0, _path2.isAbsolute)(mapFilePath) ? mapFilePath : _path().default.join(_path().default.dirname(filename), mapFilePath);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
url,
|
|
63
|
-
filename: mapFilePath,
|
|
64
|
-
map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(mapFilePath, 'utf8'))
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function loadSourceMap(filename, contents, options) {
|
|
70
|
-
let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
|
|
71
|
-
|
|
72
|
-
if (foundMap) {
|
|
73
|
-
let mapSourceRoot = _path().default.dirname(filename);
|
|
74
|
-
|
|
75
|
-
if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
|
|
76
|
-
mapSourceRoot = _path().default.join(mapSourceRoot, foundMap.map.sourceRoot);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let sourcemapInstance = new (_sourceMap().default)(options.projectRoot);
|
|
80
|
-
sourcemapInstance.addVLQMap({ ...foundMap.map,
|
|
81
|
-
sources: foundMap.map.sources.map(s => {
|
|
82
|
-
return _path().default.join(mapSourceRoot, s);
|
|
83
|
-
})
|
|
84
|
-
});
|
|
85
|
-
return sourcemapInstance;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function remapSourceLocation(loc, originalMap) {
|
|
90
|
-
let {
|
|
91
|
-
filePath,
|
|
92
|
-
start: {
|
|
93
|
-
line: startLine,
|
|
94
|
-
column: startCol
|
|
95
|
-
},
|
|
96
|
-
end: {
|
|
97
|
-
line: endLine,
|
|
98
|
-
column: endCol
|
|
99
|
-
}
|
|
100
|
-
} = loc;
|
|
101
|
-
let lineDiff = endLine - startLine;
|
|
102
|
-
let colDiff = endCol - startCol;
|
|
103
|
-
let start = originalMap.findClosestMapping(startLine, startCol);
|
|
104
|
-
let end = originalMap.findClosestMapping(endLine, endCol);
|
|
105
|
-
|
|
106
|
-
if (start !== null && start !== void 0 && start.original) {
|
|
107
|
-
if (start.source) {
|
|
108
|
-
filePath = start.source;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
({
|
|
112
|
-
line: startLine,
|
|
113
|
-
column: startCol
|
|
114
|
-
} = start.original);
|
|
115
|
-
startCol++; // source map columns are 0-based
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (end !== null && end !== void 0 && end.original) {
|
|
119
|
-
({
|
|
120
|
-
line: endLine,
|
|
121
|
-
column: endCol
|
|
122
|
-
} = end.original);
|
|
123
|
-
endCol++;
|
|
124
|
-
|
|
125
|
-
if (endLine < startLine) {
|
|
126
|
-
endLine = startLine;
|
|
127
|
-
endCol = startCol;
|
|
128
|
-
} else if (endLine === startLine && endCol < startCol && lineDiff === 0) {
|
|
129
|
-
endCol = startCol + colDiff;
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
endLine = startLine;
|
|
133
|
-
endCol = startCol;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
filePath,
|
|
138
|
-
start: {
|
|
139
|
-
line: startLine,
|
|
140
|
-
column: startCol
|
|
141
|
-
},
|
|
142
|
-
end: {
|
|
143
|
-
line: endLine,
|
|
144
|
-
column: endCol
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
package/lib/stream.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.measureStreamLength = measureStreamLength;
|
|
7
|
-
exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
|
|
8
|
-
exports.bufferStream = bufferStream;
|
|
9
|
-
exports.blobToStream = blobToStream;
|
|
10
|
-
exports.streamFromPromise = streamFromPromise;
|
|
11
|
-
exports.fallbackStream = fallbackStream;
|
|
12
|
-
|
|
13
|
-
function _stream() {
|
|
14
|
-
const data = require("stream");
|
|
15
|
-
|
|
16
|
-
_stream = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function measureStreamLength(stream) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
let length = 0;
|
|
26
|
-
stream.on('data', chunk => {
|
|
27
|
-
length += chunk;
|
|
28
|
-
});
|
|
29
|
-
stream.on('end', () => resolve(length));
|
|
30
|
-
stream.on('error', reject);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function readableFromStringOrBuffer(str) {
|
|
35
|
-
// https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
|
|
36
|
-
const stream = new (_stream().Readable)();
|
|
37
|
-
stream.push(str);
|
|
38
|
-
stream.push(null);
|
|
39
|
-
return stream;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function bufferStream(stream) {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
let buf = Buffer.from([]);
|
|
45
|
-
stream.on('data', data => {
|
|
46
|
-
buf = Buffer.concat([buf, data]);
|
|
47
|
-
});
|
|
48
|
-
stream.on('end', () => {
|
|
49
|
-
resolve(buf);
|
|
50
|
-
});
|
|
51
|
-
stream.on('error', reject);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function blobToStream(blob) {
|
|
56
|
-
if (blob instanceof _stream().Readable) {
|
|
57
|
-
return blob;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return readableFromStringOrBuffer(blob);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function streamFromPromise(promise) {
|
|
64
|
-
const stream = new (_stream().PassThrough)();
|
|
65
|
-
promise.then(blob => {
|
|
66
|
-
if (blob instanceof _stream().Readable) {
|
|
67
|
-
blob.pipe(stream);
|
|
68
|
-
} else {
|
|
69
|
-
stream.end(blob);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return stream;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function fallbackStream(stream, fallback) {
|
|
76
|
-
const res = new (_stream().PassThrough)();
|
|
77
|
-
stream.on('error', err => {
|
|
78
|
-
if (err.code === 'ENOENT') {
|
|
79
|
-
fallback().pipe(res);
|
|
80
|
-
} else {
|
|
81
|
-
res.emit('error', err);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
stream.pipe(res);
|
|
85
|
-
return res;
|
|
86
|
-
}
|
package/lib/throttle.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = throttle;
|
|
7
|
-
|
|
8
|
-
function throttle(fn, delay) {
|
|
9
|
-
let lastCalled;
|
|
10
|
-
return function (...args) {
|
|
11
|
-
if (lastCalled == null || lastCalled + delay <= Date.now()) {
|
|
12
|
-
fn.call(this, ...args);
|
|
13
|
-
lastCalled = Date.now();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|