@react-native-windows/codegen 0.0.0-canary.3 → 0.0.0-canary.32

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 (48) hide show
  1. package/CHANGELOG.md +283 -6
  2. package/bin.js +0 -0
  3. package/lib-commonjs/Cli.d.ts +7 -0
  4. package/lib-commonjs/Cli.js +231 -0
  5. package/lib-commonjs/Cli.js.map +1 -0
  6. package/lib-commonjs/generators/AliasGen.d.ts +11 -0
  7. package/lib-commonjs/generators/AliasGen.js +72 -0
  8. package/lib-commonjs/generators/AliasGen.js.map +1 -0
  9. package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
  10. package/lib-commonjs/generators/AliasManaging.js +49 -0
  11. package/lib-commonjs/generators/AliasManaging.js.map +1 -0
  12. package/lib-commonjs/generators/GenerateNM2.d.ts +11 -0
  13. package/lib-commonjs/generators/GenerateNM2.js +94 -0
  14. package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
  15. package/lib-commonjs/generators/GenerateTypeScript.d.ts +11 -0
  16. package/lib-commonjs/generators/GenerateTypeScript.js +166 -0
  17. package/lib-commonjs/generators/GenerateTypeScript.js.map +1 -0
  18. package/lib-commonjs/generators/ObjectTypes.d.ts +8 -0
  19. package/lib-commonjs/generators/ObjectTypes.js +53 -0
  20. package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
  21. package/lib-commonjs/generators/ParamTypes.d.ts +11 -0
  22. package/lib-commonjs/generators/ParamTypes.js +114 -0
  23. package/lib-commonjs/generators/ParamTypes.js.map +1 -0
  24. package/lib-commonjs/generators/ReturnTypes.d.ts +9 -0
  25. package/lib-commonjs/generators/ReturnTypes.js +63 -0
  26. package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
  27. package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
  28. package/lib-commonjs/generators/ValidateConstants.js +38 -0
  29. package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
  30. package/lib-commonjs/generators/ValidateMethods.d.ts +8 -0
  31. package/lib-commonjs/generators/ValidateMethods.js +70 -0
  32. package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
  33. package/package.json +28 -16
  34. package/src/Cli.ts +172 -35
  35. package/src/generators/AliasGen.ts +105 -0
  36. package/src/generators/AliasManaging.ts +75 -0
  37. package/src/generators/GenerateNM2.ts +62 -296
  38. package/src/generators/GenerateTypeScript.ts +247 -0
  39. package/src/generators/ObjectTypes.ts +70 -0
  40. package/src/generators/ParamTypes.ts +220 -0
  41. package/src/generators/ReturnTypes.ts +92 -0
  42. package/src/generators/ValidateConstants.ts +50 -0
  43. package/src/generators/ValidateMethods.ts +135 -0
  44. package/.eslintrc.js +0 -4
  45. package/.vscode/launch.json +0 -23
  46. package/CHANGELOG.json +0 -447
  47. package/jest.config.js +0 -1
  48. package/tsconfig.json +0 -5
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.translateImplReturnType = exports.translateSpecReturnType = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ function translateReturnType(type, aliases, baseAliasName) {
11
+ // avoid: Property 'type' does not exist on type 'never'
12
+ const returnType = type.type;
13
+ switch (type.type) {
14
+ case 'VoidTypeAnnotation':
15
+ case 'PromiseTypeAnnotation':
16
+ return 'void';
17
+ case 'StringTypeAnnotation':
18
+ return 'std::string';
19
+ case 'NumberTypeAnnotation':
20
+ case 'FloatTypeAnnotation':
21
+ case 'DoubleTypeAnnotation':
22
+ return 'double';
23
+ case 'Int32TypeAnnotation':
24
+ return 'int';
25
+ case 'BooleanTypeAnnotation':
26
+ return 'bool';
27
+ case 'ArrayTypeAnnotation':
28
+ if (type.elementType) {
29
+ return `std::vector<${translateReturnType(type.elementType, aliases, `${baseAliasName}_element`)}>`;
30
+ }
31
+ else {
32
+ return '::React::JSValueArray';
33
+ }
34
+ case 'GenericObjectTypeAnnotation':
35
+ return '::React::JSValue';
36
+ case 'ObjectTypeAnnotation':
37
+ return (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, baseAliasName, type);
38
+ case 'ReservedTypeAnnotation': {
39
+ // avoid: Property 'name' does not exist on type 'never'
40
+ const name = type.name;
41
+ // (#6597)
42
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
43
+ if (name !== 'RootTag')
44
+ throw new Error(`Unknown reserved function: ${name} in translateReturnType`);
45
+ return 'double';
46
+ }
47
+ case 'TypeAliasTypeAnnotation':
48
+ return (0, AliasManaging_1.getAliasCppName)(type.name);
49
+ case 'NullableTypeAnnotation':
50
+ return `std::optional<${translateReturnType(type.typeAnnotation, aliases, baseAliasName)}>`;
51
+ default:
52
+ throw new Error(`Unhandled type in translateReturnType: ${returnType}`);
53
+ }
54
+ }
55
+ function translateSpecReturnType(type, aliases, baseAliasName) {
56
+ return translateReturnType(type, aliases, `${baseAliasName}_returnType`);
57
+ }
58
+ exports.translateSpecReturnType = translateSpecReturnType;
59
+ function translateImplReturnType(type, aliases, baseAliasName) {
60
+ return translateReturnType(type, aliases, `${baseAliasName}_returnType`);
61
+ }
62
+ exports.translateImplReturnType = translateImplReturnType;
63
+ //# sourceMappingURL=ReturnTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReturnTypes.js","sourceRoot":"","sources":["../../src/generators/ReturnTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAMb,mDAIyB;AAEzB,SAAS,mBAAmB,CAC1B,IAAgD,EAChD,OAAiB,EACjB,aAAqB;IAErB,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,oBAAoB,CAAC;QAC1B,KAAK,uBAAuB;YAC1B,OAAO,MAAM,CAAC;QAChB,KAAK,sBAAsB;YACzB,OAAO,aAAa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ND,0DAMC;AAED,SAAgB,uBAAuB,CACrC,IAAgD,EAChD,OAAiB,EACjB,aAAqB;IAErB,OAAO,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,aAAa,aAAa,CAAC,CAAC;AAC3E,CAAC;AAND,0DAMC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NativeModuleReturnTypeAnnotation,\n Nullable,\n} from 'react-native-tscodegen';\nimport {\n AliasMap,\n getAliasCppName,\n getAnonymousAliasCppName,\n} from './AliasManaging';\n\nfunction translateReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'VoidTypeAnnotation':\n case 'PromiseTypeAnnotation':\n return 'void';\n case 'StringTypeAnnotation':\n return 'std::string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n return 'double';\n case 'Int32TypeAnnotation':\n return 'int';\n case 'BooleanTypeAnnotation':\n return 'bool';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `std::vector<${translateReturnType(\n type.elementType,\n aliases,\n `${baseAliasName}_element`,\n )}>`;\n } else {\n return '::React::JSValueArray';\n }\n case 'GenericObjectTypeAnnotation':\n return '::React::JSValue';\n case 'ObjectTypeAnnotation':\n return getAnonymousAliasCppName(aliases, baseAliasName, type);\n case 'ReservedTypeAnnotation': {\n // avoid: Property 'name' does not exist on type 'never'\n const name = type.name;\n // (#6597)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (name !== 'RootTag')\n throw new Error(\n `Unknown reserved function: ${name} in translateReturnType`,\n );\n return 'double';\n }\n case 'TypeAliasTypeAnnotation':\n return getAliasCppName(type.name);\n case 'NullableTypeAnnotation':\n return `std::optional<${translateReturnType(\n type.typeAnnotation,\n aliases,\n baseAliasName,\n )}>`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nexport function translateSpecReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n) {\n return translateReturnType(type, aliases, `${baseAliasName}_returnType`);\n}\n\nexport function translateImplReturnType(\n type: Nullable<NativeModuleReturnTypeAnnotation>,\n aliases: AliasMap,\n baseAliasName: string,\n) {\n return translateReturnType(type, aliases, `${baseAliasName}_returnType`);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleSchema } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function generateValidateConstants(nativeModule: NativeModuleSchema, aliases: AliasMap): [string, string] | undefined;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.generateValidateConstants = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ function generateValidateConstants(nativeModule, aliases) {
11
+ const candidates = nativeModule.spec.properties.filter(prop => prop.name === 'getConstants');
12
+ if (candidates.length === 0) {
13
+ return undefined;
14
+ }
15
+ const getConstant = candidates[0];
16
+ const funcType = getConstant.typeAnnotation.type === 'NullableTypeAnnotation'
17
+ ? getConstant.typeAnnotation.typeAnnotation
18
+ : getConstant.typeAnnotation;
19
+ if (funcType.params.length > 0 ||
20
+ funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation') {
21
+ return undefined;
22
+ }
23
+ const constantType = funcType.returnTypeAnnotation;
24
+ if (constantType.properties.length === 0) {
25
+ return undefined;
26
+ }
27
+ const cppName = (0, AliasManaging_1.getAnonymousAliasCppName)(aliases, 'Constants', constantType);
28
+ return [
29
+ ` TypedConstant<${cppName}>{0},`,
30
+ ` REACT_SHOW_CONSTANT_SPEC_ERRORS(
31
+ 0,
32
+ "${cppName}",
33
+ " REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\n"
34
+ " REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\n");`,
35
+ ];
36
+ }
37
+ exports.generateValidateConstants = generateValidateConstants;
38
+ //# sourceMappingURL=ValidateConstants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidateConstants.js","sourceRoot":"","sources":["../../src/generators/ValidateConstants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAmE;AAEnE,SAAgB,yBAAyB,CACvC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CACpD,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;IACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GACZ,WAAW,CAAC,cAAc,CAAC,IAAI,KAAK,wBAAwB;QAC1D,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,cAAc;QAC3C,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;IACjC,IACE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAC1B,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,sBAAsB,EAC7D;QACA,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,QAAQ,CAAC,oBAAoB,CAAC;IACnD,IAAI,YAAY,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,IAAA,wCAAwB,EAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAE7E,OAAO;QACL,uBAAuB,OAAO,OAAO;QACrC;;aAES,OAAO;mDAC+B,OAAO;0DACA,OAAO,qDAAqD;KACnH,CAAC;AACJ,CAAC;AAtCD,8DAsCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {NativeModuleSchema} from 'react-native-tscodegen';\nimport {AliasMap, getAnonymousAliasCppName} from './AliasManaging';\n\nexport function generateValidateConstants(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] | undefined {\n const candidates = nativeModule.spec.properties.filter(\n prop => prop.name === 'getConstants',\n );\n if (candidates.length === 0) {\n return undefined;\n }\n\n const getConstant = candidates[0];\n const funcType =\n getConstant.typeAnnotation.type === 'NullableTypeAnnotation'\n ? getConstant.typeAnnotation.typeAnnotation\n : getConstant.typeAnnotation;\n if (\n funcType.params.length > 0 ||\n funcType.returnTypeAnnotation.type !== 'ObjectTypeAnnotation'\n ) {\n return undefined;\n }\n\n const constantType = funcType.returnTypeAnnotation;\n if (constantType.properties.length === 0) {\n return undefined;\n }\n\n const cppName = getAnonymousAliasCppName(aliases, 'Constants', constantType);\n\n return [\n ` TypedConstant<${cppName}>{0},`,\n ` REACT_SHOW_CONSTANT_SPEC_ERRORS(\n 0,\n \"${cppName}\",\n \" REACT_GET_CONSTANTS(GetConstants) ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\"\n \" REACT_GET_CONSTANTS(GetConstants) static ${cppName} GetConstants() noexcept {/*implementation*/}\\\\n\");`,\n ];\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { NativeModuleSchema } from 'react-native-tscodegen';
7
+ import { AliasMap } from './AliasManaging';
8
+ export declare function generateValidateMethods(nativeModule: NativeModuleSchema, aliases: AliasMap): [string, string];
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.generateValidateMethods = void 0;
9
+ const ParamTypes_1 = require("./ParamTypes");
10
+ const ReturnTypes_1 = require("./ReturnTypes");
11
+ function isMethodSync(funcType) {
12
+ return (funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&
13
+ funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation');
14
+ }
15
+ function isMethodReturnPromise(funcType) {
16
+ return funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation';
17
+ }
18
+ function getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName) {
19
+ const args = (0, ParamTypes_1.translateArgs)(funcType.params, aliases, baseAliasName);
20
+ if (isMethodReturnPromise(funcType)) {
21
+ // TODO: type of the promise could be provided in the future
22
+ args.push('::React::ReactPromise<::React::JSValue> &&result');
23
+ }
24
+ // TODO: be much more exhastive on the possible method signatures that can be used..
25
+ const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }}`;
26
+ const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${prop.name}) static ${(0, ReturnTypes_1.translateImplReturnType)(funcType.returnTypeAnnotation, aliases, baseAliasName)} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }}`;
27
+ return [sig, staticsig];
28
+ }
29
+ function translatePossibleMethodSignatures(prop, funcType, aliases, baseAliasName) {
30
+ return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName)
31
+ .map(sig => `" ${sig}\\n"`)
32
+ .join('\n ');
33
+ }
34
+ function renderProperties(properties, aliases, tuple) {
35
+ // TODO: generate code for constants
36
+ return properties
37
+ .filter(prop => prop.name !== 'getConstants')
38
+ .map((prop, index) => {
39
+ // TODO: prop.optional === true
40
+ // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'
41
+ const propAliasName = prop.name;
42
+ const funcType = prop.typeAnnotation.type === 'NullableTypeAnnotation'
43
+ ? prop.typeAnnotation.typeAnnotation
44
+ : prop.typeAnnotation;
45
+ const traversedArgs = (0, ParamTypes_1.translateSpecArgs)(funcType.params, aliases, propAliasName);
46
+ const translatedReturnParam = (0, ReturnTypes_1.translateSpecReturnType)(funcType.returnTypeAnnotation, aliases, propAliasName);
47
+ if (isMethodReturnPromise(funcType)) {
48
+ // TODO: type of the promise could be provided in the future
49
+ traversedArgs.push('Promise<::React::JSValue>');
50
+ }
51
+ if (tuple) {
52
+ return ` ${isMethodSync(funcType) ? 'Sync' : ''}Method<${translatedReturnParam}(${traversedArgs.join(', ')}) noexcept>{${index}, L"${prop.name}"},`;
53
+ }
54
+ else {
55
+ return ` REACT_SHOW_METHOD_SPEC_ERRORS(
56
+ ${index},
57
+ "${prop.name}",
58
+ ${translatePossibleMethodSignatures(prop, funcType, aliases, propAliasName)});`;
59
+ }
60
+ })
61
+ .join('\n');
62
+ }
63
+ function generateValidateMethods(nativeModule, aliases) {
64
+ const properties = nativeModule.spec.properties;
65
+ const traversedProperties = renderProperties(properties, aliases, false);
66
+ const traversedPropertyTuples = renderProperties(properties, aliases, true);
67
+ return [traversedPropertyTuples, traversedProperties];
68
+ }
69
+ exports.generateValidateMethods = generateValidateMethods;
70
+ //# sourceMappingURL=ValidateMethods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidateMethods.js","sourceRoot":"","sources":["../../src/generators/ValidateMethods.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,6CAA8D;AAC9D,+CAA+E;AAE/E,SAAS,YAAY,CAAC,QAA4C;IAChE,OAAO,CACL,QAAQ,CAAC,oBAAoB,CAA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AAC,IAAI;YACV,iCAAiC,CACjC,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,aAAa,CACd,IAAI,CAAC;SACT;IACH,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAgC,EAChC,OAAiB;IAEjB,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;IAChD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACzE,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5E,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AARD,0DAQC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NativeModuleFunctionTypeAnnotation,\n NativeModulePropertyShape,\n NativeModuleSchema,\n} from 'react-native-tscodegen';\nimport {AliasMap} from './AliasManaging';\nimport {translateArgs, translateSpecArgs} from './ParamTypes';\nimport {translateImplReturnType, translateSpecReturnType} from './ReturnTypes';\n\nfunction isMethodSync(funcType: NativeModuleFunctionTypeAnnotation) {\n return (\n funcType.returnTypeAnnotation.type !== 'VoidTypeAnnotation' &&\n funcType.returnTypeAnnotation.type !== 'PromiseTypeAnnotation'\n );\n}\n\nfunction isMethodReturnPromise(funcType: NativeModuleFunctionTypeAnnotation) {\n return funcType.returnTypeAnnotation.type === 'PromiseTypeAnnotation';\n}\n\nfunction getPossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n): string[] {\n const args = translateArgs(funcType.params, aliases, baseAliasName);\n if (isMethodReturnPromise(funcType)) {\n // TODO: type of the promise could be provided in the future\n args.push('::React::ReactPromise<::React::JSValue> &&result');\n }\n\n // TODO: be much more exhastive on the possible method signatures that can be used..\n const sig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }}`;\n\n const staticsig = `REACT_${isMethodSync(funcType) ? 'SYNC_' : ''}METHOD(${\n prop.name\n }) static ${translateImplReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n baseAliasName,\n )} ${prop.name}(${args.join(', ')}) noexcept { /* implementation */ }}`;\n\n return [sig, staticsig];\n}\n\nfunction translatePossibleMethodSignatures(\n prop: NativeModulePropertyShape,\n funcType: NativeModuleFunctionTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n): string {\n return getPossibleMethodSignatures(prop, funcType, aliases, baseAliasName)\n .map(sig => `\" ${sig}\\\\n\"`)\n .join('\\n ');\n}\n\nfunction renderProperties(\n properties: ReadonlyArray<NativeModulePropertyShape>,\n aliases: AliasMap,\n tuple: boolean,\n): string {\n // TODO: generate code for constants\n return properties\n .filter(prop => prop.name !== 'getConstants')\n .map((prop, index) => {\n // TODO: prop.optional === true\n // TODO: prop.typeAnnotation.type === 'NullableTypeAnnotation'\n const propAliasName = prop.name;\n const funcType =\n prop.typeAnnotation.type === 'NullableTypeAnnotation'\n ? prop.typeAnnotation.typeAnnotation\n : prop.typeAnnotation;\n\n const traversedArgs = translateSpecArgs(\n funcType.params,\n aliases,\n propAliasName,\n );\n\n const translatedReturnParam = translateSpecReturnType(\n funcType.returnTypeAnnotation,\n aliases,\n propAliasName,\n );\n\n if (isMethodReturnPromise(funcType)) {\n // TODO: type of the promise could be provided in the future\n traversedArgs.push('Promise<::React::JSValue>');\n }\n\n if (tuple) {\n return ` ${\n isMethodSync(funcType) ? 'Sync' : ''\n }Method<${translatedReturnParam}(${traversedArgs.join(\n ', ',\n )}) noexcept>{${index}, L\"${prop.name}\"},`;\n } else {\n return ` REACT_SHOW_METHOD_SPEC_ERRORS(\n ${index},\n \"${prop.name}\",\n ${translatePossibleMethodSignatures(\n prop,\n funcType,\n aliases,\n propAliasName,\n )});`;\n }\n })\n .join('\\n');\n}\n\nexport function generateValidateMethods(\n nativeModule: NativeModuleSchema,\n aliases: AliasMap,\n): [string, string] {\n const properties = nativeModule.spec.properties;\n const traversedProperties = renderProperties(properties, aliases, false);\n const traversedPropertyTuples = renderProperties(properties, aliases, true);\n return [traversedPropertyTuples, traversedProperties];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/codegen",
3
- "version": "0.0.0-canary.3",
3
+ "version": "0.0.0-canary.32",
4
4
  "description": "Generators for react-native-codegen targeting react-native-windows",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/microsoft/react-native-windows",
