MCPcopy Create free account
hub / github.com/reactnativecn/react-native-update / getExpoMajorVersion

Function getExpoMajorVersion

scripts/check-expo-version.js:14–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12const expoConfigPath = path.resolve(projectRoot, 'expo-module.config.json');
13
14function getExpoMajorVersion() {
15 let resolvedExpoPackagePath;
16 try {
17 // Use require.resolve to find expo's package.json from the host project's perspective
18 resolvedExpoPackagePath = require.resolve('expo/package.json', {
19 paths: [path.resolve(projectRoot, '..', '..')],
20 });
21 } catch (e) {
22 console.log(
23 'Expo not found in project node_modules (via require.resolve).',
24 );
25 return null; // Expo not found or resolvable
26 }
27
28 // Check if the resolved path actually exists (belt-and-suspenders)
29 if (!fs.existsSync(resolvedExpoPackagePath)) {
30 console.log(
31 `Expo package.json path resolved to ${resolvedExpoPackagePath}, but file does not exist.`,
32 );
33 return null;
34 }
35
36 try {
37 const packageJson = JSON.parse(
38 fs.readFileSync(resolvedExpoPackagePath, 'utf8'),
39 );
40 const version = packageJson.version;
41 if (!version) {
42 console.log('Expo package.json does not contain a version.');
43 return null; // Version not found
44 }
45
46 // Extract the first number sequence as the major version
47 const match = version.match(/\d+/);
48 if (!match) {
49 console.log(
50 `Could not parse major version from Expo version string: ${version}`,
51 );
52 return null; // Cannot parse version
53 }
54
55 return parseInt(match[0], 10);
56 } catch (error) {
57 console.error('Error reading or parsing Expo package.json:', error);
58 return null; // Error during processing
59 }
60}
61
62function checkAndCleanExpoConfig() {
63 const majorVersion = getExpoMajorVersion();

Callers 1

checkAndCleanExpoConfigFunction · 0.85

Calls 2

resolveMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected