Skip to content

Commit

Permalink
chore: renamed react-native-codegen to @react-native/codegen (faceboo…
Browse files Browse the repository at this point in the history
…k#34804)

Summary:
Renamed react-native-codegen package to react-native/codegen and updated references, without changing the folder name; part of RFC480 (facebook#34692). Follow-up from facebook#34578

## Changelog

[General] [Changed] - Renamed react-native-codegen package to react-native/codegen and updated references

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: facebook#34804

Reviewed By: cortinico

Differential Revision: D39883584

Pulled By: hoxyq

fbshipit-source-id: 0ef384b75c6edd248b31e37b8f05f64b4d39ca6f
  • Loading branch information
shivenmian authored and OlimpiaZurek committed May 22, 2023
1 parent fa63002 commit f7040fc
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 45 deletions.
3 changes: 0 additions & 3 deletions .circleci/verdaccio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ packages:
'@react-native/*':
access: $all
publish: $all
'react-native-codegen':
access: $all
publish: $all
'@*/*':
access: $all
publish: $authenticated
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions packages/babel-plugin-codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"index.js"
],
"dependencies": {
"react-native-codegen": "*"
"@react-native/codegen": "*"
},
"devDependencies": {
"@babel/core": "^7.14.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-specs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-plugin-specs/react-native-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ 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\//],
plugins: [require('@babel/plugin-transform-flow-strip-types').default],
};

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');
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native-codegen/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-codegen/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion repo-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions scripts/cocoapods/__tests__/codegen-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down Expand Up @@ -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,
])
Expand All @@ -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], {
Expand Down
2 changes: 1 addition & 1 deletion scripts/cocoapods/codegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions scripts/codegen/codegen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.';
Expand Down
2 changes: 1 addition & 1 deletion scripts/codegen/generate-artifacts-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-provider-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/react_native_pods_utils/script_phases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/set-rn-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
4 changes: 2 additions & 2 deletions template/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit f7040fc

Please sign in to comment.