( plugins: readonly Plugin[], )
| 370 | } |
| 371 | |
| 372 | export 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 | |
| 401 | const sortedHotUpdatePluginsCache = new WeakMap<Environment, Plugin[]>() |
| 402 | function getSortedHotUpdatePlugins(environment: Environment): Plugin[] { |
no outgoing calls
no test coverage detected