All files / src/cli/utils path-utils.ts

100% Statements 10/10
100% Branches 6/6
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28        6x 6x         6x 106x     106x 76x       106x 4x 5x       106x    
/**
 * Shared path utilities for CLI modules
 */
 
import { homedir } from "os";
import { join } from "path";
 
/**
 * Expand path with home directory (~/) and Windows environment variables (%VAR%)
 */
export function expandPath(path: string): string {
  let expanded = path;
 
  // Expand home directory
  if (expanded.startsWith("~/")) {
    expanded = join(homedir(), expanded.slice(2));
  }
 
  // Expand Windows environment variables
  if (process.platform === "win32") {
    expanded = expanded.replace(/%([^%]+)%/g, (_, varName: string) => {
      return process.env[varName] ?? "";
    });
  }
 
  return expanded;
}