expo / expo-cli

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

[schemer] [ENG-9956]: validate for unsupported images #4764

Closed kadikraman closed 9 months ago

kadikraman commented 9 months ago

Why

We wanted Expo Doctor to be able to warn against cases like this: https://expo.dev/builds/286155f5-b460-4982-b006-b59f1cd8151f

What's wrong here is:

  1. there are several assets with .jpg file extensions which aren't getting validated
  2. prebuild fails because they're trying to use a webp asset which is not supported

How

To handle each of those cases:

  1. if you rename a .png file extension to .jpg, expo doctor will still pass since it only looks at the file content, not the extension. I've added a new error FILE_EXTENSION_MISMATCH which will warn you if the mime type does not match eht file extension
  2. if you use a webp image, it will always pass the Doctor check because of this line https://github.com/expo/expo-cli/blob/main/packages/schemer/src/index.ts#L196 - the library was unable to parse it and just failed silently. I updated the code to get the image data to use the example in their https://github.com/nodeca/probe-image-size#example

I also updated the tests from js -> ts and refactored them slightly to be more future proof. I also added quite a few more tests for general image validation.

Test Plan

Tests! Many unit tests.

linear[bot] commented 9 months ago
ENG-9956 Discuss where to validate app icons files / splash screen files

We should validate any of the images that can be specified in Expo app config. Should we validate these images (that they are valid pngs, and whatever else) inside of doctor? Or is there another place that would make more sense? If in doctor, should we be running doctor before running a build? (or some subset of doctor checks?) [image (2).png](https://uploads.linear.app/4a409308-b1e3-45fc-94fd-9ef8703ee369/0e59982a-7226-477d-98fd-26e5a05eb897/2cd983a9-f174-43e8-b7b5-801a647f62e9)