sharp 0.33.5 → 0.35.0

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 (47) hide show
  1. package/README.md +12 -18
  2. package/dist/channel.cjs +177 -0
  3. package/{lib/channel.js → dist/channel.mjs} +11 -8
  4. package/dist/colour.cjs +195 -0
  5. package/{lib/colour.js → dist/colour.mjs} +38 -23
  6. package/dist/composite.cjs +213 -0
  7. package/{lib/composite.js → dist/composite.mjs} +14 -11
  8. package/{lib/constructor.js → dist/constructor.cjs} +102 -43
  9. package/dist/constructor.mjs +511 -0
  10. package/dist/index.cjs +25 -0
  11. package/dist/index.mjs +25 -0
  12. package/dist/input.cjs +814 -0
  13. package/{lib/input.js → dist/input.mjs} +224 -68
  14. package/{lib/is.js → dist/is.cjs} +19 -45
  15. package/dist/is.mjs +143 -0
  16. package/{lib/libvips.js → dist/libvips.cjs} +52 -43
  17. package/dist/libvips.mjs +212 -0
  18. package/dist/operation.cjs +987 -0
  19. package/{lib/operation.js → dist/operation.mjs} +108 -79
  20. package/{lib/output.js → dist/output.cjs} +243 -36
  21. package/dist/output.mjs +1794 -0
  22. package/dist/resize.cjs +613 -0
  23. package/{lib/resize.js → dist/resize.mjs} +38 -12
  24. package/dist/sharp.cjs +164 -0
  25. package/dist/sharp.mjs +164 -0
  26. package/{lib/utility.js → dist/utility.cjs} +23 -24
  27. package/dist/utility.mjs +295 -0
  28. package/install/build.js +38 -0
  29. package/lib/index.d.ts +347 -125
  30. package/package.json +75 -84
  31. package/src/binding.gyp +49 -26
  32. package/src/common.cc +203 -111
  33. package/src/common.h +68 -40
  34. package/src/metadata.cc +106 -22
  35. package/src/metadata.h +15 -5
  36. package/src/operations.cc +62 -21
  37. package/src/operations.h +15 -3
  38. package/src/pipeline.cc +374 -183
  39. package/src/pipeline.h +34 -7
  40. package/src/sharp.cc +11 -8
  41. package/src/stats.cc +16 -13
  42. package/src/stats.h +6 -3
  43. package/src/utilities.cc +32 -12
  44. package/src/utilities.h +5 -2
  45. package/install/check.js +0 -41
  46. package/lib/index.js +0 -16
  47. package/lib/sharp.js +0 -114
@@ -1,9 +1,9 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
5
 
6
- const is = require('./is');
6
+ import is from './is.mjs';
7
7
 
8
8
  /**
9
9
  * Weighting to apply when using contain/cover fit.
@@ -72,7 +72,9 @@ const kernel = {
72
72
  cubic: 'cubic',
73
73
  mitchell: 'mitchell',
74
74
  lanczos2: 'lanczos2',
75
- lanczos3: 'lanczos3'
75
+ lanczos3: 'lanczos3',
76
+ mks2013: 'mks2013',
77
+ mks2021: 'mks2021'
76
78
  };
77
79
 
78
80
  /**
@@ -105,7 +107,7 @@ const mapFitToCanvas = {
105
107
  * @private
106
108
  */
107
109
  function isRotationExpected (options) {
108
- return (options.angle % 360) !== 0 || options.useExifOrientation === true || options.rotationAngle !== 0;
110
+ return (options.angle % 360) !== 0 || options.rotationAngle !== 0;
109
111
  }
110
112
 
111
113
  /**
@@ -127,7 +129,7 @@ function isResizeExpected (options) {
127
129
  *
128
130
  * Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
129
131
  *
130
- * <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.svg">
132
+ * <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="/api-resize-fit.svg">
131
133
  *
132
134
  * When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
133
135
  * - `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
@@ -148,6 +150,8 @@ function isResizeExpected (options) {
148
150
  * - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
149
151
  * - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
150
152
  * - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
153
+ * - `mks2013`: Use a [Magic Kernel Sharp](https://johncostella.com/magic/mks.pdf) 2013 kernel, as adopted by Facebook.
154
+ * - `mks2021`: Use a Magic Kernel Sharp 2021 kernel, with more accurate (reduced) sharpening than the 2013 version.
151
155
  *
152
156
  * When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.
153
157
  * Downsampling kernels without a matching upsampling interpolator map to `cubic`.
@@ -339,7 +343,7 @@ function resize (widthOrOptions, height, options) {
339
343
  }
340
344
  }
341
345
  if (isRotationExpected(this.options) && isResizeExpected(this.options)) {
342
- this.options.rotateBeforePreExtract = true;
346
+ this.options.rotateBefore = true;
343
347
  }
344
348
  return this;
345
349
  }
@@ -486,9 +490,12 @@ function extract (options) {
486
490
  // Ensure existing rotation occurs before pre-resize extraction
487
491
  if (isRotationExpected(this.options) && !isResizeExpected(this.options)) {
488
492
  if (this.options.widthPre === -1 || this.options.widthPost === -1) {
489
- this.options.rotateBeforePreExtract = true;
493
+ this.options.rotateBefore = true;
490
494
  }
491
495
  }
496
+ if (this.options.input.autoOrient) {
497
+ this.options.orientBefore = true;
498
+ }
492
499
  return this;
493
500
  }
494
501
 
@@ -499,6 +506,8 @@ function extract (options) {
499
506
  *
500
507
  * If the result of this operation would trim an image to nothing then no change is made.
501
508
  *
509
+ * Use the `lineArt` and `threshold` options for control over sensitivity.
510
+ *
502
511
  * The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
503
512
  *
504
513
  * @example
@@ -533,10 +542,19 @@ function extract (options) {
533
542
  * })
534
543
  * .toBuffer();
535
544
  *
545
+ * @example
546
+ * // Trim image leaving (up to) a 10 pixel margin around the trimmed content.
547
+ * const output = await sharp(input)
548
+ * .trim({
549
+ * margin: 10
550
+ * })
551
+ * .toBuffer();
552
+ *
536
553
  * @param {Object} [options]
537
554
  * @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
538
555
  * @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
539
556
  * @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
557
+ * @param {number} [options.margin=0] - Leave a margin around trimmed content, value is in pixels.
540
558
  * @returns {Sharp}
541
559
  * @throws {Error} Invalid parameters
542
560
  */
