aboutsummaryrefslogtreecommitdiff
path: root/src/webpack/webpack.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/webpack/webpack.ts')
-rw-r--r--src/webpack/webpack.ts22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts
index 9e550a4..ea5a7e3 100644
--- a/src/webpack/webpack.ts
+++ b/src/webpack/webpack.ts
@@ -1,5 +1,12 @@
import type { WebpackInstance } from "discord-types/other";
+export let _resolveReady: () => void;
+/**
+ * Fired once a gateway connection to Discord has been established.
+ * This indicates that the core webpack modules have been initialised
+ */
+export const onceReady = new Promise<void>(r => _resolveReady = r);
+
export let wreq: WebpackInstance;
export let cache: WebpackInstance["c"];
@@ -68,8 +75,19 @@ export function findAll(filter: FilterFn, getDefault = true) {
const ret = [] as any[];
for (const key in cache) {
const mod = cache[key];
- if (mod?.exports && filter(mod.exports)) ret.push(mod.exports);
- if (mod?.exports?.default && filter(mod.exports.default)) ret.push(getDefault ? mod.exports.default : mod.exports);
+ if (!mod?.exports) continue;
+
+ if (filter(mod.exports))
+ ret.push(mod.exports);
+ else if (typeof mod.exports !== "object")
+ continue;
+
+ if (mod.exports.default && filter(mod.exports.default))
+ ret.push(getDefault ? mod.exports.default : mod.exports);
+ else for (const nestedMod in mod.exports) if (nestedMod.length < 3) {
+ const nested = mod.exports[nestedMod];
+ if (nested && filter(nested)) ret.push(nested);
+ }
}
return ret;