Skip to main content

stylex_path_resolver/utils/
mod.rs

1use std::path::{Path, PathBuf};
2
3use path_clean::PathClean;
4use stylex_macros::stylex_panic;
5
6pub(crate) fn contains_subpath(path: &Path, sub_path: &Path) -> bool {
7  path
8    .display()
9    .to_string()
10    .split("/")
11    .any(|part| part == sub_path.display().to_string())
12}
13
14pub fn relative_path(file_path: &Path, root: &Path) -> PathBuf {
15  pathdiff::diff_paths(file_path, root)
16    .unwrap_or_else(|| {
17      stylex_panic!(
18        "Failed to get relative path for file {} based on root {}",
19        file_path.display(),
20        root.display()
21      )
22    })
23    .clean()
24}