toRelativePath function

String toRelativePath(
  1. String filePath
)

Forward-slashed path relative to the current working directory, falling back to the raw path when the file lives outside it. Mirrors the reporter's makeRelativePath.

Implementation

String toRelativePath(String filePath) {
  if (filePath.isEmpty) return '';
  final cwd = Directory.current.path;
  if (filePath.startsWith(cwd)) {
    return filePath.substring(cwd.length + 1).replaceAll('\\', '/');
  }
  return filePath.replaceAll('\\', '/');
}