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

Function getSortedPluginsByHotUpdateHook

packages/vite/src/node/server/hmr.ts:372–399  ·  view source on GitHub ↗
(
  plugins: readonly Plugin[],
)

Source from the content-addressed store, hash-verified

370}
371
372export function getSortedPluginsByHotUpdateHook(
373 plugins: readonly Plugin[],
374): Plugin[] {
375 const sortedPlugins: Plugin[] = []
376 // Use indexes to track and insert the ordered plugins directly in the
377 // resulting array to avoid creating 3 extra temporary arrays per hook
378 let pre = 0,
379 normal = 0,
380 post = 0
381 for (const plugin of plugins) {
382 const hook = plugin.hotUpdate ?? plugin.handleHotUpdate
383 if (hook) {
384 if (typeof hook === 'object') {
385 if (hook.order === 'pre') {
386 sortedPlugins.splice(pre++, 0, plugin)
387 continue
388 }
389 if (hook.order === 'post') {
390 sortedPlugins.splice(pre + normal + post++, 0, plugin)
391 continue
392 }
393 }
394 sortedPlugins.splice(pre + normal++, 0, plugin)
395 }
396 }
397
398 return sortedPlugins
399}
400
401const sortedHotUpdatePluginsCache = new WeakMap<Environment, Plugin[]>()
402function getSortedHotUpdatePlugins(environment: Environment): Plugin[] {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected