1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | try {
|
7 | const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
|
8 |
|
9 | const buildFromSource = (msg) => {
|
10 | log(msg);
|
11 | log('Attempting to build from source via node-gyp');
|
12 | try {
|
13 | const addonApi = require('node-addon-api');
|
14 | log(`Found node-addon-api ${addonApi.version || ''}`);
|
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 ${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 | };
|
32 |
|
33 | if (useGlobalLibvips(log)) {
|
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}`);
|
41 | }
|