-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
6 changed files
with
205 additions
and
145 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 was deleted.
Oops, something went wrong.
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,59 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const spawnSync = require('child_process').spawnSync; | ||
const semver = require('semver'); | ||
const platform = require('./platform'); | ||
|
||
const minimumLibvipsVersion = process.env.npm_package_config_libvips || require('../package.json').config.libvips; | ||
|
||
const spawnSyncOptions = { | ||
encoding: 'utf8', | ||
shell: true | ||
}; | ||
|
||
const globalLibvipsVersion = function () { | ||
if (process.platform !== 'win32') { | ||
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout || ''; | ||
return globalLibvipsVersion.trim(); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
const hasVendoredLibvips = function () { | ||
const currentPlatformId = platform(); | ||
try { | ||
const vendorPlatformId = require(path.join(__dirname, '..', 'vendor', 'platform.json')); | ||
if (currentPlatformId === vendorPlatformId) { | ||
return true; | ||
} else { | ||
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`); | ||
} | ||
} catch (err) {} | ||
return false; | ||
}; | ||
|
||
const pkgConfigPath = function () { | ||
if (process.platform !== 'win32') { | ||
const brewPkgConfigPath = spawnSync('which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR', spawnSyncOptions).stdout || ''; | ||
return [brewPkgConfigPath.trim(), process.env.PKG_CONFIG_PATH, '/usr/local/lib/pkgconfig', '/usr/lib/pkgconfig'] | ||
.filter(function (p) { return !!p; }) | ||
.join(':'); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
const useGlobalLibvips = function () { | ||
const globalVipsVersion = globalLibvipsVersion(); | ||
return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion); | ||
}; | ||
|
||
module.exports = { | ||
minimumLibvipsVersion: minimumLibvipsVersion, | ||
globalLibvipsVersion: globalLibvipsVersion, | ||
hasVendoredLibvips: hasVendoredLibvips, | ||
pkgConfigPath: pkgConfigPath, | ||
useGlobalLibvips: useGlobalLibvips | ||
}; |
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,76 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const detectLibc = require('detect-libc'); | ||
const npmLog = require('npmlog'); | ||
const semver = require('semver'); | ||
const simpleGet = require('simple-get'); | ||
const tar = require('tar'); | ||
|
||
const agent = require('./lib/agent'); | ||
const libvips = require('./lib/libvips'); | ||
const platform = require('./lib/platform'); | ||
|
||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion; | ||
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`; | ||
|
||
try { | ||
const globalLibvipsVersion = libvips.globalLibvipsVersion(); | ||
if (globalLibvipsVersion) { | ||
npmLog.info('sharp', `Using globally-installed libvips v${globalLibvipsVersion}`); | ||
} else if (libvips.hasVendoredLibvips()) { | ||
npmLog.info('sharp', `Using existing vendored libvips v${minimumLibvipsVersion}`); | ||
} else { | ||
// Is this arch/platform supported? | ||
const arch = process.env.npm_config_arch || process.arch; | ||
if (arch === 'ia32') { | ||
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}\n`); | ||
} | ||
if (detectLibc.isNonGlibcLinux) { | ||
throw new Error(`Use with ${detectLibc.family} libc requires manual installation of libvips >= ${minimumLibvipsVersion}`); | ||
} | ||
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && semver.lt(`${detectLibc.version}.0`, '2.13.0')) { | ||
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`); | ||
} | ||
// Download to per-process temporary file | ||
const tarFilename = ['libvips', minimumLibvipsVersion, platform()].join('-') + '.tar.gz'; | ||
const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`); | ||
const tmpFile = fs.createWriteStream(tarPathTemp); | ||
const url = distBaseUrl + tarFilename; | ||
npmLog.info('sharp', `Downloading ${url}`); | ||
simpleGet({ url: url, agent: agent() }, function (err, response) { | ||
if (err) { | ||
throw err; | ||
} | ||
if (response.statusCode !== 200) { | ||
throw new Error(`Status ${response.statusCode}`); | ||
} | ||
response.pipe(tmpFile); | ||
}); | ||
tmpFile.on('close', function () { | ||
const vendorPath = path.join(__dirname, 'vendor'); | ||
fs.mkdirSync(vendorPath); | ||
tar | ||
.extract({ | ||
file: tarPathTemp, | ||
cwd: vendorPath, | ||
strict: true | ||
}) | ||
.then(function () { | ||
try { | ||
fs.unlinkSync(tarPathTemp); | ||
} catch (err) {} | ||
}) | ||
.catch(function (err) { | ||
throw err; | ||
}); | ||
}); | ||
} | ||
} catch (err) { | ||
npmLog.error('sharp', err.message); | ||
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install'); | ||
process.exit(1); | ||
} |
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
Oops, something went wrong.