@divriots/jampack 0.12.0 → 0.12.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/config-types.d.ts +1 -1
- package/dist/index.js +0 -10
- package/dist/optimize.js +2 -1
- package/dist/optimizers/img-external.d.ts +2 -1
- package/dist/optimizers/img-external.js +10 -4
- package/dist/utils/polyfill-fetch.d.ts +1 -0
- package/dist/utils/polyfill-fetch.js +4 -0
- package/package.json +4 -3
package/dist/config-types.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type Options = {
|
|
|
11
11
|
embed_size: number;
|
|
12
12
|
srcset_min_width: number;
|
|
13
13
|
external: {
|
|
14
|
-
process: 'download' | 'cdn-srcset-when-possible' | 'add-dimensions-only'
|
|
14
|
+
process: 'off' | 'download' | 'cdn-srcset-when-possible' | 'add-dimensions-only';
|
|
15
15
|
src_include: RegExp;
|
|
16
16
|
src_exclude: RegExp | null;
|
|
17
17
|
};
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,6 @@ import { exit } from 'process';
|
|
|
11
11
|
import kleur from 'kleur';
|
|
12
12
|
import { cleanCache } from './cache.js';
|
|
13
13
|
import { VERSION } from './version.js';
|
|
14
|
-
import { mkdirSync } from 'fs';
|
|
15
|
-
import { join } from 'path';
|
|
16
14
|
const logo = ` __ __
|
|
17
15
|
|__|____ _____ ___________ ____ | | __
|
|
18
16
|
| \\__ \\ / \\\\____ \\__ \\ _/ ___\\| |/ /
|
|
@@ -56,14 +54,6 @@ program
|
|
|
56
54
|
}
|
|
57
55
|
// Clean cache
|
|
58
56
|
cleanCache(options.cleancache);
|
|
59
|
-
// Create _jampack folder
|
|
60
|
-
try {
|
|
61
|
-
mkdirSync(join($state.dir, '_jampack'));
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
console.error(e.message);
|
|
65
|
-
exit(1);
|
|
66
|
-
}
|
|
67
57
|
if (!options.onlycomp) {
|
|
68
58
|
printTitle('PASS 1 - Optimizing');
|
|
69
59
|
console.time('Done');
|
package/dist/optimize.js
CHANGED
|
@@ -194,7 +194,8 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
|
|
|
194
194
|
return;
|
|
195
195
|
case 'download': // Download external image for local processing
|
|
196
196
|
try {
|
|
197
|
-
|
|
197
|
+
const htmlFolder = path.dirname(path.resolve(path.join($state.dir, htmlfile)));
|
|
198
|
+
attrib_src = await downloadExternalImage(attrib_src, htmlFolder);
|
|
198
199
|
img.attr('src', attrib_src);
|
|
199
200
|
}
|
|
200
201
|
catch (e) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import '../utils/polyfill-fetch.js';
|
|
2
|
+
export declare function downloadExternalImage(href: string, dir: string): Promise<string>;
|
|
@@ -4,8 +4,8 @@ import hasha from 'hasha';
|
|
|
4
4
|
import { fileTypeFromBuffer } from 'file-type';
|
|
5
5
|
import { addToCache, getFromCache } from '../cache.js';
|
|
6
6
|
import { parse } from '../utils/cache-control-parser.js';
|
|
7
|
-
import
|
|
8
|
-
export async function downloadExternalImage(href) {
|
|
7
|
+
import '../utils/polyfill-fetch.js';
|
|
8
|
+
export async function downloadExternalImage(href, dir) {
|
|
9
9
|
var _a, _b, _c, _d, _e;
|
|
10
10
|
const hash = hasha(href, {
|
|
11
11
|
algorithm: 'md5',
|
|
@@ -93,7 +93,13 @@ export async function downloadExternalImage(href) {
|
|
|
93
93
|
// Construct local filename
|
|
94
94
|
if (!ext)
|
|
95
95
|
throw new Error('Unknown image format');
|
|
96
|
-
const filename =
|
|
97
|
-
|
|
96
|
+
const filename = `./_jampack/${hash}.${ext}`;
|
|
97
|
+
try {
|
|
98
|
+
await fs.mkdir(path.join(dir, '_jampack'));
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
// Nothing to do - folder is probably already present
|
|
102
|
+
}
|
|
103
|
+
fs.writeFile(path.join(dir, filename), buffer);
|
|
98
104
|
return filename;
|
|
99
105
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divriots/jampack",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Packer for static websites",
|
|
5
5
|
"author": "Georges Gomes @georges-gomes",
|
|
6
6
|
"bin": {
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"ora": "^6.3.0",
|
|
32
32
|
"sharp": "^0.32.1",
|
|
33
33
|
"svgo": "^3.0.2",
|
|
34
|
-
"table": "^6.8.1"
|
|
34
|
+
"table": "^6.8.1",
|
|
35
|
+
"undici": "^5.22.1"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/html-minifier-terser": "^7.0.0",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"prepublishOnly": "pnpm build"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
53
|
+
"node": ">=14.0.0"
|
|
53
54
|
},
|
|
54
55
|
"bugs": "https://github.com/divriots/jampack/issues",
|
|
55
56
|
"keywords": [],
|