@@ -557,21 +575,29 @@ function trim (options) {
557
575
  if (is.defined(options.lineArt)) {
558
576
  this._setBooleanOption('trimLineArt', options.lineArt);
559
577
  }
578
+ if (is.defined(options.margin)) {
579
+ if (is.integer(options.margin) && options.margin >= 0) {
580
+ this.options.trimMargin = options.margin;
581
+ } else {
582
+ throw is.invalidParameterError('margin', 'positive integer', options.margin);
583
+ }
584
+ }
560
585
  } else {
561
586
  throw is.invalidParameterError('trim', 'object', options);
562
587
  }
563
588
  }
564
589
  if (isRotationExpected(this.options)) {
565
- this.options.rotateBeforePreExtract = true;
590
+ this.options.rotateBefore = true;
566
591
  }
567
592
  return this;
568
593
  }
569
594
 
570
595
  /**
571
596
  * Decorate the Sharp prototype with resize-related functions.
597
+ * @module Sharp
572
598
  * @private
573
599
  */
574
- module.exports = function (Sharp) {
600
+ export default (Sharp) => {
575
601
  Object.assign(Sharp.prototype, {
576
602
  resize,
577
603
  extend,
package/dist/sharp.cjs 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
+
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 "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("@img/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("@img/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(`@img/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
+ 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("@img/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("@img/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(`@img/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;
@@ -1,16 +1,20 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
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
@@ -57,7 +61,7 @@ const interpolators = {
57
61
  let versions = {
58
62
  vips: libvipsVersion.semver
59
63
  };
60
- /* istanbul ignore next */
64
+ /* node:coverage ignore next 15 */
61
65
  if (!libvipsVersion.isGlobal) {
62
66
  if (!libvipsVersion.isWasm) {
63
67
  try {
@@ -73,9 +77,9 @@ 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
- /* istanbul ignore next */
82
+ /* node:coverage ignore next 5 */
79
83
  if (versions.heif && format.heif) {
80
84
  // Prebuilt binaries provide AV1
81
85
  format.heif.input.fileSuffix = ['.avif'];
@@ -135,15 +139,9 @@ cache(true);
135
139
  * e.g. libaom manages its own 4 threads when encoding AVIF images,
136
140
  * and these are independent of the value set here.
137
141
  *
138
- * The maximum number of images that sharp can process in parallel
139
- * is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
140
- * which defaults to 4.
141
- *
142
- * https://nodejs.org/api/cli.html#uv_threadpool_sizesize
143
- *
144
- * For example, by default, a machine with 8 CPU cores will process
145
- * 4 images in parallel and use up to 8 threads per image,
146
- * so there will be up to 32 concurrent threads.
142
+ * :::note
143
+ * Further {@link /performance/ control over performance} is available.
144
+ * :::
147
145
  *
148
146
  * @example
149
147
  * const threads = sharp.concurrency(); // 4
@@ -156,13 +154,13 @@ cache(true);
156
154
  function concurrency (concurrency) {
157
155
  return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
158
156
  }
159
- /* istanbul ignore next */
157
+ /* node:coverage ignore next 7 */
160
158
  if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
161
159
  // Reduce default concurrency to 1 when using glibc memory allocator
162
160
  sharp.concurrency(1);
163
161
  } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
164
162
  // Reduce default concurrency when musl thread over-subscription detected
165
- sharp.concurrency(require('node:os').availableParallelism());
163
+ sharp.concurrency(availableParallelism());
166
164
  }
167
165
 
168
166
  /**
@@ -280,9 +278,10 @@ function unblock (options) {
280
278
 
281
279
  /**
282
280
  * Decorate the Sharp class with utility-related functions.
281
+ * @module Sharp
283
282
  * @private
284
283
  */
285
- module.exports = function (Sharp) {
284
+ module.exports = (Sharp) => {
286
285
  Sharp.cache = cache;
287
286
  Sharp.concurrency = concurrency;
288
287
  Sharp.counters = counters;