Home / Class/ ModuleRunner Class — vite Architecture

ModuleRunner Class — vite Architecture

Architecture documentation for the ModuleRunner class in runner.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  1d3ff778_7ac6_0038_640f_997e968c3c8f["ModuleRunner"]
  29e248d2_9983_1037_00e6_8bcd9ee87840["runner.ts"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|defined in| 29e248d2_9983_1037_00e6_8bcd9ee87840
  8db7bac6_7d0a_15b2_5870_1fd0e71b9cf5["constructor()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 8db7bac6_7d0a_15b2_5870_1fd0e71b9cf5
  bb00524b_0245_2d21_5a59_2a82dd570676["import()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| bb00524b_0245_2d21_5a59_2a82dd570676
  2b6b5b19_2cb4_2622_a7cd_12a09a5529d3["clearCache()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 2b6b5b19_2cb4_2622_a7cd_12a09a5529d3
  81d82a3f_7d9b_6907_d4ae_2560c2cf830c["close()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 81d82a3f_7d9b_6907_d4ae_2560c2cf830c
  2ca9c642_f3d6_040e_5699_d9c42ffa44e7["isClosed()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 2ca9c642_f3d6_040e_5699_d9c42ffa44e7
  5545fcba_59d0_ba73_89b7_11f4c41391bd["processImport()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 5545fcba_59d0_ba73_89b7_11f4c41391bd
  62a26ebe_568c_7e40_6141_02c130e85f05["isCircularModule()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 62a26ebe_568c_7e40_6141_02c130e85f05
  fa390543_1809_cca2_86cc_652c388b3899["isCircularImport()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| fa390543_1809_cca2_86cc_652c388b3899
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e["cachedRequest()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e
  1ca5cbd8_3591_8042_7bb5_fed80a4ac932["cachedModule()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 1ca5cbd8_3591_8042_7bb5_fed80a4ac932
  7ea4161b_ab41_b309_0390_3e9a8521014d["ensureBuiltins()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 7ea4161b_ab41_b309_0390_3e9a8521014d
  6d9a8fd8_b579_289e_b43c_8d04619aff11["getModuleInformation()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 6d9a8fd8_b579_289e_b43c_8d04619aff11
  2299eb48_afeb_b0e8_8b25_f24d005c00d4["directRequest()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f -->|method| 2299eb48_afeb_b0e8_8b25_f24d005c00d4

Relationship Graph

Source Code

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

export class ModuleRunner {
  public evaluatedModules: EvaluatedModules
  public hmrClient?: HMRClient

  private readonly transport: NormalizedModuleRunnerTransport
  private readonly resetSourceMapSupport?: () => void
  private readonly concurrentModuleNodePromises = new Map<
    string,
    Promise<EvaluatedModuleNode>
  >()
  private isBuiltin?: (id: string) => boolean
  private builtinsPromise?: Promise<void>

  private closed = false

  constructor(
    public options: ModuleRunnerOptions,
    public evaluator: ModuleEvaluator = new ESModulesEvaluator(),
    private debug?: ModuleRunnerDebugger | undefined,
  ) {
    this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules()
    this.transport = normalizeModuleRunnerTransport(options.transport)
    if (options.hmr !== false) {
      const optionsHmr = options.hmr ?? true
      const resolvedHmrLogger: HMRLogger =
        optionsHmr === true || optionsHmr.logger === undefined
          ? hmrLogger
          : optionsHmr.logger === false
            ? silentConsole
            : optionsHmr.logger
      this.hmrClient = new HMRClient(
        resolvedHmrLogger,
        this.transport,
        ({ acceptedPath }) => this.import(acceptedPath),
      )
      if (!this.transport.connect) {
        throw new Error(
          'HMR is not supported by this runner transport, but `hmr` option was set to true',
        )
      }
      this.transport.connect(createHMRHandlerForRunner(this))
    } else {
      this.transport.connect?.()
    }
    if (options.sourcemapInterceptor !== false) {
      this.resetSourceMapSupport = enableSourceMapSupport(this)
    }
  }

  /**
   * URL to execute. Accepts file path, server path or id relative to the root.
   */
  public async import<T = any>(url: string): Promise<T> {
    const fetchedModule = await this.cachedModule(url)
    return await this.cachedRequest(url, fetchedModule)
  }

  /**
   * Clear all caches including HMR listeners.
   */
  public clearCache(): void {
    this.evaluatedModules.clear()
    this.hmrClient?.clear()
  }

  /**
   * Clears all caches, removes all HMR listeners, and resets source map support.
   * This method doesn't stop the HMR connection.
   */
  public async close(): Promise<void> {
    this.resetSourceMapSupport?.()
    this.clearCache()
    this.hmrClient = undefined
    this.closed = true
    await this.transport.disconnect?.()
  }

  /**
   * Returns `true` if the runtime has been closed by calling `close()` method.
   */
  public isClosed(): boolean {

Domain

Frequently Asked Questions

What is the ModuleRunner class?
ModuleRunner is a class in the vite codebase, defined in packages/vite/src/module-runner/runner.ts.
Where is ModuleRunner defined?
ModuleRunner is defined in packages/vite/src/module-runner/runner.ts at line 38.

Analyze Your Own Codebase

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

Try Supermodel Free