@divriots/jampack 0.9.3 → 0.9.4

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/optimize.js CHANGED
@@ -227,47 +227,39 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
227
227
  ? 'unchanged'
228
228
  : 'webp';
229
229
  }
230
- if (!$state.optimizedFiles.has(originalImage.filePathAbsolute)) {
231
- // Let's avoid to optimize same images twice
232
- $state.optimizedFiles.add(originalImage.filePathAbsolute);
233
- newImage = await compressImage(await originalImage.getData(), {
234
- toFormat: srcToFormat,
235
- });
236
- if ((newImage === null || newImage === void 0 ? void 0 : newImage.data) &&
237
- (newImage.data.length < (await originalImage.getLen()) ||
238
- srcToFormat === 'jpeg+progressive') // Progressive override all even if worse
239
- ) {
240
- // Do we need to add an new extension?
241
- const newExtension = `.${newImage.format}`;
242
- const additionalExtension = path.extname(originalImage.filePathAbsolute) === newExtension
243
- ? ''
244
- : newExtension;
245
- const newFilename = originalImage.filePathAbsolute + additionalExtension;
246
- if (!$state.args.nowrite) {
247
- fs.writeFile(newFilename, newImage.data);
248
- }
249
- // Mark new file as optimized
250
- $state.compressedFiles.add(newFilename);
251
- // Report compression result
252
- $state.reportSummary({
253
- action: newFilename !== originalImage.filePathAbsolute
254
- ? `${await originalImage.getExt()}->${newImage.format}`
255
- : path.extname(originalImage.filePathAbsolute),
256
- originalSize: await originalImage.getLen(),
257
- compressedSize: newImage.data.length,
258
- });
259
- img.attr('src', attrib_src + additionalExtension);
260
- }
261
- else {
262
- // Drop new Image
263
- newImage = undefined;
264
- // Report non-compression
265
- $state.reportSummary({
266
- action: path.extname(originalImage.filePathAbsolute),
267
- originalSize: await originalImage.getLen(),
268
- compressedSize: await originalImage.getLen(),
269
- });
230
+ newImage = await compressImage(await originalImage.getData(), {
231
+ toFormat: srcToFormat,
232
+ });
233
+ if ((newImage === null || newImage === void 0 ? void 0 : newImage.data) &&
234
+ (newImage.data.length < (await originalImage.getLen()) ||
235
+ srcToFormat === 'jpeg+progressive') // Progressive override all even if worse
236
+ ) {
237
+ const additionalExtension = `.${newImage.format}`;
238
+ const newFilename = originalImage.filePathAbsolute + additionalExtension;
239
+ if (!$state.compressedFiles.has(newFilename) && !$state.args.nowrite) {
240
+ fs.writeFile(newFilename, newImage.data);
270
241
  }
242
+ // Mark new file as compressed
243
+ $state.compressedFiles.add(newFilename);
244
+ // Report compression result
245
+ $state.reportSummary({
246
+ action: newFilename !== originalImage.filePathAbsolute
247
+ ? `${await originalImage.getExt()}->${newImage.format}`
248
+ : path.extname(originalImage.filePathAbsolute),
249
+ originalSize: await originalImage.getLen(),
250
+ compressedSize: newImage.data.length,
251
+ });
252
+ img.attr('src', attrib_src + additionalExtension);
253
+ }
254
+ else {
255
+ // Drop new Image
256
+ newImage = undefined;
257
+ // Report non-compression
258
+ $state.reportSummary({
259
+ action: path.extname(originalImage.filePathAbsolute),
260
+ originalSize: await originalImage.getLen(),
261
+ compressedSize: await originalImage.getLen(),
262
+ });
271
263
  }
272
264
  /*
273
265
  * Embed small images
package/dist/state.d.ts CHANGED
@@ -21,7 +21,6 @@ export declare class GlobalState {
21
21
  dir: string;
22
22
  args: Args;
23
23
  compressedFiles: Set<string>;
24
- optimizedFiles: Set<string>;
25
24
  issues: Map<string, Issue[]>;
26
25
  summary: Summary;
27
26
  summaryByExtension: Record<string, Summary>;
package/dist/state.js CHANGED
@@ -3,7 +3,6 @@ export class GlobalState {
3
3
  this.dir = 'dist';
4
4
  this.args = {};
5
5
  this.compressedFiles = new Set();
6
- this.optimizedFiles = new Set();
7
6
  this.issues = new Map();
8
7
  this.summary = {
9
8
  nbFiles: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {
@@ -18,13 +18,10 @@
18
18
  "dependencies": {
19
19
  "@swc/core": "^1.3.30",
20
20
  "@types/cheerio": "^0.22.31",
21
- "@types/commander": "^2.12.2",
22
21
  "@types/csso": "^5.0.0",
23
22
  "@types/html-minifier-terser": "^7.0.0",
24
- "@types/ora": "^3.2.0",
25
23
  "@types/sharp": "^0.31.1",
26
24
  "@types/svgo": "^2.6.4",
27
- "@types/table": "^6.3.2",
28
25
  "cheerio": "0.22.0",
29
26
  "commander": "^9.4.1",
30
27
  "csso": "^5.0.5",
@@ -49,7 +46,7 @@
49
46
  },
50
47
  "scripts": {
51
48
  "watch": "pnpm build --watch",
52
- "try": "shx rm -fr demo && cp -R demo_wcd demo && node ./dist/index.js ./demo --nocache --onlyoptim",
49
+ "try": "shx rm -fr demo && cp -R demo_rf demo && node ./dist/index.js ./demo --nocache --onlyoptim",
53
50
  "build": "shx rm -rf dist && tsc -b",
54
51
  "lint": "eslint . --ext .ts --config .eslintrc"
55
52
  },