import mapObj from '@tinkoff/utils/object/map' ; import escapeRegexp from '@tinkoff/utils/string/escapeRegExp' ; import type { Plugin } from 'rollup' ; const normalizePath = ( name ) => name . replace ( /\\/g , '/' ) ; export const browserPlugin = ( mapping ) : Plugin => { const regex = mapObj ( ( entry , key ) => new RegExp ( `${ escapeRegexp ( key ) }$` ) , mapping ) ; const keys = Object . keys ( mapping ) ; return { name : 'browser-build' , load ( source ) { for ( let i = 0 ; i < keys . length ; i ++ ) { const key = keys [ i ] ; if ( regex [ key ] . test ( source ) ) { const name = normalizePath ( source . replace ( regex [ key ] , mapping [ key ] ) ) ; return `export * from '${ name }';` ; } } } , } ; } ;