diff --git a/packages/react-native-codegen/BUCK b/packages/react-native-codegen/BUCK index 9fab520a5130b5..4ca87f8b453636 100644 --- a/packages/react-native-codegen/BUCK +++ b/packages/react-native-codegen/BUCK @@ -3,18 +3,7 @@ load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native") load("@fbsource//tools/build_defs:fb_xplat_cxx_binary.bzl", "fb_xplat_cxx_binary") load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "rn_xplat_cxx_library") load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace") -load("@fbsource//xplat/js/react-native-github/packages/react-native-codegen:DEFS.bzl", "rn_codegen_test") - -fb_native.sh_binary( - name = "copy_fixture_schema", - main = "buck_tests/copy_fixture.sh", - resources = [ - "buck_tests/copy-fixture.js", - "buck_tests/copy_fixture.sh", - "fbsource//xplat/js:setup_env", - "src/generators/__test_fixtures__/fixtures.js", - ], -) +load("@fbsource//xplat/js/react-native-github/packages/react-native-codegen:DEFS.bzl", "rn_codegen") fb_native.sh_binary( name = "write_to_json", @@ -44,64 +33,20 @@ fb_native.sh_binary( visibility = ["PUBLIC"], ) -rn_codegen_test( - fixture_name = "INTERFACE_ONLY", -) - -rn_codegen_test( - fixture_name = "BOOLEAN_PROP", -) - -rn_codegen_test( - fixture_name = "STRING_PROP", -) - -rn_codegen_test( - fixture_name = "INTEGER_PROPS", -) - -rn_codegen_test( - fixture_name = "FLOAT_PROPS", -) - -rn_codegen_test( - fixture_name = "COLOR_PROP", -) - -rn_codegen_test( - fixture_name = "IMAGE_PROP", -) - -rn_codegen_test( - fixture_name = "POINT_PROP", -) - -rn_codegen_test( - fixture_name = "ARRAY_PROPS", -) - -rn_codegen_test( - fixture_name = "MULTI_NATIVE_PROP", -) - -rn_codegen_test( - fixture_name = "ENUM_PROP", -) - -rn_codegen_test( - fixture_name = "EVENT_PROPS", -) - -rn_codegen_test( - fixture_name = "EVENT_NESTED_OBJECT_PROPS", -) - -rn_codegen_test( - fixture_name = "TWO_COMPONENTS_SAME_FILE", +fb_native.genrule( + name = "codegen_tests_schema", + srcs = glob( + [ + "**/e2e/__test_fixtures__/*NativeComponent.js", + ], + ), + cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:write_to_json) $OUT $SRCS", + out = "schema-codegen_tests.json", ) -rn_codegen_test( - fixture_name = "TWO_COMPONENTS_DIFFERENT_FILES", +rn_codegen( + name = "codegen_tests", + schema_target = ":codegen_tests_schema", ) fb_xplat_cxx_binary( @@ -120,21 +65,7 @@ fb_xplat_cxx_binary( ], visibility = ["PUBLIC"], deps = [ - ":generated_components-ARRAY_PROPS", - ":generated_components-BOOLEAN_PROP", - ":generated_components-COLOR_PROP", - ":generated_components-ENUM_PROP", - ":generated_components-EVENT_NESTED_OBJECT_PROPS", - ":generated_components-EVENT_PROPS", - ":generated_components-FLOAT_PROPS", - ":generated_components-IMAGE_PROP", - ":generated_components-INTEGER_PROPS", - ":generated_components-INTERFACE_ONLY", - ":generated_components-MULTI_NATIVE_PROP", - ":generated_components-POINT_PROP", - ":generated_components-STRING_PROP", - ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", - ":generated_components-TWO_COMPONENTS_SAME_FILE", + ":generated_components-codegen_tests", ], ) @@ -157,21 +88,7 @@ rn_xplat_cxx_library( "PUBLIC", ], deps = [ - ":generated_components-ARRAY_PROPS", - ":generated_components-BOOLEAN_PROP", - ":generated_components-COLOR_PROP", - ":generated_components-ENUM_PROP", - ":generated_components-EVENT_NESTED_OBJECT_PROPS", - ":generated_components-EVENT_PROPS", - ":generated_components-FLOAT_PROPS", - ":generated_components-IMAGE_PROP", - ":generated_components-INTEGER_PROPS", - ":generated_components-INTERFACE_ONLY", - ":generated_components-MULTI_NATIVE_PROP", - ":generated_components-POINT_PROP", - ":generated_components-STRING_PROP", - ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", - ":generated_components-TWO_COMPONENTS_SAME_FILE", + ":generated_components-codegen_tests", ], ) diff --git a/packages/react-native-codegen/DEFS.bzl b/packages/react-native-codegen/DEFS.bzl index 0f8ed61bbf08f2..56f12798b3a695 100644 --- a/packages/react-native-codegen/DEFS.bzl +++ b/packages/react-native-codegen/DEFS.bzl @@ -14,19 +14,6 @@ load( "rn_xplat_cxx_library", ) -def rn_codegen_test( - fixture_name = ""): - copy_schema_name = "copy_schema-{}".format(fixture_name) - - fb_native.genrule( - name = copy_schema_name, - srcs = [], - cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:copy_fixture_schema) {} $OUT".format(fixture_name), - out = "schema-{}.json".format(fixture_name), - ) - - rn_codegen(fixture_name, ":{}".format(copy_schema_name)) - def rn_codegen( name = "", schema_target = ""): diff --git a/packages/react-native-codegen/buck_tests/copy-fixture.js b/packages/react-native-codegen/buck_tests/copy-fixture.js deleted file mode 100644 index fc9f09e34aaed5..00000000000000 --- a/packages/react-native-codegen/buck_tests/copy-fixture.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - * @format - */ - -'use strict'; - -const fs = require('fs'); - -const fixtures = require('../src/generators/__test_fixtures__/fixtures.js'); - -const args = process.argv.slice(2); -if (args.length !== 2) { - throw new Error( - 'Expected to receive the fixture name and output directory as the only arg', - ); -} - -const fixtureName = args[0]; -const outputPath = args[1]; - -const fixture = fixtures[fixtureName]; - -if (fixture == null) { - throw new Error(`Can't find fixture with name ${fixtureName}`); -} - -fs.writeFileSync(outputPath, JSON.stringify(fixture, null, 2)); diff --git a/packages/react-native-codegen/buck_tests/copy_fixture.sh b/packages/react-native-codegen/buck_tests/copy_fixture.sh deleted file mode 100755 index d2cbcbdba1abbf..00000000000000 --- a/packages/react-native-codegen/buck_tests/copy_fixture.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -e -set -u - -THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) - -# shellcheck source=xplat/js/env-utils/setup_env_vars.sh -source "$THIS_DIR/../../../../env-utils/setup_env_vars.sh" - -exec "$FLOW_NODE_BINARY" "$THIS_DIR/copy-fixture.js" "$@" diff --git a/packages/react-native-codegen/buck_tests/emptyFile.cpp b/packages/react-native-codegen/buck_tests/emptyFile.cpp index 89c5b84d2741fd..156913d4dfae5d 100644 --- a/packages/react-native-codegen/buck_tests/emptyFile.cpp +++ b/packages/react-native-codegen/buck_tests/emptyFile.cpp @@ -1,18 +1,6 @@ -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import +#import + +// TODO: Import every prop and event to asset they're generated int main(){ return 0; diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/ArrayPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/ArrayPropsNativeComponent.js new file mode 100644 index 00000000000000..930868ebc610c1 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/ArrayPropsNativeComponent.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + PointValue, + ColorValue, +} from '../../../../Libraries/StyleSheet/StyleSheetTypes'; +import type {ImageSource} from '../../../../Libraries/Image/ImageSource'; +import type { + Int32, + Float, + WithDefault, +} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + names?: $ReadOnlyArray, + disableds?: $ReadOnlyArray, + progress?: $ReadOnlyArray, + radii?: $ReadOnlyArray, + colors?: $ReadOnlyArray, + srcs?: $ReadOnlyArray, + points?: $ReadOnlyArray, + sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>, +|}>; + +export default codegenNativeComponent('ArrayPropsNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/BooleanPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/BooleanPropNativeComponent.js new file mode 100644 index 00000000000000..c0805edf14e5ab --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/BooleanPropNativeComponent.js @@ -0,0 +1,26 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {WithDefault} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + disabled?: WithDefault, +|}>; + +export default codegenNativeComponent( + 'BooleanPropNativeComponent', +); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/ColorPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/ColorPropNativeComponent.js new file mode 100644 index 00000000000000..08e6f8585353ce --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/ColorPropNativeComponent.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {ColorValue} from '../../../../Libraries/StyleSheet/StyleSheetTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + tintColor?: ColorValue, +|}>; + +export default codegenNativeComponent('ColorPropNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/EnumPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/EnumPropNativeComponent.js new file mode 100644 index 00000000000000..e9e691b7ad90db --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/EnumPropNativeComponent.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {WithDefault} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + alignment?: WithDefault<'top' | 'center' | 'bottom-right', 'center'>, +|}>; + +export default codegenNativeComponent('EnumPropNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/EventNestedObjectPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/EventNestedObjectPropsNativeComponent.js new file mode 100644 index 00000000000000..be14116d242eea --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/EventNestedObjectPropsNativeComponent.js @@ -0,0 +1,43 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + Int32, + BubblingEvent, + WithDefault, +} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type OnChangeEvent = $ReadOnly<{| + location: { + source: { + url: string, + }, + x: Int32, + y: Int32, + }, +|}>; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + disabled?: WithDefault, + + // Events + onChange?: ?(event: BubblingEvent) => void, +|}>; + +export default codegenNativeComponent( + 'EventNestedObjectPropsNativeComponent', +); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/EventPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/EventPropsNativeComponent.js new file mode 100644 index 00000000000000..4dfd1e6a0c9832 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/EventPropsNativeComponent.js @@ -0,0 +1,51 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + Int32, + Float, + BubblingEvent, + DirectEvent, + WithDefault, +} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type OnChangeEvent = $ReadOnly<{| + value: boolean, + source?: string, + progress: ?Int32, + scale?: ?Float, +|}>; + +type OnEventDirect = $ReadOnly<{| + value: boolean, +|}>; + +type OnOrientationChangeEvent = $ReadOnly<{| + orientation: 'landscape' | 'portrait', +|}>; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + disabled?: WithDefault, + + // Events + onChange?: ?(event: BubblingEvent) => void, + onEventDirect?: ?(event: DirectEvent) => void, + onOrientationChange?: ?(event: DirectEvent) => void, + onEnd?: ?(event: BubblingEvent) => void, +|}>; + +export default codegenNativeComponent('EventPropsNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/FloatPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/FloatPropsNativeComponent.js new file mode 100644 index 00000000000000..be0e18f1ee9a21 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/FloatPropsNativeComponent.js @@ -0,0 +1,32 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + WithDefault, + Float, +} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + blurRadius?: WithDefault, + blurRadius2?: WithDefault, + blurRadius3?: WithDefault, + blurRadius4?: WithDefault, + blurRadius5?: WithDefault, + blurRadius6?: WithDefault, +|}>; + +export default codegenNativeComponent('FloatPropsNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/ImagePropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/ImagePropNativeComponent.js new file mode 100644 index 00000000000000..32f6549984ff98 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/ImagePropNativeComponent.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {ImageSource} from '../../../../Libraries/Image/ImageSource'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + thumbImage?: ImageSource, +|}>; + +export default codegenNativeComponent('ImagePropNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/IntegerPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/IntegerPropNativeComponent.js new file mode 100644 index 00000000000000..e539db1d02f995 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/IntegerPropNativeComponent.js @@ -0,0 +1,31 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + WithDefault, + Int32, +} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + progress1?: WithDefault, + progress2?: WithDefault, + progress3?: WithDefault, +|}>; + +export default codegenNativeComponent( + 'IntegerPropNativeComponent', +); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/InterfaceOnlyNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/InterfaceOnlyNativeComponent.js new file mode 100644 index 00000000000000..510ae82ce2fe3a --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/InterfaceOnlyNativeComponent.js @@ -0,0 +1,36 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + BubblingEvent, + WithDefault, +} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + accessibilityHint?: WithDefault, + + // Events + onChange?: ?(event: BubblingEvent<$ReadOnly<{|value: boolean|}>>) => void, +|}>; + +export default codegenNativeComponent( + 'InterfaceOnlyNativeComponent', + { + interfaceOnly: true, + paperComponentName: 'RCTInterfaceOnlyComponent', + }, +); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/MultiNativePropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/MultiNativePropNativeComponent.js new file mode 100644 index 00000000000000..04b75d30813b95 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/MultiNativePropNativeComponent.js @@ -0,0 +1,33 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type { + PointValue, + ColorValue, +} from '../../../../Libraries/StyleSheet/StyleSheetTypes'; +import type {ImageSource} from '../../../../Libraries/Image/ImageSource'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + thumbImage?: ImageSource, + color?: ColorValue, + thumbTintColor?: ColorValue, + point?: PointValue, +|}>; + +export default codegenNativeComponent( + 'MultiNativePropNativeComponent', +); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/NoPropsNoEventsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/NoPropsNoEventsNativeComponent.js new file mode 100644 index 00000000000000..a2b1bc60912804 --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/NoPropsNoEventsNativeComponent.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // No Props or events +|}>; + +export default codegenNativeComponent( + 'NoPropsNoEventsNativeComponent', +); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/PointPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/PointPropNativeComponent.js new file mode 100644 index 00000000000000..d2c6d8f42dd37f --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/PointPropNativeComponent.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {PointValue} from '../../../../Libraries/StyleSheet/StyleSheetTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + startPoint?: PointValue, +|}>; + +export default codegenNativeComponent('PointPropNativeComponent'); diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/StringPropNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/StringPropNativeComponent.js new file mode 100644 index 00000000000000..5b50a97537ad3a --- /dev/null +++ b/packages/react-native-codegen/e2e/__test_fixtures__/StringPropNativeComponent.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {WithDefault} from '../../../../Libraries/Types/CodegenTypes'; +import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; +import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent'; + +type NativeProps = $ReadOnly<{| + ...ViewProps, + + // Props + accessibilityHint?: WithDefault, + accessibilityRole?: WithDefault, +|}>; + +export default codegenNativeComponent('StringPropNativeComponent'); diff --git a/packages/react-native-codegen/package.json b/packages/react-native-codegen/package.json index 85a9de6d5acfaf..502bf0b639415f 100644 --- a/packages/react-native-codegen/package.json +++ b/packages/react-native-codegen/package.json @@ -7,6 +7,7 @@ "url": "git@github.com:facebook/react-native.git" }, "dependencies": { + "flow-parser": "^0.102.0", "jscodeshift": "^0.6.2", "nullthrows": "^1.1.0" }, diff --git a/packages/react-native-codegen/src/cli/combine/__tests__/__snapshots__/combine-js-to-schema-test.js.snap b/packages/react-native-codegen/src/cli/combine/__tests__/__snapshots__/combine-js-to-schema-test.js.snap deleted file mode 100644 index 78cb4b43ae8f63..00000000000000 --- a/packages/react-native-codegen/src/cli/combine/__tests__/__snapshots__/combine-js-to-schema-test.js.snap +++ /dev/null @@ -1,14 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should combine files 1`] = ` -Object { - "modules": Object { - "ComponentOne": Object { - "foo": "baz", - }, - "ComponentTwo": Object { - "foo": "bar", - }, - }, -} -`; diff --git a/packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js b/packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js deleted file mode 100644 index bcf3cc6aa8084c..00000000000000 --- a/packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @emails oncall+react_native - * @flow strict-local - * @format - */ - -import combine from '../combine-js-to-schema'; - -jest.mock( - '/test/module/SchemaOne', - () => ({ - modules: { - ComponentOne: { - foo: 'baz', - }, - }, - }), - {virtual: true}, -); - -jest.mock( - '/test/module/SchemaTwo', - () => ({ - modules: { - ComponentTwo: { - foo: 'bar', - }, - }, - }), - {virtual: true}, -); - -jest.mock('/test/module/NotASchema', () => ({}), {virtual: true}); - -test('should combine files', () => { - const files = [ - '/test/module/SchemaOne', - '/test/module/SchemaTwo', - '/test/module/NotASchema', - ]; - expect(combine(files)).toMatchSnapshot(); -}); - -test('should not throw for failed require', () => { - const files = ['/test/module/does/not/exist']; - expect(() => combine(files)).not.toThrow(); -}); diff --git a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js index f1815bf727201e..6d7671ea5d975e 100644 --- a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js +++ b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js @@ -11,14 +11,22 @@ 'use strict'; import type {SchemaType} from '../../CodegenSchema.js'; -const SchemaParser = require('../../parsers/schema'); +const FlowParser = require('../../parsers/flow'); +const fs = require('fs'); function combineSchemas(files: Array): SchemaType { return files.reduce( (merged, filename) => { - const schema = SchemaParser.parse(filename); - if (schema && schema.modules) { - merged.modules = {...merged.modules, ...schema.modules}; + const contents = fs.readFileSync(filename, 'utf8'); + if ( + contents && + /export\s+default\s+codegenNativeComponent/dev/null + "$INSTALL_NODE_MODULES" +popd >/dev/null + exec "$FLOW_NODE_BINARY" "$THIS_DIR/combine-js-to-schema-cli.js" "$@"