@depup/sharp 0.34.5-depup.0 → 0.35.4-depup.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 +16 -109
  2. package/changes.json +5 -0
  3. package/{lib/channel.js → dist/channel.cjs} +1 -1
  4. package/dist/channel.mjs +177 -0
  5. package/{lib/colour.js → dist/colour.cjs} +11 -7
  6. package/dist/colour.mjs +199 -0
  7. package/{lib/composite.js → dist/composite.cjs} +8 -7
  8. package/dist/composite.mjs +213 -0
  9. package/{lib/constructor.js → dist/constructor.cjs} +42 -30
  10. package/dist/constructor.mjs +511 -0
  11. package/dist/index.cjs +25 -0
  12. package/dist/index.d.cts +1999 -0
  13. package/dist/index.d.mts +2046 -0
  14. package/dist/index.mjs +25 -0
  15. package/{lib/input.js → dist/input.cjs} +47 -37
  16. package/dist/input.mjs +819 -0
  17. package/{lib/is.js → dist/is.cjs} +1 -1
  18. package/dist/is.mjs +143 -0
  19. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  20. package/dist/libvips.mjs +212 -0
  21. package/{lib/operation.js → dist/operation.cjs} +37 -51
  22. package/dist/operation.mjs +1002 -0
  23. package/{lib/output.js → dist/output.cjs} +166 -47
  24. package/dist/output.mjs +1785 -0
  25. package/{lib/resize.js → dist/resize.cjs} +54 -32
  26. package/dist/resize.mjs +617 -0
  27. package/dist/sharp.cjs +174 -0
  28. package/dist/sharp.mjs +174 -0
  29. package/{lib/utility.js → dist/utility.cjs} +18 -8
  30. package/dist/utility.mjs +301 -0
  31. package/install/build.js +3 -3
  32. package/lib/index.d.ts +111 -83
  33. package/package.json +95 -54
  34. package/src/binding.gyp +19 -14
  35. package/src/common.cc +77 -21
  36. package/src/common.h +23 -4
  37. package/src/metadata.cc +66 -8
  38. package/src/metadata.h +6 -1
  39. package/src/operations.cc +25 -8
  40. package/src/operations.h +1 -1
  41. package/src/pipeline.cc +203 -69
  42. package/src/pipeline.h +15 -1
  43. package/src/stats.cc +6 -6
  44. package/src/utilities.cc +7 -6
  45. package/install/check.js +0 -14
  46. package/lib/index.js +0 -16
  47. package/lib/sharp.js +0 -121
