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

Function getSortedPluginsByHook

packages/vite/src/node/plugins/index.ts:202–230  ·  view source on GitHub ↗
(
  hookName: K,
  plugins: readonly Plugin[],
)

Source from the content-addressed store, hash-verified

200}
201
202export function getSortedPluginsByHook<K extends keyof Plugin>(
203 hookName: K,
204 plugins: readonly Plugin[],
205): PluginWithRequiredHook<K>[] {
206 const sortedPlugins: Plugin[] = []
207 // Use indexes to track and insert the ordered plugins directly in the
208 // resulting array to avoid creating 3 extra temporary arrays per hook
209 let pre = 0,
210 normal = 0,
211 post = 0
212 for (const plugin of plugins) {
213 const hook = plugin[hookName]
214 if (hook) {
215 if (typeof hook === 'object') {
216 if (hook.order === 'pre') {
217 sortedPlugins.splice(pre++, 0, plugin)
218 continue
219 }
220 if (hook.order === 'post') {
221 sortedPlugins.splice(pre + normal + post++, 0, plugin)
222 continue
223 }
224 }
225 sortedPlugins.splice(pre + normal++, 0, plugin)
226 }
227 }
228
229 return sortedPlugins as PluginWithRequiredHook<K>[]
230}
231
232export function getHookHandler<T extends ObjectHook<Function>>(
233 hook: T,

Callers 3

runConfigHookFunction · 0.90
runConfigEnvironmentHookFunction · 0.90
getSortedPluginsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected