File tree Expand file tree Collapse file tree 4 files changed +75
-2
lines changed
Expand file tree Collapse file tree 4 files changed +75
-2
lines changed Original file line number Diff line number Diff line change 22const path = require ( 'path' ) ;
33const BinWrapper = require ( 'bin-wrapper' ) ;
44const pkg = require ( '../package.json' ) ;
5+ const getBinaryUrl = require ( '../utils' ) ;
56
6- const url = `https://raw.githubusercontent.com/imagemin/pngquant-bin/v${ pkg . version } /vendor/` ;
7+ const url = getBinaryUrl ( pkg . version , pkg )
8+ // `https://raw.githubusercontent.com/imagemin/pngquant-bin/v${pkg.version}/vendor/`;
79
810module . exports = new BinWrapper ( )
911 . src ( `${ url } macos/pngquant` , 'darwin' )
Original file line number Diff line number Diff line change 2828 },
2929 "scripts" : {
3030 "postinstall" : " node lib/install.js" ,
31- "test" : " xo && ava --timeout=120s"
31+ "test" : " ava --timeout=120s && node ./utils.test.js "
3232 },
3333 "files" : [
3434 " cli.js" ,
Original file line number Diff line number Diff line change 1+ /**
2+ * Determine the URL to fetch binary file from.
3+ * By default fetch from the pngquant-bin distribution
4+ * site on GitHub.
5+ *
6+ * The default URL can be overridden using
7+ * the environment variable PNGQUANT_BIN_BINARY_SITE,
8+ * .npmrc variable pngquant_bin_binary_site or
9+ *
10+ * The URL should to the mirror of the repository
11+ * laid out as follows:
12+ *
13+ * PNGQUANT_BIN_BINARY_SITE/
14+ *
15+ * vX.X.X
16+ * vX.X.X/macos/pngquant
17+ *
18+ * @example `https://raw.githubusercontent.com/imagemin/pngquant-bin/v${pkg.version}/vendor/`;
19+ */
20+ module . exports = function getBinaryUrl ( version , pgkConfig = { } ) {
21+ if ( ! version ) {
22+ return ''
23+ }
24+
25+ let site = process . env . PNGQUANT_BIN_BINARY_SITE ||
26+ process . env . npm_config_pngquant_bin_binary_site ||
27+ ( pgkConfig . pngquantBinConfig && pgkConfig . pngquantBinConfig . binarySite ) ||
28+ 'https://raw.githubusercontent.com/imagemin/pngquant-bin' ;
29+
30+ if ( site [ site . length - 1 ] === '/' ) {
31+ site = site . slice ( 0 , - 1 )
32+ }
33+
34+ return `${ site } /v${ version } /vendor/`
35+ }
Original file line number Diff line number Diff line change 1+ const assert = require ( 'assert' )
2+ const getBinaryUrl = require ( './utils' )
3+
4+ function main ( ) {
5+ const version = '1.1.1'
6+ const site = 'https://a.b.c/folder'
7+ const pkg = {
8+ pngquantBinConfig : {
9+ binarySite : site ,
10+ } ,
11+ }
12+ const pkg2 = {
13+ pngquantBinConfig : {
14+ binarySite : `${ site } /` ,
15+ } ,
16+ }
17+
18+
19+ assert ( getBinaryUrl ( version ) ===
20+ `https://raw.githubusercontent.com/imagemin/pngquant-bin/v${ version } /vendor/` , 'fail1' )
21+ assert ( getBinaryUrl ( version , pkg ) === `https://a.b.c/folder/v${ version } /vendor/` , 'fail2' )
22+ assert ( getBinaryUrl ( version , pkg2 ) === `https://a.b.c/folder/v${ version } /vendor/` , 'fail2' )
23+
24+ // test PNGQUANT_BIN_BINARY_SITE
25+ const cacheEnv = { ...process . env }
26+ process . env . PNGQUANT_BIN_BINARY_SITE = site
27+ assert ( getBinaryUrl ( version ) === `https://a.b.c/folder/v${ version } /vendor/` , 'fail2' )
28+ process . env = { ...cacheEnv }
29+
30+ // test .npmrc npm_config_pngquant_bin_binary_site
31+ process . env . npm_config_pngquant_bin_binary_site = site
32+ assert ( getBinaryUrl ( version ) === `https://a.b.c/folder/v${ version } /vendor/` , 'fail2' )
33+ process . env = { ...cacheEnv }
34+ }
35+
36+ main ( )
You can’t perform that action at this time.
0 commit comments