MCPcopy
hub / github.com/vitejs/vite / runOptimizer

Function runOptimizer

packages/vite/src/node/optimizer/optimizer.ts:315–522  ·  view source on GitHub ↗
(preRunResult?: DepOptimizationResult)

Source from the content-addressed store, hash-verified

313 }
314
315 async function runOptimizer(preRunResult?: DepOptimizationResult) {
316 // a successful completion of the optimizeDeps rerun will end up
317 // creating new bundled version of all current and discovered deps
318 // in the cache dir and a new metadata info object assigned
319 // to _metadata. A fullReload is only issued if the previous bundled
320 // dependencies have changed.
321
322 // if the rerun fails, _metadata remains untouched, current discovered
323 // deps are cleaned, and a fullReload is issued
324
325 // All deps, previous known and newly discovered are rebundled,
326 // respect insertion order to keep the metadata file stable
327
328 const isRerun = firstRunCalled
329 firstRunCalled = true
330
331 // Ensure that rerun is called sequentially
332 enqueuedRerun = undefined
333
334 // Ensure that a rerun will not be issued for current discovered deps
335 if (debounceProcessingHandle) clearTimeout(debounceProcessingHandle)
336
337 if (closed) {
338 currentlyProcessing = false
339 depOptimizationProcessing.resolve()
340 resolveEnqueuedProcessingPromises()
341 return
342 }
343
344 currentlyProcessing = true
345
346 try {
347 let processingResult: DepOptimizationResult
348 if (preRunResult) {
349 processingResult = preRunResult
350 } else {
351 const knownDeps = prepareKnownDeps()
352 startNextDiscoveredBatch()
353
354 optimizationResult = runOptimizeDeps(environment, knownDeps)
355 processingResult = await optimizationResult.result
356 optimizationResult = undefined
357 }
358
359 if (closed) {
360 currentlyProcessing = false
361 processingResult.cancel()
362 resolveEnqueuedProcessingPromises()
363 return
364 }
365
366 const newData = processingResult.metadata
367
368 const needsInteropMismatch = findInteropMismatches(
369 metadata.discovered,
370 newData.optimized,
371 )
372

Callers 3

initFunction · 0.85
rerunFunction · 0.85
onCrawlEndFunction · 0.85

Calls 13

runOptimizeDepsFunction · 0.90
prepareKnownDepsFunction · 0.85
startNextDiscoveredBatchFunction · 0.85
findInteropMismatchesFunction · 0.85
commitProcessingFunction · 0.85
logNewlyDiscoveredDepsFunction · 0.85
fullReloadFunction · 0.85
resolveMethod · 0.65
infoMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected