searchRoot.ts — vite Source File
Architecture documentation for searchRoot.ts, a typescript file in the vite codebase. 4 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 497939be_63aa_81b3_3492_3f2698d33097["searchRoot.ts"] 031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"] 497939be_63aa_81b3_3492_3f2698d33097 --> 031bc221_67a8_c579_f2bf_bb30a08beeb2 98952751_e0cf_2bf3_c4a0_2fde2526872b["isFileReadable"] 497939be_63aa_81b3_3492_3f2698d33097 --> 98952751_e0cf_2bf3_c4a0_2fde2526872b e6032fbc_44cf_58d6_868d_dd15106c18c5["node:fs"] 497939be_63aa_81b3_3492_3f2698d33097 --> e6032fbc_44cf_58d6_868d_dd15106c18c5 51e96894_3556_ed5c_1ede_97d449867adf["node:path"] 497939be_63aa_81b3_3492_3f2698d33097 --> 51e96894_3556_ed5c_1ede_97d449867adf c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"] c3eb47df_971b_0616_6c9f_29b3ded72224 --> 497939be_63aa_81b3_3492_3f2698d33097 57a3afd7_ead8_9778_dae5_d7cbe644bfa5["search-root.spec.ts"] 57a3afd7_ead8_9778_dae5_d7cbe644bfa5 --> 497939be_63aa_81b3_3492_3f2698d33097 a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"] a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e --> 497939be_63aa_81b3_3492_3f2698d33097 style 497939be_63aa_81b3_3492_3f2698d33097 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs'
import { dirname, join } from 'node:path'
import { isFileReadable } from '../utils'
// https://github.com/vitejs/vite/issues/2820#issuecomment-812495079
const ROOT_FILES = [
// '.git',
// https://pnpm.io/workspaces/
'pnpm-workspace.yaml',
// https://rushjs.io/pages/advanced/config_files/
// 'rush.json',
// https://nx.dev/latest/react/getting-started/nx-setup
// 'workspace.json',
// 'nx.json',
// https://github.com/lerna/lerna#lernajson
'lerna.json',
]
// npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
// yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
function hasWorkspacePackageJSON(root: string): boolean {
const path = join(root, 'package.json')
if (!isFileReadable(path)) {
return false
}
try {
const content = JSON.parse(fs.readFileSync(path, 'utf-8')) || {}
return !!content.workspaces
} catch {
return false
}
}
function hasRootFile(root: string): boolean {
return ROOT_FILES.some((file) => fs.existsSync(join(root, file)))
}
function hasPackageJSON(root: string) {
const path = join(root, 'package.json')
return fs.existsSync(path)
}
/**
* Search up for the nearest `package.json`
*/
export function searchForPackageRoot(
current: string,
root: string = current,
): string {
if (hasPackageJSON(current)) return current
const dir = dirname(current)
// reach the fs root
if (!dir || dir === current) return root
return searchForPackageRoot(dir, root)
}
/**
* Search up for the nearest workspace root
*/
export function searchForWorkspaceRoot(
current: string,
root: string = searchForPackageRoot(current),
): string {
if (hasRootFile(current)) return current
if (hasWorkspacePackageJSON(current)) return current
const dir = dirname(current)
// reach the fs root
if (!dir || dir === current) return root
return searchForWorkspaceRoot(dir, root)
}
Domain
Subdomains
Functions
Dependencies
- isFileReadable
- node:fs
- node:path
- utils.ts
Imported By
Source
Frequently Asked Questions
What does searchRoot.ts do?
searchRoot.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 searchRoot.ts?
searchRoot.ts defines 5 function(s): hasPackageJSON, hasRootFile, hasWorkspacePackageJSON, searchForPackageRoot, searchForWorkspaceRoot.
What does searchRoot.ts depend on?
searchRoot.ts imports 4 module(s): isFileReadable, node:fs, node:path, utils.ts.
What files import searchRoot.ts?
searchRoot.ts is imported by 3 file(s): css.ts, index.ts, search-root.spec.ts.
Where is searchRoot.ts in the architecture?
searchRoot.ts is located at packages/vite/src/node/server/searchRoot.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