@revizly/sharp 0.35.0-revizly4 → 0.35.0-revizly41

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.
Files changed (46) hide show
  1. package/README.md +12 -18
  2. package/{lib/channel.js → dist/channel.cjs} +1 -1
  3. package/dist/channel.mjs +177 -0
  4. package/{lib/colour.js → dist/colour.cjs} +11 -7
  5. package/dist/colour.mjs +199 -0
  6. package/{lib/composite.js → dist/composite.cjs} +2 -1
  7. package/dist/composite.mjs +213 -0
  8. package/{lib/constructor.js → dist/constructor.cjs} +42 -29
  9. package/dist/constructor.mjs +512 -0
  10. package/dist/index.cjs +25 -0
  11. package/dist/index.d.cts +2001 -0
  12. package/dist/index.d.mts +2048 -0
  13. package/dist/index.mjs +25 -0
  14. package/{lib/input.js → dist/input.cjs} +26 -21
  15. package/dist/input.mjs +814 -0
  16. package/{lib/is.js → dist/is.cjs} +1 -1
  17. package/dist/is.mjs +143 -0
  18. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  19. package/dist/libvips.mjs +212 -0
  20. package/{lib/operation.js → dist/operation.cjs} +33 -51
  21. package/dist/operation.mjs +998 -0
  22. package/{lib/output.js → dist/output.cjs} +161 -28
  23. package/dist/output.mjs +1799 -0
  24. package/{lib/resize.js → dist/resize.cjs} +46 -24
  25. package/dist/resize.mjs +617 -0
  26. package/dist/sharp.cjs +125 -0
  27. package/dist/sharp.mjs +125 -0
  28. package/{lib/utility.js → dist/utility.cjs} +18 -8
  29. package/dist/utility.mjs +301 -0
  30. package/install/build.js +3 -3
  31. package/lib/index.d.ts +105 -75
  32. package/package.json +46 -27
  33. package/src/binding.gyp +18 -13
  34. package/src/common.cc +70 -17
  35. package/src/common.h +22 -3
  36. package/src/metadata.cc +66 -8
  37. package/src/metadata.h +6 -1
  38. package/src/operations.cc +25 -8
  39. package/src/operations.h +1 -1
  40. package/src/pipeline.cc +206 -69
  41. package/src/pipeline.h +16 -1
  42. package/src/stats.cc +6 -6
  43. package/src/utilities.cc +7 -6
  44. package/install/check.js +0 -14
  45. package/lib/index.js +0 -16
  46. package/lib/sharp.js +0 -121
