resolveFilePath function

String resolveFilePath(
  1. String mention,
  2. String workingDirectory
)

Resolve a file mention to an absolute path.

Implementation

String resolveFilePath(String mention, String workingDirectory) {
  var p = mention;

  // Expand ~.
  if (p.startsWith('~/')) {
    final home =
        Platform.environment['HOME'] ??
        Platform.environment['USERPROFILE'] ??
        '/';
    p = '$home${p.substring(1)}';
  }

  // Already absolute.
  if (p.startsWith('/')) return _normalizePath(p);

  // Starts with ./ or ../ → relative to workingDirectory.
  if (p.startsWith('./') || p.startsWith('../')) {
    return _normalizePath('$workingDirectory/$p');
  }

  // Bare relative path.
  return _normalizePath('$workingDirectory/$p');
}