imagemin / cwebp-bin

cwebp bin-wrapper that makes it seamlessly available as a local dependency
https://developers.google.com/speed/webp
MIT License
91 stars 36 forks source link

Locally installed distro binaries ignored? #27

Open polarathene opened 5 years ago

polarathene commented 5 years ago

I have a docker alpine image. I'm building it without wanting to compile binaries for packages. I have cwebp binary from an official Alpine package installed already. cwebp -version returns 1.0.0, this package only seems to source binaries via URLs to this repo and then call the binary version check?

Not sure why this is failing, is it downloading a binary for linux assuming compatibility with Alpine and preferring that invalid binary to the globally installed one?

node node_modules/cwebp-bin/lib/install.js
  ⚠ spawn /site/node_modules/cwebp-bin/vendor/cwebp ENOENT
  ⚠ cwebp pre-build test failed
  ℹ compiling from source

It's here:

ls node_modules/cwebp-bin/vendor
cwebp

fails to run:

./node_modules/cwebp-bin/vendor/cwebp -version
/bin/sh: ./node_modules/cwebp-bin/vendor/cwebp: not found

outside of that location, running installed alpine package version works fine:

cwebp -version
1.0.0
polarathene commented 5 years ago

I see that bin-wrapper .run() is meant to check for local binaries before downloading source to build. With pngquant-bin this works correctly.

which pngquant
/usr/bin/pngquant

which cwebp
/usr/bin/cwebp

I have tried to compare between the two projects but I'm not noticing any differences as to why pngquant is working as expected and cwebp is having trouble?

polarathene commented 5 years ago

pngquant-bin was doing the same thing, just it's binary was smaller/faster to add I guess and compatible.

The .run() method appears to only work on the binary if it's in the .dest() path. I changed the path to /usr/bin in my case and it was able to find cwebp successfully.. though that's not really a solution for fixing this package.. :(

polarathene commented 5 years ago

Tracking PR. If this gets merged, all the imagemin binary packages relying on bin-wrapper can benefit. Just needs to use an env var to allow using system binaries instead :)

geonanorch commented 4 years ago

@polarathene from what I can see in the Google documentation (and from trying to add pngquant in the path before invoking cwebp) the cwebp binary does not care about external executables: the development version of the relevant libraries (e.g. libpng-dev) must be available at compile time, AND in some cases (dynamic linking) must be available (on the path) at runtime as well. See issue #39 , similar story.

stck commented 4 years ago

Actually I've solved this for myself by archiving necessary modules like cwebp,mozjpeg,pngquant into some tar archive. Now, my images do not require any c compilers and dynamic libs but libjpeg-turbo and libpng. Negative side-effects - i'm not able to use npm ci (node_modules are cleared before npm ci)

aaharu commented 4 years ago

I've solved this by forking. https://www.npmjs.com/package/@mole-inc/cwebp-bin

I've changed the postinstall script to use system binaries by creating symlink. https://github.com/mole-inc/cwebp-bin/blob/4096d2e/lib/install.js#L36-L63