From f7d9be91407582fd85a70eef89c03a32e37c3c0f Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 7 Nov 2022 23:34:14 +0100 Subject: lint: Disallow utils index imports This keeps leading to issues due to circular imports. Import from specific files instead, index just reexports --- .eslintrc.json | 49 ++++++- package.json | 1 + pnpm-lock.yaml | 141 ++++++++++++++++++++- src/Vencord.ts | 11 +- src/components/ErrorBoundary.tsx | 2 +- src/components/Monaco.ts | 2 +- src/components/PatchHelper.tsx | 2 +- src/components/PluginSettings/PluginModal.tsx | 3 +- src/components/PluginSettings/index.tsx | 5 +- src/plugins/experiments.tsx | 2 +- src/plugins/ignoreActivities.ts | 2 +- src/plugins/messageActions.ts | 2 +- src/plugins/nitroBypass.ts | 2 +- src/plugins/petpet.ts | 2 +- .../pronoundb/components/PronounsChatComponent.tsx | 2 +- .../components/PronounsProfileWrapper.tsx | 4 +- src/plugins/pronoundb/pronoundbUtils.ts | 94 ++++++++++++++ src/plugins/pronoundb/utils.ts | 94 -------------- src/plugins/sendify.ts | 2 +- src/plugins/spotifyControls/PlayerComponent.tsx | 3 +- src/plugins/spotifyControls/SpotifyStore.ts | 4 +- src/plugins/startupTimings/StartupTimingPage.tsx | 4 +- src/plugins/startupTimings/index.tsx | 2 +- 23 files changed, 311 insertions(+), 124 deletions(-) create mode 100644 src/plugins/pronoundb/pronoundbUtils.ts delete mode 100644 src/plugins/pronoundb/utils.ts diff --git a/.eslintrc.json b/.eslintrc.json index d10b872..111648c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,12 @@ "root": true, "parser": "@typescript-eslint/parser", "ignorePatterns": ["dist", "browser"], - "plugins": ["header", "simple-import-sort", "unused-imports"], + "plugins": [ + "@typescript-eslint", + "header", + "simple-import-sort", + "unused-imports" + ], "rules": { // Since it's only been a month and Vencord has already been stolen // by random skids who rebranded it to "AlphaCord" and erased all license @@ -88,6 +93,46 @@ "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", - "unused-imports/no-unused-imports": "error" + "unused-imports/no-unused-imports": "error", + + "@typescript-eslint/no-restricted-imports": [ + "error", + { + "paths": [ + // shrug, couldn't find a better way since the pattern one doesn't work: + // ["utils", "!utils/*"] + { + "name": "./utils", + "message": "Do not import from index. This might cause issues. Import from the specific file instead.", + "allowTypeImports": true + }, + { + "name": "../utils", + "message": "Do not import from index. This might cause issues. Import from the specific file instead.", + "allowTypeImports": true + }, + { + "name": "../../utils", + "message": "Do not import from index. This might cause issues. Import from the specific file instead.", + "allowTypeImports": true + }, + { + "name": "../../../utils", + "message": "Do not import from index. This might cause issues. Import from the specific file instead.", + "allowTypeImports": true + }, + { + "name": "../../../../utils", + "message": "Do not import from index. This might cause issues. Import from the specific file instead.", + "allowTypeImports": true + }, + { + "name": "../../../../../utils", + "message": "Do not import from index. This might cause issues. Import from the specific file instead.", + "allowTypeImports": true + } + ] + } + ] } } diff --git a/package.json b/package.json index 0382b67..a3958b1 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@types/react": "^18.0.17", "@types/react-dom": "^18.0.8", "@types/yazl": "^2.4.2", + "@typescript-eslint/eslint-plugin": "^5.42.1", "@typescript-eslint/parser": "^5.39.0", "discord-types": "^1.3.26", "esbuild": "^0.15.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be5228e..c7fa096 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ specifiers: '@types/react': ^18.0.17 '@types/react-dom': ^18.0.8 '@types/yazl': ^2.4.2 + '@typescript-eslint/eslint-plugin': ^5.42.1 '@typescript-eslint/parser': ^5.39.0 console-menu: ^0.1.0 diff: ^5.1.0 @@ -31,13 +32,14 @@ devDependencies: '@types/react': 18.0.17 '@types/react-dom': 18.0.8 '@types/yazl': 2.4.2 + '@typescript-eslint/eslint-plugin': 5.42.1_xyciw6oqjoiiono4dhv3uhn5my '@typescript-eslint/parser': 5.39.0_ypn2ylkkyfa5i233caldtndbqa discord-types: 1.3.26 esbuild: 0.15.5 eslint: 8.24.0 eslint-plugin-header: 3.1.1_eslint@8.24.0 eslint-plugin-simple-import-sort: 8.0.0_eslint@8.24.0 - eslint-plugin-unused-imports: 2.0.0_eslint@8.24.0 + eslint-plugin-unused-imports: 2.0.0_5yz3upex2kb6hbdwaq7bihlxnq standalone-electron-types: 1.0.0 type-fest: 3.1.0 typescript: 4.8.4 @@ -119,6 +121,10 @@ packages: resolution: {integrity: sha512-uw8eYMIReOwstQ0QKF0sICefSy8cNO/v7gOTiIy9SbwuHyEecJUm7qlgueOO5S1udZ5I/irVydHVwMchgzbKTg==} dev: true + /@types/json-schema/7.0.11: + resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} + dev: true + /@types/node/18.7.13: resolution: {integrity: sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==} dev: true @@ -156,12 +162,43 @@ packages: resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==} dev: true + /@types/semver/7.3.13: + resolution: {integrity: sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==} + dev: true + /@types/yazl/2.4.2: resolution: {integrity: sha512-T+9JH8O2guEjXNxqmybzQ92mJUh2oCwDDMSSimZSe1P+pceZiFROZLYmcbqkzV5EUwz6VwcKXCO2S2yUpra6XQ==} dependencies: '@types/node': 18.7.13 dev: true + /@typescript-eslint/eslint-plugin/5.42.1_xyciw6oqjoiiono4dhv3uhn5my: + resolution: {integrity: sha512-LyR6x784JCiJ1j6sH5Y0K6cdExqCCm8DJUTcwG5ThNXJj/G8o5E56u5EdG4SLy+bZAwZBswC+GYn3eGdttBVCg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + '@typescript-eslint/parser': ^5.0.0 + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/parser': 5.39.0_ypn2ylkkyfa5i233caldtndbqa + '@typescript-eslint/scope-manager': 5.42.1 + '@typescript-eslint/type-utils': 5.42.1_ypn2ylkkyfa5i233caldtndbqa + '@typescript-eslint/utils': 5.42.1_ypn2ylkkyfa5i233caldtndbqa + debug: 4.3.4 + eslint: 8.24.0 + ignore: 5.2.0 + natural-compare-lite: 1.4.0 + regexpp: 3.2.0 + semver: 7.3.7 + tsutils: 3.21.0_typescript@4.8.4 + typescript: 4.8.4 + transitivePeerDependencies: + - supports-color + dev: true + /@typescript-eslint/parser/5.39.0_ypn2ylkkyfa5i233caldtndbqa: resolution: {integrity: sha512-PhxLjrZnHShe431sBAGHaNe6BDdxAASDySgsBCGxcBecVCi8NQWxQZMcizNA4g0pN51bBAn/FUfkWG3SDVcGlA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -190,11 +227,44 @@ packages: '@typescript-eslint/visitor-keys': 5.39.0 dev: true + /@typescript-eslint/scope-manager/5.42.1: + resolution: {integrity: sha512-QAZY/CBP1Emx4rzxurgqj3rUinfsh/6mvuKbLNMfJMMKYLRBfweus8brgXF8f64ABkIZ3zdj2/rYYtF8eiuksQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + '@typescript-eslint/types': 5.42.1 + '@typescript-eslint/visitor-keys': 5.42.1 + dev: true + + /@typescript-eslint/type-utils/5.42.1_ypn2ylkkyfa5i233caldtndbqa: + resolution: {integrity: sha512-WWiMChneex5w4xPIX56SSnQQo0tEOy5ZV2dqmj8Z371LJ0E+aymWD25JQ/l4FOuuX+Q49A7pzh/CGIQflxMVXg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: '*' + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.8.4 + '@typescript-eslint/utils': 5.42.1_ypn2ylkkyfa5i233caldtndbqa + debug: 4.3.4 + eslint: 8.24.0 + tsutils: 3.21.0_typescript@4.8.4 + typescript: 4.8.4 + transitivePeerDependencies: + - supports-color + dev: true + /@typescript-eslint/types/5.39.0: resolution: {integrity: sha512-gQMZrnfEBFXK38hYqt8Lkwt8f4U6yq+2H5VDSgP/qiTzC8Nw8JO3OuSUOQ2qW37S/dlwdkHDntkZM6SQhKyPhw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true + /@typescript-eslint/types/5.42.1: + resolution: {integrity: sha512-Qrco9dsFF5lhalz+lLFtxs3ui1/YfC6NdXu+RAGBa8uSfn01cjO7ssCsjIsUs484vny9Xm699FSKwpkCcqwWwA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + /@typescript-eslint/typescript-estree/5.39.0_typescript@4.8.4: resolution: {integrity: sha512-qLFQP0f398sdnogJoLtd43pUgB18Q50QSA+BTE5h3sUxySzbWDpTSdgt4UyxNSozY/oDK2ta6HVAzvGgq8JYnA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -216,6 +286,47 @@ packages: - supports-color dev: true + /@typescript-eslint/typescript-estree/5.42.1_typescript@4.8.4: + resolution: {integrity: sha512-qElc0bDOuO0B8wDhhW4mYVgi/LZL+igPwXtV87n69/kYC/7NG3MES0jHxJNCr4EP7kY1XVsRy8C/u3DYeTKQmw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 5.42.1 + '@typescript-eslint/visitor-keys': 5.42.1 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + semver: 7.3.7 + tsutils: 3.21.0_typescript@4.8.4 + typescript: 4.8.4 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/utils/5.42.1_ypn2ylkkyfa5i233caldtndbqa: + resolution: {integrity: sha512-Gxvf12xSp3iYZd/fLqiQRD4uKZjDNR01bQ+j8zvhPjpsZ4HmvEFL/tC4amGNyxN9Rq+iqvpHLhlqx6KTxz9ZyQ==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + dependencies: + '@types/json-schema': 7.0.11 + '@types/semver': 7.3.13 + '@typescript-eslint/scope-manager': 5.42.1 + '@typescript-eslint/types': 5.42.1 + '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.8.4 + eslint: 8.24.0 + eslint-scope: 5.1.1 + eslint-utils: 3.0.0_eslint@8.24.0 + semver: 7.3.7 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /@typescript-eslint/visitor-keys/5.39.0: resolution: {integrity: sha512-yyE3RPwOG+XJBLrhvsxAidUgybJVQ/hG8BhiJo0k8JSAYfk/CshVcxf0HwP4Jt7WZZ6vLmxdo1p6EyN3tzFTkg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -224,6 +335,14 @@ packages: eslint-visitor-keys: 3.3.0 dev: true + /@typescript-eslint/visitor-keys/5.42.1: + resolution: {integrity: sha512-LOQtSF4z+hejmpUvitPlc4hA7ERGoj2BVkesOcG91HCn8edLGUXbTrErmutmPbl8Bo9HjAvOO/zBKQHExXNA2A==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + '@typescript-eslint/types': 5.42.1 + eslint-visitor-keys: 3.3.0 + dev: true + /acorn-jsx/5.3.2_acorn@8.8.0: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -605,7 +724,7 @@ packages: eslint: 8.24.0 dev: true - /eslint-plugin-unused-imports/2.0.0_eslint@8.24.0: + /eslint-plugin-unused-imports/2.0.0_5yz3upex2kb6hbdwaq7bihlxnq: resolution: {integrity: sha512-3APeS/tQlTrFa167ThtP0Zm0vctjr4M44HMpeg1P4bK6wItarumq0Ma82xorMKdFsWpphQBlRPzw/pxiVELX1A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -615,6 +734,7 @@ packages: '@typescript-eslint/eslint-plugin': optional: true dependencies: + '@typescript-eslint/eslint-plugin': 5.42.1_xyciw6oqjoiiono4dhv3uhn5my eslint: 8.24.0 eslint-rule-composer: 0.3.0 dev: true @@ -624,6 +744,14 @@ packages: engines: {node: '>=4.0.0'} dev: true + /eslint-scope/5.1.1: + resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} + engines: {node: '>=8.0.0'} + dependencies: + esrecurse: 4.3.0 + estraverse: 4.3.0 + dev: true + /eslint-scope/7.1.1: resolution: {integrity: sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -723,6 +851,11 @@ packages: estraverse: 5.3.0 dev: true + /estraverse/4.3.0: + resolution: {integrity: sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==} + engines: {node: '>=4.0'} + dev: true + /estraverse/5.3.0: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} @@ -983,6 +1116,10 @@ packages: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true + /natural-compare-lite/1.4.0: + resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} + dev: true + /natural-compare/1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: true diff --git a/src/Vencord.ts b/src/Vencord.ts index 041335f..464be2d 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -18,20 +18,19 @@ export * as Api from "./api"; export * as Plugins from "./plugins"; +// eslint-disable-next-line @typescript-eslint/no-restricted-imports export * as Util from "./utils"; export * as QuickCss from "./utils/quickCss"; export * as Updater from "./utils/updater"; export * as Webpack from "./webpack"; - -import { popNotice, showNotice } from "./api/Notices"; -import { PlainSettings, Settings } from "./api/settings"; -import { patches, PMLogger, startAllPlugins } from "./plugins"; - export { PlainSettings, Settings }; -import "./webpack/patchWebpack"; import "./utils/quickCss"; +import "./webpack/patchWebpack"; +import { popNotice, showNotice } from "./api/Notices"; +import { PlainSettings, Settings } from "./api/settings"; +import { patches, PMLogger, startAllPlugins } from "./plugins"; import { checkForUpdates, UpdateLogger } from "./utils/updater"; import { onceReady } from "./webpack"; import { Router } from "./webpack/common"; diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index aa1e889..4c2725d 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { LazyComponent } from "../utils"; import Logger from "../utils/logger"; +import { LazyComponent } from "../utils/misc"; import { Margins, React } from "../webpack/common"; import { ErrorCard } from "./ErrorCard"; diff --git a/src/components/Monaco.ts b/src/components/Monaco.ts index f40db77..16eff85 100644 --- a/src/components/Monaco.ts +++ b/src/components/Monaco.ts @@ -18,8 +18,8 @@ import monacoHtml from "~fileContent/monacoWin.html"; -import { IpcEvents } from "../utils"; import { debounce } from "../utils/debounce"; +import IpcEvents from "../utils/IpcEvents"; import { Queue } from "../utils/Queue"; import { find } from "../webpack/webpack"; diff --git a/src/components/PatchHelper.tsx b/src/components/PatchHelper.tsx index f32201a..82b804a 100644 --- a/src/components/PatchHelper.tsx +++ b/src/components/PatchHelper.tsx @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { makeCodeblock } from "../utils"; import { debounce } from "../utils/debounce"; +import { makeCodeblock } from "../utils/misc"; import { Button, Clipboard, Forms, Margins, Parser, React, Switch, TextInput } from "../webpack/common"; import { search } from "../webpack/webpack"; import { CheckedTextInput } from "./CheckedTextInput"; diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index 7dd609f..592b6cb 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -21,8 +21,9 @@ import { Constructor } from "type-fest"; import { generateId } from "../../api/Commands"; import { useSettings } from "../../api/settings"; -import { LazyComponent, lazyWebpack, proxyLazy } from "../../utils"; +import { LazyComponent, lazyWebpack } from "../../utils/misc"; import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "../../utils/modal"; +import { proxyLazy } from "../../utils/proxyLazy"; import { OptionType, Plugin } from "../../utils/types"; import { filters, findByCode } from "../../webpack"; import { Button, FluxDispatcher, Forms, React, Text, Tooltip, UserStore, UserUtils } from "../../webpack/common"; diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index 40f09d6..fef8c30 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -21,9 +21,10 @@ import Plugins from "~plugins"; import { showNotice } from "../../api/Notices"; import { Settings, useSettings } from "../../api/settings"; import { startDependenciesRecursive, startPlugin, stopPlugin } from "../../plugins"; -import { Logger, Modals } from "../../utils"; import { ChangeList } from "../../utils/ChangeList"; +import Logger from "../../utils/logger"; import { classes, LazyComponent, lazyWebpack } from "../../utils/misc"; +import { openModalLazy } from "../../utils/modal"; import { Plugin } from "../../utils/types"; import { filters, findByCode } from "../../webpack"; import { Alerts, Button, Forms, Margins, Parser, React, Select, Switch, Text, TextInput, Toasts, Tooltip } from "../../webpack/common"; @@ -88,7 +89,7 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe } function openModal() { - Modals.openModalLazy(async () => { + openModalLazy(async () => { return modalProps => { return onRestartNeeded(plugin.name)} />; }; diff --git a/src/plugins/experiments.tsx b/src/plugins/experiments.tsx index b9df6f9..861bb05 100644 --- a/src/plugins/experiments.tsx +++ b/src/plugins/experiments.tsx @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { lazyWebpack } from "../utils"; import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; import definePlugin, { OptionType } from "../utils/types"; import { Settings } from "../Vencord"; import { filters } from "../webpack"; diff --git a/src/plugins/ignoreActivities.ts b/src/plugins/ignoreActivities.ts index 5c1ddcc..2084277 100644 --- a/src/plugins/ignoreActivities.ts +++ b/src/plugins/ignoreActivities.ts @@ -17,8 +17,8 @@ */ import { DataStore } from "../api"; -import { lazyWebpack } from "../utils"; import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; import definePlugin from "../utils/types"; import { filters } from "../webpack"; diff --git a/src/plugins/messageActions.ts b/src/plugins/messageActions.ts index 98c920e..bb2ad17 100644 --- a/src/plugins/messageActions.ts +++ b/src/plugins/messageActions.ts @@ -17,8 +17,8 @@ */ import { addClickListener, removeClickListener } from "../api/MessageEvents"; -import { lazyWebpack } from "../utils"; import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; import definePlugin from "../utils/types"; import { filters } from "../webpack"; import { UserStore } from "../webpack/common"; diff --git a/src/plugins/nitroBypass.ts b/src/plugins/nitroBypass.ts index f4bdc84..d2e1e10 100644 --- a/src/plugins/nitroBypass.ts +++ b/src/plugins/nitroBypass.ts @@ -17,9 +17,9 @@ */ import { addPreEditListener, addPreSendListener, removePreEditListener, removePreSendListener } from "../api/MessageEvents"; -import { lazyWebpack } from "../utils"; import { Devs } from "../utils/constants"; import { ApngDisposeOp, getGifEncoder, importApngJs } from "../utils/dependencies"; +import { lazyWebpack } from "../utils/misc"; import definePlugin, { OptionType } from "../utils/types"; import { Settings } from "../Vencord"; import { filters } from "../webpack"; diff --git a/src/plugins/petpet.ts b/src/plugins/petpet.ts index 961d47a..59b4e56 100644 --- a/src/plugins/petpet.ts +++ b/src/plugins/petpet.ts @@ -17,9 +17,9 @@ */ import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, CommandContext, findOption } from "../api/Commands"; -import { lazyWebpack, makeLazy } from "../utils"; import { Devs } from "../utils/constants"; import { getGifEncoder } from "../utils/dependencies"; +import { lazyWebpack, makeLazy } from "../utils/misc"; import definePlugin from "../utils/types"; import { filters } from "../webpack"; diff --git a/src/plugins/pronoundb/components/PronounsChatComponent.tsx b/src/plugins/pronoundb/components/PronounsChatComponent.tsx index 2d20461..78cee48 100644 --- a/src/plugins/pronoundb/components/PronounsChatComponent.tsx +++ b/src/plugins/pronoundb/components/PronounsChatComponent.tsx @@ -22,8 +22,8 @@ import { classes, lazyWebpack, useAwaiter } from "../../../utils/misc"; import { Settings } from "../../../Vencord"; import { filters } from "../../../webpack"; import { UserStore } from "../../../webpack/common"; +import { fetchPronouns, formatPronouns } from "../pronoundbUtils"; import { PronounMapping } from "../types"; -import { fetchPronouns, formatPronouns } from "../utils"; const styles: Record = lazyWebpack(filters.byProps("timestampInline")); diff --git a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx index 3f0022e..4d12dd5 100644 --- a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx +++ b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -import { useAwaiter } from "../../../utils"; +import { useAwaiter } from "../../../utils/misc"; import { Settings } from "../../../Vencord"; import { UserStore } from "../../../webpack/common"; +import { fetchPronouns, formatPronouns } from "../pronoundbUtils"; import { PronounMapping, UserProfileProps } from "../types"; -import { fetchPronouns, formatPronouns } from "../utils"; export default function PronounsProfileWrapper(props: UserProfileProps, pronounsComponent: JSX.Element) { // Don't bother fetching bot or system users diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts new file mode 100644 index 0000000..73ec7b6 --- /dev/null +++ b/src/plugins/pronoundb/pronoundbUtils.ts @@ -0,0 +1,94 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { VENCORD_USER_AGENT } from "../../utils/constants"; +import { debounce } from "../../utils/debounce"; +import { Settings } from "../../Vencord"; +import { PronounsFormat } from "."; +import { PronounCode, PronounMapping, PronounsResponse } from "./types"; + +// A map of cached pronouns so the same request isn't sent twice +const cache: Record = {}; +// A map of ids and callbacks that should be triggered on fetch +const requestQueue: Record void)[]> = {}; + +// Executes all queued requests and calls their callbacks +const bulkFetch = debounce(async () => { + const ids = Object.keys(requestQueue); + const pronouns = await bulkFetchPronouns(ids); + for (const id of ids) { + // Call all callbacks for the id + requestQueue[id].forEach(c => c(pronouns[id])); + delete requestQueue[id]; + } +}); + +// Fetches the pronouns for one id, returning a promise that resolves if it was cached, or once the request is completed +export function fetchPronouns(id: string): Promise { + return new Promise(res => { + // If cached, return the cached pronouns + if (id in cache) res(cache[id]); + // If there is already a request added, then just add this callback to it + else if (id in requestQueue) requestQueue[id].push(res); + // If not already added, then add it and call the debounced function to make sure the request gets executed + else { + requestQueue[id] = [res]; + bulkFetch(); + } + }); +} + +async function bulkFetchPronouns(ids: string[]): Promise { + const params = new URLSearchParams(); + params.append("platform", "discord"); + params.append("ids", ids.join(",")); + + try { + const req = await fetch("https://pronoundb.org/api/v1/lookup-bulk?" + params.toString(), { + method: "GET", + headers: { + "Accept": "application/json", + "X-PronounDB-Source": VENCORD_USER_AGENT + } + }); + return await req.json() + .then((res: PronounsResponse) => { + Object.assign(cache, res); + return res; + }); + } catch (e) { + // If the request errors, treat it as if no pronouns were found for all ids, and log it + console.error("PronounDB fetching failed: ", e); + const dummyPronouns = Object.fromEntries(ids.map(id => [id, "unspecified"] as const)); + Object.assign(cache, dummyPronouns); + return dummyPronouns; + } +} + +export function formatPronouns(pronouns: PronounCode): string { + const { pronounsFormat } = Settings.plugins.PronounDB as { pronounsFormat: PronounsFormat, enabled: boolean; }; + // For capitalized pronouns, just return the mapping (it is by default capitalized) + if (pronounsFormat === PronounsFormat.Capitalized) return PronounMapping[pronouns]; + // If it is set to lowercase and a special code (any, ask, avoid), then just return the capitalized text + else if ( + pronounsFormat === PronounsFormat.Lowercase + && ["any", "ask", "avoid", "other"].includes(pronouns) + ) return PronounMapping[pronouns]; + // Otherwise (lowercase and not a special code), then convert the mapping to lowercase + else return PronounMapping[pronouns].toLowerCase(); +} diff --git a/src/plugins/pronoundb/utils.ts b/src/plugins/pronoundb/utils.ts deleted file mode 100644 index 73ec7b6..0000000 --- a/src/plugins/pronoundb/utils.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { VENCORD_USER_AGENT } from "../../utils/constants"; -import { debounce } from "../../utils/debounce"; -import { Settings } from "../../Vencord"; -import { PronounsFormat } from "."; -import { PronounCode, PronounMapping, PronounsResponse } from "./types"; - -// A map of cached pronouns so the same request isn't sent twice -const cache: Record = {}; -// A map of ids and callbacks that should be triggered on fetch -const requestQueue: Record void)[]> = {}; - -// Executes all queued requests and calls their callbacks -const bulkFetch = debounce(async () => { - const ids = Object.keys(requestQueue); - const pronouns = await bulkFetchPronouns(ids); - for (const id of ids) { - // Call all callbacks for the id - requestQueue[id].forEach(c => c(pronouns[id])); - delete requestQueue[id]; - } -}); - -// Fetches the pronouns for one id, returning a promise that resolves if it was cached, or once the request is completed -export function fetchPronouns(id: string): Promise { - return new Promise(res => { - // If cached, return the cached pronouns - if (id in cache) res(cache[id]); - // If there is already a request added, then just add this callback to it - else if (id in requestQueue) requestQueue[id].push(res); - // If not already added, then add it and call the debounced function to make sure the request gets executed - else { - requestQueue[id] = [res]; - bulkFetch(); - } - }); -} - -async function bulkFetchPronouns(ids: string[]): Promise { - const params = new URLSearchParams(); - params.append("platform", "discord"); - params.append("ids", ids.join(",")); - - try { - const req = await fetch("https://pronoundb.org/api/v1/lookup-bulk?" + params.toString(), { - method: "GET", - headers: { - "Accept": "application/json", - "X-PronounDB-Source": VENCORD_USER_AGENT - } - }); - return await req.json() - .then((res: PronounsResponse) => { - Object.assign(cache, res); - return res; - }); - } catch (e) { - // If the request errors, treat it as if no pronouns were found for all ids, and log it - console.error("PronounDB fetching failed: ", e); - const dummyPronouns = Object.fromEntries(ids.map(id => [id, "unspecified"] as const)); - Object.assign(cache, dummyPronouns); - return dummyPronouns; - } -} - -export function formatPronouns(pronouns: PronounCode): string { - const { pronounsFormat } = Settings.plugins.PronounDB as { pronounsFormat: PronounsFormat, enabled: boolean; }; - // For capitalized pronouns, just return the mapping (it is by default capitalized) - if (pronounsFormat === PronounsFormat.Capitalized) return PronounMapping[pronouns]; - // If it is set to lowercase and a special code (any, ask, avoid), then just return the capitalized text - else if ( - pronounsFormat === PronounsFormat.Lowercase - && ["any", "ask", "avoid", "other"].includes(pronouns) - ) return PronounMapping[pronouns]; - // Otherwise (lowercase and not a special code), then convert the mapping to lowercase - else return PronounMapping[pronouns].toLowerCase(); -} diff --git a/src/plugins/sendify.ts b/src/plugins/sendify.ts index 40836ad..b0fd52d 100644 --- a/src/plugins/sendify.ts +++ b/src/plugins/sendify.ts @@ -17,8 +17,8 @@ */ import { ApplicationCommandInputType, sendBotMessage } from "../api/Commands"; -import { lazyWebpack } from "../utils"; import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; import definePlugin from "../utils/types"; import { filters } from "../webpack"; import { FluxDispatcher } from "../webpack/common"; diff --git a/src/plugins/spotifyControls/PlayerComponent.tsx b/src/plugins/spotifyControls/PlayerComponent.tsx index 0e03121..15a7ef9 100644 --- a/src/plugins/spotifyControls/PlayerComponent.tsx +++ b/src/plugins/spotifyControls/PlayerComponent.tsx @@ -18,7 +18,8 @@ import ErrorBoundary from "../../components/ErrorBoundary"; import { Flex } from "../../components/Flex"; -import { classes, debounce, LazyComponent, lazyWebpack } from "../../utils"; +import { debounce } from "../../utils/debounce"; +import { classes, LazyComponent, lazyWebpack } from "../../utils/misc"; import { ContextMenu, FluxDispatcher, Forms, Menu, React, Tooltip } from "../../webpack/common"; import { filters, find } from "../../webpack/webpack"; import { SpotifyStore, Track } from "./SpotifyStore"; diff --git a/src/plugins/spotifyControls/SpotifyStore.ts b/src/plugins/spotifyControls/SpotifyStore.ts index d7d52bc..0dad503 100644 --- a/src/plugins/spotifyControls/SpotifyStore.ts +++ b/src/plugins/spotifyControls/SpotifyStore.ts @@ -18,7 +18,9 @@ import cssText from "~fileContent/styles.css"; -import { IpcEvents, lazyWebpack, proxyLazy } from "../../utils"; +import IpcEvents from "../../utils/IpcEvents"; +import { lazyWebpack } from "../../utils/misc"; +import { proxyLazy } from "../../utils/proxyLazy"; import { filters } from "../../webpack"; import { Flux, FluxDispatcher } from "../../webpack/common"; diff --git a/src/plugins/startupTimings/StartupTimingPage.tsx b/src/plugins/startupTimings/StartupTimingPage.tsx index f864138..7d8e86b 100644 --- a/src/plugins/startupTimings/StartupTimingPage.tsx +++ b/src/plugins/startupTimings/StartupTimingPage.tsx @@ -18,9 +18,9 @@ import ErrorBoundary from "../../components/ErrorBoundary"; import { Flex } from "../../components/Flex"; -import { lazyWebpack } from "../../utils"; -import { filters } from "../../webpack"; +import { lazyWebpack } from "../../utils/misc"; import { Forms, React } from "../../webpack/common"; +import { filters } from "../../webpack/webpack"; interface AppStartPerformance { prefix: string; diff --git a/src/plugins/startupTimings/index.tsx b/src/plugins/startupTimings/index.tsx index 3f121f7..d5493c1 100644 --- a/src/plugins/startupTimings/index.tsx +++ b/src/plugins/startupTimings/index.tsx @@ -17,8 +17,8 @@ */ -import { LazyComponent } from "../../utils"; import { Devs } from "../../utils/constants"; +import { LazyComponent } from "../../utils/misc"; import definePlugin from "../../utils/types"; export default definePlugin({ -- cgit