chore: remove deprecated isSupportedImage

This commit is contained in:
Ben Irvin 2024-01-18 11:50:21 +01:00 committed by GitHub
parent b9aef55175
commit 01dfca22b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 12 deletions

View File

@ -36,7 +36,7 @@ module.exports = ({ strapi }) => {
const fileTypeName = getTypeName(fileModel); const fileTypeName = getTypeName(fileModel);
const fileEntityResponseType = getEntityResponseName(fileModel); const fileEntityResponseType = getEntityResponseName(fileModel);
const { optimize, isSupportedImage } = getUploadService('image-manipulation'); const { optimize, isOptimizableImage } = getUploadService('image-manipulation');
/** /**
* Optimize and format a file using the upload services * Optimize and format a file using the upload services
@ -64,7 +64,7 @@ module.exports = ({ strapi }) => {
); );
currentFile.getStream = createReadStream; currentFile.getStream = createReadStream;
if (!(await isSupportedImage(currentFile))) { if (!(await isOptimizableImage(currentFile))) {
return currentFile; return currentFile;
} }

View File

@ -174,15 +174,6 @@ const breakpointSmallerThan = (breakpoint, { width, height }) => {
return breakpoint < width || breakpoint < height; return breakpoint < width || breakpoint < height;
}; };
// TODO V5: remove isSupportedImage
const isSupportedImage = (...args) => {
process.emitWarning(
'[deprecated] In future versions, `isSupportedImage` will be removed. Replace it with `isImage` or `isOptimizableImage` instead.'
);
return isOptimizableImage(...args);
};
/** /**
* Applies a simple image transformation to see if the image is faulty/corrupted. * Applies a simple image transformation to see if the image is faulty/corrupted.
*/ */
@ -234,7 +225,6 @@ const isImage = async (file) => {
}; };
module.exports = () => ({ module.exports = () => ({
isSupportedImage,
isFaultyImage, isFaultyImage,
isOptimizableImage, isOptimizableImage,
isResizableImage, isResizableImage,

View File

@ -0,0 +1,45 @@
import type { Transform } from 'jscodeshift';
/**
* Replaces calls to isSupportedImage with isOptimizableImage
*/
const transform: Transform = (file, api) => {
// Extract the jscodeshift API
const { j } = api;
// Parse the file content
const root = j(file.source);
// Find and update the destructuring assignment
root
.find(j.VariableDeclarator, {
init: {
callee: {
object: { callee: { property: { name: 'getUploadService' } } },
arguments: [{ value: 'image-manipulation' }],
},
},
})
.forEach((path) => {
if (path.node.id.type === 'ObjectPattern') {
path.node.id.properties.forEach((property) => {
if (property.key.type === 'Identifier' && property.key.name === 'isSupportedImage') {
property.key.name = 'isOptimizableImage';
if (property.value && property.value.type === 'Identifier') {
property.value.name = 'isOptimizableImage';
}
}
});
}
});
// Update calls to isSupportedImage
root.find(j.Identifier, { name: 'isSupportedImage' }).forEach((path) => {
path.node.name = 'isOptimizableImage';
});
// Return the updated file content
return root.toSource();
};
export default transform;