import { lazyRequire } from "lazy-require.macro" ; import { addDefault } from "@babel/helper-module-imports" ; function importHelperPlugin ( babel ) { return { pre ( file ) { const cachedHelpers = { } ; const previousHelperGenerator = file . get ( "helperGenerator" ) ; file . set ( "helperGenerator" , ( name ) => { if ( previousHelperGenerator ) { const helperFromPrev = previousHelperGenerator ( name ) ; if ( helperFromPrev != null ) return helperFromPrev ; } if ( ! file . availableHelper ( name ) ) { return null ; } if ( cachedHelpers [ name ] ) { return babel . types . identifier ( cachedHelpers [ name ] . name ) ; } return ( cachedHelpers [ name ] = addDefault ( file . path , `\0rollupPluginBabelHelpers/${ name }` , { nameHint : name } ) ) ; } ) ; } , } ; } export async function transformBabel ( code , cwd , filename ) { const babel = lazyRequire < typeof import ( "@babel/core" ) > ( ) ; return babel . transformAsync ( code , { caller : { name : "rollup-plugin-babel" , supportsStaticESM : true , supportsDynamicImport : true , } , sourceMaps : true , cwd , filename , plugins : [ importHelperPlugin ] , } ) . then ( ( res ) => { return { code : res ! . code ! , map : res ! . map } ; } ) ; } export function transformTerser ( code , optionsString ) { const { minify } = lazyRequire < typeof import ( "terser" ) > ( ) ; const options = JSON . parse ( optionsString ) ; return minify ( code , options ) as Promise < { code : string ; map : any ; } > ; }