-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(query): reverse tracing #9319
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
8 Skipped Deployments
|
255d821
to
f86b92f
Compare
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
|
||
let mut parser = Parser::new_from(Capturing::new(lexer)); | ||
pub async fn reverse_trace(mut self) -> TraceResult { | ||
let files = match globwalk::globwalk( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love at some point to combine the glob walking and the import resolution so that we can have more concurrency. Right now we have to walk the entire repo, then do the import resolution step.
bea056c
to
22f49ea
Compare
22f49ea
to
f6e69f7
Compare
c7ef347
to
1a1ccb2
Compare
…ixes in a repo where we may have multiple tsconfigs
…s easy when you can make them really annoying
a2797a9
to
971471a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Before we do any perf tinkering we should collect some profiles or set up a benchmark.
for error in &result.errors { | ||
eprintln!("error: {}", error); | ||
for error in result.errors { | ||
println!("{:?}", Report::new(error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we're printing errors to stdout?
println!("{:?}", Report::new(error)) | |
eprintln!("{:?}", Report::new(error)) |
@@ -12,12 +13,17 @@ struct Args { | |||
cwd: Option<Utf8PathBuf>, | |||
#[clap(long)] | |||
ts_config: Option<Utf8PathBuf>, | |||
#[clap(long)] | |||
node_modules: Option<Utf8PathBuf>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be any node_modules
or should it be the most specific one available?
e.g. repo/node_modules
or repo/packages/foo/node_modules
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y'know I'm not exactly sure. oxc_resolver
is a little ambiguous here. This CLI isn't meant for public use, mostly just for testing
crates/turborepo-lib/src/cli/mod.rs
Outdated
#[cfg(windows)] | ||
let repo_root = repo_root.to_realpath()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love a comment explaining why this is necessary only on Windows.
Also, we should avoid conditional compilation except where it's necessary.
#[cfg(windows)] | |
let repo_root = repo_root.to_realpath()?; | |
let repo_root = if cfg!(windows) { | |
repo_root.to_realpath()? | |
} else { | |
repo_root | |
}; |
file_path: &AbsoluteSystemPath, | ||
) -> Option<(Vec<AbsoluteSystemPathBuf>, SeenFile)> { | ||
// Read the file content | ||
let Ok(file_content) = tokio::fs::read_to_string(&file_path).await else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not worth blocking, but I wonder if throwing rayon or a thread pool would be more effective for the reverse trace. The only concurrency we're getting is the file reads and I'm not sure how much of the weight of this function is FS vs parsing and extracting info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'm not exactly sure. I think we should do some investigation after it gets some use
crates/turbo-trace/src/tracer.rs
Outdated
|
||
// Parse the file as a module | ||
let Ok(module) = parser.parse_module() else { | ||
errors.push(TraceError::FileNotFound(file_path.to_owned())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a TraceError::ParseError
?
} | ||
} | ||
|
||
pub fn trace(mut self, max_depth: Option<usize>) -> TraceResult { | ||
pub async fn get_imports_from_file( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For any future perf work it might be helpful to add some spans in this function so we can tell where time is being spent.
Description
Implements an MVP of reverse tracing. Basically goes through all the JavaScript/TypeScript files in the repo, checks which ones import the reverse traced file, and returns those. Does this concurrently with a
JoinSet
.Also adds code to detect if a tsconfig is in scope for a file and if so, add it to the resolver. That way custom aliases work.
Testing Instructions
Added some tests including a monorepo setup with tsconfigs in the packages that define aliases