@ohos-ports/sharp 0.34.5-beta.8 → 0.35.5-beta.1

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/LICENSE +191 -0
  2. package/README.md +112 -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} +12 -8
  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/{lib/index.d.ts → dist/index.d.cts} +113 -85
  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} +9 -3
  18. package/dist/is.mjs +149 -0
  19. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  20. package/dist/libvips.mjs +213 -0
  21. package/{lib/operation.js → dist/operation.cjs} +39 -53
  22. package/dist/operation.mjs +1002 -0
  23. package/{lib/output.js → dist/output.cjs} +167 -47
  24. package/dist/output.mjs +1786 -0
  25. package/{lib/resize.js → dist/resize.cjs} +54 -32
  26. package/dist/resize.mjs +617 -0
  27. package/dist/sharp.cjs +177 -0
  28. package/dist/sharp.mjs +177 -0
  29. package/{lib/utility.js → dist/utility.cjs} +23 -25
  30. package/dist/utility.mjs +301 -0
  31. package/install/build.js +3 -3
  32. package/package.json +56 -56
  33. package/src/binding.gyp +21 -269
  34. package/src/common.cc +81 -25
  35. package/src/common.h +23 -4
  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 +231 -72
  41. package/src/pipeline.h +15 -1
  42. package/src/stats.cc +6 -6
  43. package/src/utilities.cc +8 -7
  44. package/install/check.js +0 -73
  45. package/lib/index.js +0 -16
  46. package/lib/sharp.js +0 -154
