Document new WebpackRequire properties

This commit is contained in:
Nuckyz 2025-02-15 03:27:21 -03:00
parent 8773d057bc
commit 94d45780f9
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

74
src/webpack/wreq.d.ts vendored
View file

@ -33,27 +33,45 @@ export type AsyncModuleBody = (
asyncResult: (error?: any) => void asyncResult: (error?: any) => void
) => Promise<void>; ) => Promise<void>;
export type ChunkHandlers = { export type EnsureChunkHandlers = {
/** /**
* Ensures the js file for this chunk is loaded, or starts to load if it's not. * Ensures the js file for this chunk is loaded, or starts to load if it's not.
* @param chunkId The chunk id * @param chunkId The chunk id
* @param promises The promises array to add the loading promise to * @param promises The promises array to add the loading promise to
*/ */
j: (this: ChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void, j: (this: EnsureChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void;
/** /**
* Ensures the css file for this chunk is loaded, or starts to load if it's not. * Ensures the css file for this chunk is loaded, or starts to load if it's not.
* @param chunkId The chunk id * @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 * @param promises The promises array to add the loading promise to. This array will likely contain the promise of the js file too
*/ */
css: (this: ChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void, css: (this: EnsureChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void;
/**
* Trigger for prefetching next chunks. This is called after ensuring a chunk is loaded and internally looks up
* a map to see if the chunk that just loaded has next chunks to prefetch.
*
* Note that this does not add an extra promise to the promises array, and instead only executes the prefetching after
* calling Promise.all on the promises array.
* @param chunkId The chunk id
* @param promises The promises array of ensuring the chunk is loaded
*/
prefetch: (this: EnsureChunkHandlers, chunkId: PropertyKey, promises: Promise<void[]>) => void;
};
export type PrefetchChunkHandlers = {
/**
* Prefetches the js file for this chunk.
* @param chunkId The chunk id
*/
j: (this: PrefetchChunkHandlers, chunkId: PropertyKey) => void;
}; };
export type ScriptLoadDone = (event: Event) => void; export type ScriptLoadDone = (event: Event) => void;
// export type OnChunksLoaded = ((this: WebpackRequire, result: any, chunkIds: PropertyKey[] | undefined | null, callback: () => any, priority: number) => any) & { export type OnChunksLoaded = ((this: WebpackRequire, result: any, chunkIds: PropertyKey[] | undefined | null, callback: () => any, priority: number) => any) & {
// /** Check if a chunk has been loaded */ /** Check if a chunk has been loaded */
// j: (this: OnChunksLoaded, chunkId: PropertyKey) => boolean; j: (this: OnChunksLoaded, chunkId: PropertyKey) => boolean;
// }; };
export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & { export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & {
/** The module factories, where all modules that have been loaded are stored (pre-loaded or loaded by lazy chunks) */ /** The module factories, where all modules that have been loaded are stored (pre-loaded or loaded by lazy chunks) */
@ -135,13 +153,20 @@ export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & {
* // exports is now { exportName: someExportedValue } (but each value is actually a getter) * // exports is now { exportName: someExportedValue } (but each value is actually a getter)
*/ */
d: (this: WebpackRequire, exports: AnyRecord, definiton: AnyRecord) => void; d: (this: WebpackRequire, exports: AnyRecord, definiton: AnyRecord) => void;
/** The chunk handlers, which are used to ensure the files of the chunks are loaded, or load if necessary */ /** The ensure chunk handlers, which are used to ensure the files of the chunks are loaded, or load if necessary */
f: ChunkHandlers; f: EnsureChunkHandlers;
/** /**
* The ensure chunk function, it ensures a chunk is loaded, or loads if needed. * 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. * Internally it uses the handlers in {@link WebpackRequire.f} to load/ensure the chunk is loaded.
*/ */
e: (this: WebpackRequire, chunkId: PropertyKey) => Promise<void[]>; e: (this: WebpackRequire, chunkId: PropertyKey) => Promise<void[]>;
/** The prefetch chunk handlers, which are used to prefetch the files of the chunks */
F: PrefetchChunkHandlers;
/**
* The prefetch chunk function.
* Internally it uses the handlers in {@link WebpackRequire.F} to prefetch a chunk.
*/
E: (this: WebpackRequire, chunkId: PropertyKey) => void;
/** Get the filename for the css part of a chunk */ /** Get the filename for the css part of a chunk */
k: (this: WebpackRequire, chunkId: PropertyKey) => string; k: (this: WebpackRequire, chunkId: PropertyKey) => string;
/** Get the filename for the js part of a chunk */ /** Get the filename for the js part of a chunk */
@ -162,18 +187,18 @@ export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & {
r: (this: WebpackRequire, exports: ModuleExports) => void; r: (this: WebpackRequire, exports: ModuleExports) => void;
/** Node.js module decorator. Decorates a module as a Node.js module */ /** Node.js module decorator. Decorates a module as a Node.js module */
nmd: (this: WebpackRequire, module: Module) => any; nmd: (this: WebpackRequire, module: Module) => any;
// /** /**
// * Register deferred code which will be executed when the passed chunks are loaded. * 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 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 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. * 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. * When (priority & 1) it will wait for all other handlers with lower priority to be executed before itself is executed.
// */ */
// O: OnChunksLoaded; O: OnChunksLoaded;
/** /**
* Instantiate a wasm instance with source using "wasmModuleHash", and importObject "importsObj", and then assign the exports of its instance to "exports". * Instantiate a wasm instance with source using "wasmModuleHash", and importObject "importsObj", and then assign the exports of its instance to "exports".
* @returns The exports argument, but now assigned with the exports of the wasm instance * @returns The exports argument, but now assigned with the exports of the wasm instance
@ -185,6 +210,13 @@ export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & {
j: string; j: string;
/** Document baseURI or WebWorker location.href */ /** Document baseURI or WebWorker location.href */
b: string; b: string;
/* rspack only */
/** rspack version */
rv: (this: WebpackRequire) => string;
/** rspack unique id */
ruid: string;
}; };
// Utility section for Vencord // Utility section for Vencord