Skip to content

Commit 3a41b4c

Browse files
authored
fix: fallback to plain pod if Gemfile does not contain CocoaPods (#6581)
1 parent 50fcabc commit 3a41b4c

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

cli/src/config.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,18 @@ async function determineGemfileOrCocoapodPath(
446446
return process.env.CAPACITOR_COCOAPODS_PATH;
447447
}
448448

449-
// Look for 'Gemfile' in app directories
450-
const appSpecificGemfileExists =
451-
(await pathExists(resolve(rootDir, 'Gemfile'))) ||
452-
(await pathExists(resolve(platformDir, 'Gemfile'))) ||
453-
(await pathExists(resolve(nativeProjectDirAbs, 'Gemfile')));
449+
let gemfilePath = '';
450+
if (await pathExists(resolve(rootDir, 'Gemfile'))) {
451+
gemfilePath = resolve(rootDir, 'Gemfile');
452+
} else if (await pathExists(resolve(platformDir, 'Gemfile'))) {
453+
gemfilePath = resolve(platformDir, 'Gemfile');
454+
} else if (await pathExists(resolve(nativeProjectDirAbs, 'Gemfile'))) {
455+
gemfilePath = resolve(nativeProjectDirAbs, 'Gemfile');
456+
}
457+
458+
const appSpecificGemfileExists = gemfilePath != '';
454459

455460
// Multi-app projects might share a single global 'Gemfile' at the Git repository root directory.
456-
let globalGemfileExists = false;
457461
if (!appSpecificGemfileExists) {
458462
try {
459463
const output = await getCommandOutput(
@@ -462,16 +466,26 @@ async function determineGemfileOrCocoapodPath(
462466
{ cwd: rootDir },
463467
);
464468
if (output != null) {
465-
globalGemfileExists = await pathExists(resolve(output, 'Gemfile'));
469+
gemfilePath = resolve(output, 'Gemfile');
466470
}
467-
} catch (e) {
471+
} catch (e: any) {
468472
// Nothing
469473
}
470474
}
471475

472-
if (appSpecificGemfileExists || globalGemfileExists) {
473-
return 'bundle exec pod';
474-
} else {
476+
try {
477+
const gemfileText = (await readFile(gemfilePath)).toString();
478+
if (!gemfileText) {
479+
return 'pod';
480+
}
481+
const cocoapodsInGemfile = new RegExp(/gem 'cocoapods'/).test(gemfileText);
482+
483+
if (cocoapodsInGemfile) {
484+
return 'bundle exec pod';
485+
} else {
486+
return 'pod';
487+
}
488+
} catch {
475489
return 'pod';
476490
}
477491
}

0 commit comments

Comments
 (0)