split up webpack commons into categories & type everything (#455)

This commit is contained in:
Ven 2023-01-25 03:25:29 +01:00 committed by GitHub
parent a38ac956df
commit f19504f828
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 930 additions and 372 deletions

View file

@ -152,34 +152,6 @@ export function sleep(ms: number): Promise<void> {
return new Promise(r => setTimeout(r, ms));
}
/**
* Wraps a Function into a try catch block and logs any errors caught
* Due to the nature of this function, not all paths return a result.
* Thus, for consistency, the returned functions will always return void or Promise<void>
*
* @param name Name identifying the wrapped function. This will appear in the logged errors
* @param func Function (async or sync both work)
* @param thisObject Optional thisObject
* @returns Wrapped Function
*/
export function suppressErrors<F extends Function>(name: string, func: F, thisObject?: any): F {
return (func.constructor.name === "AsyncFunction"
? async function (this: any) {
try {
await func.apply(thisObject ?? this, arguments);
} catch (e) {
console.error(`Caught an Error in ${name || "anonymous"}\n`, e);
}
}
: function (this: any) {
try {
func.apply(thisObject ?? this, arguments);
} catch (e) {
console.error(`Caught an Error in ${name || "anonymous"}\n`, e);
}
}) as any as F;
}
/**
* Wrap the text in ``` with an optional language
*/