(factory: () => T): T {
diff --git a/src/utils/quickCss.ts b/src/utils/quickCss.ts
index 0ce1f588e..1f9f235f5 100644
--- a/src/utils/quickCss.ts
+++ b/src/utils/quickCss.ts
@@ -16,7 +16,8 @@
* along with this program. If not, see .
*/
-import { addSettingsListener, Settings } from "../api/settings";
+import { addSettingsListener, Settings } from "@api/settings";
+
import IpcEvents from "./IpcEvents";
let style: HTMLStyleElement;
diff --git a/src/utils/settingsSync.ts b/src/utils/settingsSync.ts
index ecf66652a..5cd81e7e4 100644
--- a/src/utils/settingsSync.ts
+++ b/src/utils/settingsSync.ts
@@ -16,7 +16,8 @@
* along with this program. If not, see .
*/
-import { Toasts } from "../webpack/common";
+import { Toasts } from "@webpack/common";
+
import IpcEvents from "./IpcEvents";
import Logger from "./Logger";
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 30c603f4d..310fbea08 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -16,10 +16,9 @@
* along with this program. If not, see .
*/
+import { Command } from "@api/Commands";
import { Promisable } from "type-fest";
-import { Command } from "../api/Commands";
-
// exists to export default definePlugin({...})
export default function definePlugin(p: P & Record) {
return p;
diff --git a/src/webpack/common.tsx b/src/webpack/common.tsx
index 426b183df..318cd02fe 100644
--- a/src/webpack/common.tsx
+++ b/src/webpack/common.tsx
@@ -16,30 +16,35 @@
* along with this program. If not, see .
*/
+import { LazyComponent } from "@utils/misc";
+import { proxyLazy } from "@utils/proxyLazy";
+import {
+ _resolveReady,
+ filters, findByCode, findByCodeLazy, findByPropsLazy, mapMangledModule, mapMangledModuleLazy, waitFor
+} from "@webpack";
import type Components from "discord-types/components";
import { User } from "discord-types/general";
import type Other from "discord-types/other";
import type Stores from "discord-types/stores";
-import { LazyComponent, lazyWebpack } from "../utils/misc";
-import { proxyLazy } from "../utils/proxyLazy";
-import { _resolveReady, filters, findByCode, mapMangledModule, mapMangledModuleLazy, waitFor } from "./webpack";
-
-export const Margins = lazyWebpack(filters.byProps("marginTop20"));
+export const Margins = findByPropsLazy("marginTop20");
export let FluxDispatcher: Other.FluxDispatcher;
-export const Flux = lazyWebpack(filters.byProps("connectStores"));
+export const Flux = findByPropsLazy("connectStores");
export let React: typeof import("react");
-export const ReactDOM: typeof import("react-dom") = lazyWebpack(filters.byProps("createPortal", "render"));
+export const ReactDOM: typeof import("react-dom") = findByPropsLazy("createPortal", "render");
-export const moment: typeof import("moment") = lazyWebpack(filters.byProps("parseTwoDigitYear"));
+export const RestAPI = findByPropsLazy("getAPIBaseURL", "get");
+export const moment: typeof import("moment") = findByPropsLazy("parseTwoDigitYear");
-export const MessageStore = lazyWebpack(filters.byProps("getRawMessages")) as Omit & { getMessages(chanId: string): any; };
-export const PermissionStore = lazyWebpack(filters.byProps("can", "getGuildPermissions"));
-export const PrivateChannelsStore = lazyWebpack(filters.byProps("openPrivateChannel"));
-export const GuildChannelStore = lazyWebpack(filters.byProps("getChannels"));
-export const ReadStateStore = lazyWebpack(filters.byProps("lastMessageId"));
-export const PresenceStore = lazyWebpack(filters.byProps("setCurrentUserOnConnectionOpen"));
+export const MessageStore = findByPropsLazy("getRawMessages") as Omit & {
+ getMessages(chanId: string): any;
+};
+export const PermissionStore = findByPropsLazy("can", "getGuildPermissions");
+export const PrivateChannelsStore = findByPropsLazy("openPrivateChannel");
+export const GuildChannelStore = findByPropsLazy("getChannels");
+export const ReadStateStore = findByPropsLazy("lastMessageId");
+export const PresenceStore = findByPropsLazy("setCurrentUserOnConnectionOpen");
export let GuildStore: Stores.GuildStore;
export let UserStore: Stores.UserStore;
export let SelectedChannelStore: Stores.SelectedChannelStore;
@@ -120,7 +125,7 @@ export const Toasts = {
};
export const UserUtils = {
- fetchUser: lazyWebpack(filters.byCode(".USER(", "getUser")) as (id: string) => Promise,
+ fetchUser: findByCodeLazy(".USER(", "getUser") as (id: string) => Promise,
};
export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', {
@@ -194,7 +199,7 @@ export type TextProps = React.PropsWithChildren & {
className?: string;
};
-export type TextVariant = "heading-sm/normal" | "heading-sm/medium" | "heading-sm/bold" | "heading-md/normal" | "heading-md/medium" | "heading-md/bold" | "heading-lg/normal" | "heading-lg/medium" | "heading-lg/bold" | "heading-xl/normal" | "heading-xl/medium" | "heading-xl/bold" | "heading-xxl/normal" | "heading-xxl/medium" | "heading-xxl/bold" | "eyebrow" | "heading-deprecated-14/normal" | "heading-deprecated-14/medium" | "heading-deprecated-14/bold" | "text-xxs/normal" | "text-xxs/medium" | "text-xxs/semibold" | "text-xxs/bold" | "text-xs/normal" | "text-xs/medium" | "text-xs/semibold" | "text-xs/bold" | "text-sm/normal" | "text-sm/medium" | "text-sm/semibold" | "text-sm/bold" | "text-md/normal" | "text-md/medium" | "text-md/semibold" | "text-md/bold" | "text-lg/normal" | "text-lg/medium" | "text-lg/semibold" | "text-lg/bold" | "display-md" | "display-lg" | "code";
+export type TextVariant = "heading-sm/normal" | "heading-sm/medium" | "heading-sm/bold" | "heading-md/normal" | "heading-md/medium" | "heading-md/bold" | "heading-lg/normal" | "heading-lg/medium" | "heading-lg/bold" | "heading-xl/normal" | "heading-xl/medium" | "heading-xl/bold" | "heading-xxl/normal" | "heading-xxl/medium" | "heading-xxl/bold" | "eyebrow" | "heading-deprecated-14/normal" | "heading-deprecated-14/medium" | "heading-deprecated-14/bold" | "text-xxs/normal" | "text-xxs/medium" | "text-xxs/semibold" | "text-xxs/bold" | "text-xs/normal" | "text-xs/medium" | "text-xs/semibold" | "text-xs/bold" | "text-sm/normal" | "text-sm/medium" | "text-sm/semibold" | "text-sm/bold" | "text-md/normal" | "text-md/medium" | "text-md/semibold" | "text-md/bold" | "text-lg/normal" | "text-lg/medium" | "text-lg/semibold" | "text-lg/bold" | "display-sm" | "display-md" | "display-lg" | "code";
type RC = React.ComponentType>>;
interface Menu {
diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts
index e17ddfcfc..273a0623f 100644
--- a/src/webpack/patchWebpack.ts
+++ b/src/webpack/patchWebpack.ts
@@ -16,8 +16,9 @@
* along with this program. If not, see .
*/
-import { WEBPACK_CHUNK } from "../utils/constants";
-import Logger from "../utils/Logger";
+import { WEBPACK_CHUNK } from "@utils/constants";
+import Logger from "@utils/Logger";
+
import { _initWebpack } from ".";
let webpackChunk: any[];
diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts
index 1231d9e4c..0bbd81506 100644
--- a/src/webpack/webpack.ts
+++ b/src/webpack/webpack.ts
@@ -16,11 +16,11 @@
* along with this program. If not, see .
*/
+import Logger from "@utils/Logger";
+import { proxyLazy } from "@utils/proxyLazy";
import type { WebpackInstance } from "discord-types/other";
import { traceFunction } from "../debug/Tracer";
-import Logger from "../utils/Logger";
-import { proxyLazy } from "../utils/proxyLazy";
const logger = new Logger("Webpack");
@@ -42,8 +42,6 @@ export const filters = {
? m => m[props[0]] !== void 0
: m => props.every(p => m[p] !== void 0),
- byDisplayName: (deezNuts: string): FilterFn => m => m.default?.displayName === deezNuts,
-
byCode: (...code: string[]): FilterFn => m => {
if (typeof m !== "function") return false;
const s = Function.prototype.toString.call(m);
@@ -75,6 +73,9 @@ if (IS_DEV && !IS_WEB) {
}, 0);
}
+/**
+ * Find the first module that matches the filter
+ */
export const find = traceFunction("find", function find(filter: FilterFn, getDefault = true, isWaitFor = false) {
if (typeof filter !== "function")
throw new Error("Invalid filter. Expected a function got " + typeof filter);
@@ -112,6 +113,13 @@ export const find = traceFunction("find", function find(filter: FilterFn, getDef
return null;
});
+/**
+ * find but lazy
+ */
+export function findLazy(filter: FilterFn, getDefault = true) {
+ return proxyLazy(() => find(filter, getDefault));
+}
+
export function findAll(filter: FilterFn, getDefault = true) {
if (typeof filter !== "function")
throw new Error("Invalid filter. Expected a function got " + typeof filter);
@@ -283,22 +291,45 @@ export function mapMangledModuleLazy(code: string, mappers: Re
return proxyLazy(() => mapMangledModule(code, mappers));
}
+/**
+ * Find the first module that has the specified properties
+ */
export function findByProps(...props: string[]) {
return find(filters.byProps(...props));
}
+/**
+ * findByProps but lazy
+ */
+export function findByPropsLazy(...props: string[]) {
+ return findLazy(filters.byProps(...props));
+}
+
+/**
+ * Find all modules that have the specified properties
+ */
export function findAllByProps(...props: string[]) {
return findAll(filters.byProps(...props));
}
+/**
+ * Find a function by its code
+ */
export function findByCode(...code: string[]) {
return find(filters.byCode(...code));
}
-export function findByDisplayName(deezNuts: string) {
- return find(filters.byDisplayName(deezNuts));
+/**
+ * findByCode but lazy
+ */
+export function findByCodeLazy(...code: string[]) {
+ return findLazy(filters.byCode(...code));
}
+/**
+ * Wait for a module that matches the provided filter to be registered,
+ * then call the callback with the module as the first argument
+ */
export function waitFor(filter: string | string[] | FilterFn, callback: CallbackFn) {
if (typeof filter === "string")
filter = filters.byProps(filter);
diff --git a/tsconfig.json b/tsconfig.json
index aa1253296..a55c1fe36 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -14,7 +14,16 @@
"strict": true,
"noImplicitAny": false,
"target": "ESNEXT",
- "jsx": "preserve"
+ "jsx": "preserve",
+
+ "baseUrl": "./src/",
+ "paths": {
+ "@webpack": ["./webpack"],
+ "@webpack/common": ["./webpack/common"],
+ "@utils/*": ["./utils/*"],
+ "@api/*": ["./api/*"],
+ "@components/*": ["./components/*"]
+ }
},
"include": ["src/**/*"]
}