sharp 0.33.5 → 0.35.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.
Files changed (49) hide show
  1. package/README.md +12 -18
  2. package/dist/channel.cjs +177 -0
  3. package/{lib/channel.js → dist/channel.mjs} +11 -8
  4. package/dist/colour.cjs +199 -0
  5. package/{lib/colour.js → dist/colour.mjs} +42 -23
  6. package/dist/composite.cjs +213 -0
  7. package/{lib/composite.js → dist/composite.mjs} +14 -11
  8. package/{lib/constructor.js → dist/constructor.cjs} +102 -43
  9. package/dist/constructor.mjs +511 -0
  10. package/dist/index.cjs +25 -0
  11. package/dist/index.d.cts +1999 -0
  12. package/dist/index.d.mts +2046 -0
  13. package/dist/index.mjs +25 -0
  14. package/dist/input.cjs +814 -0
  15. package/{lib/input.js → dist/input.mjs} +232 -76
  16. package/{lib/is.js → dist/is.cjs} +19 -45
  17. package/dist/is.mjs +143 -0
  18. package/{lib/libvips.js → dist/libvips.cjs} +52 -43
  19. package/dist/libvips.mjs +212 -0
  20. package/dist/operation.cjs +998 -0
  21. package/{lib/operation.js → dist/operation.mjs} +131 -91
  22. package/{lib/output.js → dist/output.cjs} +262 -61
  23. package/dist/output.mjs +1788 -0
  24. package/dist/resize.cjs +617 -0
  25. package/{lib/resize.js → dist/resize.mjs} +65 -35
  26. package/dist/sharp.cjs +174 -0
  27. package/dist/sharp.mjs +174 -0
  28. package/{lib/utility.js → dist/utility.cjs} +30 -25
  29. package/dist/utility.mjs +301 -0
  30. package/install/build.js +38 -0
  31. package/lib/index.d.ts +387 -142
  32. package/package.json +90 -85
  33. package/src/binding.gyp +49 -26
  34. package/src/common.cc +203 -111
  35. package/src/common.h +68 -40
  36. package/src/metadata.cc +106 -22
  37. package/src/metadata.h +15 -5
  38. package/src/operations.cc +62 -21
  39. package/src/operations.h +15 -3
  40. package/src/pipeline.cc +391 -201
  41. package/src/pipeline.h +36 -7
  42. package/src/sharp.cc +11 -8
  43. package/src/stats.cc +16 -13
  44. package/src/stats.h +6 -3
  45. package/src/utilities.cc +35 -15
  46. package/src/utilities.h +5 -2
  47. package/install/check.js +0 -41
  48. package/lib/index.js +0 -16
  49. package/lib/sharp.js +0 -114
package/src/pipeline.h CHANGED
@@ -1,13 +1,15 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_PIPELINE_H_
5
7
  #define SRC_PIPELINE_H_
6
8
 
7
9
  #include <memory>
8
10
  #include <string>
9
- #include <vector>
10
11
  #include <unordered_map>
12
+ #include <vector>
11
13
 
12
14
  #include <napi.h>
13
15
  #include <vips/vips8>
