import plugin , { StartDataFile , StartDataFilesProps } from '@start/plugin/src/' ; import { TransformOptions } from '@babel/core' ; export default ( userOptions ? ) => plugin ( 'babel' , ( { logPath } ) => async ( { files } ) => { const { transform } = await import ( '@babel/core' ) ; return { files : await Promise . all ( files . reduce ( ( result , file ) : StartDataFile [ ] => { const options = { ... userOptions , ast : false , inputSourceMap : file . map != null ? file . map : false , filename : file . path } ; const transformed = transform ( file . data , options ) ; if ( transformed !== null ) { if ( typeof transformed . code !== 'string' ) { return result ; } const dataFile = { path : file . path , data : transformed . code } ; if ( options . sourceMaps && transformed . map ) { dataFile . map = transformed . map ; } logPath ( file . path ) ; result . push ( dataFile ) ; } return result ; } , [ ] as StartDataFile [ ] ) ) } ; } ) ;