mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Verify platform of vendor binaries at install and run time
This commit is contained in:
@@ -6,8 +6,24 @@ const stream = require('stream');
|
||||
const events = require('events');
|
||||
const semver = require('semver');
|
||||
const is = require('./is');
|
||||
const platform = require('./platform');
|
||||
const sharp = require('../build/Release/sharp.node');
|
||||
|
||||
// Vendor platform
|
||||
(function () {
|
||||
let vendorPlatformId;
|
||||
try {
|
||||
vendorPlatformId = require('../vendor/platform.json');
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
const currentPlatformId = platform();
|
||||
/* istanbul ignore if */
|
||||
if (currentPlatformId !== vendorPlatformId) {
|
||||
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm rebuild'.`);
|
||||
}
|
||||
})();
|
||||
|
||||
// Versioning
|
||||
let versions = {
|
||||
vips: sharp.libvipsVersion()
|
||||
@@ -21,7 +37,7 @@ let versions = {
|
||||
}
|
||||
// Include versions of dependencies, if present
|
||||
try {
|
||||
versions = require('../vendor/lib/versions.json');
|
||||
versions = require('../vendor/versions.json');
|
||||
} catch (err) {}
|
||||
})();
|
||||
|
||||
|
||||
15
lib/platform.js
Normal file
15
lib/platform.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function () {
|
||||
const arch = process.env.npm_config_arch || process.arch;
|
||||
const platform = process.env.npm_config_platform || process.platform;
|
||||
|
||||
const platformId = [platform];
|
||||
if (arch === 'arm' || arch === 'armhf' || arch === 'arm64') {
|
||||
const armVersion = (arch === 'arm64') ? '8' : process.env.npm_config_armv || process.config.variables.arm_version || '6';
|
||||
platformId.push(`armv${armVersion}`);
|
||||
} else {
|
||||
platformId.push(arch);
|
||||
}
|
||||
return platformId.join('-');
|
||||
};
|
||||
Reference in New Issue
Block a user