react-server675fbba4
react-servertreemainpackagesreact-serverlibloaderutils.mjs
packages/react-server/lib/loader/utils.mjsmjs522 Bb5483a73
import { pathToFileURL } from "node:url";

import { normalizePath } from "../sys.mjs";

export function toFileURL(specifier) {
  if (
    /:\//.test(specifier) &&
    !specifier.startsWith("file:") &&
    !specifier.startsWith("data:") &&
    !specifier.startsWith("http:") &&
    !specifier.startsWith("https:")
  )
    return pathToFileURL(specifier).href;
  return specifier;
}

export function applyAlias(alias, specifier) {
  specifier = normalizePath(alias[specifier] ?? specifier);
  return toFileURL(specifier);
}