Skip to content

Commit

Permalink
refactor: improve scanner logs (#12578)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Mar 25, 2023
1 parent 4c142ea commit 9925a72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ export function runOptimizeDeps(
stringifyDepsOptimizerMetadata(metadata, depsCacheDir),
)

debug(`deps bundled in ${(performance.now() - start).toFixed(2)}ms`)
debug(
`Dependencies bundled in ${(performance.now() - start).toFixed(2)}ms`,
)

return createProcessingResult()
})
Expand Down
10 changes: 0 additions & 10 deletions packages/vite/src/node/optimizer/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,6 @@ async function createDepsOptimizer(
const deps = await discover.result
discover = undefined

debug(
colors.green(
Object.keys(deps).length > 0
? `dependencies found by scanner: ${depsLogString(
Object.keys(deps),
)}`
: `no dependencies found by scanner`,
),
)

// Add these dependencies to the discovered list, as these are currently
// used by the preAliasPlugin to support aliased and optimized deps.
// This is also used by the CJS externalization heuristics in legacy mode
Expand Down
20 changes: 15 additions & 5 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { transformGlobImport } from '../plugins/importMetaGlob'

type ResolveIdOptions = Parameters<PluginContainer['resolveId']>[2]

const isDebug = process.env.DEBUG
const debug = createDebugger('vite:deps')

const htmlTypesRE = /\.(html|vue|svelte|astro|imba)$/
Expand Down Expand Up @@ -83,7 +84,11 @@ export function scanImports(config: ResolvedConfig): {
}
if (scanContext.cancelled) return

debug(`Crawling dependencies using entries:\n ${entries.join('\n ')}`)
debug(
`Crawling dependencies using entries: ${entries
.map((entry) => `\n ${colors.dim(entry)}`)
.join('')}`,
)
return prepareEsbuildScanner(config, entries, deps, missing, scanContext)
})

Expand Down Expand Up @@ -135,10 +140,15 @@ export function scanImports(config: ResolvedConfig): {
throw e
})
.finally(() => {
debug(
`Scan completed in ${(performance.now() - start).toFixed(2)}ms:`,
deps,
)
if (isDebug) {
const duration = (performance.now() - start).toFixed(2)
const depsStr =
Object.keys(orderedDependencies(deps))
.sort()
.map((id) => `\n ${colors.cyan(id)} -> ${colors.dim(deps[id])}`)
.join('') || colors.dim('no dependencies found')
debug(`Scan completed in ${duration}ms: ${depsStr}`)
}
})

return {
Expand Down

0 comments on commit 9925a72

Please sign in to comment.