Skip to content
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

chore(trace): fixes and improvements #9398

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions crates/turbo-trace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,36 +274,40 @@ impl Tracer {
root: &AbsoluteSystemPath,
existing_resolver: &Resolver,
) -> Option<Resolver> {
let resolver = root
let tsconfig_dir = root
.ancestors()
.skip(1)
.find(|p| p.join_component("tsconfig.json").exists())
.map(|ts_config_dir| {
let mut options = existing_resolver.options().clone();
.find(|p| p.join_component("tsconfig.json").exists());

// Resolves the closest `node_modules` directory. This is to work with monorepos
// where both the package and the monorepo have a `node_modules`
// directory.
let node_modules_dir = root
.ancestors()
.skip(1)
.find(|p| p.join_component("node_modules").exists());

if tsconfig_dir.is_some() || node_modules_dir.is_some() {
let mut options = existing_resolver.options().clone();
if let Some(tsconfig_dir) = tsconfig_dir {
options.tsconfig = Some(TsconfigOptions {
config_file: ts_config_dir
config_file: tsconfig_dir
.join_component("tsconfig.json")
.as_std_path()
.into(),
references: TsconfigReferences::Auto,
});
}

existing_resolver.clone_with_options(options)
});
if let Some(node_modules_dir) = node_modules_dir {
options = options
.with_module(node_modules_dir.join_component("node_modules").to_string());
}

root.ancestors()
.skip(1)
.find(|p| p.join_component("node_modules").exists())
.map(|node_modules_dir| {
let node_modules = node_modules_dir.join_component("node_modules");
let resolver = resolver.as_ref().unwrap_or(existing_resolver);
let options = resolver
.options()
.clone()
.with_module(node_modules.to_string());

resolver.clone_with_options(options)
})
Some(existing_resolver.clone_with_options(options))
} else {
None
}
}

pub fn create_resolver(&mut self) -> Resolver {
Expand All @@ -312,7 +316,10 @@ impl Tracer {
.with_force_extension(EnforceExtension::Disabled)
.with_extension(".ts")
.with_extension(".tsx")
.with_condition_names(&["import", "require"]);
.with_module(self.cwd.join_component("node_modules").to_string())
// Condition names are used to determine which export to use when importing a module.
// We add a bunch so oxc_resolver can resolve all kinds of imports.
.with_condition_names(&["import", "require", "node", "default"]);

if let Some(ts_config) = self.ts_config.take() {
options.tsconfig = Some(TsconfigOptions {
Expand Down
5 changes: 4 additions & 1 deletion crates/turborepo-lib/src/query/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl File {
depth: Option<usize>,
ts_config: Option<String>,
import_type: Option<ImportType>,
emit_errors: Option<bool>,
) -> Result<TraceResult, Error> {
let mut tracer = Tracer::new(
self.run.repo_root().to_owned(),
Expand All @@ -209,7 +210,9 @@ impl File {
}

let mut result = tracer.trace(depth).await;
result.emit_errors();
if emit_errors.unwrap_or(true) {
result.emit_errors();
}
// Remove the file itself from the result
result.files.remove(&self.path);
TraceResult::new(result, self.run.clone())
Expand Down
Loading