Skip to content

Commit 28f3026

Browse files
grabbouthymikee
authored andcommitted
fix: give a better error message when CocoaPods linking fails (#321)
* initial commit * Remove log * fix: failing cocoa-pods tests * Improve accessibility
1 parent 4554de1 commit 28f3026

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

packages/cli/src/commands/link/pods/findLineToAddPod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function findLineToAddPod(podLines, firstTargetLine) {
1515
// match function definition, like: post_install do |installer| (some Podfiles have function defined inside main target
1616
const functionDefinition = /^\s*[a-z_]+\s+do(\s+\|[a-z]+\|)?/g;
1717

18-
for (let i = firstTargetLine, len = podLines.length; i < len; i++) {
18+
for (let i = firstTargetLine; i < podLines.length - 1; i++) {
1919
const matchNextConstruct =
2020
podLines[i].match(nextTarget) || podLines[i].match(functionDefinition);
2121
const matchEnd = podLines[i].match(endOfCurrentTarget);

packages/cli/src/commands/link/pods/findMarkedLinesInPodfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @format
88
*/
99

10-
const MARKER_TEXT = '# Add new pods below this line';
10+
export const MARKER_TEXT = '# Add new pods below this line';
1111

1212
export default function findMarkedLinesInPodfile(podLines) {
1313
const result = [];

packages/cli/src/commands/link/pods/registerNativeModule.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*
77
* @format
88
*/
9-
9+
import chalk from 'chalk';
1010
import readPodfile from './readPodfile';
1111
import findPodTargetLine from './findPodTargetLine';
1212
import findLineToAddPod from './findLineToAddPod';
13-
import findMarkedLinesInPodfile from './findMarkedLinesInPodfile';
13+
import findMarkedLinesInPodfile, {
14+
MARKER_TEXT,
15+
} from './findMarkedLinesInPodfile';
1416
import addPodEntry from './addPodEntry';
1517
import savePodFile from './savePodFile';
1618

@@ -31,5 +33,16 @@ function getLinesToAddEntry(podLines, {projectName}) {
3133
return linesToAddPodWithMarker;
3234
}
3335
const firstTargetLined = findPodTargetLine(podLines, projectName);
36+
if (firstTargetLined === null) {
37+
throw new Error(`We couldn't find a target to add a CocoaPods dependency.
38+
Make sure that you have a "${chalk.dim(
39+
`target '${projectName.replace('.xcodeproj', '')}' do`,
40+
)}" line in your Podfile.
41+
42+
Alternatively, include "${chalk.dim(
43+
MARKER_TEXT,
44+
)}" in a Podfile where we should add
45+
linked dependencies.`);
46+
}
3447
return findLineToAddPod(podLines, firstTargetLined);
3548
}

0 commit comments

Comments
 (0)