@revizly/sharp 0.35.0-revizly28 → 0.35.0-revizly30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sharp.cjs ADDED
@@ -0,0 +1,162 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ // Inspects the runtime environment and exports the relevant sharp.node binary
7
+
8
+ const { familySync, versionSync } = require("detect-libc");
9
+
10
+ const libvips = require("./libvips.cjs");
11
+ const pkg = require('../package.json');
12
+
13
+ const { version } = pkg;
14
+
15
+ const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = libvips;
16
+ const runtimePlatform = runtimePlatformArch();
17
+
18
+ /* node:coverage disable */
19
+
20
+ let sharp;
21
+ const errors = [];
22
+ try {
23
+ sharp = require(`../src/build/Release/sharp-${runtimePlatform}-${version}.node`);
24
+ } catch (err) {
25
+ errors.push(err);
26
+ }
27
+ if (!sharp) {
28
+ try {
29
+ sharp = require(`../src/build/Release/sharp-wasm32-${version}.node`);
30
+ } catch (err) {
31
+ errors.push(err);
32
+ }
33
+ }
34
+ if (!sharp) {
35
+ try {
36
+ switch (runtimePlatform) {
37
+ case "darwin-arm64":
38
+ sharp = require("@img/sharp-darwin-arm64/sharp.node");
39
+ break;
40
+ case "darwin-x64":
41
+ sharp = require("@img/sharp-darwin-x64/sharp.node");
42
+ break;
43
+ case "linux-arm":
44
+ sharp = require("@img/sharp-linux-arm/sharp.node");
45
+ break;
46
+ case "linux-arm64":
47
+ sharp = require("@revizly/sharp-linux-arm64/sharp.node");
48
+ break;
49
+ case "linux-ppc64":
50
+ sharp = require("@img/sharp-linux-ppc64/sharp.node");
51
+ break;
52
+ case "linux-riscv64":
53
+ sharp = require("@img/sharp-linux-riscv64/sharp.node");
54
+ break;
55
+ case "linux-s390x":
56
+ sharp = require("@img/sharp-linux-s390x/sharp.node");
57
+ break;
58
+ case "linux-x64":
59
+ sharp = require("@revizly/sharp-linux-x64/sharp.node");
60
+ break;
61
+ case "linuxmusl-arm64":
62
+ sharp = require("@img/sharp-linuxmusl-arm64/sharp.node");
63
+ break;
64
+ case "linuxmusl-x64":
65
+ sharp = require("@img/sharp-linuxmusl-x64/sharp.node");
66
+ break;
67
+ case "win32-arm64":
68
+ sharp = require("@img/sharp-win32-arm64/sharp.node");
69
+ break;
70
+ case "win32-ia32":
71
+ sharp = require("@img/sharp-win32-ia32/sharp.node");
72
+ break;
73
+ case "win32-x64":
74
+ sharp = require("@img/sharp-win32-x64/sharp.node");
75
+ break;
76
+ case "freebsd-arm64":
77
+ case "freebsd-x64":
78
+ sharp = require("@img/sharp-freebsd-wasm32/sharp.node");
79
+ break;
80
+ case "linux-wasm32":
81
+ sharp = require("@img/sharp-webcontainers-wasm32/sharp.node");
82
+ break;
83
+ default:
84
+ sharp = require("@img/sharp-wasm32/sharp.node");
85
+ break;
86
+ }
87
+ if (["linux-x64", "linuxmusl-x64"].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
88
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
89
+ err.code = "Unsupported CPU";
90
+ errors.push(err);
91
+ sharp = null;
92
+ }
93
+ } catch (err) {
94
+ errors.push(err);
95
+ }
96
+ }
97
+
98
+ if (!sharp) {
99
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
100
+
101
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
102
+ errors.forEach((err) => {
103
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
104
+ help.push(`${err.code}: ${err.message}`);
105
+ }
106
+ });
107
+ const messages = errors.map((err) => err.message).join(" ");
108
+ help.push("Possible solutions:");
109
+ // Common error messages
110
+ if (isUnsupportedNodeRuntime()) {
111
+ const { found, expected } = isUnsupportedNodeRuntime();
112
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
113
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
114
+ const [os, cpu] = runtimePlatform.split("-");
115
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
116
+ help.push(
117
+ "- Ensure optional dependencies can be installed:",
118
+ " npm install --include=optional sharp",
119
+ "- Ensure your package manager supports multi-platform installation:",
120
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
121
+ "- Add platform-specific dependencies:",
122
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
123
+ );
124
+ } else {
125
+ help.push(
126
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
127
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
128
+ "- Add WebAssembly-based dependencies:",
129
+ " npm install sharp @img/sharp-wasm32",
130
+ );
131
+ }
132
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
133
+ try {
134
+ const { config } = require(`@revizly/sharp-libvips-${runtimePlatform}/package`);
135
+ const libcFound = `${familySync()} ${versionSync()}`;
136
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
137
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
138
+ } catch (_errEngines) {}
139
+ }
140
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
141
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
142
+ }
143
+ if (isMacOs && /Incompatible library version/.test(messages)) {
144
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
145
+ }
146
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
147
+ help.push("- Run Node.js without using the --no-addons flag");
148
+ }
149
+ // Link to installation docs
150
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
151
+ help.push(
152
+ "- Using the canvas package on Windows?",
153
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
154
+ "- Check for outdated versions of sharp in the dependency tree:",
155
+ " npm ls sharp",
156
+ );
157
+ }
158
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
159
+ throw new Error(help.join("\n"));
160
+ }
161
+
162
+ module.exports = sharp;
package/dist/sharp.mjs ADDED
@@ -0,0 +1,164 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ // Inspects the runtime environment and exports the relevant sharp.node binary
7
+
8
+ import { createRequire } from "node:module"
9
+ import { familySync, versionSync } from "detect-libc";
10
+
11
+ import libvips from "./libvips.mjs";
12
+ import pkg from '../package.json' with { type: 'json' };
13
+
14
+ const require = createRequire(import.meta.url);
15
+ const { version } = pkg;
16
+
17
+ const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = libvips;
18
+ const runtimePlatform = runtimePlatformArch();
19
+
20
+ /* node:coverage disable */
21
+
22
+ let sharp;
23
+ const errors = [];
24
+ try {
25
+ sharp = require(`../src/build/Release/sharp-${runtimePlatform}-${version}.node`);
26
+ } catch (err) {
27
+ errors.push(err);
28
+ }
29
+ if (!sharp) {
30
+ try {
31
+ sharp = require(`../src/build/Release/sharp-wasm32-${version}.node`);
32
+ } catch (err) {
33
+ errors.push(err);
34
+ }
35
+ }
36
+ if (!sharp) {
37
+ try {
38
+ switch (runtimePlatform) {
39
+ case "darwin-arm64":
40
+ sharp = require("@img/sharp-darwin-arm64/sharp.node");
41
+ break;
42
+ case "darwin-x64":
43
+ sharp = require("@img/sharp-darwin-x64/sharp.node");
44
+ break;
45
+ case "linux-arm":
46
+ sharp = require("@img/sharp-linux-arm/sharp.node");
47
+ break;
48
+ case "linux-arm64":
49
+ sharp = require("@revizly/sharp-linux-arm64/sharp.node");
50
+ break;
51
+ case "linux-ppc64":
52
+ sharp = require("@img/sharp-linux-ppc64/sharp.node");
53
+ break;
54
+ case "linux-riscv64":
55
+ sharp = require("@img/sharp-linux-riscv64/sharp.node");
56
+ break;
57
+ case "linux-s390x":
58
+ sharp = require("@img/sharp-linux-s390x/sharp.node");
59
+ break;
60
+ case "linux-x64":
61
+ sharp = require("@revizly/sharp-linux-x64/sharp.node");
62
+ break;
63
+ case "linuxmusl-arm64":
64
+ sharp = require("@img/sharp-linuxmusl-arm64/sharp.node");
65
+ break;
66
+ case "linuxmusl-x64":
67
+ sharp = require("@img/sharp-linuxmusl-x64/sharp.node");
68
+ break;
69
+ case "win32-arm64":
70
+ sharp = require("@img/sharp-win32-arm64/sharp.node");
71
+ break;
72
+ case "win32-ia32":
73
+ sharp = require("@img/sharp-win32-ia32/sharp.node");
74
+ break;
75
+ case "win32-x64":
76
+ sharp = require("@img/sharp-win32-x64/sharp.node");
77
+ break;
78
+ case "freebsd-arm64":
79
+ case "freebsd-x64":
80
+ sharp = require("@img/sharp-freebsd-wasm32/sharp.node");
81
+ break;
82
+ case "linux-wasm32":
83
+ sharp = require("@img/sharp-webcontainers-wasm32/sharp.node");
84
+ break;
85
+ default:
86
+ sharp = require("@img/sharp-wasm32/sharp.node");
87
+ break;
88
+ }
89
+ if (["linux-x64", "linuxmusl-x64"].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
90
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
91
+ err.code = "Unsupported CPU";
92
+ errors.push(err);
93
+ sharp = null;
94
+ }
95
+ } catch (err) {
96
+ errors.push(err);
97
+ }
98
+ }
99
+
100
+ if (!sharp) {
101
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
102
+
103
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
104
+ errors.forEach((err) => {
105
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
106
+ help.push(`${err.code}: ${err.message}`);
107
+ }
108
+ });
109
+ const messages = errors.map((err) => err.message).join(" ");
110
+ help.push("Possible solutions:");
111
+ // Common error messages
112
+ if (isUnsupportedNodeRuntime()) {
113
+ const { found, expected } = isUnsupportedNodeRuntime();
114
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
115
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
116
+ const [os, cpu] = runtimePlatform.split("-");
117
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
118
+ help.push(
119
+ "- Ensure optional dependencies can be installed:",
120
+ " npm install --include=optional sharp",
121
+ "- Ensure your package manager supports multi-platform installation:",
122
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
123
+ "- Add platform-specific dependencies:",
124
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
125
+ );
126
+ } else {
127
+ help.push(
128
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
129
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
130
+ "- Add WebAssembly-based dependencies:",
131
+ " npm install sharp @img/sharp-wasm32",
132
+ );
133
+ }
134
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
135
+ try {
136
+ const { config } = require(`@revizly/sharp-libvips-${runtimePlatform}/package`);
137
+ const libcFound = `${familySync()} ${versionSync()}`;
138
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
139
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
140
+ } catch (_errEngines) {}
141
+ }
142
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
143
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
144
+ }
145
+ if (isMacOs && /Incompatible library version/.test(messages)) {
146
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
147
+ }
148
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
149
+ help.push("- Run Node.js without using the --no-addons flag");
150
+ }
151
+ // Link to installation docs
152
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
153
+ help.push(
154
+ "- Using the canvas package on Windows?",
155
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
156
+ "- Check for outdated versions of sharp in the dependency tree:",
157
+ " npm ls sharp",
158
+ );
159
+ }
160
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
161
+ throw new Error(help.join("\n"));
162
+ }
163
+
164
+ export default sharp;
@@ -4,13 +4,15 @@
4
4
  */
