Skip to content

Commit

Permalink
refactor: update import analysis plugin debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 22, 2021
1 parent 713b480 commit 2fb2561
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { makeLegalIdentifier } from '@rollup/pluginutils'
import { shouldExternalizeForSSR } from '../ssr/ssrExternal'

const isDebug = !!process.env.DEBUG
const debugRewrite = createDebugger('vite:rewrite')
const debug = createDebugger('vite:import-analysis')

const clientDir = normalizePath(CLIENT_DIR)

Expand Down Expand Up @@ -105,11 +105,11 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
const prettyImporter = prettifyUrl(importer, root)

if (canSkip(importer)) {
isDebug && debugRewrite(chalk.dim(`[skipped] ${prettyImporter}`))
isDebug && debug(chalk.dim(`[skipped] ${prettyImporter}`))
return null
}

const rewriteStart = Date.now()
const start = Date.now()
await init
let imports: readonly ImportSpecifier[] = []
// strip UTF-8 BOM
Expand Down Expand Up @@ -140,10 +140,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {

if (!imports.length) {
isDebug &&
debugRewrite(
`${timeFrom(rewriteStart)} ${chalk.dim(
`[no imports] ${prettyImporter}`
)}`
debug(
`${timeFrom(start)} ${chalk.dim(`[no imports] ${prettyImporter}`)}`
)
return source
}
Expand Down Expand Up @@ -510,6 +508,13 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
}
}

isDebug &&
debug(
`${timeFrom(start)} ${chalk.dim(
`[${importedUrls.size} imports rewritten] ${prettyImporter}`
)}`
)

if (s) {
return s.toString()
} else {
Expand Down

0 comments on commit 2fb2561

Please sign in to comment.