@@ -39,12 +41,15 @@ struct Composite {
39
41
 
40
42
  struct PipelineBaton {
41
43
  sharp::InputDescriptor *input;
44
+ std::vector<sharp::InputDescriptor *> join;
42
45
  std::string formatOut;
43
46
  std::string fileOut;
44
47
  void *bufferOut;
45
48
  size_t bufferOutLength;
46
49
  int pageHeightOut;
47
50
  int pagesOut;
51
+ bool typedArrayOut;
52
+ bool hasAlphaOut;
48
53
  std::vector<Composite *> composite;
49
54
  std::vector<sharp::InputDescriptor *> joinChannelIn;
50
55
  int topOffsetPre;
@@ -98,8 +103,11 @@ struct PipelineBaton {
98
103
  bool trimLineArt;
99
104
  int trimOffsetLeft;
100
105
  int trimOffsetTop;
106
+ int trimMargin;
101
107
  std::vector<double> linearA;
102
108
  std::vector<double> linearB;
109
+ int dilateWidth;
110
+ int erodeWidth;
103
111
  double gamma;
104
112
  double gammaOut;
105
113
  bool greyscale;
@@ -109,11 +117,11 @@ struct PipelineBaton {
109
117
  int claheWidth;
110
118
  int claheHeight;
111
119
  int claheMaxSlope;
112
- bool useExifOrientation;
113
120
  int angle;
114
121
  double rotationAngle;
115
122
  std::vector<double> rotationBackground;
116
- bool rotateBeforePreExtract;
123
+ bool rotateBefore;
124
+ bool orientBefore;
117
125
  bool flip;
118
126
  bool flop;
119
127
  int extendTop;
@@ -157,19 +165,23 @@ struct PipelineBaton {
157
165
  bool webpNearLossless;
158
166
  bool webpLossless;
159
167
  bool webpSmartSubsample;
168
+ bool webpSmartDeblock;
160
169
  VipsForeignWebpPreset webpPreset;
161
170
  int webpEffort;
162
171
  bool webpMinSize;
163
172
  bool webpMixed;
173
+ bool webpExact;
164
174
  int gifBitdepth;
165
175
  int gifEffort;
166
176
  double gifDither;
167
177
  double gifInterFrameMaxError;
168
178
  double gifInterPaletteMaxError;
179
+ bool gifKeepDuplicateFrames;
169
180
  bool gifReuse;
170
181
  bool gifProgressive;
171
182
  int tiffQuality;
172
183
  VipsForeignTiffCompression tiffCompression;
184
+ bool tiffBigtiff;
173
185
  VipsForeignTiffPredictor tiffPredictor;
174
186
  bool tiffPyramid;
175
187
  int tiffBitdepth;
@@ -186,18 +198,23 @@ struct PipelineBaton {
186
198
  std::string heifChromaSubsampling;
187
199
  bool heifLossless;
188
200
  int heifBitdepth;
201
+ std::string heifTune;
189
202
  double jxlDistance;
190
203
  int jxlDecodingTier;
191
204
  int jxlEffort;
192
205
  bool jxlLossless;
193
206
  VipsBandFormat rawDepth;
194
207
  std::string err;
208
+ bool errUseWarning;
195
209
  int keepMetadata;
196
210
  int withMetadataOrientation;
197
211
  double withMetadataDensity;
198
212
  std::string withIccProfile;
199
213
  std::unordered_map<std::string, std::string> withExif;
200
214
  bool withExifMerge;
215
+ std::string withXmp;
216
+ bool withGainMap;
217
+ bool keepGainMap;
201
218
  int timeoutSeconds;
202
219
  std::vector<double> convKernel;
203
220
  int convKernelWidth;
@@ -232,6 +249,8 @@ struct PipelineBaton {
232
249
  bufferOutLength(0),
233
250
  pageHeightOut(0),
234
251
  pagesOut(0),
252
+ typedArrayOut(false),
253
+ hasAlphaOut(false),
235
254
  topOffsetPre(-1),
236
255
  topOffsetPost(-1),
237
256
  channels(0),
@@ -271,8 +290,11 @@ struct PipelineBaton {
271
290
  trimLineArt(false),
272
291
  trimOffsetLeft(0),
273
292
  trimOffsetTop(0),
293
+ trimMargin(0),
274
294
  linearA{},
275
295
  linearB{},
296
+ dilateWidth(0),
297
+ erodeWidth(0),
276
298
  gamma(0.0),
277
299
  greyscale(false),
278
300
  normalise(false),
@@ -281,7 +303,6 @@ struct PipelineBaton {
281
303
  claheWidth(0),
282
304
  claheHeight(0),
283
305
  claheMaxSlope(3),
284
- useExifOrientation(false),
285
306
  angle(0),
286
307
  rotationAngle(0.0),
287
308
  rotationBackground{ 0.0, 0.0, 0.0, 255.0 },
@@ -328,22 +349,26 @@ struct PipelineBaton {
328
349
  webpNearLossless(false),
329
350
  webpLossless(false),
330
351
  webpSmartSubsample(false),
352
+ webpSmartDeblock(false),
331
353
  webpPreset(VIPS_FOREIGN_WEBP_PRESET_DEFAULT),
332
354
  webpEffort(4),
333
355
  webpMinSize(false),
334
356
  webpMixed(false),
357
+ webpExact(false),
335
358
  gifBitdepth(8),
336
359
  gifEffort(7),
337
360
  gifDither(1.0),
338
361
  gifInterFrameMaxError(0.0),
339
362
  gifInterPaletteMaxError(3.0),
363
+ gifKeepDuplicateFrames(false),
340
364
  gifReuse(true),
341
365
  gifProgressive(false),
342
366
  tiffQuality(80),
343
367
  tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
368
+ tiffBigtiff(false),
344
369
  tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
345
370
  tiffPyramid(false),
346
- tiffBitdepth(8),
371
+ tiffBitdepth(0),
347
372
  tiffMiniswhite(false),
348
373
  tiffTile(false),
349
374
  tiffTileHeight(256),
@@ -357,15 +382,19 @@ struct PipelineBaton {
357
382
  heifChromaSubsampling("4:4:4"),
358
383
  heifLossless(false),
359
384
  heifBitdepth(8),
385
+ heifTune("auto"),
360
386
  jxlDistance(1.0),
361
387
  jxlDecodingTier(0),
362
388
  jxlEffort(7),
363
389
  jxlLossless(false),
364
390
  rawDepth(VIPS_FORMAT_UCHAR),
391
+ errUseWarning(false),
365
392
  keepMetadata(0),
366
393
  withMetadataOrientation(-1),
367
394
  withMetadataDensity(0.0),
368
395
  withExifMerge(true),
396
+ withGainMap(false),
397
+ keepGainMap(false),
369
398
  timeoutSeconds(0),
370
399
  convKernelWidth(0),
371
400
  convKernelHeight(0),
package/src/sharp.cc CHANGED
@@ -1,16 +1,18 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
- #include <mutex> // NOLINT(build/c++11)
6
+ #include <mutex>
5
7
 
6
8
  #include <napi.h>
7
9
  #include <vips/vips8>
8
10
 
9
- #include "common.h"
10
- #include "metadata.h"
11
- #include "pipeline.h"
12
- #include "utilities.h"
13
- #include "stats.h"
11
+ #include "./common.h"
12
+ #include "./metadata.h"
13
+ #include "./pipeline.h"
14
+ #include "./stats.h"
15
+ #include "./utilities.h"
14
16
 
15
17
  Napi::Object init(Napi::Env env, Napi::Object exports) {
16
18
  static std::once_flag sharp_vips_init_once;
@@ -33,6 +35,7 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
33
35
  exports.Set("block", Napi::Function::New(env, block));
34
36
  exports.Set("_maxColourDistance", Napi::Function::New(env, _maxColourDistance));
35
37
  exports.Set("_isUsingJemalloc", Napi::Function::New(env, _isUsingJemalloc));
38
+ exports.Set("_isUsingX64V2", Napi::Function::New(env, _isUsingX64V2));
36
39
  exports.Set("stats", Napi::Function::New(env, stats));
37
40
  return exports;
38
41
  }
package/src/stats.cc CHANGED
@@ -1,15 +1,18 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
6
+ #include <iostream>
4
7
  #include <numeric>
8
+ #include <string>
5
9
  #include <vector>
6
- #include <iostream>
7
10
 
8
11
  #include <napi.h>
9
12
  #include <vips/vips8>
10
13
 
11
- #include "common.h"
12
- #include "stats.h"
14
+ #include "./common.h"
15
+ #include "./stats.h"
13
16
 
14
17
  class StatsWorker : public Napi::AsyncWorker {
15
18
  public:
@@ -36,7 +39,7 @@ class StatsWorker : public Napi::AsyncWorker {
36
39
  sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
37
40
  try {
38
41
  std::tie(image, imageType) = OpenInput(baton->input);
39
- } catch (vips::VError const &err) {
42
+ } catch (std::runtime_error const &err) {
40
43
  (baton->err).append(err.what());
41
44
  }
42
45
  if (imageType != sharp::ImageType::UNKNOWN) {
@@ -58,9 +61,9 @@ class StatsWorker : public Napi::AsyncWorker {
58
61
  baton->channelStats.push_back(cStats);
59
62
  }
60
63
  // Image is not opaque when alpha layer is present and contains a non-mamixa value
61
- if (sharp::HasAlpha(image)) {
64
+ if (image.has_alpha()) {
62
65
  double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
63
- if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) {
66
+ if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) {
64
67
  baton->isOpaque = false;
65
68
  }
66
69
  }
@@ -89,7 +92,7 @@ class StatsWorker : public Napi::AsyncWorker {
89
92
  baton->dominantRed = dx * 16 + 8;
90
93
  baton->dominantGreen = dy * 16 + 8;
91
94
  baton->dominantBlue = dz * 16 + 8;
92
- } catch (vips::VError const &err) {
95
+ } catch (std::runtime_error const &err) {
93
96
  (baton->err).append(err.what());
94
97
  }
95
98
  }
@@ -106,10 +109,9 @@ class StatsWorker : public Napi::AsyncWorker {
106
109
  // Handle warnings
107
110
  std::string warning = sharp::VipsWarningPop();
108
111
  while (!warning.empty()) {
109
- debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
112
+ debuglog.SHARP_CALLBACK_FN_NAME(Receiver().Value(), { Napi::String::New(env, warning) });
110
113
  warning = sharp::VipsWarningPop();
111
114
  }
112
-
113
115
  if (baton->err.empty()) {
114
116
  // Stats Object
115
117
  Napi::Object info = Napi::Object::New(env);
@@ -141,9 +143,10 @@ class StatsWorker : public Napi::AsyncWorker {
141
143
  dominant.Set("g", baton->dominantGreen);
142
144
  dominant.Set("b", baton->dominantBlue);
143
145
  info.Set("dominant", dominant);
144
- Callback().Call(Receiver().Value(), { env.Null(), info });
146
+ Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), info });
145
147
  } else {
146
- Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
148
+ Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(),
149
+ { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
147
150
  }
148
151
 
149
152
  delete baton->input;
package/src/stats.h CHANGED
@@ -1,10 +1,13 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_STATS_H_
5
7
  #define SRC_STATS_H_
6
8
 
7
9
  #include <string>
10
+ #include <vector>
8
11
  #include <napi.h>
9
12
 
10
13
  #include "./common.h"
@@ -24,7 +27,7 @@ struct ChannelStats {
24
27
 
25
28
  ChannelStats(int minVal, int maxVal, double sumVal, double squaresSumVal,
26
29
  double meanVal, double stdevVal, int minXVal, int minYVal, int maxXVal, int maxYVal):
27
- min(minVal), max(maxVal), sum(sumVal), squaresSum(squaresSumVal),
30
+ min(minVal), max(maxVal), sum(sumVal), squaresSum(squaresSumVal), // NOLINT(build/include_what_you_use)
28
31
  mean(meanVal), stdev(stdevVal), minX(minXVal), minY(minYVal), maxX(maxXVal), maxY(maxYVal) {}
29
32
  };
30
33
 
package/src/utilities.cc CHANGED
@@ -1,17 +1,19 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #include <cmath>
5
- #include <string>
6
7
  #include <cstdio>
8
+ #include <string>
7
9
 
8
10
  #include <napi.h>
9
11
  #include <vips/vips8>
10
12
  #include <vips/vector.h>
11
13
 
12
- #include "common.h"
13
- #include "operations.h"
14
- #include "utilities.h"
14
+ #include "./common.h"
15
+ #include "./operations.h"
16
+ #include "./utilities.h"
15
17
 
16
18
  /*
17
19
  Get and set cache limits
@@ -21,15 +23,15 @@ Napi::Value cache(const Napi::CallbackInfo& info) {
21
23
 
22
24
  // Set memory limit
23
25
  if (info[size_t(0)].IsNumber()) {
24
- vips_cache_set_max_mem(info[size_t(0)].As<Napi::Number>().Int32Value() * 1048576);
26
+ vips_cache_set_max_mem(static_cast<size_t>(info[size_t(0)].As<Napi::Number>().Uint32Value()) * 1048576);
25
27
  }
26
28
  // Set file limit
27
29
  if (info[size_t(1)].IsNumber()) {
28
- vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Int32Value());
30
+ vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Uint32Value());
29
31
  }
30
32
  // Set items limit
31
33
  if (info[size_t(2)].IsNumber()) {
32
- vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Int32Value());
34
+ vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Uint32Value());
33
35
  }
34
36
 
35
37
  // Get memory stats
@@ -119,8 +121,9 @@ Napi::Value format(const Napi::CallbackInfo& info) {
119
121
  Napi::Object format = Napi::Object::New(env);
120
122
  for (std::string const f : {
121
123
  "jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
122
- "ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl"
124
+ "ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad", "dcraw"
123
125
  }) {
126
+ std::string id = f == "jp2k" ? "jp2" : f;
124
127
  // Input
125
128
  const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());
126
129
  Napi::Boolean hasInputFile = Napi::Boolean::New(env, oc);
@@ -152,11 +155,11 @@ Napi::Value format(const Napi::CallbackInfo& info) {
152
155
  output.Set("stream", hasOutputBuffer);
153
156
  // Other attributes
154
157
  Napi::Object container = Napi::Object::New(env);
155
- container.Set("id", f);
158
+ container.Set("id", id);
156
159
  container.Set("input", input);
157
160
  container.Set("output", output);
158
161
  // Add to set of formats
159
- format.Set(f, container);
162
+ format.Set(id, container);
160
163
  }
161
164
 
162
165
  // Raw, uncompressed data
@@ -233,15 +236,15 @@ Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {
233
236
  double maxColourDistance;
234
237
  try {
235
238
  // Premultiply and remove alpha
236
- if (sharp::HasAlpha(image1)) {
239
+ if (image1.has_alpha()) {
237
240
  image1 = image1.premultiply().extract_band(1, VImage::option()->set("n", image1.bands() - 1));
238
241
  }
239
- if (sharp::HasAlpha(image2)) {
242
+ if (image2.has_alpha()) {
240
243
  image2 = image2.premultiply().extract_band(1, VImage::option()->set("n", image2.bands() - 1));
241
244
  }
242
245
  // Calculate colour distance
243
246
  maxColourDistance = image1.dE00(image2).max();
244
- } catch (vips::VError const &err) {
247
+ } catch (std::runtime_error const &err) {
245
248
  throw Napi::Error::New(env, err.what());
246
249
  }
247
250
 
@@ -267,3 +270,20 @@ Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {
267
270
  return Napi::Boolean::New(env, false);
268
271
  }
269
272
  #endif
273
+
274
+ #if defined(__GNUC__) && defined(__x86_64__)
275
+ // Are SSE 4.2 intrinsics available at runtime?
276
+ Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {
277
+ Napi::Env env = info.Env();
278
+ unsigned int eax, ebx, ecx, edx;
279
+ __asm__ __volatile__("cpuid"
280
+ : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
281
+ : "a"(1));
282
+ return Napi::Boolean::New(env, (ecx & 1U << 20) != 0);
283
+ }
284
+ #else
285
+ Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {
286
+ Napi::Env env = info.Env();
287
+ return Napi::Boolean::New(env, false);
288
+ }
289
+ #endif
package/src/utilities.h CHANGED
@@ -1,5 +1,7 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_UTILITIES_H_
5
7
  #define SRC_UTILITIES_H_
@@ -15,5 +17,6 @@ Napi::Value format(const Napi::CallbackInfo& info);
15
17
  void block(const Napi::CallbackInfo& info);
16
18
  Napi::Value _maxColourDistance(const Napi::CallbackInfo& info);
17
19
  Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info);
20
+ Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info);
18
21
 
19
22
  #endif // SRC_UTILITIES_H_
package/install/check.js DELETED
@@ -1,41 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
6
- try {
7
- const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
8
-
9
- const buildFromSource = (msg) => {
10
- log(msg);
11
- log('Attempting to build from source via node-gyp');
12
- try {
13
- const addonApi = require('node-addon-api');
14
- log(`Found node-addon-api ${addonApi.version || ''}`);
15
- } catch (err) {
16
- log('Please add node-addon-api to your dependencies');
17
- return;
18
- }
19
- try {
20
- const gyp = require('node-gyp');
21
- log(`Found node-gyp ${gyp().version}`);
22
- } catch (err) {
23
- log('Please add node-gyp to your dependencies');
24
- return;
25
- }
26
- log('See https://sharp.pixelplumbing.com/install#building-from-source');
27
- const status = spawnRebuild();
28
- if (status !== 0) {
29
- process.exit(status);
30
- }
31
- };
32
-
33
- if (useGlobalLibvips(log)) {
34
- buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
35
- } else if (process.env.npm_config_build_from_source) {
36
- buildFromSource('Detected --build-from-source flag');
37
- }
38
- } catch (err) {
39
- const summary = err.message.split(/\n/).slice(0, 1);
40
- console.log(`sharp: skipping install check: ${summary}`);
41
- }
package/lib/index.js DELETED
@@ -1,16 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
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,114 +0,0 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- 'use strict';
5
-
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
- }
31
-
32
- /* istanbul ignore next */
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}`);
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
- '- Ensure your package manager supports multi-platform installation:',
61
- ' See https://sharp.pixelplumbing.com/install#cross-platform',
62
- '- Add platform-specific dependencies:',
63
- ` npm install --os=${os.replace('musl', '')}${libc} --cpu=${cpu} sharp`
64
- );
65
- } else {
66
- help.push(
67
- `- Manually install libvips >= ${minimumLibvipsVersion}`,
68
- '- Add experimental WebAssembly-based dependencies:',
69
- ' npm install --cpu=wasm32 sharp',
70
- ' npm install @img/sharp-wasm32'
71
- );
72
- }
73
- if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
74
- try {
75
- const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
76
- const libcFound = `${familySync()} ${versionSync()}`;
77
- const libcRequires = `${config.musl ? 'musl' : 'glibc'} ${config.musl || config.glibc}`;
78
- help.push(
79
- '- Update your OS:',
80
- ` Found ${libcFound}`,
81
- ` Requires ${libcRequires}`
82
- );
83
- } catch (errEngines) {}
84
- }
85
- if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
86
- help.push(
87
- '- Remove the Node.js Snap, which does not support native modules',
88
- ' snap remove node'
89
- );
90
- }
91
- if (isMacOs && /Incompatible library version/.test(messages)) {
92
- help.push(
93
- '- Update Homebrew:',
94
- ' brew update && brew upgrade vips'
95
- );
96
- }
97
- if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
98
- help.push('- Run Node.js without using the --no-addons flag');
99
- }
100
- // Link to installation docs
101
- if (isWindows && /The specified procedure could not be found/.test(messages)) {
102
- help.push(
103
- '- Using the canvas package on Windows?',
104
- ' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
105
- '- Check for outdated versions of sharp in the dependency tree:',
106
- ' npm ls sharp'
107
- );
108
- }
109
- help.push(
110
- '- Consult the installation documentation:',
111
- ' See https://sharp.pixelplumbing.com/install'
112
- );
113
- throw new Error(help.join('\n'));
114
- }