@divriots/jampack 0.24.2 → 0.24.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.
@@ -24,7 +24,7 @@ const default_options = {
24
24
  },
25
25
  cdn: {
26
26
  process: 'off',
27
- src_include: /^.*$/,
27
+ src_include: null,
28
28
  src_exclude: null,
29
29
  },
30
30
  compress: true,
@@ -31,7 +31,7 @@ export type Options = {
31
31
  };
32
32
  cdn: {
33
33
  process: 'off' | 'optimize';
34
- src_include: RegExp;
34
+ src_include: RegExp | null;
35
35
  src_exclude: RegExp | null;
36
36
  transformer?: UrlTransformer;
37
37
  };
package/dist/optimize.js CHANGED
@@ -270,48 +270,51 @@ async function processImage(htmlfile, img, isAboveTheFold) {
270
270
  /*
271
271
  * Check for external images
272
272
  */
273
- if (!isLocal(attrib_src)) {
274
- switch (config.image.cdn.process) {
275
- case 'off':
276
- break;
277
- case 'optimize':
278
- let cdnTransformer = config.image.cdn.transformer;
279
- if (!cdnTransformer) {
280
- const canonical = getCanonicalCdnForUrl(attrib_src);
281
- if (!canonical)
282
- break;
283
- cdnTransformer = getTransformer(canonical.cdn);
284
- }
285
- if (!cdnTransformer)
286
- break;
287
- if (!isIncluded(attrib_src, config.image.cdn.src_include, config.image.cdn.src_exclude))
273
+ switch (config.image.cdn.process) {
274
+ case 'off':
275
+ break;
276
+ case 'optimize':
277
+ let cdnTransformer = config.image.cdn.transformer;
278
+ if (cdnTransformer && !config.image.cdn.src_include) {
279
+ throw new Error('config.image.cdn.src_include is required when specifying a config.image.cdn.transformer');
280
+ }
281
+ if (!cdnTransformer) {
282
+ const canonical = getCanonicalCdnForUrl(attrib_src);
283
+ if (!canonical)
288
284
  break;
289
- let attrib_width = getIntAttr(img, 'width');
290
- if (!attrib_width) {
291
- $state.reportIssue(htmlfile, {
292
- type: 'warn',
293
- msg: `Missing or malformed'width' attribute for image ${attrib_src}, unable to perform CDN transform`,
294
- });
295
- return;
296
- }
297
- let attrib_height = getIntAttr(img, 'height');
298
- if (!attrib_height) {
299
- $state.reportIssue(htmlfile, {
300
- type: 'warn',
301
- msg: `Missing or malformed 'height' attribute for image ${attrib_src}, unable to perform CDN transform`,
302
- });
303
- return;
304
- }
305
- const new_srcset = await generateSrcSetForCdn(attrib_src, cdnTransformer, attrib_width, attrib_height);
306
- if (new_srcset !== null) {
307
- img.attr('srcset', new_srcset);
308
- }
309
- // Add sizes attribute if not specified
310
- if (img.attr('srcset') && !img.attr('sizes')) {
311
- img.attr('sizes', '100vw');
312
- }
285
+ cdnTransformer = getTransformer(canonical.cdn);
286
+ }
287
+ if (!cdnTransformer)
288
+ break;
289
+ if (!isIncluded(attrib_src, config.image.cdn.src_include || /.*/, config.image.cdn.src_exclude))
290
+ break;
291
+ let attrib_width = getIntAttr(img, 'width');
292
+ if (!attrib_width) {
293
+ $state.reportIssue(htmlfile, {
294
+ type: 'warn',
295
+ msg: `Missing or malformed'width' attribute for image ${attrib_src}, unable to perform CDN transform`,
296
+ });
313
297
  return;
314
- }
298
+ }
299
+ let attrib_height = getIntAttr(img, 'height');
300
+ if (!attrib_height) {
301
+ $state.reportIssue(htmlfile, {
302
+ type: 'warn',
303
+ msg: `Missing or malformed 'height' attribute for image ${attrib_src}, unable to perform CDN transform`,
304
+ });
305
+ return;
306
+ }
307
+ const new_srcset = await generateSrcSetForCdn(attrib_src, cdnTransformer, attrib_width, attrib_height);
308
+ if (new_srcset !== null) {
309
+ img.attr('srcset', new_srcset);
310
+ }
311
+ // Add sizes attribute if not specified
312
+ if (img.attr('srcset') && !img.attr('sizes')) {
313
+ img.attr('sizes', '100vw');
314
+ }
315
+ return;
316
+ }
317
+ if (!isLocal(attrib_src)) {
315
318
  switch (config.image.external.process) {
316
319
  case 'off': // Don't process external images
317
320
  return;
@@ -115,8 +115,6 @@ export class Resource {
115
115
  }
116
116
  }
117
117
  export function isLocal(src) {
118
- if (src.startsWith('/cdn_cgi/'))
119
- return false;
120
118
  const u = url.parse(src);
121
119
  return !u.host;
122
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.24.2",
3
+ "version": "0.24.3",
4
4
  "cache-version": {
5
5
  "img": "v1",
6
6
  "img-ext": "v1"