Skip to content

Commit 46e8792

Browse files
authored
fix(cli): Don't downgrade deployment target on migrate (#7953)
1 parent c3ea809 commit 46e8792

3 files changed

Lines changed: 45 additions & 28 deletions

File tree

cli/src/ios/common.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execSync } from 'child_process';
2-
import { readFile, writeFile } from 'fs-extra';
3-
import { resolve } from 'path';
2+
import { readFile, readFileSync, writeFile } from 'fs-extra';
3+
import { join, resolve } from 'path';
44

55
import c from '../colors';
66
import { checkCapacitorPlatform } from '../common';
@@ -103,3 +103,13 @@ export async function editProjectSettingsIOS(config: Config): Promise<void> {
103103
await writeFile(plistPath, plistContent, { encoding: 'utf-8' });
104104
await writeFile(pbxPath, pbxContent, { encoding: 'utf-8' });
105105
}
106+
107+
export function getMajoriOSVersion(config: Config): string {
108+
const pbx = readFileSync(join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'utf-8');
109+
const searchString = 'IPHONEOS_DEPLOYMENT_TARGET = ';
110+
const iosVersion = pbx.substring(
111+
pbx.indexOf(searchString) + searchString.length,
112+
pbx.indexOf(searchString) + searchString.length + 2,
113+
);
114+
return iosVersion;
115+
}

cli/src/tasks/migrate.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import c from '../colors';
88
import { getCoreVersion, runTask, checkJDKMajorVersion } from '../common';
99
import type { Config } from '../definitions';
1010
import { fatal } from '../errors';
11+
import { getMajoriOSVersion } from '../ios/common';
1112
import { logger, logPrompt, logSuccess } from '../log';
1213
import { getPlugins } from '../plugin';
1314
import { deleteFolderRecursive } from '../util/fs';
@@ -48,6 +49,7 @@ const plugins = [
4849
const coreVersion = '^7.0.0';
4950
const pluginVersion = '^7.0.0';
5051
const gradleVersion = '8.11.1';
52+
const iOSVersion = '14';
5153
let installFailed = false;
5254

5355
export async function migrateCommand(config: Config, noprompt: boolean, packagemanager: string): Promise<void> {
@@ -90,7 +92,7 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
9092

9193
const { migrateconfirm } = noprompt
9294
? { migrateconfirm: 'y' }
93-
: await logPrompt(`Capacitor 7 sets a deployment target of iOS 14 and Android 15 (SDK 35). \n`, {
95+
: await logPrompt(`Capacitor 7 sets a deployment target of iOS ${iOSVersion} and Android 15 (SDK 35). \n`, {
9496
type: 'text',
9597
name: 'migrateconfirm',
9698
message: `Are you sure you want to migrate? (Y/n)`,
@@ -147,23 +149,33 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
147149

148150
// Update iOS Projects
149151
if (allDependencies['@capacitor/ios'] && existsSync(config.ios.platformDirAbs)) {
150-
// ios template changes
151-
// Set deployment target to 14.0
152-
await runTask(`Migrating deployment target to 14.0.`, () => {
153-
return updateFile(
154-
config,
155-
join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'),
156-
'IPHONEOS_DEPLOYMENT_TARGET = ',
157-
';',
158-
'14.0',
159-
);
160-
});
161-
162-
if ((await checkPackageManager(config)) === 'Cocoapods') {
163-
// Update Podfile to 14.0
164-
await runTask(`Migrating Podfile to 14.0.`, () => {
165-
return updateFile(config, join(config.ios.nativeProjectDirAbs, 'Podfile'), `platform :ios, '`, `'`, '14.0');
152+
const currentiOSVersion = getMajoriOSVersion(config);
153+
if (parseInt(currentiOSVersion) < parseInt(iOSVersion)) {
154+
// ios template changes
155+
await runTask(`Migrating deployment target to ${iOSVersion}.0.`, () => {
156+
return updateFile(
157+
config,
158+
join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'),
159+
'IPHONEOS_DEPLOYMENT_TARGET = ',
160+
';',
161+
`${iOSVersion}.0`,
162+
);
166163
});
164+
165+
if ((await checkPackageManager(config)) === 'Cocoapods') {
166+
// Update Podfile
167+
await runTask(`Migrating Podfile to ${iOSVersion}.0.`, () => {
168+
return updateFile(
169+
config,
170+
join(config.ios.nativeProjectDirAbs, 'Podfile'),
171+
`platform :ios, '`,
172+
`'`,
173+
`${iOSVersion}.0`,
174+
);
175+
});
176+
}
177+
} else {
178+
logger.warn('Skipped updating deployment target');
167179
}
168180
}
169181

cli/src/util/spm.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { existsSync, readFileSync, writeFileSync } from 'fs-extra';
2-
import { join, relative, resolve } from 'path';
1+
import { existsSync, writeFileSync } from 'fs-extra';
2+
import { relative, resolve } from 'path';
33

44
import { getCapacitorPackageVersion } from '../common';
55
import type { Config } from '../definitions';
6+
import { getMajoriOSVersion } from '../ios/common';
67
import { logger } from '../log';
78
import type { Plugin } from '../plugin';
89

@@ -37,13 +38,7 @@ export async function generatePackageFile(config: Config, plugins: Plugin[]): Pr
3738

3839
async function generatePackageText(config: Config, plugins: Plugin[]): Promise<string> {
3940
const iosPlatformVersion = await getCapacitorPackageVersion(config, config.ios.name);
40-
41-
const pbx = readFileSync(join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'utf-8');
42-
const searchString = 'IPHONEOS_DEPLOYMENT_TARGET = ';
43-
const iosVersion = pbx.substring(
44-
pbx.indexOf(searchString) + searchString.length,
45-
pbx.indexOf(searchString) + searchString.length + 2,
46-
);
41+
const iosVersion = getMajoriOSVersion(config);
4742

4843
let packageSwiftText = `// swift-tools-version: 5.9
4944
import PackageDescription

0 commit comments

Comments
 (0)