5
5
 
6
6
  const events = require('node:events');
7
+ const { availableParallelism } = require("node:os");
7
8
  const detectLibc = require('detect-libc');
8
9
 
9
- const is = require('./is');
10
- const { runtimePlatformArch } = require('./libvips');
11
- const sharp = require('./sharp');
10
+ const is = require('./is.cjs');
11
+ const libvips = require('./libvips.cjs');
12
+ const sharp = require('./sharp.cjs');
13
+ const pkg = require("../package.json");
12
14
 
13
- const runtimePlatform = runtimePlatformArch();
15
+ const runtimePlatform = libvips.runtimePlatformArch();
14
16
  const libvipsVersion = sharp.libvipsVersion();
15
17
 
16
18
  /**
@@ -73,7 +75,7 @@ if (!libvipsVersion.isGlobal) {
73
75
  } catch (_) {}
74
76
  }
75
77
  }
76
- versions.sharp = require('../package.json').version;
78
+ versions.sharp = pkg.version;
77
79
 
78
80
  /* node:coverage ignore next 5 */
79
81
  if (versions.heif && format.heif) {
@@ -156,7 +158,7 @@ if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
156
158
  sharp.concurrency(1);
157
159
  } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
158
160
  // Reduce default concurrency when musl thread over-subscription detected
