From 7b562c3fc6b46a55987f35a36f58a59b01fdc3a6 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 6 Oct 2025 13:51:06 +0100 Subject: [PATCH 1/6] Use RCT_SCRIPT_OUTPUT_DIR env var to find autolinking.json output too --- .../generate-artifacts-executor/utils.js | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index 97a4b89c540ed0..9914b3d55d5aa7 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -100,20 +100,28 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) { function readGeneratedAutolinkingOutput( baseOutputPath /*: string */, ) /*: $FlowFixMe */ { - // NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules) - const autolinkingGeneratedPath = path.resolve( + const outputPathCandidates = [ + // The `outputDir` may not be set correctly if it's set to the a temporary output directory + process.env.RCT_SCRIPT_OUTPUT_DIR, + // NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules) baseOutputPath, - 'build/generated/autolinking/autolinking.json', - ); - if (fs.existsSync(autolinkingGeneratedPath)) { - // $FlowFixMe[unsupported-syntax] - return require(autolinkingGeneratedPath); - } else { - codegenLog( - `Could not find generated autolinking output at: ${autolinkingGeneratedPath}`, - ); - return null; + ]; + for (const outputPathCandidate of outputPathCandidates) { + if (outputPathCandidate != null && outputPathCandidate.length > 0) { + const autolinkingGeneratedPath = path.resolve( + outputPathCandidate, + 'build/generated/autolinking/autolinking.json', + ); + if (fs.existsSync(autolinkingGeneratedPath)) { + // $FlowFixMe[unsupported-syntax] + return require(autolinkingGeneratedPath); + } + codegenLog( + `Could not find generated autolinking output at: ${autolinkingGeneratedPath}`, + ); + } } + return null; } function readReactNativeConfig( From b4642569c67dff43a755e48a426fc78dd00174a2 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 6 Oct 2025 13:55:20 +0100 Subject: [PATCH 2/6] Use real RCT_SCRIPT_OUTPUT_DIR for generate-codegen-artifacts in script_phases.sh Avoid ending up in in derive data output folder to be able to discover `autolinking.json` generated in Cocoapods step in all cases, regardless of if the script checks `RCT_SCRIPT_OUTPUT_DIR` itself. --- .../react_native_pods_utils/script_phases.sh | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/react-native/scripts/react_native_pods_utils/script_phases.sh b/packages/react-native/scripts/react_native_pods_utils/script_phases.sh index 92325f1ad078f4..92b95f9e59bb7e 100755 --- a/packages/react-native/scripts/react_native_pods_utils/script_phases.sh +++ b/packages/react-native/scripts/react_native_pods_utils/script_phases.sh @@ -93,13 +93,6 @@ generateCodegenArtifactsFromSchema () { popd >/dev/null || exit 1 } -generateArtifacts () { - describe "Generating codegen artifacts" - pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1 - "$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --targetPlatform "ios" - popd >/dev/null || exit 1 -} - moveOutputs () { mkdir -p "$RCT_SCRIPT_OUTPUT_DIR" @@ -110,22 +103,21 @@ moveOutputs () { } withCodegenDiscovery () { - setup_dirs - find_node - find_codegen - generateArtifacts - moveOutputs + describe "Generating codegen artifacts" + pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1 + "$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$RCT_SCRIPT_OUTPUT_DIR" --targetPlatform "ios" + popd >/dev/null || exit 1 } noCodegenDiscovery () { setup_dirs - find_node - find_codegen generateCodegenSchemaFromJavaScript generateCodegenArtifactsFromSchema moveOutputs } +find_node +find_codegen if [ "$RCT_SCRIPT_TYPE" = "withCodegenDiscovery" ]; then withCodegenDiscovery "$@" else From c7af00465f703f53ee88e0df6d4cbbb1e1131776 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 6 Oct 2025 19:25:01 +0100 Subject: [PATCH 3/6] Add comments and separate pods/xcode autolinking.json loading --- .../generate-artifacts-executor/utils.js | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index 9914b3d55d5aa7..d96a522d9ec110 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -100,27 +100,34 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) { function readGeneratedAutolinkingOutput( baseOutputPath /*: string */, ) /*: $FlowFixMe */ { - const outputPathCandidates = [ - // The `outputDir` may not be set correctly if it's set to the a temporary output directory - process.env.RCT_SCRIPT_OUTPUT_DIR, - // NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules) - baseOutputPath, - ]; - for (const outputPathCandidate of outputPathCandidates) { - if (outputPathCandidate != null && outputPathCandidate.length > 0) { - const autolinkingGeneratedPath = path.resolve( - outputPathCandidate, - 'build/generated/autolinking/autolinking.json', - ); - if (fs.existsSync(autolinkingGeneratedPath)) { - // $FlowFixMe[unsupported-syntax] - return require(autolinkingGeneratedPath); - } - codegenLog( - `Could not find generated autolinking output at: ${autolinkingGeneratedPath}`, - ); + // When run from Xcode, the generated file can be found via `RCT_SCRIPT_OUTPUT_DIR` consistently + if (process.env.RCT_SCRIPT_OUTPUT_DIR) { + const xcodeAutolinkingGeneratedPath = path.resolve( + process.env.RCT_SCRIPT_OUTPUT_DIR, + 'build/generated/autolinking/autolinking.json', + ); + if (fs.existsSync(xcodeAutolinkingGeneratedPath)) { + // $FlowFixMe[unsupported-syntax] + return require(xcodeAutolinkingGeneratedPath); } + codegenLog( + `Could not find generated autolinking output at: ${xcodeAutolinkingGeneratedPath}`, + ); } + + // Otherwise, we expect to find it in the output path iself, when it's been generated in Cocoapods + const podsAutolinkingGeneratedPath = path.resolve( + baseOutputPath, + 'build/generated/autolinking/autolinking.json', + ); + if (fs.existsSync(podsAutolinkingGeneratedPath)) { + // $FlowFixMe[unsupported-syntax] + return require(podsAutolinkingGeneratedPath); + } + codegenLog( + `Could not find generated autolinking output at: ${podsAutolinkingGeneratedPath}`, + ); + return null; } From 449258e01d1fe1aa76687029af9f7f513a9a3e0e Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 6 Oct 2025 19:26:11 +0100 Subject: [PATCH 4/6] Revert structural changes in react_native_pods_utils/script_phases.sh --- .../react_native_pods_utils/script_phases.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/react-native/scripts/react_native_pods_utils/script_phases.sh b/packages/react-native/scripts/react_native_pods_utils/script_phases.sh index 92b95f9e59bb7e..0878b9d6a8cf8a 100755 --- a/packages/react-native/scripts/react_native_pods_utils/script_phases.sh +++ b/packages/react-native/scripts/react_native_pods_utils/script_phases.sh @@ -93,6 +93,13 @@ generateCodegenArtifactsFromSchema () { popd >/dev/null || exit 1 } +generateArtifacts () { + describe "Generating codegen artifacts" + pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1 + "$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$RCT_SCRIPT_OUTPUT_DIR" --targetPlatform "ios" + popd >/dev/null || exit 1 +} + moveOutputs () { mkdir -p "$RCT_SCRIPT_OUTPUT_DIR" @@ -103,21 +110,20 @@ moveOutputs () { } withCodegenDiscovery () { - describe "Generating codegen artifacts" - pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1 - "$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$RCT_SCRIPT_OUTPUT_DIR" --targetPlatform "ios" - popd >/dev/null || exit 1 + find_node + find_codegen + generateArtifacts } noCodegenDiscovery () { setup_dirs + find_node + find_codegen generateCodegenSchemaFromJavaScript generateCodegenArtifactsFromSchema moveOutputs } -find_node -find_codegen if [ "$RCT_SCRIPT_TYPE" = "withCodegenDiscovery" ]; then withCodegenDiscovery "$@" else From d5955f2dbebdfcc346d9d383f854de6639fa6b28 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 6 Oct 2025 20:00:57 +0100 Subject: [PATCH 5/6] Move RCT_SCRIPT_OUTPUT_DIR switching to `generate-artifacts-executor/index.js` --- .../generate-artifacts-executor/index.js | 8 ++++- .../generate-artifacts-executor/utils.js | 33 +++++-------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js index f057a9eb05ee32..20aed7c0a2a8d6 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js @@ -90,8 +90,14 @@ function execute( const reactNativeConfig = readReactNativeConfig( projectRoot, - baseOutputPath, + // NOTE: Used to load `build/generated/autolinking/autolinking.json` generated by `scripts/cocoapods/autolinking.rb` + // If we have RCT_SCRIPT_OUTPUT_DIR (set in `react_native_pods_utils/script_phases.sh`, it takes precedence, otherwise + // we search for the `autolinking.json` output in the `baseOutputPath` + process.env.RCT_SCRIPT_OUTPUT_DIR != null && process.env.RCT_SCRIPT_OUTPUT_DIR.length > 0 + ? process.env.RCT_SCRIPT_OUTPUT_DIR + : baseOutputPath, ); + const codegenEnabledLibraries = findCodegenEnabledLibraries( pkgJson, projectRoot, diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index d96a522d9ec110..97a4b89c540ed0 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -100,35 +100,20 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) { function readGeneratedAutolinkingOutput( baseOutputPath /*: string */, ) /*: $FlowFixMe */ { - // When run from Xcode, the generated file can be found via `RCT_SCRIPT_OUTPUT_DIR` consistently - if (process.env.RCT_SCRIPT_OUTPUT_DIR) { - const xcodeAutolinkingGeneratedPath = path.resolve( - process.env.RCT_SCRIPT_OUTPUT_DIR, - 'build/generated/autolinking/autolinking.json', - ); - if (fs.existsSync(xcodeAutolinkingGeneratedPath)) { - // $FlowFixMe[unsupported-syntax] - return require(xcodeAutolinkingGeneratedPath); - } - codegenLog( - `Could not find generated autolinking output at: ${xcodeAutolinkingGeneratedPath}`, - ); - } - - // Otherwise, we expect to find it in the output path iself, when it's been generated in Cocoapods - const podsAutolinkingGeneratedPath = path.resolve( + // NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules) + const autolinkingGeneratedPath = path.resolve( baseOutputPath, 'build/generated/autolinking/autolinking.json', ); - if (fs.existsSync(podsAutolinkingGeneratedPath)) { + if (fs.existsSync(autolinkingGeneratedPath)) { // $FlowFixMe[unsupported-syntax] - return require(podsAutolinkingGeneratedPath); + return require(autolinkingGeneratedPath); + } else { + codegenLog( + `Could not find generated autolinking output at: ${autolinkingGeneratedPath}`, + ); + return null; } - codegenLog( - `Could not find generated autolinking output at: ${podsAutolinkingGeneratedPath}`, - ); - - return null; } function readReactNativeConfig( From 4d334e1e3277ab27ab552fe2425733781952a992 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 7 Oct 2025 12:20:38 +0100 Subject: [PATCH 6/6] Apply prettier --- .../scripts/codegen/generate-artifacts-executor/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js index 20aed7c0a2a8d6..588c5d2b5fd327 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js @@ -93,7 +93,8 @@ function execute( // NOTE: Used to load `build/generated/autolinking/autolinking.json` generated by `scripts/cocoapods/autolinking.rb` // If we have RCT_SCRIPT_OUTPUT_DIR (set in `react_native_pods_utils/script_phases.sh`, it takes precedence, otherwise // we search for the `autolinking.json` output in the `baseOutputPath` - process.env.RCT_SCRIPT_OUTPUT_DIR != null && process.env.RCT_SCRIPT_OUTPUT_DIR.length > 0 + process.env.RCT_SCRIPT_OUTPUT_DIR != null && + process.env.RCT_SCRIPT_OUTPUT_DIR.length > 0 ? process.env.RCT_SCRIPT_OUTPUT_DIR : baseOutputPath, );