Verify platform of vendor binaries at install and run time

This commit is contained in:
Lovell Fuller
2017-09-26 19:06:40 +01:00
parent 57946ed672
commit 7b6c80327e
4 changed files with 131 additions and 67 deletions

View File

@@ -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
View 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('-');
};