Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Sep 19, 2024
1 parent ae983e0 commit 26e893a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/turbo-trace/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 7 additions & 4 deletions crates/turbo-trace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use turbopath::{AbsoluteSystemPathBuf, PathError};
use crate::import_finder::ImportFinder;

pub struct Tracer {
cwd: AbsoluteSystemPathBuf,
files: Vec<AbsoluteSystemPathBuf>,
seen: HashSet<AbsoluteSystemPathBuf>,
ts_config: Option<AbsoluteSystemPathBuf>,
Expand All @@ -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")]
Expand All @@ -44,8 +45,8 @@ pub struct TraceResult {

impl Tracer {
pub fn new(
files: Vec<AbsoluteSystemPathBuf>,
cwd: AbsoluteSystemPathBuf,
files: Vec<AbsoluteSystemPathBuf>,
ts_config: Option<Utf8PathBuf>,
) -> Result<Self, PathError> {
let ts_config =
Expand All @@ -54,7 +55,6 @@ impl Tracer {
let seen = HashSet::new();

Ok(Self {
cwd,
files,
seen,
ts_config,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/query/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl File {

async fn dependencies(&self) -> Result<Vec<File>, Error> {
let tracer = Tracer::new(
vec![self.path.clone()],
self.run.repo_root().to_owned(),
vec![self.path.clone()],
None,
)?;

Expand Down

0 comments on commit 26e893a

Please sign in to comment.