@atlaspack/utils 2.17.2 → 2.17.3-typescript-80839fbd5.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/LICENSE +201 -0
- package/lib/DefaultMap.js +0 -4
- package/lib/config.js +3 -1
- package/lib/debug-tools.js +1 -0
- package/lib/generateCertificate.js +2 -0
- package/lib/glob.js +14 -4
- package/lib/index.js +164 -9
- package/lib/is-url.js +2 -0
- package/lib/objectHash.js +0 -1
- package/lib/prettyDiagnostic.js +3 -5
- package/lib/schema.js +38 -19
- package/lib/shared-buffer.js +1 -1
- package/lib/urlJoin.js +1 -1
- package/package.json +18 -13
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +41 -36
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +14 -15
- package/src/{ansi-html.js → ansi-html.ts} +0 -1
- package/src/{blob.js → blob.ts} +2 -4
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +14 -21
- package/src/{config.js → config.ts} +18 -19
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/{debug-tools.js → debug-tools.ts} +6 -8
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +16 -18
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -5
- package/src/{getCertificate.js → getCertificate.ts} +5 -3
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +0 -2
- package/src/{glob.js → glob.ts} +16 -11
- package/src/{hash.js → hash.ts} +22 -17
- package/src/{http-server.js → http-server.ts} +32 -38
- package/src/{index.js → index.ts} +7 -8
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +0 -1
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +1 -3
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +22 -20
- package/src/{progress-message.js → progress-message.ts} +3 -2
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +3 -3
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +54 -36
- package/src/{schema.js → schema.ts} +158 -141
- package/src/{shared-buffer.js → shared-buffer.ts} +6 -4
- package/src/{sourcemap.js → sourcemap.ts} +16 -6
- package/src/{stream.js → stream.ts} +29 -21
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +4 -0
- package/src/Deferred.js +0 -23
- package/src/throttle.js +0 -15
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import ThrowableDiagnostic, {
|
|
3
2
|
generateJSONCodeHighlights,
|
|
4
3
|
escapeMarkdown,
|
|
@@ -19,105 +18,107 @@ export type SchemaEntity =
|
|
|
19
18
|
| SchemaAllOf
|
|
20
19
|
| SchemaNot
|
|
21
20
|
| SchemaAny;
|
|
22
|
-
export type SchemaArray = {
|
|
23
|
-
type: 'array'
|
|
24
|
-
items?: SchemaEntity
|
|
25
|
-
__type?: string
|
|
26
|
-
|
|
27
|
-
export type SchemaBoolean = {
|
|
28
|
-
type: 'boolean'
|
|
29
|
-
__type?: string
|
|
30
|
-
|
|
31
|
-
export type SchemaOneOf = {
|
|
32
|
-
oneOf: Array<SchemaEntity
|
|
33
|
-
|
|
34
|
-
export type SchemaAllOf = {
|
|
35
|
-
allOf: Array<SchemaEntity
|
|
36
|
-
|
|
37
|
-
export type SchemaNot = {
|
|
38
|
-
not: SchemaEntity
|
|
39
|
-
__message: string
|
|
40
|
-
|
|
41
|
-
export type SchemaString = {
|
|
42
|
-
type: 'string'
|
|
43
|
-
enum?: Array<string
|
|
44
|
-
__validate?: (val: string) =>
|
|
45
|
-
__type?: string
|
|
46
|
-
|
|
47
|
-
export type SchemaNumber = {
|
|
48
|
-
type: 'number'
|
|
49
|
-
enum?: Array<number
|
|
50
|
-
__type?: string
|
|
51
|
-
|
|
52
|
-
export type SchemaEnum = {
|
|
53
|
-
enum: Array<
|
|
54
|
-
|
|
55
|
-
export type SchemaObject = {
|
|
56
|
-
type: 'object'
|
|
57
|
-
properties: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
21
|
+
export type SchemaArray = {
|
|
22
|
+
type: 'array';
|
|
23
|
+
items?: SchemaEntity;
|
|
24
|
+
__type?: string;
|
|
25
|
+
};
|
|
26
|
+
export type SchemaBoolean = {
|
|
27
|
+
type: 'boolean';
|
|
28
|
+
__type?: string;
|
|
29
|
+
};
|
|
30
|
+
export type SchemaOneOf = {
|
|
31
|
+
oneOf: Array<SchemaEntity>;
|
|
32
|
+
};
|
|
33
|
+
export type SchemaAllOf = {
|
|
34
|
+
allOf: Array<SchemaEntity>;
|
|
35
|
+
};
|
|
36
|
+
export type SchemaNot = {
|
|
37
|
+
not: SchemaEntity;
|
|
38
|
+
__message: string;
|
|
39
|
+
};
|
|
40
|
+
export type SchemaString = {
|
|
41
|
+
type: 'string';
|
|
42
|
+
enum?: Array<string>;
|
|
43
|
+
__validate?: (val: string) => string | null | undefined;
|
|
44
|
+
__type?: string;
|
|
45
|
+
};
|
|
46
|
+
export type SchemaNumber = {
|
|
47
|
+
type: 'number';
|
|
48
|
+
enum?: Array<number>;
|
|
49
|
+
__type?: string;
|
|
50
|
+
};
|
|
51
|
+
export type SchemaEnum = {
|
|
52
|
+
enum: Array<unknown>;
|
|
53
|
+
};
|
|
54
|
+
export type SchemaObject = {
|
|
55
|
+
type: 'object';
|
|
56
|
+
properties: {
|
|
57
|
+
[key: string]: SchemaEntity;
|
|
58
|
+
};
|
|
59
|
+
additionalProperties?: boolean | SchemaEntity;
|
|
60
|
+
required?: Array<string>;
|
|
61
|
+
__forbiddenProperties?: Array<string>;
|
|
62
|
+
__type?: string;
|
|
63
|
+
};
|
|
64
|
+
export type SchemaAny = Record<any, any>;
|
|
64
65
|
export type SchemaError =
|
|
65
|
-
| {
|
|
66
|
-
type: 'type'
|
|
67
|
-
expectedTypes: Array<string
|
|
68
|
-
dataType:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
message?: string,
|
|
111
|
-
dataPath: string,
|
|
112
|
-
ancestors: Array<SchemaEntity>,
|
|
113
|
-
|};
|
|
66
|
+
| {
|
|
67
|
+
type: 'type';
|
|
68
|
+
expectedTypes: Array<string>;
|
|
69
|
+
dataType: 'key' | null | undefined | 'value';
|
|
70
|
+
dataPath: string;
|
|
71
|
+
ancestors: Array<SchemaEntity>;
|
|
72
|
+
prettyType?: string;
|
|
73
|
+
}
|
|
74
|
+
| {
|
|
75
|
+
type: 'enum';
|
|
76
|
+
expectedValues: Array<unknown>;
|
|
77
|
+
dataType: 'key' | 'value';
|
|
78
|
+
actualValue: unknown;
|
|
79
|
+
dataPath: string;
|
|
80
|
+
ancestors: Array<SchemaEntity>;
|
|
81
|
+
prettyType?: string;
|
|
82
|
+
}
|
|
83
|
+
| {
|
|
84
|
+
type: 'forbidden-prop';
|
|
85
|
+
prop: string;
|
|
86
|
+
expectedProps: Array<string>;
|
|
87
|
+
actualProps: Array<string>;
|
|
88
|
+
dataType: 'key';
|
|
89
|
+
dataPath: string;
|
|
90
|
+
ancestors: Array<SchemaEntity>;
|
|
91
|
+
prettyType?: string;
|
|
92
|
+
}
|
|
93
|
+
| {
|
|
94
|
+
type: 'missing-prop';
|
|
95
|
+
prop: string;
|
|
96
|
+
expectedProps: Array<string>;
|
|
97
|
+
actualProps: Array<string>;
|
|
98
|
+
dataType: 'key' | 'value';
|
|
99
|
+
dataPath: string;
|
|
100
|
+
ancestors: Array<SchemaEntity>;
|
|
101
|
+
prettyType?: string;
|
|
102
|
+
}
|
|
103
|
+
| {
|
|
104
|
+
type: 'other';
|
|
105
|
+
actualValue: unknown;
|
|
106
|
+
dataType: 'key' | null | undefined | 'value';
|
|
107
|
+
message?: string;
|
|
108
|
+
dataPath: string;
|
|
109
|
+
ancestors: Array<SchemaEntity>;
|
|
110
|
+
};
|
|
114
111
|
|
|
115
|
-
function validateSchema(
|
|
112
|
+
function validateSchema(
|
|
113
|
+
schema: SchemaEntity,
|
|
114
|
+
data: unknown,
|
|
115
|
+
): Array<SchemaError> {
|
|
116
116
|
function walk(
|
|
117
|
+
// @ts-expect-error TS7006
|
|
117
118
|
schemaAncestors,
|
|
118
|
-
dataNode,
|
|
119
|
-
dataPath,
|
|
120
|
-
):
|
|
119
|
+
dataNode: unknown,
|
|
120
|
+
dataPath: string,
|
|
121
|
+
): SchemaError | null | undefined | Array<SchemaError> {
|
|
121
122
|
let [schemaNode] = schemaAncestors;
|
|
122
123
|
|
|
123
124
|
if (schemaNode.type) {
|
|
@@ -136,23 +137,26 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
136
137
|
case 'array': {
|
|
137
138
|
if (schemaNode.items) {
|
|
138
139
|
let results: Array<SchemaError | Array<SchemaError>> = [];
|
|
139
|
-
//
|
|
140
|
+
// @ts-expect-error TS18046
|
|
140
141
|
for (let i = 0; i < dataNode.length; i++) {
|
|
141
142
|
let result = walk(
|
|
142
143
|
[schemaNode.items].concat(schemaAncestors),
|
|
143
|
-
//
|
|
144
|
+
// @ts-expect-error TS18046
|
|
144
145
|
dataNode[i],
|
|
145
146
|
dataPath + '/' + i,
|
|
146
147
|
);
|
|
147
148
|
if (result) results.push(result);
|
|
148
149
|
}
|
|
149
150
|
if (results.length)
|
|
150
|
-
return results.reduce(
|
|
151
|
+
return results.reduce<Array<any>>(
|
|
152
|
+
(acc, v) => acc.concat(v),
|
|
153
|
+
[],
|
|
154
|
+
);
|
|
151
155
|
}
|
|
152
156
|
break;
|
|
153
157
|
}
|
|
154
158
|
case 'string': {
|
|
155
|
-
//
|
|
159
|
+
// @ts-expect-error TS2322
|
|
156
160
|
let value: string = dataNode;
|
|
157
161
|
if (schemaNode.enum) {
|
|
158
162
|
if (!schemaNode.enum.includes(value)) {
|
|
@@ -181,7 +185,7 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
181
185
|
break;
|
|
182
186
|
}
|
|
183
187
|
case 'number': {
|
|
184
|
-
//
|
|
188
|
+
// @ts-expect-error TS2322
|
|
185
189
|
let value: number = dataNode;
|
|
186
190
|
if (schemaNode.enum) {
|
|
187
191
|
if (!schemaNode.enum.includes(value)) {
|
|
@@ -201,13 +205,15 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
201
205
|
let results: Array<Array<SchemaError> | SchemaError> = [];
|
|
202
206
|
let invalidProps;
|
|
203
207
|
if (schemaNode.__forbiddenProperties) {
|
|
204
|
-
//
|
|
208
|
+
// @ts-expect-error TS2769
|
|
205
209
|
let keys = Object.keys(dataNode);
|
|
210
|
+
// @ts-expect-error TS7006
|
|
206
211
|
invalidProps = schemaNode.__forbiddenProperties.filter((val) =>
|
|
207
212
|
keys.includes(val),
|
|
208
213
|
);
|
|
209
214
|
results.push(
|
|
210
215
|
...invalidProps.map(
|
|
216
|
+
// @ts-expect-error TS7006
|
|
211
217
|
(k) =>
|
|
212
218
|
({
|
|
213
219
|
type: 'forbidden-prop',
|
|
@@ -217,18 +223,20 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
217
223
|
expectedProps: Object.keys(schemaNode.properties),
|
|
218
224
|
actualProps: keys,
|
|
219
225
|
ancestors: schemaAncestors,
|
|
220
|
-
}
|
|
226
|
+
}) as SchemaError,
|
|
221
227
|
),
|
|
222
228
|
);
|
|
223
229
|
}
|
|
224
230
|
if (schemaNode.required) {
|
|
225
|
-
//
|
|
231
|
+
// @ts-expect-error TS2769
|
|
226
232
|
let keys = Object.keys(dataNode);
|
|
227
233
|
let missingKeys = schemaNode.required.filter(
|
|
234
|
+
// @ts-expect-error TS7006
|
|
228
235
|
(val) => !keys.includes(val),
|
|
229
236
|
);
|
|
230
237
|
results.push(
|
|
231
238
|
...missingKeys.map(
|
|
239
|
+
// @ts-expect-error TS7006
|
|
232
240
|
(k) =>
|
|
233
241
|
({
|
|
234
242
|
type: 'missing-prop',
|
|
@@ -238,13 +246,13 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
238
246
|
expectedProps: schemaNode.required,
|
|
239
247
|
actualProps: keys,
|
|
240
248
|
ancestors: schemaAncestors,
|
|
241
|
-
}
|
|
249
|
+
}) as SchemaError,
|
|
242
250
|
),
|
|
243
251
|
);
|
|
244
252
|
}
|
|
245
253
|
if (schemaNode.properties) {
|
|
246
254
|
let {additionalProperties = true} = schemaNode;
|
|
247
|
-
//
|
|
255
|
+
// @ts-expect-error TS2407
|
|
248
256
|
for (let k in dataNode) {
|
|
249
257
|
if (invalidProps && invalidProps.includes(k)) {
|
|
250
258
|
// Don't check type on forbidden props
|
|
@@ -252,7 +260,7 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
252
260
|
} else if (k in schemaNode.properties) {
|
|
253
261
|
let result = walk(
|
|
254
262
|
[schemaNode.properties[k]].concat(schemaAncestors),
|
|
255
|
-
//
|
|
263
|
+
// @ts-expect-error TS18046
|
|
256
264
|
dataNode[k],
|
|
257
265
|
dataPath + '/' + encodeJSONKeyComponent(k),
|
|
258
266
|
);
|
|
@@ -266,10 +274,8 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
266
274
|
dataPath: dataPath + '/' + encodeJSONKeyComponent(k),
|
|
267
275
|
expectedValues: Object.keys(
|
|
268
276
|
schemaNode.properties,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
(p) => !(p in dataNode),
|
|
272
|
-
),
|
|
277
|
+
// @ts-expect-error TS18046
|
|
278
|
+
).filter((p) => !(p in dataNode)),
|
|
273
279
|
actualValue: k,
|
|
274
280
|
ancestors: schemaAncestors,
|
|
275
281
|
prettyType: schemaNode.__type,
|
|
@@ -278,7 +284,7 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
278
284
|
} else {
|
|
279
285
|
let result = walk(
|
|
280
286
|
[additionalProperties].concat(schemaAncestors),
|
|
281
|
-
//
|
|
287
|
+
// @ts-expect-error TS18046
|
|
282
288
|
dataNode[k],
|
|
283
289
|
dataPath + '/' + encodeJSONKeyComponent(k),
|
|
284
290
|
);
|
|
@@ -288,7 +294,7 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
288
294
|
}
|
|
289
295
|
}
|
|
290
296
|
if (results.length)
|
|
291
|
-
return results.reduce((acc, v) => acc.concat(v), []);
|
|
297
|
+
return results.reduce<Array<any>>((acc, v) => acc.concat(v), []);
|
|
292
298
|
break;
|
|
293
299
|
}
|
|
294
300
|
case 'boolean':
|
|
@@ -328,10 +334,10 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
328
334
|
? Array.isArray(a) && !Array.isArray(b)
|
|
329
335
|
? -1
|
|
330
336
|
: !Array.isArray(a) && Array.isArray(b)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
? 1
|
|
338
|
+
: Array.isArray(a) && Array.isArray(b)
|
|
339
|
+
? b.length - a.length
|
|
340
|
+
: 0
|
|
335
341
|
: b.dataPath.length - a.dataPath.length,
|
|
336
342
|
);
|
|
337
343
|
return results[0];
|
|
@@ -342,6 +348,7 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
|
|
|
342
348
|
dataNode,
|
|
343
349
|
dataPath,
|
|
344
350
|
);
|
|
351
|
+
// @ts-expect-error TS2339
|
|
345
352
|
if (!result || result.length == 0) {
|
|
346
353
|
return {
|
|
347
354
|
type: 'other',
|
|
@@ -371,33 +378,38 @@ export function fuzzySearch(
|
|
|
371
378
|
.map((exp) => [exp, levenshtein.distance(exp, actualValue)])
|
|
372
379
|
.filter(
|
|
373
380
|
// Remove if more than half of the string would need to be changed
|
|
374
|
-
|
|
381
|
+
// @ts-expect-error TS2769
|
|
382
|
+
([, d]: [any, any]) => d * 2 < actualValue.length,
|
|
375
383
|
);
|
|
376
|
-
|
|
377
|
-
|
|
384
|
+
// @ts-expect-error TS2345
|
|
385
|
+
result.sort(([, a]: [any, any], [, b]: [any, any]) => a - b);
|
|
386
|
+
// @ts-expect-error TS2345
|
|
387
|
+
return result.map(([v]: [any]) => v);
|
|
378
388
|
}
|
|
379
389
|
|
|
380
390
|
validateSchema.diagnostic = function (
|
|
381
391
|
schema: SchemaEntity,
|
|
382
|
-
data:
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
392
|
+
data: (
|
|
393
|
+
| {
|
|
394
|
+
source?: string | null | undefined;
|
|
395
|
+
data?: unknown;
|
|
396
|
+
}
|
|
397
|
+
| {
|
|
398
|
+
source: string;
|
|
399
|
+
map: {
|
|
400
|
+
data: unknown;
|
|
401
|
+
pointers: {
|
|
402
|
+
[key: string]: Mapping;
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
) & {
|
|
407
|
+
filePath?: string | null | undefined;
|
|
408
|
+
prependKey?: string | null | undefined;
|
|
409
|
+
},
|
|
398
410
|
origin: string,
|
|
399
411
|
message: string,
|
|
400
|
-
):
|
|
412
|
+
): undefined {
|
|
401
413
|
if (
|
|
402
414
|
'source' in data &&
|
|
403
415
|
'data' in data &&
|
|
@@ -408,10 +420,12 @@ validateSchema.diagnostic = function (
|
|
|
408
420
|
'At least one of data.source and data.data must be defined!',
|
|
409
421
|
);
|
|
410
422
|
}
|
|
423
|
+
// @ts-expect-error TS2339
|
|
411
424
|
let object = data.map
|
|
412
|
-
?
|
|
413
|
-
|
|
414
|
-
|
|
425
|
+
? // @ts-expect-error TS2339
|
|
426
|
+
data.map.data
|
|
427
|
+
: // @ts-expect-error TS2339
|
|
428
|
+
(data.data ?? JSON.parse(data.source));
|
|
415
429
|
let errors = validateSchema(schema, object);
|
|
416
430
|
if (errors.length) {
|
|
417
431
|
let keys = errors.map((e) => {
|
|
@@ -469,11 +483,13 @@ validateSchema.diagnostic = function (
|
|
|
469
483
|
return {key: e.dataPath, type: e.dataType, message};
|
|
470
484
|
});
|
|
471
485
|
let map, code;
|
|
486
|
+
// @ts-expect-error TS2339
|
|
472
487
|
if (data.map) {
|
|
488
|
+
// @ts-expect-error TS2339
|
|
473
489
|
map = data.map;
|
|
474
490
|
code = data.source;
|
|
475
491
|
} else {
|
|
476
|
-
//
|
|
492
|
+
// @ts-expect-error TS2339
|
|
477
493
|
map = data.source ?? JSON.stringify(nullthrows(data.data), 0, '\t');
|
|
478
494
|
code = map;
|
|
479
495
|
}
|
|
@@ -497,6 +513,7 @@ validateSchema.diagnostic = function (
|
|
|
497
513
|
diagnostic: {
|
|
498
514
|
message: message,
|
|
499
515
|
origin,
|
|
516
|
+
// @ts-expect-error TS2322
|
|
500
517
|
codeFrames,
|
|
501
518
|
},
|
|
502
519
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import {Flow} from 'flow-to-typescript-codemod';
|
|
2
2
|
|
|
3
|
-
export let SharedBuffer:
|
|
3
|
+
export let SharedBuffer:
|
|
4
|
+
| Flow.Class<ArrayBuffer>
|
|
5
|
+
| Flow.Class<SharedArrayBuffer>;
|
|
4
6
|
|
|
5
|
-
//
|
|
7
|
+
// @ts-expect-error process.browser is a browser-specific property
|
|
6
8
|
if (process.browser) {
|
|
7
9
|
SharedBuffer = ArrayBuffer;
|
|
8
10
|
// Safari has removed the constructor
|
|
@@ -12,7 +14,7 @@ if (process.browser) {
|
|
|
12
14
|
// Firefox might throw when sending the Buffer over a MessagePort
|
|
13
15
|
channel.port1.postMessage(new SharedArrayBuffer(0));
|
|
14
16
|
SharedBuffer = SharedArrayBuffer;
|
|
15
|
-
} catch (_) {
|
|
17
|
+
} catch (_: any) {
|
|
16
18
|
// NOOP
|
|
17
19
|
}
|
|
18
20
|
channel.port1.close();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {SourceLocation} from '@atlaspack/types';
|
|
3
2
|
import type {FileSystem} from '@atlaspack/fs';
|
|
4
3
|
import SourceMap from '@parcel/source-map';
|
|
@@ -21,7 +20,7 @@ export const SOURCEMAP_EXTENSIONS: Set<string> = new Set<string>([
|
|
|
21
20
|
|
|
22
21
|
export function matchSourceMappingURL(
|
|
23
22
|
contents: string,
|
|
24
|
-
):
|
|
23
|
+
): RegExpMatchArray | null {
|
|
25
24
|
return contents.match(SOURCEMAP_RE);
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -29,7 +28,15 @@ export async function loadSourceMapUrl(
|
|
|
29
28
|
fs: FileSystem,
|
|
30
29
|
filename: string,
|
|
31
30
|
contents: string,
|
|
32
|
-
): Promise
|
|
31
|
+
): Promise<
|
|
32
|
+
| {
|
|
33
|
+
filename: string;
|
|
34
|
+
map: any;
|
|
35
|
+
url: string;
|
|
36
|
+
}
|
|
37
|
+
| null
|
|
38
|
+
| undefined
|
|
39
|
+
> {
|
|
33
40
|
let match = matchSourceMappingURL(contents);
|
|
34
41
|
if (match) {
|
|
35
42
|
let url = match[1].trim();
|
|
@@ -60,8 +67,11 @@ export async function loadSourceMapUrl(
|
|
|
60
67
|
export async function loadSourceMap(
|
|
61
68
|
filename: string,
|
|
62
69
|
contents: string,
|
|
63
|
-
options: {
|
|
64
|
-
|
|
70
|
+
options: {
|
|
71
|
+
fs: FileSystem;
|
|
72
|
+
projectRoot: string;
|
|
73
|
+
},
|
|
74
|
+
): Promise<SourceMap | null | undefined> {
|
|
65
75
|
let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
|
|
66
76
|
if (foundMap) {
|
|
67
77
|
let mapSourceRoot = path.dirname(filename);
|
|
@@ -75,7 +85,7 @@ export async function loadSourceMap(
|
|
|
75
85
|
let sourcemapInstance = new SourceMap(options.projectRoot);
|
|
76
86
|
sourcemapInstance.addVLQMap({
|
|
77
87
|
...foundMap.map,
|
|
78
|
-
sources: foundMap.map.sources.map((s) => {
|
|
88
|
+
sources: foundMap.map.sources.map((s: string) => {
|
|
79
89
|
return path.join(mapSourceRoot, s);
|
|
80
90
|
}),
|
|
81
91
|
});
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {Readable, PassThrough} from 'stream';
|
|
4
2
|
import type {Blob} from '@atlaspack/types';
|
|
5
3
|
|
|
6
4
|
export function measureStreamLength(stream: Readable): Promise<number> {
|
|
7
|
-
return new Promise(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
return new Promise(
|
|
6
|
+
(
|
|
7
|
+
resolve: (result: Promise<number> | number) => void,
|
|
8
|
+
reject: (error?: any) => void,
|
|
9
|
+
) => {
|
|
10
|
+
let length = 0;
|
|
11
|
+
stream.on('data', (chunk) => {
|
|
12
|
+
length += chunk;
|
|
13
|
+
});
|
|
14
|
+
stream.on('end', () => resolve(length));
|
|
15
|
+
stream.on('error', reject);
|
|
16
|
+
},
|
|
17
|
+
);
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export function readableFromStringOrBuffer(str: string | Buffer): Readable {
|
|
@@ -23,16 +26,21 @@ export function readableFromStringOrBuffer(str: string | Buffer): Readable {
|
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export function bufferStream(stream: Readable): Promise<Buffer> {
|
|
26
|
-
return new Promise(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
return new Promise(
|
|
30
|
+
(
|
|
31
|
+
resolve: (result: Promise<Buffer> | Buffer) => void,
|
|
32
|
+
reject: (error?: any) => void,
|
|
33
|
+
) => {
|
|
34
|
+
let buf = Buffer.from([]);
|
|
35
|
+
stream.on('data', (data) => {
|
|
36
|
+
buf = Buffer.concat([buf, data]);
|
|
37
|
+
});
|
|
38
|
+
stream.on('end', () => {
|
|
39
|
+
resolve(buf);
|
|
40
|
+
});
|
|
41
|
+
stream.on('error', reject);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
export function blobToStream(blob: Blob): Readable {
|
|
@@ -62,7 +70,7 @@ export function fallbackStream(
|
|
|
62
70
|
): Readable {
|
|
63
71
|
const res = new PassThrough();
|
|
64
72
|
stream.on('error', (err) => {
|
|
65
|
-
if (err.code === 'ENOENT') {
|
|
73
|
+
if ((err as any).code === 'ENOENT') {
|
|
66
74
|
fallback().pipe(res);
|
|
67
75
|
} else {
|
|
68
76
|
res.emit('error', err);
|
package/src/throttle.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function throttle<TArgs extends Array<unknown>>(
|
|
2
|
+
fn: (...args: TArgs) => unknown,
|
|
3
|
+
delay: number,
|
|
4
|
+
): (...args: TArgs) => void {
|
|
5
|
+
let lastCalled: number | null | undefined;
|
|
6
|
+
|
|
7
|
+
return function throttled(this: any, ...args: TArgs) {
|
|
8
|
+
if (lastCalled == null || lastCalled + delay <= Date.now()) {
|
|
9
|
+
fn.call(this, ...args);
|
|
10
|
+
lastCalled = Date.now();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import URL from 'url';
|
|
4
2
|
import path from 'path';
|
|
5
3
|
|
|
@@ -12,7 +10,7 @@ export default function urlJoin(publicURL: string, assetPath: string): string {
|
|
|
12
10
|
// Leading / ensures that paths with colons are not parsed as a protocol.
|
|
13
11
|
let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
|
|
14
12
|
const assetUrl = URL.parse(p);
|
|
15
|
-
url.pathname = path.posix.join(url.pathname, assetUrl.pathname);
|
|
13
|
+
url.pathname = path.posix.join(url.pathname ?? '', assetUrl.pathname ?? '');
|
|
16
14
|
url.search = assetUrl.search;
|
|
17
15
|
url.hash = assetUrl.hash;
|
|
18
16
|
return URL.format(url);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import {DefaultMap} from '../src/DefaultMap';
|
|
5
3
|
|
|
6
4
|
describe('DefaultMap', () => {
|
|
7
5
|
it('constructs with entries just like Map', () => {
|
|
8
6
|
let map = new DefaultMap(
|
|
9
|
-
(k) => k,
|
|
7
|
+
(k: any) => k,
|
|
10
8
|
[
|
|
11
9
|
[1, 3],
|
|
12
10
|
[2, 27],
|
|
@@ -20,18 +18,18 @@ describe('DefaultMap', () => {
|
|
|
20
18
|
});
|
|
21
19
|
|
|
22
20
|
it("returns a default value based on a key if it doesn't exist", () => {
|
|
23
|
-
let map = new DefaultMap((k) => k);
|
|
21
|
+
let map = new DefaultMap((k: any) => k);
|
|
24
22
|
assert.equal(map.get(3), 3);
|
|
25
23
|
});
|
|
26
24
|
|
|
27
25
|
it("sets a default value based on a key if it doesn't exist", () => {
|
|
28
|
-
let map = new DefaultMap((k) => k);
|
|
26
|
+
let map = new DefaultMap((k: any) => k);
|
|
29
27
|
map.get(3);
|
|
30
28
|
assert.deepEqual(Array.from(map.entries()), [[3, 3]]);
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
it('respects undefined/null if it already existed in the map', () => {
|
|
34
|
-
let map = new DefaultMap<number, number |
|
|
32
|
+
let map = new DefaultMap<number, number | undefined | null>((k: any) => k);
|
|
35
33
|
map.set(3, undefined);
|
|
36
34
|
assert.equal(map.get(3), undefined);
|
|
37
35
|
|