Home / File/ deprecations.ts — vite Source File

deprecations.ts — vite Source File

Architecture documentation for deprecations.ts, a typescript file in the vite codebase. 4 imports, 4 dependents.

File typescript ViteCore ConfigEngine 4 imports 4 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  8e764982_4d15_ae9b_89fa_c657779af0c5["deprecations.ts"]
  7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"]
  8e764982_4d15_ae9b_89fa_c657779af0c5 --> 7da774f9_eca5_d54e_6e01_6bee7d460a2b
  c0f95e79_2339_ea34_5b2e_489e1f43be5c["FutureOptions"]
  8e764982_4d15_ae9b_89fa_c657779af0c5 --> c0f95e79_2339_ea34_5b2e_489e1f43be5c
  eb5604c2_58e1_1c00_5a1a_5d97ea5236ad["ResolvedConfig"]
  8e764982_4d15_ae9b_89fa_c657779af0c5 --> eb5604c2_58e1_1c00_5a1a_5d97ea5236ad
  bff4f846_ab01_b5ba_74d4_c1608e434d2c["picocolors"]
  8e764982_4d15_ae9b_89fa_c657779af0c5 --> bff4f846_ab01_b5ba_74d4_c1608e434d2c
  45981d85_cbdd_e969_8c88_c17072ea0eda["build.ts"]
  45981d85_cbdd_e969_8c88_c17072ea0eda --> 8e764982_4d15_ae9b_89fa_c657779af0c5
  18db4f26_79f1_5b7d_b291_4feeaf95538f["hmr.ts"]
  18db4f26_79f1_5b7d_b291_4feeaf95538f --> 8e764982_4d15_ae9b_89fa_c657779af0c5
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"]
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e --> 8e764982_4d15_ae9b_89fa_c657779af0c5
  3b8df068_35d0_2c94_3ad1_e93c93d1d613["pluginContainer.ts"]
  3b8df068_35d0_2c94_3ad1_e93c93d1d613 --> 8e764982_4d15_ae9b_89fa_c657779af0c5
  style 8e764982_4d15_ae9b_89fa_c657779af0c5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import colors from 'picocolors'
import type { FutureOptions, ResolvedConfig } from './config'

const docsURL = 'https://vite.dev'

const deprecationCode = {
  removePluginHookSsrArgument: 'this-environment-in-hooks',
  removePluginHookHandleHotUpdate: 'hotupdate-hook',

  removeServerModuleGraph: 'per-environment-apis',
  removeServerReloadModule: 'per-environment-apis',
  removeServerPluginContainer: 'per-environment-apis',
  removeServerHot: 'per-environment-apis',
  removeServerTransformRequest: 'per-environment-apis',
  removeServerWarmupRequest: 'per-environment-apis',

  removeSsrLoadModule: 'ssr-using-modulerunner',
} satisfies Record<keyof FutureOptions, string>

const deprecationMessages = {
  removePluginHookSsrArgument:
    "Plugin hook `options.ssr` is replaced with `this.environment.config.consumer === 'server'`.",
  removePluginHookHandleHotUpdate:
    'Plugin hook `handleHotUpdate()` is replaced with `hotUpdate()`.',

  removeServerModuleGraph:
    'The `server.moduleGraph` is replaced with `this.environment.moduleGraph`.',
  removeServerReloadModule:
    'The `server.reloadModule` is replaced with `environment.reloadModule`.',
  removeServerPluginContainer:
    'The `server.pluginContainer` is replaced with `this.environment.pluginContainer`.',
  removeServerHot: 'The `server.hot` is replaced with `this.environment.hot`.',
  removeServerTransformRequest:
    'The `server.transformRequest` is replaced with `this.environment.transformRequest`.',
  removeServerWarmupRequest:
    'The `server.warmupRequest` is replaced with `this.environment.warmupRequest`.',

  removeSsrLoadModule:
    'The `server.ssrLoadModule` is replaced with Environment Runner.',
} satisfies Record<keyof FutureOptions, string>

let _ignoreDeprecationWarnings = false

export function isFutureDeprecationEnabled(
  config: ResolvedConfig,
  type: keyof FutureOptions,
): boolean {
  return !!config.future?.[type]
}

// Later we could have a `warnDeprecation` utils when the deprecation is landed
/**
 * Warn about future deprecations.
 */
export function warnFutureDeprecation(
  config: ResolvedConfig,
  type: keyof FutureOptions,
  extraMessage?: string,
  stacktrace = true,
): void {
  if (
    _ignoreDeprecationWarnings ||
    !config.future ||
    config.future[type] !== 'warn'
  )
    return

  let msg = `[vite future] ${deprecationMessages[type]}`
  if (extraMessage) {
    msg += ` ${extraMessage}`
  }
  msg = colors.yellow(msg)

  const docs = `${docsURL}/changes/${deprecationCode[type].toLowerCase()}`
  msg +=
    colors.gray(`\n  ${stacktrace ? '├' : '└'}─── `) +
    colors.underline(docs) +
    '\n'

  if (stacktrace) {
    const stack = new Error().stack
    if (stack) {
      let stacks = stack
        .split('\n')
        .slice(3)
        .filter((i) => !i.includes('/node_modules/vite/dist/'))
      if (stacks.length === 0) {
        stacks.push('No stack trace found.')
      }
      stacks = stacks.map(
        (i, idx) => `  ${idx === stacks.length - 1 ? '└' : '│'} ${i.trim()}`,
      )
      msg += colors.dim(stacks.join('\n')) + '\n'
    }
  }
  config.logger.warnOnce(msg)
}

export function ignoreDeprecationWarnings<T>(fn: () => T): T {
  const before = _ignoreDeprecationWarnings
  _ignoreDeprecationWarnings = true
  const ret = fn()
  _ignoreDeprecationWarnings = before
  return ret
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does deprecations.ts do?
deprecations.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 deprecations.ts?
deprecations.ts defines 3 function(s): ignoreDeprecationWarnings, isFutureDeprecationEnabled, warnFutureDeprecation.
What does deprecations.ts depend on?
deprecations.ts imports 4 module(s): FutureOptions, ResolvedConfig, config.ts, picocolors.
What files import deprecations.ts?
deprecations.ts is imported by 4 file(s): build.ts, hmr.ts, index.ts, pluginContainer.ts.
Where is deprecations.ts in the architecture?
deprecations.ts is located at packages/vite/src/node/deprecations.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node).

Analyze Your Own Codebase

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

Try Supermodel Free