expo / expo-cli

Tools for creating, running, and deploying universal Expo and React Native apps
https://docs.expo.io/workflow/expo-cli/
2.61k stars 477 forks source link

[doctor] check for sdkVersion in Expo config #4732

Closed keith-kurak closed 1 year ago

keith-kurak commented 1 year ago

Why

Detects when someone's upgrade goes awry due to sdkVersion in Expo config overriding the actual installed SDK version. (e.g., https://github.com/expo/expo/issues/23351)

How

We can't use exp from getExpoConfig() because this always populates sdkVersion (either based on installed version or expo.sdkVersion). So, we have to read the actual Expo config to see if sdkVersion was set. This is really only practical in Doctor for a static config file. We could possibly attempt some comparison between exp's sdkVersion and package.json, but there'd be limitations to have to tiptoe around there.

One other option would be to actually change @expo/config to expose where sdkVersion came from. Not sure if it's worth the effort, though.

@brentvatne I can add some unit tests to this, but wanted to first run the concept by you first to see if we should take this approach or go further in one of the directions described above before I spent more time on it.

On Brent's advice, we now compare the final output from getConfig in @expo/config with how @expo/config resolves the installed SDK version. If they don't match, sdkVersion is being overridden in the Expo config, whether it's static or dynamic.

Test Plan

The message itself:

image

When you put in the wrong sdkVersion, you also get a ton of wrong package versions from the step where it checks against bundledNativeModules (not pictured)