openBrowser.ts — vite Source File
Architecture documentation for openBrowser.ts, a typescript file in the vite codebase. 8 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 42b33c04_e36e_8276_32b6_47412295d0b2["openBrowser.ts"] eca93de5_04d5_dda0_7ae6_2ceb5379ea81["logger.ts"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> eca93de5_04d5_dda0_7ae6_2ceb5379ea81 fff7f05e_fc73_d337_53a0_b846230bc8e2["Logger"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> fff7f05e_fc73_d337_53a0_b846230bc8e2 545df65b_7f67_94d3_e2e8_a592d5e64b8f["constants.ts"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> 545df65b_7f67_94d3_e2e8_a592d5e64b8f 51e96894_3556_ed5c_1ede_97d449867adf["node:path"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> 51e96894_3556_ed5c_1ede_97d449867adf 2dd48a01_733b_e717_9c4b_f4fe7eb42567["node:child_process"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> 2dd48a01_733b_e717_9c4b_f4fe7eb42567 3d8f1fd4_9c9e_0bd4_b481_4f540b320ed2["open"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> 3d8f1fd4_9c9e_0bd4_b481_4f540b320ed2 4b6c8853_2812_b8f0_6998_2e15bbc9c835["cross-spawn"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> 4b6c8853_2812_b8f0_6998_2e15bbc9c835 bff4f846_ab01_b5ba_74d4_c1608e434d2c["picocolors"] 42b33c04_e36e_8276_32b6_47412295d0b2 --> bff4f846_ab01_b5ba_74d4_c1608e434d2c e49f0ff7_5101_3a1d_5a1f_33fae58eea2d["preview.ts"] e49f0ff7_5101_3a1d_5a1f_33fae58eea2d --> 42b33c04_e36e_8276_32b6_47412295d0b2 a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"] a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e --> 42b33c04_e36e_8276_32b6_47412295d0b2 ed89bdb5_1269_0bd7_7665_244657588aa2["shortcuts.ts"] ed89bdb5_1269_0bd7_7665_244657588aa2 --> 42b33c04_e36e_8276_32b6_47412295d0b2 style 42b33c04_e36e_8276_32b6_47412295d0b2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* The following is modified based on source found in
* https://github.com/facebook/create-react-app
*
* MIT Licensed
* Copyright (c) 2015-present, Facebook, Inc.
* https://github.com/facebook/create-react-app/blob/main/LICENSE
*
*/
import { join } from 'node:path'
import { exec } from 'node:child_process'
import type { ExecOptions } from 'node:child_process'
import open from 'open'
import type { Options } from 'open'
import spawn from 'cross-spawn'
import colors from 'picocolors'
import type { Logger } from '../logger'
import { VITE_PACKAGE_DIR } from '../constants'
/**
* Reads the BROWSER environment variable and decides what to do with it.
*/
export function openBrowser(
url: string,
opt: string | true,
logger: Logger,
): void {
// The browser executable to open.
// See https://github.com/sindresorhus/open#app for documentation.
const browser = typeof opt === 'string' ? opt : process.env.BROWSER || ''
if (browser.toLowerCase().endsWith('.js')) {
executeNodeScript(browser, url, logger)
} else if (browser.toLowerCase() !== 'none') {
const browserArgs = process.env.BROWSER_ARGS
? process.env.BROWSER_ARGS.split(' ')
: []
startBrowserProcess(browser, browserArgs, url, logger)
}
}
function executeNodeScript(scriptPath: string, url: string, logger: Logger) {
const extraArgs = process.argv.slice(2)
const child = spawn(process.execPath, [scriptPath, ...extraArgs, url], {
stdio: 'inherit',
})
child.on('close', (code) => {
if (code !== 0) {
logger.error(
colors.red(
`\nThe script specified as BROWSER environment variable failed.\n\n${colors.cyan(
scriptPath,
)} exited with code ${code}.`,
),
{ error: null },
)
}
})
}
// ... (90 more lines)
Domain
Subdomains
Dependencies
- Logger
- constants.ts
- cross-spawn
- logger.ts
- node:child_process
- node:path
- open
- picocolors
Imported By
Source
Frequently Asked Questions
What does openBrowser.ts do?
openBrowser.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 openBrowser.ts?
openBrowser.ts defines 4 function(s): execAsync, executeNodeScript, openBrowser, startBrowserProcess.
What does openBrowser.ts depend on?
openBrowser.ts imports 8 module(s): Logger, constants.ts, cross-spawn, logger.ts, node:child_process, node:path, open, picocolors.
What files import openBrowser.ts?
openBrowser.ts is imported by 3 file(s): index.ts, preview.ts, shortcuts.ts.
Where is openBrowser.ts in the architecture?
openBrowser.ts is located at packages/vite/src/node/server/openBrowser.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/server).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free