package/dist/sharp.cjs ADDED
@@ -0,0 +1,125 @@
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
+
9
+ const { familySync, versionSync } = require("detect-libc");
10
+
11
+ const libvips = require("./libvips.cjs");
12
+ const pkg = require('../package.json');
13
+
14
+
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 "linux-arm64":
40
+ sharp = require("@revizly/sharp-linux-arm64/sharp.node");
41
+ break;
42
+ case "linux-x64":
43
+ sharp = require("@revizly/sharp-linux-x64/sharp.node");
44
+ break;
45
+ }
46
+ if (sharp && runtimePlatform === "linux-x64" && !sharp._isUsingX64V2()) {
47
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
48
+ err.code = "Unsupported CPU";
49
+ errors.push(err);
50
+ sharp = null;
51
+ }
52
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
53
+ process.emitWarning(
54
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
55
+ { code: "SharpElectronLinux" }
56
+ );
57
+ }
58
+ } catch (err) {
59
+ errors.push(err);
60
+ }
61
+ }
62
+
63
+ if (!sharp) {
64
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
65
+
66
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
67
+ errors.forEach((err) => {
68
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
69
+ help.push(`${err.code}: ${err.message}`);
70
+ }
71
+ });
72
+ const messages = errors.map((err) => err.message).join(" ");
73
+ help.push("Possible solutions:");
74
+ // Common error messages
75
+ if (isUnsupportedNodeRuntime()) {
76
+ const { found, expected } = isUnsupportedNodeRuntime();
77
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
78
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
79
+ const [os, cpu] = runtimePlatform.split("-");
80
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
81
+ help.push(
82
+ "- Ensure optional dependencies can be installed:",
83
+ " npm install --include=optional sharp",
84
+ "- Ensure your package manager supports multi-platform installation:",
85
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
86
+ "- Add platform-specific dependencies:",
87
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
88
+ );
89
+ } else {
90
+ help.push(
91
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
92
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
93
+ );
94
+ }
95
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
96
+ try {
97
+ const { config } = require(`@revizly/sharp-libvips-${runtimePlatform}/package`);
98
+ const libcFound = `${familySync()} ${versionSync()}`;
99
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
100
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
101
+ } catch (_errEngines) {}
102
+ }
103
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
104
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
105
+ }
106
+ if (isMacOs && /Incompatible library version/.test(messages)) {
107
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
108
+ }
109
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
110
+ help.push("- Run Node.js without using the --no-addons flag");
111
+ }
112
+ // Link to installation docs
113
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
114
+ help.push(
115
+ "- Using the canvas package on Windows?",
116
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
117
+ "- Check for outdated versions of sharp in the dependency tree:",
118
+ " npm ls sharp",
119
+ );
120
+ }
121
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
122
+ throw new Error(help.join("\n"));
123
+ }
124
+
125
+ module.exports = sharp;
package/dist/sharp.mjs ADDED
@@ -0,0 +1,125 @@
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 "linux-arm64":
40
+ sharp = require("@revizly/sharp-linux-arm64/sharp.node");
41
+ break;
42
+ case "linux-x64":
43
+ sharp = require("@revizly/sharp-linux-x64/sharp.node");
44
+ break;
45
+ }
46
+ if (sharp && runtimePlatform === "linux-x64" && !sharp._isUsingX64V2()) {
47
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
48
+ err.code = "Unsupported CPU";
49
+ errors.push(err);
50
+ sharp = null;
51
+ }
52
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
53
+ process.emitWarning(
54
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
55
+ { code: "SharpElectronLinux" }
56
+ );
57
+ }
58
+ } catch (err) {
59
+ errors.push(err);
60
+ }
61
+ }
62
+
63
+ if (!sharp) {
64
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
65
+
66
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
67
+ errors.forEach((err) => {
68
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
69
+ help.push(`${err.code}: ${err.message}`);
70
+ }
71
+ });
72
+ const messages = errors.map((err) => err.message).join(" ");
73
+ help.push("Possible solutions:");
74
+ // Common error messages
75
+ if (isUnsupportedNodeRuntime()) {
76
+ const { found, expected } = isUnsupportedNodeRuntime();
77
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
78
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
79
+ const [os, cpu] = runtimePlatform.split("-");
80
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
81
+ help.push(
82
+ "- Ensure optional dependencies can be installed:",
83
+ " npm install --include=optional sharp",
84
+ "- Ensure your package manager supports multi-platform installation:",
85
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
86
+ "- Add platform-specific dependencies:",
87
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
88
+ );
89
+ } else {
90
+ help.push(
91
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
92
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
93
+ );
94
+ }
95
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
96
+ try {
97
+ const { config } = require(`@revizly/sharp-libvips-${runtimePlatform}/package`);
98
+ const libcFound = `${familySync()} ${versionSync()}`;
99
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
100
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
101
+ } catch (_errEngines) {}
102
+ }
103
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
104
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
105
+ }
106
+ if (isMacOs && /Incompatible library version/.test(messages)) {
107
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
108
+ }
109
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
110
+ help.push("- Run Node.js without using the --no-addons flag");
111
+ }
112
+ // Link to installation docs
113
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
114
+ help.push(
115
+ "- Using the canvas package on Windows?",
116
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
117
+ "- Check for outdated versions of sharp in the dependency tree:",
118
+ " npm ls sharp",
119
+ );
120
+ }
121
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
122
+ throw new Error(help.join("\n"));
123
+ }
124
+
125
+ export default sharp;
@@ -4,13 +4,17 @@
4
4
  */
5
5
 
6
6
  const events = require('node:events');
7
+
8
+ const { availableParallelism } = require("node:os");
7
9
  const detectLibc = require('detect-libc');
8
10
 
9
- const is = require('./is');
10
- const { runtimePlatformArch } = require('./libvips');
11
- const sharp = require('./sharp');
11
+ const is = require('./is.cjs');
12
+ const libvips = require('./libvips.cjs');
13
+ const sharp = require('./sharp.cjs');
14
+ const pkg = require("../package.json");
15
+
12
16
 
13
- const runtimePlatform = runtimePlatformArch();
17
+ const runtimePlatform = libvips.runtimePlatformArch();
14
18
  const libvipsVersion = sharp.libvipsVersion();
15
19
 
