Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated isSupportedImage #19204

Merged
merged 4 commits into from Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/upload/server/graphql.js
Expand Up @@ -36,7 +36,7 @@ module.exports = ({ strapi }) => {
const fileTypeName = getTypeName(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
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = ({ strapi }) => {
);
currentFile.getStream = createReadStream;

if (!(await isSupportedImage(currentFile))) {
if (!(await isOptimizableImage(currentFile))) {
return currentFile;
}

Expand Down
10 changes: 0 additions & 10 deletions packages/core/upload/server/services/image-manipulation.js
Expand Up @@ -174,15 +174,6 @@ const breakpointSmallerThan = (breakpoint, { width, 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.'
innerdvations marked this conversation as resolved.
Show resolved Hide resolved
);

return isOptimizableImage(...args);
};

/**
* Applies a simple image transformation to see if the image is faulty/corrupted.
*/
Expand Down Expand Up @@ -234,7 +225,6 @@ const isImage = async (file) => {
};

module.exports = () => ({
isSupportedImage,
isFaultyImage,
isOptimizableImage,
isResizableImage,
Expand Down
@@ -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;