Home / Class/ TransformPluginContext Class — vite Architecture

TransformPluginContext Class — vite Architecture

Architecture documentation for the TransformPluginContext class in pluginContainer.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  bbea215d_7020_772f_d578_a87b3eba030c["TransformPluginContext"]
  3b8df068_35d0_2c94_3ad1_e93c93d1d613["pluginContainer.ts"]
  bbea215d_7020_772f_d578_a87b3eba030c -->|defined in| 3b8df068_35d0_2c94_3ad1_e93c93d1d613
  a5d27c62_2d14_1da0_d55d_7514df61bba4["constructor()"]
  bbea215d_7020_772f_d578_a87b3eba030c -->|method| a5d27c62_2d14_1da0_d55d_7514df61bba4
  3c78163f_527c_d054_7003_68d51942d57a["_getCombinedSourcemap()"]
  bbea215d_7020_772f_d578_a87b3eba030c -->|method| 3c78163f_527c_d054_7003_68d51942d57a
  7f968f26_079b_e4e6_bf70_99a14c481596["getCombinedSourcemap()"]
  bbea215d_7020_772f_d578_a87b3eba030c -->|method| 7f968f26_079b_e4e6_bf70_99a14c481596
  b7368e97_ca47_08c0_9ca2_49c2fa72e70d["_updateActiveInfo()"]
  bbea215d_7020_772f_d578_a87b3eba030c -->|method| b7368e97_ca47_08c0_9ca2_49c2fa72e70d

Relationship Graph

Source Code

packages/vite/src/node/server/pluginContainer.ts lines 1063–1173

class TransformPluginContext
  extends LoadPluginContext
  implements Omit<RollupTransformPluginContext, 'cache'>
{
  filename: string
  originalCode: string
  originalSourcemap: SourceMap | null = null
  sourcemapChain: NonNullable<SourceDescription['map']>[] = []
  combinedMap: SourceMap | { mappings: '' } | null = null

  constructor(
    container: EnvironmentPluginContainer,
    id: string,
    code: string,
    inMap?: SourceMap | string,
  ) {
    super(container)

    this.filename = id
    this.originalCode = code
    if (inMap) {
      if (debugSourcemapCombine) {
        // @ts-expect-error inject name for debug purpose
        inMap.name = '$inMap'
      }
      this.sourcemapChain.push(inMap)
    }
  }

  _getCombinedSourcemap(): SourceMap | { mappings: '' } | null {
    if (
      debugSourcemapCombine &&
      debugSourcemapCombineFilter &&
      this.filename.includes(debugSourcemapCombineFilter)
    ) {
      debugSourcemapCombine('----------', this.filename)
      debugSourcemapCombine(this.combinedMap)
      debugSourcemapCombine(this.sourcemapChain)
      debugSourcemapCombine('----------')
    }

    let combinedMap = this.combinedMap
    // { mappings: '' }
    if (
      combinedMap &&
      !('version' in combinedMap) &&
      combinedMap.mappings === ''
    ) {
      this.sourcemapChain.length = 0
      return combinedMap
    }

    for (let m of this.sourcemapChain) {
      if (typeof m === 'string') m = JSON.parse(m)
      if (!('version' in (m as SourceMap))) {
        // { mappings: '' }
        if ((m as SourceMap).mappings === '') {
          combinedMap = { mappings: '' }
          break
        }
        // empty, nullified source map
        combinedMap = null
        break
      }
      if (!combinedMap) {
        const sm = m as SourceMap
        // sourcemap should not include `sources: [null]` (because `sources` should be string) nor
        // `sources: ['']` (because `''` means the path of sourcemap)
        // but MagicString generates this when `filename` option is not set.
        // Rollup supports these and therefore we support this as well
        if (sm.sources.length === 1 && !sm.sources[0]) {
          combinedMap = {
            ...sm,
            sources: [this.filename],
            sourcesContent: [this.originalCode],
          }
        } else {
          combinedMap = sm
        }
      } else {
        combinedMap = combineSourcemaps(cleanUrl(this.filename), [

Domain

Frequently Asked Questions

What is the TransformPluginContext class?
TransformPluginContext is a class in the vite codebase, defined in packages/vite/src/node/server/pluginContainer.ts.
Where is TransformPluginContext defined?
TransformPluginContext is defined in packages/vite/src/node/server/pluginContainer.ts at line 1063.

Analyze Your Own Codebase

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

Try Supermodel Free