fix: update file-type dependency and fix dependency version mismatch (#6638)

This commit is contained in:
Alessio Gravili
2024-06-05 10:55:02 -04:00
committed by GitHub
parent b2751f75d5
commit 2077da8665
14 changed files with 33 additions and 86 deletions

View File

@@ -0,0 +1,9 @@
<component name="ProjectRunConfigurationManager">
<configuration default="true" type="JavaScriptTestRunnerJest">
<node-interpreter value="project" />
<node-options value="--experimental-vm-modules --no-deprecation" />
<envs />
<scope-kind value="ALL" />
<method v="2" />
</configuration>
</component>

View File

@@ -41,5 +41,6 @@
"source.fixAll.eslint": "explicit" "source.fixAll.eslint": "explicit"
} }
}, },
"files.insertFinalNewline": true "files.insertFinalNewline": true,
"jestrunner.jestCommand": "pnpm exec cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-deprecation\" node 'node_modules/jest/bin/jest.js'"
} }

View File

@@ -1,24 +1,7 @@
/** /** @type {import('jest').Config} */ const baseJestConfig = {
* Ignores all ESM packages that make Jest mad.
*
* "Jest encountered an unexpected token"
*
* Direct packages:
* - file-type
*/
const esModules = [
// file-type and all dependencies: https://github.com/sindresorhus/file-type
'file-type',
'strtok3',
'readable-web-to-node-stream',
'token-types',
'peek-readable',
].join('|')
/** @type {import('jest').Config} */
const baseJestConfig = {
extensionsToTreatAsEsm: ['.ts', '.tsx'], extensionsToTreatAsEsm: ['.ts', '.tsx'],
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.ts'], setupFiles: ['<rootDir>/test/jest.setup.env.js'],
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.js'],
moduleNameMapper: { moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/test/helpers/mocks/emptyModule.js', '\\.(css|scss)$': '<rootDir>/test/helpers/mocks/emptyModule.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
@@ -31,10 +14,6 @@ const baseJestConfig = {
transform: { transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'], '^.+\\.(t|j)sx?$': ['@swc/jest'],
}, },
transformIgnorePatterns: [
`/node_modules/(?!.pnpm)(?!(${esModules})/)`,
`/node_modules/.pnpm/(?!(${esModules.replace(/\//g, '\\+')})@)`,
],
verbose: true, verbose: true,
} }

View File

@@ -13,7 +13,7 @@
/** @type {import('jest').Config} */ /** @type {import('jest').Config} */
const customJestConfig = { const customJestConfig = {
extensionsToTreatAsEsm: ['.ts', '.tsx'], extensionsToTreatAsEsm: ['.ts', '.tsx'],
// setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'], // setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: { moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/helpers/mocks/emptyModule.js', '\\.(css|scss)$': '<rootDir>/helpers/mocks/emptyModule.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':

View File

@@ -47,7 +47,7 @@
"@payloadcms/translations": "workspace:*", "@payloadcms/translations": "workspace:*",
"@payloadcms/ui": "workspace:*", "@payloadcms/ui": "workspace:*",
"busboy": "^1.6.0", "busboy": "^1.6.0",
"file-type": "19.0.0 || 19.0.0-rc-f994737d14-20240522", "file-type": "17.1.6",
"graphql-http": "^1.22.0", "graphql-http": "^1.22.0",
"graphql-playground-html": "1.6.30", "graphql-playground-html": "1.6.30",
"http-status": "1.6.2", "http-status": "1.6.2",

View File

@@ -89,7 +89,7 @@
"console-table-printer": "2.11.2", "console-table-printer": "2.11.2",
"dataloader": "2.2.2", "dataloader": "2.2.2",
"deepmerge": "4.3.1", "deepmerge": "4.3.1",
"file-type": "16.5.4", "file-type": "17.1.6",
"find-up": "7.0.0", "find-up": "7.0.0",
"get-tsconfig": "^4.7.2", "get-tsconfig": "^4.7.2",
"http-status": "1.6.2", "http-status": "1.6.2",

View File

@@ -1,7 +1,6 @@
import type { OutputInfo, Sharp, SharpOptions } from 'sharp' import type { OutputInfo, Sharp, SharpOptions } from 'sharp'
import fileType from 'file-type' import { fileTypeFromBuffer } from 'file-type'
const { fromBuffer } = fileType
import fs from 'fs' import fs from 'fs'
import mkdirp from 'mkdirp' import mkdirp from 'mkdirp'
import sanitize from 'sanitize-filename' import sanitize from 'sanitize-filename'
@@ -161,7 +160,7 @@ export const generateFileData = async <T>({
if (sharpFile) { if (sharpFile) {
const metadata = await sharpFile.metadata() const metadata = await sharpFile.metadata()
fileBuffer = await sharpFile.toBuffer({ resolveWithObject: true }) fileBuffer = await sharpFile.toBuffer({ resolveWithObject: true })
;({ ext, mime } = await fromBuffer(fileBuffer.data)) // This is getting an incorrect gif height back. ;({ ext, mime } = await fileTypeFromBuffer(fileBuffer.data)) // This is getting an incorrect gif height back.
fileData.width = fileBuffer.info.width fileData.width = fileBuffer.info.width
fileData.height = fileBuffer.info.height fileData.height = fileBuffer.info.height
fileData.filesize = fileBuffer.info.size fileData.filesize = fileBuffer.info.size

View File

@@ -1,7 +1,6 @@
import fileType from 'file-type' import { fileTypeFromFile } from 'file-type'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
const { fromFile } = fileType
import type { PayloadRequestWithData } from '../types/index.js' import type { PayloadRequestWithData } from '../types/index.js'
@@ -12,7 +11,7 @@ const mimeTypeEstimate = {
export const getFileByPath = async (filePath: string): Promise<PayloadRequestWithData['file']> => { export const getFileByPath = async (filePath: string): Promise<PayloadRequestWithData['file']> => {
if (typeof filePath === 'string') { if (typeof filePath === 'string') {
const data = fs.readFileSync(filePath) const data = fs.readFileSync(filePath)
const mimetype = fromFile(filePath) const mimetype = fileTypeFromFile(filePath)
const { size } = fs.statSync(filePath) const { size } = fs.statSync(filePath)
const name = path.basename(filePath) const name = path.basename(filePath)

View File

@@ -1,8 +1,6 @@
import type { OutputInfo, Sharp, SharpOptions } from 'sharp' import type { OutputInfo, Sharp, SharpOptions } from 'sharp'
import fileType from 'file-type' import { fileTypeFromBuffer } from 'file-type'
const { fromBuffer } = fileType
import fs from 'fs' import fs from 'fs'
import sanitize from 'sanitize-filename' import sanitize from 'sanitize-filename'
@@ -343,7 +341,7 @@ export async function resizeAndTransformImageSizes({
req.payloadUploadSizes[imageResizeConfig.name] = bufferData req.payloadUploadSizes[imageResizeConfig.name] = bufferData
} }
const mimeInfo = await fromBuffer(bufferData) const mimeInfo = await fileTypeFromBuffer(bufferData)
const imageNameWithDimensions = createImageName( const imageNameWithDimensions = createImageName(
sanitizedImage.name, sanitizedImage.name,

48
pnpm-lock.yaml generated
View File

@@ -571,8 +571,8 @@ importers:
specifier: ^1.6.0 specifier: ^1.6.0
version: 1.6.0 version: 1.6.0
file-type: file-type:
specifier: 19.0.0 || 19.0.0-rc-f994737d14-20240522 specifier: 17.1.6
version: 19.0.0 version: 17.1.6
graphql: graphql:
specifier: ^16.8.1 specifier: ^16.8.1
version: 16.8.1 version: 16.8.1
@@ -701,8 +701,8 @@ importers:
specifier: 4.3.1 specifier: 4.3.1
version: 4.3.1 version: 4.3.1
file-type: file-type:
specifier: 16.5.4 specifier: 17.1.6
version: 16.5.4 version: 17.1.6
find-up: find-up:
specifier: 7.0.0 specifier: 7.0.0
version: 7.0.0 version: 7.0.0
@@ -10762,15 +10762,6 @@ packages:
dependencies: dependencies:
flat-cache: 3.2.0 flat-cache: 3.2.0
/file-type@16.5.4:
resolution: {integrity: sha512-/yFHK0aGjFEgDJjEKP0pWCplsPFPhwyfwevf/pVxiN0tmE4L9LmwWxWukdJSHdoCli4VgQLehjJtwQBnqmsKcw==}
engines: {node: '>=10'}
dependencies:
readable-web-to-node-stream: 3.0.2
strtok3: 6.3.0
token-types: 4.2.1
dev: false
/file-type@17.1.6: /file-type@17.1.6:
resolution: {integrity: sha512-hlDw5Ev+9e883s0pwUsuuYNu4tD7GgpUnOvykjv1Gya0ZIjuKumthDRua90VUn6/nlRKAjcxLUnHNTIUWwWIiw==} resolution: {integrity: sha512-hlDw5Ev+9e883s0pwUsuuYNu4tD7GgpUnOvykjv1Gya0ZIjuKumthDRua90VUn6/nlRKAjcxLUnHNTIUWwWIiw==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@@ -10778,16 +10769,6 @@ packages:
readable-web-to-node-stream: 3.0.2 readable-web-to-node-stream: 3.0.2
strtok3: 7.0.0 strtok3: 7.0.0
token-types: 5.0.1 token-types: 5.0.1
dev: true
/file-type@19.0.0:
resolution: {integrity: sha512-s7cxa7/leUWLiXO78DVVfBVse+milos9FitauDLG1pI7lNaJ2+5lzPnr2N24ym+84HVwJL6hVuGfgVE+ALvU8Q==}
engines: {node: '>=18'}
dependencies:
readable-web-to-node-stream: 3.0.2
strtok3: 7.0.0
token-types: 5.0.1
dev: false
/filename-reserved-regex@3.0.0: /filename-reserved-regex@3.0.0:
resolution: {integrity: sha512-hn4cQfU6GOT/7cFHXBqeBg2TbrMBgdD0kcjLhvSQYYwm3s4B6cjvBfb7nBALJLAXqmU5xajSa7X2NnUud/VCdw==} resolution: {integrity: sha512-hn4cQfU6GOT/7cFHXBqeBg2TbrMBgdD0kcjLhvSQYYwm3s4B6cjvBfb7nBALJLAXqmU5xajSa7X2NnUud/VCdw==}
@@ -14029,11 +14010,6 @@ packages:
resolution: {integrity: sha512-YYEs+eauIjDH5nUEGi18EohWE0nV2QbGTqmxQcqgZ/0g+laPCQmuIqq7EBLVi9uim9zMgfJv0QBZEnQ3uHw/Tw==} resolution: {integrity: sha512-YYEs+eauIjDH5nUEGi18EohWE0nV2QbGTqmxQcqgZ/0g+laPCQmuIqq7EBLVi9uim9zMgfJv0QBZEnQ3uHw/Tw==}
dev: false dev: false
/peek-readable@4.1.0:
resolution: {integrity: sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg==}
engines: {node: '>=8'}
dev: false
/peek-readable@5.0.0: /peek-readable@5.0.0:
resolution: {integrity: sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==} resolution: {integrity: sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==}
engines: {node: '>=14.16'} engines: {node: '>=14.16'}
@@ -16404,14 +16380,6 @@ packages:
/strnum@1.0.5: /strnum@1.0.5:
resolution: {integrity: sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==} resolution: {integrity: sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==}
/strtok3@6.3.0:
resolution: {integrity: sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==}
engines: {node: '>=10'}
dependencies:
'@tokenizer/token': 0.3.0
peek-readable: 4.1.0
dev: false
/strtok3@7.0.0: /strtok3@7.0.0:
resolution: {integrity: sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==} resolution: {integrity: sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==}
engines: {node: '>=14.16'} engines: {node: '>=14.16'}
@@ -16755,14 +16723,6 @@ packages:
engines: {node: '>=0.6'} engines: {node: '>=0.6'}
dev: false dev: false
/token-types@4.2.1:
resolution: {integrity: sha512-6udB24Q737UD/SDsKAHI9FCRP7Bqc9D/MQUV02ORQg5iskjtLJlZJNdN4kKtcdtwCeWIwIHDGaUsTsCCAa8sFQ==}
engines: {node: '>=10'}
dependencies:
'@tokenizer/token': 0.3.0
ieee754: 1.2.1
dev: false
/token-types@5.0.1: /token-types@5.0.1:
resolution: {integrity: sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==} resolution: {integrity: sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==}
engines: {node: '>=14.16'} engines: {node: '>=14.16'}

View File

@@ -7,6 +7,7 @@ export default async () => {
process.env.PAYLOAD_DROP_DATABASE = 'true' process.env.PAYLOAD_DROP_DATABASE = 'true'
process.env.NODE_OPTIONS = '--no-deprecation' process.env.NODE_OPTIONS = '--no-deprecation'
process.env.DISABLE_PAYLOAD_HMR = 'true' process.env.DISABLE_PAYLOAD_HMR = 'true'
process.env.NODE_OPTIONS = '--experimental-vm-modules --no-deprecation'
if ( if (
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') && (!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') &&

View File

@@ -9,10 +9,8 @@ const dirname = path.dirname(filename)
const customJestConfig = { const customJestConfig = {
...jestBaseConfig, ...jestBaseConfig,
testMatch: ['<rootDir>/**/*int.spec.ts'], testMatch: ['<rootDir>/**/*int.spec.ts'],
setupFilesAfterEnv: [ setupFiles: ['<rootDir>/jest.setup.env.js'],
//path.resolve(dirname, './helpers/startMemoryDB.ts'), setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
'<rootDir>/jest.setup.ts',
],
globalSetup: path.resolve(dirname, './helpers/startMemoryDB.ts'), globalSetup: path.resolve(dirname, './helpers/startMemoryDB.ts'),
moduleNameMapper: { moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/helpers/mocks/emptyModule.js', '\\.(css|scss)$': '<rootDir>/helpers/mocks/emptyModule.js',

1
test/jest.setup.env.js Normal file
View File

@@ -0,0 +1 @@
process.env.NODE_OPTIONS = '--experimental-vm-modules --no-deprecation'

View File

@@ -2,3 +2,5 @@ process.env.PAYLOAD_DISABLE_ADMIN = 'true'
process.env.PAYLOAD_DROP_DATABASE = 'true' process.env.PAYLOAD_DROP_DATABASE = 'true'
process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER = 's3' process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER = 's3'
process.env.NODE_OPTIONS = '--experimental-vm-modules --no-deprecation'