Support gyp-based (re)build without npm env vars #412

This commit is contained in:
Lovell Fuller 2016-04-16 20:35:28 +01:00
parent c808139b02
commit cb10f9a9c8

View File

@ -12,6 +12,9 @@ var tmp = require('os').tmpdir();
var distBaseUrl = 'https://dl.bintray.com/lovell/sharp/'; var distBaseUrl = 'https://dl.bintray.com/lovell/sharp/';
// Use NPM-provided environment variable where available, falling back to require-based method for Electron
var minimumLibvipsVersion = process.env.npm_package_config_libvips || require('./package.json').config.libvips;
var vipsHeaderPath = path.join(__dirname, 'include', 'vips', 'vips.h'); var vipsHeaderPath = path.join(__dirname, 'include', 'vips', 'vips.h');
// -- Helpers // -- Helpers
@ -75,7 +78,7 @@ module.exports.download_vips = function() {
} }
// Arch/platform-specific .tar.gz // Arch/platform-specific .tar.gz
var platform = (process.arch === 'arm') ? 'arm' : process.platform.substr(0, 3); var platform = (process.arch === 'arm') ? 'arm' : process.platform.substr(0, 3);
var tarFilename = ['libvips', process.env.npm_package_config_libvips, platform].join('-') + '.tar.gz'; var tarFilename = ['libvips', minimumLibvipsVersion, platform].join('-') + '.tar.gz';
var tarPath = path.join(__dirname, 'packaging', tarFilename); var tarPath = path.join(__dirname, 'packaging', tarFilename);
if (isFile(tarPath)) { if (isFile(tarPath)) {
unpack(tarPath); unpack(tarPath);
@ -114,13 +117,13 @@ module.exports.use_global_vips = function() {
if (globalVipsVersion) { if (globalVipsVersion) {
useGlobalVips = semver.gte( useGlobalVips = semver.gte(
globalVipsVersion, globalVipsVersion,
process.env.npm_package_config_libvips minimumLibvipsVersion
); );
} }
if (process.platform === 'darwin' && !useGlobalVips) { if (process.platform === 'darwin' && !useGlobalVips) {
if (globalVipsVersion) { if (globalVipsVersion) {
error( error(
'Found libvips ' + globalVipsVersion + ' but require ' + process.env.npm_package_config_libvips + 'Found libvips ' + globalVipsVersion + ' but require ' + minimumLibvipsVersion +
'\nPlease upgrade libvips by running: brew update && brew upgrade' '\nPlease upgrade libvips by running: brew update && brew upgrade'
); );
} else { } else {