Home / File/ runnableEnvironment.ts — vite Source File

runnableEnvironment.ts — vite Source File

Architecture documentation for runnableEnvironment.ts, a typescript file in the vite codebase. 13 imports, 2 dependents.

File typescript ViteCore ConfigEngine 13 imports 2 dependents 3 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  e21da89c_08b2_d4be_4023_7ef3ad334bdb["runnableEnvironment.ts"]
  7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 7da774f9_eca5_d54e_6e01_6bee7d460a2b
  eb5604c2_58e1_1c00_5a1a_5d97ea5236ad["ResolvedConfig"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> eb5604c2_58e1_1c00_5a1a_5d97ea5236ad
  7916c84f_5621_2b3b_d220_a171ebce997f["environment.ts"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 7916c84f_5621_2b3b_d220_a171ebce997f
  70c452df_b1b7_50ef_d90e_5bd179627481["DevEnvironmentContext"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 70c452df_b1b7_50ef_d90e_5bd179627481
  f634223d_ed8e_a65b_08f8_a839ec17994a["DevEnvironment"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> f634223d_ed8e_a65b_08f8_a839ec17994a
  d14cf24c_f830_6905_0df1_4e9b0f67c84b["serverModuleRunner.ts"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> d14cf24c_f830_6905_0df1_4e9b0f67c84b
  981bce9f_678d_05fa_327e_a90532eff213["ServerModuleRunnerOptions"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 981bce9f_678d_05fa_327e_a90532eff213
  ebea5da1_fa3d_b3f6_9793_71dfb88847a4["createServerModuleRunner"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> ebea5da1_fa3d_b3f6_9793_71dfb88847a4
  18db4f26_79f1_5b7d_b291_4feeaf95538f["hmr.ts"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 18db4f26_79f1_5b7d_b291_4feeaf95538f
  3ae37b09_9e5f_0382_d4ac_99a73ab344c3["createServerHotChannel"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 3ae37b09_9e5f_0382_d4ac_99a73ab344c3
  0c33ff62_54e9_5c90_902b_b26728e71fca["environment.ts"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 0c33ff62_54e9_5c90_902b_b26728e71fca
  7e6f7c83_3515_4e0d_5362_4eb9515b4a86["Environment"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 7e6f7c83_3515_4e0d_5362_4eb9515b4a86
  9ca835cf_b489_83a7_91dd_00ed2ef4e6f6["module-runner"]
  e21da89c_08b2_d4be_4023_7ef3ad334bdb --> 9ca835cf_b489_83a7_91dd_00ed2ef4e6f6
  7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"]
  7da774f9_eca5_d54e_6e01_6bee7d460a2b --> e21da89c_08b2_d4be_4023_7ef3ad334bdb
  b5e1db85_5394_4902_e419_6145447db3eb["runnerImport.ts"]
  b5e1db85_5394_4902_e419_6145447db3eb --> e21da89c_08b2_d4be_4023_7ef3ad334bdb
  style e21da89c_08b2_d4be_4023_7ef3ad334bdb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { ModuleRunner } from 'vite/module-runner'
import type { ResolvedConfig } from '../../config'
import type { DevEnvironmentContext } from '../environment'
import { DevEnvironment } from '../environment'
import type { ServerModuleRunnerOptions } from '../../ssr/runtime/serverModuleRunner'
import { createServerModuleRunner } from '../../ssr/runtime/serverModuleRunner'
import { createServerHotChannel } from '../hmr'
import type { Environment } from '../../environment'

export function createRunnableDevEnvironment(
  name: string,
  config: ResolvedConfig,
  context: RunnableDevEnvironmentContext = {},
): RunnableDevEnvironment {
  if (context.transport == null) {
    context.transport = createServerHotChannel()
  }
  if (context.hot == null) {
    context.hot = true
  }

  return new RunnableDevEnvironment(name, config, context)
}

export interface RunnableDevEnvironmentContext extends Omit<
  DevEnvironmentContext,
  'hot'
> {
  runner?: (
    environment: RunnableDevEnvironment,
    options?: ServerModuleRunnerOptions,
  ) => ModuleRunner
  runnerOptions?: ServerModuleRunnerOptions
  hot?: boolean
}

export function isRunnableDevEnvironment(
  environment: Environment,
): environment is RunnableDevEnvironment {
  return environment instanceof RunnableDevEnvironment
}

class RunnableDevEnvironment extends DevEnvironment {
  private _runner: ModuleRunner | undefined
  private _runnerFactory:
    | ((
        environment: RunnableDevEnvironment,
        options?: ServerModuleRunnerOptions,
      ) => ModuleRunner)
    | undefined
  private _runnerOptions: ServerModuleRunnerOptions | undefined

  constructor(
    name: string,
    config: ResolvedConfig,
    context: RunnableDevEnvironmentContext,
  ) {
    super(name, config, context as DevEnvironmentContext)
    this._runnerFactory = context.runner
    this._runnerOptions = context.runnerOptions
  }

  get runner(): ModuleRunner {
    if (this._runner) {
      return this._runner
    }
    const factory = this._runnerFactory || createServerModuleRunner
    this._runner = factory(this, this._runnerOptions)
    return this._runner
  }

  override async close(): Promise<void> {
    await super.close()
    if (this._runner) {
      await this._runner.close()
    }
  }
}

export type { RunnableDevEnvironment }

Domain

Subdomains

Frequently Asked Questions

What does runnableEnvironment.ts do?
runnableEnvironment.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 runnableEnvironment.ts?
runnableEnvironment.ts defines 3 function(s): ModuleRunner, createRunnableDevEnvironment, isRunnableDevEnvironment.
What does runnableEnvironment.ts depend on?
runnableEnvironment.ts imports 13 module(s): DevEnvironment, DevEnvironmentContext, Environment, ResolvedConfig, ServerModuleRunnerOptions, config.ts, createServerHotChannel, createServerModuleRunner, and 5 more.
What files import runnableEnvironment.ts?
runnableEnvironment.ts is imported by 2 file(s): config.ts, runnerImport.ts.
Where is runnableEnvironment.ts in the architecture?
runnableEnvironment.ts is located at packages/vite/src/node/server/environments/runnableEnvironment.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/server/environments).

Analyze Your Own Codebase

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

Try Supermodel Free