diff --git a/.config/ast-grep/rules/no-context.yml b/.config/ast-grep/rules/no-context.yml index b7f496e459454..c8a5675acbfc3 100644 --- a/.config/ast-grep/rules/no-context.yml +++ b/.config/ast-grep/rules/no-context.yml @@ -1,7 +1,7 @@ id: no-context message: Don't name variables `context`. note: Use a more specific name, such as chunking_context, asset_context, etc. -severity: warning +severity: error language: Rust rule: regex: \bcontext\b @@ -18,3 +18,20 @@ rule: - kind: field_identifier - inside: kind: field_declaration +ignores: + - "./crates/turbopack-core/**" + - "./crates/turbopack-css/**" + - "./crates/turbopack-dev-server/**" + - "./crates/turbopack-dev/**" + - "./crates/turbopack-ecmascript-hmr-protocol/**" + - "./crates/turbopack-ecmascript-plugins/**" + - "./crates/turbopack-ecmascript-runtime/**" + - "./crates/turbopack-ecmascript/**" + - "./crates/turbopack-json/**" + - "./crates/turbopack-mdx/**" + - "./crates/turbopack-node/**" + - "./crates/turbopack-static/**" + - "./crates/turbopack-tests/**" + - "./crates/turbopack/**" + - "./crates/turborepo-cache/**" + - "./crates/turborepo-scm/**" diff --git a/crates/node-file-trace/src/lib.rs b/crates/node-file-trace/src/lib.rs index 99988005bd785..2bef22cfb3c43 100644 --- a/crates/node-file-trace/src/lib.rs +++ b/crates/node-file-trace/src/lib.rs @@ -195,8 +195,8 @@ impl Args { } } -async fn create_fs(name: &str, context: &str, watch: bool) -> Result>> { - let fs = DiskFileSystem::new(name.to_string(), context.to_string()); +async fn create_fs(name: &str, root: &str, watch: bool) -> Result>> { + let fs = DiskFileSystem::new(name.to_string(), root.to_string()); if watch { fs.await?.start_watching()?; } else { @@ -206,7 +206,7 @@ async fn create_fs(name: &str, context: &str, watch: bool) -> Result>, + asset_context: Vc>, result: Vc, list: &mut Vec>>, ) -> Result<()> { @@ -214,7 +214,7 @@ async fn add_glob_results( for entry in result.results.values() { if let DirectoryEntry::File(path) = entry { let source = Vc::upcast(FileSource::new(*path)); - list.push(context.process( + list.push(asset_context.process( source, Value::new(turbopack_core::reference_type::ReferenceType::Undefined), )); @@ -222,14 +222,14 @@ async fn add_glob_results( } for result in result.inner.values() { fn recurse<'a>( - context: Vc>, + asset_context: Vc>, result: Vc, list: &'a mut Vec>>, ) -> Pin> + Send + 'a>> { - Box::pin(add_glob_results(context, result, list)) + Box::pin(add_glob_results(asset_context, result, list)) } // Boxing for async recursion - recurse(context, *result, list).await?; + recurse(asset_context, *result, list).await?; } Ok(()) } @@ -240,16 +240,16 @@ async fn input_to_modules( input: Vec, exact: bool, process_cwd: Option, - context: String, + context_directory: String, module_options: TransientInstance, resolve_options: TransientInstance, ) -> Result> { let root = fs.root(); let process_cwd = process_cwd .clone() - .map(|p| p.trim_start_matches(&context).to_owned()); + .map(|p| p.trim_start_matches(&context_directory).to_owned()); - let context: Vc> = Vc::upcast(create_module_asset( + let asset_context: Vc> = Vc::upcast(create_module_asset( root, process_cwd, module_options, @@ -260,42 +260,42 @@ async fn input_to_modules( for input in input { if exact { let source = Vc::upcast(FileSource::new(root.join(input))); - list.push(context.process( + list.push(asset_context.process( source, Value::new(turbopack_core::reference_type::ReferenceType::Undefined), )); } else { let glob = Glob::new(input); - add_glob_results(context, root.read_glob(glob, false), &mut list).await?; + add_glob_results(asset_context, root.read_glob(glob, false), &mut list).await?; }; } Ok(Vc::cell(list)) } fn process_context(dir: &Path, context_directory: Option<&String>) -> Result { - let mut context = PathBuf::from(context_directory.map_or(".", |s| s)); - if !context.is_absolute() { - context = dir.join(context); + let mut context_directory = PathBuf::from(context_directory.map_or(".", |s| s)); + if !context_directory.is_absolute() { + context_directory = dir.join(context_directory); } // context = context.canonicalize().unwrap(); - Ok(context + Ok(context_directory .to_str() .ok_or_else(|| anyhow!("context directory contains invalid characters")) .unwrap() .to_string()) } -fn make_relative_path(dir: &Path, context: &str, input: &str) -> Result { +fn make_relative_path(dir: &Path, context_directory: &str, input: &str) -> Result { let mut input = PathBuf::from(input); if !input.is_absolute() { input = dir.join(input); } // input = input.canonicalize()?; - let input = input.strip_prefix(context).with_context(|| { + let input = input.strip_prefix(context_directory).with_context(|| { anyhow!( "{} is not part of the context directory {}", input.display(), - context + context_directory ) })?; Ok(input @@ -304,10 +304,10 @@ fn make_relative_path(dir: &Path, context: &str, input: &str) -> Result .replace('\\', "/")) } -fn process_input(dir: &Path, context: &str, input: &[String]) -> Result> { +fn process_input(dir: &Path, context_directory: &str, input: &[String]) -> Result> { input .iter() - .map(|input| make_relative_path(dir, context, input)) + .map(|input| make_relative_path(dir, context_directory, input)) .collect() } @@ -547,19 +547,19 @@ async fn main_operation( ref process_cwd, .. } = args.common(); - let context = process_context(&dir, context_directory.as_ref()).unwrap(); - let fs = create_fs("context directory", &context, watch).await?; + let context_directory = process_context(&dir, context_directory.as_ref()).unwrap(); + let fs = create_fs("context directory", &context_directory, watch).await?; match *args { Args::Print { common: _ } => { - let input = process_input(&dir, &context, input).unwrap(); + let input = process_input(&dir, &context_directory, input).unwrap(); let mut result = BTreeSet::new(); let modules = input_to_modules( fs, input, exact, process_cwd.clone(), - context, + context_directory, module_options, resolve_options, ) @@ -577,7 +577,7 @@ async fn main_operation( return Ok(Vc::cell(result.into_iter().collect::>())); } Args::Annotate { common: _ } => { - let input = process_input(&dir, &context, input).unwrap(); + let input = process_input(&dir, &context_directory, input).unwrap(); let mut output_nft_assets = Vec::new(); let mut emits = Vec::new(); for module in input_to_modules( @@ -585,7 +585,7 @@ async fn main_operation( input, exact, process_cwd.clone(), - context, + context_directory, module_options, resolve_options, ) @@ -608,7 +608,7 @@ async fn main_operation( common: _, } => { let output = process_context(&dir, Some(output_directory)).unwrap(); - let input = process_input(&dir, &context, input).unwrap(); + let input = process_input(&dir, &context_directory, input).unwrap(); let out_fs = create_fs("output directory", &output, watch).await?; let input_dir = fs.root(); let output_dir = out_fs.root(); @@ -618,7 +618,7 @@ async fn main_operation( input, exact, process_cwd.clone(), - context, + context_directory, module_options, resolve_options, ) diff --git a/crates/node-file-trace/src/nft_json.rs b/crates/node-file-trace/src/nft_json.rs index 474d988bca631..addce3edd74df 100644 --- a/crates/node-file-trace/src/nft_json.rs +++ b/crates/node-file-trace/src/nft_json.rs @@ -38,15 +38,15 @@ impl OutputAsset for NftJsonAsset { impl Asset for NftJsonAsset { #[turbo_tasks::function] async fn content(&self) -> Result> { - let context = self.entry.ident().path().parent().await?; + let parent_dir = self.entry.ident().path().parent().await?; // For clippy -- This explicit deref is necessary let entry_path = &*self.entry.ident().path().await?; let mut result = Vec::new(); - if let Some(self_path) = context.get_relative_path_to(entry_path) { + if let Some(self_path) = parent_dir.get_relative_path_to(entry_path) { let set = all_modules(self.entry); for asset in set.await?.iter() { let path = asset.ident().path().await?; - if let Some(rel_path) = context.get_relative_path_to(&path) { + if let Some(rel_path) = parent_dir.get_relative_path_to(&path) { if rel_path != self_path { result.push(rel_path); } diff --git a/crates/turbo-tasks-build/src/lib.rs b/crates/turbo-tasks-build/src/lib.rs index dd83adf84ffe8..10ae097733467 100644 --- a/crates/turbo-tasks-build/src/lib.rs +++ b/crates/turbo-tasks-build/src/lib.rs @@ -267,13 +267,13 @@ impl<'a> RegisterContext<'a> { fn process_mod(&mut self, mod_item: ItemMod) -> Result<()> { if mod_item.content.is_none() { let name = mod_item.ident.to_string(); - let context = self.file_path.parent().unwrap(); - let direct = context.join(format!("{name}.rs")); + let parent_path = self.file_path.parent().unwrap(); + let direct = parent_path.join(format!("{name}.rs")); if direct.exists() { self.queue .push((format!("{}::{name}", self.mod_path), direct)); } else { - let nested = context.join(&name).join("mod.rs"); + let nested = parent_path.join(&name).join("mod.rs"); if nested.exists() { self.queue .push((format!("{}::{name}", self.mod_path), nested)); diff --git a/crates/turbo-tasks-fetch/src/lib.rs b/crates/turbo-tasks-fetch/src/lib.rs index 70b089256f233..264f673308b14 100644 --- a/crates/turbo-tasks-fetch/src/lib.rs +++ b/crates/turbo-tasks-fetch/src/lib.rs @@ -108,11 +108,11 @@ impl FetchError { pub async fn to_issue( self: Vc, severity: Vc, - context: Vc, + issue_context: Vc, ) -> Result> { let this = &*self.await?; Ok(FetchIssue { - context, + issue_context, severity, url: this.url, kind: this.kind, @@ -124,7 +124,7 @@ impl FetchError { #[turbo_tasks::value(shared)] pub struct FetchIssue { - pub context: Vc, + pub issue_context: Vc, pub severity: Vc, pub url: Vc, pub kind: Vc, @@ -135,7 +135,7 @@ pub struct FetchIssue { impl Issue for FetchIssue { #[turbo_tasks::function] fn context(&self) -> Vc { - self.context + self.issue_context } #[turbo_tasks::function] diff --git a/crates/turbo-tasks-fs/src/lib.rs b/crates/turbo-tasks-fs/src/lib.rs index 147fe4557fb88..1e866d636c199 100644 --- a/crates/turbo-tasks-fs/src/lib.rs +++ b/crates/turbo-tasks-fs/src/lib.rs @@ -879,25 +879,25 @@ pub struct FileSystemPath { } impl FileSystemPath { - pub fn is_inside_ref(&self, context: &FileSystemPath) -> bool { - if self.fs == context.fs && self.path.starts_with(&context.path) { - if context.path.is_empty() { + pub fn is_inside_ref(&self, other: &FileSystemPath) -> bool { + if self.fs == other.fs && self.path.starts_with(&other.path) { + if other.path.is_empty() { true } else { - self.path.as_bytes().get(context.path.len()) == Some(&b'/') + self.path.as_bytes().get(other.path.len()) == Some(&b'/') } } else { false } } - pub fn is_inside_or_equal_ref(&self, context: &FileSystemPath) -> bool { - if self.fs == context.fs && self.path.starts_with(&context.path) { - if context.path.is_empty() { + pub fn is_inside_or_equal_ref(&self, other: &FileSystemPath) -> bool { + if self.fs == other.fs && self.path.starts_with(&other.path) { + if other.path.is_empty() { true } else { matches!( - self.path.as_bytes().get(context.path.len()), + self.path.as_bytes().get(other.path.len()), Some(&b'/') | None ) } diff --git a/crates/turbo-tasks/src/read_ref.rs b/crates/turbo-tasks/src/read_ref.rs index 1328e7a968320..0e722b1d5a51f 100644 --- a/crates/turbo-tasks/src/read_ref.rs +++ b/crates/turbo-tasks/src/read_ref.rs @@ -65,8 +65,8 @@ where T: VcValueType, >::Target: TraceRawVcs, { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - (**self).trace_raw_vcs(context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + (**self).trace_raw_vcs(trace_context); } } diff --git a/crates/turbo-tasks/src/state.rs b/crates/turbo-tasks/src/state.rs index 1adc34fce1d6a..072a2558729b1 100644 --- a/crates/turbo-tasks/src/state.rs +++ b/crates/turbo-tasks/src/state.rs @@ -33,8 +33,8 @@ impl Debug for State { } impl TraceRawVcs for State { - fn trace_raw_vcs(&self, context: &mut crate::trace::TraceRawVcsContext) { - self.inner.lock().value.trace_raw_vcs(context); + fn trace_raw_vcs(&self, trace_context: &mut crate::trace::TraceRawVcsContext) { + self.inner.lock().value.trace_raw_vcs(trace_context); } } diff --git a/crates/turbo-tasks/src/trace.rs b/crates/turbo-tasks/src/trace.rs index 1d47432375f3b..da7000c8501cd 100644 --- a/crates/turbo-tasks/src/trace.rs +++ b/crates/turbo-tasks/src/trace.rs @@ -36,11 +36,11 @@ impl TraceRawVcsContext { /// `#[derive(TraceRawVcs)]` is available. /// `#[trace_ignore]` can be used on fields to skip tracing for them. pub trait TraceRawVcs { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext); fn get_raw_vcs(&self) -> Vec { - let mut context = TraceRawVcsContext::new(); - self.trace_raw_vcs(&mut context); - context.into_vec() + let mut trace_context = TraceRawVcsContext::new(); + self.trace_raw_vcs(&mut trace_context); + trace_context.into_vec() } } @@ -75,150 +75,150 @@ ignore!(Path, PathBuf); ignore!(serde_json::Value); impl<'a> TraceRawVcs for &'a str { - fn trace_raw_vcs(&self, _context: &mut TraceRawVcsContext) {} + fn trace_raw_vcs(&self, _trace_context: &mut TraceRawVcsContext) {} } impl TraceRawVcs for (A,) { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - TraceRawVcs::trace_raw_vcs(&self.0, context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + TraceRawVcs::trace_raw_vcs(&self.0, trace_context); } } impl TraceRawVcs for (A, B) { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - TraceRawVcs::trace_raw_vcs(&self.0, context); - TraceRawVcs::trace_raw_vcs(&self.1, context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + TraceRawVcs::trace_raw_vcs(&self.0, trace_context); + TraceRawVcs::trace_raw_vcs(&self.1, trace_context); } } impl TraceRawVcs for (A, B, C) { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - TraceRawVcs::trace_raw_vcs(&self.0, context); - TraceRawVcs::trace_raw_vcs(&self.1, context); - TraceRawVcs::trace_raw_vcs(&self.2, context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + TraceRawVcs::trace_raw_vcs(&self.0, trace_context); + TraceRawVcs::trace_raw_vcs(&self.1, trace_context); + TraceRawVcs::trace_raw_vcs(&self.2, trace_context); } } impl TraceRawVcs for Option { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { if let Some(item) = self { - TraceRawVcs::trace_raw_vcs(item, context); + TraceRawVcs::trace_raw_vcs(item, trace_context); } } } impl TraceRawVcs for Vec { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for item in self.iter() { - TraceRawVcs::trace_raw_vcs(item, context); + TraceRawVcs::trace_raw_vcs(item, trace_context); } } } impl TraceRawVcs for HashSet { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for item in self.iter() { - TraceRawVcs::trace_raw_vcs(item, context); + TraceRawVcs::trace_raw_vcs(item, trace_context); } } } impl TraceRawVcs for AutoSet { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for item in self.iter() { - TraceRawVcs::trace_raw_vcs(item, context); + TraceRawVcs::trace_raw_vcs(item, trace_context); } } } impl TraceRawVcs for BTreeSet { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for item in self.iter() { - TraceRawVcs::trace_raw_vcs(item, context); + TraceRawVcs::trace_raw_vcs(item, trace_context); } } } impl TraceRawVcs for IndexSet { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for item in self.iter() { - TraceRawVcs::trace_raw_vcs(item, context); + TraceRawVcs::trace_raw_vcs(item, trace_context); } } } impl TraceRawVcs for HashMap { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for (key, value) in self.iter() { - TraceRawVcs::trace_raw_vcs(key, context); - TraceRawVcs::trace_raw_vcs(value, context); + TraceRawVcs::trace_raw_vcs(key, trace_context); + TraceRawVcs::trace_raw_vcs(value, trace_context); } } } impl TraceRawVcs for AutoMap { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for (key, value) in self.iter() { - TraceRawVcs::trace_raw_vcs(key, context); - TraceRawVcs::trace_raw_vcs(value, context); + TraceRawVcs::trace_raw_vcs(key, trace_context); + TraceRawVcs::trace_raw_vcs(value, trace_context); } } } impl TraceRawVcs for BTreeMap { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for (key, value) in self.iter() { - TraceRawVcs::trace_raw_vcs(key, context); - TraceRawVcs::trace_raw_vcs(value, context); + TraceRawVcs::trace_raw_vcs(key, trace_context); + TraceRawVcs::trace_raw_vcs(value, trace_context); } } } impl TraceRawVcs for IndexMap { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { for (key, value) in self.iter() { - TraceRawVcs::trace_raw_vcs(key, context); - TraceRawVcs::trace_raw_vcs(value, context); + TraceRawVcs::trace_raw_vcs(key, trace_context); + TraceRawVcs::trace_raw_vcs(value, trace_context); } } } impl TraceRawVcs for Box { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - TraceRawVcs::trace_raw_vcs(&**self, context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + TraceRawVcs::trace_raw_vcs(&**self, trace_context); } } impl TraceRawVcs for Arc { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - TraceRawVcs::trace_raw_vcs(&**self, context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + TraceRawVcs::trace_raw_vcs(&**self, trace_context); } } impl TraceRawVcs for RawVc { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - context.list.push(*self); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + trace_context.list.push(*self); } } impl TraceRawVcs for Result { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { match self { - Ok(o) => o.trace_raw_vcs(context), - Err(e) => e.trace_raw_vcs(context), + Ok(o) => o.trace_raw_vcs(trace_context), + Err(e) => e.trace_raw_vcs(trace_context), } } } impl TraceRawVcs for Mutex { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - self.lock().unwrap().trace_raw_vcs(context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + self.lock().unwrap().trace_raw_vcs(trace_context); } } impl TraceRawVcs for RefCell { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - self.borrow().trace_raw_vcs(context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + self.borrow().trace_raw_vcs(trace_context); } } diff --git a/crates/turbo-tasks/src/vc/mod.rs b/crates/turbo-tasks/src/vc/mod.rs index 0803971823573..d907e89e9ef53 100644 --- a/crates/turbo-tasks/src/vc/mod.rs +++ b/crates/turbo-tasks/src/vc/mod.rs @@ -446,8 +446,8 @@ impl TraceRawVcs for Vc where T: ?Sized, { - fn trace_raw_vcs(&self, context: &mut TraceRawVcsContext) { - TraceRawVcs::trace_raw_vcs(&self.node, context); + fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext) { + TraceRawVcs::trace_raw_vcs(&self.node, trace_context); } } diff --git a/crates/turbopack-build/src/chunking_context.rs b/crates/turbopack-build/src/chunking_context.rs index ca18e1e1fd5b0..b22798c9145c4 100644 --- a/crates/turbopack-build/src/chunking_context.rs +++ b/crates/turbopack-build/src/chunking_context.rs @@ -24,23 +24,23 @@ use crate::ecmascript::node::{ /// A builder for [`Vc`]. pub struct BuildChunkingContextBuilder { - context: BuildChunkingContext, + chunking_context: BuildChunkingContext, } impl BuildChunkingContextBuilder { pub fn runtime_type(mut self, runtime_type: RuntimeType) -> Self { - self.context.runtime_type = runtime_type; + self.chunking_context.runtime_type = runtime_type; self } pub fn layer(mut self, layer: impl Into) -> Self { - self.context.layer = Some(layer.into()); + self.chunking_context.layer = Some(layer.into()); self } /// Builds the chunking context. pub fn build(self) -> Vc { - BuildChunkingContext::new(Value::new(self.context)) + BuildChunkingContext::new(Value::new(self.chunking_context)) } } @@ -75,7 +75,7 @@ impl BuildChunkingContext { environment: Vc, ) -> BuildChunkingContextBuilder { BuildChunkingContextBuilder { - context: BuildChunkingContext { + chunking_context: BuildChunkingContext { context_path, output_root, chunk_root_path, @@ -276,9 +276,9 @@ impl ChunkingContext for BuildChunkingContext { #[turbo_tasks::function] async fn with_layer(self: Vc, layer: String) -> Result> { - let mut context = self.await?.clone_value(); - context.layer = (!layer.is_empty()).then(|| layer.to_string()); - Ok(BuildChunkingContext::new(Value::new(context))) + let mut chunking_context = self.await?.clone_value(); + chunking_context.layer = (!layer.is_empty()).then(|| layer.to_string()); + Ok(BuildChunkingContext::new(Value::new(chunking_context))) } #[turbo_tasks::function] diff --git a/crates/turbopack-cli-utils/src/runtime_entry.rs b/crates/turbopack-cli-utils/src/runtime_entry.rs index 648e8a454e7f7..6d4f2d03c69a6 100644 --- a/crates/turbopack-cli-utils/src/runtime_entry.rs +++ b/crates/turbopack-cli-utils/src/runtime_entry.rs @@ -23,18 +23,18 @@ impl RuntimeEntry { #[turbo_tasks::function] pub async fn resolve_entry( self: Vc, - context: Vc>, + asset_context: Vc>, ) -> Result> { let (request, path) = match *self.await? { RuntimeEntry::Evaluatable(e) => return Ok(EvaluatableAssets::one(e)), RuntimeEntry::Source(source) => { - return Ok(EvaluatableAssets::one(source.to_evaluatable(context))); + return Ok(EvaluatableAssets::one(source.to_evaluatable(asset_context))); } RuntimeEntry::Request(r, path) => (r, path), }; let modules = cjs_resolve( - Vc::upcast(PlainResolveOrigin::new(context, path)), + Vc::upcast(PlainResolveOrigin::new(asset_context, path)), request, OptionIssueSource::none(), IssueSeverity::Error.cell(), @@ -68,12 +68,12 @@ impl RuntimeEntries { #[turbo_tasks::function] pub async fn resolve_entries( self: Vc, - context: Vc>, + asset_context: Vc>, ) -> Result> { let mut runtime_entries = Vec::new(); for reference in &self.await? { - let resolved_entries = reference.resolve_entry(context).await?; + let resolved_entries = reference.resolve_entry(asset_context).await?; runtime_entries.extend(&resolved_entries); } diff --git a/crates/turbopack-cli/src/build/mod.rs b/crates/turbopack-cli/src/build/mod.rs index 6f02bd496fc66..f96c4935515e9 100644 --- a/crates/turbopack-cli/src/build/mod.rs +++ b/crates/turbopack-cli/src/build/mod.rs @@ -185,7 +185,7 @@ async fn build_internal( let compile_time_info = get_client_compile_time_info(browserslist_query, node_env); let execution_context = ExecutionContext::new(project_path, chunking_context, load_env(project_path)); - let context = + let asset_context = get_client_asset_context(project_path, execution_context, compile_time_info, node_env); let entry_requests = (*entry_requests @@ -204,7 +204,7 @@ async fn build_internal( .await?) .to_vec(); - let origin = PlainResolveOrigin::new(context, output_fs.root().join("_".to_string())); + let origin = PlainResolveOrigin::new(asset_context, output_fs.root().join("_".to_string())); let project_dir = &project_dir; let entries = entry_requests .into_iter() diff --git a/crates/turbopack-cli/src/contexts.rs b/crates/turbopack-cli/src/contexts.rs index e5d913f692417..41d6dcffbfd58 100644 --- a/crates/turbopack-cli/src/contexts.rs +++ b/crates/turbopack-cli/src/contexts.rs @@ -164,14 +164,14 @@ pub fn get_client_asset_context( node_env, ); - let context: Vc> = Vc::upcast(ModuleAssetContext::new( + let asset_context: Vc> = Vc::upcast(ModuleAssetContext::new( Vc::cell(HashMap::new()), compile_time_info, module_options_context, resolve_options_context, )); - context + asset_context } fn client_defines(node_env: &NodeEnv) -> Vc { diff --git a/crates/turbopack-cli/src/dev/web_entry_source.rs b/crates/turbopack-cli/src/dev/web_entry_source.rs index 2c36238a9ea8a..2e1d6e4d8a1b8 100644 --- a/crates/turbopack-cli/src/dev/web_entry_source.rs +++ b/crates/turbopack-cli/src/dev/web_entry_source.rs @@ -90,15 +90,15 @@ pub async fn create_web_entry_source( browserslist_query: String, ) -> Result>> { let compile_time_info = get_client_compile_time_info(browserslist_query, node_env); - let context = + let asset_context = get_client_asset_context(project_path, execution_context, compile_time_info, node_env); let chunking_context = get_client_chunking_context(project_path, server_root, compile_time_info.environment()); let entries = get_client_runtime_entries(project_path); - let runtime_entries = entries.resolve_entries(context); + let runtime_entries = entries.resolve_entries(asset_context); - let origin = PlainResolveOrigin::new(context, project_path.join("_".to_string())); + let origin = PlainResolveOrigin::new(asset_context, project_path.join("_".to_string())); let entries = entry_requests .into_iter() .map(|request| async move { diff --git a/crates/turbopack-core/src/resolve/mod.rs b/crates/turbopack-core/src/resolve/mod.rs index 21116a7cd1a9b..c019214dcd5fc 100644 --- a/crates/turbopack-core/src/resolve/mod.rs +++ b/crates/turbopack-core/src/resolve/mod.rs @@ -778,8 +778,8 @@ enum ImportsFieldResult { /// Extracts the "imports" field out of the nearest package.json, parsing it /// into an appropriate [AliasMap] for lookups. #[turbo_tasks::function] -async fn imports_field(context: Vc) -> Result> { - let package_json_context = find_context_file(context, package_json()).await?; +async fn imports_field(lookup_path: Vc) -> Result> { + let package_json_context = find_context_file(lookup_path, package_json()).await?; let FindContextFileResult::Found(package_json_path, _refs) = &*package_json_context else { return Ok(ImportsFieldResult::None.cell()); }; @@ -820,13 +820,13 @@ pub enum FindContextFileResult { #[turbo_tasks::function] pub async fn find_context_file( - context: Vc, + lookup_path: Vc, names: Vc>, ) -> Result> { let mut refs = Vec::new(); - let context_value = context.await?; + let context_value = lookup_path.await?; for name in &*names.await? { - let fs_path = context.join(name.clone()); + let fs_path = lookup_path.join(name.clone()); if let Some(fs_path) = exists(fs_path, &mut refs).await? { return Ok(FindContextFileResult::Found(fs_path, refs).into()); } @@ -836,9 +836,9 @@ pub async fn find_context_file( } if refs.is_empty() { // Tailcall - Ok(find_context_file(context.parent(), names)) + Ok(find_context_file(lookup_path.parent(), names)) } else { - let parent_result = find_context_file(context.parent(), names).await?; + let parent_result = find_context_file(lookup_path.parent(), names).await?; Ok(match &*parent_result { FindContextFileResult::Found(p, r) => { refs.extend(r.iter().copied()); @@ -861,7 +861,7 @@ struct FindPackageResult { #[turbo_tasks::function] async fn find_package( - context: Vc, + lookup_path: Vc, package_name: String, options: Vc, ) -> Result> { @@ -871,13 +871,13 @@ async fn find_package( for resolve_modules in &options.modules { match resolve_modules { ResolveModules::Nested(root_vc, names) => { - let mut context = context; - let mut context_value = context.await?; + let mut lookup_path = lookup_path; + let mut lookup_path_value = lookup_path.await?; // For clippy -- This explicit deref is necessary let root = &*root_vc.await?; - while context_value.is_inside_ref(root) { + while lookup_path_value.is_inside_ref(root) { for name in names.iter() { - let fs_path = context.join(name.clone()); + let fs_path = lookup_path.join(name.clone()); if let Some(fs_path) = dir_exists(fs_path, &mut affecting_sources).await? { let fs_path = fs_path.join(package_name.clone()); if let Some(fs_path) = @@ -887,12 +887,12 @@ async fn find_package( } } } - context = context.parent().resolve().await?; - let new_context_value = context.await?; - if *new_context_value == *context_value { + lookup_path = lookup_path.parent().resolve().await?; + let new_context_value = lookup_path.await?; + if *new_context_value == *lookup_path_value { break; } - context_value = new_context_value; + lookup_path_value = new_context_value; } } ResolveModules::Path(context) => { diff --git a/crates/turbopack-ecmascript/src/parse.rs b/crates/turbopack-ecmascript/src/parse.rs index be523bf2541de..de3cdc81fc06b 100644 --- a/crates/turbopack-ecmascript/src/parse.rs +++ b/crates/turbopack-ecmascript/src/parse.rs @@ -320,7 +320,7 @@ async fn parse_content( is_typescript, )); - let context = TransformContext { + let transform_context = TransformContext { comments: &comments, source_map: &source_map, top_level_mark, @@ -331,7 +331,9 @@ async fn parse_content( file_path: fs_path_vc, }; for transform in transforms.iter() { - transform.apply(&mut parsed_program, &context).await?; + transform + .apply(&mut parsed_program, &transform_context) + .await?; } parsed_program.visit_mut_with( diff --git a/crates/turbopack-wasm/src/lib.rs b/crates/turbopack-wasm/src/lib.rs index f219287105c15..db012caeb2ac9 100644 --- a/crates/turbopack-wasm/src/lib.rs +++ b/crates/turbopack-wasm/src/lib.rs @@ -43,23 +43,26 @@ fn modifier() -> Vc { #[derive(Clone)] pub struct WebAssemblyModuleAsset { pub source: Vc>, - pub context: Vc>, + pub asset_context: Vc>, } #[turbo_tasks::value_impl] impl WebAssemblyModuleAsset { #[turbo_tasks::function] - pub fn new(source: Vc>, context: Vc>) -> Vc { - Self::cell(WebAssemblyModuleAsset { source, context }) + pub fn new(source: Vc>, asset_context: Vc>) -> Vc { + Self::cell(WebAssemblyModuleAsset { + source, + asset_context, + }) } #[turbo_tasks::function] async fn wasm_asset( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Result> { Ok(WebAssemblyAsset::cell(WebAssemblyAsset { - context, + chunking_context, source: self.await?.source, })) } @@ -86,11 +89,11 @@ impl ChunkableModule for WebAssemblyModuleAsset { #[turbo_tasks::function] fn as_chunk( self: Vc, - context: Vc>, + chunking_context: Vc>, availability_info: Value, ) -> Vc> { Vc::upcast(EcmascriptChunk::new( - context, + chunking_context, Vc::upcast(self), availability_info, )) @@ -102,12 +105,12 @@ impl EcmascriptChunkPlaceable for WebAssemblyModuleAsset { #[turbo_tasks::function] fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast(ModuleChunkItem::cell(ModuleChunkItem { module: self, - context, - wasm_asset: self.wasm_asset(Vc::upcast(context)), + chunking_context, + wasm_asset: self.wasm_asset(Vc::upcast(chunking_context)), })) } @@ -131,7 +134,7 @@ impl EcmascriptChunkPlaceable for WebAssemblyModuleAsset { #[turbo_tasks::value] struct WebAssemblyAsset { - context: Vc>, + chunking_context: Vc>, source: Vc>, } @@ -141,7 +144,7 @@ impl OutputAsset for WebAssemblyAsset { async fn ident(&self) -> Result> { let ident = self.source.ident().with_modifier(modifier()); - let asset_path = self.context.chunk_path(ident, ".wasm".to_string()); + let asset_path = self.chunking_context.chunk_path(ident, ".wasm".to_string()); Ok(AssetIdent::from_path(asset_path)) } @@ -158,7 +161,7 @@ impl Asset for WebAssemblyAsset { #[turbo_tasks::value] struct ModuleChunkItem { module: Vc, - context: Vc>, + chunking_context: Vc>, wasm_asset: Vc, } @@ -185,7 +188,7 @@ impl ChunkItem for ModuleChunkItem { impl EcmascriptChunkItem for ModuleChunkItem { #[turbo_tasks::function] fn chunking_context(&self) -> Vc> { - self.context + self.chunking_context } #[turbo_tasks::function] @@ -199,7 +202,7 @@ impl EcmascriptChunkItem for ModuleChunkItem { availability_info: Value, ) -> Result> { let path = self.wasm_asset.ident().path().await?; - let output_root = self.context.output_root().await?; + let output_root = self.chunking_context.output_root().await?; let Some(path) = output_root.get_path_to(&path) else { bail!("WASM asset ident is not relative to output root");