import * as path from 'path' ; const slashRegex = /[\\/]/g ; export function trimFileName ( fileName , cwd = process . cwd ( ) , platform ? ) { const pathLib = platform ? path [ platform ] : path ; const originalSep = fileName . match ( slashRegex ) ?. [ 0 ] || pathLib . sep ; const normalizedFileName = pathLib . normalize ( fileName ) ; const root = pathLib . parse ( cwd ) . root ; let parent = cwd ; do { if ( normalizedFileName . startsWith ( parent ) ) { return ( pathLib . relative ( pathLib . dirname ( parent ) , normalizedFileName ) . replace ( slashRegex , originalSep ) ) ; } parent = pathLib . dirname ( parent ) ; } while ( parent !== root ) ; return fileName ; }