@react-native-windows/codegen 0.69.0 → 0.70.0-preview.1
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 +31 -10
- package/lib-commonjs/Cli.js +9 -1
- package/lib-commonjs/Cli.js.map +1 -1
- package/lib-commonjs/generators/GenerateNM2.d.ts +2 -1
- package/lib-commonjs/generators/GenerateNM2.js +4 -4
- package/lib-commonjs/generators/GenerateNM2.js.map +1 -1
- package/package.json +7 -8
- package/src/Cli.ts +9 -1
- package/src/generators/GenerateNM2.ts +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,26 +1,47 @@
|
|
|
1
1
|
# Change Log - @react-native-windows/codegen
|
|
2
2
|
|
|
3
|
-
This log was last generated on Mon,
|
|
3
|
+
This log was last generated on Mon, 22 Aug 2022 20:19:25 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.
|
|
7
|
+
## 0.70.0-preview.1
|
|
8
8
|
|
|
9
|
-
Mon,
|
|
9
|
+
Mon, 22 Aug 2022 20:19:25 GMT
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Changes
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
- Bump @react-native-windows/fs to v0.
|
|
13
|
+
- Promote 0.70 to preview (34109996+chiaramooney@users.noreply.github.com)
|
|
14
|
+
- Bump @react-native-windows/fs to v0.70.0-preview.1
|
|
15
15
|
|
|
16
|
-
## 0.
|
|
16
|
+
## 0.0.0-canary.35
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Sat, 04 Jun 2022 05:10:05 GMT
|
|
19
19
|
|
|
20
20
|
### Changes
|
|
21
21
|
|
|
22
|
-
-
|
|
23
|
-
- Bump @
|
|
22
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.5
|
|
23
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.8
|
|
24
|
+
- Bump @rnw-scripts/just-task to v2.2.5
|
|
25
|
+
|
|
26
|
+
## 0.0.0-canary.34
|
|
27
|
+
|
|
28
|
+
Thu, 12 May 2022 05:09:43 GMT
|
|
29
|
+
|
|
30
|
+
### Changes
|
|
31
|
+
|
|
32
|
+
- Build/dependency fixes (ngerlem@microsoft.com)
|
|
33
|
+
- Bump @react-native-windows/fs to v0.0.0-canary.4
|
|
34
|
+
- Bump @rnw-scripts/eslint-config to v1.1.13
|
|
35
|
+
- Bump @rnw-scripts/jest-unittest-config to v1.2.7
|
|
36
|
+
- Bump @rnw-scripts/just-task to v2.2.4
|
|
37
|
+
|
|
38
|
+
## 0.0.0-canary.33
|
|
39
|
+
|
|
40
|
+
Wed, 11 May 2022 05:08:51 GMT
|
|
41
|
+
|
|
42
|
+
### Changes
|
|
43
|
+
|
|
44
|
+
- Add --methodonly to RNW/codegen (53799235+ZihanChen-MSFT@users.noreply.github.com)
|
|
24
45
|
|
|
25
46
|
## 0.0.0-canary.32
|
|
26
47
|
|
package/lib-commonjs/Cli.js
CHANGED
|
@@ -33,6 +33,11 @@ const argv = yargs_1.default.options({
|
|
|
33
33
|
describe: 'generate turbo module definition files in TypeScript',
|
|
34
34
|
default: false,
|
|
35
35
|
},
|
|
36
|
+
methodonly: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
describe: 'generate only method metadata in C++ turbo module spec',
|
|
39
|
+
default: false,
|
|
40
|
+
},
|
|
36
41
|
outdir: {
|
|
37
42
|
type: 'string',
|
|
38
43
|
describe: 'output directory',
|
|
@@ -181,7 +186,10 @@ function generate({ libraryName, schema, outputDirectory, moduleSpecName }, { /*
|
|
|
181
186
|
const componentOutputdir = path_1.default.join(outputDirectory, 'react/components', libraryName);
|
|
182
187
|
const generatedFiles = new Map();
|
|
183
188
|
generatedFiles.set(path_1.default.join(outputDirectory, '.clang-format'), 'DisableFormat: true\nSortIncludes: false');
|
|
184
|
-
const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({
|
|
189
|
+
const generateNM2 = (0, GenerateNM2_1.createNM2Generator)({
|
|
190
|
+
namespace: argv.namespace,
|
|
191
|
+
methodonly: argv.methodonly,
|
|
192
|
+
});
|
|
185
193
|
const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;
|
|
186
194
|
const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP').generate;
|
|
187
195
|
const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH').generate;
|
package/lib-commonjs/Cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,QAA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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 {\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()].map(_ => path.normalize(_)).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"]}
|
|
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,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,wDAAwD;QAClE,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;QAC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C,CAAC;KAC9D;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 {\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 methodonly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\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()].map(_ => path.normalize(_)).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({\n namespace: argv.namespace,\n methodonly: argv.methodonly,\n });\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"]}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { SchemaType } from 'react-native-tscodegen';
|
|
7
7
|
declare type FilesOutput = Map<string, string>;
|
|
8
|
-
export declare function createNM2Generator({ namespace }: {
|
|
8
|
+
export declare function createNM2Generator({ namespace, methodonly, }: {
|
|
9
9
|
namespace: string;
|
|
10
|
+
methodonly: boolean;
|
|
10
11
|
}): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
|
|
11
12
|
export {};
|
|
@@ -38,7 +38,7 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
|
|
|
38
38
|
|
|
39
39
|
} // namespace ::_NAMESPACE_::
|
|
40
40
|
`;
|
|
41
|
-
function createNM2Generator({ namespace }) {
|
|
41
|
+
function createNM2Generator({ namespace, methodonly, }) {
|
|
42
42
|
return (_libraryName, schema, _moduleSpecName) => {
|
|
43
43
|
const files = new Map();
|
|
44
44
|
for (const moduleName of Object.keys(schema.modules)) {
|
|
@@ -65,7 +65,7 @@ ${methods[0]}
|
|
|
65
65
|
let errors = methods[1];
|
|
66
66
|
// prepare constants
|
|
67
67
|
const constants = (0, ValidateConstants_1.generateValidateConstants)(nativeModule, aliases);
|
|
68
|
-
if (constants !== undefined) {
|
|
68
|
+
if (constants !== undefined && !methodonly) {
|
|
69
69
|
tuples = `
|
|
70
70
|
static constexpr auto constants = std::tuple{
|
|
71
71
|
${constants[0]}
|
|
@@ -80,8 +80,8 @@ ${errors}`;
|
|
|
80
80
|
const traversedAliasedStructs = (0, AliasGen_1.generateAliases)(aliases);
|
|
81
81
|
files.set(`Native${preferredModuleName}Spec.g.h`, moduleTemplate
|
|
82
82
|
.replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)
|
|
83
|
-
.replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.
|
|
84
|
-
.replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.
|
|
83
|
+
.replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
|
|
84
|
+
.replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
|
|
85
85
|
.replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
|
|
86
86
|
.replace(/::_MODULE_NAME_::/g, preferredModuleName)
|
|
87
87
|
.replace(/::_NAMESPACE_::/g, namespace));
|
|
@@ -1 +1 @@
|
|
|
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;AAI1D,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BtB,CAAC;AAEF,SAAgB,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"GenerateNM2.js","sourceRoot":"","sources":["../../src/generators/GenerateNM2.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M,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,uBAAuB,GAAG,IAAA,0BAAe,EAAC,OAAO,CAAC,CAAC;gBAEzD,KAAK,CAAC,GAAG,CACP,SAAS,mBAAmB,UAAU,EACtC,cAAc;qBACX,OAAO,CAAC,+BAA+B,EAAE,uBAAuB,CAAC;qBACjE,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;AAxED,gDAwEC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport {SchemaType} from 'react-native-tscodegen';\nimport {AliasMap, setPreferredModuleName} from './AliasManaging';\nimport {createAliasMap, generateAliases} from './AliasGen';\nimport {generateValidateConstants} from './ValidateConstants';\nimport {generateValidateMethods} from './ValidateMethods';\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_ALIASED_STRUCTS_::\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 namespace,\n methodonly,\n}: {\n namespace: string;\n methodonly: 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.aliases);\n\n // prepare methods\n const methods = generateValidateMethods(nativeModule, aliases);\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 traversedAliasedStructs = generateAliases(aliases);\n\n files.set(\n `Native${preferredModuleName}Spec.g.h`,\n moduleTemplate\n .replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-windows/codegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.70.0-preview.1",
|
|
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": "0.
|
|
21
|
+
"@react-native-windows/fs": "0.70.0-preview.1",
|
|
22
22
|
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
|
23
23
|
"@typescript-eslint/parser": "^5.20.0",
|
|
24
24
|
"chalk": "^4.1.0",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"yargs": "^16.2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@rnw-scripts/eslint-config": "1.1.
|
|
33
|
-
"@rnw-scripts/jest-unittest-config": "1.2.
|
|
34
|
-
"@rnw-scripts/just-task": "2.2.
|
|
32
|
+
"@rnw-scripts/eslint-config": "1.1.13",
|
|
33
|
+
"@rnw-scripts/jest-unittest-config": "1.2.8",
|
|
34
|
+
"@rnw-scripts/just-task": "2.2.5",
|
|
35
35
|
"@rnw-scripts/ts-config": "2.0.2",
|
|
36
36
|
"@types/chalk": "^2.2.0",
|
|
37
37
|
"@types/jest": "^26.0.20",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"babel-jest": "^26.3.0",
|
|
41
41
|
"eslint": "^7.32.0",
|
|
42
42
|
"jest": "^26.6.3",
|
|
43
|
-
"just-scripts": "^1.3.3",
|
|
44
43
|
"prettier": "^2.4.1",
|
|
45
44
|
"typescript": "^4.4.4"
|
|
46
45
|
},
|
|
@@ -52,11 +51,11 @@
|
|
|
52
51
|
"src"
|
|
53
52
|
],
|
|
54
53
|
"beachball": {
|
|
55
|
-
"defaultNpmTag": "
|
|
54
|
+
"defaultNpmTag": "preview",
|
|
56
55
|
"disallowedChangeTypes": [
|
|
57
56
|
"major",
|
|
58
57
|
"minor",
|
|
59
|
-
"
|
|
58
|
+
"patch"
|
|
60
59
|
]
|
|
61
60
|
},
|
|
62
61
|
"promoteRelease": true,
|
package/src/Cli.ts
CHANGED
|
@@ -33,6 +33,11 @@ const argv = yargs.options({
|
|
|
33
33
|
describe: 'generate turbo module definition files in TypeScript',
|
|
34
34
|
default: false,
|
|
35
35
|
},
|
|
36
|
+
methodonly: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
describe: 'generate only method metadata in C++ turbo module spec',
|
|
39
|
+
default: false,
|
|
40
|
+
},
|
|
36
41
|
outdir: {
|
|
37
42
|
type: 'string',
|
|
38
43
|
describe: 'output directory',
|
|
@@ -237,7 +242,10 @@ function generate(
|
|
|
237
242
|
'DisableFormat: true\nSortIncludes: false',
|
|
238
243
|
);
|
|
239
244
|
|
|
240
|
-
const generateNM2 = createNM2Generator({
|
|
245
|
+
const generateNM2 = createNM2Generator({
|
|
246
|
+
namespace: argv.namespace,
|
|
247
|
+
methodonly: argv.methodonly,
|
|
248
|
+
});
|
|
241
249
|
|
|
242
250
|
const generatorPropsH =
|
|
243
251
|
require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH').generate;
|
|
@@ -43,7 +43,13 @@ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
|
|
|
43
43
|
} // namespace ::_NAMESPACE_::
|
|
44
44
|
`;
|
|
45
45
|
|
|
46
|
-
export function createNM2Generator({
|
|
46
|
+
export function createNM2Generator({
|
|
47
|
+
namespace,
|
|
48
|
+
methodonly,
|
|
49
|
+
}: {
|
|
50
|
+
namespace: string;
|
|
51
|
+
methodonly: boolean;
|
|
52
|
+
}) {
|
|
47
53
|
return (
|
|
48
54
|
_libraryName: string,
|
|
49
55
|
schema: SchemaType,
|
|
@@ -79,7 +85,7 @@ ${methods[0]}
|
|
|
79
85
|
|
|
80
86
|
// prepare constants
|
|
81
87
|
const constants = generateValidateConstants(nativeModule, aliases);
|
|
82
|
-
if (constants !== undefined) {
|
|
88
|
+
if (constants !== undefined && !methodonly) {
|
|
83
89
|
tuples = `
|
|
84
90
|
static constexpr auto constants = std::tuple{
|
|
85
91
|
${constants[0]}
|
|
@@ -98,8 +104,8 @@ ${errors}`;
|
|
|
98
104
|
`Native${preferredModuleName}Spec.g.h`,
|
|
99
105
|
moduleTemplate
|
|
100
106
|
.replace(/::_MODULE_ALIASED_STRUCTS_::/g, traversedAliasedStructs)
|
|
101
|
-
.replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.
|
|
102
|
-
.replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.
|
|
107
|
+
.replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
|
|
108
|
+
.replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
|
|
103
109
|
.replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
|
|
104
110
|
.replace(/::_MODULE_NAME_::/g, preferredModuleName)
|
|
105
111
|
.replace(/::_NAMESPACE_::/g, namespace),
|