From 02f855d57a4cc4e217790725653b1a5dd3ccbbd6 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 17 Jan 2023 09:56:58 +0000 Subject: [PATCH] Expose own version as sharp.versions.sharp #3471 --- docs/api-utility.md | 2 +- docs/changelog.md | 3 +++ lib/utility.js | 3 ++- test/unit/util.js | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/api-utility.md b/docs/api-utility.md index 365a3057..7e27c8e7 100644 --- a/docs/api-utility.md +++ b/docs/api-utility.md @@ -1,5 +1,5 @@ ## versions -An Object containing the version numbers of libvips and its dependencies. +An Object containing the version numbers of sharp, libvips and its dependencies. **Example** diff --git a/docs/changelog.md b/docs/changelog.md index 68b6e986..b30ac106 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -32,6 +32,9 @@ Requires libvips v8.14.0 [#3470](https://github.com/lovell/sharp/pull/3470) [@ejoebstl](https://github.com/ejoebstl) +* Expose sharp version as `sharp.versions.sharp`. + [#3471](https://github.com/lovell/sharp/issues/3471) + * Respect `fastShrinkOnLoad` resize option for WebP input. [#3516](https://github.com/lovell/sharp/issues/3516) diff --git a/lib/utility.js b/lib/utility.js index 782f30ba..c35145f9 100644 --- a/lib/utility.js +++ b/lib/utility.js @@ -43,7 +43,7 @@ const interpolators = { }; /** - * An Object containing the version numbers of libvips and its dependencies. + * An Object containing the version numbers of sharp, libvips and its dependencies. * @member * @example * console.log(sharp.versions); @@ -54,6 +54,7 @@ let versions = { try { versions = require(`../vendor/${versions.vips}/${platformAndArch}/versions.json`); } catch (_err) { /* ignore */ } +versions.sharp = require('../package.json').version; /** * An Object containing the platform and architecture diff --git a/test/unit/util.js b/test/unit/util.js index f9dda22c..035e357b 100644 --- a/test/unit/util.js +++ b/test/unit/util.js @@ -1,6 +1,7 @@ 'use strict'; const assert = require('assert'); +const semver = require('semver'); const sharp = require('../../'); describe('Utilities', function () { @@ -137,7 +138,8 @@ describe('Utilities', function () { describe('Versions', function () { it('Contains expected attributes', function () { assert.strictEqual('object', typeof sharp.versions); - assert.strictEqual('string', typeof sharp.versions.vips); + assert(semver.valid(sharp.versions.vips)); + assert(semver.valid(sharp.versions.sharp)); }); });