From bece810021945bb7404a963dc0921d46393eaa42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Tue, 19 Jul 2022 09:11:08 -0700 Subject: [PATCH] Move cocoapods cli native_modules require from template to rn scripts (#34215) Summary: This resolves issues where the node_modules structure is not hoisted (like with pnpm). Since the template does not directly depend on the cli, it doesn't exist in the pnpm node_modules root. Moving it to the rn scripts makes sure that the relative require starts in the correct directory for both hoisted and pnpm structures. ## Changelog [iOS] [Fixed] - Fix cocoapods cli native_modules require for pnpm node_modules Pull Request resolved: https://github.com/facebook/react-native/pull/34215 Test Plan: 1. react-native init 2. rm -rf node_modules 3. pnpm i 4. bundle install 5. bundle exec pod install --project-directory=ios This should succeed. Without the patch, it will fail with ``` [!] Invalid `Podfile` file: cannot load such file -- /.../node_modules/react-native-community/cli-platform-ios/native_modules. # from /.../ios/Podfile:2 # ------------------------------------------- # require_relative '../node_modules/react-native/scripts/react_native_pods' > require_relative '../node_modules/react-native-community/cli-platform-ios/native_modules' # # ------------------------------------------- ``` Reviewed By: cortinico Differential Revision: D37959152 Pulled By: cipolleschi fbshipit-source-id: 7fa9af4a8c153cfd38360f57eca415a8c252dbd5 --- package.json | 1 + scripts/native_modules.rb | 6 ++++++ template/ios/Podfile | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 scripts/native_modules.rb diff --git a/package.json b/package.json index a29bacdae4d875..d195e03b4a1967 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "scripts/ios-configure-glog.sh", "scripts/launchPackager.bat", "scripts/launchPackager.command", + "scripts/native_modules.rb", "scripts/node-binary.sh", "scripts/packager.sh", "scripts/packager-reporter.js", diff --git a/scripts/native_modules.rb b/scripts/native_modules.rb new file mode 100644 index 00000000000000..729035ddd91d71 --- /dev/null +++ b/scripts/native_modules.rb @@ -0,0 +1,6 @@ +# 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. + +require_relative '../../@react-native-community/cli-platform-ios/native_modules' diff --git a/template/ios/Podfile b/template/ios/Podfile index 01506faf7913c7..56a960b2367bf0 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -1,5 +1,5 @@ require_relative '../node_modules/react-native/scripts/react_native_pods' -require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' +require_relative '../node_modules/react-native/scripts/native_modules' platform :ios, '11.0' install! 'cocoapods', :deterministic_uuids => false