From a584ae093e1198d9d7171ec924218f5aafcb2ff5 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 10 Dec 2023 19:51:21 +0000 Subject: [PATCH] Allow yarn locator hash calc to fail e.g. Windows --- lib/libvips.js | 10 +++++++--- test/unit/libvips.js | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/libvips.js b/lib/libvips.js index fbf831fe..6376e217 100644 --- a/lib/libvips.js +++ b/lib/libvips.js @@ -101,9 +101,13 @@ const isRosetta = () => { const sha512 = (s) => createHash('sha512').update(s).digest('hex'); const yarnLocator = () => { - const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`); - const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version; - return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10); + try { + const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`); + const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version; + return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10); + } catch {} + /* istanbul ignore next */ + return ''; }; /* istanbul ignore next */ diff --git a/test/unit/libvips.js b/test/unit/libvips.js index 36a21fa3..d18af852 100644 --- a/test/unit/libvips.js +++ b/test/unit/libvips.js @@ -147,7 +147,9 @@ describe('libvips binaries', function () { it('yarn locator hash', () => { const locatorHash = libvips.yarnLocator(); - assert.strictEqual(locatorHash.length, 10); - assert.strict(/[a-f0-9]{10}/.test(locatorHash)); + if (locatorHash.length) { + assert.strict(locatorHash.length, 10); + assert.strict(/[a-f0-9]{10}/.test(locatorHash)); + } }); });