@@ -15,33 +15,42 @@
15
15
  "watch": "rnw-scripts watch"
16
16
  },
17
17
  "bin": {
18
- "codegen": "./bin.js"
18
+ "react-native-windows-codegen": "./bin.js"
19
19
  },
20
20
  "dependencies": {
21
+ "@react-native-windows/fs": "^0.0.0-canary.3",
22
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
23
+ "@typescript-eslint/parser": "^5.20.0",
21
24
  "chalk": "^4.1.0",
22
- "globby": "^9.2.0",
25
+ "globby": "^11.0.4",
23
26
  "mustache": "^4.0.1",
24
- "react-native-tscodegen": "0.66.1",
27
+ "react-native-tscodegen": "0.68.4",
25
28
  "source-map-support": "^0.5.19",
26
- "yargs": "^15.4.1"
29
+ "yargs": "^16.2.0"
27
30
  },
28
31
  "devDependencies": {
29
- "@rnw-scripts/eslint-config": "1.1.6",
30
- "@rnw-scripts/jest-unittest-config": "1.2.0",
31
- "@rnw-scripts/just-task": "2.1.0",
32
- "@rnw-scripts/ts-config": "1.1.0",
32
+ "@rnw-scripts/eslint-config": "1.1.12",
33
+ "@rnw-scripts/jest-unittest-config": "1.2.6",
34
+ "@rnw-scripts/just-task": "2.2.3",
35
+ "@rnw-scripts/ts-config": "2.0.2",
33
36
  "@types/chalk": "^2.2.0",
34
- "@types/globby": "^9.1.0",
35
37
  "@types/jest": "^26.0.20",
36
38
  "@types/node": "^14.14.22",
37
- "@types/yargs": "15.0.5",
39
+ "@types/yargs": "16.0.0",
38
40
  "babel-jest": "^26.3.0",
39
- "eslint": "7.12.0",
40
- "jest": "^26.5.2",
41
+ "eslint": "^7.32.0",
42
+ "jest": "^26.6.3",
41
43
  "just-scripts": "^1.3.3",
42
- "prettier": "1.19.1",
43
- "typescript": "^3.8.3"
44
+ "prettier": "^2.4.1",
45
+ "typescript": "^4.4.4"
44
46
  },