16
20
  /**
@@ -24,7 +28,7 @@ const format = sharp.format();
24
28
  format.heif.output.alias = ['avif', 'heic'];
25
29
  format.jpeg.output.alias = ['jpe', 'jpg'];
26
30
  format.tiff.output.alias = ['tif'];
27
- format.jp2k.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
31
+ format.jp2.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
28
32
 
29
33
  /**
30
34
  * An Object containing the available interpolators and their proper values
@@ -73,7 +77,7 @@ if (!libvipsVersion.isGlobal) {
73
77
  } catch (_) {}
74
78
  }
75
79
  }
76
- versions.sharp = require('../package.json').version;
80
+ versions.sharp = pkg.version;
77
81
 
78
82
  /* node:coverage ignore next 5 */
79
83
  if (versions.heif && format.heif) {
@@ -110,6 +114,12 @@ function cache (options) {
110
114
  return sharp.cache(0, 0, 0);
111
115
  }
112
116
  } else if (is.object(options)) {
117
+ for (const property of ['memory', 'files', 'items']) {
118
+ const value = options[property];
119
+ if (is.defined(value) && !(is.integer(value) && value >= 0)) {
120
+ throw is.invalidParameterError(property, 'a positive integer', value);
121
+ }
122
+ }
113
123
  return sharp.cache(options.memory, options.files, options.items);
114
124
  } else {
115
125
  return sharp.cache();
@@ -151,12 +161,12 @@ function concurrency (concurrency) {
151
161
  return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
152
162
  }
153
163
  /* node:coverage ignore next 7 */
154
- if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
164
+ if (!process.env.MALLOC_ARENA_MAX && detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
155
165
  // Reduce default concurrency to 1 when using glibc memory allocator
156
166
  sharp.concurrency(1);
157
167
  } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
158
168
  // Reduce default concurrency when musl thread over-subscription detected
159
- sharp.concurrency(require('node:os').availableParallelism());
169
+ sharp.concurrency(availableParallelism());
160
170
  }
161
171
 
