From 66a3ce5e550c1b2299989f269dfd828cf43a43ce Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Sun, 24 Apr 2022 23:17:57 +0530 Subject: [PATCH] Allow installation of prebuilt libvips binary from filesystem (#3196) --- docs/install.md | 8 ++++++++ install/libvips.js | 6 ++++++ package.json | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/install.md b/docs/install.md index 71dbd0ca..0ad95911 100644 --- a/docs/install.md +++ b/docs/install.md @@ -118,6 +118,8 @@ Building from source requires: This is an advanced approach that most people will not require. +### Prebuilt sharp binaries + To install the prebuilt sharp binaries from a custom URL, set the `sharp_binary_host` npm config option or the `npm_config_sharp_binary_host` environment variable. @@ -126,10 +128,16 @@ To install the prebuilt sharp binaries from a directory on the local filesystem, set the `sharp_local_prebuilds` npm config option or the `npm_config_sharp_local_prebuilds` environment variable. +### Prebuilt libvips binaries + To install the prebuilt libvips binaries from a custom URL, set the `sharp_libvips_binary_host` npm config option or the `npm_config_sharp_libvips_binary_host` environment variable. +To install the prebuilt libvips binaries from a directory on the local filesystem, +set the `sharp_libvips_local_prebuilds` npm config option +or the `npm_config_sharp_libvips_local_prebuilds` environment variable. + The version subpath and file name are appended to these. For example, if `sharp_libvips_binary_host` is set to `https://hostname/path` and the libvips version is `1.2.3` then the resultant URL will be diff --git a/install/libvips.js b/install/libvips.js index 62176eb6..a3ef084f 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -35,6 +35,7 @@ const hasSharpPrebuild = [ ]; const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips; +const localLibvipsDir = process.env.npm_config_sharp_libvips_local_prebuilds || ''; 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 installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE); @@ -156,6 +157,11 @@ try { if (fs.existsSync(tarPathCache)) { libvips.log(`Using cached ${tarPathCache}`); extractTarball(tarPathCache, platformAndArch); + } else if (localLibvipsDir) { + // If localLibvipsDir is given try to use binaries from local directory + const tarPathLocal = path.join(path.resolve(localLibvipsDir), `v${minimumLibvipsVersionLabelled}`, tarFilename); + libvips.log(`Using local libvips from ${tarPathLocal}`); + extractTarball(tarPathLocal, platformAndArch); } else { const url = distBaseUrl + tarFilename; libvips.log(`Downloading ${url}`); diff --git a/package.json b/package.json index bc52a64e..cc845d03 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,8 @@ "Joris Dugué ", "Chris Banks ", "Ompal Singh ", - "Brodan " ], "scripts": { "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)",