Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 16c015f

Browse files
committedNov 21, 2024
feat: update file-type to disable eval dynamic code errors during build
close #1361
1 parent b6b0e41 commit 16c015f

File tree

7 files changed

+900
-119
lines changed

7 files changed

+900
-119
lines changed
 

‎packages/core/package.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"scripts": {
99
"lint": "eslint .",
1010
"test-off": "vitest",
11-
"build": "tshy",
12-
"dev": "tshy --watch",
11+
"build": "tsup",
12+
"dev": "tsup --watch",
1313
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
1414
},
1515
"author": "Andrew Lisowski <lisowski54@gmail.com>",
@@ -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": {
@@ -32,6 +32,7 @@
3232
"@types/node": "^18.19.48",
3333
"eslint": "^9.9.1",
3434
"tshy": "^3.0.2",
35+
"tsup": "^8.3.5",
3536
"typescript": "^5.5.4",
3637
"vite-plugin-node-polyfills": "^0.22.0",
3738
"vitest": "^2.0.5"
@@ -49,21 +50,21 @@
4950
"./package.json": "./package.json",
5051
".": {
5152
"import": {
52-
"types": "./dist/esm/index.d.ts",
53-
"default": "./dist/esm/index.js"
53+
"types": "./dist/index.d.ts",
54+
"default": "./dist/index.js"
5455
},
5556
"require": {
56-
"types": "./dist/commonjs/index.d.ts",
57-
"default": "./dist/commonjs/index.js"
57+
"types": "./dist/index.d.cts",
58+
"default": "./dist/index.cjs"
5859
}
5960
}
6061
},
61-
"main": "./dist/commonjs/index.js",
62-
"types": "./dist/commonjs/index.d.ts",
62+
"main": "./dist/index.cjs",
63+
"types": "./dist/index.d.cts",
6364
"type": "module",
6465
"publishConfig": {
6566
"access": "public"
6667
},
6768
"sideEffects": false,
68-
"module": "./dist/esm/index.js"
69+
"module": "./dist/index.js"
6970
}

‎packages/core/src/index.ts

+2-2
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 "#file-type/core";
44
import { to } from "await-to-js";
55
import { existsSync, readFile, writeFile } from "@jimp/file-ops";
66
import mime from "mime/lite.js";
@@ -334,7 +334,7 @@ export function createJimp<
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");

‎packages/core/src/polyfills/cjs.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { fileTypeFromBuffer as fileTypeFromBufferCore } from 'file-type/core'
2+
3+
export const fileTypeFromBuffer: typeof fileTypeFromBufferCore = async (
4+
buffer,
5+
) => {
6+
const { fileTypeFromBuffer } = await import('file-type/core')
7+
return await fileTypeFromBuffer(buffer)
8+
}

‎packages/core/src/polyfills/esm.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { fileTypeFromBuffer } from 'file-type/core'

‎packages/core/tsconfig.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"extends": "@jimp/config-typescript/base.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "dist",
5+
"module": "ESNext",
6+
"moduleResolution": "bundler",
7+
"paths": {
8+
"#file-type/core": ["./src/polyfills/esm.ts"]
9+
}
510
}
611
}

‎packages/core/tsup.config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig } from 'tsup'
2+
3+
export default defineConfig({
4+
entry: ['src/index.ts'],
5+
format: ['esm', 'cjs'],
6+
dts: true,
7+
clean: true,
8+
esbuildOptions(options) {
9+
options.alias = {
10+
'#file-type/core':
11+
options.format === 'esm'
12+
? './src/polyfills/esm.ts'
13+
: './src/polyfills/cjs.ts',
14+
}
15+
},
16+
})

‎pnpm-lock.yaml

+856-106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.