From 1592f96b7b475d49b5f8b9c3b1aedc3a1e55c5a0 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 10 Dec 2023 19:38:03 +0000 Subject: [PATCH] Add support for Yarn Plug'n'Play filesystem layout #3888 --- docs/changelog.md | 5 +++++ docs/install.md | 2 -- lib/libvips.js | 12 +++++++++++- src/binding.gyp | 7 +++++-- test/unit/libvips.js | 6 ++++++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 5962dd2f..352336b7 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ Requires libvips v8.15.0 +### v0.33.1 - TBD + +* Add support for Yarn Plug'n'Play filesystem layout. + [#3888](https://github.com/lovell/sharp/issues/3888) + ### v0.33.0 - 29th November 2023 * Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0 diff --git a/docs/install.md b/docs/install.md index bf13f5c1..1350ace6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -13,8 +13,6 @@ pnpm add sharp ``` ```sh -# yarn v3+ (Plug'n'Play is unsupported) -yarn config set nodeLinker node-modules yarn add sharp ``` diff --git a/lib/libvips.js b/lib/libvips.js index 9d0f09d0..fbf831fe 100644 --- a/lib/libvips.js +++ b/lib/libvips.js @@ -4,11 +4,12 @@ 'use strict'; const { spawnSync } = require('node:child_process'); +const { createHash } = require('node:crypto'); const semverCoerce = require('semver/functions/coerce'); const semverGreaterThanOrEqualTo = require('semver/functions/gte'); const detectLibc = require('detect-libc'); -const { engines } = require('../package.json'); +const { engines, optionalDependencies } = require('../package.json'); const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || /* istanbul ignore next */ engines.libvips; @@ -97,6 +98,14 @@ const isRosetta = () => { return false; }; +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); +}; + /* istanbul ignore next */ const spawnRebuild = () => spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, { @@ -164,6 +173,7 @@ module.exports = { buildSharpLibvipsLibDir, runtimePlatformArch, log, + yarnLocator, spawnRebuild, globalLibvipsVersion, pkgConfigPath, diff --git a/src/binding.gyp b/src/binding.gyp index dedb2b2d..f1fc6091 100644 --- a/src/binding.gyp +++ b/src/binding.gyp @@ -6,6 +6,7 @@ 'vips_version': ' { + const locatorHash = libvips.yarnLocator(); + assert.strictEqual(locatorHash.length, 10); + assert.strict(/[a-f0-9]{10}/.test(locatorHash)); + }); });