Socket
Socket
Sign inDemoInstall

@mapbox/appropriate-images

Package Overview
Dependencies
302
Maintainers
14
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0-beta.8 to 4.1.0

4

CHANGELOG.md
# Changelog
## 4.1.0
- Add `maxConcurrency` flag to optimize multiple images with limited concurrency.
# 4.0.0

@@ -4,0 +8,0 @@

@@ -44,2 +44,3 @@ 'use strict';

appropriate-images horse pigMan walrus --quiet
appropriate-images --all -c 5

@@ -49,2 +50,3 @@ ${chalk.bold.underline('Options')}

-q, --quiet Do not log output filenames.
-c, --maxConcurrency Optimize images with limited maxConcurrency.
`;

@@ -57,3 +59,4 @@

a: 'all',
q: 'quiet'
q: 'quiet',
c: 'maxConcurrency'
}

@@ -83,2 +86,6 @@ }

if (cli.flags.c) {
generateOptions.maxConcurrency = cli.flags.c;
}
const logUsageError = (error) => {

@@ -85,0 +92,0 @@ console.log(`${chalk.red.bold('Usage error:')} ${error.message}`);

37

lib/generate.js

@@ -16,4 +16,2 @@ 'use strict';

const limit = pLimit(5);
// Suppress vips warnings from sharp

@@ -87,2 +85,24 @@ process.env.VIPS_WARNING = true;

/**
* Handle optimizing file(s)
*
* @param {string} options
* @param {array} results
* @return {array} - Resolves with an array of optimized filenames.
*/
function handleOptimize(options, results) {
if (options.maxConcurrency) {
const limit = pLimit(options.maxConcurrency);
const optimizeQueue = [];
for (const res in results) {
optimizeQueue.push(
limit(() => optimize(_.flatten(results[res]), options))
);
}
return Promise.all(optimizeQueue);
} else {
return optimize(_.flatten(results), options);
}
}
// Documented in README.

@@ -164,17 +184,6 @@ module.exports = (imageConfig, options) => {

})
.then((result) => {
const optimizeQueue = [];
.then((result) => handleOptimize(options, result));
for (var res in result) {
optimizeQueue.push(
limit(() => optimize(_.flatten(result[res]), options))
);
}
return Promise.all(optimizeQueue).catch((err) =>
console.log('err!!', err)
);
});
return pFinally(makeItHappen, destroyTemporaryDirectory);
});
};
{
"name": "@mapbox/appropriate-images",
"version": "4.1.0-beta.8",
"version": "4.1.0",
"description": "Get appropriately sized images into your website.",

@@ -31,7 +31,7 @@ "main": "index.js",

"engines": {
"node": ">=12"
"node": ">=10"
},
"dependencies": {
"chalk": "^4.1.0",
"del": "^6.0.0",
"del": "^5.1.0",
"fasterror": "^1.1.0",

@@ -48,4 +48,4 @@ "imagemin": "^7.0.1",

"pify": "^5.0.0",
"sharp": "^0.27.1",
"tempy": "^1.0.0"
"sharp": "^0.25.4",
"tempy": "^0.5.0"
},

@@ -52,0 +52,0 @@ "devDependencies": {

@@ -7,3 +7,3 @@ # @mapbox/appropriate-images

Images are resized with [sharp](http://sharp.dimens.io/en/stable/), then each size variant is optimized (including the creation of a `webp` version) with [imagemin](https://github.com/imagemin/imagemin) plugins.
Images are resized with [sharp](https://sharp.pixelplumbing.com/), then each size variant is optimized (including the creation of a `webp` version) with [imagemin](https://github.com/imagemin/imagemin) plugins.

@@ -10,0 +10,0 @@ [@mapbox/appropriate-images-get-url] can then be used in the browser to determine which size variant of an image to render, at run time, given an [image configuration] and the available width.

@@ -72,2 +72,48 @@ 'use strict';

test('works with maxConcurrency', () => {
const imageConfig = {
bear: {
basename: 'bear.png',
sizes: [{ width: 300 }, { width: 600 }]
},
montaraz: {
basename: 'montaraz.jpg',
sizes: [{ width: 300 }, { width: 600 }]
},
osprey: {
basename: 'osprey.jpg',
sizes: [{ width: 300 }, { width: 600 }]
},
walrus: {
basename: 'walrus.png',
sizes: [{ width: 300 }, { width: 600 }]
}
};
const options = { inputDirectory, outputDirectory, maxConcurrency: 2 };
return generate(imageConfig, options)
.then(() => pify(fs.readdir)(outputDirectory))
.then((outputFiles) => {
expect(outputFiles).toEqual([
'bear-300.png',
'bear-300.webp',
'bear-600.png',
'bear-600.webp',
'montaraz-300.jpg',
'montaraz-300.webp',
'montaraz-600.jpg',
'montaraz-600.webp',
'osprey-300.jpg',
'osprey-300.webp',
'osprey-600.jpg',
'osprey-600.webp',
'walrus-300.png',
'walrus-300.webp',
'walrus-600.png',
'walrus-600.webp'
]);
});
});
test('works with specified ids', () => {

@@ -74,0 +120,0 @@ const imageConfig = {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc