@atlaspack/utils 2.14.5-canary.26 → 2.14.5-canary.261
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/CHANGELOG.md +324 -0
- package/benchmark.js +23 -0
- package/dist/DefaultMap.js +41 -0
- package/dist/Deferred.js +16 -0
- package/dist/PromiseQueue.js +107 -0
- package/dist/TapStream.js +23 -0
- package/dist/alternatives.js +97 -0
- package/dist/ansi-html.js +12 -0
- package/dist/blob.js +29 -0
- package/dist/bundle-url.js +32 -0
- package/dist/collection.js +106 -0
- package/dist/config.js +138 -0
- package/dist/countLines.js +12 -0
- package/dist/debounce.js +15 -0
- package/dist/debug-tools.js +39 -0
- package/dist/dependency-location.js +22 -0
- package/dist/escape-html.js +19 -0
- package/dist/generateBuildMetrics.js +111 -0
- package/dist/generateCertificate.js +124 -0
- package/dist/getCertificate.js +13 -0
- package/dist/getExisting.js +20 -0
- package/dist/getModuleParts.js +27 -0
- package/dist/getRootDir.js +46 -0
- package/dist/glob.js +129 -0
- package/dist/hash.js +45 -0
- package/dist/http-server.js +55 -0
- package/dist/index.js +146 -0
- package/dist/is-url.js +15 -0
- package/dist/isDirectoryInside.js +11 -0
- package/dist/objectHash.js +20 -0
- package/dist/openInBrowser.js +61 -0
- package/dist/parseCSSImport.js +14 -0
- package/dist/path.js +36 -0
- package/dist/prettifyTime.js +6 -0
- package/dist/prettyDiagnostic.js +104 -0
- package/dist/progress-message.js +31 -0
- package/dist/relativeBundlePath.js +13 -0
- package/dist/relativeUrl.js +11 -0
- package/dist/replaceBundleReferences.js +131 -0
- package/dist/schema.js +403 -0
- package/dist/shared-buffer.js +24 -0
- package/dist/sourcemap.js +121 -0
- package/dist/stream.js +69 -0
- package/dist/throttle.js +12 -0
- package/dist/urlJoin.js +22 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.js +111 -0
- package/lib/config.js +174 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.js +40 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.js +52 -0
- package/lib/glob.js +110 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.js +85 -0
- package/lib/index.js +635 -37310
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.js +150 -0
- package/lib/progress-message.js +39 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.js +182 -0
- package/lib/schema.js +369 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.js +138 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.js +15 -0
- package/lib/types/DefaultMap.d.ts +13 -0
- package/lib/types/Deferred.d.ts +8 -0
- package/lib/types/PromiseQueue.d.ts +25 -0
- package/lib/types/TapStream.d.ts +6 -0
- package/lib/types/alternatives.d.ts +3 -0
- package/lib/types/ansi-html.d.ts +1 -0
- package/lib/types/blob.d.ts +4 -0
- package/lib/types/bundle-url.d.ts +4 -0
- package/lib/types/collection.d.ts +33 -0
- package/lib/types/config.d.ts +17 -0
- package/lib/types/countLines.d.ts +1 -0
- package/lib/types/debounce.d.ts +1 -0
- package/lib/types/debug-tools.d.ts +8 -0
- package/lib/types/dependency-location.d.ts +14 -0
- package/lib/types/escape-html.d.ts +1 -0
- package/lib/types/generateBuildMetrics.d.ts +18 -0
- package/lib/types/generateCertificate.d.ts +5 -0
- package/lib/types/getCertificate.d.ts +5 -0
- package/lib/types/getExisting.d.ts +8 -0
- package/lib/types/getModuleParts.d.ts +4 -0
- package/lib/types/getRootDir.d.ts +2 -0
- package/lib/types/glob.d.ts +9 -0
- package/lib/types/hash.d.ts +7 -0
- package/lib/types/http-server.d.ts +19 -0
- package/lib/types/index.d.ts +48 -0
- package/lib/types/is-url.d.ts +1 -0
- package/lib/types/isDirectoryInside.d.ts +2 -0
- package/lib/types/objectHash.d.ts +3 -0
- package/lib/types/openInBrowser.d.ts +1 -0
- package/lib/types/parseCSSImport.d.ts +1 -0
- package/lib/types/path.d.ts +8 -0
- package/lib/types/prettifyTime.d.ts +1 -0
- package/lib/types/prettyDiagnostic.d.ts +17 -0
- package/lib/types/progress-message.d.ts +3 -0
- package/lib/types/relativeBundlePath.d.ts +4 -0
- package/lib/types/relativeUrl.d.ts +1 -0
- package/lib/types/replaceBundleReferences.d.ts +39 -0
- package/lib/types/schema.d.ts +107 -0
- package/lib/types/shared-buffer.d.ts +2 -0
- package/lib/types/sourcemap.d.ts +15 -0
- package/lib/types/stream.d.ts +8 -0
- package/lib/types/throttle.d.ts +1 -0
- package/lib/types/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +26 -17
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +15 -16
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +3 -5
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +23 -20
- package/src/{config.js → config.ts} +20 -21
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/debug-tools.ts +48 -0
- 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} +18 -20
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
- package/src/{getCertificate.js → getCertificate.ts} +6 -5
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +1 -3
- package/src/{glob.js → glob.ts} +13 -14
- package/src/{hash.js → hash.ts} +23 -18
- package/src/{http-server.js → http-server.ts} +34 -40
- package/src/{index.js → index.ts} +13 -9
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
- 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} +2 -4
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +34 -22
- package/src/progress-message.ts +43 -0
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +66 -50
- package/src/{schema.js → schema.ts} +179 -150
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +27 -9
- package/src/{stream.js → stream.ts} +30 -22
- 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/schema.test.ts +748 -0
- 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 +33 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/index.js.map +0 -1
- package/src/Deferred.js +0 -23
- package/src/progress-message.js +0 -22
- 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,47 +378,64 @@ 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) | string | null | undefined;
|
|
395
|
+
data?: unknown;
|
|
396
|
+
}
|
|
397
|
+
| {
|
|
398
|
+
source: string | (() => 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
|
-
):
|
|
401
|
-
if (
|
|
402
|
-
'source' in data &&
|
|
403
|
-
'data' in data &&
|
|
404
|
-
typeof data.source !== 'string' &&
|
|
405
|
-
!data
|
|
406
|
-
) {
|
|
412
|
+
): undefined {
|
|
413
|
+
if (!('map' in data) && !('source' in data || 'data' in data)) {
|
|
407
414
|
throw new Error(
|
|
408
|
-
'At least one of data.source
|
|
415
|
+
'At least one of data.source, data.data, or data.map must be defined!',
|
|
409
416
|
);
|
|
410
417
|
}
|
|
418
|
+
let loadedSource: string | null | undefined;
|
|
419
|
+
function loadSource(
|
|
420
|
+
loader: string | (() => string) | null | undefined,
|
|
421
|
+
): string | null | undefined {
|
|
422
|
+
if (loadedSource !== undefined) {
|
|
423
|
+
return loadedSource;
|
|
424
|
+
} else if (typeof loader === 'function') {
|
|
425
|
+
loadedSource = loader();
|
|
426
|
+
return loadedSource;
|
|
427
|
+
} else if (typeof loader === 'string') {
|
|
428
|
+
loadedSource = loader;
|
|
429
|
+
return loadedSource;
|
|
430
|
+
}
|
|
431
|
+
return loadedSource;
|
|
432
|
+
}
|
|
433
|
+
// @ts-expect-error TS2339
|
|
411
434
|
let object = data.map
|
|
412
|
-
?
|
|
413
|
-
|
|
414
|
-
|
|
435
|
+
? // @ts-expect-error TS2339
|
|
436
|
+
data.map.data
|
|
437
|
+
: // @ts-expect-error TS2339
|
|
438
|
+
(data.data ?? JSON.parse(loadSource(data.source)));
|
|
415
439
|
let errors = validateSchema(schema, object);
|
|
416
440
|
if (errors.length) {
|
|
417
441
|
let keys = errors.map((e) => {
|
|
@@ -469,12 +493,16 @@ validateSchema.diagnostic = function (
|
|
|
469
493
|
return {key: e.dataPath, type: e.dataType, message};
|
|
470
494
|
});
|
|
471
495
|
let map, code;
|
|
496
|
+
// @ts-expect-error TS2339
|
|
472
497
|
if (data.map) {
|
|
498
|
+
// @ts-expect-error TS2339
|
|
473
499
|
map = data.map;
|
|
474
|
-
code = data.source;
|
|
500
|
+
code = loadSource(data.source);
|
|
475
501
|
} else {
|
|
476
|
-
|
|
477
|
-
|
|
502
|
+
map =
|
|
503
|
+
loadSource(data.source) ??
|
|
504
|
+
// @ts-expect-error TS2339
|
|
505
|
+
JSON.stringify(nullthrows(data.data), 0, '\t');
|
|
478
506
|
code = map;
|
|
479
507
|
}
|
|
480
508
|
let codeFrames = [
|
|
@@ -497,6 +525,7 @@ validateSchema.diagnostic = function (
|
|
|
497
525
|
diagnostic: {
|
|
498
526
|
message: message,
|
|
499
527
|
origin,
|
|
528
|
+
// @ts-expect-error TS2322
|
|
500
529
|
codeFrames,
|
|
501
530
|
},
|
|
502
531
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
//
|
|
1
|
+
// flow-to-ts helpers
|
|
2
|
+
export type Class<T> = new (...args: any[]) => T;
|
|
3
|
+
// /flow-to-ts helpers
|
|
2
4
|
|
|
3
5
|
export let SharedBuffer: Class<ArrayBuffer> | 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,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import type {FileSystem} from '@atlaspack/fs';
|
|
1
|
+
import type {SourceLocation, FileSystem} from '@atlaspack/types-internal';
|
|
2
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
4
3
|
import SourceMap from '@parcel/source-map';
|
|
5
4
|
import path from 'path';
|
|
6
5
|
import {normalizeSeparators, isAbsolute} from './path';
|
|
@@ -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
|
});
|
|
@@ -86,6 +96,7 @@ export async function loadSourceMap(
|
|
|
86
96
|
export function remapSourceLocation(
|
|
87
97
|
loc: SourceLocation,
|
|
88
98
|
originalMap: SourceMap,
|
|
99
|
+
projectRoot: string,
|
|
89
100
|
): SourceLocation {
|
|
90
101
|
let {
|
|
91
102
|
filePath,
|
|
@@ -99,7 +110,14 @@ export function remapSourceLocation(
|
|
|
99
110
|
|
|
100
111
|
if (start?.original) {
|
|
101
112
|
if (start.source) {
|
|
102
|
-
|
|
113
|
+
if (
|
|
114
|
+
getFeatureFlag('symbolLocationFix') &&
|
|
115
|
+
!path.isAbsolute(start.source)
|
|
116
|
+
) {
|
|
117
|
+
filePath = path.join(projectRoot, start.source);
|
|
118
|
+
} else {
|
|
119
|
+
filePath = start.source;
|
|
120
|
+
}
|
|
103
121
|
}
|
|
104
122
|
|
|
105
123
|
({line: startLine, column: startCol} = start.original);
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {Readable, PassThrough} from 'stream';
|
|
4
|
-
import type {Blob} from '@atlaspack/types';
|
|
2
|
+
import type {Blob} from '@atlaspack/types-internal';
|
|
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
|
+
}
|