162
172
  /**
@@ -0,0 +1,301 @@
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
+ for (const property of ['memory', 'files', 'items']) {
118
+ const value = options[property];
119
+ if (is.defined(value) && !(is.integer(value) && value >= 0)) {
120
+ throw is.invalidParameterError(property, 'a positive integer', value);
121
+ }
122
+ }
123
+ return sharp.cache(options.memory, options.files, options.items);
124
+ } else {
125
+ return sharp.cache();
126
+ }
127
+ }
128
+ cache(true);
129
+
130
+ /**
131
+ * Gets or, when a concurrency is provided, sets
132
+ * the maximum number of threads _libvips_ should use to process _each image_.
133
+ * These are from a thread pool managed by glib,
134
+ * which helps avoid the overhead of creating new threads.
135
+ *
136
+ * This method always returns the current concurrency.
137
+ *
138
+ * The default value is the number of CPU cores,
139
+ * except when using glibc-based Linux without jemalloc,
140
+ * where the default is `1` to help reduce memory fragmentation.
141
+ *
142
+ * A value of `0` will reset this to the number of CPU cores.
143
+ *
144
+ * Some image format libraries spawn additional threads,
145
+ * e.g. libaom manages its own 4 threads when encoding AVIF images,
146
+ * and these are independent of the value set here.
147
+ *
148
+ * :::note
149
+ * Further {@link /performance/ control over performance} is available.
150
+ * :::
151
+ *
152
+ * @example
153
+ * const threads = sharp.concurrency(); // 4
154
+ * sharp.concurrency(2); // 2
155
+ * sharp.concurrency(0); // 4
156
+ *
157
+ * @param {number} [concurrency]
158
+ * @returns {number} concurrency
159
+ */
160
+ function concurrency (concurrency) {
161
+ return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
162
+ }
163
+ /* node:coverage ignore next 7 */
164
+ if (!process.env.MALLOC_ARENA_MAX && detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
165
+ // Reduce default concurrency to 1 when using glibc memory allocator
166
+ sharp.concurrency(1);
167
+ } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
168
+ // Reduce default concurrency when musl thread over-subscription detected
169
+ sharp.concurrency(availableParallelism());
170
+ }
171
+
172
+ /**
173
+ * An EventEmitter that emits a `change` event when a task is either:
174
+ * - queued, waiting for _libuv_ to provide a worker thread
175
+ * - complete
176
+ * @member
177
+ * @example
178
+ * sharp.queue.on('change', function(queueLength) {
179
+ * console.log('Queue contains ' + queueLength + ' task(s)');
180
+ * });
181
+ */
182
+ const queue = new events.EventEmitter();
183
+
184
+ /**
185
+ * Provides access to internal task counters.
186
+ * - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
187
+ * - process is the number of resize tasks currently being processed.
188
+ *
189
+ * @example
190
+ * const counters = sharp.counters(); // { queue: 2, process: 4 }
191
+ *
192
+ * @returns {Object}
193
+ */
194
+ function counters () {
195
+ return sharp.counters();
196
+ }
197
+
198
+ /**
199
+ * Get and set use of SIMD vector unit instructions.
200
+ * Requires libvips to have been compiled with highway support.
201
+ *
202
+ * Improves the performance of `resize`, `blur` and `sharpen` operations
203
+ * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
204
+ *
205
+ * @example
206
+ * const simd = sharp.simd();
207
+ * // simd is `true` if the runtime use of highway is currently enabled
208
+ * @example
209
+ * const simd = sharp.simd(false);
210
+ * // prevent libvips from using highway at runtime
211
+ *
212
+ * @param {boolean} [simd=true]
213
+ * @returns {boolean}
214
+ */
215
+ function simd (simd) {
216
+ return sharp.simd(is.bool(simd) ? simd : null);
217
+ }
218
+
219
+ /**
220
+ * Block libvips operations at runtime.
221
+ *
222
+ * This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
223
+ * which when set will block all "untrusted" operations.
224
+ *
225
+ * @since 0.32.4
226
+ *
227
+ * @example <caption>Block all TIFF input.</caption>
228
+ * sharp.block({
229
+ * operation: ['VipsForeignLoadTiff']
230
+ * });
231
+ *
232
+ * @param {Object} options
233
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to block.
234
+ */
235
+ function block (options) {
236
+ if (is.object(options)) {
237
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
238
+ sharp.block(options.operation, true);
239
+ } else {
240
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
241
+ }
242
+ } else {
243
+ throw is.invalidParameterError('options', 'object', options);
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Unblock libvips operations at runtime.
249
+ *
250
+ * This is useful for defining a list of allowed operations.
251
+ *
252
+ * @since 0.32.4
253
+ *
254
+ * @example <caption>Block all input except WebP from the filesystem.</caption>
255
+ * sharp.block({
256
+ * operation: ['VipsForeignLoad']
257
+ * });
258
+ * sharp.unblock({
259
+ * operation: ['VipsForeignLoadWebpFile']
260
+ * });
261
+ *
262
+ * @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
263
+ * sharp.block({
264
+ * operation: ['VipsForeignLoad']
265
+ * });
266
+ * sharp.unblock({
267
+ * operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
268
+ * });
269
+ *
270
+ * @param {Object} options
271
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
272
+ */
273
+ function unblock (options) {
274
+ if (is.object(options)) {
275
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
276
+ sharp.block(options.operation, false);
277
+ } else {
278
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
279
+ }
280
+ } else {
281
+ throw is.invalidParameterError('options', 'object', options);
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Decorate the Sharp class with utility-related functions.
287
+ * @module Sharp
288
+ * @private
289
+ */
290
+ export default (Sharp) => {
291
+ Sharp.cache = cache;
292
+ Sharp.concurrency = concurrency;
293
+ Sharp.counters = counters;
294
+ Sharp.simd = simd;
295
+ Sharp.format = format;
296
+ Sharp.interpolators = interpolators;
297
+ Sharp.versions = versions;
298
+ Sharp.queue = queue;
299
+ Sharp.block = block;
300
+ Sharp.unblock = unblock;
301
+ };
package/install/build.js CHANGED
@@ -8,9 +8,9 @@ const {
8
8
  globalLibvipsVersion,
9
9
  log,
10
10
  spawnRebuild,
11
- } = require('../lib/libvips');
11
+ } = require('../dist/libvips.cjs');
12
12
 
13
- log('Attempting to build from source via node-gyp');
13
+ log('Building from source');
14
14
  log('See https://sharp.pixelplumbing.com/install#building-from-source');
15
15
 
16
16
  try {
@@ -29,7 +29,7 @@ try {
29
29
  }
30
30
 
31
31
  if (useGlobalLibvips(log)) {
32
- log(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
32
+ log(`Found globally-installed libvips v${globalLibvipsVersion()}`);
33
33
  }
34
34
 
35
35
  const status = spawnRebuild();