From 790c30a6d54e49c1c07088c93a281999f8be9855 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Thu, 4 Sep 2025 01:26:26 +0700 Subject: [PATCH] fix: debug build flags --- lib/modules/src/finders/lookup.ts | 2 +- lib/utils/src/object.ts | 18 ++++++++++++++++++ lib/utils/src/proxy.ts | 2 +- scripts/build.ts | 2 +- types/build.d.ts | 12 ++++++++---- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/modules/src/finders/lookup.ts b/lib/modules/src/finders/lookup.ts index a82e27a..34938b3 100644 --- a/lib/modules/src/finders/lookup.ts +++ b/lib/modules/src/finders/lookup.ts @@ -429,7 +429,7 @@ export function lookupModuleWithImportedPath( const __DEBUG_TRACER_IGNORE_LIST__ = __BUILD_FLAG_DEBUG_MODULE_LOOKUPS__ ? proxify( () => [ - require('./get').getModule, + require('./get').getModules, isModuleInitialized(0) && require('@revenge-mod/utils/discord') .lookupGeneratedIconComponent, diff --git a/lib/utils/src/object.ts b/lib/utils/src/object.ts index 42c59cc..603e6c0 100644 --- a/lib/utils/src/object.ts +++ b/lib/utils/src/object.ts @@ -1,3 +1,4 @@ +import { getCurrentStack } from './error' import type { AnyObject } from './types' /** @@ -73,6 +74,16 @@ function lazyPropDesc( key: K, loader: () => T[K], ): PropertyDescriptor { + if (__BUILD_FLAG_DEBUG_LAZY_VALUES__) { + const value = loader() + if (value == null) DEBUG_warnNullishLazyValue(key) + + return { + configurable: true, + value, + } + } + return { configurable: true, get(this: T) { @@ -81,3 +92,10 @@ function lazyPropDesc( }, } } + +function DEBUG_warnNullishLazyValue(key: PropertyKey) { + nativeLoggingHook( + `\u001b[33mLazy property ${String(key)} is being initialized to a nullish value:\n${getCurrentStack()}\u001b[0m`, + 2, + ) +} diff --git a/lib/utils/src/proxy.ts b/lib/utils/src/proxy.ts index 87c1f7a..3d26801 100644 --- a/lib/utils/src/proxy.ts +++ b/lib/utils/src/proxy.ts @@ -138,7 +138,7 @@ export function proxify(signal: () => T, options?: ProxifyOptions): T { cacheable: options?.cache ?? false, }) - if (__BUILD_FLAG_DEBUG_PROXIFIED_VALUES__) + if (__BUILD_FLAG_DEBUG_LAZY_VALUES__) // Prevent race conditions where proxified values with a self modifying signal gets called, // modifying the original value to a non-proxified value, causing subsequent destructure() calls to fail diff --git a/scripts/build.ts b/scripts/build.ts index 89f28ce..a3b098a 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -82,7 +82,7 @@ export default async function build(dev = Dev, log = true) { // See types/build.d.ts for what these flags do __BUILD_FLAG_DEBUG_MODULE_LOOKUPS__: String(dev), __BUILD_FLAG_DEBUG_MODULE_WAITS__: String(dev), - __BUILD_FLAG_DEBUG_PROXIFIED_VALUES__: 'false', + __BUILD_FLAG_DEBUG_LAZY_VALUES__: 'false', __BUILD_FLAG_LOG_PROMISE_REJECTIONS__: String(dev), }, plugins: [ diff --git a/types/build.d.ts b/types/build.d.ts index a8e6245..9c65464 100644 --- a/types/build.d.ts +++ b/types/build.d.ts @@ -22,12 +22,16 @@ declare global { */ const __BUILD_FLAG_DEBUG_MODULE_LOOKUPS__: boolean /** - * Whether to debug proxified values. + * Whether to debug lazy values. * - * - Immediately calls the signal to initialize the proxified value. - * - Warns if the proxified value is nullish. + * **This flag may break a lot of things depending on initialization timing. Use with caution.** + * + * - Immediately calls the signal to initialize proxified values. + * - Immediately calls the loader to initialize lazy object properties. + * + * - Warns if the values are nullish. */ - const __BUILD_FLAG_DEBUG_PROXIFIED_VALUES__: boolean + const __BUILD_FLAG_DEBUG_LAZY_VALUES__: boolean /** * Whether to debug module waits. *