-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathindex.ts
More file actions
23 lines (20 loc) · 957 Bytes
/
index.ts
File metadata and controls
23 lines (20 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type { UnloaderPlugin, UnpluginContextMeta, UnpluginFactory, UnpluginInstance } from '../types'
import { version as unpluginVersion } from '../../package.json'
import { toRollupPlugin } from '../rollup'
import { toArray } from '../utils/general'
export function getUnloaderPlugin<UserOptions = Record<string, never>, Nested extends boolean = boolean>(
factory: UnpluginFactory<UserOptions, Nested>,
) {
return ((userOptions?: UserOptions) => {
const meta: UnpluginContextMeta = {
framework: 'unloader',
versions: { unplugin: unpluginVersion }, // Will be populated in buildStart hook
}
const rawPlugins = toArray(factory(userOptions!, meta))
const plugins = rawPlugins.map((rawPlugin) => {
const plugin = toRollupPlugin(rawPlugin, 'unloader', meta) as UnloaderPlugin
return plugin
})
return plugins.length === 1 ? plugins[0] : plugins
}) as UnpluginInstance<UserOptions, Nested>['unloader']
}