@react-native-windows/codegen 0.72.0 → 0.72.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 (33) hide show
  1. package/CHANGELOG.md +22 -5
  2. package/lib-commonjs/Cli.js +18 -0
  3. package/lib-commonjs/Cli.js.map +1 -1
  4. package/lib-commonjs/generators/AliasGen.d.ts +2 -1
  5. package/lib-commonjs/generators/AliasGen.js +33 -17
  6. package/lib-commonjs/generators/AliasGen.js.map +1 -1
  7. package/lib-commonjs/generators/GenerateNM2.d.ts +5 -2
  8. package/lib-commonjs/generators/GenerateNM2.js +68 -20
  9. package/lib-commonjs/generators/GenerateNM2.js.map +1 -1
  10. package/lib-commonjs/generators/ObjectTypes.d.ts +6 -2
  11. package/lib-commonjs/generators/ObjectTypes.js +9 -9
  12. package/lib-commonjs/generators/ObjectTypes.js.map +1 -1
  13. package/lib-commonjs/generators/ParamTypes.d.ts +3 -2
  14. package/lib-commonjs/generators/ParamTypes.js +27 -27
  15. package/lib-commonjs/generators/ParamTypes.js.map +1 -1
  16. package/lib-commonjs/generators/ReturnTypes.d.ts +3 -2
  17. package/lib-commonjs/generators/ReturnTypes.js +7 -7
  18. package/lib-commonjs/generators/ReturnTypes.js.map +1 -1
  19. package/lib-commonjs/generators/ValidateMethods.d.ts +2 -1
  20. package/lib-commonjs/generators/ValidateMethods.js +15 -15
  21. package/lib-commonjs/generators/ValidateMethods.js.map +1 -1
  22. package/lib-commonjs/index.d.ts +11 -13
  23. package/lib-commonjs/index.js +8 -4
  24. package/lib-commonjs/index.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/Cli.ts +24 -2
  27. package/src/generators/AliasGen.ts +61 -17
  28. package/src/generators/GenerateNM2.ts +86 -17
  29. package/src/generators/ObjectTypes.ts +15 -3
  30. package/src/generators/ParamTypes.ts +43 -9
  31. package/src/generators/ReturnTypes.ts +18 -3
  32. package/src/generators/ValidateMethods.ts +32 -4
  33. package/src/index.ts +23 -14
@@ -12,6 +12,7 @@ import type {
12
12
  NativeModuleSchema,
13
13
  } from '@react-native/codegen/lib/CodegenSchema';
14
14
  import {AliasMap} from './AliasManaging';
15
+ import type {CppCodegenOptions} from './ObjectTypes';
15
16
  import {translateArgs, translateSpecArgs} from './ParamTypes';
16
17
  import {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';
17
18
 
@@ -27,8 +28,9 @@ function getPossibleMethodSignatures(
27
28
  funcType: NativeModuleFunctionTypeAnnotation,
28
29
  aliases: AliasMap,
29
30
  baseAliasName: string,
31
+ options: CppCodegenOptions,
30
32
  ): string[] {
31
- const args = translateArgs(funcType.params, aliases, baseAliasName);
33
+ const args = translateArgs(funcType.params, aliases, baseAliasName, options);
32
34
  if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
33
35
  if (funcType.returnTypeAnnotation.elementType) {
34
36
  args.push(
@@ -36,6 +38,7 @@ function getPossibleMethodSignatures(
36
38
  funcType.returnTypeAnnotation.elementType,
37
39
  aliases,
38
40
  baseAliasName,
41
+ options,
39
42
  )}> &&result`,
40
43
  );
41
44
  } else {
@@ -50,6 +53,7 @@ function getPossibleMethodSignatures(
50
53
  funcType.returnTypeAnnotation,
51
54
  aliases,
52
55
  baseAliasName,
56
+ options,
53
57
  )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
54
58
 
55
59
  const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${
@@ -58,6 +62,7 @@ function getPossibleMethodSignatures(
58
62
  funcType.returnTypeAnnotation,
59
63
  aliases,
60
64
  baseAliasName,
65
+ options,
61
66
  )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }`;
62
67
 
63
68
  return [sig, staticsig];
@@ -68,8 +73,15 @@ function translatePossibleMethodSignatures(
68
73
  funcType: NativeModuleFunctionTypeAnnotation,
69
74
  aliases: AliasMap,
70
75
  baseAliasName: string,
76
+ options: CppCodegenOptions,
71
77
  ): string {
72
- return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName)
78
+ return getPossibleMethodSignatures(
79
+ prop,
80
+ funcType,
81
+ aliases,
82
+ baseAliasName,
83
+ options,
84
+ )
73
85
  .map(sig => `" ${sig}\\n"`)
74
86
  .join('\n ');
75
87
  }
@@ -78,6 +90,7 @@ function renderProperties(
78
90
  properties: ReadonlyArray<NativeModulePropertyShape>,
79
91
  aliases: AliasMap,
80
92
  tuple: boolean,
93
+ options: CppCodegenOptions,
81
94
  ): string {
82
95
  // TODO: generate code for constants
83
96
  return properties
@@ -95,12 +108,14 @@ function renderProperties(
95
108
  funcType.params,
96
109
  aliases,
97
110
  propAliasName,
111
+ options,
98
112
  );
99
113
 
100
114
  const translatedReturnParam = translateSpecReturnType(
101
115
  funcType.returnTypeAnnotation,
102
116
  aliases,
103
117
  propAliasName,
118
+ options,
104
119
  );
105
120
 
106
121
  if (funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation') {
@@ -110,6 +125,7 @@ function renderProperties(
110
125
  funcType.returnTypeAnnotation.elementType,
111
126
  aliases,
112
127
  propAliasName,
128
+ options,
113
129
  )}>`,
114
130
  );
115
131
  } else {
@@ -132,6 +148,7 @@ function renderProperties(
132
148
  funcType,
133
149
  aliases,
134
150
  propAliasName,
151
+ options,
135
152
  )});`;
136
153
  }
137
154
  })
