// @flow
import path from 'path';

export default function normalizePath(
  rawPath: ?string,
  workingDirectory: string,
): string {
  if (!rawPath) {
    return './';
  }

  if (rawPath.startsWith(workingDirectory)) {
    return `.${rawPath.slice(workingDirectory.length)}`;
  }

  if (rawPath.startsWith('/')) {
    return `.${rawPath}`;
  }

  if (
    rawPath === '.' || rawPath.startsWith('./') || rawPath.startsWith('../') || path.isAbsolute(rawPath)
  ) {
    return rawPath;
  }

  return `./${rawPath}`;
}

// @flow
import path from 'path';

export default function normalizePath(
  rawPath: ?string,
  workingDirectory: string,
): string {
  if (!rawPath) {
    return './';
  }

  if (rawPath.startsWith(workingDirectory)) {
    return `.${rawPath.slice(workingDirectory.length)}`;
  }

  if (rawPath.startsWith('/')) {
    return `.${rawPath}`;
  }

  if (
    rawPath === '.' || rawPath.startsWith('./') || rawPath.startsWith('../')
  ) {
    return rawPath;
  }

  return `./${rawPath}`;
}

Revert "Use path.isAbsolute"