From f7040fc5e0fe355075aac0cf27d0cfab0f742760 Mon Sep 17 00:00:00 2001 From: shivenmian Date: Mon, 28 Nov 2022 08:28:51 -0800 Subject: [PATCH] chore: renamed react-native-codegen to @react-native/codegen (#34804) Summary: Renamed react-native-codegen package to react-native/codegen and updated references, without changing the folder name; part of RFC480 (https://github.com/facebook/react-native/issues/34692). Follow-up from https://github.com/facebook/react-native/pull/34578 ## Changelog [General] [Changed] - Renamed react-native-codegen package to react-native/codegen and updated references Pull Request resolved: https://github.com/facebook/react-native/pull/34804 Reviewed By: cortinico Differential Revision: D39883584 Pulled By: hoxyq fbshipit-source-id: 0ef384b75c6edd248b31e37b8f05f64b4d39ca6f --- .circleci/verdaccio.yml | 3 --- .gitignore | 2 +- ReactAndroid/build.gradle | 2 +- packages/babel-plugin-codegen/index.js | 12 ++++++------ packages/babel-plugin-codegen/package.json | 2 +- packages/eslint-plugin-specs/package.json | 2 +- packages/eslint-plugin-specs/react-native-modules.js | 12 ++++++------ packages/react-native-codegen/README.md | 8 ++++---- packages/react-native-codegen/package.json | 2 +- .../main/kotlin/com/facebook/react/ReactExtension.kt | 6 +++--- packages/rn-tester/android/app/build.gradle | 4 ++-- repo-config/package.json | 2 +- scripts/cocoapods/__tests__/codegen-test.rb | 6 +++--- scripts/cocoapods/codegen.rb | 2 +- scripts/codegen/codegen-utils.js | 4 ++-- scripts/codegen/generate-artifacts-executor.js | 2 +- scripts/generate-provider-cli.js | 2 +- scripts/react_native_pods_utils/script_phases.sh | 4 ++-- scripts/set-rn-version.js | 6 +++--- template/android/app/build.gradle | 4 ++-- 20 files changed, 42 insertions(+), 45 deletions(-) diff --git a/.circleci/verdaccio.yml b/.circleci/verdaccio.yml index 67f855a753178f..cec3a220475903 100644 --- a/.circleci/verdaccio.yml +++ b/.circleci/verdaccio.yml @@ -19,9 +19,6 @@ packages: '@react-native/*': access: $all publish: $all - 'react-native-codegen': - access: $all - publish: $all '@*/*': access: $all publish: $authenticated diff --git a/.gitignore b/.gitignore index 7611c0691d574e..ca4b7693511f28 100644 --- a/.gitignore +++ b/.gitignore @@ -113,7 +113,7 @@ package-lock.json !/packages/rn-tester/Pods/__offline_mirrors_hermes__ !/packages/rn-tester/Pods/__offline_mirrors_jsc__ -# react-native-codegen +# @react-native/codegen /React/FBReactNativeSpec/FBReactNativeSpec /packages/react-native-codegen/lib /packages/react-native-codegen/tmp/ diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 3f285029101ac3..6be7ca01bb1fea 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -641,7 +641,7 @@ react { reactNativeDir = file("$projectDir/..") // We search for the codegen in either one of the `node_modules` folder or in the // root packages folder (that's for when we build from source without calling `yarn install`). - codegenDir = file(findNodeModulePath(projectDir, "react-native-codegen") ?: "../packages/react-native-codegen/") + codegenDir = file(findNodeModulePath(projectDir, "@react-native/codegen") ?: "../packages/react-native-codegen/") } apply plugin: "org.jetbrains.kotlin.android" diff --git a/packages/babel-plugin-codegen/index.js b/packages/babel-plugin-codegen/index.js index b1a11612ecaebe..bb83feb4070e86 100644 --- a/packages/babel-plugin-codegen/index.js +++ b/packages/babel-plugin-codegen/index.js @@ -14,14 +14,14 @@ let flowParser, typeScriptParser, RNCodegen; const {basename} = require('path'); try { - flowParser = require('react-native-codegen/src/parsers/flow'); - typeScriptParser = require('react-native-codegen/src/parsers/typescript'); - RNCodegen = require('react-native-codegen/src/generators/RNCodegen'); + flowParser = require('@react-native/codegen/src/parsers/flow'); + typeScriptParser = require('@react-native/codegen/src/parsers/typescript'); + RNCodegen = require('@react-native/codegen/src/generators/RNCodegen'); } catch (e) { // Fallback to lib when source doesn't exit (e.g. when installed as a dev dependency) - flowParser = require('react-native-codegen/lib/parsers/flow'); - typeScriptParser = require('react-native-codegen/lib/parsers/typescript'); - RNCodegen = require('react-native-codegen/lib/generators/RNCodegen'); + flowParser = require('@react-native/codegen/lib/parsers/flow'); + typeScriptParser = require('@react-native/codegen/lib/parsers/typescript'); + RNCodegen = require('@react-native/codegen/lib/generators/RNCodegen'); } function parseFile(filename, code) { diff --git a/packages/babel-plugin-codegen/package.json b/packages/babel-plugin-codegen/package.json index 2706e70e2fc327..f91f51da913905 100644 --- a/packages/babel-plugin-codegen/package.json +++ b/packages/babel-plugin-codegen/package.json @@ -11,7 +11,7 @@ "index.js" ], "dependencies": { - "react-native-codegen": "*" + "@react-native/codegen": "*" }, "devDependencies": { "@babel/core": "^7.14.0" diff --git a/packages/eslint-plugin-specs/package.json b/packages/eslint-plugin-specs/package.json index b27d8d7bf2f78d..02c383a96ac0aa 100644 --- a/packages/eslint-plugin-specs/package.json +++ b/packages/eslint-plugin-specs/package.json @@ -17,10 +17,10 @@ "@babel/eslint-parser": "^7.18.2", "@babel/plugin-transform-flow-strip-types": "^7.0.0", "@babel/preset-flow": "^7.17.12", + "@react-native/codegen": "*", "flow-parser": "^0.185.0", "make-dir": "^2.1.0", "pirates": "^4.0.1", - "react-native-codegen": "*", "source-map-support": "0.5.0" }, "license": "MIT" diff --git a/packages/eslint-plugin-specs/react-native-modules.js b/packages/eslint-plugin-specs/react-native-modules.js index f303ab539eba12..19584626f95c16 100644 --- a/packages/eslint-plugin-specs/react-native-modules.js +++ b/packages/eslint-plugin-specs/react-native-modules.js @@ -26,7 +26,7 @@ let RNParserUtils; function requireModuleParser() { if (RNModuleParser == null || RNParserUtils == null) { - // If using this externally, we leverage react-native-codegen as published form + // If using this externally, we leverage @react-native/codegen as published form if (!PACKAGE_USAGE) { const config = { only: [/react-native-codegen\/src\//], @@ -34,18 +34,18 @@ function requireModuleParser() { }; withBabelRegister(config, () => { - RNModuleParser = require('react-native-codegen/src/parsers/flow/modules'); - RNParserUtils = require('react-native-codegen/src/parsers/utils'); + RNModuleParser = require('@react-native/codegen/src/parsers/flow/modules'); + RNParserUtils = require('@react-native/codegen/src/parsers/utils'); }); } else { const config = { - only: [/react-native-codegen\/lib\//], + only: [/@react-native\/codegen\/lib\//], plugins: [require('@babel/plugin-transform-flow-strip-types').default], }; withBabelRegister(config, () => { - RNModuleParser = require('react-native-codegen/lib/parsers/flow/modules'); - RNParserUtils = require('react-native-codegen/lib/parsers/utils'); + RNModuleParser = require('@react-native/codegen/lib/parsers/flow/modules'); + RNParserUtils = require('@react-native/codegen/lib/parsers/flow/utils'); }); } } diff --git a/packages/react-native-codegen/README.md b/packages/react-native-codegen/README.md index d1661e4e5bbfb6..2380d87f716a3a 100644 --- a/packages/react-native-codegen/README.md +++ b/packages/react-native-codegen/README.md @@ -1,17 +1,17 @@ -# react-native-codegen +# @react-native/codegen [![Version][version-badge]][package] ## Installation ``` -yarn add --dev react-native-codegen +yarn add --dev @react-native/codegen ``` *Note: We're using `yarn` to install deps. Feel free to change commands to use `npm` 3+ and `npx` if you like* -[version-badge]: https://img.shields.io/npm/v/react-native-codegen?style=flat-square -[package]: https://www.npmjs.com/package/react-native-codegen +[version-badge]: https://img.shields.io/npm/v/@react-native/codegen?style=flat-square +[package]: https://www.npmjs.com/package/@react-native/codegen ## Testing diff --git a/packages/react-native-codegen/package.json b/packages/react-native-codegen/package.json index 485356731f0bd6..da20ee59562732 100644 --- a/packages/react-native-codegen/package.json +++ b/packages/react-native-codegen/package.json @@ -1,5 +1,5 @@ { - "name": "react-native-codegen", + "name": "@react-native/codegen", "version": "0.72.0", "description": "⚛️ Code generation tools for React Native", "homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/react-native-codegen", diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt index 5dfb3737ee9d3e..553bc175020944 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt @@ -31,7 +31,7 @@ abstract class ReactExtension @Inject constructor(project: Project) { /** * The path to the react-native NPM package folder. * - * Default: ${rootProject.dir}/../node_modules/react-native-codegen + * Default: ${rootProject.dir}/../node_modules/react-native */ val reactNativeDir: DirectoryProperty = objects.directoryProperty().convention(root.dir("node_modules/react-native")) @@ -121,10 +121,10 @@ abstract class ReactExtension @Inject constructor(project: Project) { /** * The path to the react-native-codegen NPM package folder. * - * Default: ${rootProject.dir}/../node_modules/react-native-codegen + * Default: ${rootProject.dir}/../node_modules/@react-native/codegen */ val codegenDir: DirectoryProperty = - objects.directoryProperty().convention(root.dir("node_modules/react-native-codegen")) + objects.directoryProperty().convention(root.dir("node_modules/@react-native/codegen")) /** * The root directory for all JS files for the app. diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index bbe757547912ff..964948984f041f 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -20,8 +20,8 @@ react { root = file("../../") // The folder where the react-native NPM package is. Default is ../node_modules/react-native reactNativeDir = rootDir - // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen - codegenDir = file("$rootDir/node_modules/react-native-codegen") + // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen + codegenDir = file("$rootDir/node_modules/@react-native/codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js cliFile = file("$rootDir/cli.js") diff --git a/repo-config/package.json b/repo-config/package.json index 1c767844093825..1c91d260d31c10 100644 --- a/repo-config/package.json +++ b/repo-config/package.json @@ -14,6 +14,7 @@ "@babel/generator": "^7.14.0", "@babel/plugin-transform-regenerator": "^7.0.0", "@definitelytyped/dtslint": "^0.0.127", + "@react-native/codegen": "^0.72.0", "@react-native/eslint-config": "*", "@react-native/eslint-plugin": "*", "@react-native/eslint-plugin-specs": "^0.72.0", @@ -47,7 +48,6 @@ "mkdirp": "^0.5.1", "prettier": "^2.4.1", "react": "18.2.0", - "react-native-codegen": "^0.72.0", "react-test-renderer": "18.2.0", "shelljs": "^0.8.5", "signedsource": "^1.0.0", diff --git a/scripts/cocoapods/__tests__/codegen-test.rb b/scripts/cocoapods/__tests__/codegen-test.rb index ef574251c366bd..ce1f3b700db276 100644 --- a/scripts/cocoapods/__tests__/codegen-test.rb +++ b/scripts/cocoapods/__tests__/codegen-test.rb @@ -90,7 +90,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissi ]) assert_equal(Dir.exist_invocation_params, [ @base_path + "/"+ @prefix + "/packages/react-native-codegen", - @base_path + "/"+ @prefix + "/../react-native-codegen", + @base_path + "/"+ @prefix + "/../@react-native/codegen", ]) assert_equal(Pod::UI.collected_messages, []) assert_equal($collected_commands, []) @@ -147,7 +147,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen() # Arrange - codegen_cli_path = @base_path + "/" + @prefix + "/../react-native-codegen" + codegen_cli_path = @base_path + "/" + @prefix + "/../@react-native/codegen" Dir.mocked_existing_dirs([ codegen_cli_path, ]) @@ -170,7 +170,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen() "[Codegen] building #{codegen_cli_path}.", "[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider" ]) - assert_equal($collected_commands, ["~/app/ios/../../../react-native-codegen/scripts/oss/build.sh"]) + assert_equal($collected_commands, ["~/app/ios/../../../@react-native/codegen/scripts/oss/build.sh"]) assert_equal(File.open_files[0].collected_write, ["[]"]) assert_equal(File.open_files[0].fsync_invocation_count, 1) assert_equal(Pod::Executable.executed_commands[0], { diff --git a/scripts/cocoapods/codegen.rb b/scripts/cocoapods/codegen.rb index f3c214de819360..0d1dd5ffc6ab82 100644 --- a/scripts/cocoapods/codegen.rb +++ b/scripts/cocoapods/codegen.rb @@ -10,7 +10,7 @@ # @throws an error if it could not find the codegen folder. def build_codegen!(react_native_path, relative_installation_root) codegen_repo_path = "#{relative_installation_root}/#{react_native_path}/packages/react-native-codegen"; - codegen_npm_path = "#{relative_installation_root}/#{react_native_path}/../react-native-codegen"; + codegen_npm_path = "#{relative_installation_root}/#{react_native_path}/../@react-native/codegen"; codegen_cli_path = "" if Dir.exist?(codegen_repo_path) diff --git a/scripts/codegen/codegen-utils.js b/scripts/codegen/codegen-utils.js index 469f426bb79bcf..b739d81c5a4075 100644 --- a/scripts/codegen/codegen-utils.js +++ b/scripts/codegen/codegen-utils.js @@ -12,7 +12,7 @@ /** * Wrapper required to abstract away from the actual codegen. * This is needed because, when running tests in Sandcastle, not everything is setup as usually. - * For example, the `react-native-codegen` lib is not present. + * For example, the `@react-native/codegen` lib is not present. * * Thanks to this wrapper, we are able to mock the getter for the codegen in a way that allow us to return * a custom object which mimics the Codegen interface. @@ -24,7 +24,7 @@ function getCodegen() { try { RNCodegen = require('../../packages/react-native-codegen/lib/generators/RNCodegen.js'); } catch (e) { - RNCodegen = require('react-native-codegen/lib/generators/RNCodegen.js'); + RNCodegen = require('@react-native/codegen/lib/generators/RNCodegen.js'); } if (!RNCodegen) { throw 'RNCodegen not found.'; diff --git a/scripts/codegen/generate-artifacts-executor.js b/scripts/codegen/generate-artifacts-executor.js index 68a47b6fab5bf9..757ce492c5ae14 100644 --- a/scripts/codegen/generate-artifacts-executor.js +++ b/scripts/codegen/generate-artifacts-executor.js @@ -24,7 +24,7 @@ const path = require('path'); const RN_ROOT = path.join(__dirname, '../..'); const CODEGEN_REPO_PATH = `${RN_ROOT}/packages/react-native-codegen`; -const CODEGEN_NPM_PATH = `${RN_ROOT}/../react-native-codegen`; +const CODEGEN_NPM_PATH = `${RN_ROOT}/../@react-native/codegen`; const CORE_LIBRARIES = new Set(['rncore', 'FBReactNativeSpec']); const REACT_NATIVE_DEPENDENCY_NAME = 'react-native'; diff --git a/scripts/generate-provider-cli.js b/scripts/generate-provider-cli.js index 9b7744c5c9227c..852a8d300093ac 100644 --- a/scripts/generate-provider-cli.js +++ b/scripts/generate-provider-cli.js @@ -13,7 +13,7 @@ let RNCodegen; try { RNCodegen = require('../packages/react-native-codegen/lib/generators/RNCodegen.js'); } catch (e) { - RNCodegen = require('react-native-codegen/lib/generators/RNCodegen.js'); + RNCodegen = require('@react-native/codegen/lib/generators/RNCodegen.js'); if (!RNCodegen) { throw 'RNCodegen not found.'; } diff --git a/scripts/react_native_pods_utils/script_phases.sh b/scripts/react_native_pods_utils/script_phases.sh index 08efd2afbde022..f1f5b809ed8fbe 100755 --- a/scripts/react_native_pods_utils/script_phases.sh +++ b/scripts/react_native_pods_utils/script_phases.sh @@ -31,9 +31,9 @@ find_node () { } find_codegen () { - CODEGEN_CLI_PATH=$("$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native-codegen/package.json'))") + CODEGEN_CLI_PATH=$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@react-native/codegen/package.json'))") if ! [ -d "$CODEGEN_CLI_PATH" ]; then - error "error: Could not determine react-native-codegen location, using node module resolution. Try running 'yarn install' or 'npm install' in your project root." + error "error: Could not determine @react-native/codegen location, using node module resolution. Try running 'yarn install' or 'npm install' in your project root." fi } diff --git a/scripts/set-rn-version.js b/scripts/set-rn-version.js index 44f9ae4764a47a..4e04fe2fe64975 100755 --- a/scripts/set-rn-version.js +++ b/scripts/set-rn-version.js @@ -121,11 +121,11 @@ packageJson.devDependencies = { ...packageJson.devDependencies, ...repoConfigJson.dependencies, }; -// Make react-native-codegen a direct dependency of react-native -delete packageJson.devDependencies['react-native-codegen']; +// Make @react-native/codegen a direct dependency of react-native +delete packageJson.devDependencies['@react-native/codegen']; packageJson.dependencies = { ...packageJson.dependencies, - 'react-native-codegen': repoConfigJson.dependencies['react-native-codegen'], + '@react-native/codegen': repoConfigJson.dependencies['@react-native/codegen'], }; fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8'); diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 71195c76234a76..096417b06c753c 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -13,8 +13,8 @@ react { // root = file("../") // The folder where the react-native NPM package is. Default is ../node_modules/react-native // reactNativeDir = file("../node_modules/react-native") - // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen - // codegenDir = file("../node_modules/react-native-codegen") + // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen + // codegenDir = file("../node_modules/@react-native/codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js // cliFile = file("../node_modules/react-native/cli.js")