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

Commit

Permalink
[expo-cli] don't allow to use png icon with alpha channel (#399)
Browse files Browse the repository at this point in the history
Closes #374
  • Loading branch information
dsokal committed Feb 28, 2019
1 parent 019351d commit f13b545
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/expo-cli/src/commands/build/ios/IOSBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import isEmpty from 'lodash/isEmpty';
import pickBy from 'lodash/pickBy';
import get from 'lodash/get';
import { XDLError, ErrorCode } from 'xdl';
import fs from 'fs-extra';

import BaseBuilder from '../BaseBuilder';
import { PLATFORMS } from '../constants';
Expand All @@ -28,6 +29,8 @@ class IOSBuilder extends BaseBuilder {
const bundleIdentifier = get(this.manifest, 'ios.bundleIdentifier');
const sdkVersion = this.manifest.sdkVersion;

await this.validateIcon();

if (!bundleIdentifier) {
throw new XDLError(
ErrorCode.INVALID_OPTIONS,
Expand Down Expand Up @@ -158,6 +161,30 @@ See https://docs.expo.io/versions/latest/distribution/building-standalone-apps/#
platform() {
return PLATFORMS.IOS;
}

// validates whether the icon doesn't have alpha channel
// copy-pasted from https://github.com/tj/node-png-has-alpha/blob/master/index.js
async validateIcon() {
try {
const icon = get(this.manifest, 'ios.icon', this.manifest.icon);
const buf = new Buffer(1);
const fd = await fs.open(icon, 'r');
const { buffer } = await fs.read(fd, buf, 0, 1, 25);
await fs.close(fd);
if (buffer[0] === 6) {
throw new XDLError(
ErrorCode.INVALID_ASSETS,
`Your application icon (${icon}) can't have an alpha channel if you wish to upload your app to Apple Store.`
);
}
} catch (err) {
if (err instanceof XDLError) {
throw err;
} else {
// something weird happened, let's assume the icon is correct
}
}
}
}

export default IOSBuilder;

0 comments on commit f13b545

Please sign in to comment.