Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): use helper in Podfile with correct path #6888

Merged
merged 1 commit into from
Sep 12, 2023
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
30 changes: 21 additions & 9 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ async function updatePodfile(
deployment: boolean,
): Promise<void> {
const dependenciesContent = await generatePodFile(config, plugins);
const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);
const podfilePath = join(config.ios.nativeProjectDirAbs, 'Podfile');
let podfileContent = await readFile(podfilePath, { encoding: 'utf-8' });
podfileContent = podfileContent.replace(
/(def capacitor_pods)[\s\S]+?(\nend)/,
`$1${dependenciesContent}$2`,
);
podfileContent = podfileContent.replace(
`require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'`,
/(require_relative)[\s\S]+?(@capacitor\/ios\/scripts\/pods_helpers')/,
`require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`,
);
podfileContent = podfileContent.replace(
`def assertDeploymentTarget(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand All @@ -115,6 +119,7 @@ async function updatePodfile(
end
end
end`,
`require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`,
);
await writeFile(podfilePath, podfileContent, { encoding: 'utf-8' });

Expand Down Expand Up @@ -155,26 +160,33 @@ end`,
}
}

async function generatePodFile(
config: Config,
plugins: Plugin[],
): Promise<string> {
async function getRelativeCapacitoriOSPath(config: Config) {
const capacitoriOSPath = resolveNode(
config.app.rootDir,
'@capacitor/ios',
'package.json',
);

if (!capacitoriOSPath) {
fatal(
`Unable to find ${c.strong('node_modules/@capacitor/ios')}.\n` +
`Are you sure ${c.strong('@capacitor/ios')} is installed?`,
);
}

const podfilePath = config.ios.nativeProjectDirAbs;
const relativeCapacitoriOSPath = convertToUnixPath(
relative(podfilePath, await realpath(dirname(capacitoriOSPath))),
return convertToUnixPath(
relative(
config.ios.nativeProjectDirAbs,
await realpath(dirname(capacitoriOSPath)),
),
);
}

async function generatePodFile(
config: Config,
plugins: Plugin[],
): Promise<string> {
const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);

const capacitorPlugins = plugins.filter(
p => getPluginType(p, platform) === PluginType.Core,
Expand All @@ -186,7 +198,7 @@ async function generatePodFile(
}

return ` pod '${p.ios.name}', :path => '${convertToUnixPath(
relative(podfilePath, await realpath(p.rootPath)),
relative(config.ios.nativeProjectDirAbs, await realpath(p.rootPath)),
)}'\n`;
}),
);
Expand Down
13 changes: 1 addition & 12 deletions ios-template/App/Podfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
def assertDeploymentTarget(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# ensure IPHONEOS_DEPLOYMENT_TARGET is at least 13.0
deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f
should_upgrade = deployment_target < 13.0 && deployment_target != 0.0
if should_upgrade
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
end
require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'

platform :ios, '13.0'
use_frameworks!
Expand Down
Loading