Home / Function/ posixPathToFileHref() — vite Function Reference

posixPathToFileHref() — vite Function Reference

Architecture documentation for the posixPathToFileHref() function in utils.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  b4ab10d7_7a96_e400_2c45_786b44953214["posixPathToFileHref()"]
  81939ddb_795d_a69b_d1ea_fb1af459ccc2["utils.ts"]
  b4ab10d7_7a96_e400_2c45_786b44953214 -->|defined in| 81939ddb_795d_a69b_d1ea_fb1af459ccc2
  53d393ac_4ea6_3b84_76f8_1b1311b1aa3b["createDefaultImportMeta()"]
  53d393ac_4ea6_3b84_76f8_1b1311b1aa3b -->|calls| b4ab10d7_7a96_e400_2c45_786b44953214
  2299eb48_afeb_b0e8_8b25_f24d005c00d4["directRequest()"]
  2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| b4ab10d7_7a96_e400_2c45_786b44953214
  4c45fe85_e616_b54f_b767_19224269b055["encodePathChars()"]
  b4ab10d7_7a96_e400_2c45_786b44953214 -->|calls| 4c45fe85_e616_b54f_b767_19224269b055
  style b4ab10d7_7a96_e400_2c45_786b44953214 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/module-runner/utils.ts lines 38–61

export function posixPathToFileHref(posixPath: string): string {
  let resolved = posixResolve(posixPath)
  // path.resolve strips trailing slashes so we must add them back
  const filePathLast = posixPath.charCodeAt(posixPath.length - 1)
  if (
    (filePathLast === CHAR_FORWARD_SLASH ||
      (isWindows && filePathLast === CHAR_BACKWARD_SLASH)) &&
    resolved[resolved.length - 1] !== '/'
  )
    resolved += '/'

  // Call encodePathChars first to avoid encoding % again for ? and #.
  resolved = encodePathChars(resolved)

  // Question and hash character should be included in pathname.
  // Therefore, encoding is required to eliminate parsing them in different states.
  // This is done as an optimization to not creating a URL instance and
  // later triggering pathname setter, which impacts performance
  if (resolved.indexOf('?') !== -1)
    resolved = resolved.replace(questionRegex, '%3F')
  if (resolved.indexOf('#') !== -1)
    resolved = resolved.replace(hashRegex, '%23')
  return new URL(`file://${resolved}`).href
}

Domain

Subdomains

Frequently Asked Questions

What does posixPathToFileHref() do?
posixPathToFileHref() is a function in the vite codebase, defined in packages/vite/src/module-runner/utils.ts.
Where is posixPathToFileHref() defined?
posixPathToFileHref() is defined in packages/vite/src/module-runner/utils.ts at line 38.
What does posixPathToFileHref() call?
posixPathToFileHref() calls 1 function(s): encodePathChars.
What calls posixPathToFileHref()?
posixPathToFileHref() is called by 2 function(s): createDefaultImportMeta, directRequest.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free