47
+ "files": [
48
+ "bin.js",
49
+ "CHANGELOG.md",
50
+ "README.md",
51
+ "lib-commonjs",
52
+ "src"
53
+ ],
45
54
  "beachball": {
46
55
  "defaultNpmTag": "canary",
47
56
  "disallowedChangeTypes": [
@@ -50,5 +59,8 @@
50
59
  "patch"
51
60
  ]
52
61
  },
53
- "promoteRelease": true
62
+ "promoteRelease": true,
63
+ "engines": {
64
+ "node": ">= 14"
65
+ }
54
66
  }
package/src/Cli.ts CHANGED
@@ -5,15 +5,19 @@
5
5
  * @format
6
6
  */
7
7
 
8
- import * as yargs from 'yargs';
9
- import * as path from 'path';
10
- import * as fs from 'fs';
11
- import * as globby from 'globby';
8
+ import yargs from 'yargs';
9
+ import path from 'path';
10
+ import fs from '@react-native-windows/fs';
11
+ import globby from 'globby';
12
12
  import {createNM2Generator} from './generators/GenerateNM2';
13
+ import {
14
+ generateTypeScript,
15
+ setOptionalTurboModule,
16
+ } from './generators/GenerateTypeScript';
13
17
  // @ts-ignore
14
18
  import {parseFile} from 'react-native-tscodegen/lib/rncodegen/src/parsers/flow';
