Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/platform-ios/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def pluralize(count)
@podfile.use_native_modules({ "pkg-1" => @ios_package })
@podfile.use_native_modules({ "pkg-1" => @ios_package, "pkg-2" => @ios_package })
@printed_messages.must_equal [
"Detected native module pod for ios-dep",
"Detected native module pods for ios-dep, and ios-dep"
"Detected React Native module pod for ios-dep",
"Detected React Native module pods for ios-dep, and ios-dep"
]
end

Expand Down
2 changes: 1 addition & 1 deletion packages/platform-ios/src/link-pods/findLineToAddPod.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function findLineToAddPod(podLines, firstTargetLine) {
// match function definition, like: post_install do |installer| (some Podfiles have function defined inside main target
const functionDefinition = /^\s*[a-z_]+\s+do(\s+\|[a-z]+\|)?/g;

for (let i = firstTargetLine, len = podLines.length; i < len; i++) {
for (let i = firstTargetLine; i < podLines.length - 1; i++) {
const matchNextConstruct =
podLines[i].match(nextTarget) || podLines[i].match(functionDefinition);
const matchEnd = podLines[i].match(endOfCurrentTarget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @format
*/

const MARKER_TEXT = '# Add new pods below this line';
export const MARKER_TEXT = '# Add new pods below this line';

export default function findMarkedLinesInPodfile(podLines) {
const result = [];
Expand Down
22 changes: 21 additions & 1 deletion packages/platform-ios/src/link-pods/registerNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
*
* @format
*/
import chalk from 'chalk';
import {CLIError, inlineString} from '@react-native-community/cli-tools';

import readPodfile from './readPodfile';
import findPodTargetLine from './findPodTargetLine';
import findLineToAddPod from './findLineToAddPod';
import findMarkedLinesInPodfile from './findMarkedLinesInPodfile';
import findMarkedLinesInPodfile, {
MARKER_TEXT,
} from './findMarkedLinesInPodfile';
import addPodEntry from './addPodEntry';
import savePodFile from './savePodFile';

Expand All @@ -31,5 +35,21 @@ function getLinesToAddEntry(podLines, {projectName}) {
return linesToAddPodWithMarker;
}
const firstTargetLined = findPodTargetLine(podLines, projectName);
if (firstTargetLined === null) {
throw new CLIError(
inlineString(`
We couldn't find a target to add a CocoaPods dependency.

Make sure that you have a "${chalk.dim(
`target '${projectName.replace('.xcodeproj', '')}' do`,
)}" line in your Podfile.

Alternatively, include "${chalk.dim(
MARKER_TEXT,
)}" in a Podfile where we should add
linked dependencies.
`),
);
}
return findLineToAddPod(podLines, firstTargetLined);
}