Skip to content

Commit f28e79e

Browse files
committed
Improve resilience of installation check
1 parent 5cd787b commit f28e79e

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

install/check.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,39 @@
33

44
'use strict';
55

6-
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
6+
try {
7+
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
78

8-
const buildFromSource = (msg) => {
9-
log(msg);
10-
log('Attempting to build from source via node-gyp');
11-
try {
12-
require('node-addon-api');
13-
log('Found node-addon-api');
14-
} catch (err) {
15-
log('Please add node-addon-api to your dependencies');
16-
return;
17-
}
18-
try {
19-
const gyp = require('node-gyp');
20-
log(`Found node-gyp version ${gyp().version}`);
21-
} catch (err) {
22-
log('Please add node-gyp to your dependencies');
23-
return;
24-
}
25-
log('See https://sharp.pixelplumbing.com/install#building-from-source');
26-
const status = spawnRebuild();
27-
if (status !== 0) {
28-
process.exit(status);
29-
}
30-
};
9+
const buildFromSource = (msg) => {
10+
log(msg);
11+
log('Attempting to build from source via node-gyp');
12+
try {
13+
require('node-addon-api');
14+
log('Found node-addon-api');
15+
} catch (err) {
16+
log('Please add node-addon-api to your dependencies');
17+
return;
18+
}
19+
try {
20+
const gyp = require('node-gyp');
21+
log(`Found node-gyp version ${gyp().version}`);
22+
} catch (err) {
23+
log('Please add node-gyp to your dependencies');
24+
return;
25+
}
26+
log('See https://sharp.pixelplumbing.com/install#building-from-source');
27+
const status = spawnRebuild();
28+
if (status !== 0) {
29+
process.exit(status);
30+
}
31+
};
3132

32-
if (useGlobalLibvips()) {
33-
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
34-
} else if (process.env.npm_config_build_from_source) {
35-
buildFromSource('Detected --build-from-source flag');
33+
if (useGlobalLibvips()) {
34+
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
35+
} else if (process.env.npm_config_build_from_source) {
36+
buildFromSource('Detected --build-from-source flag');
37+
}
38+
} catch (err) {
39+
const summary = err.message.split(/\n/).slice(0, 1);
40+
console.log(`sharp: skipping install check: ${summary}`);
3641
}

0 commit comments

Comments
 (0)