Home / File/ shortcuts.ts — vite Source File

shortcuts.ts — vite Source File

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

File typescript ViteCore ConfigEngine 11 imports 4 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  ed89bdb5_1269_0bd7_7665_244657588aa2["shortcuts.ts"]
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e
  6f83f2b5_cff0_a52d_8544_cf0e1f4689fb["restartServerWithUrls"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 6f83f2b5_cff0_a52d_8544_cf0e1f4689fb
  31fbe894_2070_4b11_3ffa_96b46ed3dfa9["ViteDevServer"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 31fbe894_2070_4b11_3ffa_96b46ed3dfa9
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 031bc221_67a8_c579_f2bf_bb30a08beeb2
  40ede279_f539_5c9c_95c0_9686e55d8650["isDevServer"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 40ede279_f539_5c9c_95c0_9686e55d8650
  e49f0ff7_5101_3a1d_5a1f_33fae58eea2d["preview.ts"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> e49f0ff7_5101_3a1d_5a1f_33fae58eea2d
  5269a4be_cbb4_c413_4eb9_9ea227ac8b76["PreviewServer"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 5269a4be_cbb4_c413_4eb9_9ea227ac8b76
  42b33c04_e36e_8276_32b6_47412295d0b2["openBrowser.ts"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 42b33c04_e36e_8276_32b6_47412295d0b2
  9e1e86ba_9f46_dbe1_a8b7_cee1ecb37905["openBrowser"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> 9e1e86ba_9f46_dbe1_a8b7_cee1ecb37905
  e7403f2c_14d1_4dd2_bb6f_9ff8061aed49["node:readline"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> e7403f2c_14d1_4dd2_bb6f_9ff8061aed49
  bff4f846_ab01_b5ba_74d4_c1608e434d2c["picocolors"]
  ed89bdb5_1269_0bd7_7665_244657588aa2 --> bff4f846_ab01_b5ba_74d4_c1608e434d2c
  398088ae_77cc_a820_af72_6027733755e4["shortcuts.spec.ts"]
  398088ae_77cc_a820_af72_6027733755e4 --> ed89bdb5_1269_0bd7_7665_244657588aa2
  a4f486ae_83b9_5db5_eb04_81cee52d16a0["cli.ts"]
  a4f486ae_83b9_5db5_eb04_81cee52d16a0 --> ed89bdb5_1269_0bd7_7665_244657588aa2
  e49f0ff7_5101_3a1d_5a1f_33fae58eea2d["preview.ts"]
  e49f0ff7_5101_3a1d_5a1f_33fae58eea2d --> ed89bdb5_1269_0bd7_7665_244657588aa2
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"]
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e --> ed89bdb5_1269_0bd7_7665_244657588aa2
  style ed89bdb5_1269_0bd7_7665_244657588aa2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import readline from 'node:readline'
import colors from 'picocolors'
import { restartServerWithUrls } from './server'
import type { ViteDevServer } from './server'
import { isDevServer } from './utils'
import type { PreviewServer } from './preview'
import { openBrowser } from './server/openBrowser'

export type ShortcutsState<Server = ViteDevServer | PreviewServer> = {
  rl: readline.Interface
  options: BindCLIShortcutsOptions<Server>
}

export type BindCLIShortcutsOptions<Server = ViteDevServer | PreviewServer> = {
  /**
   * Print a one-line shortcuts "help" hint to the terminal
   */
  print?: boolean
  /**
   * Custom shortcuts to run when a key is pressed. These shortcuts take priority
   * over the default shortcuts if they have the same keys (except the `h` key).
   * To disable a default shortcut, define the same key but with `action: undefined`.
   */
  customShortcuts?: CLIShortcut<Server>[]
}

export type CLIShortcut<Server = ViteDevServer | PreviewServer> = {
  key: string
  description: string
  action?(server: Server): void | Promise<void>
}

export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
  server: Server,
  opts?: BindCLIShortcutsOptions<Server>,
  enabled: boolean = process.stdin.isTTY && !process.env.CI,
): void {
  if (!server.httpServer || !enabled) {
    return
  }

  const isDev = isDevServer(server)

  // Merge shortcuts: new at top, existing updated in place (keeps manual > plugin order)
  const previousShortcuts =
    server._shortcutsState?.options.customShortcuts ?? []
  const newShortcuts = opts?.customShortcuts ?? []
  const previousKeys = new Set(previousShortcuts.map((s) => s.key))
  const customShortcuts: CLIShortcut<ViteDevServer | PreviewServer>[] = [
    ...newShortcuts.filter((s) => !previousKeys.has(s.key)),
    ...previousShortcuts.map(
      (s) => newShortcuts.find((n) => n.key === s.key) ?? s,
    ),
  ]

  const newOptions: BindCLIShortcutsOptions<Server> = {
    ...opts,
    customShortcuts,
  }

// ... (137 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does shortcuts.ts do?
shortcuts.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 shortcuts.ts?
shortcuts.ts defines 1 function(s): bindCLIShortcuts.
What does shortcuts.ts depend on?
shortcuts.ts imports 11 module(s): PreviewServer, ViteDevServer, index.ts, isDevServer, node:readline, openBrowser, openBrowser.ts, picocolors, and 3 more.
What files import shortcuts.ts?
shortcuts.ts is imported by 4 file(s): cli.ts, index.ts, preview.ts, shortcuts.spec.ts.
Where is shortcuts.ts in the architecture?
shortcuts.ts is located at packages/vite/src/node/shortcuts.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