fix: debug build flags

This commit is contained in:
PalmDevs 2025-09-04 01:26:26 +07:00
parent 54c6a2ffdd
commit 790c30a6d5
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
5 changed files with 29 additions and 7 deletions

View file

@ -429,7 +429,7 @@ export function lookupModuleWithImportedPath<T = any>(
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,

View file

@ -1,3 +1,4 @@
import { getCurrentStack } from './error'
import type { AnyObject } from './types'
/**
@ -73,6 +74,16 @@ function lazyPropDesc<T extends object, K extends keyof T>(
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<T extends object, K extends keyof T>(
},
}
}
function DEBUG_warnNullishLazyValue(key: PropertyKey) {
nativeLoggingHook(
`\u001b[33mLazy property ${String(key)} is being initialized to a nullish value:\n${getCurrentStack()}\u001b[0m`,
2,
)
}

View file

@ -138,7 +138,7 @@ export function proxify<T>(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

View file

@ -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: [

12
types/build.d.ts vendored
View file

@ -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.
*