feat: add `debugDepth` option
Description
When I set the debug parameters and prepare to view relevant information, I expect to be able to see some object information with a deeper nesting level more intuitively.
| before | after |
|
|
|
Run & review this pull request in StackBlitz Codeflow.
Could it be set for the config loading specifically only? I'm not sure if Vite should change the default depth as that might expand other logs.
That makes sense, it seems that adding a new configuration alone will have the least impact.
Maybe we can add a debugDepth option like the cli option debug.
Sorry for not responding before. I was thinking the depth could be more of an option for createDebugger() options, and we can set the value on log.inspectOpts.depth so that the depth is scoped to the logging directly.
Great find with log.inspectOpts.depth though. I didn't know and thought we'd hit a brick wall. So we could do a change like this:
export function createDebugger(
namespace: ViteDebugScope,
options: DebuggerOptions = {},
): debug.Debugger['log'] | undefined {
const log = debug(namespace)
if (options.depth && log.inspectOpts.depth == null) {
log.inspectOpts.depth = options.depth
}
What do you think?
This looks good. However, I have a question. createDebugger is a global public function. We can't specify whether it should be applied to a certain scope through parameter configuration.
I'm not quite sure what you mean. Doesn't my code example only applies the custom depth to an instance of debug()? So only calling the returned log() will have the special depth behaviour, but other debug log() will not have, so it's not polluted elsewhere.
What I mean is that all debug logs that are output now are created by createDebugger. If I pass a configuration parameter in like I currently do, it seems that I can't determine which call createDebugger to pass in the second parameter.
Oh, what I was thinking is that we don't need to have a new debugDepth config in Vite. If the user wants to configure that, I think it's enough to use DEBUG_DEPTH=100 before running Vite.
I think it should be enough for Vite to pass an opinionated:
const debug = createDebugger('vite:config', { depth: 100 })
So that it gets a nice logging by default, only for the vite:config namespace.
I think it's enough to use
DEBUG_DEPTH=100before running Vite.
Directly configure the environment variable DEBUG_DEPTH=100? Or is it to configure a cli option? If we configure the environment variable directly, then debug will handle it directly, and the following manual passing of the second parameter should be unnecessary.
Directly configure the environment variable. The issue though is that because it defaults to 2 (via nodes formatWithOptions), it's not the best default to use for config logging. We could change the default for the specific logging instead to eg 10 so that it logs better without any config. But if the user explicitly set DEBUG_DEPTH we can respect that instead.
Oh, I see. However, changing this default value will cause the default output information structure to change. Will it affect some users?
I think since it's only debug information, it should probably be safe. They should also get more logging of the config by default which I think is better.
OK, I have updated it.