From ae136f38cd8c373765e63fca7a6d6e2eeebab9c0 Mon Sep 17 00:00:00 2001 From: Jungmin <101504594+JEM1224@users.noreply.github.com> Date: Wed, 17 Jan 2024 18:04:17 +0900 Subject: [PATCH] fix: remove sharp (#18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Convert buffer image to PNG format * feat: Convert buffer-formatted file to a different extension Downloaded the 'file-type' library to determine the file extension in a buffer-formatted file * fix: Changed the path for images * chore: 사용하지 않는 sharp 라이브러리 삭제 * fix: sharp로 변환하는 대신 기존 fs.writeFile 을 활용 * chore : sharp 제거 * fix all script --------- Co-authored-by: Eunjae Lee --- package.json | 4 +--- src/main.ts | 23 ++++------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index b2446cd..8ec1150 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,7 @@ "package": "ncc build --source-map --license licenses.txt", "test": "jest", "test:watch": "jest --watch", - "readd-sharp": "yarn remove sharp && yarn add sharp --platform=linux --arch=x64 sharp", - "all": "yarn readd-sharp && yarn build && yarn format && yarn lint && yarn package && yarn test", + "all": "yarn build && yarn format && yarn lint && yarn package && yarn test", "deploy": "./scripts/deploy.mjs" }, "repository": { @@ -35,7 +34,6 @@ "file-type": "^19.0.0", "gray-matter": "^4.0.3", "mkdirp": "^2.1.3", - "sharp": "^0.33.2", "yaml": "^2.2.1" }, "devDependencies": { diff --git a/src/main.ts b/src/main.ts index 5c785f2..56fc320 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,6 @@ import download from 'download' import dayjs from 'dayjs' import {extractImages} from './extract-images' import {formatFrontMatterValue} from './format' -import sharp from 'sharp' import {fileTypeFromBuffer} from 'file-type' async function run(): Promise { @@ -117,25 +116,11 @@ async function run(): Promise { if (imageExt === '') { const buffer = fs.readFileSync(imagePath) const imageType = await fileTypeFromBuffer(buffer) - sharp.cache(false) - - if ( - imageType !== undefined && - sharp.format.hasOwnProperty(imageType?.ext) - ) { - if (imageType.ext === 'gif') { - await sharp(imagePath, { - limitInputPixels: false, - animated: true, - density: 1 - }).toFile(`${imagePath}.${imageType.ext}`) - } else { - await sharp(imagePath).toFile(`${imagePath}.${imageType.ext}`) - } - newImageFilename += `.${imageType.ext}` - fs.unlinkSync(imagePath) - } + newImageFilename += `.${imageType?.ext}` + fs.writeFileSync(path.join(dirname, newImageFilename), buffer) + fs.unlinkSync(imagePath) } + bodyText = bodyText.replace( image.match, `![${image.alt}](./${newImageFilename}${