From 26e893afe6ed0f97f4788b3b8ca9e1f959613356 Mon Sep 17 00:00:00 2001 From: nicholaslyang Date: Thu, 19 Sep 2024 16:36:45 -0400 Subject: [PATCH] PR feedback --- crates/turbo-trace/src/main.rs | 2 +- crates/turbo-trace/src/tracer.rs | 11 +++++++---- crates/turborepo-lib/src/query/file.rs | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/turbo-trace/src/main.rs b/crates/turbo-trace/src/main.rs index 736c3bad890c7..be8c5cd79857c 100644 --- a/crates/turbo-trace/src/main.rs +++ b/crates/turbo-trace/src/main.rs @@ -30,7 +30,7 @@ fn main() -> Result<(), PathError> { .map(|f| AbsoluteSystemPathBuf::from_unknown(&abs_cwd, f)) .collect(); - let tracer = Tracer::new(files, abs_cwd, args.ts_config)?; + let tracer = Tracer::new(abs_cwd, files, args.ts_config)?; let result = tracer.trace(); diff --git a/crates/turbo-trace/src/tracer.rs b/crates/turbo-trace/src/tracer.rs index ba5e4260d6c6c..c7c302b6159ee 100644 --- a/crates/turbo-trace/src/tracer.rs +++ b/crates/turbo-trace/src/tracer.rs @@ -15,7 +15,6 @@ use turbopath::{AbsoluteSystemPathBuf, PathError}; use crate::import_finder::ImportFinder; pub struct Tracer { - cwd: AbsoluteSystemPathBuf, files: Vec, seen: HashSet, ts_config: Option, @@ -28,6 +27,8 @@ pub enum TraceError { FileNotFound(AbsoluteSystemPathBuf), #[error(transparent)] PathEncoding(PathError), + #[error("tracing a root file `{0}`, no parent found")] + RootFile(AbsoluteSystemPathBuf), #[error("failed to resolve import")] Resolve { #[label("import here")] @@ -44,8 +45,8 @@ pub struct TraceResult { impl Tracer { pub fn new( - files: Vec, cwd: AbsoluteSystemPathBuf, + files: Vec, ts_config: Option, ) -> Result { let ts_config = @@ -54,7 +55,6 @@ impl Tracer { let seen = HashSet::new(); Ok(Self { - cwd, files, seen, ts_config, @@ -138,7 +138,10 @@ impl Tracer { // Convert found imports/requires to absolute paths and add them to files to // visit for (import, span) in finder.imports() { - let file_dir = file_path.parent().unwrap_or(&self.cwd); + let Some(file_dir) = file_path.parent() else { + errors.push(TraceError::RootFile(file_path.to_owned())); + continue; + }; match resolver.resolve(&file_dir, &import) { Ok(resolved) => match resolved.into_path_buf().try_into() { Ok(path) => self.files.push(path), diff --git a/crates/turborepo-lib/src/query/file.rs b/crates/turborepo-lib/src/query/file.rs index a4f57f4872ead..717f4d136fd94 100644 --- a/crates/turborepo-lib/src/query/file.rs +++ b/crates/turborepo-lib/src/query/file.rs @@ -39,8 +39,8 @@ impl File { async fn dependencies(&self) -> Result, Error> { let tracer = Tracer::new( - vec![self.path.clone()], self.run.repo_root().to_owned(), + vec![self.path.clone()], None, )?;