@react-native-windows/codegen 0.0.0-canary.67 → 0.0.0-canary.69

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/CHANGELOG.md CHANGED
@@ -1,17 +1,34 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Tue, 08 Aug 2023 05:12:09 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 20 Sep 2023 05:16:07 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.0.0-canary.67
7
+ ## 0.0.0-canary.69
8
8
 
9
- Tue, 08 Aug 2023 05:12:09 GMT
9
+ Wed, 20 Sep 2023 05:16:07 GMT
10
10
 
11
11
  ### Changes
12
12
 
13
- - @rnw/codegen generates GetStructInfo instead of REACT_STRUCT (53799235+ZihanChen-MSFT@users.noreply.github.com)
13
+ - Bump @react-native-windows/fs to v0.0.0-canary.28
14
+ - Bump @rnw-scripts/just-task to v2.3.16
14
15
 
16
+ ## 0.0.0-canary.68
17
+
18
+ Tue, 15 Aug 2023 05:14:09 GMT
19
+
20
+ ### Changes
21
+
22
+ - Add `separateDataFiles` to @rnw/cli and @rnw/codegen (53799235+ZihanChen-MSFT@users.noreply.github.com)
23
+
24
+ ## 0.0.0-canary.67
25
+
26
+ Tue, 08 Aug 2023 05:13:00 GMT
27
+
28
+ ### Changes
29
+
30
+ - @rnw/codegen generates GetStructInfo instead of REACT_STRUCT (53799235+ZihanChen-MSFT@users.noreply.github.com)
31
+
15
32
  ## 0.0.0-canary.66
16
33
 
17
34
  Fri, 28 Jul 2023 05:14:53 GMT
@@ -66,6 +66,11 @@ const argv = yargs_1.default.options({
66
66
  describe: 'C++ string type in generated code, should be "std::string" or "std::wstring"',
67
67
  default: 'std::string',
68
68
  },
69
+ separateDataTypes: {
70
+ type: 'boolean',
71
+ describe: 'generate data types in a separate file',
72
+ default: false,
73
+ },
69
74
  }).argv;
70
75
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
71
76
  console.error('You must specify either --file or --files.');
@@ -1 +1 @@
1
- {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,0BAA0B;KACrC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,0CAA0C;QACpD,OAAO,EAAE,KAAK;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,mDAAmD;QAC7D,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,wDAAwD;QAClE,OAAO,EAAE,KAAK;KACf;IACD,eAAe,EAAE;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,SAAS;KACnB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,+CAA+C;QACzD,OAAO,EAAE,KAAK;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,qDAAqD;QAC/D,OAAO,EAAE,aAAa;KACvB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,4DAA4D;KACvE;IACD,aAAa,EAAE;QACb,OAAO,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC;QACxC,QAAQ,EACN,8EAA8E;QAChF,OAAO,EAAE,aAAa;KACvB;CACF,CAAC,CAAC,IAAI,CAAC;AAER,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;IAC5D,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,IACE,IAAI,CAAC,aAAa,KAAK,aAAa;IACpC,IAAI,CAAC,aAAa,KAAK,cAAc,EACrC;IACA,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,yCAAyC;AACzC,yDAAyD;AACzD,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,IAAA,kBAAU,EAAiB,IAAI,CAAC,CAAC;AAE1D,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,kGAAkG,CACnG,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, runCodeGen} from './index';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'string',\n array: true,\n describe: 'glob patterns for files which contains specs',\n },\n modulesTypeScriptTypes: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n modulesCxx: {\n type: 'boolean',\n describe: 'generate C++ JSI turbo module spec files',\n default: false,\n },\n modulesWindows: {\n type: 'boolean',\n describe: 'generate turbo module spec files for REACT_MODULE',\n default: false,\n },\n methodOnly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\n default: false,\n },\n outputDirectory: {\n type: 'string',\n describe: 'output directory',\n default: 'codegen',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\n default: false,\n },\n namespace: {\n type: 'string',\n describe: 'C++/C# Namespace to put generated native modules in',\n default: 'MyNamespace',\n },\n libraryName: {\n type: 'string',\n required: true,\n describe: 'Used for part of the path generated within the codegen dir',\n },\n cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\n },\n}).argv;\n\nif ((argv.file && argv.files) || (!argv.file && !argv.files)) {\n console.error('You must specify either --file or --files.');\n process.exit(1);\n}\n\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"react-native codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,0BAA0B;KACrC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EA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OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,yCAAyC;AACzC,yDAAyD;AACzD,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,IAAA,kBAAU,EAAiB,IAAI,CAAC,CAAC;AAE1D,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,kGAAkG,CACnG,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, runCodeGen} from './index';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'string',\n array: true,\n describe: 'glob patterns for files which contains specs',\n },\n modulesTypeScriptTypes: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n modulesCxx: {\n type: 'boolean',\n describe: 'generate C++ JSI turbo module spec files',\n default: false,\n },\n modulesWindows: {\n type: 'boolean',\n describe: 'generate turbo module spec files for REACT_MODULE',\n default: false,\n },\n methodOnly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\n default: false,\n },\n outputDirectory: {\n type: 'string',\n describe: 'output directory',\n default: 'codegen',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\n default: false,\n },\n namespace: {\n type: 'string',\n describe: 'C++/C# Namespace to put generated native modules in',\n default: 'MyNamespace',\n },\n libraryName: {\n type: 'string',\n required: true,\n describe: 'Used for part of the path generated within the codegen dir',\n },\n cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\n },\n separateDataTypes: {\n type: 'boolean',\n describe: 'generate data types in a separate file',\n default: false,\n },\n}).argv;\n\nif ((argv.file && argv.files) || (!argv.file && !argv.files)) {\n console.error('You must specify either --file or --files.');\n process.exit(1);\n}\n\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"react-native codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
@@ -7,8 +7,9 @@ import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
7
  import type { CppStringTypes } from './ObjectTypes';
