From 51e56f994ce1332f77daf625e23820a895de074d Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sat, 7 Oct 2023 11:09:45 +0100 Subject: [PATCH] Package managers cannot handle nested optionalDependencies --- lib/sharp.js | 18 ++++++++++++------ npm/darwin-arm64/package.json | 3 --- npm/darwin-x64/package.json | 3 --- npm/linux-arm/package.json | 3 --- npm/linux-arm64/package.json | 3 --- npm/linux-x64/package.json | 3 --- npm/linuxmusl-arm64/package.json | 3 --- npm/linuxmusl-x64/package.json | 3 --- 8 files changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/sharp.js b/lib/sharp.js index 26951535..bc363a95 100644 --- a/lib/sharp.js +++ b/lib/sharp.js @@ -9,6 +9,7 @@ const { familySync, versionSync } = require('detect-libc'); const { runtimePlatformArch, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips'); const runtimePlatform = runtimePlatformArch(); +const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os)); /* istanbul ignore next */ try { @@ -29,11 +30,15 @@ try { help.push('Possible solutions:'); // Common error messages if (prebuiltPlatforms.includes(runtimePlatform)) { - help.push(`- Add an explicit dependency for the runtime platform: "npm install --force @sharpen/sharp-${runtimePlatform}"`); + help.push('- Add explicit dependencies for the runtime platform:'); + help.push(` npm install --force @sharpen/sharp-${runtimePlatform}`); + if (!isWindows) { + help.push(` npm install --force @sharpen/sharp-libvips-${runtimePlatform}`); + } } else { help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`); } - if (runtimePlatform.startsWith('linux') && /symbol not found/i.test(errPackage)) { + if (isLinux && /symbol not found/i.test(errPackage)) { try { const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`); const libcFound = `${familySync()} ${versionSync()}`; @@ -41,16 +46,17 @@ try { help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`); } catch (errEngines) {} } - if (runtimePlatform.startsWith('darwin') && /Incompatible library version/.test(errLocal.message)) { - help.push('- Update Homebrew: "brew update && brew upgrade vips"'); + if (isMacOs && /Incompatible library version/.test(errLocal.message)) { + help.push('- Update Homebrew:'); + help.push(' brew update && brew upgrade vips'); } if (errPackage.code === 'ERR_DLOPEN_DISABLED') { help.push('- Run Node.js without using the --no-addons flag'); } // Link to installation docs - if (runtimePlatform.startsWith('linux') && /Module did not self-register/.test(errLocal.message + errPackage.message)) { + if (isLinux && /Module did not self-register/.test(errLocal.message + errPackage.message)) { help.push('- Using worker threads on Linux? See https://sharp.pixelplumbing.com/install#worker-threads'); - } else if (runtimePlatform.startsWith('win32') && /The specified procedure could not be found/.test(errPackage.message)) { + } else if (isWindows && /The specified procedure could not be found/.test(errPackage.message)) { help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows'); } else { help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install'); diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index eeb89de6..e2769a96 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.1" - }, "files": [ "lib" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index 2bf24680..11db4e98 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.1" - }, "files": [ "lib" ], diff --git a/npm/linux-arm/package.json b/npm/linux-arm/package.json index 9bb7613a..2e1b2145 100644 --- a/npm/linux-arm/package.json +++ b/npm/linux-arm/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.1" - }, "files": [ "lib" ], diff --git a/npm/linux-arm64/package.json b/npm/linux-arm64/package.json index 68abcc92..ea46e05e 100644 --- a/npm/linux-arm64/package.json +++ b/npm/linux-arm64/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.1" - }, "files": [ "lib" ], diff --git a/npm/linux-x64/package.json b/npm/linux-x64/package.json index f27bcefb..ab1225e6 100644 --- a/npm/linux-x64/package.json +++ b/npm/linux-x64/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.1" - }, "files": [ "lib" ], diff --git a/npm/linuxmusl-arm64/package.json b/npm/linuxmusl-arm64/package.json index 6eecb5d0..eceec78d 100644 --- a/npm/linuxmusl-arm64/package.json +++ b/npm/linuxmusl-arm64/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.1" - }, "files": [ "lib" ], diff --git a/npm/linuxmusl-x64/package.json b/npm/linuxmusl-x64/package.json index 2e1e8a99..b8909d08 100644 --- a/npm/linuxmusl-x64/package.json +++ b/npm/linuxmusl-x64/package.json @@ -13,9 +13,6 @@ "url": "https://opencollective.com/libvips" }, "preferUnplugged": true, - "optionalDependencies": { - "@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.1" - }, "files": [ "lib" ],