159
- sharp.concurrency(require('node:os').availableParallelism());
161
+ sharp.concurrency(availableParallelism());
160
162
  }
161
163
 
162
164
  /**
@@ -0,0 +1,295 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import events from 'node:events';
7
+ import { createRequire } from "node:module";
8
+ import { availableParallelism } from "node:os";
9
+ import detectLibc from 'detect-libc';
10
+
11
+ import is from './is.mjs';
12
+ import libvips from './libvips.mjs';
13
+ import sharp from './sharp.mjs';
14
+ import pkg from "../package.json" with { type: "json" };
15
+
16
+ const require = createRequire(import.meta.url);
17
+ const runtimePlatform = libvips.runtimePlatformArch();
18
+ const libvipsVersion = sharp.libvipsVersion();
19
+
20
+ /**
21
+ * An Object containing nested boolean values representing the available input and output formats/methods.
22
+ * @member
23
+ * @example
24
+ * console.log(sharp.format);
25
+ * @returns {Object}
26
+ */
27
+ const format = sharp.format();
28
+ format.heif.output.alias = ['avif', 'heic'];
29
+ format.jpeg.output.alias = ['jpe', 'jpg'];
30
+ format.tiff.output.alias = ['tif'];
31
+ format.jp2.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
32
+
33
+ /**
34
+ * An Object containing the available interpolators and their proper values
35
+ * @readonly
36
+ * @enum {string}
37
+ */
38
+ const interpolators = {
39
+ /** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
40
+ nearest: 'nearest',
41
+ /** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
42
+ bilinear: 'bilinear',
43
+ /** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
44
+ bicubic: 'bicubic',
45
+ /** [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. */
46
+ locallyBoundedBicubic: 'lbb',
47
+ /** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
48
+ nohalo: 'nohalo',
49
+ /** [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
50
+ vertexSplitQuadraticBasisSpline: 'vsqbs'
51
+ };
52
+
53
+ /**
54
+ * An Object containing the version numbers of sharp, libvips
55
+ * and (when using prebuilt binaries) its dependencies.
56
+ *
57
+ * @member
58
+ * @example
59
+ * console.log(sharp.versions);
60
+ */
61
+ let versions = {
62
+ vips: libvipsVersion.semver
63
+ };
64
+ /* node:coverage ignore next 15 */
65
+ if (!libvipsVersion.isGlobal) {
66
+ if (!libvipsVersion.isWasm) {
67
+ try {
68
+ versions = require(`@revizly/sharp-${runtimePlatform}/versions`);
69
+ } catch (_) {
70
+ try {
71
+ versions = require(`@revizly/sharp-libvips-${runtimePlatform}/versions`);
72
+ } catch (_) {}
73
+ }
74
+ } else {
75
+ try {
76
+ versions = require('@revizly/sharp-wasm32/versions');
77
+ } catch (_) {}
78
+ }
79
+ }
80
+ versions.sharp = pkg.version;
81
+
82
+ /* node:coverage ignore next 5 */
83
+ if (versions.heif && format.heif) {
84
+ // Prebuilt binaries provide AV1
85
+ format.heif.input.fileSuffix = ['.avif'];
86
+ format.heif.output.alias = ['avif'];
87
+ }
88
+
89
+ /**
90
+ * Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
91
+ * Existing entries in the cache will be trimmed after any change in limits.
92
+ * This method always returns cache statistics,
93
+ * useful for determining how much working memory is required for a particular task.
94
+ *
95
+ * @example
96
+ * const stats = sharp.cache();
97
+ * @example
98
+ * sharp.cache( { items: 200 } );
99
+ * sharp.cache( { files: 0 } );
100
+ * sharp.cache(false);
101
+ *
102
+ * @param {Object|boolean} [options=true] - Object with the following attributes, or boolean where true uses default cache settings and false removes all caching
103
+ * @param {number} [options.memory=50] - is the maximum memory in MB to use for this cache
104
+ * @param {number} [options.files=20] - is the maximum number of files to hold open
105
+ * @param {number} [options.items=100] - is the maximum number of operations to cache
106
+ * @returns {Object}
107
+ */
108
+ function cache (options) {
109
+ if (is.bool(options)) {
110
+ if (options) {
111
+ // Default cache settings of 50MB, 20 files, 100 items
112
+ return sharp.cache(50, 20, 100);
113
+ } else {
114
+ return sharp.cache(0, 0, 0);
115
+ }
116
+ } else if (is.object(options)) {
117
+ return sharp.cache(options.memory, options.files, options.items);
118
+ } else {
119
+ return sharp.cache();
120
+ }
121
+ }
122
+ cache(true);
123
+
124
+ /**
125
+ * Gets or, when a concurrency is provided, sets
126
+ * the maximum number of threads _libvips_ should use to process _each image_.
127
+ * These are from a thread pool managed by glib,
128
+ * which helps avoid the overhead of creating new threads.
129
+ *
130
+ * This method always returns the current concurrency.
131
+ *
132
+ * The default value is the number of CPU cores,
133
+ * except when using glibc-based Linux without jemalloc,
134
+ * where the default is `1` to help reduce memory fragmentation.
135
+ *
136
+ * A value of `0` will reset this to the number of CPU cores.
137
+ *
138
+ * Some image format libraries spawn additional threads,
139
+ * e.g. libaom manages its own 4 threads when encoding AVIF images,
140
+ * and these are independent of the value set here.
141
+ *
142
+ * :::note
143
+ * Further {@link /performance/ control over performance} is available.
144
+ * :::
145
+ *
146
+ * @example
147
+ * const threads = sharp.concurrency(); // 4
148
+ * sharp.concurrency(2); // 2
149
+ * sharp.concurrency(0); // 4
150
+ *
151
+ * @param {number} [concurrency]
152
+ * @returns {number} concurrency
153
+ */
154
+ function concurrency (concurrency) {
155
+ return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
156
+ }
157
+ /* node:coverage ignore next 7 */
158
+ if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
159
+ // Reduce default concurrency to 1 when using glibc memory allocator
160
+ sharp.concurrency(1);
161
+ } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
162
+ // Reduce default concurrency when musl thread over-subscription detected
163
+ sharp.concurrency(availableParallelism());
164
+ }
165
+
166
+ /**
167
+ * An EventEmitter that emits a `change` event when a task is either:
168
+ * - queued, waiting for _libuv_ to provide a worker thread
169
+ * - complete
170
+ * @member
171
+ * @example
172
+ * sharp.queue.on('change', function(queueLength) {
173
+ * console.log('Queue contains ' + queueLength + ' task(s)');
174
+ * });
175
+ */
176
+ const queue = new events.EventEmitter();
177
+
178
+ /**
179
+ * Provides access to internal task counters.
180
+ * - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
181
+ * - process is the number of resize tasks currently being processed.
182
+ *
183
+ * @example
184
+ * const counters = sharp.counters(); // { queue: 2, process: 4 }
185
+ *
186
+ * @returns {Object}
187
+ */
188
+ function counters () {
189
+ return sharp.counters();
190
+ }
191
+
192
+ /**
193
+ * Get and set use of SIMD vector unit instructions.
194
+ * Requires libvips to have been compiled with highway support.
195
+ *
196
+ * Improves the performance of `resize`, `blur` and `sharpen` operations
197
+ * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
198
+ *
199
+ * @example
200
+ * const simd = sharp.simd();
201
+ * // simd is `true` if the runtime use of highway is currently enabled
202
+ * @example
203
+ * const simd = sharp.simd(false);
204
+ * // prevent libvips from using highway at runtime
205
+ *
206
+ * @param {boolean} [simd=true]
207
+ * @returns {boolean}
208
+ */
209
+ function simd (simd) {
210
+ return sharp.simd(is.bool(simd) ? simd : null);
211
+ }
212
+
213
+ /**
214
+ * Block libvips operations at runtime.
215
+ *
216
+ * This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
217
+ * which when set will block all "untrusted" operations.
218
+ *
219
+ * @since 0.32.4
220
+ *
221
+ * @example <caption>Block all TIFF input.</caption>
222
+ * sharp.block({
223
+ * operation: ['VipsForeignLoadTiff']
224
+ * });
225
+ *
226
+ * @param {Object} options
227
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to block.
228
+ */
229
+ function block (options) {
230
+ if (is.object(options)) {
231
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
232
+ sharp.block(options.operation, true);
233
+ } else {
234
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
235
+ }
236
+ } else {
237
+ throw is.invalidParameterError('options', 'object', options);
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Unblock libvips operations at runtime.
243
+ *
244
+ * This is useful for defining a list of allowed operations.
245
+ *
246
+ * @since 0.32.4
247
+ *
248
+ * @example <caption>Block all input except WebP from the filesystem.</caption>
249
+ * sharp.block({
250
+ * operation: ['VipsForeignLoad']
251
+ * });
252
+ * sharp.unblock({
253
+ * operation: ['VipsForeignLoadWebpFile']
254
+ * });
255
+ *
256
+ * @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
257
+ * sharp.block({
258
+ * operation: ['VipsForeignLoad']
259
+ * });
260
+ * sharp.unblock({
261
+ * operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
262
+ * });
263
+ *
264
+ * @param {Object} options
265
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
266
+ */
267
+ function unblock (options) {
268
+ if (is.object(options)) {
269
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
270
+ sharp.block(options.operation, false);
271
+ } else {
272
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
273
+ }
274
+ } else {
275
+ throw is.invalidParameterError('options', 'object', options);
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Decorate the Sharp class with utility-related functions.
281
+ * @module Sharp
282
+ * @private
283
+ */
284
+ export default (Sharp) => {
285
+ Sharp.cache = cache;
286
+ Sharp.concurrency = concurrency;
287
+ Sharp.counters = counters;
288
+ Sharp.simd = simd;
289
+ Sharp.format = format;
290
+ Sharp.interpolators = interpolators;
291
+ Sharp.versions = versions;
292
+ Sharp.queue = queue;
293
+ Sharp.block = block;
294
+ Sharp.unblock = unblock;
295
+ };
package/install/build.js CHANGED
@@ -8,7 +8,7 @@ const {
8
8
  globalLibvipsVersion,
9
9
  log,
10
10
  spawnRebuild,
11
- } = require('../lib/libvips');
11
+ } = require('../dist/libvips.cjs');
12
12
 
13
13
  log('Building from source');
14
14
  log('See https://sharp.pixelplumbing.com/install#building-from-source');
package/lib/index.d.ts CHANGED
@@ -989,7 +989,8 @@ declare namespace sharp {
989
989
  autoOrient?: boolean | undefined;
990
990
  /**
991
991
  * When to abort processing of invalid pixel data, one of (in order of sensitivity):
992
- * 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
992
+ * 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort.
993
+ * Use the default 'warning' level with untrusted input. (optional, default 'warning')
993
994
  */
994
995
  failOn?: FailOnOptions | undefined;
995
996
  /**
@@ -998,6 +999,12 @@ declare namespace sharp {
998
999
  * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default 268402689)
999
1000
  */
1000
1001
  limitInputPixels?: number | boolean | undefined;
1002
+ /**
1003
+ * Do not process input images where the number of channels exceeds this limit.
1004
+ * Assumes image metadata can be trusted.
1005
+ * An integral Number of channels, zero or false to remove limit, true to use default limit of 5. (optional, default 5)
1006
+ */
1007
+ limitInputChannels?: number | boolean | undefined;
1001
1008
  /** Set this to true to remove safety features that help prevent memory exhaustion (SVG, PNG). (optional, default false) */
1002
1009
  unlimited?: boolean | undefined;
1003
1010
  /** Set this to false to use random access rather than sequential read. Some operations will do this automatically. */