sharp 0.32.5 → 0.33.0-alpha.3

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,58 @@
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, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
11
+ const runtimePlatform = runtimePlatformArch();
7
12
 
8
13
  /* istanbul ignore next */
9
14
  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');
15
+ // Check for local build
16
+ module.exports = require(`../build/Release/sharp-${runtimePlatform}.node`);
17
+ } catch (errLocal) {
18
+ try {
19
+ // Check for runtime package
20
+ module.exports = require(`@sharpen/sharp-${runtimePlatform}/sharp.node`);
21
+ } catch (errPackage) {
22
+ const help = ['Could not load the "sharp" module at runtime'];
23
+ if (errLocal.code !== 'MODULE_NOT_FOUND') {
24
+ help.push(`${errLocal.code}: ${errLocal.message}`);
20
25
  }
21
- 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"`
24
- );
25
- }
26
- help.push(
27
- '- Consult the installation documentation: https://sharp.pixelplumbing.com/install'
28
- );
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"`);
26
+ if (errPackage.code !== 'MODULE_NOT_FOUND') {
27
+ help.push(`${errPackage.code}: ${errPackage.message}`);
28
+ }
29
+ help.push('Possible solutions:');
30
+ // Common error messages
31
+ if (prebuiltPlatforms.includes(runtimePlatform)) {
32
+ help.push(`- Add an explicit dependency for the runtime platform: "npm install --force @sharpen/sharp-${runtimePlatform}"`);
33
+ } else {
34
+ help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`);
35
+ }
36
+ if (runtimePlatform.startsWith('linux') && /symbol not found/i.test(errPackage)) {
37
+ try {
38
+ const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`);
39
+ const libcFound = `${familySync()} ${versionSync()}`;
40
+ const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`;
41
+ help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`);
42
+ } catch (errEngines) {}
43
+ }
44
+ if (runtimePlatform.startsWith('darwin') && /Incompatible library version/.test(errLocal.message)) {
45
+ help.push('- Update Homebrew: "brew update && brew upgrade vips"');
46
+ }
47
+ if (errPackage.code === 'ERR_DLOPEN_DISABLED') {
48
+ help.push('- Run Node.js without using the --no-addons flag');
49
+ }
50
+ // Link to installation docs
51
+ if (runtimePlatform.startsWith('linux') && /Module did not self-register/.test(errLocal.message + errPackage.message)) {
52
+ help.push('- Using worker threads on Linux? See https://sharp.pixelplumbing.com/install#worker-threads');
53
+ } else if (runtimePlatform.startsWith('win32') && /The specified procedure could not be found/.test(errPackage.message)) {
54
+ help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows');
55
+ } else {
56
+ help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install');
35
57
  }
58
+ throw new Error(help.join('\n'));
36
59
  }
37
- throw new Error(help.join('\n'));
38
60
  }
package/lib/utility.js CHANGED
@@ -3,13 +3,11 @@
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
 
15
13
  /**
@@ -55,25 +53,14 @@ let versions = {
55
53
  vips: sharp.libvipsVersion()
56
54
  };
57
55
  try {
58
- versions = require(`../vendor/${versions.vips}/${platformAndArch}/versions.json`);
59
- } catch (_err) { /* ignore */ }
56
+ versions = require(`@sharpen/sharp-${runtimePlatformArch()}/versions`);
57
+ } catch (_) {
58
+ try {
59
+ versions = require(`@sharpen/sharp-libvips-${runtimePlatformArch()}/versions`);
60
+ } catch (_) {}
61
+ }
60
62
  versions.sharp = require('../package.json').version;
