@react-native-windows/codegen 0.0.0-canary.26 → 0.0.0-canary.29

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,42 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Thu, 24 Feb 2022 06:07:23 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 01 Apr 2022 05:08:52 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.0.0-canary.26
7
+ ## 0.0.0-canary.29
8
8
 
9
- Thu, 24 Feb 2022 06:07:23 GMT
9
+ Fri, 01 Apr 2022 05:08:52 GMT
10
10
 
11
11
  ### Changes
12
12
 
13
- - Add TypeScript turbo module definition as new codegen traget (53799235+ZihanChen-MSFT@users.noreply.github.com)
13
+ - Fix publish after promotion to preview (ngerlem@microsoft.com)
14
+ - Bump @react-native-windows/fs to v0.0.0-canary.1
14
15
 
16
+ ## 0.0.0-canary.28
17
+
18
+ Wed, 09 Mar 2022 06:09:07 GMT
19
+
20
+ ### Changes
21
+
22
+ - Fix turbo module codegen to generate correct import statement and registration (53799235+ZihanChen-MSFT@users.noreply.github.com)
23
+
24
+ ## 0.0.0-canary.27
25
+
26
+ Fri, 04 Mar 2022 06:09:13 GMT
27
+
28
+ ### Changes
29
+
30
+ - Generate fabric eventemitter.cpp (acoates@microsoft.com)
31
+
32
+ ## 0.0.0-canary.26
33
+
34
+ Thu, 24 Feb 2022 06:07:47 GMT
35
+
36
+ ### Changes
37
+
38
+ - Add TypeScript turbo module definition as new codegen traget (53799235+ZihanChen-MSFT@users.noreply.github.com)
39
+
15
40
  ## 0.0.0-canary.25
16
41
 
17
42
  Wed, 09 Feb 2022 06:09:36 GMT
@@ -139,7 +139,25 @@ function writeMapToFiles(map, outputDir) {
139
139
  }
