Make some dependencies optional: probe-image-size, source-map-support (#11247)

This commit is contained in:
Slayer95 2025-07-14 05:01:41 -05:00 committed by GitHub
parent 3b7b1d2864
commit 0b6c1dbeec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 11 deletions

10
package-lock.json generated
View File

@ -14,9 +14,7 @@
"mysql2": "^3.9.7",
"preact": "^10.5.15",
"preact-render-to-string": "^6.5.13",
"probe-image-size": "^7.2.3",
"sockjs": "^0.3.21",
"source-map-support": "^0.5.21",
"ts-chacha20": "^1.2.0"
},
"bin": {
@ -50,6 +48,8 @@
"nodemailer": "^6.4.6",
"permessage-deflate": "^0.1.7",
"pg": "^8.11.3",
"probe-image-size": "^7.2.3",
"source-map-support": "^0.5.21",
"sql-template-strings": "^2.2.2",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
@ -3893,7 +3893,8 @@
"lodash.merge": "^4.6.2",
"needle": "^2.5.2",
"stream-parser": "~0.3.1"
}
},
"optional": true
},
"node_modules/promise-inflight": {
"version": "1.0.1",
@ -7822,7 +7823,8 @@
"requires": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"optional": true
},
"split2": {
"version": "4.1.0",

View File

@ -9,9 +9,7 @@
"mysql2": "^3.9.7",
"preact": "^10.5.15",
"preact-render-to-string": "^6.5.13",
"probe-image-size": "^7.2.3",
"sockjs": "^0.3.21",
"source-map-support": "^0.5.21",
"ts-chacha20": "^1.2.0"
},
"optionalDependencies": {
@ -22,6 +20,8 @@
"nodemailer": "^6.4.6",
"permessage-deflate": "^0.1.7",
"pg": "^8.11.3",
"probe-image-size": "^7.2.3",
"source-map-support": "^0.5.21",
"sql-template-strings": "^2.2.2",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",

View File

@ -162,9 +162,11 @@ const MAX_PLUGIN_LOADING_DEPTH = 3;
import { formatText, linkRegex, stripFormatting } from './chat-formatter';
// @ts-expect-error no typedef available
import ProbeModule = require('probe-image-size');
const probe: (url: string) => Promise<{ width: number, height: number }> = ProbeModule;
let probe: null | ((url: string) => Promise<{ width: number, height: number }>) = null;
try {
probe = require('probe-image-size');
} catch {}
const EMOJI_REGEX = /[\p{Emoji_Modifier_Base}\p{Emoji_Presentation}\uFE0F]/u;
@ -2512,6 +2514,12 @@ export const Chat = new class {
* Gets the dimension of the image at url. Returns 0x0 if the image isn't found, as well as the relevant error.
*/
getImageDimensions(url: string): Promise<{ height: number, width: number }> {
if (Config.noNetRequests) {
return Promise.reject(new Error(`Net requests are disabled.`));
}
if (!probe) {
return Promise.reject(new Error(`Images not supported.`));
}
return probe(url);
}

View File

@ -43,7 +43,11 @@
*
* @license MIT
*/
require('source-map-support').install();
try {
require('source-map-support').install();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
}
// NOTE: This file intentionally doesn't use too many modern JavaScript
// features, so that it doesn't crash old versions of Node.js, so we
// can successfully print the "We require Node.js 18+" message.

View File

@ -1362,7 +1362,9 @@ export const PM = new ProcessManager.StreamProcessManager(module, () => new Room
if (!PM.isParentProcess) {
// This is a child process!
require('source-map-support').install();
try {
require('source-map-support').install();
} catch {}
global.Config = require('./config-loader').Config;
global.Dex = require('../sim/dex').Dex;
global.Monitor = {