diff --git a/packages/core/upload/server/graphql.js b/packages/core/upload/server/graphql.js index a0fb2100ac..85f41dfd7e 100644 --- a/packages/core/upload/server/graphql.js +++ b/packages/core/upload/server/graphql.js @@ -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 @@ -64,7 +64,7 @@ module.exports = ({ strapi }) => { ); currentFile.getStream = createReadStream; - if (!(await isSupportedImage(currentFile))) { + if (!(await isOptimizableImage(currentFile))) { return currentFile; } diff --git a/packages/core/upload/server/services/image-manipulation.js b/packages/core/upload/server/services/image-manipulation.js index b313f4d1f8..38048cc1b6 100644 --- a/packages/core/upload/server/services/image-manipulation.js +++ b/packages/core/upload/server/services/image-manipulation.js @@ -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.' - ); - - return isOptimizableImage(...args); -}; - /** * Applies a simple image transformation to see if the image is faulty/corrupted. */ @@ -234,7 +225,6 @@ const isImage = async (file) => { }; module.exports = () => ({ - isSupportedImage, isFaultyImage, isOptimizableImage, isResizableImage, diff --git a/packages/utils/upgrade/resources/codemods/5.0.0/replace-isSupportedImage-with-isOptimizableImage.code.ts b/packages/utils/upgrade/resources/codemods/5.0.0/replace-isSupportedImage-with-isOptimizableImage.code.ts new file mode 100644 index 0000000000..b701aac050 --- /dev/null +++ b/packages/utils/upgrade/resources/codemods/5.0.0/replace-isSupportedImage-with-isOptimizableImage.code.ts @@ -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;