sharp 0.33.0-alpha.7 → 0.33.0-alpha.9

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/index.d.ts CHANGED
@@ -640,7 +640,7 @@ declare namespace sharp {
640
640
  * @param withMetadata
641
641
  * @throws {Error} Invalid parameters.
642
642
  */
643
- withMetadata(withMetadata?: WriteableMetadata): Sharp;
643
+ withMetadata(withMetadata?: boolean | WriteableMetadata): Sharp;
644
644
 
645
645
  /**
646
646
  * Use these JPEG options for output image.
@@ -1275,10 +1275,10 @@ declare namespace sharp {
1275
1275
  }
1276
1276
 
1277
1277
  interface NormaliseOptions {
1278
- /** Percentile below which luminance values will be underexposed. */
1279
- lower?: number | undefined;
1280
- /** Percentile above which luminance values will be overexposed. */
1281
- upper?: number | undefined;
1278
+ /** Percentile below which luminance values will be underexposed. */
1279
+ lower?: number | undefined;
1280
+ /** Percentile above which luminance values will be overexposed. */
1281
+ upper?: number | undefined;
1282
1282
  }
1283
1283
 
1284
1284
  interface ResizeOptions {
package/lib/input.js CHANGED
@@ -483,14 +483,27 @@ function _isStreamInput () {
483
483
  * @returns {Promise<Object>|Sharp}
484
484
  */
485
485
  function metadata (callback) {
486
+ const stack = Error();
486
487
  if (is.fn(callback)) {
487
488
  if (this._isStreamInput()) {
488
489
  this.on('finish', () => {
489
490
  this._flattenBufferIn();
490
- sharp.metadata(this.options, callback);
491
+ sharp.metadata(this.options, (err, metadata) => {
492
+ if (err) {
493
+ callback(is.nativeError(err, stack));
494
+ } else {
495
+ callback(null, metadata);
496
+ }
497
+ });
491
498
  });
492
499
  } else {
493
- sharp.metadata(this.options, callback);
500
+ sharp.metadata(this.options, (err, metadata) => {
501
+ if (err) {
502
+ callback(is.nativeError(err, stack));
503
+ } else {
504
+ callback(null, metadata);
505
+ }
506
+ });
494
507
  }
495
508
  return this;
496
509
  } else {
@@ -500,7 +513,7 @@ function metadata (callback) {
500
513
  this._flattenBufferIn();
501
514
  sharp.metadata(this.options, (err, metadata) => {
502
515
  if (err) {
503
- reject(err);
516
+ reject(is.nativeError(err, stack));
504
517
  } else {
505
518
  resolve(metadata);
506
519
  }
@@ -516,7 +529,7 @@ function metadata (callback) {
516
529
  return new Promise((resolve, reject) => {
517
530
  sharp.metadata(this.options, (err, metadata) => {
518
531
  if (err) {
519
- reject(err);
532
+ reject(is.nativeError(err, stack));
520
533
  } else {
521
534
  resolve(metadata);
522
535
  }
@@ -572,14 +585,27 @@ function metadata (callback) {
572
585
  * @returns {Promise<Object>}
573
586
  */
574
587
  function stats (callback) {
588
+ const stack = Error();
575
589
  if (is.fn(callback)) {
576
590
  if (this._isStreamInput()) {
577
591
  this.on('finish', () => {
578
592
  this._flattenBufferIn();
579
- sharp.stats(this.options, callback);
593
+ sharp.stats(this.options, (err, stats) => {
594
+ if (err) {
595
+ callback(is.nativeError(err, stack));
596
+ } else {
597
+ callback(null, stats);
598
+ }
599
+ });
580
600
  });
581
601
  } else {
582
- sharp.stats(this.options, callback);
602
+ sharp.stats(this.options, (err, stats) => {
603
+ if (err) {
604
+ callback(is.nativeError(err, stack));
605
+ } else {
606
+ callback(null, stats);
607
+ }
608
+ });
583
609
  }
584
610
  return this;
585
611
  } else {
@@ -589,7 +615,7 @@ function stats (callback) {
589
615
  this._flattenBufferIn();
590
616
  sharp.stats(this.options, (err, stats) => {
591
617
  if (err) {
592
- reject(err);
618
+ reject(is.nativeError(err, stack));
593
619
  } else {
594
620
  resolve(stats);
595
621
  }
@@ -600,7 +626,7 @@ function stats (callback) {
600
626
  return new Promise((resolve, reject) => {
601
627
  sharp.stats(this.options, (err, stats) => {
602
628
  if (err) {
603
- reject(err);
629
+ reject(is.nativeError(err, stack));
604
630
  } else {
605
631
  resolve(stats);
606
632
  }
package/lib/is.js CHANGED
@@ -137,6 +137,19 @@ const invalidParameterError = function (name, expected, actual) {
137
137
  );
138
138
  };
139
139
 
140
+ /**
141
+ * Ensures an Error from C++ contains a JS stack.
142
+ *
143
+ * @param {Error} native - Error with message from C++.
144
+ * @param {Error} context - Error with stack from JS.
145
+ * @returns {Error} Error with message and stack.
146
+ * @private
147
+ */
148
+ const nativeError = function (native, context) {
149
+ context.message = native.message;
150
+ return context;
151
+ };
152
+
140
153
  module.exports = {
141
154
  defined,
142
155
  object,
@@ -151,5 +164,6 @@ module.exports = {
151
164
  integer,
152
165
  inRange,
153
166
  inArray,
154
- invalidParameterError
167
+ invalidParameterError,
168
+ nativeError
155
169
  };
package/lib/libvips.js CHANGED
@@ -48,7 +48,7 @@ const buildPlatformArch = () => {
48
48
 
49
49
  const buildSharpLibvipsIncludeDir = () => {
50
50
  try {
51
- return require('@sharpen/sharp-libvips-dev/include');
51
+ return require('@img/sharp-libvips-dev/include');
52
52
  } catch {}
53
53
  /* istanbul ignore next */
54
54
  return '';
@@ -56,7 +56,7 @@ const buildSharpLibvipsIncludeDir = () => {
56
56
 
57
57
  const buildSharpLibvipsCPlusPlusDir = () => {
58
58
  try {
59
- return require('@sharpen/sharp-libvips-dev/cplusplus');
59
+ return require('@img/sharp-libvips-dev/cplusplus');
60
60
  } catch {}
61
61
  /* istanbul ignore next */
62
62
  return '';
@@ -64,7 +64,7 @@ const buildSharpLibvipsCPlusPlusDir = () => {
64
64
 
65
65
  const buildSharpLibvipsLibDir = () => {
66
66
  try {
67
- return require(`@sharpen/sharp-libvips-${buildPlatformArch()}/lib`);
67
+ return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
68
68
  } catch {}
69
69
  /* istanbul ignore next */
70
70
  return '';
package/lib/output.js CHANGED
@@ -86,7 +86,8 @@ function toFile (fileOut, callback) {
86
86
  }
87
87
  } else {
88
88
  this.options.fileOut = fileOut;
89
- return this._pipeline(callback);
89
+ const stack = Error();
90
+ return this._pipeline(callback, stack);
90
91
  }
91
92
  return this;
92
93
  }
@@ -157,7 +158,8 @@ function toBuffer (options, callback) {
157
158
  this.options.resolveWithObject = false;
158
159
  }
159
160
  this.options.fileOut = '';
160
- return this._pipeline(is.fn(options) ? options : callback);
161
+ const stack = Error();
162
+ return this._pipeline(is.fn(options) ? options : callback, stack);
161
163
  }
162
164
 
163
165
  /**
@@ -1282,7 +1284,8 @@ function _read () {
1282
1284
  /* istanbul ignore else */
1283
1285
  if (!this.options.streamOut) {
1284
1286
  this.options.streamOut = true;
1285
- this._pipeline();
1287
+ const stack = Error();
1288
+ this._pipeline(undefined, stack);
1286
1289
  }
1287
1290
  }
1288
1291
 
@@ -1291,18 +1294,30 @@ function _read () {
1291
1294
  * Supports callback, stream and promise variants
1292
1295
  * @private
1293
1296
  */
1294
- function _pipeline (callback) {
1297
+ function _pipeline (callback, stack) {
1295
1298
  if (typeof callback === 'function') {
1296
1299
  // output=file/buffer
1297
1300
  if (this._isStreamInput()) {
1298
1301
  // output=file/buffer, input=stream
1299
1302
  this.on('finish', () => {
1300
1303
  this._flattenBufferIn();
1301
- sharp.pipeline(this.options, callback);
1304
+ sharp.pipeline(this.options, (err, data, info) => {
1305
+ if (err) {
1306
+ callback(is.nativeError(err, stack));
1307
+ } else {
1308
+ callback(null, data, info);
1309
+ }
1310
+ });
1302
1311
  });
1303
1312
  } else {
1304
1313
  // output=file/buffer, input=file/buffer
1305
- sharp.pipeline(this.options, callback);
1314
+ sharp.pipeline(this.options, (err, data, info) => {
1315
+ if (err) {
1316
+ callback(is.nativeError(err, stack));
1317
+ } else {
1318
+ callback(null, data, info);
1319
+ }
1320
+ });
1306
1321
  }
1307
1322
  return this;
1308
1323
  } else if (this.options.streamOut) {
@@ -1313,7 +1328,7 @@ function _pipeline (callback) {
1313
1328
  this._flattenBufferIn();
1314
1329
  sharp.pipeline(this.options, (err, data, info) => {
1315
1330
  if (err) {
1316
- this.emit('error', err);
1331
+ this.emit('error', is.nativeError(err, stack));
1317
1332
  } else {
1318
1333
  this.emit('info', info);
1319
1334
  this.push(data);
@@ -1329,7 +1344,7 @@ function _pipeline (callback) {
1329
1344
  // output=stream, input=file/buffer
1330
1345
  sharp.pipeline(this.options, (err, data, info) => {
1331
1346
  if (err) {
1332
- this.emit('error', err);
1347
+ this.emit('error', is.nativeError(err, stack));
1333
1348
  } else {
1334
1349
  this.emit('info', info);
1335
1350
  this.push(data);
@@ -1348,7 +1363,7 @@ function _pipeline (callback) {
1348
1363
  this._flattenBufferIn();
1349
1364
  sharp.pipeline(this.options, (err, data, info) => {
1350
1365
  if (err) {
1351
- reject(err);
1366
+ reject(is.nativeError(err, stack));
1352
1367
  } else {
1353
1368
  if (this.options.resolveWithObject) {
1354
1369
  resolve({ data, info });
@@ -1364,7 +1379,7 @@ function _pipeline (callback) {
1364
1379
  return new Promise((resolve, reject) => {
1365
1380
  sharp.pipeline(this.options, (err, data, info) => {
1366
1381
  if (err) {
1367
- reject(err);
1382
+ reject(is.nativeError(err, stack));
1368
1383
  } else {
1369
1384
  if (this.options.resolveWithObject) {
1370
1385
  resolve({ data, info });
package/lib/sharp.js CHANGED
@@ -18,7 +18,7 @@ try {
18
18
  } catch (errLocal) {
19
19
  try {
20
20
  // Check for runtime package
21
- module.exports = require(`@sharpen/sharp-${runtimePlatform}/sharp.node`);
21
+ module.exports = require(`@img/sharp-${runtimePlatform}/sharp.node`);
22
22
  } catch (errPackage) {
23
23
  const help = ['Could not load the "sharp" module at runtime'];
24
24
  if (errLocal.code !== 'MODULE_NOT_FOUND') {
@@ -30,20 +30,19 @@ try {
30
30
  help.push('Possible solutions:');
31
31
  // Common error messages
32
32
  if (prebuiltPlatforms.includes(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
+ help.push('- Add an explicit dependency for the runtime platform:');
34
+ help.push(` npm install --force @img/sharp-${runtimePlatform}`);
38
35
  } else {
39
36
  help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`);
40
37
  }
41
38
  if (isLinux && /symbol not found/i.test(errPackage)) {
42
39
  try {
43
- const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`);
40
+ const { engines } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
44
41
  const libcFound = `${familySync()} ${versionSync()}`;
45
42
  const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`;
46
- help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`);
43
+ help.push('- Update your OS:');
44
+ help.push(` Found ${libcFound}`);
45
+ help.push(` Requires ${libcRequires}`);
47
46
  } catch (errEngines) {}
48
47
  }
49
48
  if (isMacOs && /Incompatible library version/.test(errLocal.message)) {
@@ -54,7 +53,7 @@ try {
54
53
  help.push('- Run Node.js without using the --no-addons flag');
55
54
  }
56
55
  if (process.versions.pnp) {
57
- help.push('- Use a supported yarn linker, either pnpm or node-modules');
56
+ help.push('- Use a supported yarn linker, either pnpm or node-modules:');
58
57
  help.push(' yarn config set nodeLinker node-modules');
59
58
  }
60
59
  // Link to installation docs
package/lib/utility.js CHANGED
@@ -60,10 +60,10 @@ let versions = {
60
60
  /* istanbul ignore next */
61
61
  if (!libvipsVersion.isGlobal) {
62
62
  try {
63
- versions = require(`@sharpen/sharp-${runtimePlatform}/versions`);
63
+ versions = require(`@img/sharp-${runtimePlatform}/versions`);
64
64
  } catch (_) {
65
65
  try {
66
- versions = require(`@sharpen/sharp-libvips-${runtimePlatform}/versions`);
66
+ versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
67
67
  } catch (_) {}
68
68
  }
69
69
  }
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.7",
4
+ "version": "0.33.0-alpha.9",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://github.com/lovell/sharp",
7
7
  "contributors": [
@@ -139,27 +139,27 @@
139
139
  "semver": "^7.5.4"
140
140
  },
141
141
  "optionalDependencies": {
142
- "@sharpen/sharp-darwin-arm64": "0.0.1-alpha.7",
143
- "@sharpen/sharp-darwin-x64": "0.0.1-alpha.7",
144
- "@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.2",
145
- "@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.2",
146
- "@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.2",
147
- "@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.2",
148
- "@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.2",
149
- "@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.2",
150
- "@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.2",
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"
142
+ "@img/sharp-darwin-arm64": "0.33.0-alpha.9",
143
+ "@img/sharp-darwin-x64": "0.33.0-alpha.9",
144
+ "@img/sharp-libvips-darwin-arm64": "0.0.1",
145
+ "@img/sharp-libvips-darwin-x64": "0.0.1",
146
+ "@img/sharp-libvips-linux-arm": "0.0.1",
147
+ "@img/sharp-libvips-linux-arm64": "0.0.1",
148
+ "@img/sharp-libvips-linux-x64": "0.0.1",
149
+ "@img/sharp-libvips-linuxmusl-arm64": "0.0.1",
150
+ "@img/sharp-libvips-linuxmusl-x64": "0.0.1",
151
+ "@img/sharp-linux-arm": "0.33.0-alpha.9",
152
+ "@img/sharp-linux-arm64": "0.33.0-alpha.9",
153
+ "@img/sharp-linux-x64": "0.33.0-alpha.9",
154
+ "@img/sharp-linuxmusl-arm64": "0.33.0-alpha.9",
155
+ "@img/sharp-linuxmusl-x64": "0.33.0-alpha.9",
156
+ "@img/sharp-win32-ia32": "0.33.0-alpha.9",
157
+ "@img/sharp-win32-x64": "0.33.0-alpha.9"
158
158
  },
159
159
  "devDependencies": {
160
- "@sharpen/sharp-libvips-dev": "0.0.1-alpha.2",
161
- "@sharpen/sharp-libvips-win32-ia32": "0.0.1-alpha.2",
162
- "@sharpen/sharp-libvips-win32-x64": "0.0.1-alpha.2",
160
+ "@img/sharp-libvips-dev": "0.0.1",
161
+ "@img/sharp-libvips-win32-ia32": "0.0.1",
162
+ "@img/sharp-libvips-win32-x64": "0.0.1",
163
163
  "@types/node": "*",
164
164
  "async": "^3.2.4",
165
165
  "cc": "^3.0.1",
package/src/binding.gyp CHANGED
@@ -157,8 +157,8 @@
157
157
  'OTHER_LDFLAGS': [
158
158
  # Ensure runtime linking is relative to sharp.node
159
159
  '-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
160
- '-Wl,-rpath,\'@loader_path/../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\'',
161
- '-Wl,-rpath,\'@loader_path/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
160
+ '-Wl,-rpath,\'@loader_path/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
161
+ '-Wl,-rpath,\'@loader_path/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''
162
162
  ]
163
163
  }
164
164
  }],
@@ -178,8 +178,8 @@
178
178
  '-Wl,-s',
179
179
  '-Wl,--disable-new-dtags',
180
180
  '-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
181
- '-Wl,-rpath=\'$$ORIGIN/../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\'',
182
- '-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
181
+ '-Wl,-rpath=\'$$ORIGIN/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
182
+ '-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''
183
183
  ]
184
184
  }
185
185
  }]