import path = require ( 'path' ) ; import { CoreProperties as PackageManifest } from '@schemastore/package' ; import { Plugin , InputOptions } from 'rollup' ; export default function mainEntry ( pkg , cwd = process . cwd ( ) ) { const { rollup : { rootDir = 'src' } = { } } = pkg ; if ( ! pkg . main ) { const location = path . relative ( '.' , path . join ( cwd , 'package.json' ) ) ; throw new TypeError ( `required field 'main' missing in ${ location }` ) ; } return { name : 'main-entry' , options : ( opts ) : InputOptions => { if ( ! opts . input || ( Array . isArray ( opts . input ) && opts . input . length === 0 ) ) { opts . input = [ path . resolve ( cwd , rootDir as string , path . basename ( pkg . main ! ) ) ] ; } return opts ; } , } ; }