mirror of
https://github.com/lovell/sharp.git
synced 2025-07-13 20:30:14 +02:00
Improve/increase installation error handling
This commit is contained in:
parent
c3274e480b
commit
6007e13a22
@ -18,6 +18,12 @@ const platform = require('../lib/platform');
|
|||||||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||||
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
||||||
|
|
||||||
|
const fail = function (err) {
|
||||||
|
npmLog.error('sharp', err.message);
|
||||||
|
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install');
|
||||||
|
process.exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
const extractTarball = function (tarPath) {
|
const extractTarball = function (tarPath) {
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
const vendorPath = path.join(__dirname, '..', 'vendor');
|
||||||
libvips.mkdirSync(vendorPath);
|
libvips.mkdirSync(vendorPath);
|
||||||
@ -27,9 +33,7 @@ const extractTarball = function (tarPath) {
|
|||||||
cwd: vendorPath,
|
cwd: vendorPath,
|
||||||
strict: true
|
strict: true
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(fail);
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -77,21 +81,21 @@ try {
|
|||||||
}
|
}
|
||||||
response.pipe(tmpFile);
|
response.pipe(tmpFile);
|
||||||
});
|
});
|
||||||
tmpFile.on('close', function () {
|
tmpFile
|
||||||
try {
|
.on('error', fail)
|
||||||
// Attempt to rename
|
.on('close', function () {
|
||||||
fs.renameSync(tarPathTemp, tarPathCache);
|
try {
|
||||||
} catch (err) {
|
// Attempt to rename
|
||||||
// Fall back to copy and unlink
|
fs.renameSync(tarPathTemp, tarPathCache);
|
||||||
copyFileSync(tarPathTemp, tarPathCache);
|
} catch (err) {
|
||||||
fs.unlinkSync(tarPathTemp);
|
// Fall back to copy and unlink
|
||||||
}
|
copyFileSync(tarPathTemp, tarPathCache);
|
||||||
extractTarball(tarPathCache);
|
fs.unlinkSync(tarPathTemp);
|
||||||
});
|
}
|
||||||
|
extractTarball(tarPathCache);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
npmLog.error('sharp', err.message);
|
fail(err);
|
||||||
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user