Home / File/ watch.ts — vite Source File

watch.ts — vite Source File

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

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

Entity Profile

Dependency Diagram

graph LR
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714["watch.ts"]
  abfc9e70_3c15_b3f0_a595_3cf27afb7e64["utils.ts"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64
  1a3bec7b_1a11_316f_5831_a0535b829bbf["withTrailingSlash"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> 1a3bec7b_1a11_316f_5831_a0535b829bbf
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> 031bc221_67a8_c579_f2bf_bb30a08beeb2
  19ce2051_6a74_4b8b_104d_ec006cd7075f["arraify"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> 19ce2051_6a74_4b8b_104d_ec006cd7075f
  a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> a4adb1a7_cf54_091f_eb63_8217e684a8e1
  eca93de5_04d5_dda0_7ae6_2ceb5379ea81["logger.ts"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> eca93de5_04d5_dda0_7ae6_2ceb5379ea81
  fff7f05e_fc73_d337_53a0_b846230bc8e2["Logger"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> fff7f05e_fc73_d337_53a0_b846230bc8e2
  d55a9cec_90e1_f4ad_d084_e5cf07bdef40["node:events"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> d55a9cec_90e1_f4ad_d084_e5cf07bdef40
  51e96894_3556_ed5c_1ede_97d449867adf["node:path"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> 51e96894_3556_ed5c_1ede_97d449867adf
  693ca867_249b_3e5a_0ce1_8930413b7fcd["rolldown"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> 693ca867_249b_3e5a_0ce1_8930413b7fcd
  bff4f846_ab01_b5ba_74d4_c1608e434d2c["picocolors"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> bff4f846_ab01_b5ba_74d4_c1608e434d2c
  f768205a_533a_2be3_ec95_10f7f47d71ce["tinyglobby"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> f768205a_533a_2be3_ec95_10f7f47d71ce
  fc2cc0b9_ab54_b54a_a79d_258dcdef2f43["chokidar"]
  b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 --> fc2cc0b9_ab54_b54a_a79d_258dcdef2f43
  45981d85_cbdd_e969_8c88_c17072ea0eda["build.ts"]
  45981d85_cbdd_e969_8c88_c17072ea0eda --> b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714
  style b4c4dcfb_d52b_008a_a6fc_ed4f2bf1f714 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { EventEmitter } from 'node:events'
import path from 'node:path'
import type { OutputOptions, WatcherOptions } from 'rolldown'
import colors from 'picocolors'
import { escapePath } from 'tinyglobby'
import type { FSWatcher, WatchOptions } from '#dep-types/chokidar'
import { withTrailingSlash } from '../shared/utils'
import { arraify, normalizePath } from './utils'
import type { Logger } from './logger'

export function getResolvedOutDirs(
  root: string,
  outDir: string,
  outputOptions: OutputOptions[] | OutputOptions | undefined,
): Set<string> {
  const resolvedOutDir = path.resolve(root, outDir)
  if (!outputOptions) return new Set([resolvedOutDir])

  return new Set(
    arraify(outputOptions).map(({ dir }) =>
      dir ? path.resolve(root, dir) : resolvedOutDir,
    ),
  )
}

export function resolveEmptyOutDir(
  emptyOutDir: boolean | null,
  root: string,
  outDirs: Set<string>,
  logger?: Logger,
): boolean {
  if (emptyOutDir != null) return emptyOutDir

  for (const outDir of outDirs) {
    if (!normalizePath(outDir).startsWith(withTrailingSlash(root))) {
      // warn if outDir is outside of root
      logger?.warn(
        colors.yellow(
          `\n${colors.bold(`(!)`)} outDir ${colors.white(
            colors.dim(outDir),
          )} is not inside project root and will not be emptied.\n` +
            `Use --emptyOutDir to override.\n`,
        ),
      )
      return false
    }
  }
  return true
}

export function resolveChokidarOptions(
  options: WatchOptions | undefined,
  resolvedOutDirs: Set<string>,
  emptyOutDir: boolean,
  cacheDir: string,
): WatchOptions {
  const { ignored: ignoredList, ...otherOptions } = options ?? {}
  const ignored: WatchOptions['ignored'] = [
    '**/.git/**',
    '**/node_modules/**',
// ... (64 more lines)

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does watch.ts do?
watch.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 watch.ts?
watch.ts defines 5 function(s): convertToNotifyOptions, createNoopWatcher, getResolvedOutDirs, resolveChokidarOptions, resolveEmptyOutDir.
What does watch.ts depend on?
watch.ts imports 13 module(s): Logger, arraify, chokidar, logger.ts, node:events, node:path, normalizePath, picocolors, and 5 more.
What files import watch.ts?
watch.ts is imported by 3 file(s): build.ts, index.ts, prepareOutDir.ts.
Where is watch.ts in the architecture?
watch.ts is located at packages/vite/src/node/watch.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