Skip to content

Commit 66a3ce5

Browse files
authoredApr 24, 2022
Allow installation of prebuilt libvips binary from filesystem (#3196)
1 parent 75e5afc commit 66a3ce5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
 

‎docs/install.md

+8
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Building from source requires:
118118

119119
This is an advanced approach that most people will not require.
120120

121+
### Prebuilt sharp binaries
122+
121123
To install the prebuilt sharp binaries from a custom URL,
122124
set the `sharp_binary_host` npm config option
123125
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,
126128
set the `sharp_local_prebuilds` npm config option
127129
or the `npm_config_sharp_local_prebuilds` environment variable.
128130

131+
### Prebuilt libvips binaries
132+
129133
To install the prebuilt libvips binaries from a custom URL,
130134
set the `sharp_libvips_binary_host` npm config option
131135
or the `npm_config_sharp_libvips_binary_host` environment variable.
132136

137+
To install the prebuilt libvips binaries from a directory on the local filesystem,
138+
set the `sharp_libvips_local_prebuilds` npm config option
139+
or the `npm_config_sharp_libvips_local_prebuilds` environment variable.
140+
133141
The version subpath and file name are appended to these.
134142
For example, if `sharp_libvips_binary_host` is set to `https://hostname/path`
135143
and the libvips version is `1.2.3` then the resultant URL will be

‎install/libvips.js

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const hasSharpPrebuild = [
3535
];
3636

3737
const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
38+
const localLibvipsDir = process.env.npm_config_sharp_libvips_local_prebuilds || '';
3839
const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download';
3940
const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`;
4041
const installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE);
@@ -156,6 +157,11 @@ try {
156157
if (fs.existsSync(tarPathCache)) {
157158
libvips.log(`Using cached ${tarPathCache}`);
158159
extractTarball(tarPathCache, platformAndArch);
160+
} else if (localLibvipsDir) {
161+
// If localLibvipsDir is given try to use binaries from local directory
162+
const tarPathLocal = path.join(path.resolve(localLibvipsDir), `v${minimumLibvipsVersionLabelled}`, tarFilename);
163+
libvips.log(`Using local libvips from ${tarPathLocal}`);
164+
extractTarball(tarPathLocal, platformAndArch);
159165
} else {
160166
const url = distBaseUrl + tarFilename;
161167
libvips.log(`Downloading ${url}`);

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"Joris Dugué <zaruike10@gmail.com>",
8383
"Chris Banks <christopher.bradley.banks@gmail.com>",
8484
"Ompal Singh <ompal.hitm09@gmail.com>",
85-
"Brodan <christopher.hranj@gmail.com"
85+
"Brodan <christopher.hranj@gmail.com",
86+
"Ankur Parihar <ankur.github@gmail.com>"
8687
],
8788
"scripts": {
8889
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)",

0 commit comments

Comments
 (0)
Please sign in to comment.