-
Notifications
You must be signed in to change notification settings - Fork 479
fix: make sharp image processing library an optional dependency #742
Conversation
}; | ||
|
||
type Options = | ||
| {} |
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.
Why do we need 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.
TypeScript complained that {}
is not compatible with Options
. (The options for the removeAlpha
operation are {}
.)
|
||
const SHARP_HELP_PATTERN = /\n\nSpecify --help for available options/g; | ||
|
||
export async function sharpAsync( |
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.
Specify return values in TypeScript too?
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.
👍
// Delete the optimized version and revert changes | ||
fs.renameSync(newName, image); | ||
if (amountSaved > 0) { | ||
await fs.move(image, newName); |
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.
Promise.all
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.
These operations should not happen in parallel – we first move the old file to filename.orig.ext
and then move the optimized image from a temporary folder to its place.
Why?
Installing the
sharp
image processing library can fail for a few resons:node_modules
folder. Cannot install expo-cli global (windows 10) #650 I can not install here, Ubuntu 18.04.2 #613 Expo CLI cant be installed in Linux #591 Can't install expo-cli #590When sharp installation fails, previously the whole Expo CLI installation has failed.
How
To make it possible to install Expo CLI without
sharp
, this PR makessharp
an optional dependency (via thesharp-cli
package). Only certain functionality (expo optimize
and web builds) requiresharp
.For most users sharp will be installed without problems, and those users will be able to use all features without any additional setup.
Those users who previously had problems installing
sharp
will continue to see warnings when installing but because the dependency is now optional, it won’t fail the whole installation. They will also be able to use Expo CLI. When trying to use functionality that requiressharp
, Expo CLI will prompt themto separately install the
sharp-cli
package globally. Aftersharp-cli
is installed, those commands can be used.Further improvements
In the future, we could make our own distribution of sharp to fix the permissions issues (using the same method we use for ngrok and traveling fastlane). Additionally we could provide JS-only fallbacks (even if they’re slower) for platforms that sharp doesn’t support.