@mapbox/appropriate-images
Advanced tools
Comparing version 4.1.0-beta.8 to 4.1.0
# 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}`); |
@@ -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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2085170
892
0
0
+ Addedchownr@2.0.0(transitive)
+ Addeddel@5.1.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addednoop-logger@0.1.1(transitive)
+ Addedp-map@3.0.0(transitive)
+ Addedprebuild-install@5.3.6(transitive)
+ Addedsharp@0.25.4(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtempy@0.5.0(transitive)
+ Addedtype-fest@0.12.0(transitive)
+ Addedwhich-pm-runs@1.1.0(transitive)
- Removedarray-flatten@3.0.0(transitive)
- Removeddel@6.1.1(transitive)
- Removedglobby@11.1.0(transitive)
- Removedp-map@4.0.0(transitive)
- Removedprebuild-install@6.1.4(transitive)
- Removedsharp@0.27.2(transitive)
- Removedtempy@1.0.1(transitive)
- Removedtype-fest@0.16.0(transitive)
Updateddel@^5.1.0
Updatedsharp@^0.25.4
Updatedtempy@^0.5.0