8
8
  export type { CppStringTypes } from './ObjectTypes';
9
9
  type FilesOutput = Map<string, string>;
10
- export declare function createNM2Generator({ methodOnly, namespace, cppStringType, }: {
10
+ export declare function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }: {
11
11
  methodOnly: boolean;
12
12
  namespace: string;
13
13
  cppStringType: CppStringTypes;
14
+ separateDataTypes: boolean;
14
15
  }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
@@ -10,22 +10,15 @@ const AliasManaging_1 = require("./AliasManaging");
10
10
  const AliasGen_1 = require("./AliasGen");
11
11
  const ValidateConstants_1 = require("./ValidateConstants");
12
12
  const ValidateMethods_1 = require("./ValidateMethods");
13
- const moduleTemplate = `
14
- /*
13
+ const headerTemplate = `/*
15
14
  * This file is auto-generated from a NativeModule spec file in js.
16
15
  *
17
16
  * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
18
17
  * in a way that also verifies at compile time that the native module matches the interface required
19
18
  * by the TurboModule JS spec.
20
19
  */
21
- #pragma once
22
-
23
- #include <NativeModules.h>
24
- #include <tuple>
25
-
26
- namespace ::_NAMESPACE_:: {
27
- ::_MODULE_CUSTPM_TYPES_::
28
- ::_MODULE_CUSTPM_TYPES_REFLECTION_::
20
+ #pragma once`;
21
+ const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
29
22
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
30
23
  ::_MODULE_MEMBERS_TUPLES_::
31
24
 
@@ -34,12 +27,46 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
34
27
  ::_MODULE_MEMBERS_CHECKS_::
35
28
 
36
29
  ::_MODULE_MEMBERS_ERRORS_::
37
- }
30
+ }`;
31
+ const typeOnlyTemplate = `
32
+ ${headerTemplate}
33
+
34
+ #include <string>
35
+ #include <optional>
36
+ #include <functional>
37
+ #include <vector>
38
+
39
+ namespace ::_NAMESPACE_:: {
40
+ ::_MODULE_CUSTPM_TYPES_::
41
+ } // namespace ::_NAMESPACE_::
42
+ `;
43
+ const moduleOnlyTemplate = `
44
+ ${headerTemplate}
45
+
46
+ ::_TYPE_DEFINITION_INCLUDE_::
47
+ #include <NativeModules.h>
48
+ #include <tuple>
49
+
50
+ namespace ::_NAMESPACE_:: {
51
+ ${specTemplate}
52
+ };
53
+
54
+ } // namespace ::_NAMESPACE_::
55
+ `;
56
+ const allInOneTemplate = `
57
+ ${headerTemplate}
58
+
59
+ #include <NativeModules.h>
60
+ #include <tuple>
61
+
62
+ namespace ::_NAMESPACE_:: {
63
+ ::_MODULE_CUSTPM_TYPES_::
64
+ ${specTemplate}
38
65
  };
39
66
 
40
67
  } // namespace ::_NAMESPACE_::
41
68
  `;
42
- function createNM2Generator({ methodOnly, namespace, cppStringType, }) {
69
+ function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }) {
43
70
  return (_libraryName, schema, _moduleSpecName) => {
44
71
  const files = new Map();
45
72
  for (const moduleName of Object.keys(schema.modules)) {
@@ -83,14 +110,29 @@ ${errors}`;
83
110
  const [customTypes, customReflection] = (0, AliasGen_1.generateAliases)(aliases, {
84
111
  cppStringType,
85
112
  });
86
- files.set(`Native${preferredModuleName}Spec.g.h`, moduleTemplate
87
- .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
88
- .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
89
- .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
90
- .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
91
- .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
92
- .replace(/::_MODULE_NAME_::/g, preferredModuleName)
93
- .replace(/::_NAMESPACE_::/g, namespace));
113
+ const customTypesExist = customTypes !== '';
114
+ const replaceContent = function (template) {
115
+ return template
116
+ .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
117
+ .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
118
+ .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
119
+ .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
120
+ .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
121
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
122
+ .replace(/::_TYPE_DEFINITION_INCLUDE_::/g, customTypesExist
123
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
124
+ : '')
125
+ .replace(/::_NAMESPACE_::/g, namespace);
126
+ };
127
+ if (separateDataTypes) {
128
+ if (customTypesExist) {
129
+ files.set(`Native${preferredModuleName}DataTypes.g.h`, replaceContent(typeOnlyTemplate));
130
+ }
131
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(moduleOnlyTemplate));
132
+ }
133
+ else {
134
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(allInOneTemplate));
135
+ }
94
136
  }
95
137
  }
