@revizly/sharp 0.35.0-revizly28 → 0.35.0-revizly30

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revizly/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.35.0-revizly28",
4
+ "version": "0.35.0-revizly30",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -90,10 +90,12 @@
90
90
  "Dennis Beatty <dennis@dcbeatty.com>",
91
91
  "Ingvar Stepanyan <me@rreverser.com>",
92
92
  "Don Denton <don@happycollision.com>",
93
- "Dmytro Tiapukhin <cool.gegeg@gmail.com>"
93
+ "Dmytro Tiapukhin <cool.gegeg@gmail.com>",
94
+ "Florian Lefebvre <contact@florian-lefebvre.dev>"
94
95
  ],
95
96
  "scripts": {
96
97
  "build": "node install/build.js",
98
+ "build:dist": "node scripts/build.mjs",
97
99
  "clean": "rm -rf src/build/ test/fixtures/output.*",
98
100
  "test": "npm run lint && npm run test-unit",
99
101
  "lint": "npm run lint-cpp && npm run lint-js && npm run lint-types",
@@ -110,13 +112,21 @@
110
112
  "docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
111
113
  },
112
114
  "type": "commonjs",
113
- "main": "lib/index.js",
114
- "types": "lib/index.d.ts",
115
115
  "files": [
116
+ "dist",
116
117
  "install",
117
- "lib",
118
+ "lib/index.d.ts",
118
119
  "src/*.{cc,h,gyp}"
119
120
  ],
121
+ "main": "./dist/index.cjs",
122
+ "module": "./dist/index.mjs",
123
+ "types": "./lib/index.d.ts",
124
+ "exports": {
125
+ ".": {
126
+ "import": "./dist/index.mjs",
127
+ "require": "./dist/index.cjs"
128
+ }
129
+ },
120
130
  "repository": {
121
131
  "type": "git",
122
132
  "url": "git://github.com/janaz/sharp.git"
@@ -145,23 +155,23 @@
145
155
  "semver": "^7.7.4"
146
156
  },
147
157
  "optionalDependencies": {
148
- "@revizly/sharp-libvips-linux-arm64": "1.0.31",
149
- "@revizly/sharp-libvips-linux-x64": "1.0.31",
150
- "@revizly/sharp-linux-arm64": "0.35.0-revizly28",
151
- "@revizly/sharp-linux-x64": "0.35.0-revizly28"
158
+ "@revizly/sharp-libvips-linux-arm64": "1.0.33",
159
+ "@revizly/sharp-libvips-linux-x64": "1.0.33",
160
+ "@revizly/sharp-linux-arm64": "0.35.0-revizly30",
161
+ "@revizly/sharp-linux-x64": "0.35.0-revizly30"
152
162
  },
153
163
  "devDependencies": {
154
- "@biomejs/biome": "^2.4.10",
164
+ "@biomejs/biome": "^2.4.13",
155
165
  "@cpplint/cli": "^0.1.0",
156
- "@emnapi/runtime": "^1.9.2",
157
- "@revizly/sharp-libvips-dev": "1.0.31",
166
+ "@emnapi/runtime": "^1.10.0",
167
+ "@revizly/sharp-libvips-dev": "1.0.33",
158
168
  "@types/node": "*",
159
- "emnapi": "^1.9.2",
169
+ "emnapi": "^1.10.0",
160
170
  "exif-reader": "^2.0.3",
161
171
  "extract-zip": "^2.0.1",
162
- "icc": "^3.0.0",
172
+ "icc": "^4.0.0",
163
173
  "node-addon-api": "^8.7.0",
164
- "node-gyp": "^12.2.0",
174
+ "node-gyp": "^12.3.0",
165
175
  "tar-fs": "^3.1.2",
166
176
  "tsd": "^0.33.0"
167
177
  },
