From 8be9dbfcc1a569f9fd0b2f22de6aaff7bd34acad Mon Sep 17 00:00:00 2001 From: Tarun Chauhan Date: Tue, 21 Feb 2023 03:46:38 -0800 Subject: [PATCH] consolidate parsers component schema to common root (#36219) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: > [Codegen 85] The parses/flow/components/schema.js and parses/typescript/components/schema.js are the same. Move the schema.js from the one of the two folders to the parsers common root. Delete the other. Update the references to use the shared file. Part of the Codegen ☂️ Issue https://github.com/facebook/react-native/issues/34872 ## Changelog [Internal] [Changed] - Consolidated the schema.js files for parses/flow/components and parses/typescript/components to a common root. Pull Request resolved: https://github.com/facebook/react-native/pull/36219 Test Plan: Run ```yarn jest react-native-codegen``` Reviewed By: christophpurrer Differential Revision: D43444666 Pulled By: cipolleschi fbshipit-source-id: 24d791fd3a8110730d3f6054497ea3a31549a5a5 --- .../parsers/__tests__/parsers-commons-test.js | 2 +- .../src/parsers/flow/components/index.js | 2 +- .../src/parsers/flow/parser.js | 2 +- .../src/parsers/parsers-commons.js | 2 +- .../parsers/{flow/components => }/schema.js | 4 +- .../parsers/typescript/components/index.js | 2 +- .../parsers/typescript/components/schema.js | 62 ------------------- .../src/parsers/typescript/parser.js | 2 +- 8 files changed, 8 insertions(+), 70 deletions(-) rename packages/react-native-codegen/src/parsers/{flow/components => }/schema.js (97%) delete mode 100644 packages/react-native-codegen/src/parsers/typescript/components/schema.js diff --git a/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js b/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js index 95ef4306ebe..2d8d96175e8 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/parsers-commons-test.js @@ -23,7 +23,7 @@ import { import type {ParserType} from '../errors'; const {Visitor} = require('../flow/Visitor'); -const {wrapComponentSchema} = require('../flow/components/schema'); +const {wrapComponentSchema} = require('../schema.js'); const {buildComponentSchema} = require('../flow/components'); const {buildModuleSchema} = require('../flow/modules'); const {isModuleRegistryCall} = require('../utils.js'); diff --git a/packages/react-native-codegen/src/parsers/flow/components/index.js b/packages/react-native-codegen/src/parsers/flow/components/index.js index 50026ebf6c1..35106bcab38 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/index.js +++ b/packages/react-native-codegen/src/parsers/flow/components/index.js @@ -11,7 +11,7 @@ 'use strict'; import type {TypeDeclarationMap} from '../../utils'; import type {CommandOptions} from './options'; -import type {ComponentSchemaBuilderConfig} from './schema.js'; +import type {ComponentSchemaBuilderConfig} from '../../schema.js'; const {getTypes} = require('../utils'); const {getCommands} = require('./commands'); diff --git a/packages/react-native-codegen/src/parsers/flow/parser.js b/packages/react-native-codegen/src/parsers/flow/parser.js index bdcaf3b9eca..1e12d7daae8 100644 --- a/packages/react-native-codegen/src/parsers/flow/parser.js +++ b/packages/react-native-codegen/src/parsers/flow/parser.js @@ -28,7 +28,7 @@ const flowParser = require('flow-parser'); const {buildSchema} = require('../parsers-commons'); const {Visitor} = require('./Visitor'); const {buildComponentSchema} = require('./components'); -const {wrapComponentSchema} = require('./components/schema'); +const {wrapComponentSchema} = require('../schema.js'); const {buildModuleSchema} = require('./modules'); const fs = require('fs'); diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index 2509d384da9..0a674eb85f4 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -26,7 +26,7 @@ import type { import type {Parser} from './parser'; import type {ParserType} from './errors'; import type {ParserErrorCapturer, TypeDeclarationMap} from './utils'; -import type {ComponentSchemaBuilderConfig} from './flow/components/schema'; +import type {ComponentSchemaBuilderConfig} from './schema.js'; const { getConfigType, diff --git a/packages/react-native-codegen/src/parsers/flow/components/schema.js b/packages/react-native-codegen/src/parsers/schema.js similarity index 97% rename from packages/react-native-codegen/src/parsers/flow/components/schema.js rename to packages/react-native-codegen/src/parsers/schema.js index ec9447251c1..0fdf3c37511 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/schema.js +++ b/packages/react-native-codegen/src/parsers/schema.js @@ -4,8 +4,8 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict * @format + * @flow strict */ 'use strict'; @@ -18,7 +18,7 @@ import type { ExtendsPropsShape, SchemaType, OptionsShape, -} from '../../../CodegenSchema.js'; +} from '../CodegenSchema.js'; export type ComponentSchemaBuilderConfig = $ReadOnly<{ filename: string, diff --git a/packages/react-native-codegen/src/parsers/typescript/components/index.js b/packages/react-native-codegen/src/parsers/typescript/components/index.js index d6c66d49a63..41b5c0e41c2 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/index.js @@ -12,7 +12,7 @@ import type {ExtendsPropsShape} from '../../../CodegenSchema.js'; import type {TypeDeclarationMap} from '../../utils'; import type {CommandOptions} from './options'; -import type {ComponentSchemaBuilderConfig} from './schema.js'; +import type {ComponentSchemaBuilderConfig} from '../../schema.js'; const {getTypes} = require('../utils'); const {getCommands} = require('./commands'); diff --git a/packages/react-native-codegen/src/parsers/typescript/components/schema.js b/packages/react-native-codegen/src/parsers/typescript/components/schema.js deleted file mode 100644 index ab165031cd2..00000000000 --- a/packages/react-native-codegen/src/parsers/typescript/components/schema.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and 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 strict - */ - -'use strict'; - -import type { - EventTypeShape, - NamedShape, - CommandTypeAnnotation, - PropTypeAnnotation, - ExtendsPropsShape, - SchemaType, - OptionsShape, -} from '../../../CodegenSchema.js'; - -export type ComponentSchemaBuilderConfig = $ReadOnly<{ - filename: string, - componentName: string, - extendsProps: $ReadOnlyArray, - events: $ReadOnlyArray, - props: $ReadOnlyArray>, - commands: $ReadOnlyArray>, - options?: ?OptionsShape, -}>; - -function wrapComponentSchema({ - filename, - componentName, - extendsProps, - events, - props, - options, - commands, -}: ComponentSchemaBuilderConfig): SchemaType { - return { - modules: { - [filename]: { - type: 'Component', - components: { - [componentName]: { - ...(options || {}), - extendsProps, - events, - props, - commands, - }, - }, - }, - }, - }; -} - -module.exports = { - wrapComponentSchema, -}; diff --git a/packages/react-native-codegen/src/parsers/typescript/parser.js b/packages/react-native-codegen/src/parsers/typescript/parser.js index 9b40a7da55b..84b2dc4c159 100644 --- a/packages/react-native-codegen/src/parsers/typescript/parser.js +++ b/packages/react-native-codegen/src/parsers/typescript/parser.js @@ -28,7 +28,7 @@ const babelParser = require('@babel/parser'); const {buildSchema} = require('../parsers-commons'); const {Visitor} = require('./Visitor'); const {buildComponentSchema} = require('./components'); -const {wrapComponentSchema} = require('./components/schema'); +const {wrapComponentSchema} = require('../schema.js'); const {buildModuleSchema} = require('./modules'); const fs = require('fs');