bin-wrapper icon indicating copy to clipboard operation
bin-wrapper copied to clipboard

Ability to specify base url

Open ConfuddledPenguin opened this issue 5 years ago • 4 comments

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 avatar Jul 09 '19 18:07 ConfuddledPenguin

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,

ConfuddledPenguin avatar Aug 15 '19 19:08 ConfuddledPenguin

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

EscapeB avatar Dec 29 '21 03:12 EscapeB

+1

MondoGao avatar Mar 28 '22 06:03 MondoGao

we should add support with npm_config_<env_name>

MondoGao avatar Mar 28 '22 06:03 MondoGao