96
138
  return files;
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,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SAAS,GAAG,IAAA,6CAAyB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;gBACnE,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,UAAU,EAAE;oBAC1C,MAAM,GAAG;;EAEjB,SAAS,CAAC,CAAC,CAAC;MACR,MAAM,EAAE,CAAC;oBACL,MAAM,GAAG;6FAC0E,MAAM,EAAE,CAAC;oBAC5F,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC;;EAEhC,MAAM,EAAE,CAAC;iBACF;gBAED,4BAA4B;gBAC5B,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,IAAA,0BAAe,EAAC,OAAO,EAAE;oBAC/D,aAAa;iBACd,CAAC,CAAC;gBAEH,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc;qBACX,OAAO,CAAC,4BAA4B,EAAE,WAAW,CAAC;qBAClD,OAAO,CAAC,uCAAuC,EAAE,gBAAgB,CAAC;qBAClE,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;qBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;qBAC5D,OAAO,CAAC,8BAA8B,EAAE,MAAM,CAAC;qBAC/C,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;qBAClD,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAC1C,CAAC;aACH;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AA/ED,gDA+EC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\nimport type {CppStringTypes} from './ObjectTypes';\n\nexport type {CppStringTypes} from './ObjectTypes';\n\ntype FilesOutput = Map<string, string>;\n\nconst moduleTemplate = `\n/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules\n * in a way that also verifies at compile time that the native module matches the interface required\n * by the TurboModule JS spec.\n */\n#pragma once\n\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n::_MODULE_CUSTPM_TYPES_REFLECTION_::\nstruct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {\n::_MODULE_MEMBERS_TUPLES_::\n\n template <class TModule>\n static constexpr void ValidateModule() noexcept {\n::_MODULE_MEMBERS_CHECKS_::\n\n::_MODULE_MEMBERS_ERRORS_::\n }\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n}: {\n methodOnly: boolean;\n namespace: string;\n cppStringType: CppStringTypes;\n}) {\n return (\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n ): FilesOutput => {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const preferredModuleName = moduleName.startsWith('Native')\n ? moduleName.substr(6)\n : moduleName;\n setPreferredModuleName(preferredModuleName);\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating Native${preferredModuleName}Spec.g.h`);\n\n // copy all explicit to a map\n const aliases: AliasMap = createAliasMap(nativeModule.aliasMap);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases, {\n cppStringType,\n });\n let tuples = `\n static constexpr auto methods = std::tuple{\n${methods[0]}\n };`;\n let checks = `\n constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;\n let errors = methods[1];\n\n // prepare constants\n const constants = generateValidateConstants(nativeModule, aliases);\n if (constants !== undefined && !methodOnly) {\n tuples = `\n static constexpr auto constants = std::tuple{\n${constants[0]}\n };${tuples}`;\n checks = `\n constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;\n errors = `${constants[1]}\n\n${errors}`;\n }\n\n // generate code for structs\n const [customTypes, customReflection] = generateAliases(aliases, {\n cppStringType,\n });\n\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n moduleTemplate\n .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)\n .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)\n .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))\n .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))\n .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(/::_NAMESPACE_::/g, namespace),\n );\n }\n }\n\n return files;\n };\n}\n"]}
1
+ {"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAGb,mDAAiE;AACjE,yCAA2D;AAC3D,2DAA8D;AAC9D,uDAA0D;AAO1D,MAAM,cAAc,GAAG;;;;;;;aAOV,CAAC;AAEd,MAAM,YAAY,GAAG;;;;;;;;;IASjB,CAAC;AAEL,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;;;;CAUf,CAAC;AAEF,MAAM,kBAAkB,GAAG;EACzB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,MAAM,gBAAgB,GAAG;EACvB,cAAc;;;;;;;EAOd,YAAY;;;;CAIb,CAAC;AAEF,SAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,SAAS,EACT,aAAa,EACb,iBAAiB,GAMlB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,CAAC;iBACH;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AA1GD,gDA0GC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\nimport type {CppStringTypes} from './ObjectTypes';\n\nexport type {CppStringTypes} from './ObjectTypes';\n\ntype FilesOutput = Map<string, string>;\n\nconst headerTemplate = `/*\n * This file is auto-generated from a NativeModule spec file in js.\n *\n * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules\n * in a way that also verifies at compile time that the native module matches the interface required\n * by the TurboModule JS spec.\n */\n#pragma once`;\n\nconst specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::\nstruct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {\n::_MODULE_MEMBERS_TUPLES_::\n\n template <class TModule>\n static constexpr void ValidateModule() noexcept {\n::_MODULE_MEMBERS_CHECKS_::\n\n::_MODULE_MEMBERS_ERRORS_::\n }`;\n\nconst typeOnlyTemplate = `\n${headerTemplate}\n\n#include <string>\n#include <optional>\n#include <functional>\n#include <vector>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n} // namespace ::_NAMESPACE_::\n`;\n\nconst moduleOnlyTemplate = `\n${headerTemplate}\n\n::_TYPE_DEFINITION_INCLUDE_::\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nconst allInOneTemplate = `\n${headerTemplate}\n\n#include <NativeModules.h>\n#include <tuple>\n\nnamespace ::_NAMESPACE_:: {\n::_MODULE_CUSTPM_TYPES_::\n${specTemplate}\n};\n\n} // namespace ::_NAMESPACE_::\n`;\n\nexport function createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n}: {\n methodOnly: boolean;\n namespace: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}) {\n return (\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n ): FilesOutput => {\n const files = new Map<string, string>();\n\n for (const moduleName of Object.keys(schema.modules)) {\n const nativeModule = schema.modules[moduleName];\n // from 0.65 facebook's react-native-codegen\n // the module name has the Native prefix comparing to 0.63\n // when reading files we provided\n const preferredModuleName = moduleName.startsWith('Native')\n ? moduleName.substr(6)\n : moduleName;\n setPreferredModuleName(preferredModuleName);\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating Native${preferredModuleName}Spec.g.h`);\n\n // copy all explicit to a map\n const aliases: AliasMap = createAliasMap(nativeModule.aliasMap);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases, {\n cppStringType,\n });\n let tuples = `\n static constexpr auto methods = std::tuple{\n${methods[0]}\n };`;\n let checks = `\n constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;\n let errors = methods[1];\n\n // prepare constants\n const constants = generateValidateConstants(nativeModule, aliases);\n if (constants !== undefined && !methodOnly) {\n tuples = `\n static constexpr auto constants = std::tuple{\n${constants[0]}\n };${tuples}`;\n checks = `\n constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;\n errors = `${constants[1]}\n\n${errors}`;\n }\n\n // generate code for structs\n const [customTypes, customReflection] = generateAliases(aliases, {\n cppStringType,\n });\n\n const customTypesExist = customTypes !== '';\n\n const replaceContent = function (template: string): string {\n return template\n .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)\n .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)\n .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))\n .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))\n .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_TYPE_DEFINITION_INCLUDE_::/g,\n customTypesExist\n ? `// #include \"Native${preferredModuleName}DataTypes.g.h\" before this file to use the generated type definition`\n : '',\n )\n .replace(/::_NAMESPACE_::/g, namespace);\n };\n\n if (separateDataTypes) {\n if (customTypesExist) {\n files.set(\n `Native${preferredModuleName}DataTypes.g.h`,\n replaceContent(typeOnlyTemplate),\n );\n }\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(moduleOnlyTemplate),\n );\n } else {\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n replaceContent(allInOneTemplate),\n );\n }\n }\n }\n\n return files;\n };\n}\n"]}
@@ -16,6 +16,7 @@ export interface SharedOptions {
16
16
  namespace: string;
17
17
  outputDirectory: string;
18
18
  cppStringType: CppStringTypes;
19
+ separateDataTypes: boolean;
19
20
  }
