diff --git a/crates/turbo-trace/src/import_finder.rs b/crates/turbo-trace/src/import_finder.rs index 52d1adb9e6b22..8007efef66df3 100644 --- a/crates/turbo-trace/src/import_finder.rs +++ b/crates/turbo-trace/src/import_finder.rs @@ -41,27 +41,43 @@ impl ImportFinder { impl Visit for ImportFinder { fn visit_module_decl(&mut self, decl: &ModuleDecl) { - if let ModuleDecl::Import(import) = decl { - let import_type = if import.type_only { - ImportType::Type - } else { - ImportType::Value - }; - match self.import_type { - ImportTraceType::All => { - self.imports - .push((import.src.value.to_string(), import.span, import_type)); - } - ImportTraceType::Types if import.type_only => { - self.imports - .push((import.src.value.to_string(), import.span, import_type)); + match decl { + ModuleDecl::Import(import) => { + let import_type = if import.type_only { + ImportType::Type + } else { + ImportType::Value + }; + match self.import_type { + ImportTraceType::All => { + self.imports + .push((import.src.value.to_string(), import.span, import_type)); + } + ImportTraceType::Types if import.type_only => { + self.imports + .push((import.src.value.to_string(), import.span, import_type)); + } + ImportTraceType::Values if !import.type_only => { + self.imports + .push((import.src.value.to_string(), import.span, import_type)); + } + _ => {} } - ImportTraceType::Values if !import.type_only => { + } + ModuleDecl::ExportNamed(named_export) => { + if let Some(decl) = &named_export.src { self.imports - .push((import.src.value.to_string(), import.span, import_type)); + .push((decl.value.to_string(), decl.span, ImportType::Value)); } - _ => {} } + ModuleDecl::ExportAll(export_all) => { + self.imports.push(( + export_all.src.value.to_string(), + export_all.span, + ImportType::Value, + )); + } + _ => {} } } diff --git a/crates/turborepo/tests/query.rs b/crates/turborepo/tests/query.rs index d46b6df73029e..c266b1c3b708f 100644 --- a/crates/turborepo/tests/query.rs +++ b/crates/turborepo/tests/query.rs @@ -63,6 +63,8 @@ fn test_trace() -> Result<(), anyhow::Error> { "get `import_value_and_type.ts` with type dependencies" => "query { file(path: \"import_value_and_type.ts\") { path dependencies(importType: TYPES) { files { items { path } } } } }", "get `import_value_and_type.ts` with value dependencies" => "query { file(path: \"import_value_and_type.ts\") { path dependencies(importType: VALUES) { files { items { path } } } } }", "get `incorrect_extension.mjs` with dependencies" => "query { file(path: \"incorrect_extension.mjs\") { path dependencies(depth: 1) { files { items { path } } } } }", + "get `export_all.js` with dependencies" => "query { file(path: \"export_all.js\") { path dependencies { files { items { path } } } } }", + "get `export_named.js` with dependencies" => "query { file(path: \"export_named.js\") { path dependencies { files { items { path } } } } }", ); Ok(()) diff --git a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`export_all.js`_with_dependencies_(npm@10.5.0).snap b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`export_all.js`_with_dependencies_(npm@10.5.0).snap new file mode 100644 index 0000000000000..9ce3db7acd226 --- /dev/null +++ b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`export_all.js`_with_dependencies_(npm@10.5.0).snap @@ -0,0 +1,23 @@ +--- +source: crates/turborepo/tests/query.rs +expression: query_output +--- +{ + "data": { + "file": { + "path": "export_all.js", + "dependencies": { + "files": { + "items": [ + { + "path": "bar.js" + }, + { + "path": "foo.js" + } + ] + } + } + } + } +} diff --git a/crates/turborepo/tests/snapshots/query__turbo_trace_get_`export_named.js`_with_dependencies_(npm@10.5.0).snap b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`export_named.js`_with_dependencies_(npm@10.5.0).snap new file mode 100644 index 0000000000000..c277688efbc9a --- /dev/null +++ b/crates/turborepo/tests/snapshots/query__turbo_trace_get_`export_named.js`_with_dependencies_(npm@10.5.0).snap @@ -0,0 +1,23 @@ +--- +source: crates/turborepo/tests/query.rs +expression: query_output +--- +{ + "data": { + "file": { + "path": "export_named.js", + "dependencies": { + "files": { + "items": [ + { + "path": "bar.js" + }, + { + "path": "foo.js" + } + ] + } + } + } + } +} diff --git a/turborepo-tests/integration/fixtures/turbo_trace/export_all.js b/turborepo-tests/integration/fixtures/turbo_trace/export_all.js new file mode 100644 index 0000000000000..a527a14714a0c --- /dev/null +++ b/turborepo-tests/integration/fixtures/turbo_trace/export_all.js @@ -0,0 +1 @@ +export * from "./foo.js"; diff --git a/turborepo-tests/integration/fixtures/turbo_trace/export_named.js b/turborepo-tests/integration/fixtures/turbo_trace/export_named.js new file mode 100644 index 0000000000000..b0ec3eb0e2a30 --- /dev/null +++ b/turborepo-tests/integration/fixtures/turbo_trace/export_named.js @@ -0,0 +1 @@ +export { foo } from "./foo.js";