()
| 12 | const expoConfigPath = path.resolve(projectRoot, 'expo-module.config.json'); |
| 13 | |
| 14 | function 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 | |
| 62 | function checkAndCleanExpoConfig() { |
| 63 | const majorVersion = getExpoMajorVersion(); |
no test coverage detected