Vencord/src/webpack/wreq.d.ts

144 lines
6.9 KiB
TypeScript
Raw Normal View History

2024-05-22 09:08:40 +00:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
2024-05-23 06:10:59 +00:00
export type AnyRecord = Record<PropertyKey, any>;
2024-05-22 09:08:40 +00:00
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;
};
/** exports ({@link ModuleExports}) can be anything, however initially it is always an empty object */
2024-05-23 06:10:59 +00:00
export type ModuleFactory = (module: Module, exports: AnyRecord, require: WebpackRequire) => void;
2024-05-22 09:08:40 +00:00
2024-05-23 06:10:59 +00:00
export type AsyncModuleBody = (
2024-05-22 09:08:40 +00:00
handleDependencies: (deps: Promise<any>[]) => Promise<any[]> & (() => void)
) => Promise<void>;
2024-05-23 06:10:59 +00:00
export type ChunkHandlers = {
2024-05-22 09:08:40 +00:00
/**
* Ensures the js file for this chunk is loaded, or starts to load if it's not
* @param chunkId The chunk id
* @param promises The promises array to add the loading promise to.
*/
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
/**
* Ensures the css file for this chunk is loaded, or starts to load if it's not
* @param chunkId The chunk id
* @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-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:10:59 +00:00
j: (chunkId: PropertyKey) => boolean;
2024-05-22 09:08:40 +00:00
};
2024-05-23 06:10:59 +00:00
export type WebpackRequire = ((moduleId: PropertyKey) => Module) & {
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-23 06:10:59 +00:00
* Object.defineProperty(fromObject, "a", {
* get: () => fromObject["a"]
2024-05-22 09:08:40 +00:00
* });
* @returns fromObject
*/
2024-05-23 06:10:59 +00:00
es: (this: WebpackRequire, fromObject: AnyRecord, toObject: AnyRecord) => AnyRecord;
2024-05-22 09:08:40 +00:00
/**
* Creates an async module. The body function must be a async function.
* "module.exports" will be decorated with an AsyncModulePromise.
* The body function will be called.
* To handle async dependencies correctly do this inside the body: "([a, b, c] = await handleDependencies([a, b, c]));".
* If "hasAwaitAfterDependencies" is truthy, "handleDependencies()" must be called at the end of the body function.
*/
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
/**
* Define property getters. For every prop in "definiton", set a getter in "exports" for the value in "definitiion", like this:
* @example
* const exports = {};
* const definition = { a: 1 };
* for (const key in definition) {
* Object.defineProperty(exports, key, { get: definition[key] }
* }
*/
2024-05-23 06:10:59 +00:00
d: (this: WebpackRequire, exports: AnyRecord, definiton: AnyRecord) => 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:10:59 +00:00
k: (this: WebpackRequire, chunkId: PropertyKey) => `${chunkId}.css`;
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 */
g: Window;
/** 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:10:59 +00:00
r: (this: WebpackRequire, exports: AnyRecord) => 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
/**
* 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:10:59 +00:00
v: (this: WebpackRequire, exports: AnyRecord, 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;
};