mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-10 15:13:02 -04:00
Path aliases, better lazyWebpack (#268)
This commit is contained in:
parent
7a4402f142
commit
bad96b7887
138 changed files with 572 additions and 547 deletions
|
@ -16,31 +16,33 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { LazyComponent } from "@utils/misc";
|
||||
import { proxyLazy } from "@utils/proxyLazy";
|
||||
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";
|
||||
import { _resolveReady, filters, findByCode, findByCodeLazy, findByPropsLazy, 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 RestAPI = lazyWebpack(filters.byProps("getAPIBaseURL", "get"));
|
||||
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<Stores.MessageStore, "getMessages"> & { 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<Stores.MessageStore, "getMessages"> & {
|
||||
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;
|
||||
|
@ -121,7 +123,7 @@ export const Toasts = {
|
|||
};
|
||||
|
||||
export const UserUtils = {
|
||||
fetchUser: lazyWebpack(filters.byCode(".USER(", "getUser")) as (id: string) => Promise<User>,
|
||||
fetchUser: findByCodeLazy(".USER(", "getUser") as (id: string) => Promise<User>,
|
||||
};
|
||||
|
||||
export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', {
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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[];
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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");
|
||||
|
||||
|
@ -113,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);
|
||||
|
@ -291,6 +298,13 @@ 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
|
||||
*/
|
||||
|
@ -305,6 +319,13 @@ export function findByCode(...code: string[]) {
|
|||
return find(filters.byCode(...code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue