expo-type-information 0.0.0 → 0.0.2

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/bin/cli.js +2 -0
  4. package/build/cli.d.ts +1 -0
  5. package/build/cli.js +35 -0
  6. package/build/cli.js.map +1 -0
  7. package/build/commands/commandUtils.d.ts +46 -0
  8. package/build/commands/commandUtils.js +274 -0
  9. package/build/commands/commandUtils.js.map +1 -0
  10. package/build/commands/generateJSXIntrinsicsCommand.d.ts +2 -0
  11. package/build/commands/generateJSXIntrinsicsCommand.js +28 -0
  12. package/build/commands/generateJSXIntrinsicsCommand.js.map +1 -0
  13. package/build/commands/generateMocksForFileCommand.d.ts +2 -0
  14. package/build/commands/generateMocksForFileCommand.js +22 -0
  15. package/build/commands/generateMocksForFileCommand.js.map +1 -0
  16. package/build/commands/generateModuleTypesCommand.d.ts +2 -0
  17. package/build/commands/generateModuleTypesCommand.js +32 -0
  18. package/build/commands/generateModuleTypesCommand.js.map +1 -0
  19. package/build/commands/generateViewTypesCommand.d.ts +2 -0
  20. package/build/commands/generateViewTypesCommand.js +28 -0
  21. package/build/commands/generateViewTypesCommand.js.map +1 -0
  22. package/build/commands/inlineModulesInterfaceCommand.d.ts +2 -0
  23. package/build/commands/inlineModulesInterfaceCommand.js +129 -0
  24. package/build/commands/inlineModulesInterfaceCommand.js.map +1 -0
  25. package/build/commands/moduleInterfaceCommand.d.ts +2 -0
  26. package/build/commands/moduleInterfaceCommand.js +46 -0
  27. package/build/commands/moduleInterfaceCommand.js.map +1 -0
  28. package/build/commands/shortModuleInterfaceCommand.d.ts +2 -0
  29. package/build/commands/shortModuleInterfaceCommand.js +17 -0
  30. package/build/commands/shortModuleInterfaceCommand.js.map +1 -0
  31. package/build/commands/typeInformationCommand.d.ts +2 -0
  32. package/build/commands/typeInformationCommand.js +24 -0
  33. package/build/commands/typeInformationCommand.js.map +1 -0
  34. package/build/index.d.ts +3 -0
  35. package/build/index.js +28 -0
  36. package/build/index.js.map +1 -0
  37. package/build/mockgen.d.ts +4 -0
  38. package/build/mockgen.js +204 -0
  39. package/build/mockgen.js.map +1 -0
  40. package/build/swift/sourcekittenTypeInformation.d.ts +6 -0
  41. package/build/swift/sourcekittenTypeInformation.js +875 -0
  42. package/build/swift/sourcekittenTypeInformation.js.map +1 -0
  43. package/build/typeInformation.d.ts +209 -0
  44. package/build/typeInformation.js +157 -0
  45. package/build/typeInformation.js.map +1 -0
  46. package/build/types.d.ts +59 -0
  47. package/build/types.js +3 -0
  48. package/build/types.js.map +1 -0
  49. package/build/typescriptGeneration.d.ts +61 -0
  50. package/build/typescriptGeneration.js +696 -0
  51. package/build/typescriptGeneration.js.map +1 -0
  52. package/build/utils.d.ts +6 -0
  53. package/build/utils.js +44 -0
  54. package/build/utils.js.map +1 -0
  55. package/jest.config.js +6 -0
  56. package/package.json +46 -5
  57. package/src/cli.ts +38 -0
  58. package/src/commands/commandUtils.ts +352 -0
  59. package/src/commands/generateJSXIntrinsicsCommand.ts +38 -0
  60. package/src/commands/generateMocksForFileCommand.ts +30 -0
  61. package/src/commands/generateModuleTypesCommand.ts +39 -0
  62. package/src/commands/generateViewTypesCommand.ts +39 -0
  63. package/src/commands/inlineModulesInterfaceCommand.ts +175 -0
  64. package/src/commands/moduleInterfaceCommand.ts +56 -0
  65. package/src/commands/shortModuleInterfaceCommand.ts +26 -0
  66. package/src/commands/typeInformationCommand.ts +35 -0
  67. package/src/index.ts +9 -0
  68. package/src/mockgen.ts +338 -0
  69. package/src/swift/sourcekittenTypeInformation.ts +1173 -0
  70. package/src/typeInformation.ts +326 -0
  71. package/src/types.ts +68 -0
  72. package/src/typescriptGeneration.ts +1179 -0
  73. package/src/utils.ts +44 -0
  74. package/tests/TestModule.swift +175 -0
  75. package/tests/__snapshots__/typeInformation.test.ts.snap +1578 -0
  76. package/tests/typeInformation.test.ts +134 -0
  77. package/tsconfig.json +11 -0
package/src/utils.ts ADDED
@@ -0,0 +1,44 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ // TODO(@HubertBer): Also exists in expo-modules-autolinking, but with a limiter, maybe take it or depend on it?
5
+ export const taskAll = <T, R>(
6
+ inputs: T[],
7
+ map: (input: T, index: number) => Promise<R>
8
+ ): Promise<R[]> => {
9
+ return Promise.all(inputs.map(map));
10
+ };
11
+
12
+ // TODO(@HubertBer): Taken from expo-modules-autolinking, maybe import it instead?
13
+ export async function* scanFilesRecursively(
14
+ parentPath: string,
15
+ includeDirectory?: (parentPath: string, name: string) => boolean,
16
+ sort = !fs.promises.opendir
17
+ ) {
18
+ const queue = [parentPath];
19
+ let targetPath: string | undefined;
20
+ while (queue.length > 0 && (targetPath = queue.shift()) != null) {
21
+ try {
22
+ const entries = sort
23
+ ? (await fs.promises.readdir(targetPath, { withFileTypes: true })).sort((a, b) =>
24
+ a.name.localeCompare(b.name)
25
+ )
26
+ : await fs.promises.opendir(targetPath);
27
+ for await (const entry of entries) {
28
+ if (entry.isDirectory() && entry.name !== 'node_modules') {
29
+ if (!includeDirectory || includeDirectory(targetPath, entry.name)) {
30
+ queue.push(path.join(targetPath, entry.name));
31
+ }
32
+ } else if (entry.isFile()) {
33
+ yield {
34
+ path: path.join(targetPath, entry.name),
35
+ parentPath: targetPath,
36
+ name: entry.name,
37
+ } as const;
38
+ }
39
+ }
40
+ } catch {
41
+ continue;
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,175 @@
1
+ import ExpoModulesCore
2
+ import WebKit
3
+
4
+ public class TestModule: Module {
5
+ public func definition() -> ModuleDefinition {
6
+ Constant("StringConstant") { () -> Int in
7
+ return "Swift constant 1283"
8
+ }
9
+
10
+ Constant("IntConstant") { () -> Int in
11
+ return 37;
12
+ }
13
+
14
+ Constant("UntypedConstant") { () in 98} // Comment 1
15
+
16
+ Function("SimpleFunction") { (a: Double, b: Int) -> Double in
17
+ return a + b // Comment 2
18
+ }
19
+
20
+ Function("TestUntypedFunction") { () in
21
+ return "string"
22
+ }
23
+
24
+ Function("TestUntypedFunction2") { /* Comment 3 */ () in
25
+ // Comment 4
26
+ return TestEnum.simpleCase
27
+ }
28
+
29
+ Function("TestUntypedFunction3" /* Comment 5 */) {
30
+ return TestRecord2(field1: /* Comment 6 */ 10, "field2")
31
+ }
32
+
33
+ Function("TestArrays") { (a: [Int]) -> /* Comment 7 */ [[String]] in
34
+ return ["test"]
35
+ }
36
+
37
+ Function("TestDictionaries") { (a: [Int: String] /* Comment 8 */, b: [Int : [Float : String]]) -> Any in
38
+ return "test"
39
+ }
40
+
41
+ Function("TestParametrizedTypes") { (a: SomeParametrizedType<Either<Int, String>, Map<Set<Int>, Either<Set<Int>, Set<String>>>>) -> String in
42
+ return ""
43
+ }
44
+
45
+ Function("TestTypeCombinations") { (a: [[[Int]]]) -> [[Either<String, [Int: String]>]] in
46
+ return [["test"]]
47
+ }
48
+
49
+ Function("TestFunctionReturningRecord") { () -> TestRecord in /* Comment 10
50
+ multiple
51
+ lines
52
+ comment
53
+ body
54
+ */
55
+ return ""
56
+ }
57
+
58
+ Function("TestFunctionReturningEnum") { () -> TestEnum in
59
+ return TestEnum.simpleCase
60
+ }
61
+
62
+ AsyncFunction("TestSimpleAsyncFunction") { (a: String, b: String) async -> String in
63
+ return a + b
64
+ }
65
+
66
+ AsyncFunction("TestUnderscore") { (url: URL, _ /* Comment 10 */: [BarcodeType]) in
67
+ }
68
+
69
+
70
+ Class(TestClassWithConstructor.self) {
71
+ Constructor { (a: Int) in
72
+ TestClass(a)
73
+ }
74
+ }
75
+
76
+ Class(TestBasicClass.self) {
77
+ Constructor { (a: Int, b: String, c: Either<String, TestRecord>) in
78
+ TestClass(a)
79
+ }
80
+
81
+ Property("TestIntProperty") { () -> Int in
82
+ 1
83
+ }
84
+
85
+ Property("TestEitherProperty") { () -> Either<Int, String> in
86
+ 1
87
+ }
88
+
89
+ Property("TestEnumProperty") { () -> TestEnum in
90
+ .simpleCase
91
+ }
92
+
93
+ Property("TestRecordProperty") { () -> TestRecord2 in
94
+ TestRecord2(1, "2")
95
+ }
96
+
97
+ AsyncFunction("TestAsyncFunction") { (a: Int) async -> String in
98
+ "string"
99
+ }
100
+ }
101
+
102
+ Class(TestEmptyClass.self) {
103
+ }
104
+
105
+ View(ExpoWebView.self) {
106
+ Events("onEvent1", "onEvent2")
107
+
108
+ Prop("url") { (view, url: URL) in
109
+ if view.webView.url != url {
110
+ let urlRequest = URLRequest(url: url)
111
+ view.webView.load(urlRequest)
112
+ }
113
+ }
114
+
115
+ Prop("testRecord") { (view, testRecord: TestRecord) in
116
+ }
117
+
118
+ Prop("testRecord2") { (view, testRecord2: TestRecord2) in
119
+ }
120
+
121
+ Prop("testRecordClass") { (view, testRecordClass: TestRecordClass) in
122
+ }
123
+
124
+ Prop("testEnum") { (view, testEnum: TestEnum) in
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ struct TestRecord: Record {
131
+ @Field
132
+ var basicString: String
133
+ @Field
134
+ var basicStringInitialized: String = "utf8"
135
+ @Field
136
+ var basicIntInferred = 0
137
+ @Field
138
+ var basicDoubleInferred = 0.1
139
+ @Field
140
+ var basicStringInferred = "string"
141
+ @Field
142
+ var enumInferred = TestEnum.simpleCase
143
+ @Field
144
+ var complexEnumInferred = TestEnum.caseWithArgs1(2, 0.1, "Test")
145
+
146
+ @Field
147
+ var recordInferred = TestRecord2(field1: 21, field2: "testing")
148
+
149
+ @Field
150
+ var optionalInt: Int?
151
+ @Field
152
+ let letDoubleBinding: Double = 0.1
153
+
154
+ var fieldWithoutAnnotation: Int = 1
155
+ }
156
+
157
+ struct TestRecord2: Record {
158
+ @Field
159
+ var field1: Int
160
+ @Field
161
+ var field2: String
162
+ }
163
+
164
+ class TestRecordClass: Record {
165
+ @Field
166
+ var field1: Int
167
+ @Field
168
+ var field2: String
169
+ }
170
+
171
+ enum TestEnum {
172
+ case simpleCase
173
+ case multipleCases1, multipleCases2
174
+ case caseWithArgs1(Int, Double, String), caseWithArgs2(Double, String, Either<Int, String>)
175
+ }