From 0da4612f039325f007ff7c8df4b09b1aec4e5622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Osadnik?= Date: Thu, 8 Aug 2019 11:09:30 -0700 Subject: [PATCH] change name convention for modules Summary: Following our internal discussion we want to change previously used name convention. Now it looks like: ``` #import ``` Name is a param of `rn_codegen` and `rn_library`. Also, I found it the easiest to move replacing `::_IMPORT_::` into buck rule Reviewed By: fkgozali Differential Revision: D16646616 fbshipit-source-id: 2c33c5b4d1c42b0e6f5a42d9a318bd8bda9745f4 --- packages/react-native-codegen/BUCK | 1 + packages/react-native-codegen/DEFS.bzl | 17 ++++++++-------- .../buck_tests/emptyFile.mm | 4 ++-- .../buck_tests/generate-tests.js | 7 ++++--- .../src/generators/RNCodegen.js | 9 ++++----- .../GenerateComponentDescriptorH.js | 6 +++++- .../components/GenerateComponentHObjCpp.js | 6 +++++- .../components/GenerateEventEmitterCpp.js | 6 +++++- .../components/GenerateEventEmitterH.js | 6 +++++- .../generators/components/GeneratePropsCpp.js | 6 +++++- .../generators/components/GeneratePropsH.js | 6 +++++- .../components/GeneratePropsJavaDelegate.js | 6 +++++- .../components/GeneratePropsJavaInterface.js | 6 +++++- .../components/GenerateShadowNodeCpp.js | 6 +++++- .../components/GenerateShadowNodeH.js | 6 +++++- .../generators/components/GenerateTests.js | 6 +++++- .../GenerateComponentDescriptorH-test.js | 4 +++- .../GenerateComponentHObjCpp-test.js | 4 +++- .../__tests__/GenerateEventEmitterCpp-test.js | 4 +++- .../__tests__/GenerateEventEmitterH-test.js | 4 +++- .../__tests__/GeneratePropsCpp-test.js | 4 +++- .../__tests__/GeneratePropsH-test.js | 4 +++- .../GeneratePropsJavaDelegate-test.js | 4 +++- .../GeneratePropsJavaInterface-test.js | 4 +++- .../__tests__/GenerateShadowNodeCpp-test.js | 4 +++- .../__tests__/GenerateShadowNodeH-test.js | 4 +++- .../__tests__/GenerateTests-test.js | 4 +++- .../generators/modules/GenerateModuleCpp.js | 6 +++++- .../src/generators/modules/GenerateModuleH.js | 6 +++++- .../modules/GenerateModuleHObjCpp.js | 8 ++++++-- .../generators/modules/GenerateModuleMm.js | 13 ++++++++---- .../__tests__/GenerateModuleCpp-test.js | 4 +++- .../modules/__tests__/GenerateModuleH-test.js | 4 +++- .../__tests__/GenerateModuleHObjCpp-test.js | 4 +++- .../__tests__/GenerateModuleMm-test.js | 4 +++- .../GenerateModuleHObjCpp-test.js.snap | 10 +++++----- .../GenerateModuleMm-test.js.snap | 20 +++++++++---------- 37 files changed, 160 insertions(+), 67 deletions(-) diff --git a/packages/react-native-codegen/BUCK b/packages/react-native-codegen/BUCK index 99873ba7ca8..079267dbefe 100644 --- a/packages/react-native-codegen/BUCK +++ b/packages/react-native-codegen/BUCK @@ -48,6 +48,7 @@ fb_native.genrule( rn_codegen( name = "codegen_tests", + native_module_spec_name = "FBReactNativeTestSpec", schema_target = ":codegen_tests_schema", ) diff --git a/packages/react-native-codegen/DEFS.bzl b/packages/react-native-codegen/DEFS.bzl index 45ba4594c8c..38d7bd17553 100644 --- a/packages/react-native-codegen/DEFS.bzl +++ b/packages/react-native-codegen/DEFS.bzl @@ -18,6 +18,7 @@ load( ) def rn_codegen( + native_module_spec_name, name = "", schema_target = ""): generate_fixtures_rule_name = "generate_fixtures-{}".format(name) @@ -40,7 +41,7 @@ def rn_codegen( fb_native.genrule( name = generate_fixtures_rule_name, srcs = native.glob(["src/generators/**/*.js"]), - cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT".format(schema_target, name), + cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, native_module_spec_name), out = "codegenfiles-{}".format(name), ) @@ -125,14 +126,14 @@ def rn_codegen( fb_native.genrule( name = generate_module_hobjcpp_name, - cmd = "cp $(location :{})/RCTNativeModules.h $OUT".format(generate_fixtures_rule_name), - out = "RCTNativeModules.h", + cmd = "cp $(location :{})/{}.h $OUT".format(generate_fixtures_rule_name, native_module_spec_name), + out = "{}.h".format(native_module_spec_name), ) fb_native.genrule( name = generate_module_mm_name, - cmd = "cp $(location :{})/RCTNativeModules.mm $OUT".format(generate_fixtures_rule_name), - out = "RCTNativeModules.mm", + cmd = "cp $(location :{})/{}-generated.mm $OUT".format(generate_fixtures_rule_name, native_module_spec_name), + out = "{}-generated.mm".format(native_module_spec_name), ) # libs @@ -236,10 +237,10 @@ def rn_codegen( ":{}".format(generate_module_hobjcpp_name), ], ios_exported_headers = { - "RCTNativeModules.h": ":{}".format(generate_module_hobjcpp_name), - "RCTNativeModules.mm": ":{}".format(generate_module_mm_name), + "{}.h".format(native_module_spec_name): ":{}".format(generate_module_hobjcpp_name), + "{}-generated.mm".format(native_module_spec_name): ":{}".format(generate_module_mm_name), }, - header_namespace = "react/modules/{}".format(name), + header_namespace = native_module_spec_name, compiler_flags = [ "-fexceptions", "-frtti", diff --git a/packages/react-native-codegen/buck_tests/emptyFile.mm b/packages/react-native-codegen/buck_tests/emptyFile.mm index 32188a252c8..d36f586fc7e 100644 --- a/packages/react-native-codegen/buck_tests/emptyFile.mm +++ b/packages/react-native-codegen/buck_tests/emptyFile.mm @@ -1,7 +1,7 @@ #import #import -#import -#import +#import +#import // TODO: Import every prop and event to asset they're generated diff --git a/packages/react-native-codegen/buck_tests/generate-tests.js b/packages/react-native-codegen/buck_tests/generate-tests.js index e84ebfa9a1a..2681bddc64a 100644 --- a/packages/react-native-codegen/buck_tests/generate-tests.js +++ b/packages/react-native-codegen/buck_tests/generate-tests.js @@ -15,9 +15,9 @@ const fs = require('fs'); const mkdirp = require('mkdirp'); const args = process.argv.slice(2); -if (args.length !== 3) { +if (args.length !== 4) { throw new Error( - `Expected to receive path to schema, library name, and output directory. Received ${args.join( + `Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join( ', ', )}`, ); @@ -26,6 +26,7 @@ if (args.length !== 3) { const schemaPath = args[0]; const libraryName = args[1]; const outputDirectory = args[2]; +const moduleSpecName = args[3]; const schemaText = fs.readFileSync(schemaPath, 'utf-8'); @@ -43,7 +44,7 @@ try { } RNCodegen.generate( - {libraryName, schema, outputDirectory}, + {libraryName, schema, outputDirectory, moduleSpecName}, { generators: [ 'descriptors', diff --git a/packages/react-native-codegen/src/generators/RNCodegen.js b/packages/react-native-codegen/src/generators/RNCodegen.js index 2e863ff278d..0de0f2ec1d1 100644 --- a/packages/react-native-codegen/src/generators/RNCodegen.js +++ b/packages/react-native-codegen/src/generators/RNCodegen.js @@ -42,6 +42,7 @@ type Options = $ReadOnly<{| libraryName: string, schema: SchemaType, outputDirectory: string, + moduleSpecName: string, |}>; type Generators = @@ -50,8 +51,7 @@ type Generators = | 'props' | 'tests' | 'shadow-nodes' - | 'modules' - | 'view-configs'; + | 'modules'; type Config = $ReadOnly<{| generators: Array, @@ -79,7 +79,6 @@ const GENERATORS = { generateShadowNodeCpp.generate, generateShadowNodeH.generate, ], - 'view-configs': [generateViewConfigJs.generate], }; function writeMapToFiles(map: Map, outputDir: string) { @@ -118,7 +117,7 @@ function checkFilesForChanges( module.exports = { generate( - {libraryName, schema, outputDirectory}: Options, + {libraryName, schema, outputDirectory, moduleSpecName}: Options, {generators, test}: Config, ): boolean { schemaValidator.validate(schema); @@ -126,7 +125,7 @@ module.exports = { const generatedFiles = []; for (const name of generators) { for (const generator of GENERATORS[name]) { - generatedFiles.push(...generator(libraryName, schema)); + generatedFiles.push(...generator(libraryName, schema, moduleSpecName)); } } diff --git a/packages/react-native-codegen/src/generators/components/GenerateComponentDescriptorH.js b/packages/react-native-codegen/src/generators/components/GenerateComponentDescriptorH.js index 2656abac66b..2bd7a7817d2 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateComponentDescriptorH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateComponentDescriptorH.js @@ -42,7 +42,11 @@ using ::_CLASSNAME_::ComponentDescriptor = ConcreteComponentDescriptor<::_CLASSN `.trim(); module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'ComponentDescriptors.h'; const componentDescriptors = Object.keys(schema.modules) diff --git a/packages/react-native-codegen/src/generators/components/GenerateComponentHObjCpp.js b/packages/react-native-codegen/src/generators/components/GenerateComponentHObjCpp.js index 0f48703efd0..1d8c8e36e4b 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateComponentHObjCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateComponentHObjCpp.js @@ -263,7 +263,11 @@ function generateCommandHandler( } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'RCTComponentViewHelpers.h'; const componentContent = Object.keys(schema.modules) diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js index ce967b2adfc..58ea1679006 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js @@ -166,7 +166,11 @@ function generateEvent(componentName: string, event): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const moduleComponents: ComponentCollection = Object.keys(schema.modules) .map(moduleName => { const components = schema.modules[moduleName].components; diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js index 653ed415754..7444a724874 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js @@ -221,7 +221,11 @@ function generateEvents(componentName: string, component): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const moduleComponents: ComponentCollection = Object.keys(schema.modules) .map(moduleName => { const components = schema.modules[moduleName].components; diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js index ec818ee8ed6..7032b6c1efa 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js @@ -81,7 +81,11 @@ function getClassExtendString(component): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'Props.cpp'; const allImports: Set = new Set([ '#include ', diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index 94e4bf2a97f..64ffc352ead 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -418,7 +418,11 @@ function getImports(component): Set { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'Props.h'; const allImports: Set = new Set(); diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js index ad16a1f614b..4f48c0cf566 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js @@ -208,7 +208,11 @@ function generateMethods(propsString, commandsString): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const files = new Map(); Object.keys(schema.modules).forEach(moduleName => { const components = schema.modules[moduleName].components; diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js index 27846e460a4..0ee838f894e 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js @@ -158,7 +158,11 @@ function getClassExtendString(component): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const files = new Map(); Object.keys(schema.modules).forEach(moduleName => { const components = schema.modules[moduleName].components; diff --git a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeCpp.js b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeCpp.js index b34401375d5..8784849619f 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeCpp.js @@ -39,7 +39,11 @@ extern const char ::_CLASSNAME_::ComponentName[] = "::_CLASSNAME_::"; `.trim(); module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'ShadowNodes.cpp'; const componentNames = Object.keys(schema.modules) diff --git a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js index a224c41324f..84c22bc3190 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js @@ -49,7 +49,11 @@ using ::_CLASSNAME_::ShadowNode = ConcreteViewShadowNode< `.trim(); module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'ShadowNodes.h'; let hasAnyEvents = false; diff --git a/packages/react-native-codegen/src/generators/components/GenerateTests.js b/packages/react-native-codegen/src/generators/components/GenerateTests.js index 62968fad1c7..0f9a8266bd7 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateTests.js +++ b/packages/react-native-codegen/src/generators/components/GenerateTests.js @@ -133,7 +133,11 @@ function generateTestsString(name, component) { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const fileName = 'Tests.cpp'; const allImports = new Set([ '#include ', diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js index 02133c76f90..c73dd315c8b 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js @@ -21,7 +21,9 @@ describe('GenerateComponentDescriptorH', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentHObjCpp-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentHObjCpp-test.js index 52b638973aa..44528dbbb02 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentHObjCpp-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentHObjCpp-test.js @@ -21,7 +21,9 @@ describe('GenerateComponentHObjCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterCpp-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterCpp-test.js index 14ac106e959..5a17690e597 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterCpp-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterCpp-test.js @@ -21,7 +21,9 @@ describe('GenerateEventEmitterCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterH-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterH-test.js index 2b6a26422aa..3b1974f6653 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterH-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterH-test.js @@ -21,7 +21,9 @@ describe('GenerateEventEmitterH', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsCpp-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsCpp-test.js index f9b9332a125..284c5457aca 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsCpp-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsCpp-test.js @@ -21,7 +21,9 @@ describe('GeneratePropsCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsH-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsH-test.js index 77305fc2c4a..23f8769ebeb 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsH-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsH-test.js @@ -21,7 +21,9 @@ describe('GeneratePropsH', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaDelegate-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaDelegate-test.js index 36f1f9e8a5c..b9c5724c914 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaDelegate-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaDelegate-test.js @@ -21,7 +21,9 @@ describe('GeneratePropsJavaDelegate', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaInterface-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaInterface-test.js index cc1eadab41a..a14ac875cc7 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaInterface-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaInterface-test.js @@ -21,7 +21,9 @@ describe('GeneratePropsJavaInterface', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeCpp-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeCpp-test.js index e023ed51a49..b3cc7efdcab 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeCpp-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeCpp-test.js @@ -21,7 +21,9 @@ describe('GenerateShadowNodeCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeH-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeH-test.js index ea704d4773d..3edd5e3695f 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeH-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeH-test.js @@ -21,7 +21,9 @@ describe('GenerateShadowNodeH', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateTests-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateTests-test.js index 6961d0b1754..8b9f066b0c1 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateTests-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateTests-test.js @@ -21,7 +21,9 @@ describe('GenerateTests', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js index 00bfb6782aa..52b611455dc 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js @@ -106,7 +106,11 @@ function traverseProprety(property): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const nativeModules = Object.keys(schema.modules) .map(moduleName => { const modules = schema.modules[moduleName].nativeModules; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index 4e9809b3172..d7209593966 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -84,7 +84,11 @@ const propertyTemplate = 'virtual ::_RETURN_VALUE_:: ::_PROPERTY_NAME_::(jsi::Runtime &rt::_ARGS_::) = 0;'; module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const nativeModules = Object.keys(schema.modules) .map(moduleName => { const modules = schema.modules[moduleName].nativeModules; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js index 52c2aa83715..221979e2d97 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js @@ -149,7 +149,11 @@ const methodImplementationTemplate = '- (::_RETURN_VALUE_::) ::_PROPERTY_NAME_::::_ARGS_::;'; module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const nativeModules = Object.keys(schema.modules) .map(moduleName => { const modules = schema.modules[moduleName].nativeModules; @@ -243,7 +247,7 @@ module.exports = { }) .join('\n'); - const fileName = 'RCTNativeModules.h'; + const fileName = `${moduleSpecName}.h`; const replacedTemplate = template .replace(/::_MODULES_::/g, modules) .replace(/::_PROTOCOLS_::/g, protocols); diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleMm.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleMm.js index 5acd161969e..d56905285be 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleMm.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleMm.js @@ -56,7 +56,7 @@ const template = ` * LICENSE file in the root directory of this source tree. */ -#include +#include <::_INCLUDE_::> ::_GETTERS_:: namespace facebook { namespace react { @@ -128,7 +128,11 @@ function tranlsateMethodForImplementation(property): string { } module.exports = { - generate(libraryName: string, schema: SchemaType): FilesOutput { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { const nativeModules: {[name: string]: NativeModuleShape} = Object.keys( schema.modules, ) @@ -221,11 +225,12 @@ module.exports = { }) .join('\n'); - const fileName = 'RCTNativeModules.mm'; + const fileName = `${moduleSpecName}-generated.mm`; const replacedTemplate = template .replace(/::_GETTERS_::/g, gettersImplementations) .replace(/::_MODULES_::/g, modules) - .replace(/::_LIBRARY_NAME_::/g, libraryName); + .replace(/::_LIBRARY_NAME_::/g, libraryName) + .replace(/::_INCLUDE_::/g, `${moduleSpecName}/${moduleSpecName}.h`); return new Map([[fileName, replacedTemplate]]); }, }; diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js index f4a9e1edfa0..6dbe02f952f 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js +++ b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js @@ -21,7 +21,9 @@ describe('GenerateModuleCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleH-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleH-test.js index 200eb955e64..918184b9ff5 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleH-test.js +++ b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleH-test.js @@ -21,7 +21,9 @@ describe('GenerateModuleCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleHObjCpp-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleHObjCpp-test.js index ae8da6f16ba..b41441cb2da 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleHObjCpp-test.js +++ b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleHObjCpp-test.js @@ -21,7 +21,9 @@ describe('GenerateModuleHObjCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleMm-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleMm-test.js index 9edb472a33b..d6a59847b4a 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleMm-test.js +++ b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleMm-test.js @@ -21,7 +21,9 @@ describe('GenerateModuleHObjCpp', () => { const fixture = fixtures[fixtureName]; it(`can generate fixture ${fixtureName}`, () => { - expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); }); }); }); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap index 0013895d867..b46d05b4e44 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap @@ -2,7 +2,7 @@ exports[`GenerateModuleHObjCpp can generate fixture COMPLEX_OBJECTS 1`] = ` Map { - "RCTNativeModules.h" => " + "SampleSpec.h" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -169,7 +169,7 @@ public: exports[`GenerateModuleHObjCpp can generate fixture EMPTY_NATIVE_MODULES 1`] = ` Map { - "RCTNativeModules.h" => " + "SampleSpec.h" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -218,7 +218,7 @@ public: exports[`GenerateModuleHObjCpp can generate fixture SIMPLE_NATIVE_MODULES 1`] = ` Map { - "RCTNativeModules.h" => " + "SampleSpec.h" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -324,7 +324,7 @@ public: exports[`GenerateModuleHObjCpp can generate fixture TWO_MODULES_DIFFERENT_FILES 1`] = ` Map { - "RCTNativeModules.h" => " + "SampleSpec.h" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -388,7 +388,7 @@ public: exports[`GenerateModuleHObjCpp can generate fixture TWO_MODULES_SAME_FILE 1`] = ` Map { - "RCTNativeModules.h" => " + "SampleSpec.h" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleMm-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleMm-test.js.snap index 36ee8c57fd6..7ce647467ad 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleMm-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleMm-test.js.snap @@ -2,7 +2,7 @@ exports[`GenerateModuleHObjCpp can generate fixture COMPLEX_OBJECTS 1`] = ` Map { - "RCTNativeModules.mm" => " + "SampleSpec-generated.mm" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -10,7 +10,7 @@ Map { * LICENSE file in the root directory of this source tree. */ -#include +#include @implementation RCTCxxConvert (NativeSampleTurboModule_SpecDifficultReturnType) + (RCTManagedPointer *)JS_NativeSampleTurboModule_SpecDifficultReturnType:(id)json { @@ -51,7 +51,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(id " + "SampleSpec-generated.mm" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -59,7 +59,7 @@ Map { * LICENSE file in the root directory of this source tree. */ -#include +#include namespace facebook { namespace react { @@ -80,7 +80,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(id " + "SampleSpec-generated.mm" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -88,7 +88,7 @@ Map { * LICENSE file in the root directory of this source tree. */ -#include +#include namespace facebook { namespace react { @@ -157,7 +157,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(id " + "SampleSpec-generated.mm" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -165,7 +165,7 @@ Map { * LICENSE file in the root directory of this source tree. */ -#include +#include namespace facebook { @@ -199,7 +199,7 @@ NativeSample2TurboModuleSpecJSI::NativeSample2TurboModuleSpecJSI(id " + "SampleSpec-generated.mm" => " /** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -207,7 +207,7 @@ Map { * LICENSE file in the root directory of this source tree. */ -#include +#include namespace facebook {