Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[image-utils] [ENG-9956] add a function to check whether a PNG is valid #4761

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

kadikraman
Copy link
Contributor

@kadikraman kadikraman commented Sep 20, 2023

Why

We want to check whether the app icon and splash screen images in the codebase are invalid before pre-building so we could show the user an error message and fail the build. ENG-9956.

How

Added an getPngInfo function returns the PNG data if a valid PNG is found, and throws otherwise.

Intended usage:

import { getPngInfo } from '@expo/image-utils';

function assertValidPng(filePath: string) {
  try {
    getPngInfo(filePath);
  } catch (error) {
    if (error.code === 'ENOENT') {
      throw new CommandError('IMAGE_NOT_FOUND', `There was no image at ${filePath}`);
    }

    if (error.message.includes('Invalid file signature')) {
      throw new CommandError('IMAGE_CORRUPTED', `The image at ${filePath} is corrupted: ${error.message}`);
    }

    // unknown error
    throw error;
  }
}

Test Plan

Added packages/image-utils/src/__tests__/image-test.ts to verify for different file types.

@linear
Copy link

linear bot commented Sep 20, 2023

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

Copy link
Member

@byCedric byCedric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for working on this!

@kadikraman kadikraman merged commit a100d1b into main Sep 21, 2023
@kadikraman kadikraman deleted the @kadikraman/validate-png branch September 21, 2023 10:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy