Skip to content

Commit

Permalink
[iOS][auto-linking] fix: Add missing scriptPhases config (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar authored and thymikee committed Aug 6, 2019
1 parent 4109954 commit 7350e0e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
27 changes: 27 additions & 0 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ Custom path to `.podspec` file to use when auto-linking. Example: `node_modules/

An array of shared iOS libraries to link with the dependency. E.g. `libc++`. This is mostly a requirement of the native code that a dependency ships with.

#### platforms.ios.scriptPhases

An array of iOS script phases to add to the project. Specifying a `path` property with a path relative to the dependency root will load the contents of the file at the path as the script contents.

**Example:**

```js
// react-native.config.js
module.exports = {
dependency: {
platforms: {
ios: {
scriptPhases: [
{
name: '[MY DEPENDENCY] My Script',
path: './my_script.sh',
execution_position: 'after_compile',
},
],
},
},
},
};
```

See [`script_phase` options](https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method) for a full list of available object keys.

#### platforms.android.sourceDir

A relative path to a folder with source files. E.g. `custom-android`, or `custom-android/app`. By default, CLI searches for `android` and `android/app` as source dirs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Object {
"podspecPath": null,
"projectName": "HelloWorld.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
"scriptPhases": Array [],
"sharedLibraries": Array [],
"sourceDir": "./abc",
},
Expand Down Expand Up @@ -128,6 +129,7 @@ Object {
"podspecPath": null,
"projectName": "customProject.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-foo/customLocation/customProject.xcodeproj",
"scriptPhases": Array [],
"sharedLibraries": Array [],
"sourceDir": "<<REPLACED>>/node_modules/react-native-foo/customLocation",
},
Expand Down Expand Up @@ -167,6 +169,7 @@ Object {
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
"projectName": "customProject.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/customLocation/customProject.xcodeproj",
"scriptPhases": Array [],
"sharedLibraries": Array [],
"sourceDir": "<<REPLACED>>/node_modules/react-native-test/customLocation",
},
Expand Down Expand Up @@ -204,6 +207,7 @@ Object {
"podspecPath": null,
"projectName": "HelloWorld.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
"scriptPhases": Array [],
"sharedLibraries": Array [],
"sourceDir": "<<REPLACED>>/node_modules/react-native-test/ios",
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/config/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ module.exports = {
"podspecPath": "custom-path",
"projectName": "LocalRNLibrary.xcodeproj",
"projectPath": "<<REPLACED>>/native-libs/local-lib/ios/LocalRNLibrary.xcodeproj",
"scriptPhases": Array [],
"sharedLibraries": Array [],
"sourceDir": "<<REPLACED>>/native-libs/local-lib/ios",
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const dependencyConfig = t
podspecPath: t.string(),
sharedLibraries: t.array().items(t.string()),
libraryFolder: t.string(),
scriptPhases: t.array().items(t.object()),
})
.default({}),
android: t
Expand Down
18 changes: 10 additions & 8 deletions packages/platform-ios/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def use_native_modules!(root = "..", config = nil)
Array(package_config["scriptPhases"]).each do |phase|
# see https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method
# for the full object keys
Pod::UI.puts "Adding a custom script phase for Pod #{spec.name}: #{phase["name"] || 'No name specified.'}"

# Support passing in a path relative to the root of the package
if phase["path"]
Expand All @@ -75,6 +76,7 @@ def use_native_modules!(root = "..", config = nil)
phase["execution_position"] = phase["execution_position"].to_sym
end

phase = Hash[phase.map { |k, v| [k.to_sym, v] }]
script_phase phase
end
end
Expand Down Expand Up @@ -231,10 +233,10 @@ def pluralize(count)
@config["dependencies"]["ios-dep"]["platforms"]["ios"]["scriptPhases"] = [@script_phase]
@podfile.use_native_modules('..', @config)
@added_scripts.must_equal [{
"script" => "123",
"name" => "My Name",
"execution_position" => :before_compile,
"input" => "string"
:script => "123",
:name => "My Name",
:execution_position => :before_compile,
:input => "string"
}]
end

Expand All @@ -251,10 +253,10 @@ def pluralize(count)
end

@added_scripts.must_equal [{
"script" => "contents from file",
"name" => "My Name",
"execution_position" => :before_compile,
"input" => "string"
:script => "contents from file",
:name => "My Name",
:execution_position => :before_compile,
:input => "string"
}]
file_read_mock.verify
end
Expand Down
1 change: 1 addition & 0 deletions packages/platform-ios/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function projectConfig(
libraryFolder: userConfig.libraryFolder || 'Libraries',
sharedLibraries: mapSharedLibaries(userConfig.sharedLibraries || []),
plist: userConfig.plist || [],
scriptPhases: userConfig.scriptPhases || [],
};
}

Expand Down
5 changes: 5 additions & 0 deletions types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ type ProjectParamsIOST = {
sharedLibraries?: string[],
libraryFolder?: string,
plist: any[],
scriptPhases: Array<{
name?: string,
path?: string,
[key: string]: string,
}>,
};

type PlatformConfig<
Expand Down

0 comments on commit 7350e0e

Please sign in to comment.