@@ -141,9 +158,20 @@ function renderProperties(
141
158
  export function generateValidateMethods(
142
159
  nativeModule: NativeModuleSchema,
143
160
  aliases: AliasMap,
161
+ options: CppCodegenOptions,
144
162
  ): [string, string] {
145
163
  const properties = nativeModule.spec.properties;
146
- const traversedProperties = renderProperties(properties, aliases, false);
147
- const traversedPropertyTuples = renderProperties(properties, aliases, true);
164
+ const traversedProperties = renderProperties(
165
+ properties,
166
+ aliases,
167
+ false,
168
+ options,
169
+ );
170
+ const traversedPropertyTuples = renderProperties(
171
+ properties,
172
+ aliases,
173
+ true,
174
+ options,
175
+ );
148
176
  return [traversedPropertyTuples, traversedProperties];
149
177
  }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  import path from 'path';
9
9
  import fs from '@react-native-windows/fs';
10
10
  import globby from 'globby';
11
+ import type {CppStringTypes} from './generators/GenerateNM2';
11
12
  import {createNM2Generator} from './generators/GenerateNM2';
12
13
  import {
13
14
  generateTypeScript,
@@ -16,6 +17,8 @@ import {
16
17
  import type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';
17
18
  import type {Parser} from '@react-native/codegen/lib/parsers/parser';
18
19
 
20
+ export type {CppStringTypes} from './generators/GenerateNM2';
21
+
19
22
  // Load @react-native/codegen from react-native
20
23
  const rnPath = path.dirname(require.resolve('react-native/package.json'));
21
24
  const rncodegenPath = path.dirname(
@@ -37,18 +40,23 @@ function getParser(isTypeScript: boolean): Parser {
37
40
 
38
41
  const schemaValidator = require(path.resolve(
39
42
  rncodegenPath,
40
- 'lib/schemaValidator',
43
+ 'lib/SchemaValidator',
41
44
  ));
42
45
 
43
- interface Options {
46
+ export interface SharedOptions {
44
47
  libraryName: string;
45
48
  methodOnly: boolean;
46
49
  modulesCxx: boolean;
47
- moduleSpecName: string;
48
50
  modulesTypeScriptTypes: boolean;
49
51
  modulesWindows: boolean;
50
52
  namespace: string;
51
53
  outputDirectory: string;
54
+ cppStringType: CppStringTypes;
55
+ separateDataTypes: boolean;
56
+ }
57
+
58
+ interface Options extends SharedOptions {
59
+ moduleSpecName: string;
52
60
  schema: SchemaType;
53
61
  }
54
62
 
@@ -204,11 +212,13 @@ export function generate(
204
212
  libraryName,
205
213
  methodOnly,
206
214
  modulesCxx,
207
- moduleSpecName,
208
215
  modulesTypeScriptTypes,
209
216
  modulesWindows,
210
217
  namespace,
211
218
  outputDirectory,
219
+ cppStringType,
220
+ separateDataTypes,
221
+ moduleSpecName,
212
222
  schema,
213
223
  }: Options,
214
224
  {/*generators,*/ test}: Config,
@@ -231,6 +241,8 @@ export function generate(
231
241
  const generateNM2 = createNM2Generator({
232
242
  methodOnly,
233
243
  namespace,
244
+ cppStringType,
245
+ separateDataTypes,
234
246
  });
235
247
 
236
248
  const generateJsiModuleH = require(path.resolve(
@@ -336,18 +348,11 @@ export function generate(
336
348
  return writeMapToFiles(generatedFiles, outputDirectory);
337
349
  }
338
350
 
339
- export type CodeGenOptions = {
351
+ export interface CodeGenOptions extends SharedOptions {
340
352
  file?: string;
341
353
  files?: string[];
342
- libraryName: string;
343
- methodOnly: boolean;
344
- modulesCxx: boolean;
345
- modulesTypeScriptTypes: boolean;
346
- modulesWindows: boolean;
347
- namespace: string;
348
- outputDirectory: string;
349
354
  test: boolean;
350
- };
355
+ }
351
356
 
352
357
  export function runCodeGen(options: CodeGenOptions): boolean {
353
358
  if (!options.file && !options.files)
@@ -366,17 +371,21 @@ export function runCodeGen(options: CodeGenOptions): boolean {
366
371
  modulesWindows,
367
372
  namespace,
368
373
  outputDirectory,
374
+ cppStringType,
375
+ separateDataTypes,
369
376
  } = options;
370
377
  return generate(
371
378
  {
372
379
  libraryName,
373
380
  methodOnly,
374
381
  modulesCxx,
375
- moduleSpecName,
376
382
  modulesTypeScriptTypes,
377
383
  modulesWindows,
378
384
  namespace,
379
385
  outputDirectory,
386
+ cppStringType,
387
+ separateDataTypes,
388
+ moduleSpecName,
380
389
  schema,
381
390
  },
382
391
  {generators: [], test: options.test},