import { NOOP } from '@vue/shared' import type { App } from 'vue' import type { SFCInstallWithContext, SFCWithInstall } from './typescript' export const withInstall = >( main: T, extra?: E ) => { ;(main as SFCWithInstall).install = (app): void => { for (const comp of [main, ...Object.values(extra ?? {})]) { app.component(comp.name, comp) } } if (extra) { for (const [key, comp] of Object.entries(extra)) { ;(main as any)[key] = comp } } return main as SFCWithInstall & E } export const withInstallFunction = (fn: T, name: string) => { ;(fn as SFCWithInstall).install = (app: App) => { ;(fn as SFCInstallWithContext)._context = app._context app.config.globalProperties[name] = fn } return fn as SFCInstallWithContext } export const withNoopInstall = (component: T) => { ;(component as SFCWithInstall).install = NOOP return component as SFCWithInstall }