kevva / bin-wrapper

Binary wrapper that makes your programs seamlessly available as local dependencies
MIT License
152 stars 65 forks source link

Ability to specify base url #73

Open ConfuddledPenguin opened 5 years ago

ConfuddledPenguin commented 5 years ago

Adds the ability to specify a base url to use when performing configuration.

This allows you to follow the following pattern:

const BinWrapper = require('bin-wrapper');

const bin = new BinWrapper()
    .baseUrl('https://github.com/imagemin/gifsicle-bin/raw/master/vendor')
    .src(`/linux/x64/gifsicle`, 'linux', 'x64')
    .src(`/linux/x86/gifsicle`, 'linux', 'x86')
    .dest(path.join('vendor'))
    .use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle')

Additionally added the ability for developers to allow for this base url to be easily configured when this library is used to expose a binary.

For example, in the below example when the GIFSICLE_BIN__MIRROR env var is set, this will be used as the base location from which to perform the download:

const BinWrapper = require('bin-wrapper');

const bin = new BinWrapper()
    .baseUrl('https://github.com/imagemin/gifsicle-bin/raw/master/vendor')
        .baseUrlOverrideEnvName('GIFSICLE_BIN__MIRROR')
    .src(`/linux/x64/gifsicle`, 'linux', 'x64')
    .dest(path.join('vendor'))
    .use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle')

This allows for developers to easily add support for configuring the binary download location, this allows developers to easily support 3rd party binary mirrors and cases where due to security considerations downloading from an external source can not be considered.

ConfuddledPenguin commented 5 years ago

Hi @sindresorhus,

Sorry to chase but keen to get this issue looked at, in order to make changes on projects which use this as a dependency,

EscapeB commented 2 years ago

Hi @sindresorhus , could you please review and merge this PR ? We can only use internal network due to security consideration.

MondoGao commented 2 years ago

+1

MondoGao commented 2 years ago

we should add support with npmconfig