Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add debugDepth option #18289

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ export interface UserConfig extends DefaultEnvironmentOptions {
* @default 'spa'
*/
appType?: AppType
/**
* Specifies the number of times to recurse while formatting object.
*
* https://nodejs.org/api/util.html#utilinspectobject-options
*/
debugDepth?: string | undefined
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment variable stores a string, and the util.inspect option accepts a number. I am not sure whether the type here should be set to a number or a string. Currently, it is set to a string.

}

export interface HTMLOptions {
Expand Down Expand Up @@ -846,6 +852,10 @@ export async function resolveConfig(
configFile = loadResult.path
configFileDependencies = loadResult.dependencies
}

if (config.debugDepth && process.env.DEBUG) {
process.env.DEBUG_DEPTH = config.debugDepth
}
}

// user config may provide an alternative mode. But --mode has a higher priority
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export function createDebugger(
if (enabled) {
return (...args: [string, ...any[]]) => {
if (!filter || args.some((a) => a?.includes?.(filter))) {
if (process.env.DEBUG_DEPTH) {
const depth = parseInt(process.env.DEBUG_DEPTH)
// @ts-expect-error - The log function is bound to inspectOpts, but the type is not reflected
log.inspectOpts.depth = depth
}
log(...args)
}
}
Expand Down