@atlaspack/utils 2.17.3-typescript-bc4459c37.0 → 2.17.3

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