From ef688f9405817d97adda73d193962783e784d768 Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Mon, 18 Apr 2022 22:08:45 +0530 Subject: [PATCH 1/6] support for using locally downloaded libvips --- install/libvips.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/install/libvips.js b/install/libvips.js index 62176eb67..10b8b28be 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_binary_dir || ''; 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,15 @@ try { if (fs.existsSync(tarPathCache)) { libvips.log(`Using cached ${tarPathCache}`); extractTarball(tarPathCache, platformAndArch); + } else if (localLibvipsDir) { + const tarPathLocal = path.join(path.resolve(localLibvipsDir), `v${minimumLibvipsVersionLabelled}`, tarFilename); + // If localLibvipsDir is given try to use binaries from local directory + if (fs.existsSync(tarPathLocal)) { + console.log(`Using local libvips from ${tarPathLocal}`); + extractTarball(tarPathLocal, platformAndArch); + } else { + fail(new Error(`Unable to use local libvips from ${tarPathLocal}`)); + } } else { const url = distBaseUrl + tarFilename; libvips.log(`Downloading ${url}`); From c672889f6f79f9d157927a33d46e50d870678422 Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Mon, 18 Apr 2022 22:18:17 +0530 Subject: [PATCH 2/6] update README --- docs/install.md | 8 ++++++++ install/libvips.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/install.md b/docs/install.md index 71dbd0ca6..d6493d1d3 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_local_libvips_dir` npm config option +or the `npm_config_sharp_local_libvips_dir` 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 10b8b28be..a55aba308 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -35,7 +35,7 @@ const hasSharpPrebuild = [ ]; const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips; -const localLibvipsDir = process.env.npm_config_sharp_libvips_binary_dir || ''; +const localLibvipsDir = process.env.npm_config_sharp_local_libvips_dir || ''; 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); From 4590493ddc344778cef6df755ca1f26a75262746 Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Mon, 18 Apr 2022 22:34:40 +0530 Subject: [PATCH 3/6] Added to contributors list --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index bc52a64e9..2ed8f297d 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,8 @@ "Joris Dugué ", "Chris Banks ", "Ompal Singh ", - "Brodan (https://ankurparihar.github.io)" ], "scripts": { "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)", From 697ea2273c920925cb92b113c8b9d91695d31df9 Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Fri, 22 Apr 2022 20:36:00 +0530 Subject: [PATCH 4/6] removed url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ed8f297d..cc845d03e 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "Chris Banks ", "Ompal Singh ", "Brodan (https://ankurparihar.github.io)" + "Ankur Parihar " ], "scripts": { "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)", From 37de0d831bc7c80d64f8bd58defaa033d7ddce1f Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Fri, 22 Apr 2022 20:37:38 +0530 Subject: [PATCH 5/6] renamed env var for local prebuild libvips --- docs/install.md | 4 ++-- install/libvips.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/install.md b/docs/install.md index d6493d1d3..0ad959118 100644 --- a/docs/install.md +++ b/docs/install.md @@ -135,8 +135,8 @@ 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_local_libvips_dir` npm config option -or the `npm_config_sharp_local_libvips_dir` environment variable. +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` diff --git a/install/libvips.js b/install/libvips.js index a55aba308..c5e5391bf 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -35,7 +35,7 @@ const hasSharpPrebuild = [ ]; const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips; -const localLibvipsDir = process.env.npm_config_sharp_local_libvips_dir || ''; +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); From e65c487d25a9354f632060e60f29819751eb9abd Mon Sep 17 00:00:00 2001 From: Ankur Parihar Date: Fri, 22 Apr 2022 20:46:10 +0530 Subject: [PATCH 6/6] removed file exist check --- install/libvips.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/install/libvips.js b/install/libvips.js index c5e5391bf..a3ef084f6 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -158,14 +158,10 @@ try { libvips.log(`Using cached ${tarPathCache}`); extractTarball(tarPathCache, platformAndArch); } else if (localLibvipsDir) { - const tarPathLocal = path.join(path.resolve(localLibvipsDir), `v${minimumLibvipsVersionLabelled}`, tarFilename); // If localLibvipsDir is given try to use binaries from local directory - if (fs.existsSync(tarPathLocal)) { - console.log(`Using local libvips from ${tarPathLocal}`); - extractTarball(tarPathLocal, platformAndArch); - } else { - fail(new Error(`Unable to use local libvips from ${tarPathLocal}`)); - } + 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}`);