Skip to content

Commit

Permalink
Fix hardcoded path to codegen cli for monorepos
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Nov 22, 2022
1 parent 285a980 commit 6ec44f5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions scripts/react_native_pods_utils/script_phases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ GENERATED_SCHEMA_FILE="$GENERATED_SRCS_DIR/schema.json"

cd "$RCT_SCRIPT_RN_DIR"

CODEGEN_REPO_PATH="$RCT_SCRIPT_RN_DIR/packages/react-native-codegen"
CODEGEN_NPM_PATH="$RCT_SCRIPT_RN_DIR/../react-native-codegen"
CODEGEN_CLI_PATH=""

error () {
Expand All @@ -23,15 +21,6 @@ error () {
exit 1
}

# Determine path to react-native-codegen
if [ -d "$CODEGEN_REPO_PATH" ]; then
CODEGEN_CLI_PATH=$(cd "$CODEGEN_REPO_PATH" && pwd)
elif [ -d "$CODEGEN_NPM_PATH" ]; then
CODEGEN_CLI_PATH=$(cd "$CODEGEN_NPM_PATH" && pwd)
else
error "error: Could not determine react-native-codegen location in $CODEGEN_REPO_PATH or $CODEGEN_NPM_PATH. Try running 'yarn install' or 'npm install' in your project root."
fi

find_node () {
NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
if [ -z "$NODE_BINARY" ]; then
Expand All @@ -41,6 +30,13 @@ find_node () {
fi
}

find_codegen () {
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."
fi
}

setup_dirs () {
set +e
rm -rf "$GENERATED_SRCS_DIR"
Expand Down Expand Up @@ -116,13 +112,15 @@ moveOutputs () {
withCodgenDiscovery () {
setup_dirs
find_node
find_codegen
generateArtifacts
moveOutputs
}

noCodegenDiscovery () {
setup_dirs
find_node
find_codegen
generateCodegenSchemaFromJavaScript
generateCodegenArtifactsFromSchema
moveOutputs
Expand Down

0 comments on commit 6ec44f5

Please sign in to comment.