MCPcopy
hub / github.com/ionic-team/capacitor / determinePackageManager

Function determinePackageManager

cli/src/config.ts:428–479  ·  view source on GitHub ↗
(
  rootDir: string,
  platformDir: any,
  nativeProjectDirAbs: string,
)

Source from the content-addressed store, hash-verified

426}
427
428async function determinePackageManager(
429 rootDir: string,
430 platformDir: any,
431 nativeProjectDirAbs: string,
432): Promise<PackageManager> {
433 if (existsSync(resolve(nativeProjectDirAbs, 'CapApp-SPM'))) {
434 return 'SPM';
435 }
436
437 if (process.env.CAPACITOR_COCOAPODS_PATH) {
438 return 'Cocoapods';
439 }
440
441 let gemfilePath = '';
442 if (await pathExists(resolve(rootDir, 'Gemfile'))) {
443 gemfilePath = resolve(rootDir, 'Gemfile');
444 } else if (await pathExists(resolve(platformDir, 'Gemfile'))) {
445 gemfilePath = resolve(platformDir, 'Gemfile');
446 } else if (await pathExists(resolve(nativeProjectDirAbs, 'Gemfile'))) {
447 gemfilePath = resolve(nativeProjectDirAbs, 'Gemfile');
448 }
449
450 const appSpecificGemfileExists = gemfilePath != '';
451
452 // Multi-app projects might share a single global 'Gemfile' at the Git repository root directory.
453 if (!appSpecificGemfileExists) {
454 try {
455 const output = await getCommandOutput('git', ['rev-parse', '--show-toplevel'], { cwd: rootDir });
456 if (output != null) {
457 gemfilePath = resolve(output, 'Gemfile');
458 }
459 } catch (e: any) {
460 // Nothing
461 }
462 }
463
464 try {
465 const gemfileText = (await readFile(gemfilePath)).toString();
466 if (!gemfileText) {
467 return 'Cocoapods';
468 }
469 const cocoapodsInGemfile = new RegExp(/gem\s+['"]cocoapods/).test(gemfileText);
470
471 if (cocoapodsInGemfile && (await isInstalled('bundle'))) {
472 return 'bundler';
473 } else {
474 return 'Cocoapods';
475 }
476 } catch {
477 return 'Cocoapods';
478 }
479}
480
481function formatConfigTS(extConfig: ExternalConfig): string {
482 // TODO: <reference> tags

Callers 1

loadIOSConfigFunction · 0.85

Calls 4

getCommandOutputFunction · 0.90
isInstalledFunction · 0.90
readFileFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected