Skip to content

Commit

Permalink
Expose platform-arch of vendored binaries #2928
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Dec 12, 2021
1 parent 9755629 commit 3da258f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/api-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ An Object containing the version numbers of libvips and its dependencies.
console.log(sharp.versions);
```

## vendor

An Object containing information about the platform and architecture
of the current and installed vendored binaries.

### Examples

```javascript
console.log(sharp.vendor);
```

## cache

Gets or, when options are provided, sets the limits of *libvips'* operation cache.
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Requires libvips v8.12.1
[#2789](https://github.com/lovell/sharp/pull/2789)
[@kleisauke](https://github.com/kleisauke)

* Expose platform and architecture of vendored binaries as `sharp.vendor`.
[#2928](https://github.com/lovell/sharp/issues/2928)

* Ensure 16-bit PNG output uses correct bitdepth.
[#2958](https://github.com/lovell/sharp/pull/2958)
[@gforge](https://github.com/gforge)
Expand Down
2 changes: 1 addition & 1 deletion docs/search-index.json

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion lib/utility.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const fs = require('fs');
const path = require('path');
const events = require('events');
const detectLibc = require('detect-libc');

Expand Down Expand Up @@ -47,7 +49,22 @@ let versions = {
};
try {
versions = require(`../vendor/${versions.vips}/${platformAndArch}/versions.json`);
} catch (err) {}
} catch (_err) { /* ignore */ }

/**
* An Object containing the platform and architecture
* of the current and installed vendored binaries.
* @member
* @example
* console.log(sharp.vendor);
*/
const vendor = {
current: platformAndArch,
installed: []
};
try {
vendor.installed = fs.readdirSync(path.join(__dirname, `../vendor/${versions.vips}`));
} catch (_err) { /* ignore */ }

/**
* Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
Expand Down Expand Up @@ -176,5 +193,6 @@ module.exports = function (Sharp) {
Sharp.format = format;
Sharp.interpolators = interpolators;
Sharp.versions = versions;
Sharp.vendor = vendor;
Sharp.queue = queue;
};
9 changes: 9 additions & 0 deletions test/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,13 @@ describe('Utilities', function () {
assert.strictEqual('string', typeof sharp.versions.vips);
});
});

describe('Vendor', function () {
it('Contains expected attributes', function () {
assert.strictEqual('object', typeof sharp.vendor);
assert.strictEqual('string', typeof sharp.vendor.current);
assert.strictEqual(true, Array.isArray(sharp.vendor.installed));
assert.strictEqual(true, sharp.vendor.installed.length > 0);
});
});
});

0 comments on commit 3da258f

Please sign in to comment.