Skip to content
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
215 changes: 188 additions & 27 deletions turbopack/crates/turbopack-core/src/resolve/pattern.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions turbopack/crates/turbopack-core/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!**
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
58 changes: 24 additions & 34 deletions turbopack/crates/turbopack-ecmascript/src/references/node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use either::Either;
use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
Expand Down Expand Up @@ -78,51 +77,42 @@ async fn resolve_reference_from_dir(
) -> Result<Vc<ModuleResolveResult>> {
let path_ref = path.await?;
let (abs_path, rel_path) = path_ref.split_could_match("/ROOT/");
let matches = match (abs_path, rel_path) {
(Some(abs_path), Some(rel_path)) => Either::Right(
read_matches(
parent_path.root().owned().await?,
rcstr!("/ROOT/"),
true,
Pattern::new(abs_path.or_any_nested_file()),
)
.await?
.into_iter()
.chain(
read_matches(
parent_path,
rcstr!(""),
true,
Pattern::new(rel_path.or_any_nested_file()),
)
.await?
.into_iter(),
),
),
(Some(abs_path), None) => Either::Left(
// absolute path only
if abs_path.is_none() && rel_path.is_none() {
return Ok(*ModuleResolveResult::unresolvable());
}

let abs_matches = if let Some(abs_path) = &abs_path {
Some(
read_matches(
parent_path.root().owned().await?,
rcstr!("/ROOT/"),
true,
Pattern::new(abs_path.or_any_nested_file()),
)
.await?
.into_iter(),
),
(None, Some(rel_path)) => Either::Left(
// relative path only
.await?,
)
} else {
None
};
let rel_matches = if let Some(rel_path) = &rel_path {
Some(
read_matches(
parent_path,
rcstr!(""),
true,
Pattern::new(rel_path.or_any_nested_file()),
)
.await?
.into_iter(),
),
(None, None) => return Ok(*ModuleResolveResult::unresolvable()),
.await?,
)
} else {
None
};

let matches = abs_matches
.into_iter()
.flatten()
.chain(rel_matches.into_iter().flatten());

let mut affecting_sources = Vec::new();
let mut results = Vec::new();
for pat_match in matches {
Expand Down Expand Up @@ -158,7 +148,7 @@ impl ModuleReference for DirAssetReference {
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
let parent_path = self.source.ident().path().await?.parent();
let span = tracing::info_span!(
"resolve DirAssetReference",
"trace directory",
pattern = display(self.path.to_string().await?)
);
async {
Expand Down
14 changes: 13 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/references/raw.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use tracing::Instrument;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{
Expand Down Expand Up @@ -28,7 +29,18 @@ impl ModuleReference for FileSourceReference {
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
let context_dir = self.source.ident().path().await?.parent();

Ok(resolve_raw(context_dir, *self.path, false).as_raw_module_result())
let span = tracing::info_span!(
"trace file",
pattern = display(self.path.to_string().await?)
);
async {
resolve_raw(context_dir, *self.path, false)
.as_raw_module_result()
.resolve()
.await
}
.instrument(span)
.await
}
}

Expand Down
Loading