Skip to content

Commit c3c7e4f

Browse files
committed
iOS: Don't break string build numbers. Fixes #168
1 parent 0a1c456 commit c3c7e4f

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

packages/project/src/ios/project.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,16 @@ export class IosProject extends PlatformProject {
195195
* Set the build number (aka the `CURRENT_PROJECT_VERSION`) for the given target and build.
196196
* If the `targetName` is null the main app target is used. If the `buildName` is null the value is set for both builds (Debug/Release);
197197
*/
198-
async setBuild(targetName: IosTargetName | null, buildName: IosBuildName | null, buildNumber: number | null) {
198+
async setBuild(targetName: IosTargetName | null, buildName: IosBuildName | null, buildNumber: number | string | null) {
199199
if ((buildNumber as any) === '') {
200200
// This shouldn't happen but can
201201
buildNumber = 1;
202202
this.pbxProject?.updateBuildProperty('CURRENT_PROJECT_VERSION', 1, buildName, targetName);
203203
} else if (typeof buildNumber === 'string') {
204-
buildNumber = parseInt(buildNumber, 10);
204+
// Don't parse version strings
205+
if (buildNumber.indexOf('.') < 0) {
206+
buildNumber = parseInt(buildNumber, 10);
207+
}
205208
}
206209

207210
this.pbxProject?.updateBuildProperty('CURRENT_PROJECT_VERSION', buildNumber ?? 1, buildName, targetName);
@@ -254,8 +257,15 @@ export class IosProject extends PlatformProject {
254257
const num = await this.getBuild(targetName ?? null, buildName);
255258

256259
if (!isNaN(num)) {
257-
// If the value is a number, increment it
258-
return this.setBuild(targetName ?? null, buildName ?? null, num + 1);
260+
if (typeof num === 'number') {
261+
// If the value is a number, increment it
262+
return this.setBuild(targetName ?? null, buildName ?? null, num + 1);
263+
} else if (typeof num === 'string') {
264+
if (num.indexOf('.') < 0) {
265+
// If the value is a string and doesn't contain a period, increment it
266+
return this.setBuild(targetName ?? null, buildName ?? null, parseInt(num, 10) + 1);
267+
}
268+
}
259269
} else {
260270
// Otherwise, we need to check if there's a build property set for CURRENT_PROJECT_VERSION and create it if not
261271
let currentProjectVersion = this.pbxProject?.getBuildProperty('CURRENT_PROJECT_VERSION', buildName ? buildName : undefined/* must use undefined if null */, targetName);

packages/project/test/project.ios.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ describe('project - ios standard', () => {
111111
expect(updated?.getDocument()?.['CFBundleVersion']).toBe('$(CURRENT_PROJECT_VERSION)');
112112
});
113113

114+
it('should set string build numbers', async () => {
115+
await project.ios?.setBuild('App', 'Debug', '1.2.3');
116+
expect(await project.ios?.getBuild('App', 'Debug')).toBe('1.2.3');
117+
});
118+
119+
it('should increment build number', async () => {
120+
await project.ios?.setBuild('App', 'Debug', 42);
121+
expect(await project.ios?.getBuild('App', 'Debug')).toBe(42);
122+
await project.ios?.incrementBuild('App', 'Debug');
123+
expect(await project.ios?.getBuild('App', 'Debug')).toBe(43);
124+
await project.ios?.setBuild('App', 'Debug', '1.2.3');
125+
expect(await project.ios?.getBuild('App', 'Debug')).toBe('1.2.3');
126+
await project.ios?.incrementBuild('App', 'Debug');
127+
expect(await project.ios?.getBuild('App', 'Debug')).toBe('1.2.3');
128+
});
129+
114130
it('should set project version', async () => {
115131
await project.ios?.setVersion('App', 'Debug', '1.4.5');
116132
expect(project.ios?.getVersion('App', 'Debug')).toBe('1.4.5');

0 commit comments

Comments
 (0)