Skip to main content

floe/
lib.rs

1pub mod checker;
2pub mod codegen;
3pub mod cst;
4pub mod desugar;
5pub mod diagnostic;
6pub mod formatter;
7pub mod interop;
8pub mod lexer;
9pub mod lower;
10pub mod lsp;
11pub mod parser;
12pub mod resolve;
13pub mod sourcemap;
14pub mod stdlib;
15pub mod syntax;
16pub mod type_layout;
17pub mod walk;
18
19use std::path::{Path, PathBuf};
20
21/// Find the project root directory (where node_modules lives).
22/// Prioritizes finding `node_modules` over `package.json` to handle
23/// pnpm workspaces where node_modules is hoisted to the workspace root.
24pub fn find_project_dir(start: &Path) -> PathBuf {
25    let mut dir = start.to_path_buf();
26    let mut package_json_dir: Option<PathBuf> = None;
27    loop {
28        if dir.join("node_modules").is_dir() {
29            return dir;
30        }
31        if package_json_dir.is_none() && dir.join("package.json").is_file() {
32            package_json_dir = Some(dir.clone());
33        }
34        if !dir.pop() {
35            return package_json_dir.unwrap_or_else(|| start.to_path_buf());
36        }
37    }
38}