@mapbox/appropriate-images
Advanced tools
Comparing version 4.1.0-beta.4 to 4.1.0-beta.5
@@ -18,3 +18,3 @@ 'use strict'; | ||
*/ | ||
function writeOptimizedImages(imageData) { | ||
async function writeOptimizedImages(imageData) { | ||
return Promise.all( | ||
@@ -41,24 +41,36 @@ imageData.map((item) => | ||
*/ | ||
module.exports = (imageFilenames, options) => { | ||
module.exports = async (imageFilenames, options) => { | ||
// These are two separate processes because otherwise the webp plugin | ||
// overrides the others, somehow. | ||
let filenameArrays = []; | ||
try { | ||
const regularOptimizations = await imagemin(imageFilenames, { | ||
destination: options.outputDirectory, | ||
plugins: [ | ||
imageminPngquant(options.pngquant), | ||
imageminMozjpeg(options.mozjpeg) | ||
] | ||
}); | ||
filenameArrays = [ | ||
...filenameArrays, | ||
...(await writeOptimizedImages(regularOptimizations)) | ||
]; | ||
} catch (err) { | ||
throw new Error(err); | ||
} | ||
const regularOptimizations = imagemin(imageFilenames, { | ||
destination: options.outputDirectory, | ||
plugins: [ | ||
imageminPngquant(options.pngquant), | ||
imageminMozjpeg(options.mozjpeg) | ||
] | ||
}) | ||
.then(writeOptimizedImages) | ||
.catch((err) => console.log(err)); | ||
try { | ||
const webpOptimizations = await imagemin(imageFilenames, { | ||
destination: options.outputDirectory, | ||
plugins: [imageminWebp(options.webp)] | ||
}); | ||
filenameArrays = [ | ||
...filenameArrays, | ||
...(await writeOptimizedImages(webpOptimizations)) | ||
]; | ||
} catch (err) { | ||
throw new Error(err); | ||
} | ||
const webpOptimizations = imagemin(imageFilenames, { | ||
destination: options.outputDirectory, | ||
plugins: [imageminWebp(options.webp)] | ||
}).then(writeOptimizedImages); | ||
return Promise.all([regularOptimizations, webpOptimizations]) | ||
.then((filenameArrays) => _.flatten(filenameArrays)) | ||
.catch((err) => console.log(err)); | ||
return _.flatten(filenameArrays); | ||
}; |
{ | ||
"name": "@mapbox/appropriate-images", | ||
"version": "4.1.0-beta.4", | ||
"version": "4.1.0-beta.5", | ||
"description": "Get appropriately sized images into your website.", | ||
@@ -31,3 +31,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12" | ||
}, | ||
@@ -34,0 +34,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2083298
834
1