From 476448b9d4b3e29afe7ae6cd3418cb561055e563 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 10 May 2021 10:55:20 +0200 Subject: [PATCH] Install: allow cross-libc via sharp-install-force flag (#2692) --- docs/install.md | 2 ++ install/libvips.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/install.md b/docs/install.md index cdb4de80..aa39fa0b 100644 --- a/docs/install.md +++ b/docs/install.md @@ -54,6 +54,8 @@ When using npm v6 or earlier, the `npm install --unsafe-perm` flag must be used When using npm v7, the user running `npm install` must own the directory it is run in. +When installing cross platform prebuilts on linux hosts an installation can be forced by `--sharp-install-force` flag or by setting `SHARP_INSTALL_FORCE` env variable. + The `npm install --ignore-scripts=false` flag must be used when `npm` has been configured to ignore installation scripts. Check the output of running `npm install --verbose sharp` for useful error messages. diff --git a/install/libvips.js b/install/libvips.js index a2d1b5e5..78d8b6ff 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -36,6 +36,7 @@ const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips; const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download'; const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`; const supportsBrotli = ('BrotliDecompress' in zlib); +const installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE); const fail = function (err) { libvips.log(err); @@ -47,6 +48,14 @@ const fail = function (err) { process.exit(1); }; +const handleError = function (err) { + if (installationForced) { + console.warn(`${err.message}. Continue due forced installation`); + } else { + throw err; + } +}; + const extractTarball = function (tarPath, platformAndArch) { const vendorPath = path.join(__dirname, '..', 'vendor'); libvips.mkdirSync(vendorPath); @@ -98,18 +107,18 @@ try { } if (detectLibc.family === detectLibc.GLIBC && detectLibc.version) { if (semverLessThan(`${detectLibc.version}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { - throw new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`); + handleError(new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); } } if (detectLibc.family === detectLibc.MUSL && detectLibc.version) { if (semverLessThan(detectLibc.version, '1.1.24')) { - throw new Error(`Use with musl ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`); + handleError(new Error(`Use with musl ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); } } const supportedNodeVersion = process.env.npm_package_engines_node || require('../package.json').engines.node; if (!semverSatisfies(process.versions.node, supportedNodeVersion)) { - throw new Error(`Expected Node.js version ${supportedNodeVersion} but found ${process.versions.node}`); + handleError(new Error(`Expected Node.js version ${supportedNodeVersion} but found ${process.versions.node}`)); } const extension = supportsBrotli ? 'br' : 'gz';