Prevent use of linux-x64 binaries with v1 microarchitecture

This commit is contained in:
Lovell Fuller
2025-03-19 17:24:46 +00:00
parent d419aba76d
commit 3fd818c4b5
5 changed files with 31 additions and 2 deletions

View File

@@ -17,9 +17,9 @@ const paths = [
'@img/sharp-wasm32/sharp.node'
];
let sharp;
let path, sharp;
const errors = [];
for (const path of paths) {
for (path of paths) {
try {
sharp = require(path);
break;
@@ -29,6 +29,14 @@ for (const path of paths) {
}
}
/* istanbul ignore next */
if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) {
const err = new Error('Prebuilt binaries for linux-x64 require v2 microarchitecture');
err.code = 'Unsupported CPU';
errors.push(err);
sharp = null;
}
/* istanbul ignore next */
if (sharp) {
module.exports = sharp;