sharp 0.33.0-alpha.4 → 0.33.0-alpha.7

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/install/check.js CHANGED
@@ -3,18 +3,27 @@
3
3
 
4
4
  'use strict';
5
5
 
6
- const { useGlobalLibvips, globalLibvipsVersion, log, gypRebuild } = require('../lib/libvips');
6
+ const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
7
7
 
8
8
  const buildFromSource = (msg) => {
9
9
  log(msg);
10
10
  log('Attempting to build from source via node-gyp');
11
11
  try {
12
- require('node-gyp');
12
+ require('node-addon-api');
13
+ log('Found node-addon-api');
13
14
  } catch (err) {
14
- log('You might need to install node-gyp');
15
+ log('Please add node-addon-api to your dependencies');
16
+ return;
17
+ }
18
+ try {
19
+ const gyp = require('node-gyp');
20
+ log(`Found node-gyp version ${gyp().version}`);
21
+ } catch (err) {
22
+ log('Please add node-gyp to your dependencies');
23
+ return;
15
24
  }
16
25
  log('See https://sharp.pixelplumbing.com/install#building-from-source');
17
- const status = gypRebuild();
26
+ const status = spawnRebuild();
18
27
  if (status !== 0) {
19
28
  process.exit(status);
20
29
  }
package/lib/libvips.js CHANGED
@@ -80,8 +80,8 @@ const isRosetta = () => {
80
80
  };
81
81
 
82
82
  /* istanbul ignore next */
83
- const gypRebuild = () =>
84
- spawnSync('node-gyp rebuild', {
83
+ const spawnRebuild = () =>
84
+ spawnSync('node-gyp rebuild --directory=src', {
85
85
  ...spawnSyncOptions,
86
86
  stdio: 'inherit'
87
87
  }).status;
@@ -146,7 +146,7 @@ module.exports = {
146
146
  buildSharpLibvipsLibDir,
147
147
  runtimePlatformArch,
148
148
  log,
149
- gypRebuild,
149
+ spawnRebuild,
150
150
  globalLibvipsVersion,
151
151
  pkgConfigPath,
152
152
  useGlobalLibvips
package/lib/sharp.js CHANGED
@@ -9,11 +9,12 @@ const { familySync, versionSync } = require('detect-libc');
9
9
 
10
10
  const { runtimePlatformArch, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
11
11
  const runtimePlatform = runtimePlatformArch();
12
+ const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
12
13
 
13
14
  /* istanbul ignore next */
14
15
  try {
15
16
  // Check for local build
16
- module.exports = require(`../build/Release/sharp-${runtimePlatform}.node`);
17
+ module.exports = require(`../src/build/Release/sharp-${runtimePlatform}.node`);
17
18
  } catch (errLocal) {
18
19
  try {
19
20
  // Check for runtime package
@@ -29,11 +30,15 @@ try {
29
30
  help.push('Possible solutions:');
30
31
  // Common error messages
31
32
  if (prebuiltPlatforms.includes(runtimePlatform)) {
32
- help.push(`- Add an explicit dependency for the runtime platform: "npm install --force @sharpen/sharp-${runtimePlatform}"`);
33
+ help.push('- Add explicit dependencies for the runtime platform:');
34
+ help.push(` npm install --force @sharpen/sharp-${runtimePlatform}`);
35
+ if (!isWindows) {
36
+ help.push(` npm install --force @sharpen/sharp-libvips-${runtimePlatform}`);
37
+ }
33
38
  } else {
34
39
  help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`);
35
40
  }
36
- if (runtimePlatform.startsWith('linux') && /symbol not found/i.test(errPackage)) {
41
+ if (isLinux && /symbol not found/i.test(errPackage)) {
37
42
  try {
38
43
  const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`);
39
44
  const libcFound = `${familySync()} ${versionSync()}`;
@@ -41,16 +46,21 @@ try {
41
46
  help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`);
42
47
  } catch (errEngines) {}
43
48
  }
44
- if (runtimePlatform.startsWith('darwin') && /Incompatible library version/.test(errLocal.message)) {
45
- help.push('- Update Homebrew: "brew update && brew upgrade vips"');
49
+ if (isMacOs && /Incompatible library version/.test(errLocal.message)) {
50
+ help.push('- Update Homebrew:');
51
+ help.push(' brew update && brew upgrade vips');
46
52
  }
47
53
  if (errPackage.code === 'ERR_DLOPEN_DISABLED') {
48
54
  help.push('- Run Node.js without using the --no-addons flag');
49
55
  }
56
+ if (process.versions.pnp) {
57
+ help.push('- Use a supported yarn linker, either pnpm or node-modules');
58
+ help.push(' yarn config set nodeLinker node-modules');
59
+ }
50
60
  // Link to installation docs
51
- if (runtimePlatform.startsWith('linux') && /Module did not self-register/.test(errLocal.message + errPackage.message)) {
61
+ if (isLinux && /Module did not self-register/.test(errLocal.message + errPackage.message)) {
52
62
  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)) {
63
+ } else if (isWindows && /The specified procedure could not be found/.test(errPackage.message)) {
54
64
  help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows');
55
65
  } else {
56
66
  help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install');
package/lib/utility.js CHANGED
@@ -10,6 +10,9 @@ const is = require('./is');
10
10
  const { runtimePlatformArch } = require('./libvips');
11
11
  const sharp = require('./sharp');
12
12
 
13
+ const runtimePlatform = runtimePlatformArch();
14
+ const libvipsVersion = sharp.libvipsVersion();
15
+
13
16
  /**
14
17
  * An Object containing nested boolean values representing the available input and output formats/methods.
15
18
  * @member
@@ -44,20 +47,25 @@ const interpolators = {
44
47
  };
45
48
 
46
49
  /**
47
- * 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
+ *
48
53
  * @member
49
54
  * @example
50
55
  * console.log(sharp.versions);
51
56
  */
52
57
  let versions = {
53
- vips: sharp.libvipsVersion()
58
+ vips: libvipsVersion.semver
54
59
  };
55
- try {
56
- versions = require(`@sharpen/sharp-${runtimePlatformArch()}/versions`);
57
- } catch (_) {
60
+ /* istanbul ignore next */
61
+ if (!libvipsVersion.isGlobal) {
58
62
  try {
59
- versions = require(`@sharpen/sharp-libvips-${runtimePlatformArch()}/versions`);
60
- } catch (_) {}
63
+ versions = require(`@sharpen/sharp-${runtimePlatform}/versions`);
64
+ } catch (_) {
65
+ try {
66
+ versions = require(`@sharpen/sharp-libvips-${runtimePlatform}/versions`);
67
+ } catch (_) {}
68
+ }
61
69
  }
62
70
  versions.sharp = require('../package.json').version;
63
71
 
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.33.0-alpha.4",
4
+ "version": "0.33.0-alpha.7",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://github.com/lovell/sharp",
7
7
  "contributors": [
@@ -90,7 +90,7 @@
90
90
  ],
91
91
  "scripts": {
92
92
  "install": "node install/check",
93
- "clean": "rm -rf build/ .nyc_output/ coverage/ test/fixtures/output.*",
93
+ "clean": "rm -rf src/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",
@@ -107,10 +107,9 @@
107
107
  "main": "lib/index.js",
108
108
  "types": "lib/index.d.ts",
109
109
  "files": [
110
- "binding.gyp",
111
110
  "install",
112
111
  "lib",
113
- "src"
112
+ "src/*.{cc,h,gyp}"
114
113
  ],
115
114
  "repository": {
116
115
  "type": "git",
@@ -137,12 +136,11 @@
137
136
  "dependencies": {
138
137
  "color": "^4.2.3",
139
138
  "detect-libc": "^2.0.2",
140
- "node-addon-api": "^7.0.0",
141
139
  "semver": "^7.5.4"
142
140
  },
143
141
  "optionalDependencies": {
144
- "@sharpen/sharp-darwin-arm64": "0.0.1-alpha.4",
145
- "@sharpen/sharp-darwin-x64": "0.0.1-alpha.4",
142
+ "@sharpen/sharp-darwin-arm64": "0.0.1-alpha.7",
143
+ "@sharpen/sharp-darwin-x64": "0.0.1-alpha.7",
146
144
  "@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.2",
147
145
  "@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.2",
148
146
  "@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.2",
@@ -150,13 +148,13 @@
150
148
  "@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.2",
151
149
  "@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.2",
152
150
  "@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.2",
153
- "@sharpen/sharp-linux-arm": "0.0.1-alpha.4",
154
- "@sharpen/sharp-linux-arm64": "0.0.1-alpha.4",
155
- "@sharpen/sharp-linux-x64": "0.0.1-alpha.4",
156
- "@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.4",
157
- "@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.4",
158
- "@sharpen/sharp-win32-ia32": "0.0.1-alpha.4",
159
- "@sharpen/sharp-win32-x64": "0.0.1-alpha.4"
151
+ "@sharpen/sharp-linux-arm": "0.0.1-alpha.7",
152
+ "@sharpen/sharp-linux-arm64": "0.0.1-alpha.7",
153
+ "@sharpen/sharp-linux-x64": "0.0.1-alpha.7",
154
+ "@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.7",
155
+ "@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.7",
156
+ "@sharpen/sharp-win32-ia32": "0.0.1-alpha.7",
157
+ "@sharpen/sharp-win32-x64": "0.0.1-alpha.7"
160
158
  },
161
159
  "devDependencies": {
162
160
  "@sharpen/sharp-libvips-dev": "0.0.1-alpha.2",
@@ -171,6 +169,7 @@
171
169
  "jsdoc-to-markdown": "^8.0.0",
172
170
  "license-checker": "^25.0.1",
173
171
  "mocha": "^10.2.0",
172
+ "node-addon-api": "^7.0.0",
174
173
  "nyc": "^15.1.0",
175
174
  "prebuild": "^12.1.0",
176
175
  "semistandard": "^17.0.0",
@@ -3,11 +3,11 @@
3
3
 
4
4
  {
5
5
  'variables': {
6
- 'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
7
- 'platform_and_arch': '<!(node -p "require(\'./lib/libvips\').buildPlatformArch()")',
8
- 'sharp_libvips_include_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsIncludeDir()")',
9
- 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
10
- 'sharp_libvips_lib_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsLibDir()")'
6
+ 'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
7
+ 'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
8
+ 'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
9
+ 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
10
+ 'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
11
11
  },
12
12
  'targets': [{
13
13
  'target_name': 'libvips-cpp',
@@ -86,8 +86,8 @@
86
86
  'variables': {
87
87
  'conditions': [
88
88
  ['OS != "win"', {
89
- 'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
90
- 'use_global_libvips': '<!(node -p "Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString()")'
89
+ 'pkg_config_path': '<!(node -p "require(\'../lib/libvips\').pkgConfigPath()")',
90
+ 'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips()).toString()")'
91
91
  }, {
92
92
  'pkg_config_path': '',
93
93
  'use_global_libvips': ''
@@ -95,13 +95,13 @@
95
95
  ]
96
96
  },
97
97
  'sources': [
98
- 'src/common.cc',
99
- 'src/metadata.cc',
100
- 'src/stats.cc',
101
- 'src/operations.cc',
102
- 'src/pipeline.cc',
103
- 'src/utilities.cc',
104
- 'src/sharp.cc'
98
+ 'common.cc',
99
+ 'metadata.cc',
100
+ 'stats.cc',
101
+ 'operations.cc',
102
+ 'pipeline.cc',
103
+ 'utilities.cc',
104
+ 'sharp.cc'
105
105
  ],
106
106
  'include_dirs': [
107
107
  '<!(node -p "require(\'node-addon-api\').include_dir")',
@@ -111,6 +111,9 @@
111
111
  # Use pkg-config for include and lib
112
112
  'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
113
113
  'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
114
+ 'defines': [
115
+ 'SHARP_USE_GLOBAL_LIBVIPS'
116
+ ],
114
117
  'conditions': [
115
118
  ['OS == "linux"', {
116
119
  'defines': [
package/src/utilities.cc CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include <cmath>
5
5
  #include <string>
6
+ #include <cstdio>
6
7
 
7
8
  #include <napi.h>
8
9
  #include <vips/vips8>
@@ -91,9 +92,18 @@ Napi::Value simd(const Napi::CallbackInfo& info) {
91
92
  Get libvips version
92
93
  */
93
94
  Napi::Value libvipsVersion(const Napi::CallbackInfo& info) {
94
- char version[9];
95
- g_snprintf(version, sizeof(version), "%d.%d.%d", vips_version(0), vips_version(1), vips_version(2));
96
- return Napi::String::New(info.Env(), version);
95
+ Napi::Env env = info.Env();
96
+ Napi::Object version = Napi::Object::New(env);
97
+
98
+ char semver[9];
99
+ std::snprintf(semver, sizeof(semver), "%d.%d.%d", vips_version(0), vips_version(1), vips_version(2));
100
+ version.Set("semver", Napi::String::New(env, semver));
101
+ #ifdef SHARP_USE_GLOBAL_LIBVIPS
102
+ version.Set("isGlobal", Napi::Boolean::New(env, true));
103
+ #else
104
+ version.Set("isGlobal", Napi::Boolean::New(env, false));
105
+ #endif
106
+ return version;
97
107
  }
98
108
 
99
109
  /*