package/dist/sharp.cjs ADDED
@@ -0,0 +1,177 @@
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 "openharmony-arm64":
40
+ sharp = require("@ohos-ports/img-sharp-openharmony-arm64/sharp.node");
41
+ break;
42
+ case "darwin-arm64":
43
+ sharp = require("@img/sharp-darwin-arm64/sharp.node");
44
+ break;
45
+ case "darwin-x64":
46
+ sharp = require("@img/sharp-darwin-x64/sharp.node");
47
+ break;
48
+ case "linux-arm":
49
+ sharp = require("@img/sharp-linux-arm/sharp.node");
50
+ break;
51
+ case "linux-arm64":
52
+ sharp = require("@img/sharp-linux-arm64/sharp.node");
53
+ break;
54
+ case "linux-ppc64":
55
+ sharp = require("@img/sharp-linux-ppc64/sharp.node");
56
+ break;
57
+ case "linux-riscv64":
58
+ sharp = require("@img/sharp-linux-riscv64/sharp.node");
59
+ break;
60
+ case "linux-s390x":
61
+ sharp = require("@img/sharp-linux-s390x/sharp.node");
62
+ break;
63
+ case "linux-x64":
64
+ sharp = require("@img/sharp-linux-x64/sharp.node");
65
+ break;
66
+ case "linuxmusl-arm64":
67
+ sharp = require("@img/sharp-linuxmusl-arm64/sharp.node");
68
+ break;
69
+ case "linuxmusl-x64":
70
+ sharp = require("@img/sharp-linuxmusl-x64/sharp.node");
71
+ break;
72
+ case "win32-arm64":
73
+ sharp = require("@img/sharp-win32-arm64/sharp.node");
74
+ break;
75
+ case "win32-ia32":
76
+ sharp = require("@img/sharp-win32-ia32/sharp.node");
77
+ break;
78
+ case "win32-x64":
79
+ sharp = require("@img/sharp-win32-x64/sharp.node");
80
+ break;
81
+ case "freebsd-arm64":
82
+ case "freebsd-x64":
83
+ sharp = require("@img/sharp-freebsd-wasm32/sharp.node");
84
+ break;
85
+ case "linux-wasm32":
86
+ sharp = require("@img/sharp-webcontainers-wasm32/sharp.node");
87
+ break;
88
+ }
89
+ if (sharp && ["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
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
96
+ process.emitWarning(
97
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
98
+ { code: "SharpElectronLinux" }
99
+ );
100
+ }
101
+ } catch (err) {
102
+ errors.push(err);
103
+ }
104
+ }
105
+ if (!sharp) {
106
+ try {
107
+ sharp = require("@img/sharp-wasm32/sharp.node");
108
+ } catch (err) {
109
+ errors.push(err);
110
+ }
111
+ }
112
+
113
+ if (!sharp) {
114
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
115
+
116
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
117
+ errors.forEach((err) => {
118
+ if (!err.code?.endsWith("MODULE_NOT_FOUND")) {
119
+ help.push(err.code ? `${err.code}: ${err.message}` : err.message);
120
+ }
121
+ });
122
+ const messages = errors.map((err) => err.message).join(" ");
123
+ help.push("Possible solutions:");
124
+ // Common error messages
125
+ if (isUnsupportedNodeRuntime()) {
126
+ const { found, expected } = isUnsupportedNodeRuntime();
127
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
128
+ } else if (prebuiltPlatforms.includes(runtimePlatform) && !/libstdc\+\+\.so/.test(messages)) {
129
+ const [os, cpu] = runtimePlatform.split("-");
130
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
131
+ help.push(
132
+ "- Ensure optional dependencies can be installed:",
133
+ " npm install --include=optional sharp",
134
+ "- Ensure your package manager supports multi-platform installation:",
135
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
136
+ "- Add platform-specific dependencies:",
137
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
138
+ );
139
+ } else {
140
+ help.push(
141
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
142
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
143
+ "- Add WebAssembly-based dependencies:",
144
+ " npm install sharp @img/sharp-wasm32",
145
+ );
146
+ }
147
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
148
+ try {
149
+ const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
150
+ const libcFound = `${familySync()} ${versionSync()}`;
151
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
152
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
153
+ } catch (_errEngines) {}
154
+ }
155
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
156
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
157
+ }
158
+ if (isMacOs && /Incompatible library version/.test(messages)) {
159
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
160
+ }
161
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
162
+ help.push("- Run Node.js without using the --no-addons flag");
163
+ }
164
+ // Link to installation docs
165
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
166
+ help.push(
167
+ "- Using the canvas package on Windows?",
168
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
169
+ "- Check for outdated versions of sharp in the dependency tree:",
170
+ " npm ls sharp",
171
+ );
172
+ }
173
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
174
+ throw new Error(help.join("\n"));
175
+ }
176
+
177
+ module.exports = sharp;
package/dist/sharp.mjs ADDED
@@ -0,0 +1,177 @@
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 "openharmony-arm64":
40
+ sharp = require("@ohos-ports/img-sharp-openharmony-arm64/sharp.node");
41
+ break;
42
+ case "darwin-arm64":
43
+ sharp = require("@img/sharp-darwin-arm64/sharp.node");
44
+ break;
45
+ case "darwin-x64":
46
+ sharp = require("@img/sharp-darwin-x64/sharp.node");
47
+ break;
48
+ case "linux-arm":
49
+ sharp = require("@img/sharp-linux-arm/sharp.node");
50
+ break;
51
+ case "linux-arm64":
52
+ sharp = require("@img/sharp-linux-arm64/sharp.node");
53
+ break;
54
+ case "linux-ppc64":
55
+ sharp = require("@img/sharp-linux-ppc64/sharp.node");
56
+ break;
57
+ case "linux-riscv64":
58
+ sharp = require("@img/sharp-linux-riscv64/sharp.node");
59
+ break;
60
+ case "linux-s390x":
61
+ sharp = require("@img/sharp-linux-s390x/sharp.node");
62
+ break;
63
+ case "linux-x64":
64
+ sharp = require("@img/sharp-linux-x64/sharp.node");
65
+ break;
66
+ case "linuxmusl-arm64":
67
+ sharp = require("@img/sharp-linuxmusl-arm64/sharp.node");
68
+ break;
69
+ case "linuxmusl-x64":
70
+ sharp = require("@img/sharp-linuxmusl-x64/sharp.node");
71
+ break;
72
+ case "win32-arm64":
73
+ sharp = require("@img/sharp-win32-arm64/sharp.node");
74
+ break;
75
+ case "win32-ia32":
76
+ sharp = require("@img/sharp-win32-ia32/sharp.node");
77
+ break;
78
+ case "win32-x64":
79
+ sharp = require("@img/sharp-win32-x64/sharp.node");
80
+ break;
81
+ case "freebsd-arm64":
82
+ case "freebsd-x64":
83
+ sharp = require("@img/sharp-freebsd-wasm32/sharp.node");
84
+ break;
85
+ case "linux-wasm32":
86
+ sharp = require("@img/sharp-webcontainers-wasm32/sharp.node");
87
+ break;
88
+ }
89
+ if (sharp && ["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
+ if (sharp && process.versions.electron && runtimePlatform.startsWith("linux")) {
96
+ process.emitWarning(
97
+ "Binaries provided by Electron for use on Linux may be incompatible with sharp - see https://sharp.pixelplumbing.com/install#electron-and-linux",
98
+ { code: "SharpElectronLinux" }
99
+ );
100
+ }
101
+ } catch (err) {
102
+ errors.push(err);
103
+ }
104
+ }
105
+ if (!sharp) {
106
+ try {
107
+ sharp = require("@img/sharp-wasm32/sharp.node");
108
+ } catch (err) {
109
+ errors.push(err);
110
+ }
111
+ }
112
+
113
+ if (!sharp) {
114
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
115
+
116
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
117
+ errors.forEach((err) => {
118
+ if (!err.code?.endsWith("MODULE_NOT_FOUND")) {
119
+ help.push(err.code ? `${err.code}: ${err.message}` : err.message);
120
+ }
121
+ });
122
+ const messages = errors.map((err) => err.message).join(" ");
123
+ help.push("Possible solutions:");
124
+ // Common error messages
125
+ if (isUnsupportedNodeRuntime()) {
126
+ const { found, expected } = isUnsupportedNodeRuntime();
127
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
128
+ } else if (prebuiltPlatforms.includes(runtimePlatform) && !/libstdc\+\+\.so/.test(messages)) {
129
+ const [os, cpu] = runtimePlatform.split("-");
130
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
131
+ help.push(
132
+ "- Ensure optional dependencies can be installed:",
133
+ " npm install --include=optional sharp",
134
+ "- Ensure your package manager supports multi-platform installation:",
135
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
136
+ "- Add platform-specific dependencies:",
137
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
138
+ );
139
+ } else {
140
+ help.push(
141
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
142
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
143
+ "- Add WebAssembly-based dependencies:",
144
+ " npm install sharp @img/sharp-wasm32",
145
+ );
146
+ }
147
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
148
+ try {
149
+ const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
150
+ const libcFound = `${familySync()} ${versionSync()}`;
151
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
152
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
153
+ } catch (_errEngines) {}
154
+ }
155
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
156
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
157
+ }
158
+ if (isMacOs && /Incompatible library version/.test(messages)) {
159
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
160
+ }
161
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
162
+ help.push("- Run Node.js without using the --no-addons flag");
163
+ }
164
+ // Link to installation docs
165
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
166
+ help.push(
167
+ "- Using the canvas package on Windows?",
168
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
169
+ "- Check for outdated versions of sharp in the dependency tree:",
170
+ " npm ls sharp",
171
+ );
172
+ }
173
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
174
+ throw new Error(help.join("\n"));
175
+ }
176
+
177
+ 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
@@ -61,31 +65,19 @@ let versions = {
61
65
  if (!libvipsVersion.isGlobal) {
62
66
  if (!libvipsVersion.isWasm) {
63
67
  try {
64
- versions = require(`@ohos-ports/img-sharp-${runtimePlatform}/versions`);
68
+ versions = require(`@img/sharp-${runtimePlatform}/versions`);
65
69
  } catch (_) {
66
70
  try {
67
- versions = require(`@img/sharp-${runtimePlatform}/versions`);
68
- } catch (_) {
69
- try {
70
- versions = require(`@ohos-ports/img-sharp-libvips-${runtimePlatform}/versions`);
71
- } catch (_) {
72
- try {
73
- versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
74
- } catch (_) {}
75
- }
76
- }
71
+ versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
72
+ } catch (_) {}
77
73
  }
78
74
  } else {
79
75
  try {
80
- versions = require('@ohos-ports/img-sharp-wasm32/versions');
81
- } catch (_) {
82
- try {
83
- versions = require('@img/sharp-wasm32/versions');
84
- } catch (_) {}
85
- }
76
+ versions = require('@img/sharp-wasm32/versions');
77
+ } catch (_) {}
86
78
  }
87
79
  }
88
- versions.sharp = require('../package.json').version;
80
+ versions.sharp = pkg.version;
89
81
 
90
82
  /* node:coverage ignore next 5 */
91
83
  if (versions.heif && format.heif) {
@@ -122,6 +114,12 @@ function cache (options) {
122
114
  return sharp.cache(0, 0, 0);
123
115
  }
124
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
+ }
125
123
  return sharp.cache(options.memory, options.files, options.items);
126
124
  } else {
127
125
  return sharp.cache();
@@ -163,12 +161,12 @@ function concurrency (concurrency) {
163
161
  return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
164
162
  }
165
163
  /* node:coverage ignore next 7 */
166
- if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
164
+ if (!process.env.MALLOC_ARENA_MAX && detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
167
165
  // Reduce default concurrency to 1 when using glibc memory allocator
168
166
  sharp.concurrency(1);
169
167
  } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
170
168
  // Reduce default concurrency when musl thread over-subscription detected
171
- sharp.concurrency(require('node:os').availableParallelism());
169
+ sharp.concurrency(availableParallelism());
172
170
  }
173
171
 
174
172
  /**