diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index 287468f95..cff2a1b42 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -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 diff --git a/packages/platform-ios/src/link-pods/findLineToAddPod.js b/packages/platform-ios/src/link-pods/findLineToAddPod.js index 9f7a4c61a..691a6629c 100644 --- a/packages/platform-ios/src/link-pods/findLineToAddPod.js +++ b/packages/platform-ios/src/link-pods/findLineToAddPod.js @@ -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); diff --git a/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js b/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js index 3087937b7..05033817a 100644 --- a/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js +++ b/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js @@ -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 = []; diff --git a/packages/platform-ios/src/link-pods/registerNativeModule.js b/packages/platform-ios/src/link-pods/registerNativeModule.js index 5d8abca42..a3363e0a4 100644 --- a/packages/platform-ios/src/link-pods/registerNativeModule.js +++ b/packages/platform-ios/src/link-pods/registerNativeModule.js @@ -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'; @@ -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); }