diff --git a/.config/ast-grep/rules/no-context.yml b/.config/ast-grep/rules/no-context.yml index 8116e9c60b89b..df073c56dfc12 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 diff --git a/crates/turbopack-css/src/asset.rs b/crates/turbopack-css/src/asset.rs index be5b89720ecc2..11faffafbab12 100644 --- a/crates/turbopack-css/src/asset.rs +++ b/crates/turbopack-css/src/asset.rs @@ -43,7 +43,7 @@ fn modifier() -> Vc { #[derive(Clone)] pub struct CssModuleAsset { source: Vc>, - context: Vc>, + asset_context: Vc>, transforms: Vc, ty: CssModuleAssetType, } @@ -54,13 +54,13 @@ impl CssModuleAsset { #[turbo_tasks::function] pub fn new( source: Vc>, - context: Vc>, + asset_context: Vc>, transforms: Vc, ty: CssModuleAssetType, ) -> Vc { Self::cell(CssModuleAsset { source, - context, + asset_context, transforms, ty, }) @@ -114,10 +114,14 @@ impl ChunkableModule for CssModuleAsset { #[turbo_tasks::function] fn as_chunk( self: Vc, - context: Vc>, + chunking_context: Vc>, availability_info: Value, ) -> Vc> { - Vc::upcast(CssChunk::new(context, Vc::upcast(self), availability_info)) + Vc::upcast(CssChunk::new( + chunking_context, + Vc::upcast(self), + availability_info, + )) } } @@ -126,11 +130,11 @@ impl CssChunkPlaceable for CssModuleAsset { #[turbo_tasks::function] fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast(CssModuleChunkItem::cell(CssModuleChunkItem { module: self, - context, + chunking_context, })) } } @@ -144,14 +148,14 @@ impl ResolveOrigin for CssModuleAsset { #[turbo_tasks::function] fn asset_context(&self) -> Vc> { - self.context + self.asset_context } } #[turbo_tasks::value] struct CssModuleChunkItem { module: Vc, - context: Vc>, + chunking_context: Vc>, } #[turbo_tasks::value_impl] @@ -173,7 +177,7 @@ impl CssChunkItem for CssModuleChunkItem { async fn content(&self) -> Result> { let references = &*self.module.references().await?; let mut imports = vec![]; - let context = self.context; + let chunking_context = self.chunking_context; for reference in references.iter() { if let Some(import_ref) = @@ -190,7 +194,7 @@ impl CssChunkItem for CssModuleChunkItem { { imports.push(CssImport::Internal( import_ref, - placeable.as_chunk_item(context), + placeable.as_chunk_item(chunking_context), )); } } @@ -206,7 +210,9 @@ impl CssChunkItem for CssModuleChunkItem { if let Some(placeable) = Vc::try_resolve_downcast::>(module).await? { - imports.push(CssImport::Composes(placeable.as_chunk_item(context))); + imports.push(CssImport::Composes( + placeable.as_chunk_item(chunking_context), + )); } } } @@ -217,7 +223,7 @@ impl CssChunkItem for CssModuleChunkItem { if let Some(code_gen) = Vc::try_resolve_sidecast::>(*r).await? { - code_gens.push(code_gen.code_generation(context)); + code_gens.push(code_gen.code_generation(chunking_context)); } } // need to keep that around to allow references into that @@ -308,6 +314,6 @@ impl CssChunkItem for CssModuleChunkItem { #[turbo_tasks::function] fn chunking_context(&self) -> Vc> { - self.context + self.chunking_context } } diff --git a/crates/turbopack-css/src/chunk/mod.rs b/crates/turbopack-css/src/chunk/mod.rs index bed67556231e0..4459473190dae 100644 --- a/crates/turbopack-css/src/chunk/mod.rs +++ b/crates/turbopack-css/src/chunk/mod.rs @@ -39,7 +39,7 @@ use crate::{ #[turbo_tasks::value] pub struct CssChunk { - pub context: Vc>, + pub chunking_context: Vc>, pub main_entries: Vc, pub availability_info: AvailabilityInfo, } @@ -51,12 +51,12 @@ pub struct CssChunks(Vec>); impl CssChunk { #[turbo_tasks::function] pub fn new_normalized( - context: Vc>, + chunking_context: Vc>, main_entries: Vc, availability_info: Value, ) -> Vc { CssChunk { - context, + chunking_context, main_entries, availability_info: availability_info.into_value(), } @@ -65,11 +65,11 @@ impl CssChunk { #[turbo_tasks::function] pub fn new( - context: Vc>, + chunking_context: Vc>, entry: Vc>, availability_info: Value, ) -> Vc { - Self::new_normalized(context, Vc::cell(vec![entry]), availability_info) + Self::new_normalized(chunking_context, Vc::cell(vec![entry]), availability_info) } /// Return the most specific directory which contains all elements of the @@ -101,14 +101,18 @@ impl CssChunk { #[turbo_tasks::function] async fn chunk_content(self: Vc) -> Result> { let this = self.await?; - Ok(CssChunkContent::new(this.main_entries, this.context, self)) + Ok(CssChunkContent::new( + this.main_entries, + this.chunking_context, + self, + )) } } #[turbo_tasks::value] struct CssChunkContent { main_entries: Vc, - context: Vc>, + chunking_context: Vc>, chunk: Vc, } @@ -117,12 +121,12 @@ impl CssChunkContent { #[turbo_tasks::function] async fn new( main_entries: Vc, - context: Vc>, + chunking_context: Vc>, chunk: Vc, ) -> Result> { Ok(CssChunkContent { main_entries, - context, + chunking_context, chunk, } .cell()) @@ -138,7 +142,7 @@ impl CssChunkContent { let mut body = CodeBuilder::default(); let mut external_imports = IndexSet::new(); for entry in this.main_entries.await?.iter() { - let entry_item = entry.as_chunk_item(this.context); + let entry_item = entry.as_chunk_item(this.chunking_context); // TODO(WEB-1261) for external_import in expand_imports(&mut body, entry_item).await? { @@ -155,7 +159,7 @@ impl CssChunkContent { code.push_code(&body.build()); if *this - .context + .chunking_context .reference_chunk_source_maps(Vc::upcast(this.chunk)) .await? && code.has_source_map() @@ -208,7 +212,7 @@ impl From>>> for CssChunkContentResu #[turbo_tasks::function] async fn css_chunk_content( - context: Vc>, + chunking_context: Vc>, entries: Vc, availability_info: Value, ) -> Result> { @@ -216,7 +220,7 @@ async fn css_chunk_content( let entries = entries.iter().copied(); let contents = entries - .map(|entry| css_chunk_content_single_entry(context, entry, availability_info)) + .map(|entry| css_chunk_content_single_entry(chunking_context, entry, availability_info)) .collect::>(); if contents.len() == 1 { @@ -248,18 +252,24 @@ async fn css_chunk_content( #[turbo_tasks::function] async fn css_chunk_content_single_entry( - context: Vc>, + chunking_context: Vc>, entry: Vc>, availability_info: Value, ) -> Result> { let asset = Vc::upcast(entry); let res = if let Some(res) = - chunk_content::>(context, asset, None, availability_info).await? + chunk_content::>(chunking_context, asset, None, availability_info) + .await? { res } else { - chunk_content_split::>(context, asset, None, availability_info) - .await? + chunk_content_split::>( + chunking_context, + asset, + None, + availability_info, + ) + .await? }; Ok(CssChunkContentResult::cell(res.into())) @@ -275,13 +285,13 @@ impl Chunk for CssChunk { #[turbo_tasks::function] fn chunking_context(&self) -> Vc> { - self.context + self.chunking_context } #[turbo_tasks::function] async fn parallel_chunks(&self) -> Result> { let content = css_chunk_content( - self.context, + self.chunking_context, self.main_entries, Value::new(self.availability_info), ) @@ -304,7 +314,7 @@ impl OutputChunk for CssChunk { #[turbo_tasks::function] async fn runtime_info(&self) -> Result> { let content = css_chunk_content( - self.context, + self.chunking_context, self.main_entries, Value::new(self.availability_info), ) @@ -313,7 +323,7 @@ impl OutputChunk for CssChunk { .main_entries .await? .iter() - .map(|&entry| entry.as_chunk_item(self.context)) + .map(|&entry| entry.as_chunk_item(self.chunking_context)) .collect(); let included_ids = entries_chunk_items .iter() @@ -345,7 +355,7 @@ impl OutputChunk for CssChunk { .chunk_items .iter() .chain(imports_chunk_items.iter()) - .map(|item| Vc::upcast(SingleItemCssChunk::new(self.context, *item))) + .map(|item| Vc::upcast(SingleItemCssChunk::new(self.chunking_context, *item))) .collect(); Ok(OutputChunkRuntimeInfo { included_ids: Some(Vc::cell(included_ids)), @@ -384,7 +394,7 @@ impl OutputAsset for CssChunk { }; Ok(AssetIdent::from_path( - this.context.chunk_path(ident, ".css".to_string()), + this.chunking_context.chunk_path(ident, ".css".to_string()), )) } @@ -392,7 +402,7 @@ impl OutputAsset for CssChunk { async fn references(self: Vc) -> Result> { let this = self.await?; let content = css_chunk_content( - this.context, + this.chunking_context, this.main_entries, Value::new(this.availability_info), ) @@ -419,15 +429,18 @@ impl OutputAsset for CssChunk { if let Some(embeddable) = Vc::try_resolve_sidecast::>(asset).await? { - let embed = embeddable.as_css_embed(this.context); + let embed = embeddable.as_css_embed(this.chunking_context); references.extend(embed.references().await?.iter()); } } for item in content.chunk_items.iter() { - references.push(Vc::upcast(SingleItemCssChunk::new(this.context, *item))); + references.push(Vc::upcast(SingleItemCssChunk::new( + this.chunking_context, + *item, + ))); } if *this - .context + .chunking_context .reference_chunk_source_maps(Vc::upcast(self)) .await? { @@ -455,14 +468,14 @@ impl GenerateSourceMap for CssChunk { #[turbo_tasks::value] pub struct CssChunkContext { - context: Vc>, + chunking_context: Vc>, } #[turbo_tasks::value_impl] impl CssChunkContext { #[turbo_tasks::function] - pub fn of(context: Vc>) -> Vc { - CssChunkContext { context }.cell() + pub fn of(chunking_context: Vc>) -> Vc { + CssChunkContext { chunking_context }.cell() } #[turbo_tasks::function] @@ -470,7 +483,7 @@ impl CssChunkContext { self: Vc, chunk_item: Vc>, ) -> Result> { - let layer = self.await?.context.layer(); + let layer = self.await?.chunking_context.layer(); let mut ident = chunk_item.asset_ident(); if !layer.await?.is_empty() { ident = ident.with_modifier(layer) @@ -483,7 +496,7 @@ impl CssChunkContext { pub trait CssChunkPlaceable: ChunkableModule + Module + Asset { fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc>; } @@ -517,13 +530,13 @@ pub trait CssChunkItem: ChunkItem { #[async_trait::async_trait] impl FromChunkableModule for Box { async fn from_asset( - context: Vc>, + chunking_context: Vc>, asset: Vc>, ) -> Result>> { if let Some(placeable) = Vc::try_resolve_downcast::>(asset).await? { - return Ok(Some(placeable.as_chunk_item(context))); + return Ok(Some(placeable.as_chunk_item(chunking_context))); } Ok(None) } @@ -565,7 +578,7 @@ impl Introspectable for CssChunk { let mut details = String::new(); let this = self.await?; let chunk_content = css_chunk_content( - this.context, + this.chunking_context, this.main_entries, Value::new(this.availability_info), ) diff --git a/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs b/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs index 776e424a3b642..162452593382a 100644 --- a/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs +++ b/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs @@ -21,7 +21,7 @@ use crate::chunk::CssChunkItem; /// avoiding rule duplication. #[turbo_tasks::value] pub struct SingleItemCssChunk { - context: Vc>, + chunking_context: Vc>, item: Vc>, } @@ -29,8 +29,15 @@ pub struct SingleItemCssChunk { impl SingleItemCssChunk { /// Creates a new [`Vc`]. #[turbo_tasks::function] - pub fn new(context: Vc>, item: Vc>) -> Vc { - SingleItemCssChunk { context, item }.cell() + pub fn new( + chunking_context: Vc>, + item: Vc>, + ) -> Vc { + SingleItemCssChunk { + chunking_context, + item, + } + .cell() } } @@ -50,7 +57,7 @@ impl SingleItemCssChunk { code.push_source(&content.inner_code, content.source_map.map(Vc::upcast)); if *this - .context + .chunking_context .reference_chunk_source_maps(Vc::upcast(self)) .await? && code.has_source_map() @@ -78,7 +85,7 @@ impl Chunk for SingleItemCssChunk { #[turbo_tasks::function] fn chunking_context(&self) -> Vc> { - self.context + self.chunking_context } } @@ -92,7 +99,7 @@ impl OutputAsset for SingleItemCssChunk { #[turbo_tasks::function] async fn ident(&self) -> Result> { Ok(AssetIdent::from_path( - self.context.chunk_path( + self.chunking_context.chunk_path( self.item .asset_ident() .with_modifier(single_item_modifier()), @@ -106,7 +113,7 @@ impl OutputAsset for SingleItemCssChunk { let this = self.await?; let mut references = Vec::new(); if *this - .context + .chunking_context .reference_chunk_source_maps(Vc::upcast(self)) .await? { diff --git a/crates/turbopack-css/src/code_gen.rs b/crates/turbopack-css/src/code_gen.rs index 69b9a47813d0f..55391294d3586 100644 --- a/crates/turbopack-css/src/code_gen.rs +++ b/crates/turbopack-css/src/code_gen.rs @@ -27,8 +27,10 @@ pub trait VisitorFactory: Send + Sync { #[turbo_tasks::value_trait] pub trait CodeGenerateable { - fn code_generation(self: Vc, context: Vc>) - -> Vc; + fn code_generation( + self: Vc, + chunking_context: Vc>, + ) -> Vc; } #[turbo_tasks::value(transparent)] diff --git a/crates/turbopack-css/src/embed.rs b/crates/turbopack-css/src/embed.rs index 5ec4b45a70f4e..10b22a41bb854 100644 --- a/crates/turbopack-css/src/embed.rs +++ b/crates/turbopack-css/src/embed.rs @@ -8,8 +8,10 @@ use turbopack_core::{ #[turbo_tasks::value_trait] pub trait CssEmbeddable: ChunkableModule + Module + Asset { - fn as_css_embed(self: Vc, context: Vc>) - -> Vc>; + fn as_css_embed( + self: Vc, + chunking_context: Vc>, + ) -> Vc>; } #[turbo_tasks::value_trait] diff --git a/crates/turbopack-css/src/global_asset.rs b/crates/turbopack-css/src/global_asset.rs index 208a7eb440cc8..8ffb732cbacad 100644 --- a/crates/turbopack-css/src/global_asset.rs +++ b/crates/turbopack-css/src/global_asset.rs @@ -17,15 +17,18 @@ use crate::references::internal::InternalCssAssetReference; #[derive(Clone)] pub struct GlobalCssAsset { source: Vc>, - context: Vc>, + asset_context: Vc>, } #[turbo_tasks::value_impl] impl GlobalCssAsset { /// Creates a new CSS asset. The CSS is treated as global CSS. #[turbo_tasks::function] - pub fn new(source: Vc>, context: Vc>) -> Vc { - Self::cell(GlobalCssAsset { source, context }) + pub fn new(source: Vc>, asset_context: Vc>) -> Vc { + Self::cell(GlobalCssAsset { + source, + asset_context, + }) } } @@ -38,7 +41,7 @@ impl GlobalCssAsset { // This can then be picked up by other rules to treat CSS assets in // a special way. For instance, in the Next App Router implementation, // RSC CSS assets will be added to the client references manifest. - Ok(this.context.process( + Ok(this.asset_context.process( this.source, Value::new(ReferenceType::Css(CssReferenceSubType::Internal)), )) diff --git a/crates/turbopack-css/src/module_asset.rs b/crates/turbopack-css/src/module_asset.rs index 3a4ddfee833d0..5de8ef3929f5d 100644 --- a/crates/turbopack-css/src/module_asset.rs +++ b/crates/turbopack-css/src/module_asset.rs @@ -46,7 +46,7 @@ fn modifier() -> Vc { #[derive(Clone)] pub struct ModuleCssAsset { pub source: Vc>, - pub context: Vc>, + pub asset_context: Vc>, } #[turbo_tasks::value_impl] @@ -54,9 +54,12 @@ impl ModuleCssAsset { #[turbo_tasks::function] pub async fn new( source: Vc>, - context: Vc>, + asset_context: Vc>, ) -> Result> { - Ok(Self::cell(ModuleCssAsset { source, context })) + Ok(Self::cell(ModuleCssAsset { + source, + asset_context, + })) } } @@ -139,7 +142,7 @@ impl ModuleCssAsset { #[turbo_tasks::function] async fn inner(self: Vc) -> Result>> { let this = self.await?; - Ok(this.context.process( + Ok(this.asset_context.process( this.source, Value::new(ReferenceType::Css(CssReferenceSubType::Internal)), )) @@ -210,11 +213,11 @@ impl ChunkableModule for ModuleCssAsset { #[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, )) @@ -226,11 +229,11 @@ impl EcmascriptChunkPlaceable for ModuleCssAsset { #[turbo_tasks::function] fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast( ModuleChunkItem { - context, + chunking_context, module: self, } .cell(), @@ -252,14 +255,14 @@ impl ResolveOrigin for ModuleCssAsset { #[turbo_tasks::function] fn asset_context(&self) -> Vc> { - self.context + self.asset_context } } #[turbo_tasks::value] struct ModuleChunkItem { module: Vc, - context: Vc>, + chunking_context: Vc>, } #[turbo_tasks::value_impl] @@ -279,7 +282,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] @@ -335,7 +338,7 @@ impl EcmascriptChunkItem for ModuleChunkItem { let placeable: Vc> = Vc::upcast(css_module); - let module_id = placeable.as_chunk_item(self.context).id().await?; + let module_id = placeable.as_chunk_item(self.chunking_context).id().await?; let module_id = StringifyJs(&*module_id); let original_name = StringifyJs(&original_name); exported_class_names.push(format! { diff --git a/crates/turbopack-css/src/parse.rs b/crates/turbopack-css/src/parse.rs index 0b09bd7893594..b60d028a27f62 100644 --- a/crates/turbopack-css/src/parse.rs +++ b/crates/turbopack-css/src/parse.rs @@ -197,11 +197,13 @@ async fn parse_content( return Ok(ParseCssResult::Unparseable.into()); } - let context = TransformContext { + let transform_context = TransformContext { source_map: &source_map, }; for transform in transforms.iter() { - transform.apply(&mut parsed_stylesheet, &context).await?; + transform + .apply(&mut parsed_stylesheet, &transform_context) + .await?; } let (imports, exports) = match ty { diff --git a/crates/turbopack-css/src/references/url.rs b/crates/turbopack-css/src/references/url.rs index b6ef7abafcf2a..1e2d4ff790e84 100644 --- a/crates/turbopack-css/src/references/url.rs +++ b/crates/turbopack-css/src/references/url.rs @@ -57,14 +57,14 @@ impl UrlAssetReference { #[turbo_tasks::function] async fn get_referenced_asset( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Result> { for &module in self.resolve_reference().primary_modules().await?.iter() { if let Some(embeddable) = Vc::try_resolve_sidecast::>(module).await? { return Ok(ReferencedAsset::Some( - embeddable.as_css_embed(context).embeddable_asset(), + embeddable.as_css_embed(chunking_context).embeddable_asset(), ) .into()); } @@ -102,12 +102,12 @@ impl CodeGenerateable for UrlAssetReference { #[turbo_tasks::function] async fn code_generation( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Result> { let this = self.await?; // TODO(WEB-662) This is not the correct way to get the current chunk path. It // currently works as all chunks are in the same directory. - let chunk_path = context.chunk_path( + let chunk_path = chunking_context.chunk_path( AssetIdent::from_path(this.origin.origin_path()), ".css".to_string(), ); @@ -115,7 +115,7 @@ impl CodeGenerateable for UrlAssetReference { let mut visitors = Vec::new(); - if let ReferencedAsset::Some(asset) = &*self.get_referenced_asset(context).await? { + if let ReferencedAsset::Some(asset) = &*self.get_referenced_asset(chunking_context).await? { // TODO(WEB-662) This is not the correct way to get the path of the asset. // `asset` is on module-level, but we need the output-level asset instead. let path = asset.ident().path().await?; diff --git a/crates/turbopack-dev-server/src/source/issue_context.rs b/crates/turbopack-dev-server/src/source/issue_context.rs index 8e4c9bfdd5ea9..b4d71bacad438 100644 --- a/crates/turbopack-dev-server/src/source/issue_context.rs +++ b/crates/turbopack-dev-server/src/source/issue_context.rs @@ -13,22 +13,22 @@ use super::{ }; #[turbo_tasks::value] -pub struct IssueContextContentSource { - context: Option>, +pub struct IssueFilePathContentSource { + file_path: Option>, description: String, source: Vc>, } #[turbo_tasks::value_impl] -impl IssueContextContentSource { +impl IssueFilePathContentSource { #[turbo_tasks::function] - pub fn new_context( - context: Vc, + pub fn new_file_path( + file_path: Vc, description: String, source: Vc>, ) -> Vc { - IssueContextContentSource { - context: Some(context), + IssueFilePathContentSource { + file_path: Some(file_path), description, source, } @@ -37,8 +37,8 @@ impl IssueContextContentSource { #[turbo_tasks::function] pub fn new_description(description: String, source: Vc>) -> Vc { - IssueContextContentSource { - context: None, + IssueFilePathContentSource { + file_path: None, description, source, } @@ -47,14 +47,14 @@ impl IssueContextContentSource { } #[turbo_tasks::value_impl] -impl ContentSource for IssueContextContentSource { +impl ContentSource for IssueFilePathContentSource { #[turbo_tasks::function] async fn get_routes(self: Vc) -> Result> { let this = self.await?; let routes = this .source .get_routes() - .issue_file_path(this.context, &this.description) + .issue_file_path(this.file_path, &this.description) .await?; Ok(routes.map_routes(Vc::upcast( IssueContextContentSourceMapper { source: self }.cell(), @@ -69,7 +69,7 @@ impl ContentSource for IssueContextContentSource { #[turbo_tasks::value] struct IssueContextContentSourceMapper { - source: Vc, + source: Vc, } #[turbo_tasks::value_impl] @@ -92,7 +92,7 @@ impl MapGetContentSourceContent for IssueContextContentSourceMapper { #[turbo_tasks::value] struct IssueContextGetContentSourceContent { get_content: Vc>, - source: Vc, + source: Vc, } #[turbo_tasks::value_impl] @@ -103,7 +103,7 @@ impl GetContentSourceContent for IssueContextGetContentSourceContent { let result = self .get_content .vary() - .issue_file_path(source.context, &source.description) + .issue_file_path(source.file_path, &source.description) .await?; Ok(result) } @@ -118,14 +118,14 @@ impl GetContentSourceContent for IssueContextGetContentSourceContent { let result = self .get_content .get(path, data) - .issue_file_path(source.context, &source.description) + .issue_file_path(source.file_path, &source.description) .await?; Ok(result) } } #[turbo_tasks::value_impl] -impl Introspectable for IssueContextContentSource { +impl Introspectable for IssueFilePathContentSource { #[turbo_tasks::function] async fn ty(&self) -> Result> { Ok( diff --git a/crates/turbopack-dev-server/src/source/mod.rs b/crates/turbopack-dev-server/src/source/mod.rs index 9638f8c12a545..b47843f49b67c 100644 --- a/crates/turbopack-dev-server/src/source/mod.rs +++ b/crates/turbopack-dev-server/src/source/mod.rs @@ -27,7 +27,8 @@ use turbo_tasks_hash::{DeterministicHash, DeterministicHasher, Xxh3Hash64Hasher} use turbopack_core::version::{Version, VersionedContent}; use self::{ - headers::Headers, issue_context::IssueContextContentSource, query::Query, route_tree::RouteTree, + headers::Headers, issue_context::IssueFilePathContentSource, query::Query, + route_tree::RouteTree, }; /// The result of proxying a request to another HTTP server. @@ -420,9 +421,9 @@ pub trait ContentSource { } pub trait ContentSourceExt { - fn issue_context( + fn issue_file_path( self: Vc, - context: Vc, + file_path: Vc, description: String, ) -> Vc>; } @@ -431,13 +432,13 @@ impl ContentSourceExt for T where T: Upcast>, { - fn issue_context( + fn issue_file_path( self: Vc, - context: Vc, + file_path: Vc, description: String, ) -> Vc> { - Vc::upcast(IssueContextContentSource::new_context( - context, + Vc::upcast(IssueFilePathContentSource::new_file_path( + file_path, description, Vc::upcast(self), )) diff --git a/crates/turbopack-dev/src/chunking_context.rs b/crates/turbopack-dev/src/chunking_context.rs index 73b6f6330974f..620439a1b2d32 100644 --- a/crates/turbopack-dev/src/chunking_context.rs +++ b/crates/turbopack-dev/src/chunking_context.rs @@ -27,42 +27,42 @@ use crate::{ }; pub struct DevChunkingContextBuilder { - context: DevChunkingContext, + chunking_context: DevChunkingContext, } impl DevChunkingContextBuilder { pub fn hot_module_replacement(mut self) -> Self { - self.context.enable_hot_module_replacement = true; + self.chunking_context.enable_hot_module_replacement = true; self } pub fn chunk_base_path(mut self, chunk_base_path: Vc>) -> Self { - self.context.chunk_base_path = chunk_base_path; + self.chunking_context.chunk_base_path = chunk_base_path; self } pub fn layer(mut self, layer: &str) -> Self { - self.context.layer = (!layer.is_empty()).then(|| layer.to_string()); + self.chunking_context.layer = (!layer.is_empty()).then(|| layer.to_string()); self } pub fn reference_chunk_source_maps(mut self, source_maps: bool) -> Self { - self.context.reference_chunk_source_maps = source_maps; + self.chunking_context.reference_chunk_source_maps = source_maps; self } pub fn reference_css_chunk_source_maps(mut self, source_maps: bool) -> Self { - self.context.reference_css_chunk_source_maps = source_maps; + self.chunking_context.reference_css_chunk_source_maps = source_maps; self } 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 build(self) -> Vc { - DevChunkingContext::new(Value::new(self.context)) + DevChunkingContext::new(Value::new(self.chunking_context)) } } @@ -109,7 +109,7 @@ impl DevChunkingContext { environment: Vc, ) -> DevChunkingContextBuilder { DevChunkingContextBuilder { - context: DevChunkingContext { + chunking_context: DevChunkingContext { context_path, output_root, chunk_root_path, @@ -302,9 +302,9 @@ impl ChunkingContext for DevChunkingContext { #[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(DevChunkingContext::new(Value::new(context))) + let mut chunking_context = self.await?.clone_value(); + chunking_context.layer = (!layer.is_empty()).then(|| layer.to_string()); + Ok(DevChunkingContext::new(Value::new(chunking_context))) } #[turbo_tasks::function] diff --git a/crates/turbopack-dev/src/css/optimize.rs b/crates/turbopack-dev/src/css/optimize.rs index cfb1946f079a4..668051545715a 100644 --- a/crates/turbopack-dev/src/css/optimize.rs +++ b/crates/turbopack-dev/src/css/optimize.rs @@ -34,7 +34,7 @@ async fn merge_chunks( .flat_map(|e| e.iter().copied()) .collect::>(); Ok(CssChunk::new_normalized( - first.await?.context, + first.await?.chunking_context, Vc::cell(main_entries.into_iter().collect()), Value::new(first.await?.availability_info), )) diff --git a/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs b/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs index 9b32744469e1f..d614d5e9bbdce 100644 --- a/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs +++ b/crates/turbopack-ecmascript-hmr-protocol/src/lib.rs @@ -129,7 +129,7 @@ pub struct IssueSource<'a> { #[derive(Serialize)] pub struct Issue<'a> { pub severity: IssueSeverity, - pub context: &'a str, + pub file_path: &'a str, pub category: &'a str, pub title: &'a str, @@ -155,7 +155,7 @@ impl<'a> From<&'a PlainIssue> for Issue<'a> { Issue { severity: plain.severity, - context: &plain.file_path, + file_path: &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 05c4b11f487b7..af4b87d222571 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 @@ -54,7 +54,7 @@ impl SwcPluginModule { #[turbo_tasks::value(shared)] struct UnsupportedSwcEcmaTransformPluginsIssue { - pub context: Vc, + pub file_path: Vc, } #[turbo_tasks::value_impl] @@ -78,7 +78,7 @@ impl Issue for UnsupportedSwcEcmaTransformPluginsIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - self.context + self.file_path } #[turbo_tasks::function] @@ -226,7 +226,7 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer { use turbopack_core::issue::IssueExt; UnsupportedSwcEcmaTransformPluginsIssue { - context: ctx.file_path, + file_path: ctx.file_path, } .cell() .emit(); diff --git a/crates/turbopack-ecmascript-runtime/src/asset_context.rs b/crates/turbopack-ecmascript-runtime/src/asset_context.rs index 9b43906468c7c..c5e90c6827bb6 100644 --- a/crates/turbopack-ecmascript-runtime/src/asset_context.rs +++ b/crates/turbopack-ecmascript-runtime/src/asset_context.rs @@ -16,12 +16,12 @@ pub fn get_runtime_asset_context(environment: Vc) -> Vc> = Vc::upcast(ModuleAssetContext::new( + let asset_context: Vc> = Vc::upcast(ModuleAssetContext::new( Vc::cell(Default::default()), compile_time_info, module_options_context, Vc::default(), )); - context + asset_context } diff --git a/crates/turbopack-json/src/lib.rs b/crates/turbopack-json/src/lib.rs index 3954abf8aaea7..8081229976857 100644 --- a/crates/turbopack-json/src/lib.rs +++ b/crates/turbopack-json/src/lib.rs @@ -68,11 +68,11 @@ impl ChunkableModule for JsonModuleAsset { #[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, )) @@ -84,11 +84,11 @@ impl EcmascriptChunkPlaceable for JsonModuleAsset { #[turbo_tasks::function] fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast(JsonChunkItem::cell(JsonChunkItem { module: self, - context, + chunking_context, })) } @@ -101,7 +101,7 @@ impl EcmascriptChunkPlaceable for JsonModuleAsset { #[turbo_tasks::value] struct JsonChunkItem { module: Vc, - context: Vc>, + chunking_context: Vc>, } #[turbo_tasks::value_impl] @@ -121,7 +121,7 @@ impl ChunkItem for JsonChunkItem { impl EcmascriptChunkItem for JsonChunkItem { #[turbo_tasks::function] fn chunking_context(&self) -> Vc> { - self.context + self.chunking_context } #[turbo_tasks::function] diff --git a/crates/turbopack-mdx/src/lib.rs b/crates/turbopack-mdx/src/lib.rs index e3bf70f2d574a..116b96e222539 100644 --- a/crates/turbopack-mdx/src/lib.rs +++ b/crates/turbopack-mdx/src/lib.rs @@ -75,7 +75,7 @@ impl ValueDefault for MdxTransformOptions { #[derive(Clone, Copy)] pub struct MdxModuleAsset { source: Vc>, - context: Vc>, + asset_context: Vc>, transforms: Vc, options: Vc, } @@ -132,11 +132,11 @@ async fn into_ecmascript_module_asset( ); Ok(EcmascriptModuleAsset::new( Vc::upcast(source), - this.context, + this.asset_context, Value::new(EcmascriptModuleAssetType::Typescript), this.transforms, Value::new(Default::default()), - this.context.compile_time_info(), + this.asset_context.compile_time_info(), )) } @@ -145,13 +145,13 @@ impl MdxModuleAsset { #[turbo_tasks::function] pub fn new( source: Vc>, - context: Vc>, + asset_context: Vc>, transforms: Vc, options: Vc, ) -> Vc { Self::cell(MdxModuleAsset { source, - context, + asset_context, transforms, options, }) @@ -191,11 +191,11 @@ impl ChunkableModule for MdxModuleAsset { #[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, )) @@ -207,11 +207,11 @@ impl EcmascriptChunkPlaceable for MdxModuleAsset { #[turbo_tasks::function] fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast(MdxChunkItem::cell(MdxChunkItem { module: self, - context, + chunking_context, })) } @@ -230,14 +230,14 @@ impl ResolveOrigin for MdxModuleAsset { #[turbo_tasks::function] fn asset_context(&self) -> Vc> { - self.context + self.asset_context } } #[turbo_tasks::value] struct MdxChunkItem { module: Vc, - context: Vc>, + chunking_context: Vc>, } #[turbo_tasks::value_impl] @@ -257,7 +257,7 @@ impl ChunkItem for MdxChunkItem { impl EcmascriptChunkItem for MdxChunkItem { #[turbo_tasks::function] fn chunking_context(&self) -> Vc> { - self.context + self.chunking_context } /// Once we have mdx contents, we should treat it as j|tsx components and @@ -266,7 +266,7 @@ impl EcmascriptChunkItem for MdxChunkItem { async fn content(&self) -> Result> { Ok(into_ecmascript_module_asset(&self.module) .await? - .as_chunk_item(self.context) + .as_chunk_item(self.chunking_context) .content()) } } diff --git a/crates/turbopack-node/src/evaluate.rs b/crates/turbopack-node/src/evaluate.rs index 2ef70a23c7b38..5658e0aedaeaa 100644 --- a/crates/turbopack-node/src/evaluate.rs +++ b/crates/turbopack-node/src/evaluate.rs @@ -98,13 +98,13 @@ pub async fn get_evaluate_pool( module_asset: Vc>, cwd: Vc, env: Vc>, - context: Vc>, + asset_context: Vc>, chunking_context: Vc>, runtime_entries: Option>, additional_invalidation: Vc, debug: bool, ) -> Result> { - let runtime_asset = context.process( + let runtime_asset = asset_context.process( Vc::upcast(FileSource::new(embed_file_path( "ipc/evaluate.ts".to_string(), ))), @@ -121,7 +121,7 @@ pub async fn get_evaluate_pool( Cow::Owned(format!("{file_name}.js")) }; let path = chunking_context.output_root().join(file_name.to_string()); - let entry_module = context.process( + let entry_module = asset_context.process( Vc::upcast(VirtualSource::new( runtime_asset.ident().path().join("evaluate.js".to_string()), AssetContent::file( @@ -149,7 +149,7 @@ pub async fn get_evaluate_pool( }; let runtime_entries = { - let globals_module = context.process( + let globals_module = asset_context.process( Vc::upcast(FileSource::new(embed_file_path("globals.ts".to_string()))), Value::new(ReferenceType::Internal(InnerAssets::empty())), ); @@ -233,7 +233,7 @@ pub fn evaluate( cwd: Vc, env: Vc>, context_ident_for_issue: Vc, - context: Vc>, + asset_context: Vc>, chunking_context: Vc>, runtime_entries: Option>, args: Vec>, @@ -262,7 +262,7 @@ pub fn evaluate( cwd, env, context_ident_for_issue, - context, + asset_context, chunking_context, runtime_entries, args, @@ -297,7 +297,7 @@ async fn compute_evaluate_stream( cwd: Vc, env: Vc>, context_ident_for_issue: Vc, - context: Vc>, + asset_context: Vc>, chunking_context: Vc>, runtime_entries: Option>, args: Vec>, @@ -316,7 +316,7 @@ async fn compute_evaluate_stream( module_asset, cwd, env, - context, + asset_context, chunking_context, runtime_entries, additional_invalidation, @@ -450,7 +450,7 @@ async fn pull_operation( } EvalJavaScriptIncomingMessage::EmittedError { error, severity } => { EvaluateEmittedErrorIssue { - context: context_ident_for_issue.path(), + file_path: context_ident_for_issue.path(), error, severity: severity.cell(), assets_for_source_mapping: pool.assets_for_source_mapping, @@ -597,7 +597,7 @@ async fn dir_dependency_shallow(glob: Vc) -> Result, + pub file_path: Vc, pub severity: Vc, pub error: StructuredError, pub assets_for_source_mapping: Vc, @@ -609,7 +609,7 @@ pub struct EvaluateEmittedErrorIssue { impl Issue for EvaluateEmittedErrorIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - self.context + self.file_path } #[turbo_tasks::function] diff --git a/crates/turbopack-node/src/render/issue.rs b/crates/turbopack-node/src/render/issue.rs index ae34c0e35ade1..c30853e99aa58 100644 --- a/crates/turbopack-node/src/render/issue.rs +++ b/crates/turbopack-node/src/render/issue.rs @@ -6,7 +6,7 @@ use turbopack_core::issue::Issue; #[turbo_tasks::value(shared)] #[derive(Copy, Clone)] pub struct RenderingIssue { - pub context: Vc, + pub file_path: Vc, pub message: Vc, pub status: Option, } @@ -25,7 +25,7 @@ impl Issue for RenderingIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - self.context + self.file_path } #[turbo_tasks::function] diff --git a/crates/turbopack-node/src/render/render_proxy.rs b/crates/turbopack-node/src/render/render_proxy.rs index fc438e933b207..19e6e05518472 100644 --- a/crates/turbopack-node/src/render/render_proxy.rs +++ b/crates/turbopack-node/src/render/render_proxy.rs @@ -118,7 +118,7 @@ async fn proxy_error( .clone_value(); RenderingIssue { - context: path, + file_path: path, message: Vc::cell(message), status: status.and_then(|status| status.code()), } diff --git a/crates/turbopack-node/src/render/render_static.rs b/crates/turbopack-node/src/render/render_static.rs index e6d3f27b99fb0..4b7e117306d61 100644 --- a/crates/turbopack-node/src/render/render_static.rs +++ b/crates/turbopack-node/src/render/render_static.rs @@ -166,7 +166,7 @@ async fn static_error( ); let issue = RenderingIssue { - context: path, + file_path: path, message: Vc::cell(error), status: status.and_then(|status| status.code()), }; diff --git a/crates/turbopack-node/src/transforms/postcss.rs b/crates/turbopack-node/src/transforms/postcss.rs index dc1e9ca860720..a9f4f6fc99a9e 100644 --- a/crates/turbopack-node/src/transforms/postcss.rs +++ b/crates/turbopack-node/src/transforms/postcss.rs @@ -138,7 +138,7 @@ struct ProcessPostCssResult { #[turbo_tasks::function] async fn extra_configs( - context: Vc>, + asset_context: Vc>, postcss_config_path: Vc, ) -> Result> { let config_paths = [postcss_config_path @@ -149,7 +149,7 @@ async fn extra_configs( .map(|path| async move { Ok( matches!(&*path.get_type().await?, FileSystemEntryType::File).then(|| { - any_content_changed_of_module(context.process( + any_content_changed_of_module(asset_context.process( Vc::upcast(FileSource::new(path)), Value::new(ReferenceType::Internal(InnerAssets::empty())), )) @@ -167,15 +167,15 @@ async fn extra_configs( #[turbo_tasks::function] fn postcss_executor( - context: Vc>, + asset_context: Vc>, postcss_config_path: Vc, ) -> Vc> { - let config_asset = context.process( + let config_asset = asset_context.process( Vc::upcast(FileSource::new(postcss_config_path)), Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)), ); - context.process( + asset_context.process( Vc::upcast(VirtualSource::new( postcss_config_path.join("transform.ts".to_string()), AssetContent::File(embed_file("transforms/postcss.ts".to_string())).cell(), @@ -218,12 +218,12 @@ impl PostCssTransformedAsset { .cell()); }; let content = content.content().to_str()?; - let context = this.evaluate_context; + let evaluate_context = this.evaluate_context; // This invalidates the transform when the config changes. - let extra_configs_changed = extra_configs(context, config_path); + let extra_configs_changed = extra_configs(evaluate_context, config_path); - let postcss_executor = postcss_executor(context, config_path); + let postcss_executor = postcss_executor(evaluate_context, config_path); let css_fs_path = this.source.ident().path().await?; let css_path = css_fs_path.path.as_str(); @@ -232,7 +232,7 @@ impl PostCssTransformedAsset { project_path, env, this.source.ident(), - context, + evaluate_context, chunking_context, None, vec![Vc::cell(content.into()), Vc::cell(css_path.into())], diff --git a/crates/turbopack-node/src/transforms/webpack.rs b/crates/turbopack-node/src/transforms/webpack.rs index b32a186765962..252b6eaa543f0 100644 --- a/crates/turbopack-node/src/transforms/webpack.rs +++ b/crates/turbopack-node/src/transforms/webpack.rs @@ -119,8 +119,8 @@ struct ProcessWebpackLoadersResult { } #[turbo_tasks::function] -fn webpack_loaders_executor(context: Vc>) -> Vc> { - context.process( +fn webpack_loaders_executor(evaluate_context: Vc>) -> Vc> { + evaluate_context.process( Vc::upcast(FileSource::new(embed_file_path( "transforms/webpack-loaders.ts".to_string(), ))), @@ -152,9 +152,9 @@ impl WebpackLoadersProcessedAsset { .cell()); }; let content = content.content().to_str()?; - let context = transform.evaluate_context; + let evaluate_context = transform.evaluate_context; - let webpack_loaders_executor = webpack_loaders_executor(context); + let webpack_loaders_executor = webpack_loaders_executor(evaluate_context); let resource_fs_path = this.source.ident().path().await?; let resource_path = resource_fs_path.path.as_str(); let loaders = transform.loaders.await?; @@ -163,7 +163,7 @@ impl WebpackLoadersProcessedAsset { project_path, env, this.source.ident(), - context, + evaluate_context, chunking_context, None, vec![ diff --git a/crates/turbopack-static/src/lib.rs b/crates/turbopack-static/src/lib.rs index 885ed40b92253..aab53afd87c6b 100644 --- a/crates/turbopack-static/src/lib.rs +++ b/crates/turbopack-static/src/lib.rs @@ -47,23 +47,26 @@ fn modifier() -> Vc { #[derive(Clone)] pub struct StaticModuleAsset { pub source: Vc>, - pub context: Vc>, + pub asset_context: Vc>, } #[turbo_tasks::value_impl] impl StaticModuleAsset { #[turbo_tasks::function] - pub fn new(source: Vc>, context: Vc>) -> Vc { - Self::cell(StaticModuleAsset { source, context }) + pub fn new(source: Vc>, asset_context: Vc>) -> Vc { + Self::cell(StaticModuleAsset { + source, + asset_context, + }) } #[turbo_tasks::function] async fn static_asset( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Result> { Ok(StaticAsset::cell(StaticAsset { - context, + chunking_context, source: self.await?.source, })) } @@ -90,11 +93,11 @@ impl ChunkableModule for StaticModuleAsset { #[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, )) @@ -106,12 +109,12 @@ impl EcmascriptChunkPlaceable for StaticModuleAsset { #[turbo_tasks::function] fn as_chunk_item( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast(ModuleChunkItem::cell(ModuleChunkItem { module: self, - context, - static_asset: self.static_asset(Vc::upcast(context)), + chunking_context, + static_asset: self.static_asset(Vc::upcast(chunking_context)), })) } @@ -126,17 +129,17 @@ impl CssEmbeddable for StaticModuleAsset { #[turbo_tasks::function] fn as_css_embed( self: Vc, - context: Vc>, + chunking_context: Vc>, ) -> Vc> { Vc::upcast(StaticCssEmbed::cell(StaticCssEmbed { - static_asset: self.static_asset(context), + static_asset: self.static_asset(chunking_context), })) } } #[turbo_tasks::value] struct StaticAsset { - context: Vc>, + chunking_context: Vc>, source: Vc>, } @@ -156,7 +159,7 @@ impl OutputAsset for StaticAsset { }; let content_hash_b16 = turbo_tasks_hash::encode_hex(content_hash); let asset_path = self - .context + .chunking_context .asset_path(content_hash_b16, self.source.ident()); Ok(AssetIdent::from_path(asset_path)) } @@ -173,7 +176,7 @@ impl Asset for StaticAsset { #[turbo_tasks::value] struct ModuleChunkItem { module: Vc, - context: Vc>, + chunking_context: Vc>, static_asset: Vc, } @@ -200,7 +203,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] diff --git a/crates/turbopack-tests/tests/execution.rs b/crates/turbopack-tests/tests/execution.rs index 699a78f297d1f..7eb03b3d7ae52 100644 --- a/crates/turbopack-tests/tests/execution.rs +++ b/crates/turbopack-tests/tests/execution.rs @@ -203,7 +203,7 @@ async fn run_test(resource: String) -> Result> { ) .cell(); - let context: Vc> = Vc::upcast(ModuleAssetContext::new( + let asset_context: Vc> = Vc::upcast(ModuleAssetContext::new( Vc::cell(HashMap::new()), compile_time_info, ModuleOptionsContext { @@ -246,7 +246,7 @@ async fn run_test(resource: String) -> Result> { ) .build(); - let jest_entry_asset = process_path_to_asset(jest_entry_path, context); + let jest_entry_asset = process_path_to_asset(jest_entry_path, asset_context); let jest_runtime_asset = FileSource::new(jest_runtime_path); let test_asset = FileSource::new(test_path); @@ -255,11 +255,11 @@ async fn run_test(resource: String) -> Result> { path, Vc::upcast(CommandLineProcessEnv::new()), test_asset.ident(), - context, + asset_context, Vc::upcast(chunking_context), Some(EvaluatableAssets::many(vec![ - jest_runtime_asset.to_evaluatable(context), - test_asset.to_evaluatable(context), + jest_runtime_asset.to_evaluatable(asset_context), + test_asset.to_evaluatable(asset_context), ])), vec![], Completion::immutable(), @@ -324,9 +324,9 @@ async fn snapshot_issues(run_result: Vc) -> Result> { #[turbo_tasks::function] fn process_path_to_asset( path: Vc, - context: Vc>, + asset_context: Vc>, ) -> Vc> { - context.process( + asset_context.process( Vc::upcast(FileSource::new(path)), Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)), ) diff --git a/crates/turbopack-tests/tests/snapshot.rs b/crates/turbopack-tests/tests/snapshot.rs index 7ee893cbf6a58..aa449bb7059ab 100644 --- a/crates/turbopack-tests/tests/snapshot.rs +++ b/crates/turbopack-tests/tests/snapshot.rs @@ -239,7 +239,7 @@ async fn run_test(resource: String) -> Result> { output_transforms: vec![], }, )); - let context: Vc> = Vc::upcast(ModuleAssetContext::new( + let asset_context: Vc> = Vc::upcast(ModuleAssetContext::new( Vc::cell(HashMap::new()), compile_time_info, ModuleOptionsContext { @@ -278,9 +278,9 @@ async fn run_test(resource: String) -> Result> { .cell(), )); - let runtime_entries = maybe_load_env(context, project_path) + let runtime_entries = maybe_load_env(asset_context, project_path) .await? - .map(|asset| EvaluatableAssets::one(asset.to_evaluatable(context))); + .map(|asset| EvaluatableAssets::one(asset.to_evaluatable(asset_context))); let chunk_root_path = path.join("output".to_string()); let static_root_path = path.join("static".to_string()); @@ -311,7 +311,7 @@ async fn run_test(resource: String) -> Result> { .copied() .collect(); - let entry_module = context.process( + let entry_module = asset_context.process( Vc::upcast(FileSource::new(entry_asset)), Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)), ); diff --git a/crates/turbopack/benches/node_file_trace.rs b/crates/turbopack/benches/node_file_trace.rs index 2c9a83785f781..a66c6682fc8a9 100644 --- a/crates/turbopack/benches/node_file_trace.rs +++ b/crates/turbopack/benches/node_file_trace.rs @@ -83,7 +83,7 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) { ExecutionEnvironment::NodeJsLambda(NodeJsEnvironment::default().into()), ))) .cell(); - let context = ModuleAssetContext::new( + let module_asset_context = ModuleAssetContext::new( Vc::cell(HashMap::new()), compile_time_info, ModuleOptionsContext { @@ -97,8 +97,8 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) { } .cell(), ); - let module = - context.process(Vc::upcast(source), Value::new(ReferenceType::Undefined)); + let module = module_asset_context + .process(Vc::upcast(source), Value::new(ReferenceType::Undefined)); let rebased = RebasedAsset::new(Vc::upcast(module), input_dir, output_dir); emit_with_completion(Vc::upcast(rebased), output_dir).await?; diff --git a/crates/turbopack/examples/turbopack.rs b/crates/turbopack/examples/turbopack.rs index 152ab13995d1b..64d75a2b64b07 100644 --- a/crates/turbopack/examples/turbopack.rs +++ b/crates/turbopack/examples/turbopack.rs @@ -50,7 +50,7 @@ async fn main() -> Result<()> { let entry = fs.root().join("demo/index.js".to_string()); let source = FileSource::new(entry); - let context = turbopack::ModuleAssetContext::new( + let module_asset_context = turbopack::ModuleAssetContext::new( Vc::cell(HashMap::new()), CompileTimeInfo::new(Environment::new(Value::new( ExecutionEnvironment::NodeJsLambda(NodeJsEnvironment::default().into()), @@ -65,7 +65,7 @@ async fn main() -> Result<()> { } .cell(), ); - let module = context.process( + let module = module_asset_context.process( Vc::upcast(source), Value::new(turbopack_core::reference_type::ReferenceType::Undefined), ); diff --git a/crates/turbopack/src/condition.rs b/crates/turbopack/src/condition.rs index f9cc71d7e1f33..87d6b55840444 100644 --- a/crates/turbopack/src/condition.rs +++ b/crates/turbopack/src/condition.rs @@ -33,14 +33,14 @@ impl ContextCondition { #[async_recursion] /// Returns true if the condition matches the context. - pub async fn matches(&self, context: &FileSystemPath) -> Result { + pub async fn matches(&self, path: &FileSystemPath) -> Result { match self { ContextCondition::All(conditions) => { // False positive. #[allow(clippy::manual_try_fold)] stream::iter(conditions) .fold(Ok(true), |acc, c| async move { - Ok(acc? && c.matches(context).await?) + Ok(acc? && c.matches(path).await?) }) .await } @@ -49,16 +49,16 @@ impl ContextCondition { #[allow(clippy::manual_try_fold)] stream::iter(conditions) .fold(Ok(true), |acc, c| async move { - Ok(acc? || c.matches(context).await?) + Ok(acc? || c.matches(path).await?) }) .await } - ContextCondition::Not(condition) => condition.matches(context).await.map(|b| !b), - ContextCondition::InPath(path) => Ok(context.is_inside_ref(&*path.await?)), - ContextCondition::InDirectory(dir) => Ok(context.path.starts_with(&format!("{dir}/")) - || context.path.contains(&format!("/{dir}/")) - || context.path.ends_with(&format!("/{dir}")) - || context.path == *dir), + ContextCondition::Not(condition) => condition.matches(path).await.map(|b| !b), + ContextCondition::InPath(other_path) => Ok(path.is_inside_ref(&*other_path.await?)), + ContextCondition::InDirectory(dir) => Ok(path.path.starts_with(&format!("{dir}/")) + || path.path.contains(&format!("/{dir}/")) + || path.path.ends_with(&format!("/{dir}")) + || path.path == *dir), } } } diff --git a/crates/turbopack/src/lib.rs b/crates/turbopack/src/lib.rs index f8ec6d25c7b9d..daeb43c15f387 100644 --- a/crates/turbopack/src/lib.rs +++ b/crates/turbopack/src/lib.rs @@ -96,7 +96,7 @@ impl Issue for ModuleIssue { #[turbo_tasks::function] async fn apply_module_type( source: Vc>, - context: Vc, + module_asset_context: Vc, module_type: Vc, part: Option>, inner_assets: Option>, @@ -122,16 +122,16 @@ async fn apply_module_type( let context_for_module = match module_type { ModuleType::TypescriptWithTypes { .. } | ModuleType::TypescriptDeclaration { .. } => { - context.with_types_resolving_enabled() + module_asset_context.with_types_resolving_enabled() } - _ => context, + _ => module_asset_context, }; let mut builder = EcmascriptModuleAsset::builder( source, Vc::upcast(context_for_module), *transforms, *options, - context.compile_time_info(), + module_asset_context.compile_time_info(), ); match module_type { ModuleType::Ecmascript { .. } => { @@ -163,29 +163,38 @@ async fn apply_module_type( } ModuleType::Json => Vc::upcast(JsonModuleAsset::new(source)), ModuleType::Raw => Vc::upcast(RawModule::new(source)), - ModuleType::CssGlobal => Vc::upcast(GlobalCssAsset::new(source, Vc::upcast(context))), - ModuleType::CssModule => Vc::upcast(ModuleCssAsset::new(source, Vc::upcast(context))), + ModuleType::CssGlobal => Vc::upcast(GlobalCssAsset::new( + source, + Vc::upcast(module_asset_context), + )), + ModuleType::CssModule => Vc::upcast(ModuleCssAsset::new( + source, + Vc::upcast(module_asset_context), + )), ModuleType::Css { ty, transforms } => Vc::upcast(CssModuleAsset::new( source, - Vc::upcast(context), + Vc::upcast(module_asset_context), *transforms, *ty, )), - ModuleType::Static => Vc::upcast(StaticModuleAsset::new(source, Vc::upcast(context))), + ModuleType::Static => Vc::upcast(StaticModuleAsset::new( + source, + Vc::upcast(module_asset_context), + )), ModuleType::Mdx { transforms, options, } => Vc::upcast(MdxModuleAsset::new( source, - Vc::upcast(context), + Vc::upcast(module_asset_context), *transforms, *options, )), ModuleType::WebAssembly { source_ty } => Vc::upcast(WebAssemblyModuleAsset::new( WebAssemblySource::new(source, *source_ty), - Vc::upcast(context), + Vc::upcast(module_asset_context), )), - ModuleType::Custom(custom) => custom.create_module(source, context, part), + ModuleType::Custom(custom) => custom.create_module(source, module_asset_context, part), }) } @@ -241,8 +250,10 @@ impl ModuleAssetContext { #[turbo_tasks::function] pub async fn is_types_resolving_enabled(self: Vc) -> Result> { - let context = self.await?.resolve_options_context.await?; - Ok(Vc::cell(context.enable_types && context.enable_typescript)) + let resolve_options_context = self.await?.resolve_options_context.await?; + Ok(Vc::cell( + resolve_options_context.enable_types && resolve_options_context.enable_typescript, + )) } #[turbo_tasks::function] @@ -276,13 +287,16 @@ impl ModuleAssetContext { #[turbo_tasks::function] async fn process_default( - context: Vc, + module_asset_context: Vc, source: Vc>, reference_type: Value, processed_rules: Vec, ) -> Result>> { let ident = source.ident().resolve().await?; - let options = ModuleOptions::new(ident.path().parent(), context.module_options_context()); + let options = ModuleOptions::new( + ident.path().parent(), + module_asset_context.module_options_context(), + ); let reference_type = reference_type.into_value(); let part: Option> = match &reference_type { @@ -314,7 +328,7 @@ async fn process_default( let mut processed_rules = processed_rules.clone(); processed_rules.push(i); return Ok(process_default( - context, + module_asset_context, current_source, Value::new(reference_type), processed_rules, @@ -386,7 +400,7 @@ async fn process_default( Ok(apply_module_type( current_source, - context, + module_asset_context, module_type, part, inner_assets, @@ -407,7 +421,7 @@ impl AssetContext for ModuleAssetContext { _reference_type: Value, ) -> Result> { let this = self.await?; - let context = if let Some(transition) = this.transition { + let module_asset_context = if let Some(transition) = this.transition { transition.process_context(self) } else { self @@ -415,7 +429,7 @@ impl AssetContext for ModuleAssetContext { // TODO move `apply_commonjs/esm_resolve_options` etc. to here Ok(resolve_options( origin_path.parent().resolve().await?, - context.await?.resolve_options_context, + module_asset_context.await?.resolve_options_context, )) } diff --git a/crates/turbopack/src/module_options/custom_module_type.rs b/crates/turbopack/src/module_options/custom_module_type.rs index 8d8d7190a31bc..91c9cf987b484 100644 --- a/crates/turbopack/src/module_options/custom_module_type.rs +++ b/crates/turbopack/src/module_options/custom_module_type.rs @@ -8,7 +8,7 @@ pub trait CustomModuleType { fn create_module( self: Vc, source: Vc>, - context: Vc, + module_asset_context: Vc, part: Option>, ) -> Vc>; } diff --git a/crates/turbopack/src/module_options/mod.rs b/crates/turbopack/src/module_options/mod.rs index 84b06b27c339a..9bfa15f0fb43a 100644 --- a/crates/turbopack/src/module_options/mod.rs +++ b/crates/turbopack/src/module_options/mod.rs @@ -58,7 +58,7 @@ impl ModuleOptions { #[turbo_tasks::function] pub async fn new( path: Vc, - context: Vc, + module_options_context: Vc, ) -> Result> { let ModuleOptionsContext { enable_jsx, @@ -77,7 +77,7 @@ impl ModuleOptions { execution_context, ref rules, .. - } = *context.await?; + } = *module_options_context.await?; if !rules.is_empty() { let path_value = path.await?; diff --git a/crates/turbopack/src/resolve.rs b/crates/turbopack/src/resolve.rs index 970ccdf40dd3e..b8e9883f0a149 100644 --- a/crates/turbopack/src/resolve.rs +++ b/crates/turbopack/src/resolve.rs @@ -71,17 +71,17 @@ const NODE_EXTERNALS: [&str; 51] = [ #[turbo_tasks::function] async fn base_resolve_options( - context: Vc, + resolve_path: Vc, options_context: Vc, ) -> Result> { - let parent = context.parent().resolve().await?; - if parent != context { + let parent = resolve_path.parent().resolve().await?; + if parent != resolve_path { return Ok(base_resolve_options(parent, options_context)); } - let context_value = context.await?; + let resolve_path_value = resolve_path.await?; let opt = options_context.await?; let emulating = opt.emulate_environment; - let root = context_value.fs.root(); + let root = resolve_path_value.fs.root(); let mut direct_mappings = AliasMap::new(); let node_externals = if let Some(environment) = emulating { environment.node_externals().await?.clone_value() @@ -232,23 +232,23 @@ async fn base_resolve_options( #[turbo_tasks::function] pub async fn resolve_options( - context: Vc, + resolve_path: Vc, options_context: Vc, ) -> Result> { let options_context_value = options_context.await?; if !options_context_value.rules.is_empty() { - let context_value = &*context.await?; + let context_value = &*resolve_path.await?; for (condition, new_options_context) in options_context_value.rules.iter() { if condition.matches(context_value).await? { - return Ok(resolve_options(context, *new_options_context)); + return Ok(resolve_options(resolve_path, *new_options_context)); } } } - let resolve_options = base_resolve_options(context, options_context); + let resolve_options = base_resolve_options(resolve_path, options_context); let resolve_options = if options_context_value.enable_typescript { - let tsconfig = find_context_file(context, tsconfig()).await?; + let tsconfig = find_context_file(resolve_path, tsconfig()).await?; match *tsconfig { FindContextFileResult::Found(path, _) => { apply_tsconfig_resolve_options(resolve_options, tsconfig_resolve_options(path)) diff --git a/crates/turbopack/src/transition/mod.rs b/crates/turbopack/src/transition/mod.rs index 33207c7236b5d..20d0249f1872d 100644 --- a/crates/turbopack/src/transition/mod.rs +++ b/crates/turbopack/src/transition/mod.rs @@ -34,16 +34,16 @@ pub trait Transition { /// Apply modifications/wrapping to the module options context fn process_module_options_context( self: Vc, - context: Vc, + module_options_context: Vc, ) -> Vc { - context + module_options_context } /// Apply modifications/wrapping to the resolve options context fn process_resolve_options_context( self: Vc, - context: Vc, + resolve_options_context: Vc, ) -> Vc { - context + resolve_options_context } /// Apply modifications/wrapping to the final asset fn process_module( @@ -56,33 +56,34 @@ pub trait Transition { /// Apply modifications to the context async fn process_context( self: Vc, - context: Vc, + module_asset_context: Vc, ) -> Result> { - let context = context.await?; - let compile_time_info = self.process_compile_time_info(context.compile_time_info); + let module_asset_context = module_asset_context.await?; + let compile_time_info = + self.process_compile_time_info(module_asset_context.compile_time_info); let module_options_context = - self.process_module_options_context(context.module_options_context); + self.process_module_options_context(module_asset_context.module_options_context); let resolve_options_context = - self.process_resolve_options_context(context.resolve_options_context); - let context = ModuleAssetContext::new( - context.transitions, + self.process_resolve_options_context(module_asset_context.resolve_options_context); + let module_asset_context = ModuleAssetContext::new( + module_asset_context.transitions, compile_time_info, module_options_context, resolve_options_context, ); - Ok(context) + Ok(module_asset_context) } /// Apply modification on the processing of the asset fn process( self: Vc, asset: Vc>, - context: Vc, + module_asset_context: Vc, reference_type: Value, ) -> Vc> { let asset = self.process_source(asset); - let context = self.process_context(context); - let m = context.process_default(asset, reference_type); - self.process_module(m, context) + let module_asset_context = self.process_context(module_asset_context); + let m = module_asset_context.process_default(asset, reference_type); + self.process_module(m, module_asset_context) } } diff --git a/crates/turbopack/src/unsupported_sass.rs b/crates/turbopack/src/unsupported_sass.rs index 5a95768bf01ca..acf21e13a1a9f 100644 --- a/crates/turbopack/src/unsupported_sass.rs +++ b/crates/turbopack/src/unsupported_sass.rs @@ -37,14 +37,17 @@ impl ResolvePlugin for UnsupportedSassResolvePlugin { async fn after_resolve( &self, fs_path: Vc, - context: Vc, + lookup_path: Vc, request: Vc, ) -> Result> { let extension = fs_path.extension().await?; if ["sass", "scss"].iter().any(|ext| ext == &*extension) { - UnsupportedSassModuleIssue { context, request } - .cell() - .emit(); + UnsupportedSassModuleIssue { + file_path: lookup_path, + request, + } + .cell() + .emit(); } Ok(ResolveResultOption::none()) @@ -53,7 +56,7 @@ impl ResolvePlugin for UnsupportedSassResolvePlugin { #[turbo_tasks::value(shared)] struct UnsupportedSassModuleIssue { - context: Vc, + file_path: Vc, request: Vc, } @@ -79,7 +82,7 @@ impl Issue for UnsupportedSassModuleIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - self.context + self.file_path } #[turbo_tasks::function] diff --git a/crates/turbopack/tests/helpers/mod.rs b/crates/turbopack/tests/helpers/mod.rs index f050e9c86a94d..92a468ed57791 100644 --- a/crates/turbopack/tests/helpers/mod.rs +++ b/crates/turbopack/tests/helpers/mod.rs @@ -5,29 +5,29 @@ use difference::{Changeset, Difference}; pub fn print_changeset(changeset: &Changeset) -> String { assert!(changeset.split == "\n"); let mut result = String::from("--- DIFF ---\n- Expected\n+ Actual\n------------\n"); - const CONTEXT_LINES: usize = 3; - let mut context = VecDeque::with_capacity(CONTEXT_LINES); - let mut need_context = CONTEXT_LINES; + const CONTEXT_LINES_COUNT: usize = 3; + let mut context_lines = VecDeque::with_capacity(CONTEXT_LINES_COUNT); + let mut context_lines_needed = CONTEXT_LINES_COUNT; let mut has_spacing = false; for diff in changeset.diffs.iter() { match diff { Difference::Same(content) => { let lines = content .rsplit('\n') - .take(need_context) + .take(context_lines_needed) .collect::>() .into_iter() .rev(); for line in lines { - if need_context > 0 { + if context_lines_needed > 0 { writeln!(result, " {line}").unwrap(); - need_context -= 1; + context_lines_needed -= 1; } else { - if context.len() == CONTEXT_LINES { + if context_lines.len() == CONTEXT_LINES_COUNT { has_spacing = true; - context.pop_front(); + context_lines.pop_front(); } - context.push_back(line); + context_lines.push_back(line); } } } @@ -36,22 +36,22 @@ pub fn print_changeset(changeset: &Changeset) -> String { writeln!(result, "...").unwrap(); has_spacing = false; } - while let Some(line) = context.pop_front() { + while let Some(line) = context_lines.pop_front() { writeln!(result, " {line}").unwrap(); } writeln!(result, "+ {line}").unwrap(); - need_context = CONTEXT_LINES; + context_lines_needed = CONTEXT_LINES_COUNT; } Difference::Rem(line) => { if has_spacing { writeln!(result, "...").unwrap(); has_spacing = false; } - while let Some(line) = context.pop_front() { + while let Some(line) = context_lines.pop_front() { writeln!(result, " {line}").unwrap(); } writeln!(result, "- {line}").unwrap(); - need_context = CONTEXT_LINES; + context_lines_needed = CONTEXT_LINES_COUNT; } } } diff --git a/crates/turbopack/tests/node-file-trace.rs b/crates/turbopack/tests/node-file-trace.rs index 78eb09415aa7f..3aafb294b6843 100644 --- a/crates/turbopack/tests/node-file-trace.rs +++ b/crates/turbopack/tests/node-file-trace.rs @@ -416,7 +416,7 @@ fn node_file_trace( let output_dir = output_fs.root(); let source = FileSource::new(input); - let context = ModuleAssetContext::new( + let module_asset_context = ModuleAssetContext::new( Vc::cell(HashMap::new()), // TODO It's easy to make a mistake here as this should match the config in the // binary. TODO These test cases should move into the @@ -438,8 +438,8 @@ fn node_file_trace( } .cell(), ); - let module = - context.process(Vc::upcast(source), Value::new(ReferenceType::Undefined)); + let module = module_asset_context + .process(Vc::upcast(source), Value::new(ReferenceType::Undefined)); let rebased = RebasedAsset::new(Vc::upcast(module), input_dir, output_dir); #[cfg(not(feature = "bench_against_node_nft"))] diff --git a/crates/turborepo-cache/src/cache_archive/restore.rs b/crates/turborepo-cache/src/cache_archive/restore.rs index 0ec1fa2727388..531e31ec688ca 100644 --- a/crates/turborepo-cache/src/cache_archive/restore.rs +++ b/crates/turborepo-cache/src/cache_archive/restore.rs @@ -45,17 +45,17 @@ impl<'a> CacheReader<'a> { } pub fn get_sha(mut self) -> Result, CacheError> { - let mut context = Sha512::new(); + let mut hasher = Sha512::new(); let mut buffer = [0; 8192]; loop { let n = self.reader.read(&mut buffer)?; if n == 0 { break; } - context.update(&buffer[..n]); + hasher.update(&buffer[..n]); } - Ok(context.finalize().to_vec()) + Ok(hasher.finalize().to_vec()) } pub fn restore( diff --git a/crates/turborepo-scm/src/lib.rs b/crates/turborepo-scm/src/lib.rs index ab03fefb6dfab..c43b45da44f6a 100644 --- a/crates/turborepo-scm/src/lib.rs +++ b/crates/turborepo-scm/src/lib.rs @@ -66,8 +66,8 @@ impl Error { Error::Git(s.into(), Backtrace::capture()) } - pub(crate) fn git2_error_context(error: git2::Error, context: String) -> Self { - Error::Git2(error, context, Backtrace::capture()) + pub(crate) fn git2_error_context(error: git2::Error, error_context: String) -> Self { + Error::Git2(error, error_context, Backtrace::capture()) } }