diff --git a/.config/ast-grep/rules/no-context.yml b/.config/ast-grep/rules/no-context.yml index fc1086737586b..f0ca208422ab5 100644 --- a/.config/ast-grep/rules/no-context.yml +++ b/.config/ast-grep/rules/no-context.yml @@ -11,7 +11,7 @@ rule: any: - kind: closure_parameters - kind: parameter - - kind: function_type + - kind: function_item - kind: let_declaration - kind: identifier - all: @@ -19,7 +19,6 @@ rule: - inside: kind: field_declaration ignores: - - "./crates/turbopack-core/**" - "./crates/turbopack-css/**" - "./crates/turbopack-dev-server/**" - "./crates/turbopack-dev/**" diff --git a/crates/node-file-trace/src/lib.rs b/crates/node-file-trace/src/lib.rs index 2bef22cfb3c43..63a09ab937e91 100644 --- a/crates/node-file-trace/src/lib.rs +++ b/crates/node-file-trace/src/lib.rs @@ -44,7 +44,7 @@ use turbopack_core::{ context::AssetContext, environment::{Environment, ExecutionEnvironment, NodeJsEnvironment}, file_source::FileSource, - issue::{IssueContextExt, IssueReporter, IssueSeverity}, + issue::{IssueFilePathExt, IssueReporter, IssueSeverity}, module::{Module, Modules}, output::OutputAsset, reference::all_modules, @@ -566,7 +566,7 @@ async fn main_operation( .await?; for module in modules.iter() { let set = all_modules(*module) - .issue_context(module.ident().path(), "gathering list of assets") + .issue_file_path(module.ident().path(), "gathering list of assets") .await?; for asset in set.await?.iter() { let path = asset.ident().path().await?; diff --git a/crates/turbo-tasks-fetch/src/lib.rs b/crates/turbo-tasks-fetch/src/lib.rs index 264f673308b14..0d996391a17b9 100644 --- a/crates/turbo-tasks-fetch/src/lib.rs +++ b/crates/turbo-tasks-fetch/src/lib.rs @@ -134,7 +134,7 @@ pub struct FetchIssue { #[turbo_tasks::value_impl] impl Issue for FetchIssue { #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.issue_context } diff --git a/crates/turbopack-cli-utils/src/issue.rs b/crates/turbopack-cli-utils/src/issue.rs index cfb8aee709bfc..330aa822934de 100644 --- a/crates/turbopack-cli-utils/src/issue.rs +++ b/crates/turbopack-cli-utils/src/issue.rs @@ -97,7 +97,7 @@ fn format_optional_path( let mut last_context = None; for item in path.iter().rev() { let PlainIssueProcessingPathItem { - ref context, + file_path: ref context, ref description, } = **item; if let Some(context) = context { @@ -138,7 +138,7 @@ pub fn format_issue( let severity = plain_issue.severity; // TODO CLICKABLE PATHS let context_path = plain_issue - .context + .file_path .replace("[project]", ¤t_dir.to_string_lossy()) .replace("/./", "/") .replace("\\\\?\\", ""); @@ -187,7 +187,7 @@ pub fn format_issue( "{} - [{}] {}", severity.style(severity_to_style(severity)), category, - plain_issue.context + plain_issue.file_path ) .unwrap(); @@ -392,7 +392,8 @@ impl IssueReporter for ConsoleUi { has_fatal = true; } - let context_path = make_relative_to_cwd(&plain_issue.context, project_dir, current_dir); + let context_path = + make_relative_to_cwd(&plain_issue.file_path, project_dir, current_dir); let category = &plain_issue.category; let title = &plain_issue.title; let processing_path = &*plain_issue.processing_path; diff --git a/crates/turbopack-core/src/chunk/evaluate.rs b/crates/turbopack-core/src/chunk/evaluate.rs index 8f4a57b744805..bd16032de8ef8 100644 --- a/crates/turbopack-core/src/chunk/evaluate.rs +++ b/crates/turbopack-core/src/chunk/evaluate.rs @@ -20,7 +20,7 @@ pub trait EvaluatableAsset: Asset + Module + ChunkableModule {} pub trait EvaluatableAssetExt { fn to_evaluatable( self: Vc, - context: Vc>, + asset_context: Vc>, ) -> Vc>; } @@ -30,18 +30,18 @@ where { fn to_evaluatable( self: Vc, - context: Vc>, + asset_context: Vc>, ) -> Vc> { - to_evaluatable(Vc::upcast(self), context) + to_evaluatable(Vc::upcast(self), asset_context) } } #[turbo_tasks::function] async fn to_evaluatable( asset: Vc>, - context: Vc>, + asset_context: Vc>, ) -> Result>> { - let asset = context.process( + let asset = asset_context.process( asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Runtime)), ); diff --git a/crates/turbopack-core/src/chunk/mod.rs b/crates/turbopack-core/src/chunk/mod.rs index 8c92fc22f13d1..8c33d7568a7ea 100644 --- a/crates/turbopack-core/src/chunk/mod.rs +++ b/crates/turbopack-core/src/chunk/mod.rs @@ -87,13 +87,16 @@ pub struct ModuleIds(Vec>); pub trait ChunkableModule: Module + Asset { fn as_chunk( self: Vc, - context: Vc>, + chunking_context: Vc>, availability_info: Value, ) -> Vc>; - fn as_root_chunk(self: Vc, context: Vc>) -> Vc> { + fn as_root_chunk( + self: Vc, + chunking_context: Vc>, + ) -> Vc> { self.as_chunk( - context, + chunking_context, Value::new(AvailabilityInfo::Root { current_availability_root: Vc::upcast(self), }), @@ -254,18 +257,18 @@ pub struct ChunkContentResult { #[async_trait::async_trait] pub trait FromChunkableModule: ChunkItem { async fn from_asset( - context: Vc>, + chunking_context: Vc>, asset: Vc>, ) -> Result>>; async fn from_async_asset( - context: Vc>, + chunking_context: Vc>, asset: Vc>, availability_info: Value, ) -> Result>>; } pub async fn chunk_content_split( - context: Vc>, + chunking_context: Vc>, entry: Vc>, additional_entries: Option>, availability_info: Value, @@ -273,13 +276,19 @@ pub async fn chunk_content_split( where I: FromChunkableModule, { - chunk_content_internal_parallel(context, entry, additional_entries, availability_info, true) - .await - .map(|o| o.unwrap()) + chunk_content_internal_parallel( + chunking_context, + entry, + additional_entries, + availability_info, + true, + ) + .await + .map(|o| o.unwrap()) } pub async fn chunk_content( - context: Vc>, + chunking_context: Vc>, entry: Vc>, additional_entries: Option>, availability_info: Value, @@ -287,8 +296,14 @@ pub async fn chunk_content( where I: FromChunkableModule, { - chunk_content_internal_parallel(context, entry, additional_entries, availability_info, false) - .await + chunk_content_internal_parallel( + chunking_context, + entry, + additional_entries, + availability_info, + false, + ) + .await } #[derive(Eq, PartialEq, Clone, Hash)] @@ -314,7 +329,7 @@ struct ChunkContentContext { } async fn reference_to_graph_nodes( - context: ChunkContentContext, + chunk_content_context: ChunkContentContext, reference: Vc>, ) -> Result< Vec<( @@ -347,7 +362,8 @@ where for &module in &modules { let module = module.resolve().await?; - if let Some(available_modules) = context.availability_info.available_modules() { + if let Some(available_modules) = chunk_content_context.availability_info.available_modules() + { if *available_modules.includes(module).await? { graph_nodes.push(( Some((module, chunking_type)), @@ -381,7 +397,9 @@ where match chunking_type { ChunkingType::Placed => { - if let Some(chunk_item) = I::from_asset(context.chunking_context, module).await? { + if let Some(chunk_item) = + I::from_asset(chunk_content_context.chunking_context, module).await? + { graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::ChunkItem { @@ -398,15 +416,17 @@ where } } ChunkingType::Parallel => { - let chunk = - chunkable_module.as_chunk(context.chunking_context, context.availability_info); + let chunk = chunkable_module.as_chunk( + chunk_content_context.chunking_context, + chunk_content_context.availability_info, + ); graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::Chunk(chunk), )); } ChunkingType::IsolatedParallel => { - let chunk = chunkable_module.as_root_chunk(context.chunking_context); + let chunk = chunkable_module.as_root_chunk(chunk_content_context.chunking_context); graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::Chunk(chunk), @@ -414,15 +434,15 @@ where } ChunkingType::PlacedOrParallel => { // heuristic for being in the same chunk - if !context.split - && *context + if !chunk_content_context.split + && *chunk_content_context .chunking_context - .can_be_in_same_chunk(context.entry, module) + .can_be_in_same_chunk(chunk_content_context.entry, module) .await? { // chunk item, chunk or other asset? if let Some(chunk_item) = - I::from_asset(context.chunking_context, module).await? + I::from_asset(chunk_content_context.chunking_context, module).await? { graph_nodes.push(( Some((module, chunking_type)), @@ -435,8 +455,10 @@ where } } - let chunk = - chunkable_module.as_chunk(context.chunking_context, context.availability_info); + let chunk = chunkable_module.as_chunk( + chunk_content_context.chunking_context, + chunk_content_context.availability_info, + ); graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::Chunk(chunk), @@ -444,9 +466,9 @@ where } ChunkingType::Async => { if let Some(manifest_loader_item) = I::from_async_asset( - context.chunking_context, + chunk_content_context.chunking_context, chunkable_module, - context.availability_info, + chunk_content_context.availability_info, ) .await? { @@ -475,7 +497,7 @@ where const MAX_CHUNK_ITEMS_COUNT: usize = 5000; struct ChunkContentVisit { - context: ChunkContentContext, + chunk_content_context: ChunkContentContext, chunk_items_count: usize, processed_assets: HashSet<(ChunkingType, Vc>)>, _phantom: PhantomData, @@ -522,7 +544,8 @@ where // Make sure the chunk doesn't become too large. // This will hurt performance in many aspects. - if !self.context.split && self.chunk_items_count >= MAX_CHUNK_ITEMS_COUNT { + if !self.chunk_content_context.split && self.chunk_items_count >= MAX_CHUNK_ITEMS_COUNT + { // Chunk is too large, cancel this algorithm and restart with splitting from the // start. return VisitControlFlow::Abort(()); @@ -535,7 +558,7 @@ where fn edges(&mut self, node: &ChunkContentGraphNode>) -> Self::EdgesFuture { let node = node.clone(); - let context = self.context; + let chunk_content_context = self.chunk_content_context; async move { let references = match node { @@ -549,7 +572,7 @@ where Ok(references .await? .into_iter() - .map(|reference| reference_to_graph_nodes::(context, *reference)) + .map(|reference| reference_to_graph_nodes::(chunk_content_context, *reference)) .try_join() .await? .into_iter() @@ -597,7 +620,7 @@ where .try_join() .await?; - let context = ChunkContentContext { + let chunk_content_context = ChunkContentContext { chunking_context, entry, split, @@ -605,7 +628,7 @@ where }; let visit = ChunkContentVisit { - context, + chunk_content_context, chunk_items_count: 0, processed_assets: Default::default(), _phantom: PhantomData, diff --git a/crates/turbopack-core/src/compile_time_info.rs b/crates/turbopack-core/src/compile_time_info.rs index d0c85658d12a5..a98c7b9d96e58 100644 --- a/crates/turbopack-core/src/compile_time_info.rs +++ b/crates/turbopack-core/src/compile_time_info.rs @@ -122,7 +122,7 @@ impl CompileTimeDefines { pub enum FreeVarReference { EcmaScriptModule { request: String, - context: Option>, + lookup_path: Option>, export: Option, }, Value(CompileTimeDefineValue), diff --git a/crates/turbopack-core/src/issue/analyze.rs b/crates/turbopack-core/src/issue/analyze.rs index 32ee5c97c3387..9e732e2c37e3d 100644 --- a/crates/turbopack-core/src/issue/analyze.rs +++ b/crates/turbopack-core/src/issue/analyze.rs @@ -38,7 +38,7 @@ impl Issue for AnalyzeIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.source_ident.path() } diff --git a/crates/turbopack-core/src/issue/code_gen.rs b/crates/turbopack-core/src/issue/code_gen.rs index 2059a17ad8f1e..82b18235b3a1e 100644 --- a/crates/turbopack-core/src/issue/code_gen.rs +++ b/crates/turbopack-core/src/issue/code_gen.rs @@ -29,7 +29,7 @@ impl Issue for CodeGenerationIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.path } diff --git a/crates/turbopack-core/src/issue/mod.rs b/crates/turbopack-core/src/issue/mod.rs index fd610b0d65d43..6caf4d617068b 100644 --- a/crates/turbopack-core/src/issue/mod.rs +++ b/crates/turbopack-core/src/issue/mod.rs @@ -83,7 +83,7 @@ pub trait Issue { /// The file path that generated the issue, displayed to the user as message /// header. - fn context(self: Vc) -> Vc; + fn file_path(self: Vc) -> Vc; /// A short identifier of the type of error (eg "parse", "analyze", or /// "evaluate") displayed to the user as part of the message header. @@ -132,7 +132,7 @@ pub trait Issue { ) -> Result> { Ok(PlainIssue { severity: *self.severity().await?, - context: self.context().to_string().await?.clone_value(), + file_path: self.file_path().to_string().await?.clone_value(), category: self.category().await?.clone_value(), title: self.title().await?.clone_value(), description: self.description().await?.clone_value(), @@ -170,7 +170,7 @@ trait IssueProcessingPath { #[turbo_tasks::value] pub struct IssueProcessingPathItem { - pub context: Option>, + pub file_path: Option>, pub description: Vc, } @@ -178,7 +178,7 @@ pub struct IssueProcessingPathItem { impl ValueToString for IssueProcessingPathItem { #[turbo_tasks::function] async fn to_string(&self) -> Result> { - if let Some(context) = self.context { + if let Some(context) = self.file_path { Ok(Vc::cell(format!( "{} ({})", context.to_string().await?, @@ -196,7 +196,7 @@ impl IssueProcessingPathItem { pub async fn into_plain(self: Vc) -> Result> { let this = self.await?; Ok(PlainIssueProcessingPathItem { - context: if let Some(context) = this.context { + file_path: if let Some(context) = this.file_path { Some(context.to_string().await?) } else { None @@ -466,7 +466,7 @@ impl OptionIssueSource { #[derive(Clone, Debug)] pub struct PlainIssue { pub severity: IssueSeverity, - pub context: String, + pub file_path: String, pub category: String, pub title: String, @@ -481,7 +481,7 @@ pub struct PlainIssue { fn hash_plain_issue(issue: &PlainIssue, hasher: &mut Xxh3Hash64Hasher, full: bool) { hasher.write_ref(&issue.severity); - hasher.write_ref(&issue.context); + hasher.write_ref(&issue.file_path); hasher.write_ref(&issue.category); hasher.write_ref(&issue.title); hasher.write_ref( @@ -598,7 +598,7 @@ pub struct PlainIssueProcessingPath(Option>, + pub file_path: Option>, pub description: ReadRef, } @@ -624,23 +624,23 @@ pub trait IssueReporter { } #[async_trait] -pub trait IssueContextExt +pub trait IssueFilePathExt where Self: Sized, { #[allow(unused_variables, reason = "behind feature flag")] - async fn attach_context( + async fn attach_file_path( self, - context: impl Into>> + Send, + file_path: impl Into>> + Send, description: impl Into + Send, ) -> Result; #[allow(unused_variables, reason = "behind feature flag")] async fn attach_description(self, description: impl Into + Send) -> Result; - async fn issue_context( + async fn issue_file_path( self, - context: impl Into>> + Send, + file_path: impl Into>> + Send, description: impl Into + Send, ) -> Result; async fn issue_description(self, description: impl Into + Send) -> Result; @@ -657,14 +657,14 @@ where } #[async_trait] -impl IssueContextExt for T +impl IssueFilePathExt for T where T: CollectiblesSource + Copy + Send, { #[allow(unused_variables, reason = "behind feature flag")] - async fn attach_context( + async fn attach_file_path( self, - context: impl Into>> + Send, + file_path: impl Into>> + Send, description: impl Into + Send, ) -> Result { #[cfg(feature = "issue_path")] @@ -674,7 +674,7 @@ where emit(Vc::upcast::>( ItemIssueProcessingPath::cell(ItemIssueProcessingPath( Some(IssueProcessingPathItem::cell(IssueProcessingPathItem { - context: context.into(), + file_path: file_path.into(), description: Vc::cell(description.into()), })), children, @@ -687,12 +687,12 @@ where #[allow(unused_variables, reason = "behind feature flag")] async fn attach_description(self, description: impl Into + Send) -> Result { - self.attach_context(None, description).await + self.attach_file_path(None, description).await } - async fn issue_context( + async fn issue_file_path( self, - context: impl Into>> + Send, + file_path: impl Into>> + Send, description: impl Into + Send, ) -> Result { #[cfg(feature = "issue_path")] @@ -702,7 +702,7 @@ where emit(Vc::upcast::>( ItemIssueProcessingPath::cell(ItemIssueProcessingPath( Some(IssueProcessingPathItem::cell(IssueProcessingPathItem { - context: context.into(), + file_path: file_path.into(), description: Vc::cell(description.into()), })), children, @@ -712,13 +712,13 @@ where } #[cfg(not(feature = "issue_path"))] { - let _ = (context, description); + let _ = (file_path, description); } Ok(self) } async fn issue_description(self, description: impl Into + Send) -> Result { - self.issue_context(None, description).await + self.issue_file_path(None, description).await } async fn peek_issues_with_path(self) -> Result> { diff --git a/crates/turbopack-core/src/issue/resolve.rs b/crates/turbopack-core/src/issue/resolve.rs index 04887710ec182..77f90122316ea 100644 --- a/crates/turbopack-core/src/issue/resolve.rs +++ b/crates/turbopack-core/src/issue/resolve.rs @@ -16,7 +16,7 @@ pub struct ResolvingIssue { pub severity: Vc, pub request_type: String, pub request: Vc, - pub context: Vc, + pub file_path: Vc, pub resolve_options: Vc, pub error_message: Option, pub source: Vc, @@ -43,8 +43,8 @@ impl Issue for ResolvingIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { - self.context + fn file_path(&self) -> Vc { + self.file_path } #[turbo_tasks::function] @@ -73,7 +73,7 @@ impl Issue for ResolvingIssue { writeln!( detail, "Path where resolving has started: {context}", - context = self.context.to_string().await? + context = self.file_path.to_string().await? )?; writeln!( detail, @@ -81,7 +81,7 @@ impl Issue for ResolvingIssue { request_type = self.request_type, )?; if let Some(import_map) = &self.resolve_options.await?.import_map { - let result = import_map.lookup(self.context, self.request); + let result = import_map.lookup(self.file_path, self.request); match result.to_string().await { Ok(str) => writeln!(detail, "Import map: {}", str)?, diff --git a/crates/turbopack-core/src/issue/unsupported_module.rs b/crates/turbopack-core/src/issue/unsupported_module.rs index 62fa5d511b4d7..16d11ef4029b4 100644 --- a/crates/turbopack-core/src/issue/unsupported_module.rs +++ b/crates/turbopack-core/src/issue/unsupported_module.rs @@ -6,7 +6,7 @@ use super::{Issue, IssueSeverity}; #[turbo_tasks::value(shared)] pub struct UnsupportedModuleIssue { - pub context: Vc, + pub file_path: Vc, pub package: String, pub package_path: Option, } @@ -29,8 +29,8 @@ impl Issue for UnsupportedModuleIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { - self.context + fn file_path(&self) -> Vc { + self.file_path } #[turbo_tasks::function] diff --git a/crates/turbopack-core/src/package_json.rs b/crates/turbopack-core/src/package_json.rs index 9783f00935d87..afd37fdc9ed9a 100644 --- a/crates/turbopack-core/src/package_json.rs +++ b/crates/turbopack-core/src/package_json.rs @@ -74,7 +74,7 @@ impl Issue for PackageJsonIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.path } diff --git a/crates/turbopack-core/src/reference/mod.rs b/crates/turbopack-core/src/reference/mod.rs index 4c0e76560db53..307e06d0556ff 100644 --- a/crates/turbopack-core/src/reference/mod.rs +++ b/crates/turbopack-core/src/reference/mod.rs @@ -7,7 +7,7 @@ use turbo_tasks::{ }; use crate::{ - issue::IssueContextExt, + issue::IssueFilePathExt, module::{Module, Modules}, output::{OutputAsset, OutputAssets}, resolve::ModuleResolveResult, @@ -198,7 +198,7 @@ pub async fn all_modules(asset: Vc>) -> Result> { assets.insert(asset); while let Some((parent, references)) = queue.pop_front() { let references = references - .issue_context(parent.ident().path(), "expanding references of asset") + .issue_file_path(parent.ident().path(), "expanding references of asset") .await?; for asset in references.await?.iter() { if assets.insert(*asset) { diff --git a/crates/turbopack-core/src/resolve/alias_map.rs b/crates/turbopack-core/src/resolve/alias_map.rs index 3f44486e4377a..0a8ba265405ef 100644 --- a/crates/turbopack-core/src/resolve/alias_map.rs +++ b/crates/turbopack-core/src/resolve/alias_map.rs @@ -110,10 +110,10 @@ impl TraceRawVcs for AliasMap where T: TraceRawVcs, { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for (_, map) in self.map.iter() { for value in map.values() { - value.trace_raw_vcs(context); + value.trace_raw_vcs(trace_context); } } } diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index c019214dcd5fc..c2e48bb68b31e 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -941,9 +941,9 @@ fn merge_results_with_affecting_sources( #[turbo_tasks::function] pub async fn resolve_raw( - context: Vc, + lookup_dir: Vc, path: Vc, - force_in_context: bool, + force_in_lookup_dir: bool, ) -> Result> { async fn to_result(path: Vc) -> Result> { let RealPathResult { path, symlinks } = &*path.realpath_with_links().await?; @@ -961,12 +961,12 @@ pub async fn resolve_raw( if let Some(pat) = pat.filter_could_match("/ROOT/") { if let Some(pat) = pat.filter_could_not_match("/ROOT/fsd8nz8og54z") { let path = Pattern::new(pat); - let matches = read_matches(context.root(), "/ROOT/".to_string(), true, path).await?; + let matches = read_matches(lookup_dir.root(), "/ROOT/".to_string(), true, path).await?; if matches.len() > 10000 { println!( "WARN: resolving abs pattern {} in {} leads to {} results", path.to_string().await?, - context.to_string().await?, + lookup_dir.to_string().await?, matches.len() ); } else { @@ -979,12 +979,12 @@ pub async fn resolve_raw( } } { - let matches = read_matches(context, "".to_string(), force_in_context, path).await?; + let matches = read_matches(lookup_dir, "".to_string(), force_in_lookup_dir, path).await?; if matches.len() > 10000 { println!( "WARN: resolving pattern {} in {} leads to {} results", pat, - context.to_string().await?, + lookup_dir.to_string().await?, matches.len() ); } @@ -999,31 +999,31 @@ pub async fn resolve_raw( #[turbo_tasks::function] pub async fn resolve( - context: Vc, + lookup_path: Vc, request: Vc, options: Vc, ) -> Result> { - let raw_result = resolve_internal(context, request, options); - let result = handle_resolve_plugins(context, request, options, raw_result); + let raw_result = resolve_internal(lookup_path, request, options); + let result = handle_resolve_plugins(lookup_path, request, options, raw_result); Ok(result) } #[turbo_tasks::function] async fn handle_resolve_plugins( - context: Vc, + lookup_path: Vc, request: Vc, options: Vc, result: Vc, ) -> Result> { async fn apply_plugins_to_path( path: Vc, - context: Vc, + lookup_path: Vc, request: Vc, options: Vc, ) -> Result>> { for plugin in &options.await?.plugins { if *plugin.after_resolve_condition().matches(path).await? { - if let Some(result) = *plugin.after_resolve(path, context, request).await? { + if let Some(result) = *plugin.after_resolve(path, lookup_path, request).await? { return Ok(Some(result)); } } @@ -1041,7 +1041,7 @@ async fn handle_resolve_plugins( if let &ResolveResultItem::Source(source) = primary { if let Some(new_result) = apply_plugins_to_path( source.ident().path().resolve().await?, - context, + lookup_path, request, options, ) @@ -1075,7 +1075,7 @@ async fn handle_resolve_plugins( #[turbo_tasks::function] async fn resolve_internal( - context: Vc, + lookup_path: Vc, request: Vc, options: Vc, ) -> Result> { @@ -1085,11 +1085,12 @@ async fn resolve_internal( // Apply import mappings if provided if let Some(import_map) = &options_value.import_map { - let result_ref = import_map.lookup(context, request).await?; + let result_ref = import_map.lookup(lookup_path, request).await?; let result = &*result_ref; if !matches!(result, ImportMapResult::NoEntry) { let resolved_result = - resolve_import_map_result(result, context, context, request, options).await?; + resolve_import_map_result(result, lookup_path, lookup_path, request, options) + .await?; // We might have matched an alias in the import map, but there is no guarantee // the alias actually resolves to something. For instance, a tsconfig.json // `compilerOptions.paths` option might alias "@*" to "./*", which @@ -1108,27 +1109,28 @@ async fn resolve_internal( Request::Alternatives { requests } => { let results = requests .iter() - .map(|req| resolve_internal(context, *req, options)) + .map(|req| resolve_internal(lookup_path, *req, options)) .collect(); merge_results(results) } Request::Raw { path, - force_in_context, + force_in_lookup_dir, } => { let mut results = Vec::new(); let matches = read_matches( - context, + lookup_path, "".to_string(), - *force_in_context, + *force_in_lookup_dir, Pattern::new(path.clone()), ) .await?; for m in matches.iter() { match m { PatternMatch::File(_, path) => { - results - .push(resolved(*path, context, request, options_value, options).await?); + results.push( + resolved(*path, lookup_path, request, options_value, options).await?, + ); } PatternMatch::Directory(_, path) => { results.push(resolve_into_folder(*path, options).await?); @@ -1139,7 +1141,7 @@ async fn resolve_internal( } Request::Relative { path, - force_in_context, + force_in_lookup_dir, } => { let mut patterns = vec![path.clone()]; for ext in options_value.extensions.iter() { @@ -1154,8 +1156,8 @@ async fn resolve_internal( let mut results = Vec::new(); for pattern in patterns { results.push(resolve_internal( - context, - Request::raw(Value::new(pattern), *force_in_context), + lookup_path, + Request::raw(Value::new(pattern), *force_in_lookup_dir), options, )); } @@ -1166,7 +1168,9 @@ async fn resolve_internal( module, path, query, - } => resolve_module_request(context, options, options_value, module, path, query).await?, + } => { + resolve_module_request(lookup_path, options, options_value, module, path, query).await? + } Request::ServerRelative { path } => { let mut new_pat = path.clone(); new_pat.push_front(".".to_string().into()); @@ -1176,7 +1180,7 @@ async fn resolve_internal( severity: IssueSeverity::Error.cell(), request_type: "server relative import: not implemented yet".to_string(), request, - context, + file_path: lookup_path, resolve_options: options, error_message: Some( "server relative imports are not implemented yet. Please try an import \ @@ -1188,14 +1192,14 @@ async fn resolve_internal( .cell() .emit(); - resolve_internal(context.root(), relative, options) + resolve_internal(lookup_path.root(), relative, options) } Request::Windows { path: _ } => { ResolvingIssue { severity: IssueSeverity::Error.cell(), request_type: "windows import: not implemented yet".to_string(), request, - context, + file_path: lookup_path, resolve_options: options, error_message: Some("windows imports are not implemented yet".to_string()), source: OptionIssueSource::none(), @@ -1220,7 +1224,7 @@ async fn resolve_internal( }) .unwrap_or_else(|| (Default::default(), ConditionValue::Unset)); resolve_package_internal_with_imports_field( - context, + lookup_path, request, options, path, @@ -1242,7 +1246,7 @@ async fn resolve_internal( severity: IssueSeverity::Error.cell(), request_type: format!("unknown import: `{}`", path), request, - context, + file_path: lookup_path, resolve_options: options, error_message: None, source: OptionIssueSource::none(), @@ -1256,10 +1260,11 @@ async fn resolve_internal( // Apply fallback import mappings if provided if let Some(import_map) = &options_value.fallback_import_map { if *result.is_unresolveable().await? { - let result_ref = import_map.lookup(context, request).await?; + let result_ref = import_map.lookup(lookup_path, request).await?; let result = &*result_ref; let resolved_result = - resolve_import_map_result(result, context, context, request, options).await?; + resolve_import_map_result(result, lookup_path, lookup_path, request, options) + .await?; if let Some(result) = resolved_result { return Ok(result); } @@ -1332,7 +1337,7 @@ async fn resolve_into_folder( } async fn resolve_module_request( - context: Vc, + lookup_path: Vc, options: Vc, options_value: &ResolveOptions, module: &str, @@ -1344,7 +1349,7 @@ async fn resolve_module_request( match in_package { ResolveInPackage::AliasField(field) => { if let FindContextFileResult::Found(package_json_path, refs) = - &*find_context_file(context, package_json()).await? + &*find_context_file(lookup_path, package_json()).await? { let read = read_package_json(*package_json_path).await?; if let Some(package_json) = &*read { @@ -1379,7 +1384,7 @@ async fn resolve_module_request( } let result = find_package( - context, + lookup_path, module.to_string(), resolve_modules_options(options), ) @@ -1457,23 +1462,23 @@ async fn resolve_module_request( async fn resolve_import_map_result( result: &ImportMapResult, - context: Vc, - original_context: Vc, + lookup_path: Vc, + original_lookup_path: Vc, original_request: Vc, options: Vc, ) -> Result>> { Ok(match result { ImportMapResult::Result(result) => Some(*result), - ImportMapResult::Alias(request, alias_context) => { + ImportMapResult::Alias(request, alias_lookup_path) => { let request = *request; - let context = alias_context.unwrap_or(context); + let lookup_path = alias_lookup_path.unwrap_or(lookup_path); // We must avoid cycles during resolving if request.resolve().await? == original_request - && context.resolve().await? == original_context + && lookup_path.resolve().await? == original_lookup_path { None } else { - Some(resolve_internal(context, request, options)) + Some(resolve_internal(lookup_path, request, options)) } } ImportMapResult::Alternatives(list) => { @@ -1482,8 +1487,8 @@ async fn resolve_import_map_result( .map(|result| { resolve_import_map_result_boxed( result, - context, - original_context, + lookup_path, + original_lookup_path, original_request, options, ) @@ -1502,14 +1507,20 @@ type ResolveImportMapResult = Result>>; fn resolve_import_map_result_boxed<'a>( result: &'a ImportMapResult, - context: Vc, - original_context: Vc, + lookup_path: Vc, + original_lookup_path: Vc, original_request: Vc, options: Vc, ) -> Pin + Send + 'a>> { Box::pin(async move { - resolve_import_map_result(result, context, original_context, original_request, options) - .await + resolve_import_map_result( + result, + lookup_path, + original_lookup_path, + original_request, + options, + ) + .await }) } @@ -1537,7 +1548,7 @@ async fn resolve_alias_field_result( } ResolvingIssue { severity: IssueSeverity::Error.cell(), - context: issue_context, + file_path: issue_context, request_type: format!("alias field ({field_name})"), request: Request::parse(Value::new(Pattern::Constant(issue_request.to_string()))), resolve_options, @@ -1673,7 +1684,7 @@ fn handle_exports_imports_field( /// static strings or conditions like `import` or `require` to handle ESM/CJS /// with differently compiled files. async fn resolve_package_internal_with_imports_field( - context: Vc, + file_path: Vc, request: Vc, resolve_options: Vc, pattern: &Pattern, @@ -1687,7 +1698,7 @@ async fn resolve_package_internal_with_imports_field( if specifier == "#" || specifier.starts_with("#/") || specifier.ends_with('/') { ResolvingIssue { severity: IssueSeverity::Error.cell(), - context, + file_path, request_type: format!("package imports request: `{specifier}`"), request, resolve_options, @@ -1699,7 +1710,7 @@ async fn resolve_package_internal_with_imports_field( return Ok(ResolveResult::unresolveable().into()); } - let imports_result = imports_field(context).await?; + let imports_result = imports_field(file_path).await?; let (imports, package_json_path) = match &*imports_result { ImportsFieldResult::Some(i, p) => (i, p), ImportsFieldResult::None => return Ok(ResolveResult::unresolveable().into()), @@ -1762,7 +1773,7 @@ pub async fn handle_resolve_error( if *unresolveable { ResolvingIssue { severity, - context: origin_path, + file_path: origin_path, request_type: format!("{} request", reference_type.into_value()), request, resolve_options, @@ -1777,7 +1788,7 @@ pub async fn handle_resolve_error( Err(err) => { ResolvingIssue { severity, - context: origin_path, + file_path: origin_path, request_type: format!("{} request", reference_type.into_value()), request, resolve_options, diff --git a/crates/turbopack-core/src/resolve/options.rs b/crates/turbopack-core/src/resolve/options.rs index 581375b44398c..c2d5e5ebb9a30 100644 --- a/crates/turbopack-core/src/resolve/options.rs +++ b/crates/turbopack-core/src/resolve/options.rs @@ -105,16 +105,16 @@ pub enum ImportMapping { impl ImportMapping { pub fn primary_alternatives( list: Vec, - context: Option>, + lookup_path: Option>, ) -> ImportMapping { if list.is_empty() { ImportMapping::Ignore } else if list.len() == 1 { - ImportMapping::PrimaryAlternative(list.into_iter().next().unwrap(), context) + ImportMapping::PrimaryAlternative(list.into_iter().next().unwrap(), lookup_path) } else { ImportMapping::Alternatives( list.into_iter() - .map(|s| ImportMapping::PrimaryAlternative(s, context).cell()) + .map(|s| ImportMapping::PrimaryAlternative(s, lookup_path).cell()) .collect(), ) } @@ -263,7 +263,7 @@ pub enum ImportMapResult { async fn import_mapping_to_result( mapping: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Result { Ok(match &*mapping.await? { @@ -288,12 +288,12 @@ async fn import_mapping_to_result( } ImportMapping::Alternatives(list) => ImportMapResult::Alternatives( list.iter() - .map(|mapping| import_mapping_to_result_boxed(*mapping, context, request)) + .map(|mapping| import_mapping_to_result_boxed(*mapping, lookup_path, request)) .try_join() .await?, ), ImportMapping::Dynamic(replacement) => { - (*replacement.result(context, request).await?).clone() + (*replacement.result(lookup_path, request).await?).clone() } }) } @@ -339,10 +339,10 @@ impl ValueToString for ImportMapResult { // `resolve::options::import_mapping_to_result::{opaque#0}` fn import_mapping_to_result_boxed( mapping: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Pin> + Send>> { - Box::pin(async move { import_mapping_to_result(mapping, context, request).await }) + Box::pin(async move { import_mapping_to_result(mapping, lookup_path, request).await }) } #[turbo_tasks::value_impl] @@ -350,7 +350,7 @@ impl ImportMap { #[turbo_tasks::function] pub async fn lookup( self: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Result> { let this = self.await?; @@ -359,7 +359,7 @@ impl ImportMap { if let Some(result) = this.map.lookup(&request_string).next() { return Ok(import_mapping_to_result( result.try_join_into_self().await?.into_owned(), - context, + lookup_path, request, ) .await? @@ -376,7 +376,7 @@ impl ResolvedMap { pub async fn lookup( self: Vc, resolved: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Result> { let this = self.await?; @@ -385,7 +385,7 @@ impl ResolvedMap { let root = root.await?; if let Some(path) = root.get_path_to(&resolved) { if glob.await?.execute(path) { - return Ok(import_mapping_to_result(*mapping, context, request) + return Ok(import_mapping_to_result(*mapping, lookup_path, request) .await? .into()); } @@ -480,7 +480,7 @@ pub trait ImportMappingReplacement { fn replace(self: Vc, capture: String) -> Vc; fn result( self: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Vc; } diff --git a/crates/turbopack-core/src/resolve/origin.rs b/crates/turbopack-core/src/resolve/origin.rs index 8e36cb58e7822..a565c5c3f4a5a 100644 --- a/crates/turbopack-core/src/resolve/origin.rs +++ b/crates/turbopack-core/src/resolve/origin.rs @@ -17,7 +17,7 @@ pub trait ResolveOrigin { /// The AssetContext that carries the configuration for building that /// subgraph. - fn context(self: Vc) -> Vc>; + fn asset_context(self: Vc) -> Vc>; /// Get an inner asset form this origin that doesn't require resolving but /// is directly attached @@ -61,7 +61,7 @@ where } fn resolve_options(self: Vc, reference_type: Value) -> Vc { - self.context() + self.asset_context() .resolve_options(self.origin_path(), reference_type) } @@ -86,7 +86,7 @@ async fn resolve_asset( if let Some(asset) = *resolve_origin.get_inner_asset(request).await? { return Ok(ModuleResolveResult::module(asset).cell()); } - Ok(resolve_origin.context().resolve_asset( + Ok(resolve_origin.asset_context().resolve_asset( resolve_origin.origin_path(), request, options, @@ -97,16 +97,19 @@ async fn resolve_asset( /// A resolve origin for some path and context without additional modifications. #[turbo_tasks::value] pub struct PlainResolveOrigin { - context: Vc>, + asset_context: Vc>, origin_path: Vc, } #[turbo_tasks::value_impl] impl PlainResolveOrigin { #[turbo_tasks::function] - pub fn new(context: Vc>, origin_path: Vc) -> Vc { + pub fn new( + asset_context: Vc>, + origin_path: Vc, + ) -> Vc { PlainResolveOrigin { - context, + asset_context, origin_path, } .cell() @@ -121,8 +124,8 @@ impl ResolveOrigin for PlainResolveOrigin { } #[turbo_tasks::function] - fn context(&self) -> Vc> { - self.context + fn asset_context(&self) -> Vc> { + self.asset_context } } @@ -141,9 +144,9 @@ impl ResolveOrigin for ResolveOriginWithTransition { } #[turbo_tasks::function] - fn context(&self) -> Vc> { + fn asset_context(&self) -> Vc> { self.previous - .context() + .asset_context() .with_transition(self.transition.clone()) } diff --git a/crates/turbopack-core/src/resolve/parse.rs b/crates/turbopack-core/src/resolve/parse.rs index 3676a0ff39414..9a56eefd8e431 100644 --- a/crates/turbopack-core/src/resolve/parse.rs +++ b/crates/turbopack-core/src/resolve/parse.rs @@ -11,11 +11,11 @@ use super::pattern::{Pattern, QueryMap}; pub enum Request { Raw { path: Pattern, - force_in_context: bool, + force_in_lookup_dir: bool, }, Relative { path: Pattern, - force_in_context: bool, + force_in_lookup_dir: bool, }, Module { module: String, @@ -96,7 +96,7 @@ impl Request { } else if r.starts_with("./") || r.starts_with("../") || r == "." || r == ".." { Request::Relative { path: request, - force_in_context: false, + force_in_lookup_dir: false, } } else { lazy_static! { @@ -201,18 +201,18 @@ impl Request { } #[turbo_tasks::function] - pub fn raw(request: Value, force_in_context: bool) -> Vc { + pub fn raw(request: Value, force_in_lookup_dir: bool) -> Vc { Self::cell(Request::Raw { path: request.into_value(), - force_in_context, + force_in_lookup_dir, }) } #[turbo_tasks::function] - pub fn relative(request: Value, force_in_context: bool) -> Vc { + pub fn relative(request: Value, force_in_lookup_dir: bool) -> Vc { Self::cell(Request::Relative { path: request.into_value(), - force_in_context, + force_in_lookup_dir, }) } @@ -271,20 +271,20 @@ impl ValueToString for Request { Ok(Vc::cell(match self { Request::Raw { path, - force_in_context, + force_in_lookup_dir, } => { - if *force_in_context { - format!("in-context {path}") + if *force_in_lookup_dir { + format!("in-lookup-dir {path}") } else { format!("{path}") } } Request::Relative { path, - force_in_context, + force_in_lookup_dir, } => { - if *force_in_context { - format!("relative-in-context {path}") + if *force_in_lookup_dir { + format!("relative-in-lookup-dir {path}") } else { format!("relative {path}") } diff --git a/crates/turbopack-core/src/resolve/pattern.rs b/crates/turbopack-core/src/resolve/pattern.rs index 9617d2bdff7d9..0aafdfca9ad19 100644 --- a/crates/turbopack-core/src/resolve/pattern.rs +++ b/crates/turbopack-core/src/resolve/pattern.rs @@ -645,17 +645,18 @@ pub enum PatternMatch { pub struct PatternMatches(Vec); /// Find all files or directories that match the provided `pattern` with the -/// specified `context` directory. `prefix` is the already matched part of the -/// pattern that leads to the `context` directory. When `force_in_context` is -/// set, leaving the `context` directory by matching `..` is not allowed. +/// specified `lookup_dir` directory. `prefix` is the already matched part of +/// the pattern that leads to the `lookup_dircontext_dir` directory. When +/// `force_in_lookup_dir` is set, leaving the `lookup_dir` directory by +/// matching `..` is not allowed. /// /// Symlinks will not be resolved. It's expected that the caller resolves /// symlinks when they are interested in that. #[turbo_tasks::function] pub async fn read_matches( - context: Vc, + lookup_dir: Vc, prefix: String, - force_in_context: bool, + force_in_lookup_dir: bool, pattern: Vc, ) -> Result> { let mut prefix = prefix; @@ -674,16 +675,16 @@ pub async fn read_matches( for (str, until_end) in constants { if until_end { if handled.insert(str) { - if let Some(fs_path) = &*if force_in_context { - context.try_join_inside(str.to_string()).await? + if let Some(fs_path) = &*if force_in_lookup_dir { + lookup_dir.try_join_inside(str.to_string()).await? } else { - context.try_join(str.to_string()).await? + lookup_dir.try_join(str.to_string()).await? } { let fs_path = fs_path.resolve().await?; // This explicit deref of `context` is necessary #[allow(clippy::explicit_auto_deref)] - let should_match = - !force_in_context || fs_path.await?.is_inside_ref(&*context.await?); + let should_match = !force_in_lookup_dir + || fs_path.await?.is_inside_ref(&*lookup_dir.await?); if should_match { let len = prefix.len(); @@ -719,10 +720,10 @@ pub async fn read_matches( } else { let subpath = &str[..=str.rfind('/').unwrap()]; if handled.insert(subpath) { - if let Some(fs_path) = &*if force_in_context { - context.try_join_inside(subpath.to_string()).await? + if let Some(fs_path) = &*if force_in_lookup_dir { + lookup_dir.try_join_inside(subpath.to_string()).await? } else { - context.try_join(subpath.to_string()).await? + lookup_dir.try_join(subpath.to_string()).await? } { let fs_path = fs_path.resolve().await?; let len = prefix.len(); @@ -730,7 +731,7 @@ pub async fn read_matches( nested.push(read_matches( fs_path, prefix.to_string(), - force_in_context, + force_in_lookup_dir, pattern, )); prefix.truncate(len); @@ -748,21 +749,21 @@ pub async fn read_matches( if slow_path { // Slow path: There are infinite matches for the pattern // We will enumerate the filesystem to find matches - if !force_in_context { + if !force_in_lookup_dir { // {prefix}.. prefix.push_str(".."); if pat.is_match(&prefix) { - results.push(PatternMatch::Directory(prefix.clone(), context.parent())); + results.push(PatternMatch::Directory(prefix.clone(), lookup_dir.parent())); } // {prefix}../ prefix.push('/'); if pat.is_match(&prefix) { - results.push(PatternMatch::Directory(prefix.clone(), context.parent())); + results.push(PatternMatch::Directory(prefix.clone(), lookup_dir.parent())); } if pat.could_match(&prefix) { nested.push(read_matches( - context.parent(), + lookup_dir.parent(), prefix.clone(), false, pattern, @@ -776,33 +777,33 @@ pub async fn read_matches( prefix.push('.'); // {prefix}. if pat.is_match(&prefix) { - results.push(PatternMatch::Directory(prefix.clone(), context)); + results.push(PatternMatch::Directory(prefix.clone(), lookup_dir)); } prefix.pop(); } if prefix.is_empty() { if pat.is_match("./") { - results.push(PatternMatch::Directory("./".to_string(), context)); + results.push(PatternMatch::Directory("./".to_string(), lookup_dir)); } if pat.could_match("./") { - nested.push(read_matches(context, "./".to_string(), false, pattern)); + nested.push(read_matches(lookup_dir, "./".to_string(), false, pattern)); } } else { prefix.push('/'); // {prefix}/ if pat.could_match(&prefix) { - nested.push(read_matches(context, prefix.to_string(), false, pattern)); + nested.push(read_matches(lookup_dir, prefix.to_string(), false, pattern)); } prefix.pop(); prefix.push_str("./"); // {prefix}./ if pat.could_match(&prefix) { - nested.push(read_matches(context, prefix.to_string(), false, pattern)); + nested.push(read_matches(lookup_dir, prefix.to_string(), false, pattern)); } prefix.pop(); prefix.pop(); } - match &*context.read_dir().await? { + match &*lookup_dir.read_dir().await? { DirectoryContent::Entries(map) => { for (key, entry) in map.iter() { match entry { diff --git a/crates/turbopack-core/src/resolve/plugin.rs b/crates/turbopack-core/src/resolve/plugin.rs index 84eaaad6c5d6c..eaea46053db91 100644 --- a/crates/turbopack-core/src/resolve/plugin.rs +++ b/crates/turbopack-core/src/resolve/plugin.rs @@ -47,7 +47,7 @@ pub trait ResolvePlugin { fn after_resolve( self: Vc, fs_path: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Vc; } diff --git a/crates/turbopack-css/src/asset.rs b/crates/turbopack-css/src/asset.rs index ed377d7e17beb..be5b89720ecc2 100644 --- a/crates/turbopack-css/src/asset.rs +++ b/crates/turbopack-css/src/asset.rs @@ -143,7 +143,7 @@ impl ResolveOrigin for CssModuleAsset { } #[turbo_tasks::function] - fn context(&self) -> Vc> { + fn asset_context(&self) -> Vc> { self.context } } diff --git a/crates/turbopack-css/src/module_asset.rs b/crates/turbopack-css/src/module_asset.rs index 5d1e108958cc1..3a4ddfee833d0 100644 --- a/crates/turbopack-css/src/module_asset.rs +++ b/crates/turbopack-css/src/module_asset.rs @@ -251,7 +251,7 @@ impl ResolveOrigin for ModuleCssAsset { } #[turbo_tasks::function] - fn context(&self) -> Vc> { + fn asset_context(&self) -> Vc> { self.context } } @@ -418,7 +418,7 @@ impl Issue for CssModuleComposesIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.source.path() } diff --git a/crates/turbopack-dev-server/src/source/issue_context.rs b/crates/turbopack-dev-server/src/source/issue_context.rs index 9d7413f6df2c9..433baf9f26fa4 100644 --- a/crates/turbopack-dev-server/src/source/issue_context.rs +++ b/crates/turbopack-dev-server/src/source/issue_context.rs @@ -3,7 +3,7 @@ use turbo_tasks::{Value, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ introspect::{Introspectable, IntrospectableChildren}, - issue::IssueContextExt, + issue::IssueFilePathExt, }; use super::{ @@ -54,7 +54,7 @@ impl ContentSource for IssueContextContentSource { let routes = this .source .get_routes() - .issue_context(this.context, &this.description) + .issue_file_path(this.context, &this.description) .await?; Ok(routes.map_routes(Vc::upcast( IssueContextContentSourceMapper { source: self }.cell(), @@ -103,7 +103,7 @@ impl GetContentSourceContent for IssueContextGetContentSourceContent { let result = self .get_content .vary() - .issue_context(source.context, &source.description) + .issue_file_path(source.context, &source.description) .await?; Ok(result) } @@ -118,7 +118,7 @@ impl GetContentSourceContent for IssueContextGetContentSourceContent { let result = self .get_content .get(path, data) - .issue_context(source.context, &source.description) + .issue_file_path(source.context, &source.description) .await?; Ok(result) } diff --git a/crates/turbopack-dev-server/src/update/stream.rs b/crates/turbopack-dev-server/src/update/stream.rs index 56e3832d895c7..149a106656bc7 100644 --- a/crates/turbopack-dev-server/src/update/stream.rs +++ b/crates/turbopack-dev-server/src/update/stream.rs @@ -9,7 +9,7 @@ use turbo_tasks::{unit, IntoTraitRef, ReadRef, TransientInstance, Vc}; use turbo_tasks_fs::{FileSystem, FileSystemPath}; use turbopack_core::{ error::PrettyPrintError, - issue::{Issue, IssueContextExt, IssueSeverity, OptionIssueProcessingPathItems, PlainIssue}, + issue::{Issue, IssueFilePathExt, IssueSeverity, OptionIssueProcessingPathItems, PlainIssue}, server_fs::ServerFileSystem, version::{ NotFoundVersion, PartialUpdate, TotalUpdate, Update, Version, VersionState, @@ -288,7 +288,7 @@ impl Issue for FatalStreamIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { ServerFileSystem::new().root().join(self.resource.clone()) } diff --git a/crates/turbopack-dev/src/react_refresh.rs b/crates/turbopack-dev/src/react_refresh.rs index c2ad9092d8a8a..eb4463f605aa5 100644 --- a/crates/turbopack-dev/src/react_refresh.rs +++ b/crates/turbopack-dev/src/react_refresh.rs @@ -84,7 +84,7 @@ impl Issue for ReactRefreshResolvingIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.path } diff --git a/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs b/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs index 2235aef62d770..9b32744469e1f 100644 --- a/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs +++ b/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs @@ -155,7 +155,7 @@ impl<'a> From<&'a PlainIssue> for Issue<'a> { Issue { severity: plain.severity, - context: &plain.context, + context: &plain.file_path, category: &plain.category, title: &plain.title, description: &plain.description, diff --git a/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs b/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs index 5146caf9cd1b1..05c4b11f487b7 100644 --- a/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs +++ b/crates/turbopack-ecmascript-plugins/src/transform/swc_ecma_transform_plugins.rs @@ -77,7 +77,7 @@ impl Issue for UnsupportedSwcEcmaTransformPluginsIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context } diff --git a/crates/turbopack-ecmascript/src/lib.rs b/crates/turbopack-ecmascript/src/lib.rs index b7c848fb5d81a..6b2a030b5d780 100644 --- a/crates/turbopack-ecmascript/src/lib.rs +++ b/crates/turbopack-ecmascript/src/lib.rs @@ -452,7 +452,7 @@ impl ResolveOrigin for EcmascriptModuleAsset { } #[turbo_tasks::function] - fn context(&self) -> Vc> { + fn asset_context(&self) -> Vc> { self.context } diff --git a/crates/turbopack-ecmascript/src/parse.rs b/crates/turbopack-ecmascript/src/parse.rs index de3cdc81fc06b..edfb14585e320 100644 --- a/crates/turbopack-ecmascript/src/parse.rs +++ b/crates/turbopack-ecmascript/src/parse.rs @@ -384,7 +384,7 @@ struct ReadSourceIssue { #[turbo_tasks::value_impl] impl Issue for ReadSourceIssue { #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.source.ident().path() } diff --git a/crates/turbopack-ecmascript/src/references/mod.rs b/crates/turbopack-ecmascript/src/references/mod.rs index ea3cb7f189fba..c4fd22b92d40b 100644 --- a/crates/turbopack-ecmascript/src/references/mod.rs +++ b/crates/turbopack-ecmascript/src/references/mod.rs @@ -1751,12 +1751,15 @@ async fn handle_free_var_reference( } FreeVarReference::EcmaScriptModule { request, - context, + lookup_path: context, export, } => { let esm_reference = EsmAssetReference::new( context.map_or(state.origin, |context| { - Vc::upcast(PlainResolveOrigin::new(state.origin.context(), context)) + Vc::upcast(PlainResolveOrigin::new( + state.origin.asset_context(), + context, + )) }), Request::parse(Value::new(request.clone().into())), Default::default(), diff --git a/crates/turbopack-ecmascript/src/references/type_issue.rs b/crates/turbopack-ecmascript/src/references/type_issue.rs index 11724a145e7b7..de7de0b92e36e 100644 --- a/crates/turbopack-ecmascript/src/references/type_issue.rs +++ b/crates/turbopack-ecmascript/src/references/type_issue.rs @@ -13,7 +13,7 @@ pub struct SpecifiedModuleTypeIssue { #[turbo_tasks::value_impl] impl Issue for SpecifiedModuleTypeIssue { #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.path } diff --git a/crates/turbopack-ecmascript/src/references/typescript.rs b/crates/turbopack-ecmascript/src/references/typescript.rs index bd54ad450cf07..828dae7a24e20 100644 --- a/crates/turbopack-ecmascript/src/references/typescript.rs +++ b/crates/turbopack-ecmascript/src/references/typescript.rs @@ -76,7 +76,7 @@ impl ModuleReference for TsReferencePathAssetReference { .try_join(self.path.clone()) .await? { - ModuleResolveResult::module(Vc::upcast(self.origin.context().process( + ModuleResolveResult::module(Vc::upcast(self.origin.asset_context().process( Vc::upcast(FileSource::new(*path)), Value::new(ReferenceType::TypeScript( TypeScriptReferenceSubType::Undefined, diff --git a/crates/turbopack-ecmascript/src/resolve/mod.rs b/crates/turbopack-ecmascript/src/resolve/mod.rs index dd830e5027b81..625e0abe617f7 100644 --- a/crates/turbopack-ecmascript/src/resolve/mod.rs +++ b/crates/turbopack-ecmascript/src/resolve/mod.rs @@ -104,7 +104,9 @@ pub async fn url_resolve( } else { rel_result }; - let result = origin.context().process_resolve_result(result, ty.clone()); + let result = origin + .asset_context() + .process_resolve_result(result, ty.clone()); handle_resolve_error( result, ty, diff --git a/crates/turbopack-ecmascript/src/transform/mod.rs b/crates/turbopack-ecmascript/src/transform/mod.rs index 4b57d233fab2c..c57f8d935225f 100644 --- a/crates/turbopack-ecmascript/src/transform/mod.rs +++ b/crates/turbopack-ecmascript/src/transform/mod.rs @@ -309,7 +309,7 @@ impl Issue for UnsupportedServerActionIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context } diff --git a/crates/turbopack-ecmascript/src/typescript/resolve.rs b/crates/turbopack-ecmascript/src/typescript/resolve.rs index 859cf3980c36d..918111c9dfef5 100644 --- a/crates/turbopack-ecmascript/src/typescript/resolve.rs +++ b/crates/turbopack-ecmascript/src/typescript/resolve.rs @@ -363,7 +363,9 @@ pub async fn type_resolve( } else { resolve(context_path, request, options) }; - let result = origin.context().process_resolve_result(result, ty.clone()); + let result = origin + .asset_context() + .process_resolve_result(result, ty.clone()); handle_resolve_error( result, ty, @@ -466,7 +468,7 @@ impl Issue for TsConfigIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.source_ident.path() } diff --git a/crates/turbopack-env/src/issue.rs b/crates/turbopack-env/src/issue.rs index a42813bf23511..9c7cee07b00a7 100644 --- a/crates/turbopack-env/src/issue.rs +++ b/crates/turbopack-env/src/issue.rs @@ -22,7 +22,7 @@ impl Issue for ProcessEnvIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.path } diff --git a/crates/turbopack-image/src/process/mod.rs b/crates/turbopack-image/src/process/mod.rs index a9a06c5821f39..4887abbe25e52 100644 --- a/crates/turbopack-image/src/process/mod.rs +++ b/crates/turbopack-image/src/process/mod.rs @@ -398,7 +398,7 @@ struct ImageProcessingIssue { #[turbo_tasks::value_impl] impl Issue for ImageProcessingIssue { #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.path } #[turbo_tasks::function] diff --git a/crates/turbopack-mdx/src/lib.rs b/crates/turbopack-mdx/src/lib.rs index 8b0a7d79e60d4..e3bf70f2d574a 100644 --- a/crates/turbopack-mdx/src/lib.rs +++ b/crates/turbopack-mdx/src/lib.rs @@ -229,7 +229,7 @@ impl ResolveOrigin for MdxModuleAsset { } #[turbo_tasks::function] - fn context(&self) -> Vc> { + fn asset_context(&self) -> Vc> { self.context } } diff --git a/crates/turbopack-node/src/evaluate.rs b/crates/turbopack-node/src/evaluate.rs index 038140464db86..2ef70a23c7b38 100644 --- a/crates/turbopack-node/src/evaluate.rs +++ b/crates/turbopack-node/src/evaluate.rs @@ -499,7 +499,7 @@ impl Issue for EvaluationIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context_ident.path() } @@ -543,7 +543,7 @@ impl Issue for BuildDependencyIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context_ident.path() } @@ -608,7 +608,7 @@ pub struct EvaluateEmittedErrorIssue { #[turbo_tasks::value_impl] impl Issue for EvaluateEmittedErrorIssue { #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context } diff --git a/crates/turbopack-node/src/render/issue.rs b/crates/turbopack-node/src/render/issue.rs index 4c9cd5f46ec55..ae34c0e35ade1 100644 --- a/crates/turbopack-node/src/render/issue.rs +++ b/crates/turbopack-node/src/render/issue.rs @@ -24,7 +24,7 @@ impl Issue for RenderingIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context } diff --git a/crates/turbopack-node/src/render/rendered_source.rs b/crates/turbopack-node/src/render/rendered_source.rs index 707c3d150ae96..c43e36855aa40 100644 --- a/crates/turbopack-node/src/render/rendered_source.rs +++ b/crates/turbopack-node/src/render/rendered_source.rs @@ -9,7 +9,7 @@ use turbopack_core::{ module::IntrospectableModule, output_asset::IntrospectableOutputAsset, Introspectable, IntrospectableChildren, }, - issue::IssueContextExt, + issue::IssueFilePathExt, module::Module, output::OutputAsset, version::VersionedContentExt, @@ -213,7 +213,7 @@ impl GetContentSourceContent for NodeRenderContentSource { .cell(), self.debug, ) - .issue_context( + .issue_file_path( entry.module.ident().path(), format!("server-side rendering {}", self.pathname.await?), ) diff --git a/crates/turbopack-node/src/transforms/postcss.rs b/crates/turbopack-node/src/transforms/postcss.rs index c563e9244d279..3ec16f541922b 100644 --- a/crates/turbopack-node/src/transforms/postcss.rs +++ b/crates/turbopack-node/src/transforms/postcss.rs @@ -12,7 +12,7 @@ use turbopack_core::{ context::AssetContext, file_source::FileSource, ident::AssetIdent, - issue::IssueContextExt, + issue::IssueFilePathExt, module::Module, reference_type::{EntryReferenceSubType, InnerAssets, ReferenceType}, resolve::{find_context_file, FindContextFileResult}, @@ -123,7 +123,7 @@ impl Asset for PostCssTransformedAsset { let this = self.await?; Ok(self .process() - .issue_context(this.source.ident().path(), "PostCSS processing") + .issue_file_path(this.source.ident().path(), "PostCSS processing") .await? .await? .content) diff --git a/crates/turbopack-tests/tests/execution.rs b/crates/turbopack-tests/tests/execution.rs index f6a31a72d4ca8..23f2d9a2f05d6 100644 --- a/crates/turbopack-tests/tests/execution.rs +++ b/crates/turbopack-tests/tests/execution.rs @@ -29,7 +29,7 @@ use turbopack_core::{ context::AssetContext, environment::{Environment, ExecutionEnvironment, NodeJsEnvironment}, file_source::FileSource, - issue::{Issue, IssueContextExt}, + issue::{Issue, IssueFilePathExt}, module::Module, reference_type::{EntryReferenceSubType, ReferenceType}, source::Source, diff --git a/crates/turbopack-tests/tests/snapshot.rs b/crates/turbopack-tests/tests/snapshot.rs index 10d13b3b307cd..6dbdbdd3191f4 100644 --- a/crates/turbopack-tests/tests/snapshot.rs +++ b/crates/turbopack-tests/tests/snapshot.rs @@ -34,7 +34,7 @@ use turbopack_core::{ context::AssetContext, environment::{BrowserEnvironment, Environment, ExecutionEnvironment, NodeJsEnvironment}, file_source::FileSource, - issue::{Issue, IssueContextExt}, + issue::{Issue, IssueFilePathExt}, module::Module, output::OutputAsset, reference_type::{EntryReferenceSubType, ReferenceType}, diff --git a/crates/turbopack-wasm/src/module_asset.rs b/crates/turbopack-wasm/src/module_asset.rs index 1552809083e25..eb0cbaab44de3 100644 --- a/crates/turbopack-wasm/src/module_asset.rs +++ b/crates/turbopack-wasm/src/module_asset.rs @@ -155,7 +155,7 @@ impl ResolveOrigin for WebAssemblyModuleAsset { } #[turbo_tasks::function] - fn context(&self) -> Vc> { + fn asset_context(&self) -> Vc> { self.asset_context } diff --git a/crates/turbopack/src/lib.rs b/crates/turbopack/src/lib.rs index 53bd3a92aa9d9..f8ec6d25c7b9d 100644 --- a/crates/turbopack/src/lib.rs +++ b/crates/turbopack/src/lib.rs @@ -78,7 +78,7 @@ impl Issue for ModuleIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.ident.path() } diff --git a/crates/turbopack/src/unsupported_sass.rs b/crates/turbopack/src/unsupported_sass.rs index e04e3837b1e9d..5a95768bf01ca 100644 --- a/crates/turbopack/src/unsupported_sass.rs +++ b/crates/turbopack/src/unsupported_sass.rs @@ -78,7 +78,7 @@ impl Issue for UnsupportedSassModuleIssue { } #[turbo_tasks::function] - fn context(&self) -> Vc { + fn file_path(&self) -> Vc { self.context }