20
21
  interface Options extends SharedOptions {
21
22
  moduleSpecName: string;
@@ -27,7 +28,7 @@ interface Config {
27
28
  }
28
29
  export declare function parseFile(filename: string): SchemaType;
29
30
  export declare function combineSchemas(files: string[]): SchemaType;
30
- export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
31
+ export declare function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }: Options, { /*generators,*/ test }: Config): boolean;
31
32
  export interface CodeGenOptions extends SharedOptions {
32
33
  file?: string;
33
34
  files?: string[];
@@ -137,7 +137,7 @@ function combineSchemas(files) {
137
137
  }, { modules: {} });
138
138
  }
139
139
  exports.combineSchemas = combineSchemas;
140
- function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, moduleSpecName, schema, }, { /*generators,*/ test }) {
140
+ function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, moduleSpecName, schema, }, { /*generators,*/ test }) {
141
141
  schemaValidator.validate(schema);
142
142
  const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
143
143
  const generatedFiles = new Map();
@@ -146,6 +146,7 @@ function generate({ libraryName, methodOnly, modulesCxx, modulesTypeScriptTypes,
146
146
  methodOnly,
147
147
  namespace,
148
148
  cppStringType,
149
+ separateDataTypes,
149
150
  });
150
151
  const generateJsiModuleH = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleH')).generate;
151
152
  const generateJsiModuleCpp = require(path_1.default.resolve(rncodegenPath, 'lib/generators/modules/GenerateModuleCpp')).generate;
@@ -204,7 +205,7 @@ function runCodeGen(options) {
204
205
  : combineSchemas(globby_1.default.sync(options.files));
205
206
  const libraryName = options.libraryName;
206
207
  const moduleSpecName = 'moduleSpecName';
207
- const { methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, } = options;
208
+ const { methodOnly, modulesCxx, modulesTypeScriptTypes, modulesWindows, namespace, outputDirectory, cppStringType, separateDataTypes, } = options;
208
209
  return generate({
209
210
  libraryName,
210
211
  methodOnly,
@@ -214,6 +215,7 @@ function runCodeGen(options) {
214
215
  namespace,
215
216
  outputDirectory,
216
217
  cppStringType,
218
+ separateDataTypes,
217
219
  moduleSpecName,
218
220
  schema,
219
221
  }, { generators: [], test: options.test });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAE5B,0DAA4D;AAC5D,wEAGyC;AAMzC,+CAA+C;AAC/C,MAAM,MAAM,GAAG,c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CAAC,CAAC;KACJ;IAED,IAAI,IAAI,KAAK,IAAI,EAAE;QACjB,OAAO,oBAAoB,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;KAC9D;IAED,OAAO,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAC1D,CAAC;AAzID,4BAyIC;AAQD,SAAgB,UAAU,CAAC,OAAuB;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;QACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI;QACzB,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAC,CAAC;IAEhD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,cAAc,EACd,SAAS,EACT,eAAe,EACf,aAAa,GACd,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,aAAa;QACb,cAAc;QACd,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AAlCD,gCAkCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport type {CppStringTypes} from './generators/GenerateNM2';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport type {Parser} from '@react-native/codegen/lib/parsers/parser';\n\nexport type {CppStringTypes} from './generators/GenerateNM2';\n\n// Load @react-native/codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}),\n);\n\nfunction getParser(isTypeScript: boolean): Parser {\n if (isTypeScript) {\n const fp = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript/parser',\n ));\n return new fp.TypeScriptParser();\n } else {\n const fp = require(path.resolve(rncodegenPath, 'lib/parsers/flow/parser'));\n return new fp.FlowParser();\n }\n}\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/SchemaValidator',\n));\n\nexport interface SharedOptions {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n cppStringType: CppStringTypes;\n}\n\ninterface Options extends SharedOptions {\n moduleSpecName: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n const allExistingFiles = globby\n .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], {absolute: true})\n .map(_ => path.normalize(_));\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allGeneratedFiles.every(filepath =>\n allExistingFiles.includes(\n path.normalize(path.resolve(process.cwd(), filepath)),\n ),\n )\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(\n [`${globbyDir}/**`, `${globbyDir}/**/.*`],\n {absolute: true},\n );\n\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n allExistingFiles.forEach(existingFile => {\n if (!allGeneratedFiles.includes(path.normalize(existingFile))) {\n console.log('Deleting ', existingFile);\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n console.log('Writing ', fileName);\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n const contents = fs.readFileSync(filename, 'utf8');\n const schema = getParser(isTypeScript).parseString(contents, filename);\n // there will be at most one turbo module per file\n const moduleName = Object.keys(schema.modules)[0];\n if (moduleName) {\n const spec = schema.modules[moduleName];\n if (spec.type === 'NativeModule') {\n if (contents) {\n // This is a temporary implementation until such information is added to the schema in facebook/react-native\n if (contents.includes('TurboModuleRegistry.get<')) {\n setOptionalTurboModule(spec, true);\n } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {\n setOptionalTurboModule(spec, false);\n }\n }\n }\n }\n return schema;\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nexport function combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n moduleSpecName,\n schema,\n }: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n const generateJsiModuleCpp = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleCpp',\n )).generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCPP',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCPP',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n const generatorStateCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateCpp',\n )).generate;\n const generatorStateH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateH',\n )).generate;\n\n const moduleGenerators = [];\n\n if (modulesWindows) {\n moduleGenerators.push(generateNM2);\n }\n\n if (modulesCxx) {\n moduleGenerators.push(generateJsiModuleH);\n moduleGenerators.push(generateJsiModuleCpp);\n }\n\n if (modulesTypeScriptTypes) {\n moduleGenerators.push(generateTypeScript);\n }\n\n moduleGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, outputDirectory, generatedFiles);\n });\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorComponentDescriptorH,\n generatorEventEmitterCPP,\n generatorEventEmitterH,\n generatorPropsCPP,\n generatorPropsH,\n generatorShadowNodeCPP,\n generatorShadowNodeH,\n generatorStateCPP,\n generatorStateH,\n ];\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n }\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\n\nexport interface CodeGenOptions extends SharedOptions {\n file?: string;\n files?: string[];\n test: boolean;\n}\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n moduleSpecName,\n schema,\n },\n {generators: [], test: options.test},\n );\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAE5B,0DAA4D;AAC5D,wEAGyC;AAMzC,+CAA+C;AAC/C,MAAM,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAC1E,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,oCAAoC,EAAE,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,CACzE,CAAC;AAEF,SAAS,SAAS,CAAC,YAAqB;IACtC,IAAI,YAAY,EAAE;QAChB,MAAM,EAAE,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAC7B,aAAa,EACb,+BAA+B,CAChC,CAAC,CAAC;QACH,OAAO,IAAI,EAAE,CAAC,gBAAgB,EAAE,CAAC;KAClC;SAAM;QACL,MAAM,EAAE,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC;QAC3E,OAAO,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC;KAC5B;AACH,CAAC;AAED,MAAM,eAAe,GAAG,OAAO,CAAC,cAAI,CAAC,OAAO,CAC1C,aAAa,EACb,qBAAqB,CACtB,CAAC,CAAC;AAwBH,SAAS,gBAAgB,CACvB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ACT,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,GAAG,OAAO,CAAC;IACZ,OAAO,QAAQ,CACb;QACE,WAAW;QACX,UAAU;QACV,UAAU;QACV,sBAAsB;QACtB,cAAc;QACd,SAAS;QACT,eAAe;QACf,aAAa;QACb,iBAAiB;QACjB,cAAc;QACd,MAAM;KACP,EACD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CACrC,CAAC;AACJ,CAAC;AApCD,gCAoCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport type {CppStringTypes} from './generators/GenerateNM2';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\nimport type {SchemaType} from '@react-native/codegen/lib/CodegenSchema';\nimport type {Parser} from '@react-native/codegen/lib/parsers/parser';\n\nexport type {CppStringTypes} from './generators/GenerateNM2';\n\n// Load @react-native/codegen from react-native\nconst rnPath = path.dirname(require.resolve('react-native/package.json'));\nconst rncodegenPath = path.dirname(\n require.resolve('@react-native/codegen/package.json', {paths: [rnPath]}),\n);\n\nfunction getParser(isTypeScript: boolean): Parser {\n if (isTypeScript) {\n const fp = require(path.resolve(\n rncodegenPath,\n 'lib/parsers/typescript/parser',\n ));\n return new fp.TypeScriptParser();\n } else {\n const fp = require(path.resolve(rncodegenPath, 'lib/parsers/flow/parser'));\n return new fp.FlowParser();\n }\n}\n\nconst schemaValidator = require(path.resolve(\n rncodegenPath,\n 'lib/SchemaValidator',\n));\n\nexport interface SharedOptions {\n libraryName: string;\n methodOnly: boolean;\n modulesCxx: boolean;\n modulesTypeScriptTypes: boolean;\n modulesWindows: boolean;\n namespace: string;\n outputDirectory: string;\n cppStringType: CppStringTypes;\n separateDataTypes: boolean;\n}\n\ninterface Options extends SharedOptions {\n moduleSpecName: string;\n schema: SchemaType;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\nfunction normalizeFileMap(\n map: Map<string, string>,\n outputDir: string,\n outMap: Map<string, string>,\n): void {\n for (const [fileName, contents] of map) {\n const location = path.join(outputDir, fileName);\n outMap.set(path.normalize(location), contents);\n }\n}\n\nfunction checkFilesForChanges(\n map: Map<string, string>,\n outputDir: string,\n): boolean {\n let hasChanges = false;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n const allExistingFiles = globby\n .sync([`${globbyDir}/**`, `${globbyDir}/**/.*`], {absolute: true})\n .map(_ => path.normalize(_));\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allGeneratedFiles.every(filepath =>\n allExistingFiles.includes(\n path.normalize(path.resolve(process.cwd(), filepath)),\n ),\n )\n )\n return true;\n\n for (const [fileName, contents] of map) {\n if (!fs.existsSync(fileName)) {\n hasChanges = true;\n continue;\n }\n\n const currentContents = fs.readFileSync(fileName, 'utf8');\n if (currentContents !== contents) {\n console.log(`- ${fileName} has changed`);\n hasChanges = true;\n continue;\n }\n }\n\n return hasChanges;\n}\n\nfunction writeMapToFiles(map: Map<string, string>, outputDir: string) {\n let success = true;\n\n outputDir = path.resolve(outputDir);\n const globbyDir = outputDir.replace(/\\\\/g, '/');\n\n // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(\n [`${globbyDir}/**`, `${globbyDir}/**/.*`],\n {absolute: true},\n );\n\n const allGeneratedFiles = [...map.keys()].map(_ => path.normalize(_)).sort();\n allExistingFiles.forEach(existingFile => {\n if (!allGeneratedFiles.includes(path.normalize(existingFile))) {\n console.log('Deleting ', existingFile);\n fs.unlinkSync(existingFile);\n }\n });\n\n for (const [fileName, contents] of map) {\n try {\n fs.mkdirSync(path.dirname(fileName), {recursive: true});\n\n if (fs.existsSync(fileName)) {\n const currentContents = fs.readFileSync(fileName, 'utf8');\n // Don't update the files if there are no changes as this breaks incremental builds\n if (currentContents === contents) {\n continue;\n }\n }\n\n console.log('Writing ', fileName);\n fs.writeFileSync(fileName, contents);\n } catch (error) {\n success = false;\n console.error(`Failed to write ${fileName} to ${fileName}`, error);\n }\n }\n\n return success;\n}\n\nexport function parseFile(filename: string): SchemaType {\n try {\n const isTypeScript =\n path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';\n const contents = fs.readFileSync(filename, 'utf8');\n const schema = getParser(isTypeScript).parseString(contents, filename);\n // there will be at most one turbo module per file\n const moduleName = Object.keys(schema.modules)[0];\n if (moduleName) {\n const spec = schema.modules[moduleName];\n if (spec.type === 'NativeModule') {\n if (contents) {\n // This is a temporary implementation until such information is added to the schema in facebook/react-native\n if (contents.includes('TurboModuleRegistry.get<')) {\n setOptionalTurboModule(spec, true);\n } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {\n setOptionalTurboModule(spec, false);\n }\n }\n }\n }\n return schema;\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nexport function combineSchemas(files: string[]): SchemaType {\n return files.reduce(\n (merged, filename) => {\n const contents = fs.readFileSync(filename, 'utf8');\n if (\n contents &&\n (/export\\s+default\\s+\\(?codegenNativeComponent</.test(contents) ||\n contents.includes('extends TurboModule'))\n ) {\n const schema = parseFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nexport function generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\n schema,\n }: Options,\n {/*generators,*/ test}: Config,\n): boolean {\n schemaValidator.validate(schema);\n\n const componentOutputdir = path.join(\n outputDirectory,\n 'react/components',\n libraryName,\n );\n\n const generatedFiles = new Map<string, string>();\n\n generatedFiles.set(\n path.join(outputDirectory, '.clang-format'),\n 'DisableFormat: true\\nSortIncludes: false',\n );\n\n const generateNM2 = createNM2Generator({\n methodOnly,\n namespace,\n cppStringType,\n separateDataTypes,\n });\n\n const generateJsiModuleH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleH',\n )).generate;\n const generateJsiModuleCpp = require(path.resolve(\n rncodegenPath,\n 'lib/generators/modules/GenerateModuleCpp',\n )).generate;\n const generatorPropsH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsH',\n )).generate;\n const generatorPropsCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GeneratePropsCPP',\n )).generate;\n const generatorShadowNodeH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeH',\n )).generate;\n const generatorShadowNodeCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateShadowNodeCPP',\n )).generate;\n const generatorComponentDescriptorH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateComponentDescriptorH',\n )).generate;\n const generatorEventEmitterH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterH',\n )).generate;\n const generatorEventEmitterCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateEventEmitterCpp',\n )).generate;\n const generatorStateCPP = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateCpp',\n )).generate;\n const generatorStateH = require(path.resolve(\n rncodegenPath,\n 'lib/generators/components/GenerateStateH',\n )).generate;\n\n const moduleGenerators = [];\n\n if (modulesWindows) {\n moduleGenerators.push(generateNM2);\n }\n\n if (modulesCxx) {\n moduleGenerators.push(generateJsiModuleH);\n moduleGenerators.push(generateJsiModuleCpp);\n }\n\n if (modulesTypeScriptTypes) {\n moduleGenerators.push(generateTypeScript);\n }\n\n moduleGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, outputDirectory, generatedFiles);\n });\n\n if (\n Object.keys(schema.modules).some(\n moduleName => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorComponentDescriptorH,\n generatorEventEmitterCPP,\n generatorEventEmitterH,\n generatorPropsCPP,\n generatorPropsH,\n generatorShadowNodeCPP,\n generatorShadowNodeH,\n generatorStateCPP,\n generatorStateH,\n ];\n\n componentGenerators.forEach(generator => {\n const generated: Map<string, string> = generator(\n libraryName,\n schema,\n moduleSpecName,\n );\n normalizeFileMap(generated, componentOutputdir, generatedFiles);\n });\n }\n\n if (test === true) {\n return checkFilesForChanges(generatedFiles, outputDirectory);\n }\n\n return writeMapToFiles(generatedFiles, outputDirectory);\n}\n\nexport interface CodeGenOptions extends SharedOptions {\n file?: string;\n files?: string[];\n test: boolean;\n}\n\nexport function runCodeGen(options: CodeGenOptions): boolean {\n if (!options.file && !options.files)\n throw new Error('Must specify file or files option');\n\n const schema = options.file\n ? parseFile(options.file)\n : combineSchemas(globby.sync(options.files!));\n\n const libraryName = options.libraryName;\n const moduleSpecName = 'moduleSpecName';\n const {\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n } = options;\n return generate(\n {\n libraryName,\n methodOnly,\n modulesCxx,\n modulesTypeScriptTypes,\n modulesWindows,\n namespace,\n outputDirectory,\n cppStringType,\n separateDataTypes,\n moduleSpecName,\n schema,\n },\n {generators: [], test: options.test},\n );\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.67",
3
+ "version": "0.0.0-canary.69",
4
4
  "description": "Generators for react-native-codegen targeting react-native-windows",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "react-native-windows-codegen": "./bin.js"
23
23
  },
24
24
  "dependencies": {
25
- "@react-native-windows/fs": "^0.0.0-canary.27",
25
+ "@react-native-windows/fs": "^0.0.0-canary.28",
26
26
  "chalk": "^4.1.0",
27
27
  "globby": "^11.0.4",
28
28
  "mustache": "^4.0.1",
@@ -32,7 +32,7 @@
32
32
  "devDependencies": {
33
33
  "@rnw-scripts/eslint-config": "1.2.2",
34
34
  "@rnw-scripts/jest-unittest-config": "1.5.6",
35
- "@rnw-scripts/just-task": "2.3.15",
35
+ "@rnw-scripts/just-task": "2.3.16",
36
36
  "@rnw-scripts/ts-config": "2.0.5",
37
37
  "@types/chalk": "^2.2.0",
38
38
  "@types/jest": "^29.2.2",
package/src/Cli.ts CHANGED
@@ -64,6 +64,11 @@ const argv = yargs.options({
64
64
  'C++ string type in generated code, should be "std::string" or "std::wstring"',
65
65
  default: 'std::string',
66
66
  },
67
+ separateDataTypes: {
68
+ type: 'boolean',
69
+ describe: 'generate data types in a separate file',
70
+ default: false,
71
+ },
67
72
  }).argv;
68
73
 
69
74
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
@@ -17,22 +17,16 @@ export type {CppStringTypes} from './ObjectTypes';
17
17
 
18
18
  type FilesOutput = Map<string, string>;
19
19
 
20
- const moduleTemplate = `
21
- /*
20
+ const headerTemplate = `/*
22
21
  * This file is auto-generated from a NativeModule spec file in js.
23
22
  *
24
23
  * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
25
24
  * in a way that also verifies at compile time that the native module matches the interface required
26
25
  * by the TurboModule JS spec.
27
26
  */
28
- #pragma once
27
+ #pragma once`;
29
28
 
30
- #include <NativeModules.h>
31
- #include <tuple>
32
-
33
- namespace ::_NAMESPACE_:: {
34
- ::_MODULE_CUSTPM_TYPES_::
35
- ::_MODULE_CUSTPM_TYPES_REFLECTION_::
29
+ const specTemplate = `::_MODULE_CUSTPM_TYPES_REFLECTION_::
36
30
  struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
37
31
  ::_MODULE_MEMBERS_TUPLES_::
38
32
 
@@ -41,7 +35,44 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
41
35
  ::_MODULE_MEMBERS_CHECKS_::
42
36
 
43
37
  ::_MODULE_MEMBERS_ERRORS_::
44
- }
38
+ }`;
39
+
40
+ const typeOnlyTemplate = `
41
+ ${headerTemplate}
42
+
43
+ #include <string>
44
+ #include <optional>
45
+ #include <functional>
46
+ #include <vector>
47
+
48
+ namespace ::_NAMESPACE_:: {
49
+ ::_MODULE_CUSTPM_TYPES_::
50
+ } // namespace ::_NAMESPACE_::
51
+ `;
52
+
53
+ const moduleOnlyTemplate = `
54
+ ${headerTemplate}
55
+
56
+ ::_TYPE_DEFINITION_INCLUDE_::
57
+ #include <NativeModules.h>
58
+ #include <tuple>
59
+
60
+ namespace ::_NAMESPACE_:: {
61
+ ${specTemplate}
62
+ };
63
+
64
+ } // namespace ::_NAMESPACE_::
65
+ `;
66
+
67
+ const allInOneTemplate = `
68
+ ${headerTemplate}
69
+
70
+ #include <NativeModules.h>
71
+ #include <tuple>
72
+
73
+ namespace ::_NAMESPACE_:: {
74
+ ::_MODULE_CUSTPM_TYPES_::
75
+ ${specTemplate}
45
76
  };
46
77
 
47
78
  } // namespace ::_NAMESPACE_::
@@ -51,10 +82,12 @@ export function createNM2Generator({
51
82
  methodOnly,
52
83
  namespace,
53
84
  cppStringType,
85
+ separateDataTypes,
54
86
  }: {
55
87
  methodOnly: boolean;
56
88
  namespace: string;
57
89
  cppStringType: CppStringTypes;
90
+ separateDataTypes: boolean;
58
91
  }) {
59
92
  return (
60
93
  _libraryName: string,
@@ -110,17 +143,42 @@ ${errors}`;
110
143
  cppStringType,
111
144
  });
112
145
 
113
- files.set(
114
- `Native${preferredModuleName}Spec.g.h`,
115
- moduleTemplate
146
+ const customTypesExist = customTypes !== '';
147
+
148
+ const replaceContent = function (template: string): string {
149
+ return template
116
150
  .replace(/::_MODULE_CUSTPM_TYPES_::/g, customTypes)
117
151
  .replace(/::_MODULE_CUSTPM_TYPES_REFLECTION_::/g, customReflection)
118
152
  .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
119
153
  .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
120
154
  .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
121
155
  .replace(/::_MODULE_NAME_::/g, preferredModuleName)
122
- .replace(/::_NAMESPACE_::/g, namespace),
123
- );
156
+ .replace(
157
+ /::_TYPE_DEFINITION_INCLUDE_::/g,
158
+ customTypesExist
159
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
160
+ : '',
161
+ )
162
+ .replace(/::_NAMESPACE_::/g, namespace);
163
+ };
164
+
165
+ if (separateDataTypes) {
166
+ if (customTypesExist) {
167
+ files.set(
168
+ `Native${preferredModuleName}DataTypes.g.h`,
169
+ replaceContent(typeOnlyTemplate),
170
+ );
171
+ }
172
+ files.set(
173
+ `Native${preferredModuleName}Spec.g.h`,
174
+ replaceContent(moduleOnlyTemplate),
175
+ );
176
+ } else {
177
+ files.set(
178
+ `Native${preferredModuleName}Spec.g.h`,
179
+ replaceContent(allInOneTemplate),
180
+ );
181
+ }
124
182
  }
125
183
  }
