Skip to content

Commit

Permalink
feat: support debugDepth option
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Oct 6, 2024
1 parent 31ff4e4 commit f23abf5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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
}

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

0 comments on commit f23abf5

Please sign in to comment.