package/src/binding.gyp CHANGED
@@ -3,14 +3,14 @@
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()")',
6
+ 'vips_version': '<!(node -p "require(\'../dist/libvips.cjs\').minimumLibvipsVersion")',
7
+ 'platform_and_arch': '<!(node -p "require(\'../dist/libvips.cjs\').buildPlatformArch()")',
8
8
  'sharp_version': '<!(node -p "require(\'../package.json\').version")',
9
9
  'sharp_libvips_version': '<!(node -p "require(\'../package.json\').optionalDependencies[\'@revizly/sharp-libvips-<(platform_and_arch)\']")',
10
- 'sharp_libvips_yarn_locator': '<!(node -p "require(\'../lib/libvips\').yarnLocator()")',
11
- 'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
12
- 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
13
- 'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
10
+ 'sharp_libvips_yarn_locator': '<!(node -p "require(\'../dist/libvips.cjs\').yarnLocator()")',
11
+ 'sharp_libvips_include_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsIncludeDir()")',
12
+ 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsCPlusPlusDir()")',
13
+ 'sharp_libvips_lib_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsLibDir()")'
14
14
  },
15
15
  'targets': [{
16
16
  'target_name': 'libvips-cpp-<(vips_version)',
@@ -99,8 +99,8 @@
99
99
  'variables': {
100
100
  'conditions': [
101
101
  ['OS != "win"', {
102
- 'pkg_config_path': '<!(node -p "require(\'../lib/libvips\').pkgConfigPath()")',
103
- 'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips()).toString()")'
102
+ 'pkg_config_path': '<!(node -p "require(\'../dist/libvips.cjs\').pkgConfigPath()")',
103
+ 'use_global_libvips': '<!(node -p "Boolean(require(\'../dist/libvips.cjs\').useGlobalLibvips()).toString()")'
104
104
  }, {
105
105
  'pkg_config_path': '',
106
106
  'use_global_libvips': ''
package/src/common.cc CHANGED
@@ -196,8 +196,8 @@ namespace sharp {
196
196
  if (HasAttr(input, "joinValign")) {
197
197
  descriptor->joinValign = AttrAsEnum<VipsAlign>(input, "joinValign", VIPS_TYPE_ALIGN);
198
198
  }
199
- // Limit input images to a given number of pixels, where pixels = width * height
200
199
  descriptor->limitInputPixels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputPixels"));
200
+ descriptor->limitInputChannels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputChannels"));
201
201
  if (HasAttr(input, "access")) {
202
202
  descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
203
203
  }
@@ -614,6 +614,9 @@ namespace sharp {
614
614
  static_cast<uint64_t>(image.width()) * image.height() > descriptor->limitInputPixels) {
615
615
  throw std::runtime_error("Input image exceeds pixel limit");
616
616
  }
617
+ if (descriptor->limitInputChannels > 0 && static_cast<uint64_t>(image.bands()) > descriptor->limitInputChannels) {
618
+ throw std::runtime_error("Input image exceeds channel limit");
619
+ }
617
620
  return std::make_tuple(image, imageType);
618
621
  }
619
622
 
@@ -632,7 +635,7 @@ namespace sharp {
632
635
  if (HasProfile(image)) {
633
636
  size_t length;
634
637
  const void *data = image.get_blob(VIPS_META_ICC_NAME, &length);
635
- icc.first = static_cast<char*>(g_malloc(length));
638
+ icc.first = static_cast<char*>(vips_malloc(reinterpret_cast<VipsObject*>(image.get_image()), length));
636
639
  icc.second = length;
637
640
  memcpy(icc.first, data, length);
638
641
  }
@@ -645,7 +648,7 @@ namespace sharp {
645
648
  VImage SetProfile(VImage image, std::pair<char*, size_t> icc) {
646
649
  if (icc.first != nullptr) {
647
650
  image = image.copy();
648
- image.set(VIPS_META_ICC_NAME, reinterpret_cast<VipsCallbackFn>(vips_area_free_cb), icc.first, icc.second);
651
+ image.set(VIPS_META_ICC_NAME, nullptr, icc.first, icc.second);
649
652
  }
650
653
  return image;
651
654
  }
package/src/common.h CHANGED
@@ -46,6 +46,7 @@ namespace sharp {
46
46
  char *buffer;
47
47
  VipsFailOn failOn;
48
48
  uint64_t limitInputPixels;
49
+ uint64_t limitInputChannels;
49
50
  bool unlimited;
50
51
  VipsAccess access;
51
52
  size_t bufferLength;
@@ -98,6 +99,7 @@ namespace sharp {
98
99
  buffer(nullptr),
99
100
  failOn(VIPS_FAIL_ON_WARNING),
100
101
  limitInputPixels(0x3FFF * 0x3FFF),
102
+ limitInputChannels(5),
101
103
  unlimited(false),
102
104
  access(VIPS_ACCESS_SEQUENTIAL),
103
105
  bufferLength(0),
package/lib/index.js DELETED
@@ -1,16 +0,0 @@
1
- /*!
2
- Copyright 2013 Lovell Fuller and others.
3
- SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- const Sharp = require('./constructor');
7
- require('./input')(Sharp);
8
- require('./resize')(Sharp);
9
- require('./composite')(Sharp);
10
- require('./operation')(Sharp);
11
- require('./colour')(Sharp);
12
- require('./channel')(Sharp);
13
- require('./output')(Sharp);
14
- require('./utility')(Sharp);
15
-
16
- module.exports = Sharp;
package/lib/sharp.js DELETED
@@ -1,163 +0,0 @@
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
- const { familySync, versionSync } = require('detect-libc');
9
-
10
- const { version } = require('../package.json');
11
- const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
12
- const runtimePlatform = runtimePlatformArch();
13
-
14
- /* node:coverage disable */
15
-
16
- const prebuiltBinaryForRuntime = () => {
17
- switch (runtimePlatform) {
18
- case 'darwin-arm64':
19
- return require('@revizly/sharp-darwin-arm64/sharp.node');
20
- case 'darwin-x64':
21
- return require('@revizly/sharp-darwin-x64/sharp.node');
22
- case 'linux-arm':
23
- return require('@revizly/sharp-linux-arm/sharp.node');
24
- case 'linux-arm64':
25
- return require('@revizly/sharp-linux-arm64/sharp.node');
26
- case 'linux-ppc64':
27
- return require('@revizly/sharp-linux-ppc64/sharp.node');
28
- case 'linux-riscv64':
29
- return require('@revizly/sharp-linux-riscv64/sharp.node');
30
- case 'linux-s390x':
31
- return require('@revizly/sharp-linux-s390x/sharp.node');
32
- case 'linux-x64':
33
- return require('@revizly/sharp-linux-x64/sharp.node');
34
- case 'linuxmusl-arm64':
35
- return require('@revizly/sharp-linuxmusl-arm64/sharp.node') ;
36
- case 'linuxmusl-x64':
37
- return require('@revizly/sharp-linuxmusl-x64/sharp.node');
38
- case 'win32-arm64':
39
- return require('@revizly/sharp-win32-arm64/sharp.node');
40
- case 'win32-ia32':
41
- return require('@revizly/sharp-win32-ia32/sharp.node');
42
- case 'win32-x64':
43
- return require('@revizly/sharp-win32-x64/sharp.node');
44
- case 'freebsd-arm64':
45
- case 'freebsd-x64':
46
- return require('@revizly/sharp-freebsd-wasm32/sharp.node');
47
- case 'linux-wasm32':
48
- return require('@revizly/sharp-webcontainers-wasm32/sharp.node');
49
- default:
50
- return require('@revizly/sharp-wasm32/sharp.node');
51
- }
52
- };
53
-
54
- let sharp;
55
- const errors = [];
56
- try {
57
- sharp = require(`../src/build/Release/sharp-${runtimePlatform}-${version}.node`);
58
- } catch (err) {
59
- errors.push(err);
60
- }
61
- if (!sharp) {
62
- try {
63
- sharp = require(`../src/build/Release/sharp-wasm32-${version}.node`);
64
- } catch (err) {
65
- errors.push(err);
66
- }
67
- }
68
- if (!sharp) {
69
- try {
70
- sharp = prebuiltBinaryForRuntime();
71
- if (['linux-x64', 'linuxmusl-x64'].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
72
- const err = new Error('Prebuilt binaries for Linux x64 require v2 microarchitecture');
73
- err.code = 'Unsupported CPU';
74
- errors.push(err);
75
- sharp = null;
76
- }
77
- } catch (err) {
78
- errors.push(err);
79
- }
80
- }
81
-
82
- if (sharp) {
83
- module.exports = sharp;
84
- } else {
85
- const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
86
-
87
- const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
88
- errors.forEach(err => {
89
- if (err.code !== 'MODULE_NOT_FOUND') {
90
- help.push(`${err.code}: ${err.message}`);
91
- }
92
- });
93
- const messages = errors.map(err => err.message).join(' ');
94
- help.push('Possible solutions:');
95
- // Common error messages
96
- if (isUnsupportedNodeRuntime()) {
97
- const { found, expected } = isUnsupportedNodeRuntime();
98
- help.push(
99
- '- Please upgrade Node.js:',
100
- ` Found ${found}`,
101
- ` Requires ${expected}`
102
- );
103
- } else if (prebuiltPlatforms.includes(runtimePlatform)) {
104
- const [os, cpu] = runtimePlatform.split('-');
105
- const libc = os.endsWith('musl') ? ' --libc=musl' : '';
106
- help.push(
107
- '- Ensure optional dependencies can be installed:',
108
- ' npm install --include=optional sharp',
109
- '- Ensure your package manager supports multi-platform installation:',
110
- ' See https://sharp.pixelplumbing.com/install#cross-platform',
111
- '- Add platform-specific dependencies:',
112
- ` npm install --os=${os.replace('musl', '')}${libc} --cpu=${cpu} @revizly/sharp`
113
- );
114
- } else {
115
- help.push(
116
- `- Manually install libvips >= ${minimumLibvipsVersion}`,
117
- ' See https://sharp.pixelplumbing.com/install#building-from-source',
118
- '- Add WebAssembly-based dependencies:',
119
- ' npm install sharp @revizly/sharp-wasm32'
120
- );
121
- }
122
- if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
123
- try {
124
- const { config } = require(`@revizly/sharp-libvips-${runtimePlatform}/package`);
125
- const libcFound = `${familySync()} ${versionSync()}`;
126
- const libcRequires = `${config.musl ? 'musl' : 'glibc'} ${config.musl || config.glibc}`;
127
- help.push(
128
- '- Update your OS:',
129
- ` Found ${libcFound}`,
130
- ` Requires ${libcRequires}`
131
- );
132
- } catch (_errEngines) {}
133
- }
134
- if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
135
- help.push(
136
- '- Remove the Node.js Snap, which does not support native modules',
137
- ' snap remove node'
138
- );
139
- }
140
- if (isMacOs && /Incompatible library version/.test(messages)) {
141
- help.push(
142
- '- Update Homebrew:',
143
- ' brew update && brew upgrade vips'
144
- );
145
- }
146
- if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
147
- help.push('- Run Node.js without using the --no-addons flag');
148
- }
149
- // Link to installation docs
150
- if (isWindows && /The specified procedure could not be found/.test(messages)) {
151
- help.push(
152
- '- Using the canvas package on Windows?',
153
- ' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
154
- '- Check for outdated versions of sharp in the dependency tree:',
155
- ' npm ls sharp'
156
- );
157
- }
158
- help.push(
159
- '- Consult the installation documentation:',
160
- ' See https://sharp.pixelplumbing.com/install'
161
- );
162
- throw new Error(help.join('\n'));
163
- }
File without changes