Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions packages/platform-ios/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# which declare themselves to be iOS dependencies (via having a Podspec) and automatically
# imports those into your current target.
#
def use_native_modules!(root = "..", packages = nil)
if (!packages)
def use_native_modules!(root = "..", config = nil)
if (!config)
command = "./node_modules/.bin/react-native"
args = ["config"]
output = ""
Expand All @@ -17,10 +17,12 @@ def use_native_modules!(root = "..", packages = nil)
output.each_line do |line|
json << line
end

config = JSON.parse(json.join("\n"))
packages = config["dependencies"]
end

packages = config["dependencies"]
project_root = config["root"]
found_pods = []

packages.each do |package_name, package|
Expand Down Expand Up @@ -54,11 +56,9 @@ def use_native_modules!(root = "..", packages = nil)
existing_dep.name.split('/').first == spec.name
end

# Use relative path
absolute_podspec_path = File.dirname(podspec_path)
relative_podspec_path = File.join(root, absolute_podspec_path.partition('node_modules').last(2).join())
relative_path = File.dirname(podspec_path).split(project_root).last || ""

pod spec.name, :path => relative_podspec_path
pod spec.name, :path => File.join(root, relative_path)

if package_config["scriptPhases"]
# Can be either an object, or an array of objects
Expand Down Expand Up @@ -144,7 +144,13 @@ def pluralize(count)
},
}
}
@config = { "ios-dep" => @ios_package, "android-dep" => @android_package }
@config = {
"root" => "/root/app",
"dependencies" => {
"ios-dep" => @ios_package,
"android-dep" => @android_package
}
}

@activated_pods = activated_pods = []
@current_target_definition_dependencies = current_target_definition_dependencies = []
Expand Down Expand Up @@ -211,9 +217,11 @@ def pluralize(count)
end

it "prints out the native module pods that were found" do
@podfile.use_native_modules('..', {})
@podfile.use_native_modules('..', { "pkg-1" => @ios_package })
@podfile.use_native_modules('..', { "pkg-1" => @ios_package, "pkg-2" => @ios_package })
@podfile.use_native_modules('..', { "root" => "", "dependencies" => {} })
@podfile.use_native_modules('..', { "root" => "", "dependencies" => { "pkg-1" => @ios_package }})
@podfile.use_native_modules('..', {
"root" => "", "dependencies" => { "pkg-1" => @ios_package, "pkg-2" => @ios_package }
})
@printed_messages.must_equal [
"Detected React Native module pod for ios-dep",
"Detected React Native module pods for ios-dep, and ios-dep"
Expand All @@ -222,7 +230,7 @@ def pluralize(count)

describe "concerning script_phases" do
it "uses the options directly" do
@config["ios-dep"]["platforms"]["ios"]["scriptPhases"] = [@script_phase]
@config["dependencies"]["ios-dep"]["platforms"]["ios"]["scriptPhases"] = [@script_phase]
@podfile.use_native_modules('..', @config)
@added_scripts.must_equal [{
"script" => "123",
Expand All @@ -235,7 +243,7 @@ def pluralize(count)
it "reads a script file relative to the package root" do
@script_phase.delete("script")
@script_phase["path"] = "./some_shell_script.sh"
@config["ios-dep"]["platforms"]["ios"]["scriptPhases"] = [@script_phase]
@config["dependencies"]["ios-dep"]["platforms"]["ios"]["scriptPhases"] = [@script_phase]

file_read_mock = MiniTest::Mock.new
file_read_mock.expect(:call, "contents from file", [File.join(@ios_package["root"], "some_shell_script.sh")])
Expand Down