UNPKG

hins

Version:

[![codecov](https://codecov.io/gh/l-zoy/hins/branch/main/graph/badge.svg)](https://codecov.io/gh/l-zoy/hins) [![GitHub license](https://img.shields.io/github/license/l-zoy/hins)](https://github.com/l-zoy/hins/blob/master/LICENSE) ![node-current](https://i

37 lines (32 loc) 922 B
import resolve from 'resolve' import assert from 'assert' import slash from 'slash' import fs from 'fs' import { compatESModuleRequire, flatDeep } from './tools' import type { IResolvePlugins } from './types' /** * @desc Get the execution function of the plug-in, add path as the unique key value * @param { string } path string */ export function pathToRegister(path: string) { assert(fs.existsSync(path), `${path} not exists, pathToRegister failed`) return { path: slash(path), apply() { return compatESModuleRequire(require(path)) } } } /** * @desc Get all plugins * @param { object } options object */ export default function resolvePlugins(options: IResolvePlugins) { const plugins = flatDeep([...options.plugins].filter(Boolean)).map((path) => resolve.sync(path, { basedir: options.cwd, extensions: ['.js', '.ts'] }) ) return plugins.map(pathToRegister) }