@react-native/compatibility-check 0.0.0 → 0.0.1
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/README.md +245 -1
- package/dist/ComparisonResult.d.ts +135 -0
- package/dist/ComparisonResult.js +88 -0
- package/dist/ComparisonResult.js.flow +188 -0
- package/dist/DiffResults.d.ts +137 -0
- package/dist/DiffResults.js +52 -0
- package/dist/DiffResults.js.flow +160 -0
- package/dist/ErrorFormatting.d.ts +31 -0
- package/dist/ErrorFormatting.js +272 -0
- package/dist/ErrorFormatting.js.flow +34 -0
- package/dist/SortTypeAnnotations.d.ts +18 -0
- package/dist/SortTypeAnnotations.js +300 -0
- package/dist/SortTypeAnnotations.js.flow +20 -0
- package/dist/TypeDiffing.d.ts +86 -0
- package/dist/TypeDiffing.js +1253 -0
- package/dist/TypeDiffing.js.flow +99 -0
- package/dist/VersionDiffing.d.ts +59 -0
- package/dist/VersionDiffing.js +1235 -0
- package/dist/VersionDiffing.js.flow +71 -0
- package/dist/convertPropToBasicTypes.d.ts +20 -0
- package/dist/convertPropToBasicTypes.js +86 -0
- package/dist/convertPropToBasicTypes.js.flow +20 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/index.js.flow +12 -0
- package/package.json +31 -3
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.compareTypeAnnotationForSorting = compareTypeAnnotationForSorting;
|
|
7
|
+
exports.sortTypeAnnotations = sortTypeAnnotations;
|
|
8
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
9
|
+
function _interopRequireDefault(e) {
|
|
10
|
+
return e && e.__esModule ? e : { default: e };
|
|
11
|
+
}
|
|
12
|
+
function sortTypeAnnotations(annotations) {
|
|
13
|
+
const sortableArray = annotations.map((a, i) => [i, a]);
|
|
14
|
+
return sortableArray.sort(compareTypeAnnotationForSorting);
|
|
15
|
+
}
|
|
16
|
+
const EQUALITY_MSG = "typeA and typeB differ despite check";
|
|
17
|
+
function compareTypeAnnotationForSorting(
|
|
18
|
+
[originalPositionA, typeA],
|
|
19
|
+
[originalPositionB, typeB]
|
|
20
|
+
) {
|
|
21
|
+
if (typeA.type !== typeB.type) {
|
|
22
|
+
if (typeA.type === "NullableTypeAnnotation") {
|
|
23
|
+
return compareTypeAnnotationForSorting(
|
|
24
|
+
[originalPositionA, typeA.typeAnnotation],
|
|
25
|
+
[originalPositionB, typeB]
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (typeB.type === "NullableTypeAnnotation") {
|
|
29
|
+
return compareTypeAnnotationForSorting(
|
|
30
|
+
[originalPositionA, typeA],
|
|
31
|
+
[originalPositionB, typeB.typeAnnotation]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return (
|
|
35
|
+
typeAnnotationArbitraryOrder(typeA) - typeAnnotationArbitraryOrder(typeB)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
switch (typeA.type) {
|
|
39
|
+
case "AnyTypeAnnotation":
|
|
40
|
+
return 0;
|
|
41
|
+
case "ArrayTypeAnnotation":
|
|
42
|
+
(0, _invariant.default)(
|
|
43
|
+
typeB.type === "ArrayTypeAnnotation",
|
|
44
|
+
EQUALITY_MSG
|
|
45
|
+
);
|
|
46
|
+
return compareTypeAnnotationForSorting(
|
|
47
|
+
[originalPositionA, typeA.elementType],
|
|
48
|
+
[originalPositionB, typeB.elementType]
|
|
49
|
+
);
|
|
50
|
+
case "BooleanTypeAnnotation":
|
|
51
|
+
return originalPositionA - originalPositionB;
|
|
52
|
+
case "EnumDeclaration":
|
|
53
|
+
(0, _invariant.default)(typeB.type === "EnumDeclaration", EQUALITY_MSG);
|
|
54
|
+
return typeA.memberType.localeCompare(typeB.memberType);
|
|
55
|
+
case "EnumDeclarationWithMembers":
|
|
56
|
+
(0, _invariant.default)(
|
|
57
|
+
typeB.type === "EnumDeclarationWithMembers",
|
|
58
|
+
EQUALITY_MSG
|
|
59
|
+
);
|
|
60
|
+
return compareNameAnnotationArraysForSorting(
|
|
61
|
+
[originalPositionA, typeA.members.map((m) => [m.name, m.value])],
|
|
62
|
+
[originalPositionB, typeB.members.map((m) => [m.name, m.value])]
|
|
63
|
+
);
|
|
64
|
+
case "FunctionTypeAnnotation":
|
|
65
|
+
(0, _invariant.default)(
|
|
66
|
+
typeB.type === "FunctionTypeAnnotation",
|
|
67
|
+
EQUALITY_MSG
|
|
68
|
+
);
|
|
69
|
+
const parmComparison = compareAnnotationArraysForSorting(
|
|
70
|
+
[originalPositionA, typeA.params.map((p) => p.typeAnnotation)],
|
|
71
|
+
[originalPositionB, typeB.params.map((p) => p.typeAnnotation)]
|
|
72
|
+
);
|
|
73
|
+
if (parmComparison === 0) {
|
|
74
|
+
return compareTypeAnnotationForSorting(
|
|
75
|
+
[originalPositionA, typeA.returnTypeAnnotation],
|
|
76
|
+
[originalPositionB, typeB.returnTypeAnnotation]
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return parmComparison;
|
|
80
|
+
case "EventEmitterTypeAnnotation":
|
|
81
|
+
(0, _invariant.default)(
|
|
82
|
+
typeB.type === "EventEmitterTypeAnnotation",
|
|
83
|
+
EQUALITY_MSG
|
|
84
|
+
);
|
|
85
|
+
return compareTypeAnnotationForSorting(
|
|
86
|
+
[originalPositionA, typeA.typeAnnotation],
|
|
87
|
+
[originalPositionB, typeB.typeAnnotation]
|
|
88
|
+
);
|
|
89
|
+
case "GenericObjectTypeAnnotation":
|
|
90
|
+
(0, _invariant.default)(
|
|
91
|
+
typeB.type === "GenericObjectTypeAnnotation",
|
|
92
|
+
EQUALITY_MSG
|
|
93
|
+
);
|
|
94
|
+
if (
|
|
95
|
+
typeA.dictionaryValueType == null &&
|
|
96
|
+
typeB.dictionaryValueType == null
|
|
97
|
+
) {
|
|
98
|
+
return 0;
|
|
99
|
+
} else if (
|
|
100
|
+
typeA.dictionaryValueType != null &&
|
|
101
|
+
typeB.dictionaryValueType != null
|
|
102
|
+
) {
|
|
103
|
+
return compareTypeAnnotationForSorting(
|
|
104
|
+
[originalPositionA, typeA.dictionaryValueType],
|
|
105
|
+
[originalPositionB, typeB.dictionaryValueType]
|
|
106
|
+
);
|
|
107
|
+
} else {
|
|
108
|
+
return typeA.dictionaryValueType == null ? -1 : 1;
|
|
109
|
+
}
|
|
110
|
+
case "NullableTypeAnnotation":
|
|
111
|
+
(0, _invariant.default)(
|
|
112
|
+
typeB.type === "NullableTypeAnnotation",
|
|
113
|
+
EQUALITY_MSG
|
|
114
|
+
);
|
|
115
|
+
return compareTypeAnnotationForSorting(
|
|
116
|
+
[originalPositionA, typeA.typeAnnotation],
|
|
117
|
+
[originalPositionB, typeB.typeAnnotation]
|
|
118
|
+
);
|
|
119
|
+
case "NumberTypeAnnotation":
|
|
120
|
+
case "Int32TypeAnnotation":
|
|
121
|
+
case "FloatTypeAnnotation":
|
|
122
|
+
case "DoubleTypeAnnotation":
|
|
123
|
+
return 0;
|
|
124
|
+
case "NumberLiteralTypeAnnotation":
|
|
125
|
+
(0, _invariant.default)(
|
|
126
|
+
typeB.type === "NumberLiteralTypeAnnotation",
|
|
127
|
+
EQUALITY_MSG
|
|
128
|
+
);
|
|
129
|
+
return typeA.value - typeB.value;
|
|
130
|
+
case "ObjectTypeAnnotation":
|
|
131
|
+
(0, _invariant.default)(
|
|
132
|
+
typeB.type === "ObjectTypeAnnotation",
|
|
133
|
+
EQUALITY_MSG
|
|
134
|
+
);
|
|
135
|
+
return compareNameAnnotationArraysForSorting(
|
|
136
|
+
[
|
|
137
|
+
originalPositionA,
|
|
138
|
+
typeA.properties.map((p) => [p.name, p.typeAnnotation]),
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
originalPositionB,
|
|
142
|
+
typeB.properties.map((p) => [p.name, p.typeAnnotation]),
|
|
143
|
+
]
|
|
144
|
+
);
|
|
145
|
+
case "StringTypeAnnotation":
|
|
146
|
+
return originalPositionA - originalPositionB;
|
|
147
|
+
case "StringLiteralTypeAnnotation":
|
|
148
|
+
(0, _invariant.default)(
|
|
149
|
+
typeB.type === "StringLiteralTypeAnnotation",
|
|
150
|
+
EQUALITY_MSG
|
|
151
|
+
);
|
|
152
|
+
return typeA.value.localeCompare(typeB.value);
|
|
153
|
+
case "StringLiteralUnionTypeAnnotation":
|
|
154
|
+
(0, _invariant.default)(
|
|
155
|
+
typeB.type === "StringLiteralUnionTypeAnnotation",
|
|
156
|
+
EQUALITY_MSG
|
|
157
|
+
);
|
|
158
|
+
return compareAnnotationArraysForSorting(
|
|
159
|
+
[originalPositionA, typeA.types],
|
|
160
|
+
[originalPositionB, typeB.types]
|
|
161
|
+
);
|
|
162
|
+
case "UnionTypeAnnotation":
|
|
163
|
+
(0, _invariant.default)(
|
|
164
|
+
typeB.type === "UnionTypeAnnotation",
|
|
165
|
+
EQUALITY_MSG
|
|
166
|
+
);
|
|
167
|
+
return 0;
|
|
168
|
+
case "VoidTypeAnnotation":
|
|
169
|
+
return 0;
|
|
170
|
+
case "ReservedTypeAnnotation":
|
|
171
|
+
return 0;
|
|
172
|
+
case "PromiseTypeAnnotation":
|
|
173
|
+
(0, _invariant.default)(
|
|
174
|
+
typeB.type === "PromiseTypeAnnotation",
|
|
175
|
+
EQUALITY_MSG
|
|
176
|
+
);
|
|
177
|
+
return compareTypeAnnotationForSorting(
|
|
178
|
+
[originalPositionA, typeA.elementType],
|
|
179
|
+
[originalPositionB, typeB.elementType]
|
|
180
|
+
);
|
|
181
|
+
case "TypeAliasTypeAnnotation":
|
|
182
|
+
return 0;
|
|
183
|
+
case "MixedTypeAnnotation":
|
|
184
|
+
return 0;
|
|
185
|
+
default:
|
|
186
|
+
typeA.type;
|
|
187
|
+
return -1;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function nameComparison([nameA], [nameB]) {
|
|
191
|
+
if (nameA === nameB) {
|
|
192
|
+
return 0;
|
|
193
|
+
} else if (nameA < nameB) {
|
|
194
|
+
return -1;
|
|
195
|
+
}
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
function compareNameAnnotationArraysForSorting(
|
|
199
|
+
[originalPositionA, arrayA],
|
|
200
|
+
[originalPositionB, arrayB]
|
|
201
|
+
) {
|
|
202
|
+
if (arrayA.length - arrayB.length !== 0) {
|
|
203
|
+
return arrayA.length - arrayB.length;
|
|
204
|
+
}
|
|
205
|
+
const nameSortedA = arrayA.sort(nameComparison);
|
|
206
|
+
const nameSortedB = arrayB.sort(nameComparison);
|
|
207
|
+
for (let i = 0; i < nameSortedA.length; i++) {
|
|
208
|
+
if (nameSortedA[i][0] === nameSortedB[i][0]) {
|
|
209
|
+
const compared = compareTypeAnnotationForSorting(
|
|
210
|
+
[originalPositionA, nameSortedA[i][1]],
|
|
211
|
+
[originalPositionB, nameSortedB[i][1]]
|
|
212
|
+
);
|
|
213
|
+
if (compared !== 0) {
|
|
214
|
+
return compared;
|
|
215
|
+
}
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (nameSortedA[i][0] < nameSortedB[i][0]) {
|
|
219
|
+
return -1;
|
|
220
|
+
}
|
|
221
|
+
return 1;
|
|
222
|
+
}
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
function compareAnnotationArraysForSorting(
|
|
226
|
+
[originalPositionA, arrayA],
|
|
227
|
+
[originalPositionB, arrayB]
|
|
228
|
+
) {
|
|
229
|
+
if (arrayA.length - arrayB.length !== 0) {
|
|
230
|
+
return arrayA.length - arrayB.length;
|
|
231
|
+
}
|
|
232
|
+
for (let i = 0; i < arrayA.length; i++) {
|
|
233
|
+
const compared = compareTypeAnnotationForSorting(
|
|
234
|
+
[originalPositionA, arrayA[i]],
|
|
235
|
+
[originalPositionB, arrayB[i]]
|
|
236
|
+
);
|
|
237
|
+
if (compared !== 0) {
|
|
238
|
+
return compared;
|
|
239
|
+
}
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
function typeAnnotationArbitraryOrder(annotation) {
|
|
245
|
+
switch (annotation.type) {
|
|
246
|
+
case "AnyTypeAnnotation":
|
|
247
|
+
return 0;
|
|
248
|
+
case "ArrayTypeAnnotation":
|
|
249
|
+
return 1;
|
|
250
|
+
case "BooleanTypeAnnotation":
|
|
251
|
+
return 2;
|
|
252
|
+
case "FunctionTypeAnnotation":
|
|
253
|
+
return 3;
|
|
254
|
+
case "EventEmitterTypeAnnotation":
|
|
255
|
+
return 4;
|
|
256
|
+
case "PromiseTypeAnnotation":
|
|
257
|
+
return 5;
|
|
258
|
+
case "GenericObjectTypeAnnotation":
|
|
259
|
+
return 6;
|
|
260
|
+
case "NullableTypeAnnotation":
|
|
261
|
+
return 9;
|
|
262
|
+
case "NumberTypeAnnotation":
|
|
263
|
+
return 10;
|
|
264
|
+
case "Int32TypeAnnotation":
|
|
265
|
+
return 11;
|
|
266
|
+
case "DoubleTypeAnnotation":
|
|
267
|
+
return 12;
|
|
268
|
+
case "FloatTypeAnnotation":
|
|
269
|
+
return 13;
|
|
270
|
+
case "NumberLiteralTypeAnnotation":
|
|
271
|
+
return 14;
|
|
272
|
+
case "ObjectTypeAnnotation":
|
|
273
|
+
return 15;
|
|
274
|
+
case "StringLiteralUnionTypeAnnotation":
|
|
275
|
+
return 17;
|
|
276
|
+
case "StringTypeAnnotation":
|
|
277
|
+
return 18;
|
|
278
|
+
case "StringLiteralTypeAnnotation":
|
|
279
|
+
return 19;
|
|
280
|
+
case "VoidTypeAnnotation":
|
|
281
|
+
return 20;
|
|
282
|
+
case "EnumDeclaration":
|
|
283
|
+
return 21;
|
|
284
|
+
case "EnumDeclarationWithMembers":
|
|
285
|
+
return 22;
|
|
286
|
+
case "GenericObjectTypeAnnotation":
|
|
287
|
+
return 25;
|
|
288
|
+
case "TypeAliasTypeAnnotation":
|
|
289
|
+
return 26;
|
|
290
|
+
case "MixedTypeAnnotation":
|
|
291
|
+
return 27;
|
|
292
|
+
case "ReservedTypeAnnotation":
|
|
293
|
+
return 28;
|
|
294
|
+
case "UnionTypeAnnotation":
|
|
295
|
+
return 30;
|
|
296
|
+
default:
|
|
297
|
+
annotation.type;
|
|
298
|
+
return -1;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { CompleteTypeAnnotation } from "@react-native/codegen/src/CodegenSchema";
|
|
12
|
+
|
|
13
|
+
declare export function sortTypeAnnotations(
|
|
14
|
+
annotations: $ReadOnlyArray<CompleteTypeAnnotation>
|
|
15
|
+
): Array<[number, CompleteTypeAnnotation]>;
|
|
16
|
+
|
|
17
|
+
declare export function compareTypeAnnotationForSorting(
|
|
18
|
+
[number, CompleteTypeAnnotation],
|
|
19
|
+
[number, CompleteTypeAnnotation]
|
|
20
|
+
): number;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
ComparisonResult,
|
|
13
|
+
MembersComparisonResult,
|
|
14
|
+
} from "./ComparisonResult";
|
|
15
|
+
import type {
|
|
16
|
+
CompleteTypeAnnotation,
|
|
17
|
+
NamedShape,
|
|
18
|
+
NativeModuleAliasMap,
|
|
19
|
+
NativeModuleEnumDeclaration,
|
|
20
|
+
NativeModuleEnumDeclarationWithMembers,
|
|
21
|
+
NativeModuleEnumMap,
|
|
22
|
+
NativeModuleEnumMember,
|
|
23
|
+
NativeModuleFunctionTypeAnnotation,
|
|
24
|
+
NativeModuleGenericObjectTypeAnnotation,
|
|
25
|
+
NativeModulePromiseTypeAnnotation,
|
|
26
|
+
NativeModuleUnionTypeAnnotation,
|
|
27
|
+
NumberLiteralTypeAnnotation,
|
|
28
|
+
StringLiteralTypeAnnotation,
|
|
29
|
+
StringLiteralUnionTypeAnnotation,
|
|
30
|
+
} from "@react-native/codegen/src/CodegenSchema";
|
|
31
|
+
export declare function compareTypes(
|
|
32
|
+
newerType: CompleteTypeAnnotation,
|
|
33
|
+
olderType: null | undefined | CompleteTypeAnnotation,
|
|
34
|
+
newerTypesReg: null | undefined | NativeModuleAliasMap,
|
|
35
|
+
olderTypesReg: null | undefined | NativeModuleAliasMap,
|
|
36
|
+
newerEnumMap: null | undefined | NativeModuleEnumMap,
|
|
37
|
+
olderEnumMap: null | undefined | NativeModuleEnumMap
|
|
38
|
+
): ComparisonResult;
|
|
39
|
+
export declare function compareTypeAnnotation(
|
|
40
|
+
originalNewerAnnotation: CompleteTypeAnnotation,
|
|
41
|
+
originalOlderAnnotation: CompleteTypeAnnotation
|
|
42
|
+
): ComparisonResult;
|
|
43
|
+
export declare function compareObjectTypes<T extends CompleteTypeAnnotation>(
|
|
44
|
+
newerPropertyTypes: ReadonlyArray<NamedShape<T>>,
|
|
45
|
+
olderPropertyTypes: ReadonlyArray<NamedShape<T>>
|
|
46
|
+
): ComparisonResult;
|
|
47
|
+
export declare function compareEnumDeclarations(
|
|
48
|
+
newerDeclaration: NativeModuleEnumDeclaration,
|
|
49
|
+
olderDeclaration: NativeModuleEnumDeclaration
|
|
50
|
+
): ComparisonResult;
|
|
51
|
+
export declare function compareEnumDeclarationMemberArrays(
|
|
52
|
+
newer: Array<NativeModuleEnumMember>,
|
|
53
|
+
older: Array<NativeModuleEnumMember>
|
|
54
|
+
): MembersComparisonResult;
|
|
55
|
+
export declare function compareEnumDeclarationWithMembers(
|
|
56
|
+
newerDeclaration: NativeModuleEnumDeclarationWithMembers,
|
|
57
|
+
olderDeclaration: NativeModuleEnumDeclarationWithMembers
|
|
58
|
+
): ComparisonResult;
|
|
59
|
+
export declare function compareUnionTypes(
|
|
60
|
+
newerType: NativeModuleUnionTypeAnnotation,
|
|
61
|
+
olderType: NativeModuleUnionTypeAnnotation
|
|
62
|
+
): ComparisonResult;
|
|
63
|
+
export declare function comparePromiseTypes(
|
|
64
|
+
newerType: NativeModulePromiseTypeAnnotation,
|
|
65
|
+
olderType: NativeModulePromiseTypeAnnotation
|
|
66
|
+
): ComparisonResult;
|
|
67
|
+
export declare function compareGenericObjectTypes(
|
|
68
|
+
newerType: NativeModuleGenericObjectTypeAnnotation,
|
|
69
|
+
olderType: NativeModuleGenericObjectTypeAnnotation
|
|
70
|
+
): ComparisonResult;
|
|
71
|
+
export declare function compareNumberLiteralTypes(
|
|
72
|
+
newerType: NumberLiteralTypeAnnotation,
|
|
73
|
+
olderType: NumberLiteralTypeAnnotation
|
|
74
|
+
): ComparisonResult;
|
|
75
|
+
export declare function compareStringLiteralTypes(
|
|
76
|
+
newerType: StringLiteralTypeAnnotation,
|
|
77
|
+
olderType: StringLiteralTypeAnnotation
|
|
78
|
+
): ComparisonResult;
|
|
79
|
+
export declare function compareStringLiteralUnionTypes(
|
|
80
|
+
newerType: StringLiteralUnionTypeAnnotation,
|
|
81
|
+
olderType: StringLiteralUnionTypeAnnotation
|
|
82
|
+
): ComparisonResult;
|
|
83
|
+
export declare function compareFunctionTypes(
|
|
84
|
+
newerType: NativeModuleFunctionTypeAnnotation,
|
|
85
|
+
olderType: NativeModuleFunctionTypeAnnotation
|
|
86
|
+
): ComparisonResult;
|