From 97b3d3d4e160866eee0f097b6039edc9e09a8495 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Sun, 2 Oct 2022 23:29:22 -0700 Subject: [PATCH] pin file-type to non-esm version, fix a few warnings --- package-lock.json | 93 +++++++++++-------- package.json | 3 +- .../elements/components/input-image-edit.tsx | 4 +- .../elements/contexts/context-menu-image.tsx | 4 +- .../lists/components/message-element.tsx | 2 +- .../elements/overlays/overlay-image.tsx | 2 +- .../webapp/elements/require/elements-util.tsx | 4 +- .../webapp/elements/sections/send-message.tsx | 4 +- src/client/webapp/guilds-manager.ts | 2 +- src/logger/logger.ts | 8 +- src/server/scripts/create-cordis-file.ts | 4 +- src/server/server-controller.ts | 10 +- 12 files changed, 80 insertions(+), 60 deletions(-) diff --git a/package-lock.json b/package-lock.json index a95d019..ec89237 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "colors": "^1.4.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-react-hooks": "^4.3.0", - "file-type": "^18.0.0", + "file-type": "^16.5.4", "image-size": "^1.0.0", "moment": "^2.29.1", "pg": "^8.7.1", @@ -36,6 +36,7 @@ "devDependencies": { "@types/jest": "^29.1.1", "@types/pg": "^8.6.1", + "@types/sharp": "^0.31.0", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^5.5.0", "@typescript-eslint/parser": "^5.5.0", @@ -1485,6 +1486,15 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" }, + "node_modules/@types/sharp": { + "version": "0.31.0", + "resolved": "https://registry.npmjs.org/@types/sharp/-/sharp-0.31.0.tgz", + "integrity": "sha512-nwivOU101fYInCwdDcH/0/Ru6yIRXOpORx25ynEOc6/IakuCmjOAGpaO5VfUl4QkDtUC6hj+Z2eCQvgXOioknw==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -3430,16 +3440,16 @@ } }, "node_modules/file-type": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-18.0.0.tgz", - "integrity": "sha512-jjMwFpnW8PKofLE/4ohlhqwDk5k0NC6iy0UHAJFKoY1fQeGMN0GDdLgHQrvCbSpMwbqzoCZhRI5dETCZna5qVA==", + "version": "16.5.4", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-16.5.4.tgz", + "integrity": "sha512-/yFHK0aGjFEgDJjEKP0pWCplsPFPhwyfwevf/pVxiN0tmE4L9LmwWxWukdJSHdoCli4VgQLehjJtwQBnqmsKcw==", "dependencies": { - "readable-web-to-node-stream": "^3.0.2", - "strtok3": "^7.0.0", - "token-types": "^5.0.1" + "readable-web-to-node-stream": "^3.0.0", + "strtok3": "^6.2.4", + "token-types": "^4.1.1" }, "engines": { - "node": ">=14.16" + "node": ">=10" }, "funding": { "url": "https://github.com/sindresorhus/file-type?sponsor=1" @@ -5943,11 +5953,11 @@ } }, "node_modules/peek-readable": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz", - "integrity": "sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-4.1.0.tgz", + "integrity": "sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg==", "engines": { - "node": ">=14.16" + "node": ">=8" }, "funding": { "type": "github", @@ -7225,15 +7235,15 @@ } }, "node_modules/strtok3": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-7.0.0.tgz", - "integrity": "sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz", + "integrity": "sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==", "dependencies": { "@tokenizer/token": "^0.3.0", - "peek-readable": "^5.0.0" + "peek-readable": "^4.1.0" }, "engines": { - "node": ">=14.16" + "node": ">=10" }, "funding": { "type": "github", @@ -7404,15 +7414,15 @@ } }, "node_modules/token-types": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/token-types/-/token-types-5.0.1.tgz", - "integrity": "sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-4.2.1.tgz", + "integrity": "sha512-6udB24Q737UD/SDsKAHI9FCRP7Bqc9D/MQUV02ORQg5iskjtLJlZJNdN4kKtcdtwCeWIwIHDGaUsTsCCAa8sFQ==", "dependencies": { "@tokenizer/token": "^0.3.0", "ieee754": "^1.2.1" }, "engines": { - "node": ">=14.16" + "node": ">=10" }, "funding": { "type": "github", @@ -9013,6 +9023,15 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" }, + "@types/sharp": { + "version": "0.31.0", + "resolved": "https://registry.npmjs.org/@types/sharp/-/sharp-0.31.0.tgz", + "integrity": "sha512-nwivOU101fYInCwdDcH/0/Ru6yIRXOpORx25ynEOc6/IakuCmjOAGpaO5VfUl4QkDtUC6hj+Z2eCQvgXOioknw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -10398,13 +10417,13 @@ } }, "file-type": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-18.0.0.tgz", - "integrity": "sha512-jjMwFpnW8PKofLE/4ohlhqwDk5k0NC6iy0UHAJFKoY1fQeGMN0GDdLgHQrvCbSpMwbqzoCZhRI5dETCZna5qVA==", + "version": "16.5.4", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-16.5.4.tgz", + "integrity": "sha512-/yFHK0aGjFEgDJjEKP0pWCplsPFPhwyfwevf/pVxiN0tmE4L9LmwWxWukdJSHdoCli4VgQLehjJtwQBnqmsKcw==", "requires": { - "readable-web-to-node-stream": "^3.0.2", - "strtok3": "^7.0.0", - "token-types": "^5.0.1" + "readable-web-to-node-stream": "^3.0.0", + "strtok3": "^6.2.4", + "token-types": "^4.1.1" } }, "fill-range": { @@ -12251,9 +12270,9 @@ "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==" }, "peek-readable": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz", - "integrity": "sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-4.1.0.tgz", + "integrity": "sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg==" }, "pend": { "version": "1.2.0", @@ -13161,12 +13180,12 @@ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, "strtok3": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-7.0.0.tgz", - "integrity": "sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz", + "integrity": "sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==", "requires": { "@tokenizer/token": "^0.3.0", - "peek-readable": "^5.0.0" + "peek-readable": "^4.1.0" } }, "sumchecker": { @@ -13296,9 +13315,9 @@ } }, "token-types": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/token-types/-/token-types-5.0.1.tgz", - "integrity": "sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-4.2.1.tgz", + "integrity": "sha512-6udB24Q737UD/SDsKAHI9FCRP7Bqc9D/MQUV02ORQg5iskjtLJlZJNdN4kKtcdtwCeWIwIHDGaUsTsCCAa8sFQ==", "requires": { "@tokenizer/token": "^0.3.0", "ieee754": "^1.2.1" diff --git a/package.json b/package.json index fbf5cb7..03f99cc 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "colors": "^1.4.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-react-hooks": "^4.3.0", - "file-type": "^18.0.0", + "file-type": "^16.5.4", "image-size": "^1.0.0", "moment": "^2.29.1", "pg": "^8.7.1", @@ -33,6 +33,7 @@ "devDependencies": { "@types/jest": "^29.1.1", "@types/pg": "^8.6.1", + "@types/sharp": "^0.31.0", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^5.5.0", "@typescript-eslint/parser": "^5.5.0", diff --git a/src/client/webapp/elements/components/input-image-edit.tsx b/src/client/webapp/elements/components/input-image-edit.tsx index 85557e8..00a2def 100644 --- a/src/client/webapp/elements/components/input-image-edit.tsx +++ b/src/client/webapp/elements/components/input-image-edit.tsx @@ -6,7 +6,7 @@ const LOG = Logger.create(__filename, electronConsole); import React, { FC, useEffect, useRef } from 'react'; import ElementsUtil from '../require/elements-util'; -import * as FileType from 'file-type'; +import { fromBuffer as fileTypeFromBuffer } from 'file-type'; import { useIsMountedRef, useOneTimeAsyncAction } from '../require/react-helper'; interface ImageEditInputProps { @@ -74,7 +74,7 @@ const ImageEditInput: FC = (props: ImageEditInputProps) => return; } const buff = Buffer.from(await file.arrayBuffer()); - const typeResult = await FileType.fromBuffer(buff); + const typeResult = await fileTypeFromBuffer(buff); if (!typeResult || !acceptedExtTypes.includes(typeResult.ext)) { e.target.value = ''; setMessage(`Invalid image type. Accepted types: ${acceptedExtTypes.join(', ')}`); diff --git a/src/client/webapp/elements/contexts/context-menu-image.tsx b/src/client/webapp/elements/contexts/context-menu-image.tsx index c146c1b..cea47e9 100644 --- a/src/client/webapp/elements/contexts/context-menu-image.tsx +++ b/src/client/webapp/elements/contexts/context-menu-image.tsx @@ -7,8 +7,8 @@ import React, { FC, useMemo } from 'react'; import * as electron from 'electron'; import { useAsyncSubmitButton, useDownloadButton } from '../require/react-helper'; import ContextMenu from './components/context-menu'; -import * as FileType from 'file-type'; import sharp from 'sharp'; +import { fromBuffer as fileTypeFromBuffer } from 'file-type'; export interface ImageContextMenuProps { relativeToPos: { x: number; y: number }; @@ -27,7 +27,7 @@ const ImageContextMenu: FC = (props: ImageContextMenuProp const [copyCallable, copyText, copyShaking] = useAsyncSubmitButton( async () => { - const type = await FileType.fromBuffer(resourceBuff); + const type = await fileTypeFromBuffer(resourceBuff); if (!type) { return { result: null, errorMessage: 'Unable to get file type' }; } diff --git a/src/client/webapp/elements/lists/components/message-element.tsx b/src/client/webapp/elements/lists/components/message-element.tsx index 9429d95..01e0fda 100644 --- a/src/client/webapp/elements/lists/components/message-element.tsx +++ b/src/client/webapp/elements/lists/components/message-element.tsx @@ -13,7 +13,7 @@ import { } from '../../require/atoms'; import ElementsUtil, { IAlignment } from '../../require/elements-util'; import { isLoaded } from '../../require/loadables'; -import { useContextClickContextMenu, useDownloadButton, useOneTimeAsyncAction } from '../../require/react-helper'; +import { useContextClickContextMenu, useDownloadButton } from '../../require/react-helper'; interface ResourceElementProps { guild: CombinedGuild; diff --git a/src/client/webapp/elements/overlays/overlay-image.tsx b/src/client/webapp/elements/overlays/overlay-image.tsx index 821aaa3..742305b 100644 --- a/src/client/webapp/elements/overlays/overlay-image.tsx +++ b/src/client/webapp/elements/overlays/overlay-image.tsx @@ -3,7 +3,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console; import Logger from '../../../../logger/logger'; const LOG = Logger.create(__filename, electronConsole); -import React, { FC, useCallback, useMemo, useRef } from 'react'; +import React, { FC, useMemo, useRef } from 'react'; import CombinedGuild from '../../guild-combined'; import ElementsUtil, { IAlignment } from '../require/elements-util'; import DownloadButton from '../components/button-download'; diff --git a/src/client/webapp/elements/require/elements-util.tsx b/src/client/webapp/elements/require/elements-util.tsx index d84a9cd..6d1e073 100644 --- a/src/client/webapp/elements/require/elements-util.tsx +++ b/src/client/webapp/elements/require/elements-util.tsx @@ -6,7 +6,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console; import Logger from '../../../../logger/logger'; const LOG = Logger.create(__filename, electronConsole); -import * as FileType from 'file-type'; +import { fromBuffer as fileTypeFromBuffer } from 'file-type'; import * as uuid from 'uuid'; import Util from '../../util'; @@ -62,7 +62,7 @@ export default class ElementsUtil { /** gets a string compatible with an src attribute */ static async getImageBufferSrc(buffer: Buffer): Promise { - const result = await FileType.fromBuffer(buffer); + const result = await fileTypeFromBuffer(buffer); switch (result && result.mime) { case 'image/png': case 'image/jpeg': diff --git a/src/client/webapp/elements/sections/send-message.tsx b/src/client/webapp/elements/sections/send-message.tsx index c6a0307..003905c 100644 --- a/src/client/webapp/elements/sections/send-message.tsx +++ b/src/client/webapp/elements/sections/send-message.tsx @@ -18,7 +18,7 @@ import { useIsMountedRef, useOneTimeAsyncAction, } from '../require/react-helper'; -import * as FileType from 'file-type'; +import { fromBuffer as fileTypeFromBuffer } from 'file-type'; import ElementsUtil from '../require/elements-util'; import FileInput from '../components/input-file'; @@ -33,7 +33,7 @@ const AttachmentPreview: FC = (props: AttachmentPreviewP const [attachmentImgSrc] = useOneTimeAsyncAction( async () => { - const type = await FileType.fromBuffer(attachmentBuff); + const type = await fileTypeFromBuffer(attachmentBuff); if (!type) return './img/file-improved.svg'; if (type.mime === 'image/gif' || type.mime === 'image/jpeg' || type.mime === 'image/png') { // show a preview of the image diff --git a/src/client/webapp/guilds-manager.ts b/src/client/webapp/guilds-manager.ts index 7064536..ef53455 100644 --- a/src/client/webapp/guilds-manager.ts +++ b/src/client/webapp/guilds-manager.ts @@ -106,7 +106,7 @@ export default class GuildsManager extends EventEmitter<{ }); try { // create a new Public/Private key pair to identify ourselves with this guild - const { publicKey, privateKey } = await new Promise((resolve, reject) => { + const { publicKey, privateKey } = await new Promise<{ publicKey: crypto.KeyObject, privateKey: crypto.KeyObject }>((resolve, reject) => { crypto.generateKeyPair('rsa', { modulusLength: 4096 }, (err, publicKey, privateKey) => { if (err) { reject(err); diff --git a/src/logger/logger.ts b/src/logger/logger.ts index a92d876..4ba666f 100644 --- a/src/logger/logger.ts +++ b/src/logger/logger.ts @@ -106,15 +106,15 @@ async function getStaticSourceMaps(): Promise> { ) continue; // make sure .map file exists const fileBuff = await fs.readFile(file + '.map'); - if (URL && URL.createObjectURL) { + if (URL && (URL.createObjectURL)) { // only run this stuff if we are running in a browser window const mappingsWasmBuffer = await fs.readFile( path.join(__dirname, '../../node_modules/source-map/lib/mappings.wasm'), ); const mappingsWasmBlob = new Blob([mappingsWasmBuffer], { type: 'application/wasm' }); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore Typescript is missing this function... Probably because it is static - SourceMapConsumer.initialize({ 'lib/mappings.wasm': URL.createObjectURL(mappingsWasmBlob) }); + // xx eslint-disable-next-line @typescript-eslint/ban-ts-comment + // xx @ts-ignore Typescript is missing this function... Probably because it is static + // xx SourceMapConsumer.initialize({ 'lib/mappings.wasm': URL.createObjectURL(mappingsWasmBlob) }); } const sourceMapConsumer = await new SourceMapConsumer(fileBuff.toString()); sourceMaps.set(file, sourceMapConsumer); diff --git a/src/server/scripts/create-cordis-file.ts b/src/server/scripts/create-cordis-file.ts index 00c66a8..4684094 100644 --- a/src/server/scripts/create-cordis-file.ts +++ b/src/server/scripts/create-cordis-file.ts @@ -1,7 +1,7 @@ import * as fs from 'fs/promises'; import * as path from 'path'; -import * as FileType from 'file-type'; +import { fromBuffer as fileTypeFromBuffer } from 'file-type'; import { ExitCodes, ExitCode } from '../../exit-codes/exit-codes'; import Logger from '../../logger/logger'; @@ -21,7 +21,7 @@ process.on('unhandledRejection', async (reason, _promise) => { // from ElementsUtil async function getImageBufferSrc(buffer: Buffer) { - const result = await FileType.fromBuffer(buffer); + const result = await fileTypeFromBuffer(buffer); switch (result && result.mime) { case 'image/png': case 'image/jpeg': diff --git a/src/server/server-controller.ts b/src/server/server-controller.ts index f58f20e..069688c 100644 --- a/src/server/server-controller.ts +++ b/src/server/server-controller.ts @@ -6,7 +6,7 @@ import * as crypto from 'crypto'; import moment from 'moment'; import sizeOf from 'image-size'; -import * as FileType from 'file-type'; +import { fromBuffer as fileTypeFromBuffer } from 'file-type'; import sharp from 'sharp'; import * as socketio from 'socket.io'; @@ -184,7 +184,7 @@ function bindRegistrationEvents(io: socketio.Server, client: socketio.Socket): v throw new EventError('invalid avatar'); } - const typeResult = await FileType.fromBuffer(avatarBuff); + const typeResult = await fileTypeFromBuffer(avatarBuff); if (!typeResult || ['image/png', 'image/jpeg', 'image/jpg'].indexOf(typeResult.mime) === -1) { throw new EventError('invalid avatar mime type'); } @@ -370,7 +370,7 @@ function bindAdminEvents(io: socketio.Server, client: socketio.Socket, identity: LOG.debug(`g#${identity.guildId} u#${identity.memberId?.slice(0, 4)} set-icon`); - const typeResult = await FileType.fromBuffer(iconBuff); + const typeResult = await fileTypeFromBuffer(iconBuff); if (!typeResult || !['image/png', 'image/jpeg', 'image/jpg'].includes(typeResult.mime)) { throw new EventError('detected invalid mime type'); } @@ -601,7 +601,7 @@ function bindActionEvents(io: socketio.Server, client: socketio.Socket, identity ); // try to get the dimensions of the resource if it is an image so that we can scale it down for the preview - const fileType = (await FileType.fromBuffer(resource)) ?? { mime: null, ext: null }; + const fileType = (await fileTypeFromBuffer(resource)) ?? { mime: null, ext: null }; const dimensions: { width: number | null; height: number | null } = { width: null, height: null }; @@ -758,7 +758,7 @@ function bindActionEvents(io: socketio.Server, client: socketio.Socket, identity return; } - const typeResult = (await FileType.fromBuffer(avatarBuff)) ?? { mime: null, ext: null }; + const typeResult = (await fileTypeFromBuffer(avatarBuff)) ?? { mime: null, ext: null }; if ((['image/png', 'image/jpeg', 'image/jpg'] as (string | null)[]).indexOf(typeResult.mime) === -1) { throw new EventError('invalid avatar buffer'); }