15
19
  // @ts-ignore
16
- import * as schemaValidator from 'react-native-tscodegen/lib/rncodegen/src/schemaValidator';
20
+ import schemaValidator from 'react-native-tscodegen/lib/rncodegen/src/schemaValidator';
17
21
 
18
22
  const argv = yargs.options({
19
23
  file: {
@@ -24,6 +28,16 @@ const argv = yargs.options({
24
28
  type: 'array',
25
29
  describe: 'glob patterns for files which contains specs',
26
30
  },
31
+ ts: {
32
+ type: 'boolean',
33
+ describe: 'generate turbo module definition files in TypeScript',
34
+ default: false,
35
+ },
36
+ outdir: {
37
+ type: 'string',
38
+ describe: 'output directory',
39
+ default: 'codegen',
40
+ },
27
41
  test: {
28
42
  type: 'boolean',
29
43
  describe: 'Verify that the generated output is unchanged',
@@ -33,6 +47,11 @@ const argv = yargs.options({
33
47
  describe: 'C++/C# Namespace to put generated native modules in',
34
48
  default: 'MyNamespace',
35
49
  },
50
+ libraryName: {
51
+ type: 'string',
52
+ required: true,
53
+ describe: 'Used for part of the path generated within the codegen dir',
54
+ },
36
55
  }).argv;
37
56
 
38
57
  import {SchemaType} from 'react-native-tscodegen';
@@ -74,20 +93,42 @@ const GENERATORS = {
74
93
  };
75
94
  */
76
95
 
96
+ function normalizeFileMap(
97
+ map: Map<string, string>,
98
+ outputDir: string,
99
+ outMap: Map<string, string>,
100
+ ): void {
101
+ for (const [fileName, contents] of map) {
102
+ const location = path.join(outputDir, fileName);
103
+ outMap.set(path.normalize(location), contents);
104
+ }
105
+ }
106
+
77
107
  function checkFilesForChanges(
78
108
  map: Map<string, string>,
79
109
  outputDir: string,
80
110
  ): boolean {
81
111
  let hasChanges = false;
82
112
 
83
- for (const [contents, fileName] of map) {
84
- const location = path.join(outputDir, fileName);
85
- if (!fs.existsSync(location)) {
113
+ const allExistingFiles = globby
114
+ .sync(`${outputDir}/**`)
115
+ .map(_ => path.normalize(_))
116
+ .sort();
117
+ const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();
118
+
119
+ if (
120
+ allExistingFiles.length !== allGeneratedFiles.length ||
121
+ !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])
122
+ )
123
+ return true;
124
+
125
+ for (const [fileName, contents] of map) {
126
+ if (!fs.existsSync(fileName)) {
86
127
  hasChanges = true;
87
128
  continue;
88
129
  }
89
130
 
90
- const currentContents = fs.readFileSync(location, 'utf8');
131
+ const currentContents = fs.readFileSync(fileName, 'utf8');
91
132
  if (currentContents !== contents) {
92
133
  console.error(`- ${fileName} has changed`);
93
134
  hasChanges = true;
@@ -100,20 +141,65 @@ function checkFilesForChanges(
100
141
 
101
142
  function writeMapToFiles(map: Map<string, string>, outputDir: string) {
102
143
  let success = true;
103
- map.forEach((contents: string, fileName: string) => {
144
+
145
+ // This ensures that we delete any generated files from modules that have been deleted
146
+ const allExistingFiles = globby.sync(`${outputDir}/**`);
147
+ allExistingFiles.forEach(existingFile => {
148
+ if (!map.has(path.normalize(existingFile))) {
149
+ fs.unlinkSync(existingFile);
150
+ }
151
+ });
152
+
153
+ for (const [fileName, contents] of map) {
104
154
  try {
105
- const location = path.join(outputDir, fileName);
106
- fs.mkdirSync(path.dirname(location), {recursive: true});
107
- fs.writeFileSync(location, contents);
155
+ fs.mkdirSync(path.dirname(fileName), {recursive: true});
156
+
157
+ if (fs.existsSync(fileName)) {
158
+ const currentContents = fs.readFileSync(fileName, 'utf8');
159
+ // Don't update the files if there are no changes as this breaks incremental builds
160
+ if (currentContents === contents) {
161
+ continue;
162
+ }
163
+ }
164
+
165
+ fs.writeFileSync(fileName, contents);
108
166
  } catch (error) {
109
167
  success = false;
110
- console.error(`Failed to write ${fileName} to ${outputDir}`, error);
168
+ console.error(`Failed to write ${fileName} to ${fileName}`, error);
111
169
  }
112
- });
170
+ }
113
171
 
114
172
  return success;
115
173
  }
116
174
 
175
+ function parseFlowFile(filename: string): SchemaType {
176
+ try {
177
+ const schema = parseFile(filename);
178
+ // there will be at most one turbo module per file
179
+ const moduleName = Object.keys(schema.modules)[0];
180
+ if (moduleName) {
181
+ const spec = schema.modules[moduleName];
182
+ if (spec.type === 'NativeModule') {
183
+ const contents = fs.readFileSync(filename, 'utf8');
184
+ if (contents) {
185
+ // This is a temporary implementation until such information is added to the schema in facebook/react-native
186
+ if (contents.includes('TurboModuleRegistry.get<')) {
187
+ setOptionalTurboModule(spec, true);
188
+ } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {
189
+ setOptionalTurboModule(spec, false);
190
+ }
191
+ }
192
+ }
193
+ }
194
+ return schema;
195
+ } catch (e) {
196
+ if (e instanceof Error) {
197
+ e.message = `(${filename}): ${e.message}`;
198
+ }
199
+ throw e;
200
+ }
201
+ }
202
+
117
203
  function combineSchemas(files: string[]): SchemaType {
118
204
  return files.reduce(
119
205
  (merged, filename) => {
@@ -123,11 +209,8 @@ function combineSchemas(files: string[]): SchemaType {
123
209
  (/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
124
210
  contents.includes('extends TurboModule'))
125
211
  ) {
126
- const schema = parseFile(filename);
127
-
128
- if (schema && schema.modules) {
129
- merged.modules = {...merged.modules, ...schema.modules};
130
- }
212
+ const schema = parseFlowFile(filename);
213
+ merged.modules = {...merged.modules, ...schema.modules};
131
214
  }
132
215
  return merged;
133
216
  },
@@ -141,26 +224,80 @@ function generate(
141
224
  ): boolean {
142
225
  schemaValidator.validate(schema);
143
226
 
144
- const generatedFiles = [];
145
- /*
146
- for (const name of generators) {
147
- for (const generator of GENERATORS[name]) {
148
- generatedFiles.push(...generator(libraryName, schema, moduleSpecName));
149
- }
150
- }
151
- */
227
+ const componentOutputdir = path.join(
228
+ outputDirectory,
229
+ 'react/components',
230
+ libraryName,
231
+ );
232
+
233
+ const generatedFiles = new Map<string, string>();
234
+
235
+ generatedFiles.set(
236
+ path.join(outputDirectory, '.clang-format'),
237
+ 'DisableFormat: true\nSortIncludes: false',
238
+ );
152
239
 
153
240
  const generateNM2 = createNM2Generator({namespace: argv.namespace});
154
241
 
155
- generatedFiles.push(...generateNM2(libraryName, schema, moduleSpecName));
242
+ const generatorPropsH =
243
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;
244
+ const generatorPropsCPP =
245
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;
246
+ const generatorShadowNodeH =
247
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;
248
+ const generatorShadowNodeCPP =
249
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;
250
+ const generatorComponentDescriptorH =
251
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;
252
+ const generatorEventEmitterH =
253
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;
254
+ const generatorEventEmitterCPP =
255
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;
156
256
 
157
- const filesToUpdate = new Map<string, string>([...generatedFiles]);
257
+ normalizeFileMap(
258
+ generateNM2(libraryName, schema, moduleSpecName),
259
+ outputDirectory,
260
+ generatedFiles,
261
+ );
262
+
263
+ if (argv.ts) {
264
+ normalizeFileMap(
265
+ generateTypeScript(libraryName, schema, moduleSpecName),
266
+ outputDirectory,
267
+ generatedFiles,
268
+ );
269
+ }
270
+
271
+ if (
272
+ Object.keys(schema.modules).some(
273
+ moduleName => schema.modules[moduleName].type === 'Component',
274
+ )
275
+ ) {
276
+ const componentGenerators = [
277
+ generatorPropsH,
278
+ generatorPropsCPP,
279
+ generatorShadowNodeH,
280
+ generatorShadowNodeCPP,
281
+ generatorComponentDescriptorH,
282
+ generatorEventEmitterH,
283
+ generatorEventEmitterCPP,
284
+ ];
285
+
286
+ componentGenerators.forEach(generator => {
287
+ const generated: Map<string, string> = generator(
288
+ libraryName,
289
+ schema,
290
+ moduleSpecName,
291
+ );
292
+ normalizeFileMap(generated, componentOutputdir, generatedFiles);
293
+ });
294
+ }
158
295
 
159
296
  if (test === true) {
160
- return checkFilesForChanges(filesToUpdate, outputDirectory);
297
+ return checkFilesForChanges(generatedFiles, outputDirectory);
161
298
  }
162
299
 
163
- return writeMapToFiles(filesToUpdate, outputDirectory);
300
+ return writeMapToFiles(generatedFiles, outputDirectory);
164
301
  }
165
302
 
166
303
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
@@ -170,14 +307,14 @@ if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
170
307
 
171
308
  let schema: SchemaType;
172
309
  if (argv.file) {
173
- schema = parseFile(argv.file);
310
+ schema = parseFlowFile(argv.file);
174
311
  } else {
175
312
  schema = combineSchemas(globby.sync(argv.files as string[]));
176
313
  }
177
314
 
178
- const libraryName = 'libraryName';
315
+ const libraryName = argv.libraryName;
179
316
  const moduleSpecName = 'moduleSpecName';
180
- const outputDirectory = 'codegen';
317
+ const outputDirectory = argv.outdir;
181
318
  generate(
182
319
  {libraryName, schema, outputDirectory, moduleSpecName},
183
320
  {generators: [], test: false},