Skip to content

Commit

Permalink
fix: assets info for sharp (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 5, 2022
1 parent afb9a8f commit c897d30
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,12 +996,14 @@ const SHARP_FORMATS = new Map([

/**
* @param {WorkerResult} original
* @param {0 | 1} action
* @param {SharpOptions} minimizerOptions
* @param {SharpFormat | null} targetFormat
* @returns {Promise<WorkerResult>}
*/
async function sharpTransform(
original,
action,
minimizerOptions = {},
targetFormat = null
) {
Expand Down Expand Up @@ -1064,19 +1066,31 @@ async function sharpTransform(

const filename = path.join(fileDir, `${fileName}${sizeSuffix}.${outputExt}`);

const info =
action === 0
? {
...original.info,
minimized: true,
minimizedBy:
original.info && original.info.generatedBy
? ["sharp", ...original.info.generatedBy]
: ["sharp"],
}
: {
...original.info,
generated: true,
generatedBy:
original.info && original.info.generatedBy
? ["sharp", ...original.info.generatedBy]
: ["sharp"],
};

return {
filename,
data: result.data,
warnings: [...original.warnings],
errors: [...original.errors],
info: {
...original.info,
generated: true,
generatedBy:
original.info && original.info.generatedBy
? ["sharp", ...original.info.generatedBy]
: ["sharp"],
},
info,
};
}

Expand Down Expand Up @@ -1115,7 +1129,7 @@ function sharpGenerate(original, minimizerOptions) {

const [targetFormat] = targetFormats;

return sharpTransform(original, squooshOptions, targetFormat);
return sharpTransform(original, 1, squooshOptions, targetFormat);
}

/**
Expand All @@ -1125,7 +1139,7 @@ function sharpGenerate(original, minimizerOptions) {
* @returns {Promise<WorkerResult>}
*/
function sharpMinify(original, options) {
return sharpTransform(original, options);
return sharpTransform(original, 0, options);
}

module.exports = {
Expand Down

0 comments on commit c897d30

Please sign in to comment.