mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Add runtime check for outdated Node.js version
This commit is contained in:
parent
b96389d975
commit
45e8071599
@ -7,6 +7,7 @@ const { spawnSync } = require('node:child_process');
|
|||||||
const { createHash } = require('node:crypto');
|
const { createHash } = require('node:crypto');
|
||||||
const semverCoerce = require('semver/functions/coerce');
|
const semverCoerce = require('semver/functions/coerce');
|
||||||
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
||||||
|
const semverSatisfies = require('semver/functions/satisfies');
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
|
|
||||||
const { engines, optionalDependencies } = require('../package.json');
|
const { engines, optionalDependencies } = require('../package.json');
|
||||||
@ -83,6 +84,15 @@ const buildSharpLibvipsLibDir = () => {
|
|||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isUnsupportedNodeRuntime = () => {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (process.release?.name === 'node' && process.versions) {
|
||||||
|
if (!semverSatisfies(process.versions.node, engines.node)) {
|
||||||
|
return { found: process.versions.node, expected: engines.node };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const isEmscripten = () => {
|
const isEmscripten = () => {
|
||||||
const { CC } = process.env;
|
const { CC } = process.env;
|
||||||
@ -174,6 +184,7 @@ module.exports = {
|
|||||||
buildSharpLibvipsIncludeDir,
|
buildSharpLibvipsIncludeDir,
|
||||||
buildSharpLibvipsCPlusPlusDir,
|
buildSharpLibvipsCPlusPlusDir,
|
||||||
buildSharpLibvipsLibDir,
|
buildSharpLibvipsLibDir,
|
||||||
|
isUnsupportedNodeRuntime,
|
||||||
runtimePlatformArch,
|
runtimePlatformArch,
|
||||||
log,
|
log,
|
||||||
yarnLocator,
|
yarnLocator,
|
||||||
|
11
lib/sharp.js
11
lib/sharp.js
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
const { familySync, versionSync } = require('detect-libc');
|
const { familySync, versionSync } = require('detect-libc');
|
||||||
|
|
||||||
const { runtimePlatformArch, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
||||||
const runtimePlatform = runtimePlatformArch();
|
const runtimePlatform = runtimePlatformArch();
|
||||||
|
|
||||||
const paths = [
|
const paths = [
|
||||||
@ -44,7 +44,14 @@ if (sharp) {
|
|||||||
const messages = errors.map(err => err.message).join(' ');
|
const messages = errors.map(err => err.message).join(' ');
|
||||||
help.push('Possible solutions:');
|
help.push('Possible solutions:');
|
||||||
// Common error messages
|
// Common error messages
|
||||||
if (prebuiltPlatforms.includes(runtimePlatform)) {
|
if (isUnsupportedNodeRuntime()) {
|
||||||
|
const { found, expected } = isUnsupportedNodeRuntime();
|
||||||
|
help.push(
|
||||||
|
'- Please upgrade Node.js:',
|
||||||
|
` Found ${found}`,
|
||||||
|
` Requires ${expected}`
|
||||||
|
);
|
||||||
|
} else if (prebuiltPlatforms.includes(runtimePlatform)) {
|
||||||
const [os, cpu] = runtimePlatform.split('-');
|
const [os, cpu] = runtimePlatform.split('-');
|
||||||
const libc = os.endsWith('musl') ? ' --libc=musl' : '';
|
const libc = os.endsWith('musl') ? ' --libc=musl' : '';
|
||||||
help.push(
|
help.push(
|
||||||
|
@ -123,6 +123,9 @@ describe('libvips binaries', function () {
|
|||||||
const [, arch] = libvips.runtimePlatformArch().split('-');
|
const [, arch] = libvips.runtimePlatformArch().split('-');
|
||||||
assert.strict(['arm', 'arm64', 'ia32', 'x64'].includes(arch));
|
assert.strict(['arm', 'arm64', 'ia32', 'x64'].includes(arch));
|
||||||
});
|
});
|
||||||
|
it('isUnsupportedNodeRuntime', () => {
|
||||||
|
assert.strictEqual(libvips.isUnsupportedNodeRuntime(), undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('logger', function () {
|
describe('logger', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user