Skip to content

Commit 942ca5d

Browse files
mfazekasclaude
andauthored
Store default Mapbox iOS and Android versions in package.json (#4081)
This change centralizes the default Mapbox SDK versions in package.json instead of hardcoding them in platform-specific build files. Changes: - Added "mapbox" section to package.json with iOS and Android version fields - Updated android/build.gradle to read default version from package.json - Updated rnmapbox-maps.podspec to read default version from package.json - Updated scripts/autogenHelpers/generateCodeWithEjs.mjs to read versions from package.json This makes version management easier and provides a single source of truth for default SDK versions. Users can still override these versions using $RNMapboxMapsVersion (iOS) and RNMapboxMapsVersion (Android) as before. Inspired by: rive-app/rive-react-native#382 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 041b97f commit 942ca5d

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

android/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
def defaultMapboxMapsImpl = "mapbox"
2-
def defaultMapboxMapsVersion = "11.15.2"
2+
3+
def getDefaultMapboxMapsVersion() {
4+
def packageJson = new groovy.json.JsonSlurper().parseText(
5+
new File(projectDir.getPath(), "../package.json").text
6+
)
7+
return packageJson.mapbox.android
8+
}
9+
10+
def defaultMapboxMapsVersion = getDefaultMapboxMapsVersion()
311

412
def safeExtGet(prop, fallback) {
513
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"url": "https://github.com/rnmapbox/maps/issues"
7373
},
7474
"homepage": "https://github.com/rnmapbox/maps#readme",
75+
"mapbox": {
76+
"ios": "~> 11.15.2",
77+
"android": "11.15.2"
78+
},
7579
"publishConfig": {
7680
"registry": "https://registry.npmjs.org/",
7781
"access": "public"

rnmapbox-maps.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require 'json'
2020
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
2121

2222
## Warning: these lines are scanned by autogenerate.js
23-
rnMapboxMapsDefaultMapboxVersion = '~> 11.15.2'
23+
rnMapboxMapsDefaultMapboxVersion = package['mapbox']['ios']
2424

2525
rnMapboxMapsDefaultImpl = 'mapbox'
2626

scripts/autogenHelpers/generateCodeWithEjs.mjs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ejs from 'ejs';
22
import path from 'path';
33
import fs from 'fs';
44
import styleSpecJSON from '../../style-spec/v8.json' with { type: 'json' };
5+
import packageJSON from '../../package.json' with { type: 'json' };
56
import * as url from 'url';
67

78
import prettier from 'prettier';
@@ -12,33 +13,25 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
1213
import { camelCase } from './globals.mjs';
1314

1415
function readIosVersion() {
15-
const podspecPath = path.join(__dirname, '..', '..', 'rnmapbox-maps.podspec');
16-
const lines = fs.readFileSync(podspecPath, 'utf8').split('\n');
17-
const mapboxLineRegex =
18-
/^\s*rnMapboxMapsDefaultMapboxVersion\s*=\s*'~>\s+(\d+\.\d+)(\.\d+)?'$/;
19-
const mapboxLine = lines.filter((i) => mapboxLineRegex.exec(i))[0];
16+
const iosVersion = packageJSON.mapbox.ios;
17+
// Extract version number from format like "~> 11.15.2"
18+
const versionMatch = iosVersion.match(/(\d+\.\d+)(\.\d+)?/);
19+
if (!versionMatch) {
20+
throw new Error(`Invalid iOS version format in package.json: ${iosVersion}`);
21+
}
2022

2123
return {
2224
v10: '10.19.0',
23-
v11: `${mapboxLineRegex.exec(mapboxLine)[1]}.0`,
25+
v11: `${versionMatch[1]}.0`,
2426
};
2527
}
2628

2729
function readAndroidVersion() {
28-
const buildGradlePath = path.join(
29-
__dirname,
30-
'..',
31-
'..',
32-
'android',
33-
'build.gradle',
34-
);
35-
const lines = fs.readFileSync(buildGradlePath, 'utf8').split('\n');
36-
const mapboxV10LineRegex =
37-
/^\s*def\s+defaultMapboxMapsVersion\s+=\s+"(\d+\.\d+\.\d+)"$/;
38-
const mapboxV10Line = lines.filter((i) => mapboxV10LineRegex.exec(i))[0];
30+
const androidVersion = packageJSON.mapbox.android;
31+
3932
return {
4033
v10: '10.19.0',
41-
v11: mapboxV10LineRegex.exec(mapboxV10Line)[1],
34+
v11: androidVersion,
4235
};
4336
}
4437

0 commit comments

Comments
 (0)