61
63
 
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
64
  /**
78
65
  * Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
79
66
  * Existing entries in the cache will be trimmed after any change in limits.
@@ -280,7 +267,6 @@ module.exports = function (Sharp) {
280
267
  Sharp.format = format;
281
268
  Sharp.interpolators = interpolators;
282
269
  Sharp.versions = versions;
283
- Sharp.vendor = vendor;
284
270
  Sharp.queue = queue;
285
271
  Sharp.block = block;
286
272
  Sharp.unblock = unblock;
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.5",
4
+ "version": "0.33.0-alpha.3",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://github.com/lovell/sharp",
7
7
  "contributors": [
@@ -89,29 +89,32 @@
89
89
  "Lachlan Newman <lachnewman007@gmail.com>"
90
90
  ],
91
91
  "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.*",
92
+ "install": "node install/check",
93
+ "clean": "rm -rf build/ .nyc_output/ coverage/ test/fixtures/output.*",
94
94
  "test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
95
95
  "test-lint": "semistandard && cpplint",
96
96
  "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\"",
97
+ "test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
98
98
  "test-leak": "./test/leak/leak.sh",
99
99
  "test-types": "tsd",
100
+ "package-from-local-build": "node npm/from-local-build",
101
+ "package-from-github-release": "node npm/from-github-release",
100
102
  "docs-build": "node docs/build && node docs/search-index/build",
101
103
  "docs-serve": "cd docs && npx serve",
102
104
  "docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
103
105
  },
106
+ "type": "commonjs",
104
107
  "main": "lib/index.js",
105
108
  "types": "lib/index.d.ts",
106
109
  "files": [
107
110
  "binding.gyp",
108
- "install/**",
109
- "lib/**",
110
- "src/**"
111
+ "install",
112
+ "lib",
113
+ "src"
111
114
  ],
112
115
  "repository": {
113
116
  "type": "git",
114
- "url": "git://github.com/lovell/sharp"
117
+ "url": "git://github.com/lovell/sharp.git"
115
118
  },
116
119
  "keywords": [
117
120
  "jpeg",
@@ -134,57 +137,57 @@
134
137
  "dependencies": {
135
138
  "color": "^4.2.3",
136
139
  "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
+ "node-addon-api": "^7.0.0",
141
+ "semver": "^7.5.4"
142
+ },
143
+ "optionalDependencies": {
144
+ "@sharpen/sharp-darwin-arm64": "0.0.1-alpha.3",
145
+ "@sharpen/sharp-darwin-x64": "0.0.1-alpha.3",
146
+ "@sharpen/sharp-linux-arm": "0.0.1-alpha.3",
147
+ "@sharpen/sharp-linux-arm64": "0.0.1-alpha.3",
148
+ "@sharpen/sharp-linux-x64": "0.0.1-alpha.3",
149
+ "@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.3",
150
+ "@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.3",
151
+ "@sharpen/sharp-win32-ia32": "0.0.1-alpha.3",
152
+ "@sharpen/sharp-win32-x64": "0.0.1-alpha.3"
143
153
  },
144
154
  "devDependencies": {
155
+ "@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.1",
156
+ "@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.1",
157
+ "@sharpen/sharp-libvips-dev": "0.0.1-alpha.1",
158
+ "@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.1",
159
+ "@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.1",
160
+ "@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.1",
161
+ "@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.1",
162
+ "@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.1",
163
+ "@sharpen/sharp-libvips-win32-ia32": "0.0.1-alpha.1",
164
+ "@sharpen/sharp-libvips-win32-x64": "0.0.1-alpha.1",
145
165
  "@types/node": "*",
146
166
  "async": "^3.2.4",
147
167
  "cc": "^3.0.1",
148
- "exif-reader": "^1.2.0",
168
+ "exif-reader": "^2.0.0",
149
169
  "extract-zip": "^2.0.1",
150
170
  "icc": "^3.0.0",
151
171
  "jsdoc-to-markdown": "^8.0.0",
152
172
  "license-checker": "^25.0.1",
153
173
  "mocha": "^10.2.0",
154
- "mock-fs": "^5.2.0",
155
174
  "nyc": "^15.1.0",
156
- "prebuild": "lovell/prebuild#add-nodejs-20-drop-nodejs-10-and-12",
157
- "semistandard": "^16.0.1",
158
- "tsd": "^0.28.1"
175
+ "prebuild": "^12.1.0",
176
+ "semistandard": "^17.0.0",
177
+ "tar-fs": "^3.0.4",
178
+ "tsd": "^0.29.0"
159
179
  },
160
180
  "license": "Apache-2.0",
161
- "config": {
162
- "libvips": "8.14.4",
163
- "integrity": {
164
- "darwin-arm64v8": "sha512-jZt5+ZBQzdloop9z/XlOAy8jHxD+ZGt3J8YUm1g3njjjKmZ/RmM9r6QAeLLILe67ATHaaAtmCil37fDc400OrQ==",
165
- "darwin-x64": "sha512-Mhpr8n8CjrU+u5K9YLucmkCgwtJGexECLOZejPfqM8CiOMerowR0wJTuSt9WTOtb9qGOL/ndybfrymsw+YH8PA==",
166
- "linux-arm64v8": "sha512-k2PiOOv8amzS4m5jc4Vceozv8h041IoyHL/1s0Rj290jg3w6BUJL3V+TLwKUPM35i7rV5rm14gtnGZ7qKENdmA==",
167
- "linux-armv6": "sha512-CuPTo50owR8P+BCCcWk1tF4qB3XSAaHeaIzSanJM/v9zBZfUfMGI0OLv+ByyHCL3BE2CbGXaSXhuEVw2JQ08Sw==",
168
- "linux-armv7": "sha512-CvD6fMy9PkZk1m2UPTWDcFfcD4qFA3RALyAWIih8ftOY9ksI3Y4uz6c0ML+ixBl0hqQK3WEg6+ac5TGDjZbbYA==",
169
- "linux-x64": "sha512-vqoV61ka2hBYQ5582nQlyUcVPtItu927mng9RUU9nyO4Wt50z9nNT/pfcYEfF2jkBNW9JaiMaj6bENHgxA6mMg==",
170
- "linuxmusl-arm64v8": "sha512-iCyl0y/qxdvgGidsYn11R8d4TEcU92uYHtYI8FSHyUobZw/9i2y3189PUTQ/fw44oqaBzTR3p9NF2eP6aLT9gQ==",
171
- "linuxmusl-x64": "sha512-qj7IUqWUqCtxECpgNp4E1NcIbsNe1ujzBuJcnnQot7GZOuPUhI5N6ZUhozmh6LfbGFdBZpPc/JFh1eDZ0IEpbQ==",
172
- "win32-arm64v8": "sha512-VRi7fpE9Kb3xQGcNmPPTJnWGAEUMq+YOq9abpaIIB2r3Ax327/7wHS7o2ezD6zQKdxIX6gODC5io/hReIJ9Jnw==",
173
- "win32-ia32": "sha512-EnvtU7Q6+pjl5/Y1/UngCFDM2CSqpYWVDwY03ilUKSuqTeDKTJYyus0rJ+n6p4nmdjJlVdhYlkvpy8kkEAtDHg==",
174
- "win32-x64": "sha512-fCl/KQuSijVYC8hULWbff8Mfuh3vjjdz4j5p73VgdLP6aZUrHctbhBvEIe0aQ8HpmcGdBnATX5pXUQ4GDl3mwQ=="
175
- },
176
- "runtime": "napi",
177
- "target": 7
178
- },
179
181
  "engines": {
180
- "node": ">=14.15.0"
182
+ "node": "^18.17.0 || ^20.3.0 || >=21.0.0",
183
+ "libvips": ">=8.14.5"
181
184
  },
182
185
  "funding": {
183
186
  "url": "https://opencollective.com/libvips"
184
187
  },
185
188
  "binary": {
186
189
  "napi_versions": [
187
- 7
190
+ 9
188
191
  ]
189
192
  },
190
193
  "semistandard": {
package/src/common.cc CHANGED
@@ -166,10 +166,10 @@ namespace sharp {
166
166
  }
167
167
 
168
168
  // How many tasks are in the queue?
169
- volatile int counterQueue = 0;
169
+ std::atomic<int> counterQueue{0};
170
170
 
171
171
  // How many tasks are being processed?
172
- volatile int counterProcess = 0;
172
+ std::atomic<int> counterProcess{0};
173
173
 
174
174
  // Filename extension checkers
175
175
  static bool EndsWith(std::string const &str, std::string const &end) {
@@ -363,12 +363,13 @@ namespace sharp {
363
363
  if (descriptor->isBuffer) {
364
364
  if (descriptor->rawChannels > 0) {
365
365
  // Raw, uncompressed pixel data
366
+ bool const is8bit = vips_band_format_is8bit(descriptor->rawDepth);
366
367
  image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
367
368
  descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, descriptor->rawDepth);
368
369
  if (descriptor->rawChannels < 3) {
369
- image.get_image()->Type = VIPS_INTERPRETATION_B_W;
370
+ image.get_image()->Type = is8bit ? VIPS_INTERPRETATION_B_W : VIPS_INTERPRETATION_GREY16;
370
371
  } else {
371
- image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
372
+ image.get_image()->Type = is8bit ? VIPS_INTERPRETATION_sRGB : VIPS_INTERPRETATION_RGB16;
372
373
  }
373
374
  if (descriptor->rawPremultiplied) {
374
375
  image = image.unpremultiply();
package/src/common.h CHANGED
@@ -7,6 +7,7 @@
7
7
  #include <string>
8
8
  #include <tuple>
9
9
  #include <vector>
10
+ #include <atomic>
10
11
 
11
12
  #include <napi.h>
12
13
  #include <vips/vips8>
@@ -15,8 +16,8 @@
15
16
 
16
17
  #if (VIPS_MAJOR_VERSION < 8) || \
17
18
  (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 14) || \
18
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 14 && VIPS_MICRO_VERSION < 4)
19
- #error "libvips version 8.14.4+ is required - please see https://sharp.pixelplumbing.com/install"
19
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 14 && VIPS_MICRO_VERSION < 5)
20
+ #error "libvips version 8.14.5+ is required - please see https://sharp.pixelplumbing.com/install"
20
21
  #endif
21
22
 
22
23
  #if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
@@ -161,10 +162,10 @@ namespace sharp {
161
162
  };
162
163
 
163
164
  // How many tasks are in the queue?
164
- extern volatile int counterQueue;
165
+ extern std::atomic<int> counterQueue;
165
166
 
166
167
  // How many tasks are being processed?
167
- extern volatile int counterProcess;
168
+ extern std::atomic<int> counterProcess;
168
169
 
169
170
  // Filename extension checkers
170
171
  bool IsJpeg(std::string const &str);
package/src/metadata.cc CHANGED
@@ -18,7 +18,7 @@ class MetadataWorker : public Napi::AsyncWorker {
18
18
 
19
19
  void Execute() {
20
20
  // Decrement queued task counter
21
- g_atomic_int_dec_and_test(&sharp::counterQueue);
21
+ sharp::counterQueue--;
22
22
 
23
23
  vips::VImage image;
24
24
  sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
@@ -281,7 +281,7 @@ Napi::Value metadata(const Napi::CallbackInfo& info) {
281
281
  worker->Queue();
282
282
 
283
283
  // Increment queued task counter
284
- g_atomic_int_inc(&sharp::counterQueue);
284
+ sharp::counterQueue++;
285
285
 
286
286
  return info.Env().Undefined();
287
287
  }
package/src/pipeline.cc CHANGED
@@ -44,9 +44,9 @@ class PipelineWorker : public Napi::AsyncWorker {
44
44
  // libuv worker
45
45
  void Execute() {
46
46
  // Decrement queued task counter
47
- g_atomic_int_dec_and_test(&sharp::counterQueue);
47
+ sharp::counterQueue--;
48
48
  // Increment processing task counter
49
- g_atomic_int_inc(&sharp::counterProcess);
49
+ sharp::counterProcess++;
50
50
 
51
51
  try {
52
52
  // Open input
@@ -326,7 +326,7 @@ class PipelineWorker : public Napi::AsyncWorker {
326
326
  try {
327
327
  image = image.icc_transform(processingProfile, VImage::option()
328
328
  ->set("embedded", TRUE)
329
- ->set("depth", image.interpretation() == VIPS_INTERPRETATION_RGB16 ? 16 : 8)
329
+ ->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
330
330
  ->set("intent", VIPS_INTENT_PERCEPTUAL));
331
331
  } catch(...) {
332
332
  sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid embedded profile", nullptr);
@@ -653,7 +653,7 @@ class PipelineWorker : public Napi::AsyncWorker {
653
653
  if (across != 0 || down != 0) {
654
654
  int left;
655
655
  int top;
656
- compositeImage = compositeImage.replicate(across, down);
656
+ compositeImage = sharp::StaySequential(compositeImage, access).replicate(across, down);
657
657
  if (composite->hasOffset) {
658
658
  std::tie(left, top) = sharp::CalculateCrop(
659
659
  compositeImage.width(), compositeImage.height(), image.width(), image.height(),
@@ -763,6 +763,7 @@ class PipelineWorker : public Napi::AsyncWorker {
763
763
  if (baton->withMetadata && sharp::HasProfile(image) && baton->withMetadataIcc.empty()) {
764
764
  image = image.icc_transform("srgb", VImage::option()
765
765
  ->set("embedded", TRUE)
766
+ ->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
766
767
  ->set("intent", VIPS_INTENT_PERCEPTUAL));
767
768
  }
768
769
  }
@@ -794,6 +795,7 @@ class PipelineWorker : public Napi::AsyncWorker {
794
795
  VImage::option()
795
796
  ->set("input_profile", processingProfile)
796
797
  ->set("embedded", TRUE)
798
+ ->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
797
799
  ->set("intent", VIPS_INTENT_PERCEPTUAL));
798
800
  }
799
801
  // Override EXIF Orientation tag
@@ -1287,8 +1289,8 @@ class PipelineWorker : public Napi::AsyncWorker {
1287
1289
  delete baton;
1288
1290
 
1289
1291
  // Decrement processing task counter
1290
- g_atomic_int_dec_and_test(&sharp::counterProcess);
1291
- Napi::Number queueLength = Napi::Number::New(env, static_cast<double>(sharp::counterQueue));
1292
+ sharp::counterProcess--;
1293
+ Napi::Number queueLength = Napi::Number::New(env, static_cast<int>(sharp::counterQueue));
1292
1294
  queueListener.MakeCallback(Receiver().Value(), { queueLength });
1293
1295
  }
1294
1296
 
@@ -1705,8 +1707,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
1705
1707
  worker->Queue();
1706
1708
 
1707
1709
  // Increment queued task counter
1708
- g_atomic_int_inc(&sharp::counterQueue);
1709
- Napi::Number queueLength = Napi::Number::New(info.Env(), static_cast<double>(sharp::counterQueue));
1710
+ Napi::Number queueLength = Napi::Number::New(info.Env(), static_cast<int>(++sharp::counterQueue));
1710
1711
  queueListener.MakeCallback(info.This(), { queueLength });
1711
1712
 
1712
1713
  return info.Env().Undefined();
package/src/sharp.cc CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright 2013 Lovell Fuller and others.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ #include <mutex> // NOLINT(build/c++11)
5
+
4
6
  #include <napi.h>
5
7
  #include <vips/vips8>
6
8
 
@@ -10,14 +12,11 @@
10
12
  #include "utilities.h"
11
13
  #include "stats.h"
12
14
 
13
- static void* sharp_vips_init(void*) {
14
- vips_init("sharp");
15
- return nullptr;
16
- }
17
-
18
15
  Napi::Object init(Napi::Env env, Napi::Object exports) {
19
- static GOnce sharp_vips_init_once = G_ONCE_INIT;
20
- g_once(&sharp_vips_init_once, static_cast<GThreadFunc>(sharp_vips_init), nullptr);
16
+ static std::once_flag sharp_vips_init_once;
17
+ std::call_once(sharp_vips_init_once, []() {
18
+ vips_init("sharp");
19
+ });
21
20
 
22
21
  g_log_set_handler("VIPS", static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING),
23
22
  static_cast<GLogFunc>(sharp::VipsWarningCallback), nullptr);
package/src/stats.cc CHANGED
@@ -30,7 +30,7 @@ class StatsWorker : public Napi::AsyncWorker {
30
30
 
31
31
  void Execute() {
32
32
  // Decrement queued task counter
33
- g_atomic_int_dec_and_test(&sharp::counterQueue);
33
+ sharp::counterQueue--;
34
34
 
35
35
  vips::VImage image;
36
36
  sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
@@ -177,7 +177,7 @@ Napi::Value stats(const Napi::CallbackInfo& info) {
177
177
  worker->Queue();
178
178
 
179
179
  // Increment queued task counter
180
- g_atomic_int_inc(&sharp::counterQueue);
180
+ sharp::counterQueue++;
181
181
 
182
182
  return info.Env().Undefined();
183
183
  }
package/src/utilities.cc CHANGED
@@ -70,8 +70,8 @@ Napi::Value concurrency(const Napi::CallbackInfo& info) {
70
70
  */
