@divriots/jampack 0.2.2 → 0.2.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.
- package/dist/compressors/image.d.ts +1 -0
- package/dist/compressors/image.js +1 -0
- package/dist/index.js +8 -7
- package/dist/logger.js +1 -1
- package/dist/optimize.js +11 -10
- package/dist/optimizers/img.d.ts +1 -0
- package/dist/optimizers/img.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -45,14 +45,17 @@ program.command('pack', { isDefault: true })
|
|
|
45
45
|
await optimize(options.exclude);
|
|
46
46
|
console.timeEnd('Done');
|
|
47
47
|
}
|
|
48
|
-
if (!options.onlyoptim) {
|
|
48
|
+
if (!options.onlyoptim && !options.fast) {
|
|
49
49
|
printTitle('PASS 2 - Compressing the rest');
|
|
50
50
|
console.time('Done');
|
|
51
51
|
await compress(options.exclude);
|
|
52
52
|
console.timeEnd('Done');
|
|
53
53
|
}
|
|
54
54
|
printSummary();
|
|
55
|
-
|
|
55
|
+
printIssues();
|
|
56
|
+
if (options.failOnIssues && $state.issues.size > 0) {
|
|
57
|
+
exit(1);
|
|
58
|
+
}
|
|
56
59
|
});
|
|
57
60
|
program.parse();
|
|
58
61
|
function printSummary() {
|
|
@@ -82,7 +85,7 @@ function printSummary() {
|
|
|
82
85
|
console.log(table(dataTable, config));
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
|
-
function
|
|
88
|
+
function printIssues() {
|
|
86
89
|
let issueCount = 0;
|
|
87
90
|
if ($state.issues.size === 0) {
|
|
88
91
|
printTitle('✔ No issues');
|
|
@@ -94,12 +97,10 @@ function printWarningsAndErrors(options) {
|
|
|
94
97
|
console.log(kleur.red('▶ ' + file + '\n'));
|
|
95
98
|
list.forEach(issue => {
|
|
96
99
|
issueCount++;
|
|
97
|
-
console.log(
|
|
100
|
+
console.log(`❌ ${issue.msg}\n`);
|
|
98
101
|
});
|
|
99
102
|
}
|
|
103
|
+
console.log('');
|
|
100
104
|
printTitle(`${issueCount} issue(s) over ${$state.issues.size} files`, kleur.bgRed);
|
|
101
|
-
if (options.failOnIssues) {
|
|
102
|
-
exit(1);
|
|
103
|
-
}
|
|
104
105
|
}
|
|
105
106
|
}
|
package/dist/logger.js
CHANGED
package/dist/optimize.js
CHANGED
|
@@ -57,7 +57,7 @@ async function processImage(htmlfile, $, imgElement) {
|
|
|
57
57
|
*/
|
|
58
58
|
const attrib_alt = img.attr('alt');
|
|
59
59
|
if (attrib_alt === undefined) {
|
|
60
|
-
$state.reportIssue(htmlfile, { msg: `Missing [alt] on img src="${attrib_src}" -
|
|
60
|
+
$state.reportIssue(htmlfile, { msg: `Missing [alt] on img src="${attrib_src}" - Adding alt="" meanwhile.` });
|
|
61
61
|
img.attr('alt', "");
|
|
62
62
|
}
|
|
63
63
|
if (attrib_src.startsWith('data:')) {
|
|
@@ -103,9 +103,10 @@ async function processImage(htmlfile, $, imgElement) {
|
|
|
103
103
|
$state.reportIssue(htmlfile, { msg: `Can't find img src="${attrib_src}" in ${absoluteImgPath}` });
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
+
// Read file
|
|
107
|
+
const originalData = await fs.readFile(absoluteImgPath);
|
|
106
108
|
const sharpFile = sharp(absoluteImgPath);
|
|
107
109
|
const meta = await sharpFile.metadata();
|
|
108
|
-
const originalData = await fs.readFile(absoluteImgPath);
|
|
109
110
|
/*
|
|
110
111
|
* Compress image to WebP
|
|
111
112
|
*/
|
|
@@ -162,6 +163,14 @@ async function processImage(htmlfile, $, imgElement) {
|
|
|
162
163
|
$state.reportSummary({ action: `${newImage.format}->embed`, originalSize: originalData.length, compressedSize: newImage.data.length });
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
/*
|
|
167
|
+
* Attribute 'width' & 'height'
|
|
168
|
+
*/
|
|
169
|
+
const [w, h] = setImageSize(img, meta);
|
|
170
|
+
if (w < 0 || h < 0) {
|
|
171
|
+
$state.reportIssue(htmlfile, { msg: `Unexpected error in image size calculation src="${attrib_src}" - can't performance some optmizations.` });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
165
174
|
if (isEmbed) {
|
|
166
175
|
// Image is embed, no need for more processing
|
|
167
176
|
return;
|
|
@@ -171,14 +180,6 @@ async function processImage(htmlfile, $, imgElement) {
|
|
|
171
180
|
//
|
|
172
181
|
if (meta.format === 'svg')
|
|
173
182
|
return;
|
|
174
|
-
/*
|
|
175
|
-
* Attribute 'width' & 'height'
|
|
176
|
-
*/
|
|
177
|
-
const [w, h] = setImageSize(img, meta);
|
|
178
|
-
if (w < 0 || h < 0) {
|
|
179
|
-
$state.reportIssue(htmlfile, { msg: `Unexpected error in image size calculation src="${attrib_src}" - can't performance some optmizations.` });
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
183
|
/*
|
|
183
184
|
* Attribute 'srcset'
|
|
184
185
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|