Skip to content

Commit 21b071a

Browse files
authored
refactor: change find_closest_pnp_manifest_path from recursion to a loop (#35)
1 parent 1a18fec commit 21b071a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,14 @@ pub fn parse_bare_identifier(specifier: &str) -> Result<(String, Option<String>)
8484
})
8585
}
8686

87-
pub fn find_closest_pnp_manifest_path<P: AsRef<Path>>(p: P) -> Option<PathBuf> {
88-
let pnp_path = p.as_ref().join(".pnp.cjs");
89-
90-
if pnp_path.exists() {
91-
Some(pnp_path)
92-
} else if let Some(directory_path) = p.as_ref().parent() {
93-
find_closest_pnp_manifest_path(directory_path)
94-
} else {
95-
None
87+
pub fn find_closest_pnp_manifest_path(path: &Path) -> Option<PathBuf> {
88+
for p in path.ancestors() {
89+
let pnp_path = p.join(".pnp.cjs");
90+
if pnp_path.exists() {
91+
return Some(pnp_path);
92+
}
9693
}
94+
None
9795
}
9896

9997
pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {

0 commit comments

Comments
 (0)