@divriots/jampack 0.7.0 → 0.7.2

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/dist/index.js CHANGED
@@ -62,7 +62,7 @@ program
62
62
  }
63
63
  printSummary();
64
64
  printIssues();
65
- if (options.failOnIssues && $state.issues.size > 0) {
65
+ if (options.fail && $state.issues.size > 0) {
66
66
  exit(1);
67
67
  }
68
68
  });
package/dist/optimize.js CHANGED
@@ -273,27 +273,33 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
273
273
  while (valueW > config.image.srcset_min_width) {
274
274
  const src = imageSrc(`@${valueW}w`);
275
275
  const absoluteFilename = translateSrc($state.dir, path.dirname(htmlfile), src);
276
+ let doAddToSrcSet = true;
276
277
  // Don't generate srcset file twice
277
278
  if (!$state.compressedFiles.has(absoluteFilename)) {
278
- // Add file to list avoid recompression
279
- $state.compressedFiles.add(absoluteFilename);
280
279
  const compressedImage = await compressImage(await originalImage.getData(), {
281
280
  resize: { width: valueW, height: valueH },
282
281
  toFormat: canBeProgressiveJpeg ? 'pjpg' : targetFormat,
283
282
  });
284
283
  if (!(compressedImage === null || compressedImage === void 0 ? void 0 : compressedImage.data) ||
285
284
  compressedImage.data.length >= previousImageSize) {
286
- // jampack was not able to compress below the original image
287
- // Let's move on
288
- continue;
285
+ // New image is not compressed or bigger than previous image in srcset
286
+ // Don't add to srcset
287
+ doAddToSrcSet = false;
289
288
  }
290
- if (!$state.args.nowrite) {
291
- fs.writeFile(absoluteFilename, compressedImage.data);
289
+ else {
290
+ // Write file
291
+ if (!$state.args.nowrite) {
292
+ fs.writeFile(absoluteFilename, compressedImage.data);
293
+ }
294
+ // Set new previous size to beat
295
+ previousImageSize = compressedImage.data.length;
296
+ // Add file to list avoid recompression
297
+ $state.compressedFiles.add(absoluteFilename);
292
298
  }
293
- // Add previous smaller file size
294
- previousImageSize = compressedImage.data.length;
295
299
  }
296
- new_srcset += `, ${src} ${valueW}w`;
300
+ if (doAddToSrcSet) {
301
+ new_srcset += `, ${src} ${valueW}w`;
302
+ }
297
303
  // reduce size
298
304
  valueW -= step;
299
305
  valueH = Math.trunc(valueW / ratio);
@@ -322,7 +328,7 @@ async function setImageSize(htmlfile, img, image) {
322
328
  if (!isNumeric(width)) {
323
329
  $state.reportIssue(htmlfile, {
324
330
  type: 'warn',
325
- msg: `Invalid width attribute format: "${width}" - overriding`,
331
+ msg: `Invalid width attribute format: "${width}" - overriding for ${image.src}`,
326
332
  });
327
333
  width = undefined;
328
334
  }
@@ -331,7 +337,7 @@ async function setImageSize(htmlfile, img, image) {
331
337
  if (!isNumeric(height)) {
332
338
  $state.reportIssue(htmlfile, {
333
339
  type: 'warn',
334
- msg: `Invalid height attribute format: "${height}" - overriding`,
340
+ msg: `Invalid height attribute format: "${height}" - overriding for ${image.src}`,
335
341
  });
336
342
  height = undefined;
337
343
  }
@@ -349,15 +355,6 @@ async function setImageSize(htmlfile, img, image) {
349
355
  // Both are provided
350
356
  const w = parseInt(width, 10);
351
357
  const h = parseInt(height, 10);
352
- // Is ratio equal?
353
- const providedRatio = Math.round((w / h) * 10) / 10;
354
- const imageRatio = Math.round(originalRatio * 10) / 10;
355
- if (providedRatio !== imageRatio) {
356
- $state.reportIssue(htmlfile, {
357
- type: 'warn',
358
- msg: `Image aspect ratio in HTML (${providedRatio}) differs from image aspect ratio (${imageRatio}) - fix width and height or let jampack fill them.`,
359
- });
360
- }
361
358
  return [w, h];
362
359
  }
363
360
  else if (width !== undefined && height === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {