[react_native_pods.rb
] Introduce a reusable resolve_node_module
function
#41990
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
The React Native project and its related packages ship Ruby code, through packages published on NPM.
To successfully resolve the path of these "node modules", the project has historically made assumptions on the relative location of these packages. This however breaks down in the context of modern package managers and features such as NPM / Yarn workspaces, since packages may be (partially) hoisted to a parent / root package.
In recent times we've made changes to some of these Ruby files that makes it easier to consume in a hoisted environment: #36485
I suggest we generalise this by introducing a function, which the other scripts, developers apps and library authors can rely on to successfully resolve a path using the node modules resolution algorithm.
As an alternative, I've considered adding this as a function on the
ReactNativePodsUtils
module, but I felt this is such a versatile helper that it should be globally available. I'd be happy to change this if deemed necessary.I'd love to follow up with additional PRs, introducing use of this utility function in more of the Ruby files of the project and related packages.
Changelog:
[IOS] [ADDED] - Add a
resolve_node_module
function to thereact_native_pods.rb
script, which will call Node.js to resolve a module path using the node modules resolution algorithm.Test Plan:
I've made the change locally and tested that the
bundle exec pod install
command works as expected and verified that theresolve_node_module
is available and works as expected from the.podspec
of a library that has been installed into the React Native app that I'm testing with.