Skip to content

Commit afa085e

Browse files
committed
fix: update file-type to disable eval dynamic code errors during build
1 parent b6b0e41 commit afa085e

File tree

6 files changed

+75
-67
lines changed

6 files changed

+75
-67
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@jimp/utils": "workspace:*",
2121
"await-to-js": "^3.0.0",
2222
"exif-parser": "^0.1.12",
23-
"file-type": "^16.0.0",
23+
"file-type": "^19.6.0",
2424
"mime": "3"
2525
},
2626
"devDependencies": {

packages/core/src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Bitmap, Format, JimpClass, Edge } from "@jimp/types";
22
import { cssColorToHex, scan, scanIterator } from "@jimp/utils";
3-
import fileType from "file-type/core.js";
3+
import { fileTypeFromBuffer } from "./utils/fileTypeFromBuffer.js";
44
import { to } from "await-to-js";
55
import { existsSync, readFile, writeFile } from "@jimp/file-ops";
66
import mime from "mime/lite.js";
@@ -90,7 +90,7 @@ export interface JimpPlugin {
9090
}
9191

9292
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
93-
k: infer I
93+
k: infer I,
9494
) => void
9595
? I
9696
: never;
@@ -225,7 +225,7 @@ export function createJimp<
225225
*/
226226
static async read(
227227
url: string | Buffer | ArrayBuffer,
228-
options?: MimeTypeToDecodeOptions
228+
options?: MimeTypeToDecodeOptions,
229229
) {
230230
if (Buffer.isBuffer(url) || url instanceof ArrayBuffer) {
231231
return this.fromBuffer(url);
@@ -292,8 +292,8 @@ export function createJimp<
292292
if (Array.isArray(bitmap.data)) {
293293
data = Buffer.concat(
294294
bitmap.data.map((hex) =>
295-
Buffer.from(hex.toString(16).padStart(8, "0"), "hex")
296-
)
295+
Buffer.from(hex.toString(16).padStart(8, "0"), "hex"),
296+
),
297297
);
298298
}
299299

@@ -329,12 +329,12 @@ export function createJimp<
329329
*/
330330
static async fromBuffer(
331331
buffer: Buffer | ArrayBuffer,
332-
options?: MimeTypeToDecodeOptions
332+
options?: MimeTypeToDecodeOptions,
333333
) {
334334
const actualBuffer =
335335
buffer instanceof ArrayBuffer ? bufferFromArrayBuffer(buffer) : buffer;
336336

337-
const mime = await fileType.fromBuffer(actualBuffer);
337+
const mime = await fileTypeFromBuffer(actualBuffer);
338338

339339
if (!mime || !mime.mime) {
340340
throw new Error("Could not find MIME for Buffer");
@@ -347,7 +347,7 @@ export function createJimp<
347347
}
348348

349349
const image = new CustomJimp(
350-
await format.decode(actualBuffer, options?.[format.mime])
350+
await format.decode(actualBuffer, options?.[format.mime]),
351351
) as InstanceType<typeof CustomJimp> & ExtraMethodMap;
352352

353353
image.mime = mime.mime;
@@ -500,7 +500,7 @@ export function createJimp<
500500
const mimeType = mime.getType(path);
501501
await writeFile(
502502
path,
503-
await this.getBuffer(mimeType as SupportedMimeTypes, options)
503+
await this.getBuffer(mimeType as SupportedMimeTypes, options),
504504
);
505505
}
506506

@@ -701,7 +701,7 @@ export function createJimp<
701701
mode?: BlendMode;
702702
opacitySource?: number;
703703
opacityDest?: number;
704-
} = {}
704+
} = {},
705705
) {
706706
return composite(this, src, x, y, options);
707707
}
@@ -731,14 +731,14 @@ export function createJimp<
731731
y: number,
732732
w: number,
733733
h: number,
734-
cb: (x: number, y: number, idx: number) => any
734+
cb: (x: number, y: number, idx: number) => any,
735735
): this;
736736
scan(
737737
x: number | ((x: number, y: number, idx: number) => any),
738738
y?: number,
739739
w?: number,
740740
h?: number,
741-
f?: (x: number, y: number, idx: number) => any
741+
f?: (x: number, y: number, idx: number) => any,
742742
): this {
743743
return scan(this, x as any, y as any, w as any, h as any, f as any);
744744
}

packages/core/src/utils/composite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function composite<I extends JimpClass>(
1313
mode?: BlendMode;
1414
opacitySource?: number;
1515
opacityDest?: number;
16-
} = {}
16+
} = {},
1717
) {
1818
if (!(src instanceof baseImage.constructor)) {
1919
throw new Error("The source must be a Jimp image");
@@ -72,7 +72,7 @@ export function composite<I extends JimpClass>(
7272
b: baseImage.bitmap.data[dstIdx + 2]! / 255,
7373
a: baseImage.bitmap.data[dstIdx + 3]! / 255,
7474
},
75-
opacitySource
75+
opacitySource,
7676
);
7777

7878
baseImage.bitmap.data[dstIdx + 0] = limit255(blended.r * 255);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const fileTypeFromBuffer = async (
2+
buffer: Uint8Array | ArrayBuffer
3+
) => {
4+
const { fileTypeFromBuffer } = await import("file-type/core");
5+
return await fileTypeFromBuffer(buffer);
6+
};

packages/core/src/utils/image-bitmap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function transformBitmap<I extends JimpClass>(
8989
img: I,
9090
width: number,
9191
height: number,
92-
transformation: (x: number, y: number) => readonly [number, number]
92+
transformation: (x: number, y: number) => readonly [number, number],
9393
) {
9494
// Underscore-prefixed values are related to the source bitmap
9595
// Their counterparts with no prefix are related to the target bitmap
@@ -140,7 +140,7 @@ function exifRotate<I extends JimpClass>(img: I) {
140140

141141
export async function attemptExifRotate<I extends JimpClass>(
142142
image: I,
143-
buffer: Buffer
143+
buffer: Buffer,
144144
) {
145145
try {
146146
(image as unknown as { _exif: ExifData })._exif =

0 commit comments

Comments
 (0)