package/dist/sharp.cjs ADDED
@@ -0,0 +1,174 @@
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
+ }
86
+ if (sharp && ["linux-x64", "linuxmusl-x64"].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
87
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
88
+ err.code = "Unsupported CPU";
89
+ errors.push(err);
90
+ sharp = null;
91
+ }
92
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
93
+ process.emitWarning(
94
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
95
+ { code: "SharpElectronLinux" }
96
+ );
97
+ }
98
+ } catch (err) {
99
+ errors.push(err);
100
+ }
101
+ }
102
+ if (!sharp) {
103
+ try {
104
+ sharp = require("@img/sharp-wasm32/sharp.node");
105
+ } catch (err) {
106
+ errors.push(err);
107
+ }
108
+ }
109
+
110
+ if (!sharp) {
111
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
112
+
113
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
114
+ errors.forEach((err) => {
115
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
116
+ help.push(`${err.code}: ${err.message}`);
117
+ }
118
+ });
119
+ const messages = errors.map((err) => err.message).join(" ");
120
+ help.push("Possible solutions:");
121
+ // Common error messages
122
+ if (isUnsupportedNodeRuntime()) {
123
+ const { found, expected } = isUnsupportedNodeRuntime();
124
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
125
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
126
+ const [os, cpu] = runtimePlatform.split("-");
127
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
128
+ help.push(
129
+ "- Ensure optional dependencies can be installed:",
130
+ " npm install --include=optional sharp",
131
+ "- Ensure your package manager supports multi-platform installation:",
132
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
133
+ "- Add platform-specific dependencies:",
134
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
135
+ );
136
+ } else {
137
+ help.push(
138
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
139
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
140
+ "- Add WebAssembly-based dependencies:",
141
+ " npm install sharp @img/sharp-wasm32",
142
+ );
143
+ }
144
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
145
+ try {
146
+ const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
147
+ const libcFound = `${familySync()} ${versionSync()}`;
148
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
149
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
150
+ } catch (_errEngines) {}
151
+ }
152
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
153
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
154
+ }
155
+ if (isMacOs && /Incompatible library version/.test(messages)) {
156
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
157
+ }
158
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
159
+ help.push("- Run Node.js without using the --no-addons flag");
160
+ }
161
+ // Link to installation docs
162
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
163
+ help.push(
164
+ "- Using the canvas package on Windows?",
165
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
166
+ "- Check for outdated versions of sharp in the dependency tree:",
167
+ " npm ls sharp",
168
+ );
169
+ }
170
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
171
+ throw new Error(help.join("\n"));
172
+ }
173
+
174
+ module.exports = sharp;
package/dist/sharp.mjs ADDED
@@ -0,0 +1,174 @@
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
+ }
86
+ if (sharp && ["linux-x64", "linuxmusl-x64"].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
87
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
88
+ err.code = "Unsupported CPU";
89
+ errors.push(err);
90
+ sharp = null;
91
+ }
92
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
93
+ process.emitWarning(
94
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
95
+ { code: "SharpElectronLinux" }
96
+ );
97
+ }
98
+ } catch (err) {
99
+ errors.push(err);
100
+ }
101
+ }
102
+ if (!sharp) {
103
+ try {
104
+ sharp = require("@img/sharp-wasm32/sharp.node");
105
+ } catch (err) {
106
+ errors.push(err);
107
+ }
108
+ }
109
+
110
+ if (!sharp) {
111
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
112
+
113
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
114
+ errors.forEach((err) => {
115
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
116
+ help.push(`${err.code}: ${err.message}`);
117
+ }
118
+ });
119
+ const messages = errors.map((err) => err.message).join(" ");
120
+ help.push("Possible solutions:");
121
+ // Common error messages
122
+ if (isUnsupportedNodeRuntime()) {
123
+ const { found, expected } = isUnsupportedNodeRuntime();
124
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
125
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
126
+ const [os, cpu] = runtimePlatform.split("-");
127
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
128
+ help.push(
129
+ "- Ensure optional dependencies can be installed:",
130
+ " npm install --include=optional sharp",
131
+ "- Ensure your package manager supports multi-platform installation:",
132
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
133
+ "- Add platform-specific dependencies:",
134
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
135
+ );
136
+ } else {
137
+ help.push(
138
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
139
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
140
+ "- Add WebAssembly-based dependencies:",
141
+ " npm install sharp @img/sharp-wasm32",
142
+ );
143
+ }
144
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
145
+ try {
146
+ const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
147
+ const libcFound = `${familySync()} ${versionSync()}`;
148
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
149
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
150
+ } catch (_errEngines) {}
151
+ }
152
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
153
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
154
+ }
155
+ if (isMacOs && /Incompatible library version/.test(messages)) {
156
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
157
+ }
158
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
159
+ help.push("- Run Node.js without using the --no-addons flag");
160
+ }
161
+ // Link to installation docs
162
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
163
+ help.push(
164
+ "- Using the canvas package on Windows?",
165
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
166
+ "- Check for outdated versions of sharp in the dependency tree:",
167
+ " npm ls sharp",
168
+ );
169
+ }
170
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
171
+ throw new Error(help.join("\n"));
172
+ }
173
+
174
+ 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
  /**