Skip to content

Commit

Permalink
Fix Bug svg#1946
Browse files Browse the repository at this point in the history
Optimize a large number of vectors sequentially instead of parallel to avoid the simultaneously opened file limit
  • Loading branch information
codermapuche committed Jan 28, 2024
1 parent 10e5e5e commit 7f48e63
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/svgo/coa.js
Expand Up @@ -303,20 +303,27 @@ function optimizeFolder(config, dir, output) {
function processDirectory(config, dir, files, output) {
// take only *.svg files, recursively if necessary
var svgFilesDescriptions = getFilesDescriptions(config, dir, files, output);

return svgFilesDescriptions.length
? Promise.all(
svgFilesDescriptions.map((fileDescription) =>
optimizeFile(
config,
fileDescription.inputPath,
fileDescription.outputPath,
),
),
)
: Promise.reject(
new Error(`No SVG files have been found in '${dir}' directory.`),
);

if ( svgFilesDescriptions.length == 0 ) {
return Promise.reject(new Error('No SVG files have been found in "' + dir + '" directory.'));
}

var semaphore = Promise.resolve([ ]);

svgFilesDescriptions.reduce(function(semaphore, fileDescription) {
return semaphore.then(function(results) {
return optimizeFile(
config,
fileDescription.inputPath,
fileDescription.outputPath,
).then(function(result) {
results.push(result);
return results;
});
});
}, semaphore);

return semaphore;
}

/**
Expand Down

0 comments on commit 7f48e63

Please sign in to comment.