126
184
 
package/src/index.ts CHANGED
@@ -52,6 +52,7 @@ export interface SharedOptions {
52
52
  namespace: string;
53
53
  outputDirectory: string;
54
54
  cppStringType: CppStringTypes;
55
+ separateDataTypes: boolean;
55
56
  }
56
57
 
57
58
  interface Options extends SharedOptions {
@@ -216,6 +217,7 @@ export function generate(
216
217
  namespace,
217
218
  outputDirectory,
218
219
  cppStringType,
220
+ separateDataTypes,
219
221
  moduleSpecName,
220
222
  schema,
221
223
  }: Options,
@@ -240,6 +242,7 @@ export function generate(
240
242
  methodOnly,
241
243
  namespace,
242
244
  cppStringType,
245
+ separateDataTypes,
243
246
  });
244
247
 
245
248
  const generateJsiModuleH = require(path.resolve(
@@ -369,6 +372,7 @@ export function runCodeGen(options: CodeGenOptions): boolean {
369
372
  namespace,
370
373
  outputDirectory,
371
374
  cppStringType,
375
+ separateDataTypes,
372
376
  } = options;
373
377
  return generate(
374
378
  {
@@ -380,6 +384,7 @@ export function runCodeGen(options: CodeGenOptions): boolean {
380
384
  namespace,
381
385
  outputDirectory,
382
386
  cppStringType,
387
+ separateDataTypes,
383
388
  moduleSpecName,
384
389
  schema,
385
390
  },