imagemin / jpegtran-bin

jpegtran bin-wrapper that makes it seamlessly available as a local dependency
http://libjpeg-turbo.virtualgl.org
MIT License
93 stars 47 forks source link

Add support for setting custom binary site #90

Closed d0whc3r closed 5 years ago

sindresorhus commented 5 years ago

Thanks for the PR, but this should be solved in https://github.com/kevva/bin-wrapper, not in every binary module individually.

raymondwu1 commented 5 years ago

Thanks for the PR, but this should be solved in https://github.com/kevva/bin-wrapper, not in every binary module individually.

Hi this is also something that I would like to see added, what would your suggestion be to solve this? An environment variable that overrides the src input that is provided to bin-wrapper?

olivierdagenais commented 5 years ago

what would your suggestion be to solve this?

I have the same question, seeing as bin-wrapper doesn't seem to [currently] be designed such that this sort of feature would be possible without also updating downstream projects.

The pattern used by imagemin/mozjpeg-bin#42 and sass/node-sass suggests maybe that bin-wrapper could be updated to allow for something like (modified from the example supplied at kevva/bin-wrapper):

const base = 'https://github.com/imagemin/gifsicle-bin/raw/master/vendor';
const bin = new BinWrapper()
    .defaultBaseUrl(base)
    .baseOverrideEnvName("GIFSICLE_BINARY_SITE")
    .baseOverrideConfigName("gifsicle_binary_site")
    .src(`macos/gifsicle`, 'darwin')
    .src(`linux/x64/gifsicle`, 'linux', 'x64')
    .src(`win/x64/gifsicle.exe`, 'win32', 'x64')
    .dest(path.join('vendor'))
    .use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle')
    .version('>=1.71');

In other words, if defaultBaseUrl() is invoked, its value will be pre-pended to all values provided via src() (inserting a slash if necessary), with the possibility of overriding said default base URL using the environment variable named after the value supplied to baseOverrideEnvName() or the configuration key named after the value supplied to baseOverrideConfigName().

Is that what you had in mind?

olivierdagenais commented 5 years ago

My idea above still doesn't allow the base URL to be parameterized as in the imagemin/mozjpeg-bin case, unless the v${pkg.version}/vendor/ portion is repeated in each src() invocations.

ambroiseRabier commented 4 years ago

I have the same issue with this package, it is a dependencie from gatsby-plugin-sharp, that I need to display images in that are in markdown. This solution provided is similar to the one I have seen on sharp.