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

refactor: improve scanner logs #12578

Merged
merged 1 commit into from
Mar 25, 2023
Merged
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
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