-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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(trace): resolve incorrect extension #9486
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
use camino::Utf8PathBuf; | ||
use camino::{Utf8Path, Utf8PathBuf}; | ||
use globwalk::WalkType; | ||
use miette::{Diagnostic, Report, SourceSpan}; | ||
use oxc_resolver::{ | ||
|
@@ -67,7 +67,7 @@ | |
} | ||
|
||
impl TraceResult { | ||
pub fn emit_errors(&self) { | ||
Check warning on line 70 in crates/turbo-trace/src/tracer.rs GitHub Actions / Rust lints
Check warning on line 70 in crates/turbo-trace/src/tracer.rs GitHub Actions / Turborepo rust check
Check warning on line 70 in crates/turbo-trace/src/tracer.rs GitHub Actions / Turborepo Rust testing on ubuntu
Check warning on line 70 in crates/turbo-trace/src/tracer.rs GitHub Actions / Turborepo Rust testing on macos
|
||
let handler = Handler::with_tty_emitter( | ||
ColorConfig::Auto, | ||
true, | ||
|
@@ -211,15 +211,36 @@ | |
debug!("built in: {:?}", err); | ||
} | ||
Err(err) => { | ||
// Try to resolve the import as a type import via `@/types/<import>` | ||
let type_package = format!("@types/{}", import); | ||
let resolved_type_import = resolver | ||
.resolve(file_path, type_package.as_str()) | ||
if !import.starts_with(".") { | ||
// Try to resolve the import as a type import via `@/types/<import>` | ||
let type_package = format!("@types/{}", import); | ||
debug!("trying to resolve type import: {}", type_package); | ||
let resolved_type_import = resolver | ||
.resolve(file_dir, type_package.as_str()) | ||
.ok() | ||
.and_then(|resolved| resolved.into_path_buf().try_into().ok()); | ||
|
||
if let Some(resolved_type_import) = resolved_type_import { | ||
debug!("resolved type import succeeded"); | ||
files.push(resolved_type_import); | ||
continue; | ||
} | ||
} | ||
|
||
// Also try without the extension just in case the wrong extension is used | ||
let without_extension = Utf8Path::new(import).with_extension(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just calling out that this will convert something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I originally had an explicit check for |
||
debug!( | ||
"trying to resolve extensionless import: {}", | ||
without_extension | ||
); | ||
let resolved_extensionless_import = resolver | ||
.resolve(file_dir, without_extension.as_str()) | ||
.ok() | ||
.and_then(|resolved| resolved.into_path_buf().try_into().ok()); | ||
|
||
if let Some(resolved_type_import) = resolved_type_import { | ||
files.push(resolved_type_import); | ||
if let Some(resolved_extensionless_import) = resolved_extensionless_import { | ||
debug!("resolved extensionless import succeeded"); | ||
files.push(resolved_extensionless_import); | ||
continue; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
source: crates/turborepo/tests/query.rs | ||
expression: query_output | ||
--- | ||
{ | ||
"data": { | ||
"file": { | ||
"path": "incorrect_extension.mjs", | ||
"dependencies": { | ||
"files": { | ||
"items": [ | ||
{ | ||
"path": "bar.js" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import { bar } from "./bar.cjs"; |
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 this a check against
./
?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 don't think packages can start with
.
?