@divriots/jampack 0.6.2 → 0.7.1

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
@@ -11,6 +11,7 @@ import kleur from 'kleur';
11
11
  import ora from 'ora';
12
12
  import { isLocal, Resource, translateSrc } from './utils/resource.js';
13
13
  async function analyse(file) {
14
+ var _a;
14
15
  console.log('▶ ' + file);
15
16
  const html = (await fs.readFile(path.join($state.dir, file))).toString();
16
17
  const $ = cheerio.load(html, {
@@ -46,6 +47,15 @@ async function analyse(file) {
46
47
  if (theFold) {
47
48
  $('the-fold').remove();
48
49
  }
50
+ // Add CSS to head
51
+ const CSS = `<style>:where(img){height:auto;}</style>`;
52
+ const heads = $('head');
53
+ if (heads.length > 0) {
54
+ heads.prepend(CSS);
55
+ }
56
+ else {
57
+ (_a = $('html')) === null || _a === void 0 ? void 0 : _a.prepend(`<head>${CSS}</head>`);
58
+ }
49
59
  if (!$state.args.nowrite) {
50
60
  await fs.writeFile(path.join($state.dir, file), $.html());
51
61
  }
@@ -312,7 +322,7 @@ async function setImageSize(htmlfile, img, image) {
312
322
  if (!isNumeric(width)) {
313
323
  $state.reportIssue(htmlfile, {
314
324
  type: 'warn',
315
- msg: `Invalid width attribute format: "${width}" - overriding`,
325
+ msg: `Invalid width attribute format: "${width}" - overriding for ${image.src}`,
316
326
  });
317
327
  width = undefined;
318
328
  }
@@ -321,7 +331,7 @@ async function setImageSize(htmlfile, img, image) {
321
331
  if (!isNumeric(height)) {
322
332
  $state.reportIssue(htmlfile, {
323
333
  type: 'warn',
324
- msg: `Invalid height attribute format: "${height}" - overriding`,
334
+ msg: `Invalid height attribute format: "${height}" - overriding for ${image.src}`,
325
335
  });
326
336
  height = undefined;
327
337
  }
@@ -339,15 +349,6 @@ async function setImageSize(htmlfile, img, image) {
339
349
  // Both are provided
340
350
  const w = parseInt(width, 10);
341
351
  const h = parseInt(height, 10);
342
- // Is ratio equal?
343
- const providedRatio = Math.round((w / h) * 10) / 10;
344
- const imageRatio = Math.round(originalRatio * 10) / 10;
345
- if (providedRatio !== imageRatio) {
346
- $state.reportIssue(htmlfile, {
347
- type: 'warn',
348
- msg: `Image aspect ratio in HTML (${providedRatio}) differs from image aspect ratio (${imageRatio}) - fix width and height or let jampack fill them.`,
349
- });
350
- }
351
352
  return [w, h];
352
353
  }
353
354
  else if (width !== undefined && height === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.6.2",
3
+ "version": "0.7.1",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- export declare function compressJS(originalCode: string): Promise<string>;
@@ -1,8 +0,0 @@
1
- import swc from '@swc/core';
2
- export async function compressJS(originalCode) {
3
- const newjsresult = await swc.minify(originalCode, {
4
- compress: true,
5
- mangle: true,
6
- });
7
- return newjsresult.code;
8
- }
package/dist/types.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- export type ImageFormat = 'webp' | 'svg' | 'jpg' | 'png' | 'avif' | undefined;
3
- export type Image = {
4
- format: ImageFormat;
5
- data: Buffer;
6
- };
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};