-
Notifications
You must be signed in to change notification settings - Fork 477
[doctor] check for sdkVersion in Expo config #4732
Conversation
* version of the `expo` package. | ||
* Adapted from https://github.com/expo/expo/blob/main/packages/%40expo/config/src/getExpoSDKVersion.ts | ||
*/ | ||
function getExpoSDKVersionFromPackage(projectRoot: string): string | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we can ask @expo/config
? If so, I think that might be a better bet. The main reason for that is that we probably want @expo/config
to handle all configuration loading, including the app manifest.
When we change something in a future version of @expo/config
, we also need to make that change here. That is, unless we use the installed @expo/config
package from the project and just use that here.
I do the same for expo-github-action
, where I pull the configuration file, required to retrieve basic information for the update / preview sub-action. (see this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get sdkVersion
from Expo config, but not where the sdkVersion
came from (Expo config or installed dependency). We use the sdkVersion
from @expo/config
everywhere else, but here, the idea is to check if someone overrode it in their Expo config (which in turn can usually break your build and throw off most other doctor checks). This is copied from @expo/config
, but it's really just checking the version of the expo
package installed, so I don't think it would change often.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Why
Detects when someone's upgrade goes awry due to
sdkVersion
in Expo config overriding the actual installed SDK version. (e.g., expo/expo#23351)How
We can't useexp
fromgetExpoConfig()
because this always populatessdkVersion
(either based on installed version orexpo.sdkVersion
). So, we have to read the actual Expo config to see ifsdkVersion
was set. This is really only practical in Doctor for a static config file. We could possibly attempt some comparison between exp'ssdkVersion
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 wheresdkVersion
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](https://private-user-images.githubusercontent.com/8053974/253666267-6c9e3582-546a-4bc0-b2e7-d8e6fe26d679.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0NjM5MjcsIm5iZiI6MTcyMDQ2MzYyNywicGF0aCI6Ii84MDUzOTc0LzI1MzY2NjI2Ny02YzllMzU4Mi01NDZhLTRiYzAtYjJlNy1kOGU2ZmUyNmQ2NzkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDhUMTgzMzQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NGNlZjQwMDZmNjZiMDBjMDBjN2JiOWQzN2RiOTViZjhlMDFiMzYzZmU3MjBlZTE2NzVhZTY5Zjg1NjEzOGMyYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.GO073SnX4HWgmQ3l2I3WGqZs_3f83LFkNUmvekY93xU)
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)