140
140
  function parseFlowFile(filename) {
141
141
  try {
142
- return (0, flow_1.parseFile)(filename);
142
+ const schema = (0, flow_1.parseFile)(filename);
143
+ // there will be at most one turbo module per file
144
+ const moduleName = Object.keys(schema.modules)[0];
145
+ if (moduleName) {
146
+ const spec = schema.modules[moduleName];
147
+ if (spec.type === 'NativeModule') {
148
+ const contents = fs_1.default.readFileSync(filename, 'utf8');
149
+ if (contents) {
150
+ // This is a temporary implementation until such information is added to the schema in facebook/react-native
151
+ if (contents.includes('TurboModuleRegistry.get<')) {
152
+ (0, GenerateTypeScript_1.setOptionalTurboModule)(spec, true);
153
+ }
154
+ else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {
155
+ (0, GenerateTypeScript_1.setOptionalTurboModule)(spec, false);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ return schema;
143
161
  }
144
162
  catch (e) {
145
163
  if (e instanceof Error) {
@@ -172,6 +190,7 @@ function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*
172
190
  const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;
173
191
  const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;
174
192
  const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;
193
+ const generatorEventEmitterCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;
175
194
  normalizeFileMap(generateNM2(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
176
195
  if (argv.ts) {
177
196
  normalizeFileMap((0, GenerateTypeScript_1.generateTypeScript)(libraryName, schema, moduleSpecName), outputDirectory, generatedFiles);
@@ -184,6 +203,7 @@ function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*
184
203
  generatorShadowNodeCPP,
185
204
  generatorComponentDescriptorH,
186
205
  generatorEventEmitterH,
206
+ generatorEventEmitterCPP,
187
207
  ];
188
208
  componentGenerators.forEach((generator) => {
189
209
  const generated = generator(libraryName, schema, moduleSp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C9D;IAED,OAAO,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AAC1D,CAAC;AAED,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,IAAI,MAAkB,CAAC;AACvB,IAAI,IAAI,CAAC,IAAI,EAAE;IACb,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CACnC;KAAM;IACL,MAAM,GAAG,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAiB,CAAC,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;AACrC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AACxC,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;AACpC,QAAQ,CACN,EAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAC,EACtD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAC,CAC9B,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {generateTypeScript} from './generators/GenerateTypeScript';\n// @ts-ignore\nimport {parseFile} from 'react-native-tscodegen/lib/rncodegen/src/parsers/flow';\n// @ts-ignore\nimport schemaValidator from 'react-native-tscodegen/lib/rncodegen/src/schemaValidator';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'array',\n describe: 'glob patterns for files which contains specs',\n },\n ts: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n outdir: {\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 },\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}).argv;\n\nimport {SchemaType} from 'react-native-tscodegen';\n\ninterface Options {\n libraryName: string;\n schema: SchemaType;\n outputDirectory: string;\n moduleSpecName: string;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\n/*\nconst GENERATORS = {\n descriptors: [generateComponentDescriptorH.generate],\n events: [\n generateEventEmitterCpp.generate,\n generateEventEmitterH.generate,\n generateModuleHObjCpp.generate,\n generateModuleMm.generate,\n ],\n props: [\n generateComponentHObjCpp.generate,\n generatePropsCpp.generate,\n generatePropsH.generate,\n generatePropsJavaInterface.generate,\n generatePropsJavaDelegate.generate,\n ],\n modules: [generateModuleCpp.generate, generateModuleH.generate],\n tests: [generateTests.generate],\n 'shadow-nodes': [\n generateShadowNodeCpp.generate,\n generateShadowNodeH.generate,\n ],\n};\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 const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map((_) => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()]\n .map((_) => path.normalize(_))\n .sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\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.error(`- ${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 // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach((existingFile) => {\n if (!map.has(path.normalize(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 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\nfunction parseFlowFile(filename: string): SchemaType {\n try {\n return parseFile(filename);\n } catch (e) {\n if (e instanceof Error) {\n e.message = `(${filename}): ${e.message}`;\n }\n throw e;\n }\n}\n\nfunction 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 = parseFlowFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nfunction generate(\n {libraryName, schema, outputDirectory, moduleSpecName}: 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({namespace: argv.namespace});\n\n const generatorPropsH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;\n const generatorPropsCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;\n const generatorShadowNodeH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;\n const generatorShadowNodeCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;\n const generatorComponentDescriptorH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;\n const generatorEventEmitterH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n if (argv.ts) {\n normalizeFileMap(\n generateTypeScript(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n }\n\n if (\n Object.keys(schema.modules).some(\n (moduleName) => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorPropsH,\n generatorPropsCPP,\n generatorShadowNodeH,\n generatorShadowNodeCPP,\n generatorComponentDescriptorH,\n generatorEventEmitterH,\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\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\nlet schema: SchemaType;\nif (argv.file) {\n schema = parseFlowFile(argv.file);\n} else {\n schema = combineSchemas(globby.sync(argv.files as string[]));\n}\n\nconst libraryName = argv.libraryName;\nconst moduleSpecName = 'moduleSpecName';\nconst outputDirectory = argv.outdir;\ngenerate(\n {libraryName, schema, outputDirectory, moduleSpecName},\n {generators: [], test: false},\n);\n"]}
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,gDAAwB;AACxB,kEAA0C;AAC1C,oDAA4B;AAC5B,0DAA4D;AAC5D,wEAGyC;AACzC,aAAa;AACb,gFAAgF;AAChF,aAAa;AACb,+GAAuF;AAEvF,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,OAAO;QACb,QAAQ,EAAE,8CAA8C;KACzD;IACD,EAAE,EAAE;QACF,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,SAAS;KACnB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,+CAA+C;KAC1D;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;CACF,CAAC,CAAC,IAAI,CAAC;AAgBR;;;;;;;;;;;;;;;;;;;;;;;EAuBE;AAEF,SAAS,gBAAgB,CACvB,GAAwB,EACxB,SAAiB,EACjB,MAA2B;IAE3B,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,GAAG,EAAE;QACtC,MAAM,QAAQ,GAAG,cAAI,CAAC,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MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CACnC;KAAM;IACL,MAAM,GAAG,cAAc,CAAC,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAiB,CAAC,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;AACrC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AACxC,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;AACpC,QAAQ,CACN,EAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAC,EACtD,EAAC,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAC,CAC9B,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from '@react-native-windows/fs';\nimport globby from 'globby';\nimport {createNM2Generator} from './generators/GenerateNM2';\nimport {\n generateTypeScript,\n setOptionalTurboModule,\n} from './generators/GenerateTypeScript';\n// @ts-ignore\nimport {parseFile} from 'react-native-tscodegen/lib/rncodegen/src/parsers/flow';\n// @ts-ignore\nimport schemaValidator from 'react-native-tscodegen/lib/rncodegen/src/schemaValidator';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'array',\n describe: 'glob patterns for files which contains specs',\n },\n ts: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n outdir: {\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 },\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}).argv;\n\nimport {SchemaType} from 'react-native-tscodegen';\n\ninterface Options {\n libraryName: string;\n schema: SchemaType;\n outputDirectory: string;\n moduleSpecName: string;\n}\n\ninterface Config {\n generators: any[] /*Generators[]*/;\n test?: boolean;\n}\n\n/*\nconst GENERATORS = {\n descriptors: [generateComponentDescriptorH.generate],\n events: [\n generateEventEmitterCpp.generate,\n generateEventEmitterH.generate,\n generateModuleHObjCpp.generate,\n generateModuleMm.generate,\n ],\n props: [\n generateComponentHObjCpp.generate,\n generatePropsCpp.generate,\n generatePropsH.generate,\n generatePropsJavaInterface.generate,\n generatePropsJavaDelegate.generate,\n ],\n modules: [generateModuleCpp.generate, generateModuleH.generate],\n tests: [generateTests.generate],\n 'shadow-nodes': [\n generateShadowNodeCpp.generate,\n generateShadowNodeH.generate,\n ],\n};\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 const allExistingFiles = globby\n .sync(`${outputDir}/**`)\n .map((_) => path.normalize(_))\n .sort();\n const allGeneratedFiles = [...map.keys()]\n .map((_) => path.normalize(_))\n .sort();\n\n if (\n allExistingFiles.length !== allGeneratedFiles.length ||\n !allExistingFiles.every((val, index) => val === allGeneratedFiles[index])\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.error(`- ${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 // This ensures that we delete any generated files from modules that have been deleted\n const allExistingFiles = globby.sync(`${outputDir}/**`);\n allExistingFiles.forEach((existingFile) => {\n if (!map.has(path.normalize(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 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\nfunction parseFlowFile(filename: string): SchemaType {\n try {\n const schema = parseFile(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 const contents = fs.readFileSync(filename, 'utf8');\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\nfunction 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 = parseFlowFile(filename);\n merged.modules = {...merged.modules, ...schema.modules};\n }\n return merged;\n },\n {modules: {}},\n );\n}\n\nfunction generate(\n {libraryName, schema, outputDirectory, moduleSpecName}: 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({namespace: argv.namespace});\n\n const generatorPropsH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;\n const generatorPropsCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;\n const generatorShadowNodeH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;\n const generatorShadowNodeCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP').generate;\n const generatorComponentDescriptorH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;\n const generatorEventEmitterH =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;\n const generatorEventEmitterCPP =\n require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;\n\n normalizeFileMap(\n generateNM2(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n\n if (argv.ts) {\n normalizeFileMap(\n generateTypeScript(libraryName, schema, moduleSpecName),\n outputDirectory,\n generatedFiles,\n );\n }\n\n if (\n Object.keys(schema.modules).some(\n (moduleName) => schema.modules[moduleName].type === 'Component',\n )\n ) {\n const componentGenerators = [\n generatorPropsH,\n generatorPropsCPP,\n generatorShadowNodeH,\n generatorShadowNodeCPP,\n generatorComponentDescriptorH,\n generatorEventEmitterH,\n generatorEventEmitterCPP,\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\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\nlet schema: SchemaType;\nif (argv.file) {\n schema = parseFlowFile(argv.file);\n} else {\n schema = combineSchemas(globby.sync(argv.files as string[]));\n}\n\nconst libraryName = argv.libraryName;\nconst moduleSpecName = 'moduleSpecName';\nconst outputDirectory = argv.outdir;\ngenerate(\n {libraryName, schema, outputDirectory, moduleSpecName},\n {generators: [], test: false},\n);\n"]}
@@ -3,7 +3,9 @@
3
3
  * Licensed under the MIT License.
4
4
  * @format
5
5
  */
6
- import { SchemaType } from 'react-native-tscodegen';
6
+ import { NativeModuleSchema, SchemaType } from 'react-native-tscodegen';
7
+ export declare function setOptionalTurboModule(schema: NativeModuleSchema, optional: boolean): void;
8
+ export declare function getOptionalTurboModule(schema: NativeModuleSchema): boolean;
7
9
  declare type FilesOutput = Map<string, string>;
8
10
  export declare function generateTypeScript(_libraryName: string, schema: SchemaType, _moduleSpecName: string): FilesOutput;
9
11
  export {};
@@ -5,7 +5,17 @@
5
5
  */
6
6
  'use strict';
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.generateTypeScript = void 0;
8
+ exports.generateTypeScript = exports.getOptionalTurboModule = exports.setOptionalTurboModule = void 0;
9
+ function setOptionalTurboModule(schema, optional) {
10
+ const cs = schema;
11
+ cs.optionalTurboModule = optional;
12
+ }
13
+ exports.setOptionalTurboModule = setOptionalTurboModule;
14
+ function getOptionalTurboModule(schema) {
15
+ var _a;
16
+ return (_a = schema.optionalTurboModule) !== null && _a !== void 0 ? _a : false;
17
+ }
18
+ exports.getOptionalTurboModule = getOptionalTurboModule;
9
19
  const moduleTemplate = `
10
20
  /*
11
21
  * This file is auto-generated from a NativeModule spec file in js.
@@ -13,16 +23,14 @@ const moduleTemplate = `
13
23
  * This is a TypeScript turbo module definition file.
14
24
  */
15
25
 
16
- // the following import statements are not actually working today
17
- import {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
18
- import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
26
+ import {TurboModule, TurboModuleRegistry} from 'react-native';
19
27
  'use strict';
20
28
  ::_MODULE_ALIASED_STRUCTS_::
21
29
  export interface Spec extends TurboModule {
22
30
  ::_MODULE_MEMBERS_::
23
31
  }
24
32
 
25
- export default TurboModuleRegistry.getEnforcing<Spec>('::_MODULE_NAME_::');
33
+ export default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');
26
34
  `;
27
35
  function optionalSign(obj) {
28
36
  return obj.optional ? '?' : '';
@@ -148,7 +156,8 @@ function generateTypeScript(_libraryName, schema, _moduleSpecName) {
148
156
  files.set(`${preferredModuleName}Spec.g.ts`, moduleTemplate
149
157
  .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)
150
158
  .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)
151
- .replace(/::_MODULE_NAME_::/g, preferredModuleName));
159
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
160
+ .replace(/::_MODULE_GETTER_::/g, getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing'));
152
161
  }
153
162
  }
154
163
  return files;
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateTypeScript.js","sourceRoot":"","sources":["../../src/generators/GenerateTypeScript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAmBb,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;CAiBtB,CAAC;AAEF,SAAS,YAAY,CAAI,GAAkB;IACzC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CACpB,IAIC;IAED,wDAAwD;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,sBAAsB;YACzB,OAAO,QAAQ,CAAC;QAClB,KAAK,sBAAsB,CAAC;QAC5B,KAAK,qBAAqB,CAAC;QAC3B,KAAK,sBAAsB,CAAC;QAC5B,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAC;QAClB,KAAK,uBAAuB;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AC,UAAU,CAAC;QAEf,IAAI,YAAY,CAAC,IAAI,KAAK,cAAc,EAAE;YACxC,OAAO,CAAC,GAAG,CAAC,cAAc,mBAAmB,WAAW,CAAC,CAAC;YAE1D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;iBAChD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;iBAC/D,IAAI,CAAC,EAAE,CAAC,CAAC;YAEZ,MAAM,YAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;YACtD,MAAM,YAAY,GAChB,YAAY,KAAK,SAAS;gBACxB,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,qBAAqB,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YAEzD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CACjD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACvC,CAAC;YACF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAE1D,KAAK,CAAC,GAAG,CACP,GAAG,mBAAmB,WAAW,EACjC,cAAc;iBACX,OAAO,CAAC,+BAA+B,EAAE,SAAS,CAAC;iBACnD,OAAO,CAAC,uBAAuB,EAAE,YAAY,GAAG,WAAW,CAAC;iBAC5D,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,CACtD,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA9CD,gDA8CC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NamedShape,\n NativeModuleBaseTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NativeModuleParamTypeAnnotation,\n NativeModuleReturnTypeAnnotation,\n NativeModuleSchema,\n Nullable,\n SchemaType,\n} from 'react-native-tscodegen';\n\ntype ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;\ntype FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;\ntype FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;\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 TypeScript turbo module definition file.\n */\n\n// the following import statements are not actually working today\nimport {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';\nimport * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';\n'use strict';\n::_MODULE_ALIASED_STRUCTS_::\nexport interface Spec extends TurboModule {\n::_MODULE_MEMBERS_::\n}\n\nexport default TurboModuleRegistry.getEnforcing<Spec>('::_MODULE_NAME_::');\n`;\n\nfunction optionalSign<T>(obj: NamedShape<T>): string {\n return obj.optional ? '?' : '';\n}\n\nfunction translateType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleParamTypeAnnotation\n | NativeModuleReturnTypeAnnotation\n >,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return 'string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n case 'Int32TypeAnnotation':\n return 'number';\n case 'BooleanTypeAnnotation':\n return 'boolean';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `${translateType(type.elementType)}[]`;\n } else {\n return `Array`;\n }\n case 'GenericObjectTypeAnnotation':\n return 'object';\n case 'ObjectTypeAnnotation':\n return `{${type.properties\n .map((prop: ObjectProp) => {\n return `${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )}`;\n })\n .join(', ')}}`;\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 'number';\n }\n case 'TypeAliasTypeAnnotation':\n return type.name;\n case 'NullableTypeAnnotation':\n return `(${translateType(type.typeAnnotation)} | null | undefined)`;\n case 'VoidTypeAnnotation':\n return `void`;\n case 'PromiseTypeAnnotation':\n return `Promise`;\n case `FunctionTypeAnnotation`:\n return `((${type.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nfunction translateAlias(\n name: string,\n type: NativeModuleObjectTypeAnnotation,\n): string {\n return `\nexport interface ${name} {\n${type.properties\n .map((prop: ObjectProp) => {\n return ` ${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )};`;\n })\n .join('\\n')}\n}\n`;\n}\n\nfunction tryGetConstantType(\n nativeModule: NativeModuleSchema,\n): NativeModuleObjectTypeAnnotation | 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 return constantType;\n}\n\nfunction translateMethod(func: FunctionDecl): string {\n const funcType =\n func.typeAnnotation.type === 'NullableTypeAnnotation'\n ? func.typeAnnotation.typeAnnotation\n : func.typeAnnotation;\n\n return `\n ${func.name}(${funcType.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')})${optionalSign(func)}: ${translateType(\n funcType.returnTypeAnnotation,\n )}${\n funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'\n }`;\n}\n\nexport function generateTypeScript(\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 nativePrefix = 'Native';\n const preferredModuleName = moduleName.startsWith(nativePrefix)\n ? moduleName.substr(nativePrefix.length)\n : moduleName;\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating ${preferredModuleName}Spec.g.ts`);\n\n const aliasCode = Object.keys(nativeModule.aliases)\n .map((name) => translateAlias(name, nativeModule.aliases[name]))\n .join('');\n\n const constantType = tryGetConstantType(nativeModule);\n const constantCode =\n constantType === undefined\n ? ''\n : ` getConstants(): ${translateType(constantType)}`;\n\n const methods = nativeModule.spec.properties.filter(\n (prop) => prop.name !== 'getConstants',\n );\n const membersCode = methods.map(translateMethod).join('');\n\n files.set(\n `${preferredModuleName}Spec.g.ts`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)\n .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName),\n );\n }\n }\n\n return files;\n}\n"]}
1
+ {"version":3,"file":"GenerateTypeScript.js","sourceRoot":"","sources":["../../src/generators/GenerateTypeScript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAkBb,SAAgB,sBAAsB,CACpC,MAA0B,EAC1B,QAAiB;IAEjB,MAAM,EAAE,GAA8B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AC,YAAY,CAAC,EAAE,CAAC;YAEzD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CACjD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CACvC,CAAC;YACF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAE1D,KAAK,CAAC,GAAG,CACP,GAAG,mBAAmB,WAAW,EACjC,cAAc;iBACX,OAAO,CAAC,+BAA+B,EAAE,SAAS,CAAC;iBACnD,OAAO,CAAC,uBAAuB,EAAE,YAAY,GAAG,WAAW,CAAC;iBAC5D,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;iBAClD,OAAO,CACN,sBAAsB,EACtB,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAC9D,CACJ,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAlDD,gDAkDC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {\n NamedShape,\n NativeModuleBaseTypeAnnotation,\n NativeModuleFunctionTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NativeModuleParamTypeAnnotation,\n NativeModuleReturnTypeAnnotation,\n NativeModuleSchema,\n Nullable,\n SchemaType,\n} from 'react-native-tscodegen';\n\ninterface CodegenNativeModuleSchema extends NativeModuleSchema {\n optionalTurboModule?: boolean;\n}\n\nexport function setOptionalTurboModule(\n schema: NativeModuleSchema,\n optional: boolean,\n): void {\n const cs = <CodegenNativeModuleSchema>schema;\n cs.optionalTurboModule = optional;\n}\n\nexport function getOptionalTurboModule(schema: NativeModuleSchema): boolean {\n return (<CodegenNativeModuleSchema>schema).optionalTurboModule ?? false;\n}\n\ntype ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;\ntype FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;\ntype FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;\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 TypeScript turbo module definition file.\n */\n\nimport {TurboModule, TurboModuleRegistry} from 'react-native';\n'use strict';\n::_MODULE_ALIASED_STRUCTS_::\nexport interface Spec extends TurboModule {\n::_MODULE_MEMBERS_::\n}\n\nexport default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');\n`;\n\nfunction optionalSign<T>(obj: NamedShape<T>): string {\n return obj.optional ? '?' : '';\n}\n\nfunction translateType(\n type: Nullable<\n | NativeModuleBaseTypeAnnotation\n | NativeModuleParamTypeAnnotation\n | NativeModuleReturnTypeAnnotation\n >,\n): string {\n // avoid: Property 'type' does not exist on type 'never'\n const returnType = type.type;\n switch (type.type) {\n case 'StringTypeAnnotation':\n return 'string';\n case 'NumberTypeAnnotation':\n case 'FloatTypeAnnotation':\n case 'DoubleTypeAnnotation':\n case 'Int32TypeAnnotation':\n return 'number';\n case 'BooleanTypeAnnotation':\n return 'boolean';\n case 'ArrayTypeAnnotation':\n if (type.elementType) {\n return `${translateType(type.elementType)}[]`;\n } else {\n return `Array`;\n }\n case 'GenericObjectTypeAnnotation':\n return 'object';\n case 'ObjectTypeAnnotation':\n return `{${type.properties\n .map((prop: ObjectProp) => {\n return `${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )}`;\n })\n .join(', ')}}`;\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 'number';\n }\n case 'TypeAliasTypeAnnotation':\n return type.name;\n case 'NullableTypeAnnotation':\n return `(${translateType(type.typeAnnotation)} | null | undefined)`;\n case 'VoidTypeAnnotation':\n return `void`;\n case 'PromiseTypeAnnotation':\n return `Promise`;\n case `FunctionTypeAnnotation`:\n return `((${type.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')}) => ${translateType(type.returnTypeAnnotation)})`;\n default:\n throw new Error(`Unhandled type in translateReturnType: ${returnType}`);\n }\n}\n\nfunction translateAlias(\n name: string,\n type: NativeModuleObjectTypeAnnotation,\n): string {\n return `\nexport interface ${name} {\n${type.properties\n .map((prop: ObjectProp) => {\n return ` ${prop.name}${optionalSign(prop)}: ${translateType(\n prop.typeAnnotation,\n )};`;\n })\n .join('\\n')}\n}\n`;\n}\n\nfunction tryGetConstantType(\n nativeModule: NativeModuleSchema,\n): NativeModuleObjectTypeAnnotation | 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 return constantType;\n}\n\nfunction translateMethod(func: FunctionDecl): string {\n const funcType =\n func.typeAnnotation.type === 'NullableTypeAnnotation'\n ? func.typeAnnotation.typeAnnotation\n : func.typeAnnotation;\n\n return `\n ${func.name}(${funcType.params\n .map((param: FunctionParam) => {\n return `${param.name}${optionalSign(param)}: ${translateType(\n param.typeAnnotation,\n )}`;\n })\n .join(', ')})${optionalSign(func)}: ${translateType(\n funcType.returnTypeAnnotation,\n )}${\n funcType.returnTypeAnnotation.type === 'ObjectTypeAnnotation' ? '' : ';'\n }`;\n}\n\nexport function generateTypeScript(\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 nativePrefix = 'Native';\n const preferredModuleName = moduleName.startsWith(nativePrefix)\n ? moduleName.substr(nativePrefix.length)\n : moduleName;\n\n if (nativeModule.type === 'NativeModule') {\n console.log(`Generating ${preferredModuleName}Spec.g.ts`);\n\n const aliasCode = Object.keys(nativeModule.aliases)\n .map((name) => translateAlias(name, nativeModule.aliases[name]))\n .join('');\n\n const constantType = tryGetConstantType(nativeModule);\n const constantCode =\n constantType === undefined\n ? ''\n : ` getConstants(): ${translateType(constantType)}`;\n\n const methods = nativeModule.spec.properties.filter(\n (prop) => prop.name !== 'getConstants',\n );\n const membersCode = methods.map(translateMethod).join('');\n\n files.set(\n `${preferredModuleName}Spec.g.ts`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)\n .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)\n .replace(/::_MODULE_NAME_::/g, preferredModuleName)\n .replace(\n /::_MODULE_GETTER_::/g,\n getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing',\n ),\n );\n }\n }\n\n return files;\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.26",
3
+ "version": "0.0.0-canary.29",
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",
@@ -18,7 +18,7 @@
18
18
  "react-native-windows-codegen": "./bin.js"
19
19
  },
20
20
  "dependencies": {
21
- "@react-native-windows/fs": "^1.0.2",
21
+ "@react-native-windows/fs": "^0.0.0-canary.1",
22
22
  "chalk": "^4.1.0",
23
23
  "globby": "^9.2.0",
24
24
  "mustache": "^4.0.1",
package/src/Cli.ts CHANGED
@@ -10,7 +10,10 @@ import path from 'path';
10
10
  import fs from '@react-native-windows/fs';
11
11
  import globby from 'globby';
12
12
  import {createNM2Generator} from './generators/GenerateNM2';
13
- import {generateTypeScript} from './generators/GenerateTypeScript';
13
+ import {
14
+ generateTypeScript,
15
+ setOptionalTurboModule,
16
+ } from './generators/GenerateTypeScript';
14
17
  // @ts-ignore
15
18
  import {parseFile} from 'react-native-tscodegen/lib/rncodegen/src/parsers/flow';
16
19
  // @ts-ignore
@@ -173,7 +176,24 @@ function writeMapToFiles(map: Map<string, string>, outputDir: string) {
173
176
 
174
177
  function parseFlowFile(filename: string): SchemaType {
175
178
  try {
176
- return parseFile(filename);
179
+ const schema = parseFile(filename);
180
+ // there will be at most one turbo module per file
181
+ const moduleName = Object.keys(schema.modules)[0];
182
+ if (moduleName) {
183
+ const spec = schema.modules[moduleName];
184
+ if (spec.type === 'NativeModule') {
185
+ const contents = fs.readFileSync(filename, 'utf8');
186
+ if (contents) {
187
+ // This is a temporary implementation until such information is added to the schema in facebook/react-native
188
+ if (contents.includes('TurboModuleRegistry.get<')) {
189
+ setOptionalTurboModule(spec, true);
190
+ } else if (contents.includes('TurboModuleRegistry.getEnforcing<')) {
191
+ setOptionalTurboModule(spec, false);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return schema;
177
197
  } catch (e) {
178
198
  if (e instanceof Error) {
179
199
  e.message = `(${filename}): ${e.message}`;
@@ -233,6 +253,8 @@ function generate(
233
253
  require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH').generate;
234
254
  const generatorEventEmitterH =
235
255
  require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH').generate;
256
+ const generatorEventEmitterCPP =
257
+ require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterCpp').generate;
236
258
 
237
259
  normalizeFileMap(
238
260
  generateNM2(libraryName, schema, moduleSpecName),
@@ -260,6 +282,7 @@ function generate(
260
282
  generatorShadowNodeCPP,
261
283
  generatorComponentDescriptorH,
262
284
  generatorEventEmitterH,
285
+ generatorEventEmitterCPP,
263
286
  ];
264
287
 
265
288
  componentGenerators.forEach((generator) => {
@@ -18,6 +18,22 @@ import {
18
18
  SchemaType,
19
19
  } from 'react-native-tscodegen';
20
20
 
21
+ interface CodegenNativeModuleSchema extends NativeModuleSchema {
22
+ optionalTurboModule?: boolean;
23
+ }
24
+
25
+ export function setOptionalTurboModule(
26
+ schema: NativeModuleSchema,
27
+ optional: boolean,
28
+ ): void {
29
+ const cs = <CodegenNativeModuleSchema>schema;
30
+ cs.optionalTurboModule = optional;
31
+ }
32
+
33
+ export function getOptionalTurboModule(schema: NativeModuleSchema): boolean {
34
+ return (<CodegenNativeModuleSchema>schema).optionalTurboModule ?? false;
35
+ }
36
+
21
37
  type ObjectProp = NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>;
22
38
  type FunctionParam = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
23
39
  type FunctionDecl = NamedShape<Nullable<NativeModuleFunctionTypeAnnotation>>;
@@ -30,16 +46,14 @@ const moduleTemplate = `
30
46
  * This is a TypeScript turbo module definition file.
31
47
  */
32
48
 
33
- // the following import statements are not actually working today
34
- import {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
35
- import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
49
+ import {TurboModule, TurboModuleRegistry} from 'react-native';
36
50
  'use strict';
37
51
  ::_MODULE_ALIASED_STRUCTS_::
38
52
  export interface Spec extends TurboModule {
39
53
  ::_MODULE_MEMBERS_::
40
54
  }
41
55
 
42
- export default TurboModuleRegistry.getEnforcing<Spec>('::_MODULE_NAME_::');
56
+ export default TurboModuleRegistry.::_MODULE_GETTER_::<Spec>('::_MODULE_NAME_::');
43
57
  `;
44
58
 
45
59
  function optionalSign<T>(obj: NamedShape<T>): string {
@@ -220,7 +234,11 @@ export function generateTypeScript(
220
234
  moduleTemplate
221
235
  .replace(/::_MODULE_ALIASED_STRUCTS_::/g, aliasCode)
222
236
  .replace(/::_MODULE_MEMBERS_::/g, constantCode + membersCode)
223
- .replace(/::_MODULE_NAME_::/g, preferredModuleName),
237
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
238
+ .replace(
239
+ /::_MODULE_GETTER_::/g,
240
+ getOptionalTurboModule(nativeModule) ? 'get' : 'getEnforcing',
241
+ ),
224
242
  );
225
243
  }
226
244
  }