Home / File/ sourcemap.ts — vite Source File

sourcemap.ts — vite Source File

Architecture documentation for sourcemap.ts, a typescript file in the vite codebase. 11 imports, 7 dependents.

File typescript ViteCore ConfigEngine 11 imports 7 dependents 7 functions

Entity Profile

Dependency Diagram

graph LR
  18244f7c_8357_ba88_c896_32c6447f1faf["sourcemap.ts"]
  eca93de5_04d5_dda0_7ae6_2ceb5379ea81["logger.ts"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> eca93de5_04d5_dda0_7ae6_2ceb5379ea81
  fff7f05e_fc73_d337_53a0_b846230bc8e2["Logger"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> fff7f05e_fc73_d337_53a0_b846230bc8e2
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> 031bc221_67a8_c579_f2bf_bb30a08beeb2
  c1f02fbb_c8c5_944a_d97f_c0ed9594418b["blankReplacer"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> c1f02fbb_c8c5_944a_d97f_c0ed9594418b
  23a2e685_f919_9578_27ba_bde71c122058["createDebugger"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> 23a2e685_f919_9578_27ba_bde71c122058
  abfc9e70_3c15_b3f0_a595_3cf27afb7e64["utils.ts"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  51e96894_3556_ed5c_1ede_97d449867adf["node:path"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> 51e96894_3556_ed5c_1ede_97d449867adf
  a09ff191_7c83_bdcd_30f1_b4e129910bf6["promises"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> a09ff191_7c83_bdcd_30f1_b4e129910bf6
  dc6f5c19_97fd_e1d7_2ae6_6a0d69e562e6["convert-source-map"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> dc6f5c19_97fd_e1d7_2ae6_6a0d69e562e6
  693ca867_249b_3e5a_0ce1_8930413b7fcd["rolldown"]
  18244f7c_8357_ba88_c896_32c6447f1faf --> 693ca867_249b_3e5a_0ce1_8930413b7fcd
  c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"]
  c3eb47df_971b_0616_6c9f_29b3ded72224 --> 18244f7c_8357_ba88_c896_32c6447f1faf
  04ad4685_2ce3_556a_152b_c93668a74b3b["importAnalysisBuild.ts"]
  04ad4685_2ce3_556a_152b_c93668a74b3b --> 18244f7c_8357_ba88_c896_32c6447f1faf
  3f56d5b2_9fca_532f_3bfc_6bfb2be77015["indexHtml.ts"]
  3f56d5b2_9fca_532f_3bfc_6bfb2be77015 --> 18244f7c_8357_ba88_c896_32c6447f1faf
  style 18244f7c_8357_ba88_c896_32c6447f1faf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import path from 'node:path'
import fsp from 'node:fs/promises'
import convertSourceMap from 'convert-source-map'
import type { ExistingRawSourceMap, SourceMap } from 'rolldown'
import type { Logger } from '../logger'
import { blankReplacer, createDebugger } from '../utils'
import { cleanUrl } from '../../shared/utils'

const debug = createDebugger('vite:sourcemap', {
  onlyWhenFocused: true,
})

// Virtual modules should be prefixed with a null byte to avoid a
// false positive "missing source" warning. We also check for certain
// prefixes used for special handling in esbuildDepPlugin.
const virtualSourceRE = /^(?:dep:|browser-external:|virtual:)|\0/

interface SourceMapLike {
  sources: string[]
  sourcesContent?: (string | null)[]
  sourceRoot?: string
}

async function computeSourceRoute(map: SourceMapLike, file: string) {
  let sourceRoot: string | undefined
  try {
    // The source root is undefined for virtual modules and permission errors.
    sourceRoot = await fsp.realpath(
      path.resolve(path.dirname(file), map.sourceRoot || ''),
    )
  } catch {}
  return sourceRoot
}

export async function injectSourcesContent(
  map: SourceMapLike,
  file: string,
  logger: Logger,
): Promise<void> {
  let sourceRootPromise: Promise<string | undefined>

  const missingSources: string[] = []
  const sourcesContent = map.sourcesContent || []
  const sourcesContentPromises: Promise<void>[] = []
  for (let index = 0; index < map.sources.length; index++) {
    const sourcePath = map.sources[index]
    if (
      sourcesContent[index] == null &&
      sourcePath &&
      !virtualSourceRE.test(sourcePath)
    ) {
      sourcesContentPromises.push(
        (async () => {
          // inject content from source file when sourcesContent is null
          sourceRootPromise ??= computeSourceRoute(map, file)
          const sourceRoot = await sourceRootPromise
          let resolvedSourcePath = cleanUrl(decodeURI(sourcePath))
          if (sourceRoot) {
            resolvedSourcePath = path.resolve(sourceRoot, resolvedSourcePath)
          }
// ... (120 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does sourcemap.ts do?
sourcemap.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain, ConfigEngine subdomain.
What functions are defined in sourcemap.ts?
sourcemap.ts defines 7 function(s): applySourcemapIgnoreList, computeSourceRoute, createConvertSourceMapReadMap, extractSourcemapFromFile, genSourceMapUrl, getCodeWithSourcemap, injectSourcesContent.
What does sourcemap.ts depend on?
sourcemap.ts imports 11 module(s): Logger, blankReplacer, cleanUrl, convert-source-map, createDebugger, logger.ts, node:path, promises, and 3 more.
What files import sourcemap.ts?
sourcemap.ts is imported by 7 file(s): css.ts, fetchModule.ts, importAnalysisBuild.ts, indexHtml.ts, send.ts, transform.ts, transformRequest.ts.
Where is sourcemap.ts in the architecture?
sourcemap.ts is located at packages/vite/src/node/server/sourcemap.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/server).

Analyze Your Own Codebase

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

Try Supermodel Free