sharp 0.32.6 → 0.33.4

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/lib/sharp.js CHANGED
@@ -3,36 +3,113 @@
3
3
 
4
4
  'use strict';
5
5
 
6
- const platformAndArch = require('./platform')();
6
+ // Inspects the runtime environment and exports the relevant sharp.node binary
7
+
8
+ const { familySync, versionSync } = require('detect-libc');
9
+
10
+ const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
11
+ const runtimePlatform = runtimePlatformArch();
12
+
13
+ const paths = [
14
+ `../src/build/Release/sharp-${runtimePlatform}.node`,
15
+ '../src/build/Release/sharp-wasm32.node',
16
+ `@img/sharp-${runtimePlatform}/sharp.node`,
17
+ '@img/sharp-wasm32/sharp.node'
18
+ ];
19
+
20
+ let sharp;
21
+ const errors = [];
22
+ for (const path of paths) {
23
+ try {
24
+ sharp = require(path);
25
+ break;
26
+ } catch (err) {
27
+ /* istanbul ignore next */
28
+ errors.push(err);
29
+ }
30
+ }
7
31
 
8
32
  /* istanbul ignore next */
9
- try {
10
- module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
11
- } catch (err) {
12
- // Bail early if bindings aren't available
13
- const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, '', 'Possible solutions:'];
14
- if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
15
- help.push('- Update Homebrew: "brew update && brew upgrade vips"');
16
- } else {
17
- const [platform, arch] = platformAndArch.split('-');
18
- if (platform === 'linux' && /Module did not self-register/.test(err.message)) {
19
- help.push('- Using worker threads? See https://sharp.pixelplumbing.com/install#worker-threads');
33
+ if (sharp) {
34
+ module.exports = sharp;
35
+ } else {
36
+ const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
37
+
38
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
39
+ errors.forEach(err => {
40
+ if (err.code !== 'MODULE_NOT_FOUND') {
41
+ help.push(`${err.code}: ${err.message}`);
20
42
  }
43
+ });
44
+ const messages = errors.map(err => err.message).join(' ');
45
+ help.push('Possible solutions:');
46
+ // Common error messages
47
+ if (isUnsupportedNodeRuntime()) {
48
+ const { found, expected } = isUnsupportedNodeRuntime();
49
+ help.push(
50
+ '- Please upgrade Node.js:',
51
+ ` Found ${found}`,
52
+ ` Requires ${expected}`
53
+ );
54
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
55
+ const [os, cpu] = runtimePlatform.split('-');
56
+ const libc = os.endsWith('musl') ? ' --libc=musl' : '';
57
+ help.push(
58
+ '- Ensure optional dependencies can be installed:',
59
+ ' npm install --include=optional sharp',
60
+ ' yarn add sharp --ignore-engines',
61
+ '- Ensure your package manager supports multi-platform installation:',
62
+ ' See https://sharp.pixelplumbing.com/install#cross-platform',
63
+ '- Add platform-specific dependencies:',
64
+ ` npm install --os=${os.replace('musl', '')}${libc} --cpu=${cpu} sharp`
65
+ );
66
+ } else {
21
67
  help.push(
22
- '- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"',
23
- `- Install for the current ${platformAndArch} runtime: "npm install --platform=${platform} --arch=${arch} sharp"`
68
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
69
+ '- Add experimental WebAssembly-based dependencies:',
70
+ ' npm install --cpu=wasm32 sharp',
71
+ ' npm install @img/sharp-wasm32'
72
+ );
73
+ }
74
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
75
+ try {
76
+ const { engines } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
77
+ const libcFound = `${familySync()} ${versionSync()}`;
78
+ const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`;
79
+ help.push(
80
+ '- Update your OS:',
81
+ ` Found ${libcFound}`,
82
+ ` Requires ${libcRequires}`
83
+ );
84
+ } catch (errEngines) {}
85
+ }
86
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
87
+ help.push(
88
+ '- Remove the Node.js Snap, which does not support native modules',
89
+ ' snap remove node'
90
+ );
91
+ }
92
+ if (isMacOs && /Incompatible library version/.test(messages)) {
93
+ help.push(
94
+ '- Update Homebrew:',
95
+ ' brew update && brew upgrade vips'
96
+ );
97
+ }
98
+ if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
99
+ help.push('- Run Node.js without using the --no-addons flag');
100
+ }
101
+ // Link to installation docs
102
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
103
+ help.push(
104
+ '- Using the canvas package on Windows?',
105
+ ' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
106
+ '- Check for outdated versions of sharp in the dependency tree:',
107
+ ' npm ls sharp'
24
108
  );
25
109
  }
26
110
  help.push(
27
- '- Consult the installation documentation: https://sharp.pixelplumbing.com/install'
111
+ '- Consult the installation documentation:',
112
+ ' See https://sharp.pixelplumbing.com/install'
28
113
  );
29
- // Check loaded
30
- if (process.platform === 'win32' || /symbol/.test(err.message)) {
31
- const loadedModule = Object.keys(require.cache).find((i) => /[\\/]build[\\/]Release[\\/]sharp(.*)\.node$/.test(i));
32
- if (loadedModule) {
33
- const [, loadedPackage] = loadedModule.match(/node_modules[\\/]([^\\/]+)[\\/]/);
34
- help.push(`- Ensure the version of sharp aligns with the ${loadedPackage} package: "npm ls sharp"`);
35
- }
36
- }
37
114
  throw new Error(help.join('\n'));
38
115
  }
package/lib/utility.js CHANGED
@@ -3,15 +3,16 @@
3
3
 
4
4
  'use strict';
5
5
 
6
- const fs = require('fs');
7
- const path = require('path');
8
- const events = require('events');
6
+ const events = require('node:events');
9
7
  const detectLibc = require('detect-libc');
10
8
 
11
9
  const is = require('./is');
12
- const platformAndArch = require('./platform')();
10
+ const { runtimePlatformArch } = require('./libvips');
13
11
  const sharp = require('./sharp');
14
12
 
13
+ const runtimePlatform = runtimePlatformArch();
14
+ const libvipsVersion = sharp.libvipsVersion();
15
+
15
16
  /**
16
17
  * An Object containing nested boolean values representing the available input and output formats/methods.
17
18
  * @member
@@ -46,34 +47,34 @@ const interpolators = {
46
47
  };
47
48
 
48
49
  /**
49
- * An Object containing the version numbers of sharp, libvips and its dependencies.
50
+ * An Object containing the version numbers of sharp, libvips
51
+ * and (when using prebuilt binaries) its dependencies.
52
+ *
50
53
  * @member
51
54
  * @example
52
55
  * console.log(sharp.versions);
53
56
  */
54
57
  let versions = {
55
- vips: sharp.libvipsVersion()
58
+ vips: libvipsVersion.semver
56
59
  };
57
- try {
58
- versions = require(`../vendor/${versions.vips}/${platformAndArch}/versions.json`);
59
- } catch (_err) { /* ignore */ }
60
+ /* istanbul ignore next */
61
+ if (!libvipsVersion.isGlobal) {
62
+ if (!libvipsVersion.isWasm) {
63
+ try {
64
+ versions = require(`@img/sharp-${runtimePlatform}/versions`);
65
+ } catch (_) {
66
+ try {
67
+ versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
68
+ } catch (_) {}
69
+ }
70
+ } else {
71
+ try {
72
+ versions = require('@img/sharp-wasm32/versions');
73
+ } catch (_) {}
74
+ }
75
+ }
60
76
  versions.sharp = require('../package.json').version;
61
77
 
62
- /**
63
- * An Object containing the platform and architecture
64
- * of the current and installed vendored binaries.
65
- * @member
66
- * @example
67
- * console.log(sharp.vendor);
68
- */
69
- const vendor = {
70
- current: platformAndArch,
71
- installed: []
72
- };
73
- try {
74
- vendor.installed = fs.readdirSync(path.join(__dirname, `../vendor/${versions.vips}`));
75
- } catch (_err) { /* ignore */ }
76
-
77
78
  /**
78
79
  * Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
79
80
  * Existing entries in the cache will be trimmed after any change in limits.
@@ -152,6 +153,9 @@ function concurrency (concurrency) {
152
153
  if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
153
154
  // Reduce default concurrency to 1 when using glibc memory allocator
154
155
  sharp.concurrency(1);
156
+ } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
157
+ // Reduce default concurrency when musl thread over-subscription detected
158
+ sharp.concurrency(require('node:os').availableParallelism());
155
159
  }
156
160
 
157
161
  /**
@@ -182,17 +186,17 @@ function counters () {
182
186
 
183
187
  /**
184
188
  * Get and set use of SIMD vector unit instructions.
185
- * Requires libvips to have been compiled with liborc support.
189
+ * Requires libvips to have been compiled with highway support.
186
190
  *
187
191
  * Improves the performance of `resize`, `blur` and `sharpen` operations
188
192
  * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
189
193
  *
190
194
  * @example
191
195
  * const simd = sharp.simd();
192
- * // simd is `true` if the runtime use of liborc is currently enabled
196
+ * // simd is `true` if the runtime use of highway is currently enabled
193
197
  * @example
194
198
  * const simd = sharp.simd(false);
195
- * // prevent libvips from using liborc at runtime
199
+ * // prevent libvips from using highway at runtime
196
200
  *
197
201
  * @param {boolean} [simd=true]
198
202
  * @returns {boolean}
@@ -200,7 +204,6 @@ function counters () {
200
204
  function simd (simd) {
201
205
  return sharp.simd(is.bool(simd) ? simd : null);
202
206
  }
203
- simd(true);
204
207
 
205
208
  /**
206
209
  * Block libvips operations at runtime.
@@ -280,7 +283,6 @@ module.exports = function (Sharp) {
280
283
  Sharp.format = format;
281
284
  Sharp.interpolators = interpolators;
282
285
  Sharp.versions = versions;
283
- Sharp.vendor = vendor;
284
286
  Sharp.queue = queue;
285
287
  Sharp.block = block;
286
288
  Sharp.unblock = unblock;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "sharp",
3
3
  "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
4
- "version": "0.32.6",
4
+ "version": "0.33.4",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
- "homepage": "https://github.com/lovell/sharp",
6
+ "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
8
8
  "Pierre Inglebert <pierre.inglebert@gmail.com>",
9
9
  "Jonathan Ong <jonathanrichardong@gmail.com>",
@@ -82,36 +82,40 @@
82
82
  "Joris Dugué <zaruike10@gmail.com>",
83
83
  "Chris Banks <christopher.bradley.banks@gmail.com>",
84
84
  "Ompal Singh <ompal.hitm09@gmail.com>",
85
- "Brodan <christopher.hranj@gmail.com",
85
+ "Brodan <christopher.hranj@gmail.com>",
86
86
  "Ankur Parihar <ankur.github@gmail.com>",
87
87
  "Brahim Ait elhaj <brahima@gmail.com>",
88
88
  "Mart Jansink <m.jansink@gmail.com>",
89
- "Lachlan Newman <lachnewman007@gmail.com>"
89
+ "Lachlan Newman <lachnewman007@gmail.com>",
90
+ "Dennis Beatty <dennis@dcbeatty.com>",
91
+ "Ingvar Stepanyan <me@rreverser.com>"
90
92
  ],
91
93
  "scripts": {
92
- "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)",
93
- "clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
94
+ "install": "node install/check",
95
+ "clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
94
96
  "test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
95
97
  "test-lint": "semistandard && cpplint",
96
98
  "test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
97
- "test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
99
+ "test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
98
100
  "test-leak": "./test/leak/leak.sh",
99
101
  "test-types": "tsd",
102
+ "package-from-local-build": "node npm/from-local-build",
103
+ "package-from-github-release": "node npm/from-github-release",
100
104
  "docs-build": "node docs/build && node docs/search-index/build",
101
105
  "docs-serve": "cd docs && npx serve",
102
106
  "docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
103
107
  },
108
+ "type": "commonjs",
104
109
  "main": "lib/index.js",
105
110
  "types": "lib/index.d.ts",
106
111
  "files": [
107
- "binding.gyp",
108
- "install/**",
109
- "lib/**",
110
- "src/**"
112
+ "install",
113
+ "lib",
114
+ "src/*.{cc,h,gyp}"
111
115
  ],
112
116
  "repository": {
113
117
  "type": "git",
114
- "url": "git://github.com/lovell/sharp"
118
+ "url": "git://github.com/lovell/sharp.git"
115
119
  },
116
120
  "keywords": [
117
121
  "jpeg",
@@ -133,58 +137,64 @@
133
137
  ],
134
138
  "dependencies": {
135
139
  "color": "^4.2.3",
136
- "detect-libc": "^2.0.2",
137
- "node-addon-api": "^6.1.0",
138
- "prebuild-install": "^7.1.1",
139
- "semver": "^7.5.4",
140
- "simple-get": "^4.0.1",
141
- "tar-fs": "^3.0.4",
142
- "tunnel-agent": "^0.6.0"
140
+ "detect-libc": "^2.0.3",
141
+ "semver": "^7.6.0"
142
+ },
143
+ "optionalDependencies": {
144
+ "@img/sharp-darwin-arm64": "0.33.4",
145
+ "@img/sharp-darwin-x64": "0.33.4",
146
+ "@img/sharp-libvips-darwin-arm64": "1.0.2",
147
+ "@img/sharp-libvips-darwin-x64": "1.0.2",
148
+ "@img/sharp-libvips-linux-arm": "1.0.2",
149
+ "@img/sharp-libvips-linux-arm64": "1.0.2",
150
+ "@img/sharp-libvips-linux-s390x": "1.0.2",
151
+ "@img/sharp-libvips-linux-x64": "1.0.2",
152
+ "@img/sharp-libvips-linuxmusl-arm64": "1.0.2",
153
+ "@img/sharp-libvips-linuxmusl-x64": "1.0.2",
154
+ "@img/sharp-linux-arm": "0.33.4",
155
+ "@img/sharp-linux-arm64": "0.33.4",
156
+ "@img/sharp-linux-s390x": "0.33.4",
157
+ "@img/sharp-linux-x64": "0.33.4",
158
+ "@img/sharp-linuxmusl-arm64": "0.33.4",
159
+ "@img/sharp-linuxmusl-x64": "0.33.4",
160
+ "@img/sharp-wasm32": "0.33.4",
161
+ "@img/sharp-win32-ia32": "0.33.4",
162
+ "@img/sharp-win32-x64": "0.33.4"
143
163
  },
144
164
  "devDependencies": {
165
+ "@emnapi/runtime": "^1.1.1",
166
+ "@img/sharp-libvips-dev": "1.0.2",
167
+ "@img/sharp-libvips-dev-wasm32": "1.0.3",
168
+ "@img/sharp-libvips-win32-ia32": "1.0.2",
169
+ "@img/sharp-libvips-win32-x64": "1.0.2",
145
170
  "@types/node": "*",
146
- "async": "^3.2.4",
171
+ "async": "^3.2.5",
147
172
  "cc": "^3.0.1",
148
- "exif-reader": "^1.2.0",
173
+ "emnapi": "^1.1.1",
174
+ "exif-reader": "^2.0.1",
149
175
  "extract-zip": "^2.0.1",
150
176
  "icc": "^3.0.0",
151
- "jsdoc-to-markdown": "^8.0.0",
177
+ "jsdoc-to-markdown": "^8.0.1",
152
178
  "license-checker": "^25.0.1",
153
- "mocha": "^10.2.0",
154
- "mock-fs": "^5.2.0",
179
+ "mocha": "^10.4.0",
180
+ "node-addon-api": "^8.0.0",
155
181
  "nyc": "^15.1.0",
156
- "prebuild": "^12.0.0",
157
- "semistandard": "^16.0.1",
158
- "tsd": "^0.29.0"
182
+ "prebuild": "^13.0.1",
183
+ "semistandard": "^17.0.0",
184
+ "tar-fs": "^3.0.6",
185
+ "tsd": "^0.31.0"
159
186
  },
160
187
  "license": "Apache-2.0",
161
- "config": {
162
- "libvips": "8.14.5",
163
- "integrity": {
164
- "darwin-arm64v8": "sha512-1QZzICfCJd4wAO0P6qmYI5e5VFMt9iCE4QgefI8VMMbdSzjIXA9L/ARN6pkMQPZ3h20Y9RtJ2W1skgCsvCIccw==",
165
- "darwin-x64": "sha512-sMIKMYXsdU9FlIfztj6Kt/SfHlhlDpP0Ups7ftVFqwjaszmYmpI9y/d/q3mLb4jrzuSiSUEislSWCwBnW7MPTw==",
166
- "linux-arm64v8": "sha512-CD8owELzkDumaom+O3jJ8fKamILAQdj+//KK/VNcHK3sngUcFpdjx36C8okwbux9sml/T7GTB/gzpvReDrAejQ==",
167
- "linux-armv6": "sha512-wk6IPHatDFVWKJy7lI1TJezHGHPQut1wF2bwx256KlZwXUQU3fcVcMpV1zxXjgLFewHq2+uhyMkoSGBPahWzlA==",
168
- "linux-armv7": "sha512-HEZC9KYtkmBK5rUR2MqBhrVarnQVZ/TwLUeLkKq0XuoM2pc/eXI6N0Fh5NGEFwdXI2XE8g1ySf+OYS6DDi+xCQ==",
169
- "linux-x64": "sha512-SlFWrITSW5XVUkaFPQOySAaSGXnhkGJCj8X2wGYYta9hk5piZldQyMp4zwy0z6UeRu1qKTKtZvmq28W3Gnh9xA==",
170
- "linuxmusl-arm64v8": "sha512-ga9iX7WUva3sG/VsKkOD318InLlCfPIztvzCZKZ2/+izQXRbQi8VoXWMHgEN4KHACv45FTl7mJ/8CRqUzhS8wQ==",
171
- "linuxmusl-x64": "sha512-yeaHnpfee1hrZLok2l4eFceHzlfq8gN3QOu0R4Mh8iMK5O5vAUu97bdtxeZZeJJvHw8tfh2/msGi0qysxKN8bw==",
172
- "win32-arm64v8": "sha512-kR91hy9w1+GEXK56hLh51+hBCBo7T+ijM4Slkmvb/2PsYZySq5H7s61n99iDYl6kTJP2y9sW5Xcvm3uuXDaDgg==",
173
- "win32-ia32": "sha512-HrnofEbzHNpHJ0vVnjsTj5yfgVdcqdWshXuwFO2zc8xlEjA83BvXZ0lVj9MxPxkxJ2ta+/UlLr+CFzc5bOceMw==",
174
- "win32-x64": "sha512-BwKckinJZ0Fu/EcunqiLPwOLEBWp4xf8GV7nvmVuKKz5f6B+GxoA2k9aa2wueqv4r4RJVgV/aWXZWFKOIjre/Q=="
175
- },
176
- "runtime": "napi",
177
- "target": 7
178
- },
179
188
  "engines": {
180
- "node": ">=14.15.0"
189
+ "node": "^18.17.0 || ^20.3.0 || >=21.0.0",
190
+ "libvips": ">=8.15.2"
181
191
  },
182
192
  "funding": {
183
193
  "url": "https://opencollective.com/libvips"
184
194
  },
185
195
  "binary": {
186
196
  "napi_versions": [
187
- 7
197
+ 9
188
198
  ]
189
199
  },
190
200
  "semistandard": {
@@ -198,6 +208,11 @@
198
208
  "build/include"
199
209
  ]
200
210
  },
211
+ "nyc": {
212
+ "include": [
213
+ "lib"
214
+ ]
215
+ },
201
216
  "tsd": {
202
217
  "directory": "test/types/"
203
218
  }