From b69a54fc75a21e12caf80fc7d12c1693a8b4b45b Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 16 May 2021 19:40:43 +0100 Subject: [PATCH] Ensure presence of libvips before invoking node-gyp --- docs/changelog.md | 2 ++ install/can-compile.js | 11 +++++++++++ install/libvips.js | 1 - package.json | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 install/can-compile.js diff --git a/docs/changelog.md b/docs/changelog.md index 6f65132d..9f9c5cfa 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,8 @@ Requires libvips v8.10.6 ### v0.28.3 - TBD +* Ensure presence of libvips, vendored or global, before invoking node-gyp. + * Skip shrink-on-load for multi-page WebP. [#2714](https://github.com/lovell/sharp/issues/2714) diff --git a/install/can-compile.js b/install/can-compile.js new file mode 100644 index 00000000..3534b310 --- /dev/null +++ b/install/can-compile.js @@ -0,0 +1,11 @@ +'use strict'; + +const libvips = require('../lib/libvips'); + +try { + if (!(libvips.useGlobalLibvips() || libvips.hasVendoredLibvips())) { + process.exitCode = 1; + } +} catch (err) { + process.exitCode = 1; +} diff --git a/install/libvips.js b/install/libvips.js index 52bc20c9..098c61e8 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -43,7 +43,6 @@ const fail = function (err) { if (err.code === 'EACCES') { libvips.log('Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag'); } - libvips.log('Attempting to build from source via node-gyp but this may fail due to the above error'); libvips.log('Please see https://sharp.pixelplumbing.com/install for required dependencies'); process.exit(1); }; diff --git a/package.json b/package.json index 3c6e618b..363e95a9 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "Michael Nutt " ], "scripts": { - "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)", + "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)", "clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*", "test": "npm run test-lint && npm run test-unit && npm run test-licensing", "test-lint": "semistandard && cpplint",