Unverified Commit d960fd03 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

[backport] Turbopack: don't match dynamic pattern for node_modules packages (#83803)

Backport #83176
parent 16de4b55
use anyhow::Result; use anyhow::Result;
use either::Either; use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
...@@ -77,51 +77,42 @@ async fn resolve_reference_from_dir( ...@@ -77,51 +77,42 @@ async fn resolve_reference_from_dir(
) -> Result<Vc<ModuleResolveResult>> { ) -> Result<Vc<ModuleResolveResult>> {
let path_ref = path.await?; let path_ref = path.await?;
let (abs_path, rel_path) = path_ref.split_could_match("/ROOT/"); let (abs_path, rel_path) = path_ref.split_could_match("/ROOT/");
let matches = match (abs_path, rel_path) { if abs_path.is_none() && rel_path.is_none() {
(Some(abs_path), Some(rel_path)) => Either::Right( return Ok(*ModuleResolveResult::unresolvable());
read_matches( }
parent_path.root().owned().await?,
rcstr!("/ROOT/"), let abs_matches = if let Some(abs_path) = &abs_path {
true, Some(
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
read_matches( read_matches(
parent_path.root().owned().await?, parent_path.root().owned().await?,
rcstr!("/ROOT/"), rcstr!("/ROOT/"),
true, true,
Pattern::new(abs_path.or_any_nested_file()), Pattern::new(abs_path.or_any_nested_file()),
) )
.await? .await?,
.into_iter(), )
), } else {
(None, Some(rel_path)) => Either::Left( None
// relative path only };
let rel_matches = if let Some(rel_path) = &rel_path {
Some(
read_matches( read_matches(
parent_path, parent_path,
rcstr!(""), rcstr!(""),
true, true,
Pattern::new(rel_path.or_any_nested_file()), Pattern::new(rel_path.or_any_nested_file()),
) )
.await? .await?,
.into_iter(), )
), } else {
(None, None) => return Ok(*ModuleResolveResult::unresolvable()), None
}; };
let matches = abs_matches
.into_iter()
.flatten()
.chain(rel_matches.into_iter().flatten());
let mut affecting_sources = Vec::new(); let mut affecting_sources = Vec::new();
let mut results = Vec::new(); let mut results = Vec::new();
for pat_match in matches { for pat_match in matches {
...@@ -156,7 +147,17 @@ impl ModuleReference for DirAssetReference { ...@@ -156,7 +147,17 @@ impl ModuleReference for DirAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
let parent_path = self.source.ident().path().await?.parent(); let parent_path = self.source.ident().path().await?.parent();
Ok(resolve_reference_from_dir(parent_path, *self.path)) let span = tracing::info_span!(
"trace directory",
pattern = display(self.path.to_string().await?)
);
async {
resolve_reference_from_dir(parent_path, *self.path)
.resolve()
.await
}
.instrument(span)
.await
} }
} }
......
use anyhow::Result; use anyhow::Result;
use tracing::Instrument;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
...@@ -28,7 +29,18 @@ impl ModuleReference for FileSourceReference { ...@@ -28,7 +29,18 @@ impl ModuleReference for FileSourceReference {
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
let context_dir = self.source.ident().path().await?.parent(); 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
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment