Allow yarn locator hash calc to fail e.g. Windows

This commit is contained in:
Lovell Fuller 2023-12-10 19:51:21 +00:00
parent 1592f96b7b
commit a584ae093e
2 changed files with 11 additions and 5 deletions

View File

@ -101,9 +101,13 @@ const isRosetta = () => {
const sha512 = (s) => createHash('sha512').update(s).digest('hex'); const sha512 = (s) => createHash('sha512').update(s).digest('hex');
const yarnLocator = () => { const yarnLocator = () => {
const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`); try {
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version; const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10); 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 */ /* istanbul ignore next */

View File

@ -147,7 +147,9 @@ describe('libvips binaries', function () {
it('yarn locator hash', () => { it('yarn locator hash', () => {
const locatorHash = libvips.yarnLocator(); const locatorHash = libvips.yarnLocator();
assert.strictEqual(locatorHash.length, 10); if (locatorHash.length) {
assert.strict(/[a-f0-9]{10}/.test(locatorHash)); assert.strict(locatorHash.length, 10);
assert.strict(/[a-f0-9]{10}/.test(locatorHash));
}
}); });
}); });