Skip to content

Commit

Permalink
Move cocoapods cli native_modules require from template to rn scripts (
Browse files Browse the repository at this point in the history
…facebook#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: facebook#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
  • Loading branch information
danilobuerger committed Sep 6, 2022
1 parent bda3650 commit 1a1308a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"scripts/xcode/with-environment.sh",
"scripts/launchPackager.bat",
"scripts/launchPackager.command",
"scripts/native_modules.rb",
"scripts/node-binary.sh",
"scripts/packager.sh",
"scripts/packager-reporter.js",
Expand Down
6 changes: 6 additions & 0 deletions scripts/native_modules.rb
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion template/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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, '12.4'
install! 'cocoapods', :deterministic_uuids => false
Expand Down

0 comments on commit 1a1308a

Please sign in to comment.