diff --git a/docs/changelog.md b/docs/changelog.md index fc0d618b..8169869c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -14,6 +14,9 @@ Requires libvips v8.6.1. [#1290](https://github.com/lovell/sharp/pull/1290) [@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 - 27th June 2018 * Expose libjpeg optimize_coding flag. diff --git a/lib/libvips.js b/lib/libvips.js index d8ddbd57..53599c95 100644 --- a/lib/libvips.js +++ b/lib/libvips.js @@ -23,14 +23,17 @@ const globalLibvipsVersion = function () { const hasVendoredLibvips = function () { const currentPlatformId = platform(); + let vendorPlatformId; 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) { 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; };