-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Determine the URL to fetch binary file from. | ||
* By default fetch from the pngquant-bin distribution | ||
* site on GitHub. | ||
* | ||
* The default URL can be overridden using | ||
* the environment variable PNGQUANT_BIN_BINARY_SITE, | ||
* .npmrc variable pngquant_bin_binary_site or | ||
* | ||
* The URL should to the mirror of the repository | ||
* laid out as follows: | ||
* | ||
* PNGQUANT_BIN_BINARY_SITE/ | ||
* | ||
* vX.X.X | ||
* vX.X.X/macos/pngquant | ||
* | ||
* @example `https://github.com/raw/imagemin/pngquant-bin/v${pkg.version}/vendor/`; | ||
*/ | ||
module.exports = function getBinaryUrl(version, pgkConfig = {}) { | ||
if (!version) { | ||
return '' | ||
} | ||
|
||
let site = process.env.PNGQUANT_BIN_BINARY_SITE || | ||
process.env.npm_config_pngquant_bin_binary_site || | ||
(pgkConfig.pngquantBinConfig && pgkConfig.pngquantBinConfig.binarySite) || | ||
'https://github.com/raw/imagemin/pngquant-bin'; | ||
|
||
if (site[site.length - 1] === '/') { | ||
site = site.slice(0, -1) | ||
} | ||
|
||
return `${site}/v${version}/vendor/` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const assert = require('assert') | ||
const getBinaryUrl = require('./utils') | ||
|
||
function main() { | ||
const version = '1.1.1' | ||
const site = 'https://a.b.c/folder' | ||
const pkg = { | ||
pngquantBinConfig: { | ||
binarySite: site, | ||
}, | ||
} | ||
const pkg2 = { | ||
pngquantBinConfig: { | ||
binarySite: `${site}/`, | ||
}, | ||
} | ||
|
||
|
||
assert(getBinaryUrl(version) === | ||
`https://github.com/raw/imagemin/pngquant-bin/v${version}/vendor/`, 'fail1') | ||
assert(getBinaryUrl(version, pkg) === `https://a.b.c/folder/v${version}/vendor/`, 'fail2') | ||
assert(getBinaryUrl(version, pkg2) === `https://a.b.c/folder/v${version}/vendor/`, 'fail2') | ||
|
||
// test PNGQUANT_BIN_BINARY_SITE | ||
const cacheEnv = { ...process.env } | ||
process.env.PNGQUANT_BIN_BINARY_SITE = site | ||
assert(getBinaryUrl(version) === `https://a.b.c/folder/v${version}/vendor/`, 'fail2') | ||
process.env = { ...cacheEnv } | ||
|
||
// test .npmrc npm_config_pngquant_bin_binary_site | ||
process.env.npm_config_pngquant_bin_binary_site = site | ||
assert(getBinaryUrl(version) === `https://a.b.c/folder/v${version}/vendor/`, 'fail2') | ||
process.env = { ...cacheEnv } | ||
} | ||
|
||
main() |