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: non-blocking scanning of dependencies #7379

Merged
merged 20 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: improve logs
  • Loading branch information
patak-dev committed Mar 22, 2022
commit 26e726e38272f96bac999bf9f8a143bd46031565
3 changes: 2 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { scanImports } from './scan'
import { transformWithEsbuild } from '../plugins/esbuild'
import { performance } from 'perf_hooks'

const debug = createDebugger('vite:deps')
export const debuggerViteDeps = createDebugger('vite:deps')
const debug = debuggerViteDeps
const isDebugEnabled = _debug('vite:deps').enabled

const jsExtensionRE = /\.js$/i
Expand Down
38 changes: 27 additions & 11 deletions packages/vite/src/node/optimizer/registerMissing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
createOptimizedDepsMetadata,
addOptimizedDepInfo,
discoverProjectDependencies,
depsLogString
depsLogString,
debuggerViteDeps as debug
} from '.'
import type {
DepOptimizationProcessing,
Expand Down Expand Up @@ -64,7 +65,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {

const warmUp = async () => {
try {
logger.info(colors.green(`scanning for dependencies...`), {
debug(colors.green(`scanning for dependencies...`), {
timestamp: true
})

Expand All @@ -83,10 +84,14 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
})
}

const depsString = depsLogString(Object.keys(discovered))
logger.info(colors.green(`dependencies found: ${depsString}`), {
timestamp: true
})
debug(
colors.green(
`dependencies found: ${depsLogString(Object.keys(discovered))}`
),
{
timestamp: true
}
)

scanPhaseProcessing.resolve()
optimizedDeps.scanProcessing = undefined
Expand Down Expand Up @@ -203,14 +208,23 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
}
}

const newDeps = Object.keys(newData.optimized).filter(
(dep) => !metadata.optimized[dep]
)
config.logger.info(
colors.green(`✨ dependencies optimized: ${depsLogString(newDeps)}`),
{
timestamp: true
}
)

metadata = optimizedDeps.metadata = newData
resolveEnqueuedProcessingPromises()
}

if (!needsReload) {
commitProcessing()

logger.info(colors.green(`✨ dependencies pre-bundled...`), {
debug(colors.green(`✨ previous optimized dependencies unchanged`), {
timestamp: true
})
} else {
Expand All @@ -221,7 +235,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
// once a rerun is committed
processingResult.cancel()

logger.info(
debug(
colors.green(
`✨ delaying reload as new dependencies have been found...`
),
Expand All @@ -233,7 +247,9 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
commitProcessing()

logger.info(
colors.green(`✨ dependencies updated, reloading page...`),
colors.green(
`✨ previous optimized dependencies have changed, reloading page`
),
{
timestamp: true
}
Expand Down Expand Up @@ -276,7 +292,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
// optimizeDeps processing is finished
const deps = Object.keys(optimizedDeps.metadata.discovered)
const depsString = depsLogString(deps)
logger.info(colors.green(`new dependencies found: ${depsString}`), {
debug(colors.green(`new dependencies found: ${depsString}`), {
timestamp: true
})
runOptimizer()
Expand Down