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