Ensure vendor platform mismatch throws error #1303

This commit is contained in:
Lovell Fuller 2018-08-04 21:34:11 +01:00
parent 2de062a34a
commit 75556bb57c
2 changed files with 8 additions and 2 deletions

View File

@ -14,6 +14,9 @@ Requires libvips v8.6.1.
[#1290](https://github.com/lovell/sharp/pull/1290) [#1290](https://github.com/lovell/sharp/pull/1290)
[@sylvaindumont](https://github.com/sylvaindumont) [@sylvaindumont](https://github.com/sylvaindumont)
* Ensure vendor platform mismatch throws error at install time.
[#1303](https://github.com/lovell/sharp/issues/1303)
#### v0.20.5 - 27<sup>th</sup> June 2018 #### v0.20.5 - 27<sup>th</sup> June 2018
* Expose libjpeg optimize_coding flag. * Expose libjpeg optimize_coding flag.

View File

@ -23,14 +23,17 @@ const globalLibvipsVersion = function () {
const hasVendoredLibvips = function () { const hasVendoredLibvips = function () {
const currentPlatformId = platform(); const currentPlatformId = platform();
let vendorPlatformId;
try { try {
const vendorPlatformId = require(path.join(__dirname, '..', 'vendor', 'platform.json')); vendorPlatformId = require(path.join(__dirname, '..', 'vendor', 'platform.json'));
} catch (err) {}
if (vendorPlatformId) {
if (currentPlatformId === vendorPlatformId) { if (currentPlatformId === vendorPlatformId) {
return true; return true;
} else { } 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'.`); 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; return false;
}; };