2024-05-22 09:08:40 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
2024-05-30 16:38:22 +00:00
|
|
|
* Copyright (c) 2024 Vendicated, Nuckyz and contributors
|
2024-05-22 09:08:40 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2024-05-23 06:10:59 +00:00
|
|
|
export type ModuleExports = any;
|
2024-05-22 09:08:40 +00:00
|
|
|
|
2024-05-23 06:10:59 +00:00
|
|
|
export type Module = {
|
2024-05-22 09:08:40 +00:00
|
|
|
id: PropertyKey;
|
|
|
|
loaded: boolean;
|
|
|
|
exports: ModuleExports;
|
|
|
|
};
|
|
|
|
|
2024-05-23 06:36:53 +00:00
|
|
|
/** exports can be anything, however initially it is always an empty object */
|
2024-05-24 11:23:41 +00:00
|
|
|
export type ModuleFactory = (this: ModuleExports, module: Module, exports: ModuleExports, require: WebpackRequire) => void;
|
2024-05-22 09:08:40 +00:00
|
|
|
|
2024-05-26 22:37:47 +00:00
|
|
|
export type WebpackQueues = unique symbol;
|
|
|
|
export type WebpackExports = unique symbol;
|
|
|
|
export type WebpackError = unique symbol;
|
|
|
|
|
2024-05-26 22:38:25 +00:00
|
|
|
export type AsyncModulePromise = Promise<ModuleExports> & {
|
2024-05-26 22:37:47 +00:00
|
|
|
[WebpackQueues]: (fnQueue: ((queue: any[]) => any)) => any;
|
|
|
|
[WebpackExports]: ModuleExports;
|
|
|
|
[WebpackError]?: any;
|
|
|
|
};
|
|
|
|
|
2024-05-23 06:10:59 +00:00
|
|
|
export type AsyncModuleBody = (
|
2024-05-26 22:37:47 +00:00
|
|
|
handleAsyncDependencies: (deps: AsyncModulePromise[]) =>
|
|
|
|
Promise<() => ModuleExports[]> | (() => ModuleExports[]),
|
2024-05-26 22:24:59 +00:00
|
|
|
asyncResult: (error?: any) => void
|
2024-05-22 09:08:40 +00:00
|
|
|
) => Promise<void>;
|
|
|
|
|
2024-05-23 06:10:59 +00:00
|
|
|
export type ChunkHandlers = {
|
2024-05-22 09:08:40 +00:00
|
|
|
/**
|
2024-05-26 23:22:03 +00:00
|
|
|
* Ensures the js file for this chunk is loaded, or starts to load if it's not.
|
2024-05-22 09:08:40 +00:00
|
|
|
* @param chunkId The chunk id
|
2024-05-26 23:22:03 +00:00
|
|
|
* @param promises The promises array to add the loading promise to
|
2024-05-22 09:08:40 +00:00
|
|
|
*/
|
2024-05-23 06:10:59 +00:00
|
|
|
j: (this: ChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void,
|
2024-05-22 09:08:40 +00:00
|
|
|
/**
|
2024-05-26 23:22:03 +00:00
|
|
|
* Ensures the css file for this chunk is loaded, or starts to load if it's not.
|
2024-05-22 09:08:40 +00:00
|
|
|
* @param chunkId The chunk id
|
2024-05-26 23:22:03 +00:00
|
|
|
* @param promises The promises array to add the loading promise to. This array will likely contain the promise of the js file too
|
2024-05-22 09:08:40 +00:00
|
|
|
*/
|
2024-05-23 06:10:59 +00:00
|
|
|
css: (this: ChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void,
|
2024-05-22 09:08:40 +00:00
|
|
|
};
|
|
|
|
|
2024-05-23 06:10:59 +00:00
|
|
|
export type ScriptLoadDone = (event: Event) => void;
|
2024-05-22 09:08:40 +00:00
|
|
|
|
2024-05-23 06:10:59 +00:00
|
|
|
export type OnChunksLoaded = ((this: WebpackRequire, result: any, chunkIds: PropertyKey[] | undefined | null, callback: () => any, priority: number) => any) & {
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Check if a chunk has been loaded */
|
2024-05-23 06:36:53 +00:00
|
|
|
j: (this: OnChunksLoaded, chunkId: PropertyKey) => boolean;
|
2024-05-22 09:08:40 +00:00
|
|
|
};
|
|
|
|
|
2024-06-02 21:46:03 +00:00
|
|
|
export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & {
|
2024-05-22 09:08:40 +00:00
|
|
|
/** The module factories, where all modules that have been loaded are stored (pre-loaded or loaded by lazy chunks) */
|
|
|
|
m: Record<PropertyKey, ModuleFactory>;
|
|
|
|
/** The module cache, where all modules which have been WebpackRequire'd are stored */
|
|
|
|
c: Record<PropertyKey, Module>;
|
|
|
|
/**
|
|
|
|
* Export star. Sets properties of "fromObject" to "toObject" as getters that return the value from "fromObject", like this:
|
|
|
|
* @example
|
|
|
|
* const fromObject = { a: 1 };
|
2024-05-26 10:00:03 +00:00
|
|
|
* Object.keys(fromObject).forEach(key => {
|
2024-05-26 22:51:34 +00:00
|
|
|
* if (key !== "default" && !Object.hasOwn(toObject, key)) {
|
2024-05-26 10:00:03 +00:00
|
|
|
* Object.defineProperty(toObject, key, {
|
|
|
|
* get: () => fromObject[key],
|
|
|
|
* enumerable: true
|
|
|
|
* });
|
|
|
|
* }
|
2024-05-22 09:08:40 +00:00
|
|
|
* });
|
|
|
|
* @returns fromObject
|
|
|
|
*/
|
2024-05-23 06:36:53 +00:00
|
|
|
es: (this: WebpackRequire, fromObject: Record<PropertyKey, any>, toObject: Record<PropertyKey, any>) => Record<PropertyKey, any>;
|
2024-05-22 09:08:40 +00:00
|
|
|
/**
|
2024-05-26 22:24:59 +00:00
|
|
|
* Creates an async module. A module that exports something that is a Promise, or requires an export from an async module.
|
2024-05-28 06:34:40 +00:00
|
|
|
*
|
2024-05-28 06:35:38 +00:00
|
|
|
* The body function must be an async function. "module.exports" will become an {@link AsyncModulePromise}.
|
2024-05-28 06:34:40 +00:00
|
|
|
*
|
2024-05-26 22:27:52 +00:00
|
|
|
* The body function will be called with a function to handle requires that import from an async module, and a function to resolve this async module. An example on how to handle async dependencies:
|
2024-05-26 22:24:59 +00:00
|
|
|
* @example
|
|
|
|
* const factory = (module, exports, wreq) => {
|
|
|
|
* wreq.a(module, async (handleAsyncDependencies, asyncResult) => {
|
|
|
|
* try {
|
|
|
|
* const asyncRequireA = wreq(...);
|
2024-05-28 06:35:38 +00:00
|
|
|
*
|
2024-05-26 22:24:59 +00:00
|
|
|
* const asyncDependencies = handleAsyncDependencies([asyncRequire]);
|
|
|
|
* const [requireAResult] = asyncDependencies.then != null ? (await asyncDependencies)() : asyncDependencies;
|
|
|
|
*
|
|
|
|
* // Use the required module
|
|
|
|
* console.log(requireAResult);
|
|
|
|
*
|
|
|
|
* // Mark this async module as resolved
|
|
|
|
* asyncResult();
|
|
|
|
* } catch(error) {
|
|
|
|
* // Mark this async module as rejected with an error
|
|
|
|
* asyncResult(error);
|
|
|
|
* }
|
|
|
|
* }, false); // false because our module does not have an await after dealing with the async requires
|
|
|
|
* }
|
2024-05-22 09:08:40 +00:00
|
|
|
*/
|
2024-05-23 06:10:59 +00:00
|
|
|
a: (this: WebpackRequire, module: Module, body: AsyncModuleBody, hasAwaitAfterDependencies?: boolean) => void;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** getDefaultExport function for compatibility with non-harmony modules */
|
2024-05-23 06:10:59 +00:00
|
|
|
n: (this: WebpackRequire, module: Module) => () => ModuleExports;
|
2024-05-22 09:08:40 +00:00
|
|
|
/**
|
|
|
|
* Create a fake namespace object, useful for faking an __esModule with a default export.
|
|
|
|
*
|
|
|
|
* mode & 1: Value is a module id, require it
|
|
|
|
*
|
|
|
|
* mode & 2: Merge all properties of value into the namespace
|
|
|
|
*
|
|
|
|
* mode & 4: Return value when already namespace object
|
|
|
|
*
|
|
|
|
* mode & 16: Return value when it's Promise-like
|
|
|
|
*
|
|
|
|
* mode & (8|1): Behave like require
|
|
|
|
*/
|
2024-05-23 06:10:59 +00:00
|
|
|
t: (this: WebpackRequire, value: any, mode: number) => any;
|
2024-05-22 09:08:40 +00:00
|
|
|
/**
|
2024-05-26 10:00:03 +00:00
|
|
|
* Define getter functions for harmony exports. For every prop in "definiton" (the module exports), set a getter in "exports" for the getter function in the "definition", like this:
|
2024-05-22 09:08:40 +00:00
|
|
|
* @example
|
|
|
|
* const exports = {};
|
2024-05-26 10:00:03 +00:00
|
|
|
* const definition = { exportName: () => someExportedValue };
|
2024-05-22 09:08:40 +00:00
|
|
|
* for (const key in definition) {
|
2024-05-26 22:51:34 +00:00
|
|
|
* if (Object.hasOwn(definition, key) && !Object.hasOwn(exports, key)) {
|
2024-05-26 10:00:03 +00:00
|
|
|
* Object.defineProperty(exports, key, {
|
|
|
|
* get: definition[key],
|
|
|
|
* enumerable: true
|
|
|
|
* });
|
|
|
|
* }
|
2024-05-22 09:08:40 +00:00
|
|
|
* }
|
2024-05-26 10:00:03 +00:00
|
|
|
* // exports is now { exportName: someExportedValue } (but each value is actually a getter)
|
|
|
|
*/
|
2024-05-23 06:36:53 +00:00
|
|
|
d: (this: WebpackRequire, exports: Record<PropertyKey, any>, definiton: Record<PropertyKey, any>) => void;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** The chunk handlers, which are used to ensure the files of the chunks are loaded, or load if necessary */
|
|
|
|
f: ChunkHandlers;
|
|
|
|
/**
|
|
|
|
* The ensure chunk function, it ensures a chunk is loaded, or loads if needed.
|
|
|
|
* Internally it uses the handlers in {@link WebpackRequire.f} to load/ensure the chunk is loaded.
|
|
|
|
*/
|
2024-05-23 06:10:59 +00:00
|
|
|
e: (this: WebpackRequire, chunkId: PropertyKey) => Promise<void[]>;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Get the filename name for the css part of a chunk */
|
2024-05-23 06:36:53 +00:00
|
|
|
k: (this: WebpackRequire, chunkId: PropertyKey) => string;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Get the filename for the js part of a chunk */
|
2024-05-23 06:10:59 +00:00
|
|
|
u: (this: WebpackRequire, chunkId: PropertyKey) => string;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** The global object, will likely always be the window */
|
2024-05-26 22:40:33 +00:00
|
|
|
g: typeof globalThis;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Harmony module decorator. Decorates a module as an ES Module, and prevents Node.js "module.exports" from being set */
|
2024-05-23 06:10:59 +00:00
|
|
|
hmd: (this: WebpackRequire, module: Module) => any;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Shorthand for Object.prototype.hasOwnProperty */
|
|
|
|
o: typeof Object.prototype.hasOwnProperty;
|
|
|
|
/**
|
|
|
|
* Function to load a script tag. "done" is called when the loading has finished or a timeout has occurred.
|
|
|
|
* "done" will be attached to existing scripts loading if src === url or data-webpack === `${uniqueName}:${key}`,
|
|
|
|
* so it will be called when that existing script finishes loading.
|
|
|
|
*/
|
2024-05-23 06:10:59 +00:00
|
|
|
l: (this: WebpackRequire, url: string, done: ScriptLoadDone, key?: string | number, chunkId?: PropertyKey) => void;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Defines __esModule on the exports, marking ES Modules compatibility as true */
|
2024-05-23 06:36:53 +00:00
|
|
|
r: (this: WebpackRequire, exports: ModuleExports) => void;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Node.js module decorator. Decorates a module as a Node.js module */
|
2024-05-23 06:10:59 +00:00
|
|
|
nmd: (this: WebpackRequire, module: Module) => any;
|
2024-05-22 09:08:40 +00:00
|
|
|
/**
|
|
|
|
* Register deferred code which will be executed when the passed chunks are loaded.
|
|
|
|
*
|
|
|
|
* If chunkIds is defined, it defers the execution of the callback and returns undefined.
|
|
|
|
*
|
|
|
|
* If chunkIds is undefined, and no deferred code exists or can be executed, it returns the value of the result argument.
|
|
|
|
*
|
|
|
|
* If chunkIds is undefined, and some deferred code can already be executed, it returns the result of the callback function of the last deferred code.
|
|
|
|
*
|
|
|
|
* When (priority & 1) it will wait for all other handlers with lower priority to be executed before itself is executed.
|
|
|
|
*/
|
|
|
|
O: OnChunksLoaded;
|
2024-05-22 09:22:37 +00:00
|
|
|
/**
|
2024-05-26 23:22:03 +00:00
|
|
|
* Instantiate a wasm instance with source using "wasmModuleHash", and importObject "importsObj", and then assign the exports of its instance to "exports".
|
2024-05-22 09:25:30 +00:00
|
|
|
* @returns The exports argument, but now assigned with the exports of the wasm instance
|
2024-05-22 09:22:37 +00:00
|
|
|
*/
|
2024-05-23 06:36:53 +00:00
|
|
|
v: (this: WebpackRequire, exports: ModuleExports, wasmModuleId: any, wasmModuleHash: string, importsObj?: WebAssembly.Imports) => Promise<any>;
|
2024-05-22 09:08:40 +00:00
|
|
|
/** Bundle public path, where chunk files are stored. Used by other methods which load chunks to obtain the full asset url */
|
|
|
|
p: string;
|
|
|
|
/** Document baseURI or WebWorker location.href */
|
|
|
|
b: string;
|
|
|
|
};
|
2024-06-02 21:46:03 +00:00
|
|
|
|
|
|
|
// Utility section for Vencord
|
|
|
|
|
|
|
|
export type AnyWebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & Partial<Omit<WebpackRequire, "m" | "O">> & Pick<WebpackRequire, "O"> & {
|
|
|
|
/** The module factories, where all modules that have been loaded are stored (pre-loaded or loaded by lazy chunks) */
|
|
|
|
m: Record<PropertyKey, AnyModuleFactory>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** exports can be anything, however initially it is always an empty object */
|
|
|
|
export type AnyModuleFactory = (this: ModuleExports, module: Module, exports: ModuleExports, require: AnyWebpackRequire) => void;
|
|
|
|
|
2024-06-16 22:53:31 +00:00
|
|
|
export type WrappedModuleFactory = AnyModuleFactory & {
|
2024-06-02 21:46:03 +00:00
|
|
|
$$vencordOriginal?: AnyModuleFactory;
|
|
|
|
};
|
|
|
|
|
2024-06-16 22:53:31 +00:00
|
|
|
export type WrappedModuleFactories = Record<PropertyKey, WrappedModuleFactory>;
|