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.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/bin/cli.js +2 -0
- package/build/cli.d.ts +1 -0
- package/build/cli.js +35 -0
- package/build/cli.js.map +1 -0
- package/build/commands/commandUtils.d.ts +46 -0
- package/build/commands/commandUtils.js +274 -0
- package/build/commands/commandUtils.js.map +1 -0
- package/build/commands/generateJSXIntrinsicsCommand.d.ts +2 -0
- package/build/commands/generateJSXIntrinsicsCommand.js +28 -0
- package/build/commands/generateJSXIntrinsicsCommand.js.map +1 -0
- package/build/commands/generateMocksForFileCommand.d.ts +2 -0
- package/build/commands/generateMocksForFileCommand.js +22 -0
- package/build/commands/generateMocksForFileCommand.js.map +1 -0
- package/build/commands/generateModuleTypesCommand.d.ts +2 -0
- package/build/commands/generateModuleTypesCommand.js +32 -0
- package/build/commands/generateModuleTypesCommand.js.map +1 -0
- package/build/commands/generateViewTypesCommand.d.ts +2 -0
- package/build/commands/generateViewTypesCommand.js +28 -0
- package/build/commands/generateViewTypesCommand.js.map +1 -0
- package/build/commands/inlineModulesInterfaceCommand.d.ts +2 -0
- package/build/commands/inlineModulesInterfaceCommand.js +129 -0
- package/build/commands/inlineModulesInterfaceCommand.js.map +1 -0
- package/build/commands/moduleInterfaceCommand.d.ts +2 -0
- package/build/commands/moduleInterfaceCommand.js +46 -0
- package/build/commands/moduleInterfaceCommand.js.map +1 -0
- package/build/commands/shortModuleInterfaceCommand.d.ts +2 -0
- package/build/commands/shortModuleInterfaceCommand.js +17 -0
- package/build/commands/shortModuleInterfaceCommand.js.map +1 -0
- package/build/commands/typeInformationCommand.d.ts +2 -0
- package/build/commands/typeInformationCommand.js +24 -0
- package/build/commands/typeInformationCommand.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +28 -0
- package/build/index.js.map +1 -0
- package/build/mockgen.d.ts +4 -0
- package/build/mockgen.js +204 -0
- package/build/mockgen.js.map +1 -0
- package/build/swift/sourcekittenTypeInformation.d.ts +6 -0
- package/build/swift/sourcekittenTypeInformation.js +875 -0
- package/build/swift/sourcekittenTypeInformation.js.map +1 -0
- package/build/typeInformation.d.ts +209 -0
- package/build/typeInformation.js +157 -0
- package/build/typeInformation.js.map +1 -0
- package/build/types.d.ts +59 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/typescriptGeneration.d.ts +61 -0
- package/build/typescriptGeneration.js +696 -0
- package/build/typescriptGeneration.js.map +1 -0
- package/build/utils.d.ts +6 -0
- package/build/utils.js +44 -0
- package/build/utils.js.map +1 -0
- package/jest.config.js +6 -0
- package/package.json +46 -5
- package/src/cli.ts +38 -0
- package/src/commands/commandUtils.ts +352 -0
- package/src/commands/generateJSXIntrinsicsCommand.ts +38 -0
- package/src/commands/generateMocksForFileCommand.ts +30 -0
- package/src/commands/generateModuleTypesCommand.ts +39 -0
- package/src/commands/generateViewTypesCommand.ts +39 -0
- package/src/commands/inlineModulesInterfaceCommand.ts +175 -0
- package/src/commands/moduleInterfaceCommand.ts +56 -0
- package/src/commands/shortModuleInterfaceCommand.ts +26 -0
- package/src/commands/typeInformationCommand.ts +35 -0
- package/src/index.ts +9 -0
- package/src/mockgen.ts +338 -0
- package/src/swift/sourcekittenTypeInformation.ts +1173 -0
- package/src/typeInformation.ts +326 -0
- package/src/types.ts +68 -0
- package/src/typescriptGeneration.ts +1179 -0
- package/src/utils.ts +44 -0
- package/tests/TestModule.swift +175 -0
- package/tests/__snapshots__/typeInformation.test.ts.snap +1578 -0
- package/tests/typeInformation.test.ts +134 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { it, expect } from '@jest/globals';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
|
|
4
|
+
import { generateTSMockForModule } from '../src/mockgen';
|
|
5
|
+
import {
|
|
6
|
+
FileTypeInformation,
|
|
7
|
+
getFileTypeInformation,
|
|
8
|
+
ModuleClassDeclaration,
|
|
9
|
+
serializeTypeInformation,
|
|
10
|
+
TypeInferenceOption,
|
|
11
|
+
} from '../src/typeInformation';
|
|
12
|
+
import {
|
|
13
|
+
generateFullTsInterface,
|
|
14
|
+
generateConciseTsInterface,
|
|
15
|
+
generateModuleTypesFileContent,
|
|
16
|
+
generateViewTypesFileContent,
|
|
17
|
+
} from '../src/typescriptGeneration';
|
|
18
|
+
import { GetFileTypeInformationOptions } from '../build';
|
|
19
|
+
|
|
20
|
+
const swiftFile = fs.realpathSync('./tests/TestModule.swift');
|
|
21
|
+
const defaultArgs: GetFileTypeInformationOptions = {
|
|
22
|
+
input: { inputFileAbsolutePaths: [swiftFile], type: 'file' },
|
|
23
|
+
typeInference: TypeInferenceOption.PREPROCESS_AND_INFERENCE,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
let defaultArgsFileInfo: FileTypeInformation | null = null;
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
defaultArgsFileInfo = await getFileTypeInformation(defaultArgs);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('Same type information', async () => {
|
|
32
|
+
expect(
|
|
33
|
+
serializeTypeInformation(
|
|
34
|
+
(await getFileTypeInformation(defaultArgs)) ?? {
|
|
35
|
+
usedTypeIdentifiers: new Set(),
|
|
36
|
+
declaredTypeIdentifiers: new Set(),
|
|
37
|
+
inferredTypeParametersCount: new Map(),
|
|
38
|
+
typeIdentifierDefinitionMap: new Map(),
|
|
39
|
+
moduleClasses: [],
|
|
40
|
+
records: [],
|
|
41
|
+
enums: [],
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
).toMatchSnapshot();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('Same generated view file', async () => {
|
|
48
|
+
const fileInfo = defaultArgsFileInfo;
|
|
49
|
+
expect(fileInfo).toBeTruthy();
|
|
50
|
+
if (fileInfo) {
|
|
51
|
+
expect(await generateViewTypesFileContent(fileInfo)).toMatchSnapshot();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('Same generated module file', async () => {
|
|
56
|
+
const fileInfo = defaultArgsFileInfo;
|
|
57
|
+
expect(fileInfo).toBeTruthy();
|
|
58
|
+
if (fileInfo) {
|
|
59
|
+
expect(await generateModuleTypesFileContent(fileInfo)).toMatchSnapshot();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Same generated mock file', async () => {
|
|
64
|
+
const fileInfo = defaultArgsFileInfo;
|
|
65
|
+
expect(fileInfo).toBeTruthy();
|
|
66
|
+
if (fileInfo) {
|
|
67
|
+
expect(
|
|
68
|
+
generateTSMockForModule(fileInfo.moduleClasses[0] as ModuleClassDeclaration, fileInfo, true)
|
|
69
|
+
).toMatchSnapshot();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('Same generated mock file JS', async () => {
|
|
74
|
+
const fileInfo = defaultArgsFileInfo;
|
|
75
|
+
expect(fileInfo).toBeTruthy();
|
|
76
|
+
if (fileInfo) {
|
|
77
|
+
expect(
|
|
78
|
+
generateTSMockForModule(fileInfo.moduleClasses[0] as ModuleClassDeclaration, fileInfo, false)
|
|
79
|
+
).toMatchSnapshot();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('Same generated concise ts interface', async () => {
|
|
84
|
+
const fileInfo = defaultArgsFileInfo;
|
|
85
|
+
expect(fileInfo).toBeTruthy();
|
|
86
|
+
if (fileInfo) {
|
|
87
|
+
const { volatileGeneratedFileContent, moduleTypescriptInterfaceFileContent } =
|
|
88
|
+
await generateConciseTsInterface(fileInfo);
|
|
89
|
+
expect(volatileGeneratedFileContent).toMatchSnapshot();
|
|
90
|
+
expect(moduleTypescriptInterfaceFileContent).toMatchSnapshot();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('Same generated full ts interface', async () => {
|
|
95
|
+
const fileInfo = defaultArgsFileInfo;
|
|
96
|
+
expect(fileInfo).toBeTruthy();
|
|
97
|
+
if (fileInfo) {
|
|
98
|
+
const result = await generateFullTsInterface(fileInfo);
|
|
99
|
+
expect(result).toMatchSnapshot();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('Generation from string is the same as generation from file. Preprocessing.', async () => {
|
|
104
|
+
const fileInfo = defaultArgsFileInfo;
|
|
105
|
+
const fileInfoForString = await getFileTypeInformation({
|
|
106
|
+
input: { type: 'string', fileContent: fs.readFileSync(swiftFile, 'utf8'), language: 'Swift' },
|
|
107
|
+
typeInference: TypeInferenceOption.PREPROCESS_AND_INFERENCE,
|
|
108
|
+
});
|
|
109
|
+
expect(fileInfo).toEqual(fileInfoForString);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('Generation from string is the same as generation from file. Simple type inference.', async () => {
|
|
113
|
+
const fileInfo = await getFileTypeInformation({
|
|
114
|
+
input: { type: 'file', inputFileAbsolutePaths: [swiftFile] },
|
|
115
|
+
typeInference: TypeInferenceOption.NO_INFERENCE,
|
|
116
|
+
});
|
|
117
|
+
const fileInfoForString = await getFileTypeInformation({
|
|
118
|
+
input: { type: 'string', fileContent: fs.readFileSync(swiftFile, 'utf8'), language: 'Swift' },
|
|
119
|
+
typeInference: TypeInferenceOption.NO_INFERENCE,
|
|
120
|
+
});
|
|
121
|
+
expect(fileInfo).toEqual(fileInfoForString);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('Generation from string is the same as generation from file. No type inference.', async () => {
|
|
125
|
+
const fileInfo = await getFileTypeInformation({
|
|
126
|
+
input: { type: 'file', inputFileAbsolutePaths: [swiftFile] },
|
|
127
|
+
typeInference: TypeInferenceOption.SIMPLE_INFERENCE,
|
|
128
|
+
});
|
|
129
|
+
const fileInfoForString = await getFileTypeInformation({
|
|
130
|
+
input: { type: 'string', fileContent: fs.readFileSync(swiftFile, 'utf8'), language: 'Swift' },
|
|
131
|
+
typeInference: TypeInferenceOption.SIMPLE_INFERENCE,
|
|
132
|
+
});
|
|
133
|
+
expect(fileInfo).toEqual(fileInfoForString);
|
|
134
|
+
});
|