71
71
  Napi::Value counters(const Napi::CallbackInfo& info) {
72
72
  Napi::Object counters = Napi::Object::New(info.Env());
73
- counters.Set("queue", sharp::counterQueue);
74
- counters.Set("process", sharp::counterProcess);
73
+ counters.Set("queue", static_cast<int>(sharp::counterQueue));
74
+ counters.Set("process", static_cast<int>(sharp::counterProcess));
75
75
  return counters;
76
76
  }
77
77
 
@@ -1,14 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- const libvips = require('../lib/libvips');
7
-
8
- try {
9
- if (!(libvips.useGlobalLibvips() || libvips.hasVendoredLibvips())) {
10
- process.exitCode = 1;
11
- }
12
- } catch (err) {
13
- process.exitCode = 1;
14
- }
@@ -1,40 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- const fs = require('fs');
7
- const path = require('path');
8
-
9
- const libvips = require('../lib/libvips');
10
- const platform = require('../lib/platform');
11
-
12
- const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
13
-
14
- const platformAndArch = platform();
15
-
16
- if (platformAndArch.startsWith('win32')) {
17
- const buildReleaseDir = path.join(__dirname, '..', 'build', 'Release');
18
- libvips.log(`Creating ${buildReleaseDir}`);
19
- try {
20
- libvips.mkdirSync(buildReleaseDir);
21
- } catch (err) {}
22
- const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch, 'lib');
23
- libvips.log(`Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
24
- try {
25
- fs
26
- .readdirSync(vendorLibDir)
27
- .filter(function (filename) {
28
- return /\.dll$/.test(filename);
29
- })
30
- .forEach(function (filename) {
31
- fs.copyFileSync(
32
- path.join(vendorLibDir, filename),
33
- path.join(buildReleaseDir, filename)
34
- );
35
- });
36
- } catch (err) {
37
- libvips.log(err);
38
- process.exit(1);
39
- }
40
- }