Commit ae93bed8 authored by Matt Mastracci's avatar Matt Mastracci

Remove chunkable module

parent ec5056c4
......@@ -9803,6 +9803,7 @@ dependencies = [
"turbo-tasks-fs",
"turbo-tasks-hash",
"turbopack-core",
"turbopack-css",
"turbopack-ecmascript",
"turbopack-ecmascript-runtime",
"turbopack-resolve",
......@@ -10221,6 +10222,7 @@ dependencies = [
"turbo-tasks-fs",
"turbo-tasks-hash",
"turbopack-core",
"turbopack-css",
"turbopack-ecmascript",
"turbopack-ecmascript-runtime",
"urlencoding",
......
......@@ -30,7 +30,7 @@ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs,
};
use turbopack_core::{
chunk::{ChunkableModule, ChunkingContext, availability_info::AvailabilityInfo},
chunk::{ChunkingContext, availability_info::AvailabilityInfo},
module::Module,
module_graph::{ModuleGraph, ModuleGraphLayer},
output::{OutputAssetsReference, OutputAssetsWithReferenced},
......@@ -55,7 +55,7 @@ pub(crate) async fn collect_next_dynamic_chunks(
let dynamic_import_chunks = dynamic_import_entries
.iter()
.map(|(dynamic_entry, parent_client_reference)| async move {
let module = ResolvedVc::upcast::<Box<dyn ChunkableModule>>(*dynamic_entry);
let module = ResolvedVc::upcast::<Box<dyn Module>>(*dynamic_entry);
// This is the availability info for the parent chunk group, i.e. the client reference
// containing the next/dynamic imports
......
......@@ -658,18 +658,28 @@ impl PageEndpoint {
Vc::upcast(this.pages_project.client_module_context()),
self.source(),
this.pathname.clone(),
);
)
.to_resolved()
.await?;
let is_chunkable = this
.pages_project
.project()
.client_chunking_context()
.chunking_configs()
.await?
.is_chunkable(page_loader)
.await;
if matches!(
*this.pages_project.project().next_mode().await?,
NextMode::Development
) && let Some(chunkable) = ResolvedVc::try_downcast(page_loader.to_resolved().await?)
) && is_chunkable
{
return Ok(Vc::upcast(HmrEntryModule::new(
AssetIdent::from_path(this.page.await?.base_path.clone()),
*chunkable,
*page_loader,
)));
}
Ok(page_loader)
Ok(*page_loader)
}
#[turbo_tasks::function]
......
......@@ -26,7 +26,7 @@ use turbo_tasks::{
use turbo_tasks_fs::{self, File, FileContent, FileSystemPath, rope::RopeBuilder};
use turbopack_core::{
asset::AssetContent,
chunk::{ChunkItem, ChunkingContext, ChunkingContextExt, EvaluatableAsset, ModuleId},
chunk::{ChunkItem, ChunkItemExt, ChunkingContext, EvaluatableAsset, ModuleId},
context::AssetContext,
file_source::FileSource,
ident::AssetIdent,
......@@ -76,7 +76,7 @@ pub(crate) async fn create_server_actions_manifest(
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(loader.to_resolved().await?)
.context("loader module must be evaluatable")?;
let chunk_item = chunking_context.chunk_item(Vc::upcast(loader), module_graph);
let chunk_item = ChunkItem::new(Vc::upcast(loader), module_graph, chunking_context);
let manifest = build_manifest(
node_root,
page_name,
......
......@@ -7,8 +7,8 @@ use turbo_tasks_fs::{FileSystem, VirtualFileSystem, rope::RopeBuilder};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{
AsyncModuleInfo, ChunkableModule, ChunkingContext, ChunkingContextExt, ChunkingType,
ChunkingTypeOption, EvaluatableAsset,
AsyncModuleInfo, ChunkItem, ChunkingContext, ChunkingType, ChunkingTypeOption,
EvaluatableAsset,
},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
......@@ -41,16 +41,13 @@ async fn hmr_entry_point_base_ident() -> Result<Vc<AssetIdent>> {
#[turbo_tasks::value(shared)]
pub struct HmrEntryModule {
pub ident: ResolvedVc<AssetIdent>,
pub module: ResolvedVc<Box<dyn ChunkableModule>>,
pub module: ResolvedVc<Box<dyn Module>>,
}
#[turbo_tasks::value_impl]
impl HmrEntryModule {
#[turbo_tasks::function]
pub fn new(
ident: ResolvedVc<AssetIdent>,
module: ResolvedVc<Box<dyn ChunkableModule>>,
) -> Vc<Self> {
pub fn new(ident: ResolvedVc<AssetIdent>, module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
Self { ident, module }.cell()
}
}
......@@ -70,7 +67,7 @@ impl Module for HmrEntryModule {
#[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast(
HmrEntryModuleReference::new(Vc::upcast(*self.module))
HmrEntryModuleReference::new(*self.module)
.to_resolved()
.await?,
)]))
......@@ -81,8 +78,6 @@ impl Module for HmrEntryModule {
}
}
turbopack_core::chunk_item!(HmrEntryModule, ecmascript);
#[turbo_tasks::value_impl]
impl Asset for HmrEntryModule {
#[turbo_tasks::function]
......@@ -108,7 +103,7 @@ impl EcmascriptChunkPlaceable for HmrEntryModule {
) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = self.await?;
let module = this.module;
let chunk_item = chunking_context.chunk_item(Vc::upcast(*module), module_graph);
let chunk_item = ChunkItem::new(*module, module_graph, chunking_context);
let id = chunking_context
.chunk_item_id_strategy()
.await?
......
use std::{io::Write, iter::once};
use anyhow::{Context, Result, bail};
use anyhow::{Result, bail};
use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{IntoTraitRef, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent};
use turbopack_core::{
asset::AssetContent,
chunk::{
AsyncModuleInfo, ChunkGroupType, ChunkItem, ChunkType, ChunkableModule, ChunkedItem,
ChunkingContext, ChunkingContextExt, ChunkingType, ChunkingTypeOption,
},
chunk::{AsyncModuleInfo, ChunkGroupType, ChunkingContext, ChunkingType, ChunkingTypeOption},
code_builder::CodeBuilder,
context::AssetContext,
ident::AssetIdent,
module::{Module, ModuleSideEffects},
module_graph::{ModuleGraph, binding_usage_info::ModuleExportUsageInfo},
output::OutputAssetsReference,
reference::{ModuleReference, ModuleReferences},
reference_type::ReferenceType,
resolve::ModuleResolveResult,
......@@ -24,10 +20,7 @@ use turbopack_core::{
virtual_source::VirtualSource,
};
use turbopack_ecmascript::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports,
},
chunk::{EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports},
runtime_functions::TURBOPACK_EXPORT_NAMESPACE,
utils::StringifyJs,
};
......@@ -249,31 +242,6 @@ impl Module for EcmascriptClientReferenceModule {
}
}
#[turbo_tasks::value_impl]
impl ChunkableModule for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
async fn as_chunk_item(
self: ResolvedVc<Self>,
module_graph: Vc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Result<Vc<ChunkItem>> {
let item = chunking_context.chunk_item(Vc::upcast(self.proxy_module()), module_graph);
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *item.await?;
let ecmascript_item = ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(inner)
.context("EcmascriptModuleAsset must implement EcmascriptChunkItem")?;
let chunked: Vc<Box<dyn ChunkedItem>> = Vc::upcast(
EcmascriptClientReferenceProxyChunkItem {
inner_module: self,
inner_chunk_item: ecmascript_item,
chunking_context,
}
.cell(),
);
Ok(ChunkItem::from_trait(chunked))
}
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
......@@ -284,67 +252,17 @@ impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
fn chunk_item_content(
self: Vc<Self>,
_chunking_context: Vc<Box<dyn ChunkingContext>>,
_module_graph: Vc<ModuleGraph>,
_async_module_info: Option<Vc<AsyncModuleInfo>>,
_estimated: bool,
) -> Result<Vc<EcmascriptChunkItemContent>> {
bail!("Attempted to get chunk_item_content for EcmascriptClientReferenceModule")
}
}
/// This wrapper only exists to overwrite the `asset_ident` method of the
/// wrapped [`Vc<Box<dyn EcmascriptChunkItem>>`]. Otherwise, the asset ident of
/// the chunk item would not be the same as the asset ident of the
/// [`Vc<EcmascriptClientReferenceModule>`].
#[turbo_tasks::value]
struct EcmascriptClientReferenceProxyChunkItem {
inner_module: ResolvedVc<EcmascriptClientReferenceModule>,
inner_chunk_item: ResolvedVc<Box<dyn EcmascriptChunkItem>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptClientReferenceProxyChunkItem {}
#[turbo_tasks::value_impl]
impl ChunkedItem for EcmascriptClientReferenceProxyChunkItem {
#[turbo_tasks::function]
fn asset_ident(&self) -> Vc<AssetIdent> {
self.inner_module.ident()
}
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function]
fn ty(&self) -> Vc<Box<dyn ChunkType>> {
Vc::upcast(Vc::<EcmascriptChunkType>::default())
}
#[turbo_tasks::function]
fn module(&self) -> Vc<Box<dyn Module>> {
Vc::upcast(*self.inner_module)
}
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem {
#[turbo_tasks::function]
fn content(&self) -> Vc<EcmascriptChunkItemContent> {
self.inner_chunk_item.content()
}
#[turbo_tasks::function]
fn content_with_async_module_info(
&self,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
estimated: bool,
) -> Vc<EcmascriptChunkItemContent> {
self.inner_chunk_item
.content_with_async_module_info(async_module_info, estimated)
self.proxy_module().chunk_item_content(
chunking_context,
module_graph,
async_module_info,
estimated,
)
}
}
......
......@@ -70,8 +70,6 @@ impl Module for NextDynamicEntryModule {
}
}
turbopack_core::chunk_item!(NextDynamicEntryModule, ecmascript);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
#[turbo_tasks::function]
......
......@@ -87,8 +87,6 @@ impl Module for NextServerComponentModule {
}
}
turbopack_core::chunk_item!(NextServerComponentModule, ecmascript);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for NextServerComponentModule {
#[turbo_tasks::function]
......
......@@ -68,8 +68,6 @@ impl Module for NextServerUtilityModule {
}
}
turbopack_core::chunk_item!(NextServerUtilityModule, ecmascript);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for NextServerUtilityModule {
#[turbo_tasks::function]
......
......@@ -104,8 +104,6 @@ impl Module for RawEcmascriptModule {
}
}
turbopack_core::chunk_item!(RawEcmascriptModule, ecmascript);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for RawEcmascriptModule {
#[turbo_tasks::function]
......
repo = "next.js"
name = "mmastrac__slash__associated-tuples"
branch = "mmastrac/associated-tuples"
path = "/Users/matt/Library/Application Support/clydra/__slash__Users__slash__matt__slash__Documents__slash__github__slash__vercel.toml/worktrees/next.js/mmastrac__slash__associated-tuples"
terminals = 1
......@@ -35,6 +35,7 @@ turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbopack-core = { workspace = true }
turbopack-css = { workspace = true }
turbopack-ecmascript = { workspace = true }
turbopack-ecmascript-runtime = { workspace = true }
turbopack-resolve = { workspace = true }
......
......@@ -11,10 +11,10 @@ use turbo_tasks_hash::{DeterministicHash, HashAlgorithm};
use turbopack_core::{
asset::Asset,
chunk::{
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule,
ChunkingConfig, ChunkingConfigs, ChunkingContext, ChunkingContextExt,
EntryChunkGroupResult, EvaluatableAsset, EvaluatableAssets, MinifyType,
SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkingConfig,
ChunkingConfigs, ChunkingContext, EntryChunkGroupResult, EvaluatableAsset,
EvaluatableAssets, MinifyType, SourceMapSourceType, SourceMapsType, UnusedReferences,
UrlBehavior,
availability_info::AvailabilityInfo,
chunk_group::{MakeChunkGroupResult, make_chunk_group},
chunk_id_strategy::ModuleIdStrategy,
......@@ -29,9 +29,10 @@ use turbopack_core::{
},
output::{OutputAsset, OutputAssets},
};
use turbopack_css::chunk::CssChunkType;
use turbopack_ecmascript::{
async_chunk::module::AsyncLoaderModule,
chunk::EcmascriptChunk,
chunk::{EcmascriptChunk, EcmascriptChunkType},
manifest::{chunk_asset::ManifestAsyncModule, loader_module::ManifestLoaderModule},
};
use turbopack_ecmascript_runtime::RuntimeType;
......@@ -692,8 +693,19 @@ impl ChunkingContext for BrowserChunkingContext {
}
#[turbo_tasks::function]
fn chunking_configs(&self) -> Result<Vc<ChunkingConfigs>> {
Ok(Vc::cell(self.chunking_configs.iter().cloned().collect()))
async fn chunking_configs(&self) -> Result<Vc<ChunkingConfigs>> {
let mut configs = self.chunking_configs.clone();
let ecma_type: ResolvedVc<Box<dyn ChunkType>> =
ResolvedVc::upcast(Vc::<EcmascriptChunkType>::default().to_resolved().await?);
if !configs.iter().any(|(ty, _)| *ty == ecma_type) {
configs.push((ecma_type, ChunkingConfig::default()));
}
let css_type: ResolvedVc<Box<dyn ChunkType>> =
ResolvedVc::upcast(Vc::<CssChunkType>::default().to_resolved().await?);
if !configs.iter().any(|(ty, _)| *ty == css_type) {
configs.push((css_type, ChunkingConfig::default()));
}
Ok(ChunkingConfigs::new(configs))
}
#[turbo_tasks::function]
......@@ -904,7 +916,7 @@ impl ChunkingContext for BrowserChunkingContext {
#[turbo_tasks::function]
async fn async_loader_chunk_item(
self: ResolvedVc<Self>,
module: Vc<Box<dyn ChunkableModule>>,
module: Vc<Box<dyn Module>>,
module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo,
) -> Result<Vc<ChunkItem>> {
......@@ -917,17 +929,17 @@ impl ChunkingContext for BrowserChunkingContext {
availability_info,
);
let loader_module = ManifestLoaderModule::new(manifest_asset);
chunking_context.chunk_item(Vc::upcast(loader_module), module_graph)
ChunkItem::new(Vc::upcast(loader_module), module_graph, *chunking_context)
} else {
let module = AsyncLoaderModule::new(module, *chunking_context, availability_info);
chunking_context.chunk_item(Vc::upcast(module), module_graph)
ChunkItem::new(Vc::upcast(module), module_graph, *chunking_context)
})
}
#[turbo_tasks::function]
async fn async_loader_chunk_item_ident(
self: Vc<Self>,
module: Vc<Box<dyn ChunkableModule>>,
module: Vc<Box<dyn Module>>,
) -> Result<Vc<AssetIdent>> {
Ok(if self.await?.manifest_chunks {
ManifestLoaderModule::asset_ident_for(module)
......
......@@ -2,20 +2,19 @@ use anyhow::Result;
use either::Either;
use turbo_tasks::{FxIndexMap, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{AsyncModuleInfo, ChunkItemExt, ModuleId},
chunk::{ChunkItemExt, ModuleId},
code_builder::Code,
};
use turbopack_ecmascript::chunk::{
EcmascriptChunkContent, EcmascriptChunkItem, EcmascriptChunkItemExt,
EcmascriptChunkItemOrBatchWithAsyncInfo, EcmascriptChunkItemWithAsyncInfo,
EcmascriptChunkContent, EcmascriptChunkItemOrBatchWithAsyncInfo,
EcmascriptChunkItemWithAsyncInfo, ecmascript_chunk_item_code,
};
/// A chunk item's content entry.
///
/// Instead of storing the [`Vc<Box<dyn EcmascriptChunkItem>>`] itself from
/// which `code` and `hash` are derived, we store `Vc`s directly. This avoids
/// creating tasks in a hot loop when iterating over thousands of entries when
/// computing updates.
/// Instead of storing the module itself from which `code` and `hash` are
/// derived, we store `Vc`s directly. This avoids creating tasks in a hot
/// loop when iterating over thousands of entries when computing updates.
#[turbo_tasks::value]
#[derive(Debug)]
pub struct EcmascriptDevChunkContentEntry {
......@@ -24,11 +23,15 @@ pub struct EcmascriptDevChunkContentEntry {
}
impl EcmascriptDevChunkContentEntry {
pub async fn new(
chunk_item: ResolvedVc<Box<dyn EcmascriptChunkItem>>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Self> {
let code = chunk_item.code(async_module_info).to_resolved().await?;
pub async fn new(info: &EcmascriptChunkItemWithAsyncInfo) -> Result<Self> {
let code = ecmascript_chunk_item_code(
info.module,
info.chunking_context,
info.module_graph,
info.async_info.map(|info| *info),
)
.to_resolved()
.await?;
Ok(EcmascriptDevChunkContentEntry {
code,
hash: code.source_code_hash().to_resolved().await?,
......@@ -55,19 +58,12 @@ impl EcmascriptBrowserChunkContentEntries {
.iter()
.map(async |item| {
Ok(match item {
&EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(
EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info,
},
) => Either::Left(std::iter::once((
chunk_item.id().await?,
EcmascriptDevChunkContentEntry::new(
chunk_item,
async_info.map(|info| *info),
)
.await?,
))),
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(info) => {
Either::Left(std::iter::once((
info.chunk_item().await?.id().await?,
EcmascriptDevChunkContentEntry::new(info).await?,
)))
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => {
let batch = batch.await?;
Either::Right(
......@@ -76,12 +72,8 @@ impl EcmascriptBrowserChunkContentEntries {
.iter()
.map(|item| async move {
Ok((
item.chunk_item.id().await?,
EcmascriptDevChunkContentEntry::new(
item.chunk_item,
item.async_info.map(|info| *info),
)
.await?,
item.chunk_item().await?.id().await?,
EcmascriptDevChunkContentEntry::new(item).await?,
))
})
.try_join()
......
use anyhow::{Result, anyhow};
use anyhow::{Context, Result};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
use turbo_tasks_env::ProcessEnv;
......@@ -6,9 +6,7 @@ use turbo_tasks_fs::FileSystemPath;
use turbopack_browser::{BrowserChunkingContext, react_refresh::assert_can_resolve_react_refresh};
use turbopack_cli_utils::runtime_entry::{RuntimeEntries, RuntimeEntry};
use turbopack_core::{
chunk::{
ChunkableModule, ChunkingContext, EvaluatableAsset, SourceMapSourceType, SourceMapsType,
},
chunk::{ChunkItem, ChunkingContext, EvaluatableAsset, SourceMapSourceType, SourceMapsType},
environment::Environment,
file_source::FileSource,
module::Module,
......@@ -171,33 +169,25 @@ pub async fn create_web_entry_source(
let entries: Vec<_> = entries
.into_iter()
.map(|module| async move {
if let (Some(chunkable_module), Some(entry)) = (
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module),
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module),
) {
let chunk_item = ChunkItem::new(*module, *module_graph, *chunking_context)
.to_resolved()
.await
.context(
"Entry module is not chunkable, so it can't be used to bootstrap the \
application",
)?;
if let Some(entry) = ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module) {
Ok(DevHtmlEntry {
chunkable_module,
module_graph,
chunking_context,
chunk_item,
runtime_entries: Some(runtime_entries.with_entry(*entry).to_resolved().await?),
})
} else if let Some(chunkable_module) =
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module)
{
} else {
// TODO this is missing runtime code, so it's probably broken and we should also
// add an ecmascript chunk with the runtime code
Ok(DevHtmlEntry {
chunkable_module,
module_graph,
chunking_context,
chunk_item,
runtime_entries: None,
})
} else {
// TODO convert into a serve-able asset
Err(anyhow!(
"Entry module is not chunkable, so it can't be used to bootstrap the \
application"
))
}
})
.try_join()
......
......@@ -7,7 +7,6 @@ use turbo_tasks::{
use turbo_tasks_hash::Xxh3Hash64Hasher;
use crate::{
chunk::ChunkableModule,
module::Module,
module_graph::module_batch::{ChunkableModuleOrBatch, IdentStrings, ModuleBatch},
};
......@@ -16,9 +15,9 @@ use crate::{
Debug, Copy, Clone, Hash, PartialEq, Eq, TraceRawVcs, NonLocalValue, TaskInput, Encode, Decode,
)]
pub enum AvailableModuleItem {
Module(ResolvedVc<Box<dyn ChunkableModule>>),
Module(ResolvedVc<Box<dyn Module>>),
Batch(ResolvedVc<ModuleBatch>),
AsyncLoader(ResolvedVc<Box<dyn ChunkableModule>>),
AsyncLoader(ResolvedVc<Box<dyn Module>>),
}
impl AvailableModuleItem {
......
use std::{collections::HashSet, sync::atomic::AtomicBool};
use anyhow::{Context, Result};
use anyhow::Result;
use rustc_hash::FxHashMap;
use turbo_rcstr::rcstr;
use turbo_tasks::{FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
......@@ -11,7 +11,7 @@ use super::{
};
use crate::{
chunk::{
ChunkableModule, ChunkingType, Chunks,
ChunkingConfigs, ChunkingType, Chunks,
available_modules::AvailableModuleItem,
chunk_item_batch::{ChunkItemBatchGroup, ChunkItemOrBatchWithAsyncModuleInfo},
},
......@@ -24,7 +24,7 @@ use crate::{
ChunkableModuleBatchGroup, ChunkableModuleOrBatch, ModuleBatch, ModuleBatchGroup,
ModuleOrBatch,
},
module_batches::{BatchingConfig, ModuleBatchesGraphEdge},
module_batches::ModuleBatchesGraphEdge,
},
output::{
OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsReferences,
......@@ -60,7 +60,7 @@ pub async fn make_chunk_group(
.await?;
let should_trace = *chunking_context.is_tracing_enabled().await?;
let should_merge_modules = *chunking_context.is_module_merging_enabled().await?;
let batching_config = chunking_context.batching_config();
let chunking_configs = chunking_context.chunking_configs();
let ChunkGroupContent {
chunkable_items,
......@@ -76,7 +76,7 @@ pub async fn make_chunk_group(
can_split_async,
should_trace,
should_merge_modules,
batching_config,
chunking_configs,
},
)
.await?;
......@@ -202,8 +202,8 @@ pub struct ChunkGroupContentOptions {
pub should_trace: bool,
/// Whether module merging is enabled
pub should_merge_modules: bool,
/// The batching config to use
pub batching_config: Vc<BatchingConfig>,
/// The chunking configs
pub chunking_configs: Vc<ChunkingConfigs>,
}
/// Computes the content of a chunk group.
......@@ -217,17 +217,17 @@ pub async fn chunk_group_content(
can_split_async,
should_trace,
should_merge_modules,
batching_config,
chunking_configs,
}: ChunkGroupContentOptions,
) -> Result<ChunkGroupContent> {
let module_batches_graph = module_graph.module_batches(batching_config).await?;
let module_batches_graph = module_graph.module_batches(chunking_configs).await?;
type ModuleToChunkableMap = FxHashMap<ModuleOrBatch, ChunkableModuleOrBatch>;
struct TraverseState {
unsorted_items: ModuleToChunkableMap,
chunkable_items: FxIndexSet<ChunkableModuleOrBatch>,
async_modules: FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>>>,
async_modules: FxIndexSet<ResolvedVc<Box<dyn Module>>>,
traced_modules: FxIndexSet<ResolvedVc<Box<dyn Module>>>,
}
......@@ -313,15 +313,13 @@ pub async fn chunk_group_content(
}
ChunkingType::Async => {
if can_split_async {
let chunkable_module = ResolvedVc::try_downcast(edge.module.unwrap())
.context("Module in async chunking edge is not chunkable")?;
let module = edge.module.unwrap();
let is_async_loader_available =
available_modules.as_ref().is_some_and(|available_modules| {
available_modules
.get(AvailableModuleItem::AsyncLoader(chunkable_module))
available_modules.get(AvailableModuleItem::AsyncLoader(module))
});
if !is_async_loader_available {
state.async_modules.insert(chunkable_module);
state.async_modules.insert(module);
}
GraphTraversalAction::Exclude
} else if is_available {
......@@ -388,15 +386,14 @@ pub async fn chunk_group_content(
.map(async |chunkable_module| match chunkable_module {
ChunkableModuleOrBatch::Module(module) => {
if !merged_modules_ref
.should_create_chunk_item_for(ResolvedVc::upcast(module))
.should_create_chunk_item_for(module)
.await?
{
return Ok(None);
}
let module = if let Some(replacement) = merged_modules_ref
.should_replace_module(ResolvedVc::upcast(module))
.await?
let module = if let Some(replacement) =
merged_modules_ref.should_replace_module(module).await?
{
replacement
} else {
......@@ -458,23 +455,18 @@ async fn map_module_batch(
.iter()
.copied()
.map(async |module| {
if !merged_modules
.should_create_chunk_item_for(ResolvedVc::upcast(module))
.await?
{
if !merged_modules.should_create_chunk_item_for(module).await? {
modified.store(true, std::sync::atomic::Ordering::Relaxed);
return Ok(None);
}
let module = if let Some(replacement) = merged_modules
.should_replace_module(ResolvedVc::upcast(module))
.await?
{
modified.store(true, std::sync::atomic::Ordering::Relaxed);
replacement
} else {
module
};
let module =
if let Some(replacement) = merged_modules.should_replace_module(module).await? {
modified.store(true, std::sync::atomic::Ordering::Relaxed);
replacement
} else {
module
};
Ok(Some(module))
})
......@@ -518,7 +510,7 @@ async fn map_module_batch_group(
merged_modules_ref.should_replace_module(module).await?
{
modified.store(true, std::sync::atomic::Ordering::Relaxed);
ResolvedVc::upcast(replacement)
replacement
} else {
module
};
......
......@@ -11,10 +11,8 @@ use turbo_tasks::{
};
use crate::{
chunk::{
ChunkItemWithAsyncModuleInfo, ChunkType, ChunkableModule, ChunkingContext,
chunking_context::ChunkingContextExt,
},
chunk::{ChunkItem, ChunkItemWithAsyncModuleInfo, ChunkType, ChunkingContext},
module::Module,
module_graph::{
ModuleGraph,
async_module_info::AsyncModulesInfo,
......@@ -24,24 +22,22 @@ use crate::{
};
pub async fn attach_async_info_to_chunkable_module(
module: ResolvedVc<Box<dyn ChunkableModule>>,
module: ResolvedVc<Box<dyn Module>>,
async_module_info: &ReadRef<AsyncModulesInfo>,
module_graph: Vc<ModuleGraph>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<ChunkItemWithAsyncModuleInfo> {
let general_module = ResolvedVc::upcast(module);
let async_info = if async_module_info.contains(&general_module) {
let async_info = if async_module_info.contains(&module) {
Some(
module_graph
.referenced_async_modules(*general_module)
.referenced_async_modules(*module)
.to_resolved()
.await?,
)
} else {
None
};
let chunk_item = chunking_context
.chunk_item(Vc::upcast(*module), module_graph)
let chunk_item = ChunkItem::new(*module, module_graph, chunking_context)
.to_resolved()
.await?;
Ok(ChunkItemWithAsyncModuleInfo {
......@@ -75,15 +71,26 @@ impl ChunkItemOrBatchWithAsyncModuleInfo {
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Option<Self>> {
Ok(match chunkable_module_or_batch {
ChunkableModuleOrBatch::Module(module) => Some(Self::ChunkItem(
attach_async_info_to_chunkable_module(
module,
async_module_info,
module_graph,
chunking_context,
)
.await?,
)),
ChunkableModuleOrBatch::Module(module) => {
// Skip modules that are not accepted by any chunk type
if !chunking_context
.chunking_configs()
.await?
.is_chunkable(module)
.await
{
return Ok(None);
}
Some(Self::ChunkItem(
attach_async_info_to_chunkable_module(
module,
async_module_info,
module_graph,
chunking_context,
)
.await?,
))
}
ChunkableModuleOrBatch::Batch(batch) => Some(Self::Batch(
ChunkItemBatchWithAsyncModuleInfo::from_module_batch(
*batch,
......
......@@ -67,15 +67,13 @@ pub async fn make_production_chunks(
},
..
} => Prepared::ChunkItem(
if let Some(module_chunk_groups) =
module_chunk_groups.get(&ResolvedVc::upcast(module)).await?
{
if let Some(module_chunk_groups) = module_chunk_groups.get(&module).await? {
module_chunk_groups
} else {
// Merged modules don't have a chunk group in chunk_group_info, so
// lookup using the original module.
let original_module = merged_modules
.get_original_module(ResolvedVc::upcast(module))
.get_original_module(module)
.await?
.context("every module should have a chunk group")?;
module_chunk_groups
......
use std::ops::Deref;
use anyhow::{Result, bail};
use bincode::{Decode, Encode};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ResolvedVc, TaskInput, Upcast, ValueToString, Vc, trace::TraceRawVcs,
IntoTraitRef, NonLocalValue, ResolvedVc, TaskInput, TraitRef, Upcast, Vc, trace::TraceRawVcs,
};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::DeterministicHash;
......@@ -12,8 +14,8 @@ use turbo_tasks_hash::DeterministicHash;
use crate::{
asset::Asset,
chunk::{
ChunkItem, ChunkType, ChunkableModule, EvaluatableAssets,
availability_info::AvailabilityInfo, chunk_id_strategy::ModuleIdStrategy,
ChunkItem, ChunkType, EvaluatableAssets, availability_info::AvailabilityInfo,
chunk_id_strategy::ModuleIdStrategy,
},
environment::Environment,
ident::AssetIdent,
......@@ -278,8 +280,82 @@ pub struct ChunkingConfig {
pub placeholder_for_future_extensions: (),
}
#[turbo_tasks::value(transparent)]
pub struct ChunkingConfigs(FxHashMap<ResolvedVc<Box<dyn ChunkType>>, ChunkingConfig>);
#[derive(Default)]
#[turbo_tasks::value(shared)]
pub struct ChunkingConfigs(pub FxHashMap<ResolvedVc<Box<dyn ChunkType>>, ChunkingConfig>);
#[turbo_tasks::value_impl]
impl ChunkingConfigs {
/// Create a new `ChunkingConfigs` from a list of chunk type/config pairs.
///
/// This is a memoized turbo_tasks function, so identical inputs produce the same `Vc`,
/// which is critical for downstream memoization of `module_batches()`.
#[turbo_tasks::function]
pub fn new(configs: Vec<(ResolvedVc<Box<dyn ChunkType>>, ChunkingConfig)>) -> Vc<Self> {
ChunkingConfigs(configs.into_iter().collect()).cell()
}
}
impl Deref for ChunkingConfigs {
type Target = FxHashMap<ResolvedVc<Box<dyn ChunkType>>, ChunkingConfig>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
/// Pre-resolved chunk type trait refs for efficient batch chunkability checks.
/// Created via [`ChunkingConfigs::resolved_chunk_types`].
pub type ResolvedChunkTypes = Vec<(ResolvedVc<Box<dyn ChunkType>>, TraitRef<Box<dyn ChunkType>>)>;
impl ChunkingConfigs {
pub async fn is_chunkable(&self, module: ResolvedVc<Box<dyn Module>>) -> bool {
self.chunk_type(module).await.is_some()
}
/// Returns a [`ChunkType`], if one is supported by this module.
pub async fn chunk_type(
&self,
module: ResolvedVc<Box<dyn Module>>,
) -> Option<ResolvedVc<Box<dyn ChunkType>>> {
for chunk_type in self.0.keys() {
if chunk_type
.into_trait_ref()
.await
.expect("Unexpectedly failed to cast trait")
.accepts_module(module)
{
return Some(*chunk_type);
}
}
None
}
/// Pre-resolves all chunk type trait refs. Use with [`is_chunkable_resolved`]
/// when checking many modules to avoid repeated async lookups.
pub async fn resolved_chunk_types(&self) -> Result<ResolvedChunkTypes> {
let mut result = Vec::with_capacity(self.0.len());
for chunk_type in self.0.keys() {
let trait_ref = chunk_type.into_trait_ref().await?;
result.push((*chunk_type, trait_ref));
}
Ok(result)
}
/// Check if a module is chunkable using pre-resolved trait refs.
/// More efficient than [`is_chunkable`] when checking many modules.
pub fn is_chunkable_resolved(
&self,
resolved: &ResolvedChunkTypes,
module: ResolvedVc<Box<dyn Module>>,
) -> bool {
for (_ty, trait_ref) in resolved {
if trait_ref.accepts_module(module) {
return true;
}
}
false
}
}
#[turbo_tasks::value(shared)]
#[derive(Debug, Clone, Copy, Hash, TaskInput, Default, Deserialize)]
......@@ -373,10 +449,9 @@ pub trait ChunkingContext {
Vc::cell(false)
}
/// Returns the chunking configs for this context.
#[turbo_tasks::function]
fn chunking_configs(self: Vc<Self>) -> Vc<ChunkingConfigs> {
Vc::cell(Default::default())
}
fn chunking_configs(self: Vc<Self>) -> Vc<ChunkingConfigs>;
#[turbo_tasks::function]
fn batching_config(self: Vc<Self>) -> Vc<BatchingConfig> {
......@@ -427,13 +502,12 @@ pub trait ChunkingContext {
#[turbo_tasks::function]
fn async_loader_chunk_item(
&self,
module: Vc<Box<dyn ChunkableModule>>,
module: Vc<Box<dyn Module>>,
module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo,
) -> Vc<ChunkItem>;
#[turbo_tasks::function]
fn async_loader_chunk_item_ident(&self, module: Vc<Box<dyn ChunkableModule>>)
-> Vc<AssetIdent>;
fn async_loader_chunk_item_ident(&self, module: Vc<Box<dyn Module>>) -> Vc<AssetIdent>;
#[turbo_tasks::function]
fn chunk_group(
......@@ -580,15 +654,6 @@ pub trait ChunkingContextExt {
fn relative_path_from_chunk_root_to_project_root(self: Vc<Self>) -> Vc<RcStr>
where
Self: Send;
/// Creates a chunk item from a module. The module must implement `ChunkableModule`.
fn chunk_item(
self: Vc<Self>,
module: Vc<Box<dyn Module>>,
module_graph: Vc<ModuleGraph>,
) -> Vc<ChunkItem>
where
Self: Send;
}
impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingContextExt for T {
......@@ -707,30 +772,6 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn relative_path_from_chunk_root_to_project_root(self: Vc<Self>) -> Vc<RcStr> {
relative_path_from_chunk_root_to_project_root(Vc::upcast_non_strict(self))
}
fn chunk_item(
self: Vc<Self>,
module: Vc<Box<dyn Module>>,
module_graph: Vc<ModuleGraph>,
) -> Vc<ChunkItem> {
chunk_item(Vc::upcast_non_strict(self), module, module_graph)
}
}
#[turbo_tasks::function]
async fn chunk_item(
chunking_context: Vc<Box<dyn ChunkingContext>>,
module: Vc<Box<dyn Module>>,
module_graph: Vc<ModuleGraph>,
) -> Result<Vc<ChunkItem>> {
let module = module.to_resolved().await?;
let Some(chunkable) = ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module) else {
bail!(
"Module {} is not chunkable",
module.ident().to_string().await?
);
};
Ok(chunkable.as_chunk_item(module_graph, chunking_context))
}
#[turbo_tasks::function]
......
use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, Upcast, ValueToString, Vc};
use super::ChunkableModule;
use crate::{
context::AssetContext,
module::Module,
......@@ -14,7 +13,7 @@ use crate::{
/// The chunking context implementation will resolve the dynamic entry to a
/// well-known value or trait object.
#[turbo_tasks::value_trait]
pub trait EvaluatableAsset: Module + ChunkableModule {}
pub trait EvaluatableAsset: Module {}
pub trait EvaluatableAssetExt {
fn to_evaluatable(
......
......@@ -7,7 +7,7 @@ use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoi
use crate::{
chunk::{
ChunkableModule, ChunkingType, MergeableModule, MergeableModuleExposure, MergeableModules,
ChunkingType, MergeableModule, MergeableModuleExposure, MergeableModules,
MergeableModulesExposed,
},
module::Module,
......@@ -20,7 +20,7 @@ use crate::{
#[turbo_tasks::value(transparent, cell = "keyed")]
#[allow(clippy::type_complexity)]
pub struct MergedModulesReplacements(
FxHashMap<ResolvedVc<Box<dyn Module>>, ResolvedVc<Box<dyn ChunkableModule>>>,
FxHashMap<ResolvedVc<Box<dyn Module>>, ResolvedVc<Box<dyn Module>>>,
);
#[turbo_tasks::value(transparent, cell = "keyed")]
......@@ -49,7 +49,7 @@ impl MergedModuleInfo {
pub async fn should_replace_module(
&self,
module: ResolvedVc<Box<dyn Module>>,
) -> Result<Option<ResolvedVc<Box<dyn ChunkableModule>>>> {
) -> Result<Option<ResolvedVc<Box<dyn Module>>>> {
Ok(self.replacements.get(&module).await?.as_deref().copied())
}
......@@ -763,7 +763,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
#[allow(clippy::type_complexity)]
let mut replacements: FxHashMap<
ResolvedVc<Box<dyn Module>>,
ResolvedVc<Box<dyn ChunkableModule>>,
ResolvedVc<Box<dyn Module>>,
> = Default::default();
#[allow(clippy::type_complexity)]
let mut replacements_to_original: FxHashMap<
......@@ -774,7 +774,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
for (original, replacement, replacement_included) in result.into_iter().flatten() {
replacements.insert(original, replacement);
replacements_to_original.insert(ResolvedVc::upcast(replacement), original);
replacements_to_original.insert(replacement, original);
included.extend(replacement_included);
}
......
......@@ -26,7 +26,7 @@ use turbo_tasks::{
use turbo_tasks_fs::FileSystemPath;
use crate::{
chunk::{AsyncModuleInfo, ChunkingContext, ChunkingType},
chunk::{AsyncModuleInfo, ChunkingConfigs, ChunkingContext, ChunkingType},
issue::{ImportTracer, ImportTraces, Issue},
module::Module,
module_graph::{
......@@ -782,9 +782,9 @@ impl ModuleGraph {
#[turbo_tasks::function]
pub async fn module_batches(
self: Vc<Self>,
config: Vc<BatchingConfig>,
chunking_configs: ResolvedVc<ChunkingConfigs>,
) -> Result<Vc<ModuleBatchesGraph>> {
compute_module_batches(self, &*config.await?).await
compute_module_batches(self, chunking_configs).await
}
#[turbo_tasks::function]
......
......@@ -9,9 +9,7 @@ use turbo_tasks::{
trace::TraceRawVcs,
};
use crate::{
chunk::ChunkableModule, module::Module, module_graph::chunk_group_info::RoaringBitmapWrapper,
};
use crate::{module::Module, module_graph::chunk_group_info::RoaringBitmapWrapper};
#[derive(
Debug,
......@@ -50,7 +48,7 @@ impl ModuleOrBatch {
Debug, Copy, Clone, Hash, PartialEq, Eq, TraceRawVcs, NonLocalValue, TaskInput, Encode, Decode,
)]
pub enum ChunkableModuleOrBatch {
Module(ResolvedVc<Box<dyn ChunkableModule>>),
Module(ResolvedVc<Box<dyn Module>>),
Batch(ResolvedVc<ModuleBatch>),
None(usize),
}
......@@ -58,7 +56,7 @@ pub enum ChunkableModuleOrBatch {
impl ChunkableModuleOrBatch {
pub fn from_module_or_batch(module_or_batch: ModuleOrBatch) -> Option<Self> {
match module_or_batch {
ModuleOrBatch::Module(module) => ResolvedVc::try_downcast(module).map(Self::Module),
ModuleOrBatch::Module(module) => Some(Self::Module(module)),
ModuleOrBatch::Batch(batch) => Some(Self::Batch(batch)),
ModuleOrBatch::None(i) => Some(Self::None(i)),
}
......@@ -80,7 +78,7 @@ impl ChunkableModuleOrBatch {
impl From<ChunkableModuleOrBatch> for ModuleOrBatch {
fn from(chunkable_module_or_batch: ChunkableModuleOrBatch) -> Self {
match chunkable_module_or_batch {
ChunkableModuleOrBatch::Module(module) => Self::Module(ResolvedVc::upcast(module)),
ChunkableModuleOrBatch::Module(module) => Self::Module(module),
ChunkableModuleOrBatch::Batch(batch) => Self::Batch(batch),
ChunkableModuleOrBatch::None(i) => Self::None(i),
}
......@@ -105,7 +103,7 @@ impl Debug for IdentStrings {
#[turbo_tasks::value]
pub struct ModuleBatch {
pub modules: Vec<ResolvedVc<Box<dyn ChunkableModule>>>,
pub modules: Vec<ResolvedVc<Box<dyn Module>>>,
pub chunk_groups: Option<RoaringBitmapWrapper>,
}
......@@ -113,7 +111,7 @@ pub struct ModuleBatch {
impl ModuleBatch {
#[turbo_tasks::function]
pub fn new(
modules: Vec<ResolvedVc<Box<dyn ChunkableModule>>>,
modules: Vec<ResolvedVc<Box<dyn Module>>>,
chunk_groups: Option<RoaringBitmapWrapper>,
) -> Vc<Self> {
Self {
......@@ -168,9 +166,7 @@ impl ChunkableModuleBatchGroup {
.items
.iter()
.filter_map(|batch| match *batch {
ModuleOrBatch::Module(module) => {
ResolvedVc::try_downcast(module).map(ChunkableModuleOrBatch::Module)
}
ModuleOrBatch::Module(module) => Some(ChunkableModuleOrBatch::Module(module)),
ModuleOrBatch::Batch(batch) => Some(ChunkableModuleOrBatch::Batch(batch)),
ModuleOrBatch::None(_) => None,
})
......
......@@ -18,7 +18,7 @@ use turbo_tasks::{
};
use crate::{
chunk::{ChunkableModule, ChunkingType},
chunk::{ChunkingConfigs, ChunkingType},
module::Module,
module_graph::{
GraphTraversalAction, ModuleGraph,
......@@ -334,7 +334,7 @@ impl PreBatches {
pub async fn compute_module_batches(
module_graph: Vc<ModuleGraph>,
_config: &BatchingConfig,
chunking_configs: ResolvedVc<ChunkingConfigs>,
) -> Result<Vc<ModuleBatchesGraph>> {
let outer_span = tracing::info_span!(
"compute module batches",
......@@ -655,6 +655,21 @@ pub async fn compute_module_batches(
// Now every module is only in one batch
let mut edges_count = 0;
let chunking_config = chunking_configs.await?;
// Pre-resolve chunk type trait refs to avoid repeated async lookups per module
let resolved_chunk_types = chunking_config.resolved_chunk_types().await?;
let mut chunkable_modules = FxIndexSet::default();
for prebatch in &pre_batches.batches {
for item in &prebatch.items {
if let PreBatchItem::ParallelModule(module) = item {
let is_chunkable =
chunking_config.is_chunkable_resolved(&resolved_chunk_types, *module);
if is_chunkable {
chunkable_modules.insert(*module);
}
}
}
}
// Since batches can only have references followed by a list of parallel chunkable modules,
// we need to split batches that have modules before references.
......@@ -668,13 +683,13 @@ pub async fn compute_module_batches(
}
let mut mode = Mode::Other;
for item in items {
let chunkable_module = if let PreBatchItem::ParallelModule(module) = &item {
ResolvedVc::try_downcast::<Box<dyn ChunkableModule>>(*module)
let is_chunkable = if let PreBatchItem::ParallelModule(module) = &item {
chunkable_modules.contains(module)
} else {
None
false
};
let item = if let PreBatchItem::ParallelModule(module) = item {
if chunkable_module.is_some() {
if is_chunkable {
PreBatchItem::ParallelModule(module)
} else {
pre_batches.single_module_entries.insert(module);
......@@ -689,8 +704,8 @@ pub async fn compute_module_batches(
} else {
item
};
match (&mode, chunkable_module) {
(_, Some(_)) => {
match (&mode, is_chunkable) {
(_, true) => {
mode = Mode::ParallelChunkableModule;
new_items.insert(item);
}
......@@ -707,7 +722,7 @@ pub async fn compute_module_batches(
pre_batches.batches.push(new_batch);
edges_count += 1;
new_items.insert(PreBatchItem::ParallelReference(idx));
if chunkable_module.is_some() {
if is_chunkable {
new_items.insert(item);
} else {
edges_count += 1;
......@@ -738,7 +753,11 @@ pub async fn compute_module_batches(
.map(async |(i, pre_batch)| {
let mut modules = pre_batch.items.iter().filter_map(|item| {
if let PreBatchItem::ParallelModule(module) = item {
ResolvedVc::try_downcast(*module)
if chunkable_modules.contains(module) {
Some(*module)
} else {
None
}
} else {
None
}
......@@ -757,7 +776,7 @@ pub async fn compute_module_batches(
);
Ok(ModuleOrBatch::Batch(batch.to_resolved().await?))
} else {
Ok(ModuleOrBatch::Module(ResolvedVc::upcast(first)))
Ok(ModuleOrBatch::Module(first))
}
})
.try_join()
......
......@@ -13,7 +13,7 @@ use turbo_tasks::{
use crate::{
chunk::{
ChunkItemBatchWithAsyncModuleInfo, ChunkItemWithAsyncModuleInfo, ChunkType,
ChunkableModule, ChunkingContext, chunk_item_batch::attach_async_info_to_chunkable_module,
ChunkingContext, chunk_item_batch::attach_async_info_to_chunkable_module,
},
module::{Module, StyleModule, StyleType},
module_graph::{
......@@ -66,7 +66,7 @@ impl ModuleInfo {
}
struct ChunkGroupState {
styles: FxIndexSet<ResolvedVc<Box<dyn ChunkableModule>>>,
styles: FxIndexSet<ResolvedVc<Box<dyn Module>>>,
requests: usize,
}
......@@ -77,10 +77,10 @@ pub async fn compute_style_groups(
) -> Result<Vc<StyleGroups>> {
let chunk_group_info = module_graph.chunk_group_info().await?;
let batches_graph = module_graph
.module_batches(chunking_context.batching_config())
.module_batches(chunking_context.chunking_configs())
.await?;
let async_info = module_graph.async_module_info().await?;
let mut module_info_map: FxIndexMap<ResolvedVc<Box<dyn ChunkableModule>>, Option<ModuleInfo>> =
let mut module_info_map: FxIndexMap<ResolvedVc<Box<dyn Module>>, Option<ModuleInfo>> =
FxIndexMap::default();
// Compute the style modules in each chunk group
......@@ -156,9 +156,7 @@ pub async fn compute_style_groups(
}
}
ModuleOrBatch::Module(module) => {
if let Some(chunkable_module) = ResolvedVc::try_downcast(module) {
handle_module(chunkable_module).await?;
}
handle_module(module).await?;
}
ModuleOrBatch::None(_) => {}
}
......
......@@ -3,16 +3,13 @@ use turbo_rcstr::rcstr;
use turbo_tasks::{IntoTraitRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbopack_core::{
chunk::{
ChunkItem, ChunkType, ChunkableModule, ChunkedItem, ChunkingContext, ChunkingContextExt,
MinifyType,
},
chunk::{ChunkItem, ChunkingContext, MinifyType},
context::AssetContext,
environment::Environment,
ident::AssetIdent,
module::{Module, ModuleSideEffects, StyleModule, StyleType},
module_graph::ModuleGraph,
output::{OutputAssetsReference, OutputAssetsWithReferenced},
output::OutputAssetsWithReferenced,
reference::{ModuleReference, ModuleReferences},
reference_type::ImportContext,
resolve::origin::ResolveOrigin,
......@@ -22,7 +19,7 @@ use turbopack_core::{
use crate::{
CssModuleAssetType,
chunk::{CssChunkItem, CssChunkItemContent, CssChunkPlaceable, CssChunkType, CssImport},
chunk::{CssChunkItemContent, CssChunkPlaceable, CssImport},
code_gen::CodeGenerateable,
process::{
CssWithPlaceholderResult, FinalCssResult, ParseCss, ParseCssResult, ProcessCss,
......@@ -174,97 +171,18 @@ impl StyleModule for CssModuleAsset {
}
#[turbo_tasks::value_impl]
impl ChunkableModule for CssModuleAsset {
#[turbo_tasks::function]
fn as_chunk_item(
self: ResolvedVc<Self>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Vc<ChunkItem> {
let item: Vc<Box<dyn ChunkedItem>> =
Vc::upcast(CssModuleChunkItem::cell(CssModuleChunkItem {
module: self,
module_graph,
chunking_context,
}));
ChunkItem::from_trait(item)
}
}
#[turbo_tasks::value_impl]
impl CssChunkPlaceable for CssModuleAsset {}
#[turbo_tasks::value_impl]
impl ResolveOrigin for CssModuleAsset {
#[turbo_tasks::function]
fn origin_path(&self) -> Vc<FileSystemPath> {
self.source.ident().path()
}
#[turbo_tasks::function]
fn asset_context(&self) -> Vc<Box<dyn AssetContext>> {
*self.asset_context
}
}
#[turbo_tasks::value]
struct CssModuleChunkItem {
module: ResolvedVc<CssModuleAsset>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for CssModuleChunkItem {
#[turbo_tasks::function]
async fn references(&self) -> Result<Vc<OutputAssetsWithReferenced>> {
let mut references = Vec::new();
if let ParseCssResult::Ok { url_references, .. } = &*self.module.parse_css().await? {
for (_, reference) in url_references.await? {
if let ReferencedAsset::Some(asset) = *reference
.get_referenced_asset(*self.chunking_context)
.await?
{
references.push(asset);
}
}
}
Ok(OutputAssetsWithReferenced::from_assets(Vc::cell(
references,
)))
}
}
#[turbo_tasks::value_impl]
impl ChunkedItem for CssModuleChunkItem {
#[turbo_tasks::function]
fn asset_ident(&self) -> Vc<AssetIdent> {
self.module.ident()
}
impl CssChunkPlaceable for CssModuleAsset {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
#[turbo_tasks::function]
fn ty(&self) -> Vc<Box<dyn ChunkType>> {
Vc::upcast(Vc::<CssChunkType>::default())
}
#[turbo_tasks::function]
fn module(&self) -> Vc<Box<dyn Module>> {
Vc::upcast(*self.module)
}
}
#[turbo_tasks::value_impl]
impl CssChunkItem for CssModuleChunkItem {
#[turbo_tasks::function]
async fn content(&self) -> Result<Vc<CssChunkItemContent>> {
let references = &*self.module.references().await?;
async fn chunk_item_content(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
) -> Result<Vc<CssChunkItemContent>> {
let this = self.await?;
let references = &*self.references().await?;
let mut imports = vec![];
let chunking_context = self.chunking_context;
let chunking_context = chunking_context.to_resolved().await?;
let module_graph = module_graph.to_resolved().await?;
for reference in references.iter() {
if let Some(import_ref) =
......@@ -281,14 +199,14 @@ impl CssChunkItem for CssModuleChunkItem {
if let Some(placeable) =
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(module)
{
let item =
chunking_context.chunk_item(Vc::upcast(*placeable), *self.module_graph);
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *item.await?;
if let Some(css_item) =
ResolvedVc::try_downcast::<Box<dyn CssChunkItem>>(inner)
{
imports.push(CssImport::Internal(import_ref, css_item));
}
let item = ChunkItem::new(
Vc::upcast(*placeable),
*module_graph,
*chunking_context,
)
.to_resolved()
.await?;
imports.push(CssImport::Internal(import_ref, item));
}
}
} else if let Some(compose_ref) =
......@@ -305,14 +223,14 @@ impl CssChunkItem for CssModuleChunkItem {
if let Some(placeable) =
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(module)
{
let item =
chunking_context.chunk_item(Vc::upcast(*placeable), *self.module_graph);
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *item.await?;
if let Some(css_item) =
ResolvedVc::try_downcast::<Box<dyn CssChunkItem>>(inner)
{
imports.push(CssImport::Composes(css_item));
}
let item = ChunkItem::new(
Vc::upcast(*placeable),
*module_graph,
*chunking_context,
)
.to_resolved()
.await?;
imports.push(CssImport::Composes(item));
}
}
}
......@@ -335,7 +253,6 @@ impl CssChunkItem for CssModuleChunkItem {
}
let result = self
.module
.finalize_css(*chunking_context, *chunking_context.minify_type().await?)
.await?;
......@@ -347,17 +264,13 @@ impl CssChunkItem for CssModuleChunkItem {
Ok(CssChunkItemContent {
inner_code: output_code.to_owned().into(),
imports,
import_context: self.module.await?.import_context,
import_context: this.import_context,
source_map: *source_map,
}
.cell())
} else {
Ok(CssChunkItemContent {
inner_code: format!(
"/* unparsable {} */",
self.module.ident().to_string().await?
)
.into(),
inner_code: format!("/* unparsable {} */", self.ident().to_string().await?).into(),
imports: vec![],
import_context: None,
source_map: FileContent::NotFound.resolved_cell(),
......@@ -365,4 +278,38 @@ impl CssChunkItem for CssModuleChunkItem {
.cell())
}
}
#[turbo_tasks::function]
async fn chunk_item_output_assets(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
_module_graph: Vc<ModuleGraph>,
) -> Result<Vc<OutputAssetsWithReferenced>> {
let mut references = Vec::new();
if let ParseCssResult::Ok { url_references, .. } = &*self.parse_css().await? {
for (_, reference) in url_references.await? {
if let ReferencedAsset::Some(asset) =
*reference.get_referenced_asset(chunking_context).await?
{
references.push(asset);
}
}
}
Ok(OutputAssetsWithReferenced::from_assets(Vc::cell(
references,
)))
}
}
#[turbo_tasks::value_impl]
impl ResolveOrigin for CssModuleAsset {
#[turbo_tasks::function]
fn origin_path(&self) -> Vc<FileSystemPath> {
self.source.ident().path()
}
#[turbo_tasks::function]
fn asset_context(&self) -> Vc<Box<dyn AssetContext>> {
*self.asset_context
}
}
......@@ -15,8 +15,8 @@ use turbopack_core::{
chunk::{
AsyncModuleInfo, Chunk, ChunkItem, ChunkItemBatchGroup, ChunkItemExt,
ChunkItemOrBatchWithAsyncModuleInfo, ChunkItemWithAsyncModuleInfo, ChunkType,
ChunkableModule, ChunkedItem, ChunkingContext, ChunkingContextExt, MinifyType, OutputChunk,
OutputChunkRuntimeInfo, SourceMapSourceType, round_chunk_item_size,
ChunkingContext, ChunkingContextExt, MinifyType, OutputChunk, OutputChunkRuntimeInfo,
SourceMapSourceType, round_chunk_item_size,
},
code_builder::{Code, CodeBuilder},
ident::AssetIdent,
......@@ -26,7 +26,8 @@ use turbopack_core::{
utils::{children_from_output_assets, content_to_details},
},
module::Module,
output::{OutputAsset, OutputAssetsReference, OutputAssetsWithReferenced},
module_graph::ModuleGraph,
output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced},
reference_type::ImportContext,
server_fs::ServerFileSystem,
source_map::{
......@@ -79,7 +80,15 @@ impl CssChunk {
let mut body = CodeBuilder::new(source_maps, false);
let mut external_imports = FxIndexSet::default();
for css_item in &this.content.await?.chunk_items {
let content = &css_item.content().await?;
let css_item_data = css_item.await?;
let Some(placeable) =
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(css_item_data.module)
else {
continue;
};
let content = &*placeable
.chunk_item_content(*css_item_data.chunking_context, *css_item_data.module_graph)
.await?;
for import in &content.imports {
if let CssImport::External(external_import) = import {
external_imports.insert((*external_import.await?).to_string());
......@@ -249,7 +258,7 @@ pub async fn write_import_context(
#[turbo_tasks::value]
pub struct CssChunkContent {
pub chunk_items: Vec<ResolvedVc<Box<dyn CssChunkItem>>>,
pub chunk_items: Vec<ResolvedVc<ChunkItem>>,
}
#[turbo_tasks::value_impl]
......@@ -267,7 +276,7 @@ impl OutputAssetsReference for CssChunk {
.chunk_items
.iter()
.map(|item| async {
let refs = item.references().await?;
let refs = OutputAssetsReference::references(**item).await?;
let single_css_chunk = if should_generate_single_item_chunks {
Some(ResolvedVc::upcast(
SingleItemCssChunk::new(*this.chunking_context, **item)
......@@ -357,15 +366,25 @@ impl OutputChunk for CssChunk {
let entries_chunk_items = &content.chunk_items;
let included_ids = entries_chunk_items
.iter()
.map(|chunk_item| chunk_item.id())
.map(|chunk_item| (**chunk_item).id())
.try_join()
.await?;
let imports_chunk_items: Vec<_> = entries_chunk_items
.iter()
.map(|&css_item| async move {
Ok(css_item
.content()
.await?
let css_item_data = css_item.await?;
let Some(placeable) =
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(css_item_data.module)
else {
return Ok(Vec::new());
};
let content = placeable
.chunk_item_content(
*css_item_data.chunking_context,
*css_item_data.module_graph,
)
.await?;
Ok(content
.imports
.iter()
.filter_map(|import| {
......@@ -439,19 +458,34 @@ impl GenerateSourceMap for CssChunk {
}
}
// TODO: remove
#[turbo_tasks::value_trait]
pub trait CssChunkPlaceable: ChunkableModule + Module {}
pub trait CssChunkPlaceable: Module {
#[turbo_tasks::function]
fn chunk_item_content(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
) -> Vc<CssChunkItemContent>;
/// Returns the output assets associated with this module's chunk item.
/// Most CSS modules have no output assets; override for modules that produce
/// additional output (e.g. url references).
#[turbo_tasks::function]
fn chunk_item_output_assets(
self: Vc<Self>,
_chunking_context: Vc<Box<dyn ChunkingContext>>,
_module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> {
OutputAssetsWithReferenced::from_assets(*OutputAssets::empty_resolved())
}
}
#[derive(Clone, Debug)]
#[turbo_tasks::value(shared)]
pub enum CssImport {
External(ResolvedVc<RcStr>),
Internal(
ResolvedVc<ImportAssetReference>,
ResolvedVc<Box<dyn CssChunkItem>>,
),
Composes(ResolvedVc<Box<dyn CssChunkItem>>),
Internal(ResolvedVc<ImportAssetReference>, ResolvedVc<ChunkItem>),
Composes(ResolvedVc<ChunkItem>),
}
#[derive(Debug)]
......@@ -463,12 +497,6 @@ pub struct CssChunkItemContent {
pub source_map: ResolvedVc<FileContent>,
}
#[turbo_tasks::value_trait]
pub trait CssChunkItem: ChunkedItem + OutputAssetsReference {
#[turbo_tasks::function]
fn content(self: Vc<Self>) -> Vc<CssChunkItemContent>;
}
#[turbo_tasks::value_impl]
impl Introspectable for CssChunk {
#[turbo_tasks::function]
......@@ -534,6 +562,10 @@ impl ChunkType for CssChunkType {
Vc::cell(true)
}
fn accepts_module(&self, module: ResolvedVc<Box<dyn Module>>) -> bool {
ResolvedVc::try_sidecast::<Box<dyn CssChunkPlaceable>>(module).is_some()
}
#[turbo_tasks::function]
async fn chunk(
&self,
......@@ -557,17 +589,8 @@ impl ChunkType for CssChunkType {
let content = CssChunkContent {
chunk_items: chunk_items
.iter()
.map(async |ChunkItemWithAsyncModuleInfo { chunk_item, .. }| {
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *chunk_item.await?;
let Some(chunk_item) = ResolvedVc::try_downcast::<Box<dyn CssChunkItem>>(inner)
else {
bail!("Chunk item is not an css chunk item but reporting chunk type css");
};
// CSS doesn't need to care about async_info, so we can discard it
Ok(chunk_item)
})
.try_join()
.await?,
.map(|ChunkItemWithAsyncModuleInfo { chunk_item, .. }| *chunk_item)
.collect(),
}
.cell();
Ok(Vc::upcast(CssChunk::new(*chunking_context, content)))
......@@ -580,13 +603,32 @@ impl ChunkType for CssChunkType {
chunk_item: Vc<ChunkItem>,
_async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<usize>> {
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *chunk_item.await?;
let Some(chunk_item) = ResolvedVc::try_downcast::<Box<dyn CssChunkItem>>(inner) else {
bail!("Chunk item is not an css chunk item but reporting chunk type css");
let chunk_item = chunk_item.await?;
let Some(module) =
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(chunk_item.module)
else {
bail!("Chunk item is not a css chunk item but reporting chunk type css");
};
Ok(Vc::cell(chunk_item.content().await.map_or(0, |content| {
round_chunk_item_size(content.inner_code.len())
})))
Ok(Vc::cell(
module
.chunk_item_content(*chunk_item.chunking_context, *chunk_item.module_graph)
.await
.map_or(0, |content| round_chunk_item_size(content.inner_code.len())),
))
}
#[turbo_tasks::function]
fn chunk_item_output_assets(
&self,
module: ResolvedVc<Box<dyn Module>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> {
if let Some(placeable) = ResolvedVc::try_sidecast::<Box<dyn CssChunkPlaceable>>(module) {
placeable.chunk_item_output_assets(chunking_context, module_graph)
} else {
OutputAssetsWithReferenced::from_assets(*OutputAssets::empty_resolved())
}
}
}
......
......@@ -6,7 +6,7 @@ use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath, rope::RopeBuilder};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{Chunk, ChunkedItem, ChunkingContext, MinifyType},
chunk::{Chunk, ChunkItem, ChunkingContext, MinifyType},
code_builder::{Code, CodeBuilder},
ident::AssetIdent,
introspect::Introspectable,
......@@ -15,7 +15,7 @@ use turbopack_core::{
};
use super::source_map::SingleItemCssChunkSourceMapAsset;
use crate::chunk::{CssChunkItem, write_import_context};
use crate::chunk::{CssChunkPlaceable, write_import_context};
/// A CSS chunk that only contains a single item. This is used for selectively
/// loading CSS modules that are part of a larger chunk in development mode, and
......@@ -23,7 +23,7 @@ use crate::chunk::{CssChunkItem, write_import_context};
#[turbo_tasks::value]
pub struct SingleItemCssChunk {
pub(super) chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
item: ResolvedVc<Box<dyn CssChunkItem>>,
item: ResolvedVc<ChunkItem>,
}
#[turbo_tasks::value_impl]
......@@ -32,7 +32,7 @@ impl SingleItemCssChunk {
#[turbo_tasks::function]
pub fn new(
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
item: ResolvedVc<Box<dyn CssChunkItem>>,
item: ResolvedVc<ChunkItem>,
) -> Vc<Self> {
SingleItemCssChunk {
chunking_context,
......@@ -63,7 +63,15 @@ impl SingleItemCssChunk {
let id = this.item.asset_ident().to_string().await?;
writeln!(code, "/* {id} */")?;
}
let content = this.item.content().await?;
let item_data = this.item.await?;
let Some(placeable) =
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(item_data.module)
else {
return Ok(code.build().cell());
};
let content = placeable
.chunk_item_content(*item_data.chunking_context, *item_data.module_graph)
.await?;
let close = write_import_context(&mut code, content.import_context).await?;
code.push_source(
......
......@@ -241,8 +241,6 @@ impl ModuleCssAsset {
}
}
turbopack_core::chunk_item!(ModuleCssAsset, ecmascript);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for ModuleCssAsset {
#[turbo_tasks::function]
......
......@@ -10,11 +10,10 @@ use turbo_tasks_hash::{Xxh3Hash64Hasher, encode_hex};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{
ChunkableModule, ChunkingContext, ChunkingContextExt, EvaluatableAssets,
availability_info::AvailabilityInfo,
ChunkItem, ChunkingContextExt, EvaluatableAssets, availability_info::AvailabilityInfo,
},
module::Module,
module_graph::{ModuleGraph, chunk_group_info::ChunkGroup},
module_graph::chunk_group_info::ChunkGroup,
output::{OutputAsset, OutputAssetsReference, OutputAssetsWithReferenced},
version::{Version, VersionedContent},
};
......@@ -23,9 +22,7 @@ use turbopack_core::{
Clone, Debug, Eq, Hash, NonLocalValue, PartialEq, TaskInput, TraceRawVcs, Encode, Decode,
)]
pub struct DevHtmlEntry {
pub chunkable_module: ResolvedVc<Box<dyn ChunkableModule>>,
pub module_graph: ResolvedVc<ModuleGraph>,
pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub chunk_item: ResolvedVc<ChunkItem>,
pub runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
}
......@@ -136,15 +133,18 @@ impl DevHtmlAsset {
.iter()
.map(|entry| async move {
let &DevHtmlEntry {
chunkable_module,
chunking_context,
module_graph,
chunk_item,
runtime_entries,
} = entry;
let chunk_item = chunk_item.await?;
let module = chunk_item.module;
let chunking_context = chunk_item.chunking_context;
let module_graph = chunk_item.module_graph;
let asset_with_referenced = if let Some(runtime_entries) = runtime_entries {
let runtime_entries =
if let Some(evaluatable) = ResolvedVc::try_downcast(chunkable_module) {
if let Some(evaluatable) = ResolvedVc::try_downcast(module) {
runtime_entries
.with_entry(*evaluatable)
.to_resolved()
......@@ -154,7 +154,7 @@ impl DevHtmlAsset {
};
chunking_context
.evaluated_chunk_group_assets(
chunkable_module.ident(),
module.ident(),
ChunkGroup::Entry(
runtime_entries
.await?
......@@ -169,8 +169,8 @@ impl DevHtmlAsset {
} else {
chunking_context
.root_chunk_group_assets(
chunkable_module.ident(),
ChunkGroup::Entry(vec![ResolvedVc::upcast(chunkable_module)]),
module.ident(),
ChunkGroup::Entry(vec![module]),
*module_graph,
)
.await?
......
......@@ -5,8 +5,8 @@ use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkData, ChunkableModule, ChunkingContext, ChunkingContextExt,
ChunksData, ModuleChunkItemIdExt, availability_info::AvailabilityInfo,
AsyncModuleInfo, ChunkData, ChunkingContext, ChunkingContextExt, ChunksData,
ModuleChunkItemIdExt, availability_info::AvailabilityInfo,
},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
......@@ -30,7 +30,7 @@ use crate::{
/// putting it into a separate chunk group.
#[turbo_tasks::value]
pub struct AsyncLoaderModule {
pub inner: ResolvedVc<Box<dyn ChunkableModule>>,
pub inner: ResolvedVc<Box<dyn Module>>,
pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub availability_info: AvailabilityInfo,
}
......@@ -39,7 +39,7 @@ pub struct AsyncLoaderModule {
impl AsyncLoaderModule {
#[turbo_tasks::function]
pub fn new(
module: ResolvedVc<Box<dyn ChunkableModule>>,
module: ResolvedVc<Box<dyn Module>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
availability_info: AvailabilityInfo,
) -> Vc<Self> {
......@@ -51,7 +51,7 @@ impl AsyncLoaderModule {
}
#[turbo_tasks::function]
pub fn asset_ident_for(module: Vc<Box<dyn ChunkableModule>>) -> Vc<AssetIdent> {
pub fn asset_ident_for(module: Vc<Box<dyn Module>>) -> Vc<AssetIdent> {
module.ident().with_modifier(rcstr!("async loader"))
}
......@@ -61,9 +61,9 @@ impl AsyncLoaderModule {
module_graph: Vc<ModuleGraph>,
) -> Result<Vc<OutputAssetsWithReferenced>> {
if let Some(chunk_items) = self.availability_info.available_modules() {
let inner_module = ResolvedVc::upcast(self.inner);
let inner_module = self.inner;
let batches = module_graph
.module_batches(self.chunking_context.batching_config())
.module_batches(self.chunking_context.chunking_configs())
.await?;
let module_or_batch = batches.get_entry(inner_module).await?;
if let Some(chunkable_module_or_batch) =
......@@ -80,7 +80,7 @@ impl AsyncLoaderModule {
}
Ok(self.chunking_context.chunk_group_assets(
self.inner.ident(),
ChunkGroup::Async(ResolvedVc::upcast(self.inner)),
ChunkGroup::Async(self.inner),
module_graph,
self.availability_info,
))
......@@ -119,12 +119,9 @@ impl Module for AsyncLoaderModule {
#[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast(
SingleModuleReference::new(
*ResolvedVc::upcast(self.await?.inner),
rcstr!("async module"),
)
.to_resolved()
.await?,
SingleModuleReference::new(*self.await?.inner, rcstr!("async module"))
.to_resolved()
.await?,
)]))
}
......@@ -134,8 +131,6 @@ impl Module for AsyncLoaderModule {
}
}
turbopack_core::chunk_item!(AsyncLoaderModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for AsyncLoaderModule {
#[turbo_tasks::function]
......
......@@ -38,13 +38,13 @@ impl EcmascriptChunkItemOrBatchWithAsyncInfo {
})
}
pub fn references(&self) -> Vc<OutputAssetsWithReferenced> {
match self {
pub async fn references(&self) -> Result<Vc<OutputAssetsWithReferenced>> {
Ok(match self {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(item) => {
item.chunk_item.references()
item.chunk_item().await?.references()
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => batch.references(),
}
})
}
}
......@@ -76,7 +76,7 @@ impl EcmascriptChunkBatchWithAsyncInfo {
let mut references = Vec::new();
// We expect most references to be empty, and avoiding try_join to avoid allocating the Vec
for item in &self.chunk_items {
let r = item.chunk_item.references().await?;
let r = item.chunk_item().await?.references().await?;
output_assets.extend(r.assets.await?);
referenced_output_assets.extend(r.referenced_assets.await?);
references.extend(r.references.await?);
......
use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueDefault, ValueToString, Vc};
use turbopack_core::chunk::{
AsyncModuleInfo, Chunk, ChunkItem, ChunkItemBatchGroup, ChunkItemOrBatchWithAsyncModuleInfo,
ChunkType, ChunkedItem, ChunkingContext, round_chunk_item_size,
use turbopack_core::{
chunk::{
AsyncModuleInfo, Chunk, ChunkItem, ChunkItemBatchGroup,
ChunkItemOrBatchWithAsyncModuleInfo, ChunkType, ChunkingContext, round_chunk_item_size,
},
ident::AssetIdent,
module::Module,
module_graph::ModuleGraph,
output::{OutputAssets, OutputAssetsWithReferenced},
};
use super::{EcmascriptChunk, EcmascriptChunkContent, EcmascriptChunkItem};
use crate::chunk::batch::{EcmascriptChunkItemBatchGroup, EcmascriptChunkItemOrBatchWithAsyncInfo};
use super::{EcmascriptChunk, EcmascriptChunkContent};
use crate::chunk::{
batch::{EcmascriptChunkItemBatchGroup, EcmascriptChunkItemOrBatchWithAsyncInfo},
placeable::EcmascriptChunkPlaceable,
};
#[turbo_tasks::value]
#[derive(Default, ValueToString)]
......@@ -20,6 +29,10 @@ impl ChunkType for EcmascriptChunkType {
Vc::cell(false)
}
fn accepts_module(&self, module: ResolvedVc<Box<dyn Module>>) -> bool {
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module).is_some()
}
#[turbo_tasks::function]
async fn chunk(
&self,
......@@ -53,17 +66,55 @@ impl ChunkType for EcmascriptChunkType {
chunk_item: Vc<ChunkItem>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<usize>> {
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *chunk_item.await?;
let Some(chunk_item) = ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(inner)
let chunk_item = chunk_item.await?;
let module = chunk_item.module;
let Some(module) = ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkPlaceable>>(module)
else {
bail!("Chunk item is not an ecmascript chunk item but reporting chunk type ecmascript");
};
Ok(Vc::cell(
chunk_item
.content_with_async_module_info(async_module_info, true)
.await
.map_or(0, |content| round_chunk_item_size(content.inner_code.len())),
))
let content = module
.chunk_item_content(
*chunk_item.chunking_context,
*chunk_item.module_graph,
async_module_info,
true,
)
.await;
Ok(Vc::cell(content.map_or(0, |content| {
round_chunk_item_size(content.inner_code.len())
})))
}
#[turbo_tasks::function]
fn chunk_item_content_ident(
&self,
module: ResolvedVc<Box<dyn Module>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
) -> Vc<AssetIdent> {
if let Some(placeable) =
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module)
{
placeable.chunk_item_content_ident(chunking_context, module_graph)
} else {
module.ident()
}
}
#[turbo_tasks::function]
fn chunk_item_output_assets(
&self,
module: ResolvedVc<Box<dyn Module>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> {
if let Some(placeable) =
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module)
{
placeable.chunk_item_output_assets(chunking_context, module_graph)
} else {
OutputAssetsWithReferenced::from_assets(*OutputAssets::empty_resolved())
}
}
}
......
......@@ -8,8 +8,8 @@ use turbopack_core::{
};
use crate::chunk::{
EcmascriptChunkItemBatchGroup, EcmascriptChunkItemExt, EcmascriptChunkItemOrBatchWithAsyncInfo,
EcmascriptChunkItemWithAsyncInfo,
EcmascriptChunkItemBatchGroup, EcmascriptChunkItemOrBatchWithAsyncInfo,
ecmascript_chunk_item_code,
};
#[turbo_tasks::value(transparent, serialization = "none")]
......@@ -42,13 +42,14 @@ pub async fn item_code_and_ids(
item: EcmascriptChunkItemOrBatchWithAsyncInfo,
) -> Result<Vc<CodeAndIds>> {
Ok(Vc::cell(match item {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(EcmascriptChunkItemWithAsyncInfo {
chunk_item,
async_info,
..
}) => {
let id = chunk_item.id().await?;
let code = chunk_item.code(async_info.map(|info| *info));
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(ref info) => {
let id = info.chunk_item().await?.id().await?;
let code = ecmascript_chunk_item_code(
info.module,
info.chunking_context,
info.module_graph,
info.async_info.map(|info| *info),
);
smallvec![(id, code.await?)]
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => batch
......@@ -57,10 +58,14 @@ pub async fn item_code_and_ids(
.iter()
.map(|item| async {
Ok((
item.chunk_item.id().await?,
item.chunk_item
.code(item.async_info.map(|info| *info))
.await?,
item.chunk_item().await?.id().await?,
ecmascript_chunk_item_code(
item.module,
item.chunking_context,
item.module_graph,
item.async_info.map(|info| *info),
)
.await?,
))
})
.try_join()
......
use std::future::IntoFuture;
use anyhow::Result;
use either::Either;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::chunk::{ChunkItem, ChunkItems, ChunkedItem, batch_info};
use turbo_tasks::{ReadRef, ResolvedVc, Vc};
use turbopack_core::chunk::{ChunkItem, ChunkItems, batch_info};
use crate::chunk::{
CodeAndIds,
......@@ -21,31 +20,21 @@ pub struct EcmascriptChunkContent {
impl EcmascriptChunkContent {
#[turbo_tasks::function]
pub async fn included_chunk_items(&self) -> Result<Vc<ChunkItems>> {
Ok(ChunkItems(
self.chunk_items
.iter()
.map(async |item| match item {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(item) => {
Ok(Either::Left(item.chunk_item))
let mut result: Vec<ResolvedVc<ChunkItem>> = Vec::new();
for item in &self.chunk_items {
match item {
EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(item) => {
result.push(item.chunk_item().await?);
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => {
let batch = batch.await?;
for item in &batch.chunk_items {
result.push(item.chunk_item().await?);
}
EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => {
Ok(Either::Right(batch.await?))
}
})
.try_join()
.await?
.iter()
.flat_map(|item| match item {
Either::Left(item) => Either::Left(std::iter::once(*item)),
Either::Right(batch) => {
Either::Right(batch.chunk_items.iter().map(|item| item.chunk_item))
}
})
.map(ResolvedVc::upcast::<Box<dyn ChunkedItem>>)
.map(|item| ChunkItem(item).resolved_cell())
.collect(),
)
.cell())
}
}
}
Ok(ChunkItems(result).cell())
}
}
......
......@@ -5,27 +5,24 @@ use bincode::{Decode, Encode};
use smallvec::SmallVec;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
NonLocalValue, PrettyPrintError, ResolvedVc, TaskInput, Upcast, ValueToString, Vc,
trace::TraceRawVcs,
NonLocalValue, PrettyPrintError, ResolvedVc, TaskInput, ValueToString, Vc, trace::TraceRawVcs,
};
use turbo_tasks_fs::{FileSystemPath, rope::Rope};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkItemWithAsyncModuleInfo, ChunkType, ChunkedItem, ChunkingContext,
AsyncModuleInfo, ChunkItem, ChunkItemWithAsyncModuleInfo, ChunkingContext,
ChunkingContextExt, ModuleId, SourceMapSourceType,
},
code_builder::{Code, CodeBuilder},
ident::AssetIdent,
issue::{IssueExt, IssueSeverity, StyledString, code_gen::CodeGenerationIssue},
module::Module,
module_graph::ModuleGraph,
output::OutputAssetsReference,
source_map::utils::{absolute_fileify_source_map, relative_fileify_source_map},
};
use crate::{
EcmascriptModuleContent,
chunk::{chunk_type::EcmascriptChunkType, placeable::EcmascriptChunkPlaceable},
chunk::placeable::EcmascriptChunkPlaceable,
references::async_module::{AsyncModuleOptions, OptionAsyncModuleOptions},
runtime_functions::TURBOPACK_ASYNC_MODULE,
utils::StringifyJs,
......@@ -125,7 +122,7 @@ impl EcmascriptChunkItemContent {
}
impl EcmascriptChunkItemContent {
async fn module_factory(&self) -> Result<ResolvedVc<Code>> {
pub(crate) async fn module_factory(&self) -> Result<ResolvedVc<Code>> {
let mut code = CodeBuilder::default();
for additional_id in self.additional_ids.iter() {
writeln!(code, "{}, ", StringifyJs(&additional_id))?;
......@@ -201,7 +198,9 @@ pub struct EcmascriptChunkItemOptions {
Debug, Clone, PartialEq, Eq, Hash, TraceRawVcs, TaskInput, NonLocalValue, Encode, Decode,
)]
pub struct EcmascriptChunkItemWithAsyncInfo {
pub chunk_item: ResolvedVc<Box<dyn EcmascriptChunkItem>>,
pub module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub module_graph: ResolvedVc<ModuleGraph>,
pub async_info: Option<ResolvedVc<AsyncModuleInfo>>,
}
......@@ -214,59 +213,56 @@ impl EcmascriptChunkItemWithAsyncInfo {
module: _,
async_info,
} = chunk_item;
let inner: ResolvedVc<Box<dyn ChunkedItem>> = *chunk_item.await?;
let Some(chunk_item) = ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(inner)
let chunk_item_data = chunk_item.await?;
let Some(module) =
ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkPlaceable>>(chunk_item_data.module)
else {
bail!("Chunk item is not an ecmascript chunk item but reporting chunk type ecmascript");
};
Ok(EcmascriptChunkItemWithAsyncInfo {
chunk_item,
module,
chunking_context: chunk_item_data.chunking_context,
module_graph: chunk_item_data.module_graph,
async_info: *async_info,
})
}
}
#[turbo_tasks::value_trait]
pub trait EcmascriptChunkItem: ChunkedItem + OutputAssetsReference {
#[turbo_tasks::function]
fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent>;
/// Fetches the content of the chunk item with async module info.
/// When `estimated` is true, it's ok to provide an estimated content, since it's only used for
/// compute the chunking. When `estimated` is true, this function should not invoke other
/// chunking operations that would cause cycles.
#[turbo_tasks::function]
fn content_with_async_module_info(
self: Vc<Self>,
_async_module_info: Option<Vc<AsyncModuleInfo>>,
_estimated: bool,
) -> Vc<EcmascriptChunkItemContent> {
self.content()
/// The [ChunkItem] for this ecmascript chunk item.
pub async fn chunk_item(&self) -> Result<ResolvedVc<ChunkItem>> {
ChunkItem::new(
*ResolvedVc::upcast(self.module),
*self.module_graph,
*self.chunking_context,
)
.to_resolved()
.await
}
}
pub trait EcmascriptChunkItemExt {
/// Generates the module factory for this chunk item.
fn code(self: Vc<Self>, async_module_info: Option<Vc<AsyncModuleInfo>>) -> Vc<Code>;
}
impl<T> EcmascriptChunkItemExt for T
where
T: Upcast<Box<dyn EcmascriptChunkItem>>,
{
/// Generates the module factory for this chunk item.
fn code(self: Vc<Self>, async_module_info: Option<Vc<AsyncModuleInfo>>) -> Vc<Code> {
module_factory_with_code_generation_issue(Vc::upcast_non_strict(self), async_module_info)
}
/// Generates the module factory for the given ecmascript module.
pub fn ecmascript_chunk_item_code(
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
module_graph: ResolvedVc<ModuleGraph>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Vc<Code> {
module_factory_with_code_generation_issue(
*module,
*chunking_context,
*module_graph,
async_module_info,
)
}
#[turbo_tasks::function]
async fn module_factory_with_code_generation_issue(
chunk_item: Vc<Box<dyn EcmascriptChunkItem>>,
module: Vc<Box<dyn EcmascriptChunkPlaceable>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Result<Vc<Code>> {
let content = match chunk_item
.content_with_async_module_info(async_module_info, false)
let content = match module
.chunk_item_content(chunking_context, module_graph, async_module_info, false)
.await
{
Ok(item) => item.module_factory().await,
......@@ -275,7 +271,7 @@ async fn module_factory_with_code_generation_issue(
Ok(match content {
Ok(factory) => *factory,
Err(error) => {
let id = chunk_item.asset_ident().to_string().await;
let id = module.ident().to_string().await;
let id = id.as_ref().map_or_else(|_| "unknown", |id| &**id);
let error = error.context(format!(
"An error occurred while generating the chunk item {id}"
......@@ -284,7 +280,7 @@ async fn module_factory_with_code_generation_issue(
let js_error_message = serde_json::to_string(&error_message)?;
CodeGenerationIssue {
severity: IssueSeverity::Error,
path: chunk_item.asset_ident().path().owned().await?,
path: module.ident().path().owned().await?,
title: StyledString::Text(rcstr!("Code generation for chunk item errored"))
.resolved_cell(),
message: StyledString::Text(error_message).resolved_cell(),
......@@ -300,88 +296,3 @@ async fn module_factory_with_code_generation_issue(
}
})
}
/// Generic chunk item that wraps any EcmascriptChunkPlaceable module.
/// This replaces the need for individual per-module ChunkItem wrapper structs.
#[turbo_tasks::value]
pub struct EcmascriptModuleChunkItem {
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
module_graph: ResolvedVc<ModuleGraph>,
}
/// Factory function to create an EcmascriptModuleChunkItem.
/// Use this instead of implementing ChunkableModule::as_chunk_item() on each module.
pub fn ecmascript_chunk_item(
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Vc<EcmascriptModuleChunkItem> {
EcmascriptModuleChunkItem {
module,
chunking_context,
module_graph,
}
.cell()
}
#[turbo_tasks::value_impl]
impl ChunkedItem for EcmascriptModuleChunkItem {
#[turbo_tasks::function]
fn asset_ident(&self) -> Vc<AssetIdent> {
self.module.ident()
}
#[turbo_tasks::function]
fn content_ident(&self) -> Vc<AssetIdent> {
self.module
.chunk_item_content_ident(*self.chunking_context, *self.module_graph)
}
#[turbo_tasks::function]
fn ty(&self) -> Vc<Box<dyn ChunkType>> {
Vc::upcast(Vc::<EcmascriptChunkType>::default())
}
#[turbo_tasks::function]
fn module(&self) -> Vc<Box<dyn Module>> {
Vc::upcast(*self.module)
}
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptModuleChunkItem {
#[turbo_tasks::function]
fn references(&self) -> Vc<turbopack_core::output::OutputAssetsWithReferenced> {
self.module
.chunk_item_output_assets(*self.chunking_context, *self.module_graph)
}
}
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for EcmascriptModuleChunkItem {
#[turbo_tasks::function]
fn content(&self) -> Vc<EcmascriptChunkItemContent> {
self.module
.chunk_item_content(*self.chunking_context, *self.module_graph, None, false)
}
#[turbo_tasks::function]
fn content_with_async_module_info(
&self,
async_module_info: Option<Vc<AsyncModuleInfo>>,
estimated: bool,
) -> Vc<EcmascriptChunkItemContent> {
self.module.chunk_item_content(
*self.chunking_context,
*self.module_graph,
async_module_info,
estimated,
)
}
}
......@@ -33,8 +33,8 @@ pub use self::{
content::EcmascriptChunkContent,
data::EcmascriptChunkData,
item::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemExt,
EcmascriptChunkItemOptions, EcmascriptChunkItemWithAsyncInfo, ecmascript_chunk_item,
EcmascriptChunkItemContent, EcmascriptChunkItemOptions, EcmascriptChunkItemWithAsyncInfo,
ecmascript_chunk_item_code,
},
placeable::{EcmascriptChunkPlaceable, EcmascriptExports},
};
......@@ -75,7 +75,7 @@ impl OutputAssetsReference for EcmascriptChunk {
.chunk_items
.iter()
.map(async |with_info| {
let r = with_info.references().await?;
let r = with_info.references().await?.await?;
Ok((
r.assets.await?,
r.referenced_assets.await?,
......
......@@ -9,7 +9,7 @@ use turbo_tasks_fs::{
};
use turbopack_core::{
asset::Asset,
chunk::{AsyncModuleInfo, ChunkableModule, ChunkingContext},
chunk::{AsyncModuleInfo, ChunkingContext},
file_source::FileSource,
ident::AssetIdent,
issue::{
......@@ -31,7 +31,7 @@ use crate::{
};
#[turbo_tasks::value_trait]
pub trait EcmascriptChunkPlaceable: ChunkableModule + Module {
pub trait EcmascriptChunkPlaceable: Module {
#[turbo_tasks::function]
fn get_exports(self: Vc<Self>) -> Vc<EcmascriptExports>;
#[turbo_tasks::function]
......@@ -52,9 +52,9 @@ pub trait EcmascriptChunkPlaceable: ChunkableModule + Module {
_estimated: bool,
) -> Vc<EcmascriptChunkItemContent>;
/// Returns the content identity for cache invalidation.
/// Override this for modules whose content depends on more than just the module source
/// (e.g., async loaders that depend on available modules).
/// A [AssetIdent] that uniquely identifies the content of this module's chunk item.
/// It is usually identical to the module's ident but can be different when the chunk item
/// content depends on available modules e.g. for chunk loaders.
#[turbo_tasks::function]
fn chunk_item_content_ident(
self: Vc<Self>,
......@@ -64,15 +64,16 @@ pub trait EcmascriptChunkPlaceable: ChunkableModule + Module {
self.ident()
}
/// Returns output assets that this chunk item depends on.
/// Override this for modules that reference static assets, manifests, etc.
/// Returns the output assets associated with this module's chunk item.
/// Most modules have no output assets; override for modules that produce
/// additional output (e.g. chunk loaders, external modules, static assets).
#[turbo_tasks::function]
fn chunk_item_output_assets(
self: Vc<Self>,
_chunking_context: Vc<Box<dyn ChunkingContext>>,
_module_graph: Vc<ModuleGraph>,
) -> Vc<OutputAssetsWithReferenced> {
OutputAssetsWithReferenced::from_assets(OutputAssets::empty())
OutputAssetsWithReferenced::from_assets(*OutputAssets::empty_resolved())
}
}
......
......@@ -83,7 +83,7 @@ use turbo_tasks::{
use turbo_tasks_fs::{FileJsonContent, FileSystemPath, glob::Glob, rope::Rope};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkableModule, ChunkingContext, EvaluatableAsset, MergeableModule,
AsyncModuleInfo, ChunkingContext, EvaluatableAsset, MergeableModule,
MergeableModuleExposure, MergeableModules, MergeableModulesExposed, MinifyType,
ModuleChunkItemIdExt, ModuleId,
},
......@@ -95,7 +95,7 @@ use turbopack_core::{
reference::ModuleReferences,
reference_type::InnerAssets,
resolve::{
FindContextFileResult, ModulePart, find_context_file, origin::ResolveOrigin, package_json,
FindContextFileResult, find_context_file, origin::ResolveOrigin, package_json,
parse::Request,
},
source::Source,
......@@ -118,7 +118,8 @@ use crate::{
esm::{UrlRewriteBehavior, base::EsmAssetReferences, export},
},
side_effect_optimization::{
facade::module::EcmascriptModuleFacadeModule, locals::module::EcmascriptModuleLocalsModule,
facade::module::EcmascriptModuleFacadeModule,
locals::module::EcmascriptModuleLocalsModule,
reference::EcmascriptModulePartReference,
},
swc_comments::{CowComments, ImmutableComments},
......@@ -698,6 +699,42 @@ impl EcmascriptModuleAsset {
pub fn options(&self) -> Vc<EcmascriptOptions> {
*self.options
}
/// Returns the locals module if the module should be split (has re-exports), otherwise self.
///
/// The locals module only contains the local bindings of the original module,
/// excluding any re-exports.
#[turbo_tasks::function]
pub async fn get_locals_if_split(
self: Vc<Self>,
) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
let should_split = *self.get_exports().split_locals_and_reexports().await?;
Ok(if should_split {
Vc::upcast(EcmascriptModuleLocalsModule::new(self))
} else {
Vc::upcast(self)
})
}
/// Returns the facade module if the module should be split (has re-exports), otherwise self.
///
/// The facade module re-exports all exports from the original module, including
/// both local bindings (via the locals module) and re-exports from other modules.
#[turbo_tasks::function]
pub async fn get_facade_if_split(
self: Vc<Self>,
) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
use turbopack_core::resolve::ModulePart;
let should_split = *self.get_exports().split_locals_and_reexports().await?;
Ok(if should_split {
Vc::upcast(EcmascriptModuleFacadeModule::new(
Vc::upcast(self),
ModulePart::Facade,
))
} else {
Vc::upcast(self)
})
}
}
impl EcmascriptModuleAsset {
......@@ -783,8 +820,6 @@ impl Module for EcmascriptModuleAsset {
}
}
turbopack_core::chunk_item!(EcmascriptModuleAsset, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for EcmascriptModuleAsset {
#[turbo_tasks::function]
......@@ -821,44 +856,6 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleAsset {
}
}
#[turbo_tasks::value_impl]
impl EcmascriptModuleAsset {
/// Returns the locals module if the module should be split (has re-exports), otherwise self.
///
/// The locals module contains only the local bindings and evaluation side effects,
/// while re-exports are handled separately by the facade module.
#[turbo_tasks::function]
pub async fn get_locals_if_split(
self: Vc<Self>,
) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
let should_split = *self.get_exports().split_locals_and_reexports().await?;
Ok(if should_split {
Vc::upcast(EcmascriptModuleLocalsModule::new(self))
} else {
Vc::upcast(self)
})
}
/// Returns the facade module if the module should be split (has re-exports), otherwise self.
///
/// The facade module re-exports all exports from the original module, including
/// both local bindings (via the locals module) and re-exports from other modules.
#[turbo_tasks::function]
pub async fn get_facade_if_split(
self: Vc<Self>,
) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
let should_split = *self.get_exports().split_locals_and_reexports().await?;
Ok(if should_split {
Vc::upcast(EcmascriptModuleFacadeModule::new(
Vc::upcast(self),
ModulePart::Facade,
))
} else {
Vc::upcast(self)
})
}
}
#[turbo_tasks::value_impl]
impl MergeableModule for EcmascriptModuleAsset {
#[turbo_tasks::function]
......@@ -878,7 +875,7 @@ impl MergeableModule for EcmascriptModuleAsset {
self: Vc<Self>,
modules: Vc<MergeableModulesExposed>,
entry_points: Vc<MergeableModules>,
) -> Result<Vc<Box<dyn ChunkableModule>>> {
) -> Result<Vc<Box<dyn Module>>> {
Ok(Vc::upcast(
*MergedEcmascriptModule::new(
modules,
......
......@@ -4,8 +4,8 @@ use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkData, ChunkableModule, ChunkingContext, ChunkingContextExt,
ChunksData, availability_info::AvailabilityInfo,
AsyncModuleInfo, ChunkData, ChunkingContext, ChunkingContextExt, ChunksData,
availability_info::AvailabilityInfo,
},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
......@@ -38,7 +38,7 @@ use crate::{
/// import appears in.
#[turbo_tasks::value(shared)]
pub struct ManifestAsyncModule {
pub inner: ResolvedVc<Box<dyn ChunkableModule>>,
pub inner: ResolvedVc<Box<dyn Module>>,
pub module_graph: ResolvedVc<ModuleGraph>,
pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub availability_info: AvailabilityInfo,
......@@ -48,7 +48,7 @@ pub struct ManifestAsyncModule {
impl ManifestAsyncModule {
#[turbo_tasks::function]
pub fn new(
module: ResolvedVc<Box<dyn ChunkableModule>>,
module: ResolvedVc<Box<dyn Module>>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
availability_info: AvailabilityInfo,
......@@ -65,7 +65,7 @@ impl ManifestAsyncModule {
pub(super) fn chunk_group(&self) -> Vc<OutputAssetsWithReferenced> {
self.chunking_context.chunk_group_assets(
self.inner.ident(),
ChunkGroup::Async(ResolvedVc::upcast(self.inner)),
ChunkGroup::Async(self.inner),
*self.module_graph,
self.availability_info,
)
......@@ -77,10 +77,10 @@ impl ManifestAsyncModule {
) -> Result<Vc<OutputAssetsWithReferenced>> {
let this = self.await?;
if let Some(chunk_items) = this.availability_info.available_modules() {
let inner_module = ResolvedVc::upcast(this.inner);
let inner_module = this.inner;
let batches = this
.module_graph
.module_batches(this.chunking_context.batching_config())
.module_batches(this.chunking_context.chunking_configs())
.await?;
let module_or_batch = batches.get_entry(inner_module).await?;
if let Some(chunkable_module_or_batch) =
......@@ -174,8 +174,6 @@ impl Module for ManifestAsyncModule {
}
}
turbopack_core::chunk_item!(ManifestAsyncModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for ManifestAsyncModule {
#[turbo_tasks::function]
......
......@@ -5,10 +5,7 @@ use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkData, ChunkableModule, ChunkingContext, ChunksData,
ModuleChunkItemIdExt,
},
chunk::{AsyncModuleInfo, ChunkData, ChunkingContext, ChunksData, ModuleChunkItemIdExt},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
module_graph::ModuleGraph,
......@@ -68,7 +65,7 @@ impl ManifestLoaderModule {
}
#[turbo_tasks::function]
pub fn asset_ident_for(module: Vc<Box<dyn ChunkableModule>>) -> Vc<AssetIdent> {
pub fn asset_ident_for(module: Vc<Box<dyn Module>>) -> Vc<AssetIdent> {
module.ident().with_modifier(modifier())
}
}
......@@ -96,8 +93,6 @@ impl Module for ManifestLoaderModule {
}
}
turbopack_core::chunk_item!(ManifestLoaderModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for ManifestLoaderModule {
#[turbo_tasks::function]
......@@ -184,7 +179,7 @@ impl EcmascriptChunkPlaceable for ManifestLoaderModule {
}
#[turbo_tasks::function]
fn chunk_item_output_assets(
async fn chunk_item_output_assets(
&self,
_chunking_context: Vc<Box<dyn ChunkingContext>>,
_module_graph: Vc<ModuleGraph>,
......
......@@ -88,8 +88,6 @@ impl Module for MergedEcmascriptModule {
}
}
turbopack_core::chunk_item!(MergedEcmascriptModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for MergedEcmascriptModule {
#[turbo_tasks::function]
......
......@@ -367,8 +367,6 @@ impl Module for CachedExternalModule {
}
}
turbopack_core::chunk_item!(CachedExternalModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for CachedExternalModule {
#[turbo_tasks::function]
......
......@@ -12,11 +12,11 @@ use swc_core::{
};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{
FxIndexMap, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Vc, debug::ValueDebugFormat,
FxIndexMap, NonLocalValue, TaskInput, TryJoinIterExt, Vc, debug::ValueDebugFormat,
trace::TraceRawVcs,
};
use turbopack_core::{
chunk::{ChunkableModule, ChunkingContext, ModuleChunkItemIdExt, ModuleId},
chunk::{ChunkingContext, ModuleChunkItemIdExt, ModuleId},
issue::{
Issue, IssueExt, IssueSeverity, StyledString, code_gen::CodeGenerationIssue,
module::emit_unknown_module_type_error,
......@@ -355,10 +355,16 @@ async fn to_single_pattern_mapping(
return Ok(SinglePatternMapping::Invalid);
}
};
if let Some(chunkable) = ResolvedVc::try_downcast::<Box<dyn ChunkableModule>>(module) {
if chunking_context
.chunking_configs()
.await?
.chunk_type(module)
.await
.is_some()
{
match resolve_type {
ResolveType::AsyncChunkLoader => {
let ident = chunking_context.async_loader_chunk_item_ident(*chunkable);
let ident = chunking_context.async_loader_chunk_item_ident(*module);
let loader_id = chunking_context
.chunk_item_id_strategy()
.await?
......@@ -367,16 +373,16 @@ async fn to_single_pattern_mapping(
return Ok(SinglePatternMapping::ModuleLoader(loader_id));
}
ResolveType::ChunkItem => {
let item_id = chunkable.chunk_item_id(chunking_context).await?;
let item_id = module.chunk_item_id(chunking_context).await?;
return Ok(SinglePatternMapping::Module(item_id));
}
}
}
CodeGenerationIssue {
severity: IssueSeverity::Bug,
title: StyledString::Text(rcstr!("non-ecmascript placeable asset")).resolved_cell(),
title: StyledString::Text(rcstr!("non-chunkable asset")).resolved_cell(),
message: StyledString::Text(rcstr!(
"asset is not placeable in ESM chunks, so it doesn't have a module id"
"asset is not chunkable, so it doesn't have a module id"
))
.resolved_cell(),
path: origin.origin_path().owned().await?,
......
......@@ -435,8 +435,6 @@ impl Module for RequireContextAsset {
}
}
turbopack_core::chunk_item!(RequireContextAsset, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for RequireContextAsset {
#[turbo_tasks::function]
......
......@@ -11,7 +11,7 @@ use turbo_tasks::{
};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
chunk::{ChunkableModule, ChunkingContext, ChunkingType, ChunkingTypeOption, EvaluatableAsset},
chunk::{ChunkingContext, ChunkingType, ChunkingTypeOption, EvaluatableAsset},
context::AssetContext,
issue::{IssueExt, IssueSeverity, IssueSource, StyledString, code_gen::CodeGenerationIssue},
module::Module,
......@@ -25,6 +25,7 @@ use turbopack_core::{
};
use crate::{
chunk::EcmascriptChunkPlaceable,
code_gen::{CodeGen, CodeGeneration, IntoCodeGenReference},
create_visitor,
references::{
......@@ -179,9 +180,9 @@ impl ModuleReference for WorkerAssetReference {
ModuleResolveResultItem::Module(module) => {
let module_ident = module.ident().to_string().await?;
let Some(chunkable) =
ResolvedVc::try_downcast::<Box<dyn ChunkableModule>>(*module)
else {
if ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*module)
.is_none()
{
CodeGenerationIssue {
severity: self.get_module_type_issue_severity().await?,
title: StyledString::Text(rcstr!("non-chunkable module"))
......@@ -202,13 +203,12 @@ impl ModuleReference for WorkerAssetReference {
.resolved_cell()
.emit();
continue;
};
}
// For Node.js worker threads, the module must also be evaluatable since
// it becomes an entry point
if matches!(self.worker_type, WorkerType::NodeWorkerThread)
&& ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(chunkable)
.is_none()
&& ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(*module).is_none()
{
CodeGenerationIssue {
severity: self.get_module_type_issue_severity().await?,
......@@ -234,7 +234,7 @@ impl ModuleReference for WorkerAssetReference {
}
let loader =
WorkerLoaderModule::new(*chunkable, self.worker_type, *asset_context)
WorkerLoaderModule::new(**module, self.worker_type, *asset_context)
.to_resolved()
.await?;
......
......@@ -4,8 +4,8 @@ use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkableModule, ChunkingContext, EvaluatableAsset, MergeableModule,
MergeableModules, MergeableModulesExposed,
AsyncModuleInfo, ChunkingContext, EvaluatableAsset, MergeableModule, MergeableModules,
MergeableModulesExposed,
},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
......@@ -364,11 +364,6 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
}
}
turbopack_core::chunk_item!(
EcmascriptModuleFacadeModule,
crate::chunk::ecmascript_chunk_item
);
#[turbo_tasks::value_impl]
impl EvaluatableAsset for EcmascriptModuleFacadeModule {}
......@@ -379,7 +374,7 @@ impl MergeableModule for EcmascriptModuleFacadeModule {
self: Vc<Self>,
modules: Vc<MergeableModulesExposed>,
entry_points: Vc<MergeableModules>,
) -> Result<Vc<Box<dyn ChunkableModule>>> {
) -> Result<Vc<Box<dyn Module>>> {
Ok(Vc::upcast(
*MergedEcmascriptModule::new(
modules,
......
......@@ -4,7 +4,7 @@ use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkableModule, ChunkingContext, MergeableModule, MergeableModules,
AsyncModuleInfo, ChunkingContext, MergeableModule, MergeableModules,
MergeableModulesExposed,
},
ident::AssetIdent,
......@@ -190,11 +190,6 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleLocalsModule {
}
}
turbopack_core::chunk_item!(
EcmascriptModuleLocalsModule,
crate::chunk::ecmascript_chunk_item
);
#[turbo_tasks::value_impl]
impl MergeableModule for EcmascriptModuleLocalsModule {
#[turbo_tasks::function]
......@@ -202,7 +197,7 @@ impl MergeableModule for EcmascriptModuleLocalsModule {
&self,
modules: Vc<MergeableModulesExposed>,
entry_points: Vc<MergeableModules>,
) -> Result<Vc<Box<dyn ChunkableModule>>> {
) -> Result<Vc<Box<dyn Module>>> {
Ok(Vc::upcast(
*MergedEcmascriptModule::new(modules, entry_points, self.module.await?.options).await?,
))
......
......@@ -369,11 +369,6 @@ impl EcmascriptChunkPlaceable for EcmascriptModulePartAsset {
}
}
turbopack_core::chunk_item!(
EcmascriptModulePartAsset,
crate::chunk::ecmascript_chunk_item
);
#[turbo_tasks::value_impl]
impl EcmascriptModulePartAsset {
#[turbo_tasks::function]
......
......@@ -202,7 +202,5 @@ impl EcmascriptChunkPlaceable for SideEffectsModule {
}
}
turbopack_core::chunk_item!(SideEffectsModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EvaluatableAsset for SideEffectsModule {}
......@@ -4,9 +4,9 @@ use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbopack_core::{
chunk::{
AsyncModuleInfo, ChunkData, ChunkGroupType, ChunkableModule, ChunkingContext,
ChunkingContextExt, ChunkingType, ChunkingTypeOption, ChunksData, EvaluatableAsset,
EvaluatableAssets, availability_info::AvailabilityInfo,
AsyncModuleInfo, ChunkData, ChunkGroupType, ChunkingContext, ChunkingContextExt,
ChunkingType, ChunkingTypeOption, ChunksData, EvaluatableAsset, EvaluatableAssets,
availability_info::AvailabilityInfo,
},
context::AssetContext,
ident::AssetIdent,
......@@ -32,7 +32,7 @@ use crate::{
/// constructor.
#[turbo_tasks::value]
pub struct WorkerLoaderModule {
pub inner: ResolvedVc<Box<dyn ChunkableModule>>,
pub inner: ResolvedVc<Box<dyn Module>>,
pub worker_type: WorkerType,
pub asset_context: ResolvedVc<Box<dyn AssetContext>>,
}
......@@ -41,7 +41,7 @@ pub struct WorkerLoaderModule {
impl WorkerLoaderModule {
#[turbo_tasks::function]
pub fn new(
module: ResolvedVc<Box<dyn ChunkableModule>>,
module: ResolvedVc<Box<dyn Module>>,
worker_type: WorkerType,
asset_context: ResolvedVc<Box<dyn AssetContext>>,
) -> Vc<Self> {
......@@ -65,7 +65,7 @@ impl WorkerLoaderModule {
this.inner
.ident()
.with_modifier(this.worker_type.chunk_modifier_str()),
ChunkGroup::Isolated(ResolvedVc::upcast(this.inner)),
ChunkGroup::Isolated(this.inner),
module_graph,
AvailabilityInfo::root(),
),
......@@ -161,7 +161,7 @@ impl Module for WorkerLoaderModule {
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let this = self.await?;
Ok(Vc::cell(vec![ResolvedVc::upcast(
WorkerModuleReference::new(*ResolvedVc::upcast(this.inner), this.worker_type)
WorkerModuleReference::new(*this.inner, this.worker_type)
.to_resolved()
.await?,
)]))
......@@ -173,8 +173,6 @@ impl Module for WorkerLoaderModule {
}
}
turbopack_core::chunk_item!(WorkerLoaderModule, crate::chunk::ecmascript_chunk_item);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for WorkerLoaderModule {
#[turbo_tasks::function]
......
......@@ -34,6 +34,7 @@ turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbopack-core = { workspace = true }
turbopack-css = { workspace = true }
turbopack-ecmascript = { workspace = true }
turbopack-ecmascript-runtime = { workspace = true }
......@@ -6,10 +6,9 @@ use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
asset::Asset,
chunk::{
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule,
ChunkingConfig, ChunkingConfigs, ChunkingContext, ChunkingContextExt,
EntryChunkGroupResult, EvaluatableAssets, MinifyType, SourceMapSourceType, SourceMapsType,
UnusedReferences, UrlBehavior,
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkingConfig,
ChunkingConfigs, ChunkingContext, EntryChunkGroupResult, EvaluatableAssets, MinifyType,
SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
availability_info::AvailabilityInfo,
chunk_group::{MakeChunkGroupResult, make_chunk_group},
chunk_id_strategy::ModuleIdStrategy,
......@@ -24,9 +23,10 @@ use turbopack_core::{
},
output::{OutputAsset, OutputAssets},
};
use turbopack_css::chunk::CssChunkType;
use turbopack_ecmascript::{
async_chunk::module::AsyncLoaderModule,
chunk::EcmascriptChunk,
chunk::{EcmascriptChunk, EcmascriptChunkType},
manifest::{chunk_asset::ManifestAsyncModule, loader_module::ManifestLoaderModule},
};
use turbopack_ecmascript_runtime::RuntimeType;
......@@ -448,8 +448,19 @@ impl ChunkingContext for NodeJsChunkingContext {
}
#[turbo_tasks::function]
fn chunking_configs(&self) -> Result<Vc<ChunkingConfigs>> {
Ok(Vc::cell(self.chunking_configs.iter().cloned().collect()))
async fn chunking_configs(&self) -> Result<Vc<ChunkingConfigs>> {
let mut configs = self.chunking_configs.clone();
let ecma_type: ResolvedVc<Box<dyn ChunkType>> =
ResolvedVc::upcast(Vc::<EcmascriptChunkType>::default().to_resolved().await?);
if !configs.iter().any(|(ty, _)| *ty == ecma_type) {
configs.push((ecma_type, ChunkingConfig::default()));
}
let css_type: ResolvedVc<Box<dyn ChunkType>> =
ResolvedVc::upcast(Vc::<CssChunkType>::default().to_resolved().await?);
if !configs.iter().any(|(ty, _)| *ty == css_type) {
configs.push((css_type, ChunkingConfig::default()));
}
Ok(ChunkingConfigs::new(configs))
}
#[turbo_tasks::function]
......@@ -636,7 +647,7 @@ impl ChunkingContext for NodeJsChunkingContext {
#[turbo_tasks::function]
async fn async_loader_chunk_item(
self: Vc<Self>,
module: Vc<Box<dyn ChunkableModule>>,
module: Vc<Box<dyn Module>>,
module_graph: Vc<ModuleGraph>,
availability_info: AvailabilityInfo,
) -> Result<Vc<ChunkItem>> {
......@@ -654,17 +665,17 @@ impl ChunkingContext for NodeJsChunkingContext {
.to_resolved()
.await?;
let loader_module = ManifestLoaderModule::new(*manifest_asset);
chunking_context.chunk_item(Vc::upcast(loader_module), module_graph)
ChunkItem::new(Vc::upcast(loader_module), module_graph, *chunking_context)
} else {
let module = AsyncLoaderModule::new(module, *chunking_context, availability_info);
chunking_context.chunk_item(Vc::upcast(module), module_graph)
ChunkItem::new(Vc::upcast(module), module_graph, *chunking_context)
})
}
#[turbo_tasks::function]
async fn async_loader_chunk_item_ident(
self: Vc<Self>,
module: Vc<Box<dyn ChunkableModule>>,
module: Vc<Box<dyn Module>>,
) -> Result<Vc<AssetIdent>> {
Ok(if self.await?.manifest_chunks {
ManifestLoaderModule::asset_ident_for(module)
......
......@@ -65,8 +65,6 @@ impl Module for StaticUrlJsModule {
}
}
turbopack_core::chunk_item!(StaticUrlJsModule, ecmascript);
#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for StaticUrlJsModule {
#[turbo_tasks::function]
......
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/ad3e4_tests_snapshot_basic-tree-shake_dynamic-import_input_index_7dac1ace.js",
{"otherChunks":["output/bf321_tests_snapshot_basic-tree-shake_dynamic-import_input_lib_ee638b2a.js","output/bf321_tests_snapshot_basic-tree-shake_dynamic-import_input_index_9775ceed.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/input/index.js [test] (ecmascript)"]}
"output/ad3e4_tests_snapshot_basic-tree-shake_dynamic-import_input_index_d8d543b1.js",
{"otherChunks":["output/bf321_tests_snapshot_basic-tree-shake_dynamic-import_input_index_9775ceed.js","output/bf321_tests_snapshot_basic-tree-shake_dynamic-import_input_lib_ee638b2a.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/dynamic-import/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
......@@ -3,7 +3,7 @@
__turbopack_context__.v((parentImport) => {
return Promise.all([
"output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_c52390c2._.js"
"output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_0b8573ac._.js"
].map((chunk) => __turbopack_context__.l(chunk))).then(() => {
return parentImport("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js [test] (ecmascript)");
});
......
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_df8dd76f._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/shared.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
// shared package
}),
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_ea8e1245.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
......@@ -16,17 +12,6 @@ __turbopack_context__.A("[project]/turbopack/crates/turbopack-tests/tests/snapsh
foo(true);
});
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/bar/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([
"bar",
()=>bar
]);
function bar(value) {
console.assert(value);
}
}),
]);
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_df8dd76f._.js.map
\ No newline at end of file
//# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_ea8e1245.js.map
\ No newline at end of file
......@@ -2,7 +2,5 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 3, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/shared.js"],"sourcesContent":["// shared package\n"],"names":[],"mappings":"AAAA,iBAAiB"}},
{"offset": {"line": 8, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js"],"sourcesContent":["import { bar } from 'bar'\nimport './shared'\n\nbar(true)\n\nimport('./import').then(({ foo }) => {\n foo(true)\n})\n"],"names":["then","foo"],"mappings":";AAAA;AACA;;;AAEA,IAAA,gOAAG,EAAC;AAEJ,yJAAmBA,IAAI,CAAC,CAAC,EAAEC,GAAG,EAAE;IAC9BA,IAAI;AACN"}},
{"offset": {"line": 21, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/bar/index.js"],"sourcesContent":["export function bar(value) {\n console.assert(value);\n}\n"],"names":["bar","value","console","assert"],"mappings":";;;;AAAO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}}]
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js"],"sourcesContent":["import { bar } from 'bar'\nimport './shared'\n\nbar(true)\n\nimport('./import').then(({ foo }) => {\n foo(true)\n})\n"],"names":["then","foo"],"mappings":";AAAA;AACA;;;AAEA,IAAA,gOAAG,EAAC;AAEJ,yJAAmBA,IAAI,CAAC,CAAC,EAAEC,GAAG,EAAE;IAC9BA,IAAI;AACN"}}]
}
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/ba425_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_7b89cd79.js",
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_dab22947._.js","output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_ea8e1245.js","output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import_c0ebb290.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/ba425_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_da1eef81.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_import_c0ebb290.js","output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_df8dd76f._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_c52390c2._.js",
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_0b8573ac._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([
"foo",
()=>foo
]);
function foo(value) {
console.assert(value);
}
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
......@@ -12,17 +23,6 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbo
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$async_chunk$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["foo"])(true);
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$async_chunk$2f$input$2f$node_modules$2f$bar$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["bar"])(true);
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([
"foo",
()=>foo
]);
function foo(value) {
console.assert(value);
}
}),
]);
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_c52390c2._.js.map
\ No newline at end of file
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_0b8573ac._.js.map
\ No newline at end of file
......@@ -2,6 +2,6 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/node/spawn_node_eval/input/index.js"],"sourcesContent":["import { spawn } from 'child_process'\n\nlet x = spawn(process.argv[0], ['-e', \"console.log('foo');\"])\n"],"names":["x","process","argv"],"mappings":";AAAA;;AAEA,IAAIA,IAAI,IAAA,+OAAK,EAACC,QAAQC,IAAI,CAAC,EAAE,EAAE;IAAC;IAAM;CAAsB"}},
{"offset": {"line": 15, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/node/spawn_node_eval/input/node_modules/child_process/index.js"],"sourcesContent":["export function spawn(cmd, args) {\n //\n}\n"],"names":["spawn","cmd","args"],"mappings":";;;;AAAO,SAASA,MAAMC,GAAG,EAAEC,IAAI;AAC7B,EAAE;AACJ","ignoreList":[0]}}]
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js"],"sourcesContent":["export function foo(value) {\n console.assert(value);\n}\n"],"names":["foo","value","console","assert"],"mappings":";;;;AAAO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}},
{"offset": {"line": 15, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js"],"sourcesContent":["import { foo } from 'foo'\nimport { bar } from 'bar'\nimport './shared'\n\nfoo(true)\nbar(true)\n"],"names":[],"mappings":";AAAA;AACA;AACA;;;;AAEA,IAAA,gOAAG,EAAC;AACJ,IAAA,gOAAG,EAAC"}}]
}
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js"],"sourcesContent":["import { foo } from 'foo'\nimport { bar } from 'bar'\nimport './shared'\n\nfoo(true)\nbar(true)\n"],"names":[],"mappings":";AAAA;AACA;AACA;;;;AAEA,IAAA,gOAAG,EAAC;AACJ,IAAA,gOAAG,EAAC"}},
{"offset": {"line": 17, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/foo/index.js"],"sourcesContent":["export function foo(value) {\n console.assert(value);\n}\n"],"names":["foo","value","console","assert"],"mappings":";;;;AAAO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}}]
}
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_dab22947._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/bar/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([
"bar",
()=>bar
]);
function bar(value) {
console.assert(value);
}
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/shared.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
// shared package
}),
]);
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_dab22947._.js.map
\ No newline at end of file
......@@ -2,6 +2,6 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js"],"sourcesContent":["import { foo } from 'foo'\n\nfoo(true)\n"],"names":[],"mappings":";AAAA;;AAEA,IAAA,4NAAG,EAAC"}},
{"offset": {"line": 12, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js"],"sourcesContent":["export function foo(value) {\n console.assert(value);\n}\n"],"names":["foo","value","console","assert"],"mappings":";;;;AAAO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}}]
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/node_modules/bar/index.js"],"sourcesContent":["export function bar(value) {\n console.assert(value);\n}\n"],"names":["bar","value","console","assert"],"mappings":";;;;AAAO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}},
{"offset": {"line": 14, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/shared.js"],"sourcesContent":["// shared package\n"],"names":[],"mappings":"AAAA,iBAAiB"}}]
}
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/ba425_crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_3d2893fd.js",
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_f80bf1f2._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js [test] (ecmascript)"]}
"output/ba425_crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_a86bc380.js",
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_cb37d43c._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_f80bf1f2._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([]);
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$chunked$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js [test] (ecmascript)");
;
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$chunked$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["foo"])(true);
}),
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_cb37d43c._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
......@@ -18,6 +10,14 @@ function foo(value) {
console.assert(value);
}
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([]);
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$chunked$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js [test] (ecmascript)");
;
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$chunked$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["foo"])(true);
}),
]);
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_f80bf1f2._.js.map
\ No newline at end of file
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_chunked_input_cb37d43c._.js.map
\ No newline at end of file
......@@ -2,6 +2,6 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js"],"sourcesContent":["#!/usr/bin/env node\n\nimport { foo } from 'foo'\n\nfoo(true)\n"],"names":[],"mappings":";AAEA;;AAEA,IAAA,4NAAG,EAAC"}},
{"offset": {"line": 12, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/node_modules/foo/index.js"],"sourcesContent":["#!/usr/bin/env node\n\nexport function foo(value) {\n console.assert(value);\n}\n"],"names":["foo","value","console","assert"],"mappings":";;;;AAEO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}}]
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/node_modules/foo/index.js"],"sourcesContent":["export function foo(value) {\n console.assert(value);\n}\n"],"names":["foo","value","console","assert"],"mappings":";;;;AAAO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}},
{"offset": {"line": 15, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/chunked/input/index.js"],"sourcesContent":["import { foo } from 'foo'\n\nfoo(true)\n"],"names":[],"mappings":";AAAA;;AAEA,IAAA,4NAAG,EAAC"}}]
}
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/ba425_crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_1ec6f047.js",
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_07d95226._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js [test] (ecmascript)"]}
"output/ba425_crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_c7271b63.js",
{"otherChunks":["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_75c3b344._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_07d95226._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([]);
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$shebang$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/node_modules/foo/index.js [test] (ecmascript)");
;
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$shebang$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["foo"])(true);
}),
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_75c3b344._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/node_modules/foo/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
......@@ -18,6 +10,14 @@ function foo(value) {
console.assert(value);
}
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([]);
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$shebang$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/node_modules/foo/index.js [test] (ecmascript)");
;
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2f$shebang$2f$input$2f$node_modules$2f$foo$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["foo"])(true);
}),
]);
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_07d95226._.js.map
\ No newline at end of file
//# sourceMappingURL=turbopack_crates_turbopack-tests_tests_snapshot_basic_shebang_input_75c3b344._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/node_modules/foo/index.js"],"sourcesContent":["#!/usr/bin/env node\n\nexport function foo(value) {\n console.assert(value);\n}\n"],"names":["foo","value","console","assert"],"mappings":";;;;AAEO,SAASA,IAAIC,KAAK;IACvBC,QAAQC,MAAM,CAACF;AACjB","ignoreList":[0]}},
{"offset": {"line": 15, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/shebang/input/index.js"],"sourcesContent":["#!/usr/bin/env node\n\nimport { foo } from 'foo'\n\nfoo(true)\n"],"names":[],"mappings":";AAEA;;AAEA,IAAA,4NAAG,EAAC"}}]
}
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/5c1d0_turbopack-tests_tests_snapshot_basic_top-level-await_input_index_fa502a1e.js",
{"otherChunks":["output/780ce_turbopack-tests_tests_snapshot_basic_top-level-await_input_UserAPI_284cef63.js","output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_top-level-await_input_bae4bbe2._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/top-level-await/input/index.js [test] (ecmascript)"]}
"output/5c1d0_turbopack-tests_tests_snapshot_basic_top-level-await_input_index_ff8b2f88.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_basic_top-level-await_input_bae4bbe2._.js","output/780ce_turbopack-tests_tests_snapshot_basic_top-level-await_input_UserAPI_284cef63.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/top-level-await/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/5c1d0_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_7cb9f920.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_127ba44c._.css","output/780ce_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_f81e3d8a.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/5c1d0_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_f17db994.js",
{"otherChunks":["output/780ce_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_other_5b4712f9.css","output/bf321_tests_snapshot_css_absolute-uri-import_input_withduplicateurl_a75e84b4.css","output/780ce_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_c5822330.css","output/780ce_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_f81e3d8a.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
@import "https://example.com/stylesheet1.css";
@import "https://example.com/withquote\".css";
@import "https://example.com/stylesheet2.css";
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/other.css [test] (css) */
.foo {
background-color: red;
}
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/withduplicateurl.css [test] (css) */
.bar {
background-color: green;
}
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.css [test] (css) */
body {
background-color: #00f;
}
/*# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_127ba44c._.css.map*/
\ No newline at end of file
/*# sourceMappingURL=780ce_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_c5822330.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.css"],"sourcesContent":["@import 'https://example.com/stylesheet1.css';\n@import 'https://example.com/withquote\".css';\n@import './other.css';\n@import './withduplicateurl.css';\n@import url('https://example.com/stylesheet2.css');\n\nbody {\n background-color: blue;\n}\n"],"names":[],"mappings":"AAMA"}}]
}
\ No newline at end of file
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/other.css [test] (css) */
.foo {
background-color: red;
}
/*# sourceMappingURL=780ce_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_other_5b4712f9.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 1, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/other.css"],"sourcesContent":[".foo {\n background-color: red;\n}\n"],"names":[],"mappings":"AAAA"}}]
}
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/other.css"],"sourcesContent":[".foo {\n background-color: red;\n}\n"],"names":[],"mappings":"AAAA"}},
{"offset": {"line": 9, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/withduplicateurl.css"],"sourcesContent":["/* This should not be duplicated */\n@import 'https://example.com/stylesheet1.css';\n\n.bar {\n background-color: green;\n}\n"],"names":[],"mappings":"AAGA"}},
{"offset": {"line": 14, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/index.css"],"sourcesContent":["@import 'https://example.com/stylesheet1.css';\n@import 'https://example.com/withquote\".css';\n@import './other.css';\n@import './withduplicateurl.css';\n@import url('https://example.com/stylesheet2.css');\n\nbody {\n background-color: blue;\n}\n"],"names":[],"mappings":"AAMA"}}]
}
\ No newline at end of file
@import "https://example.com/stylesheet1.css";
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/withduplicateurl.css [test] (css) */
.bar {
background-color: green;
}
/*# sourceMappingURL=bf321_tests_snapshot_css_absolute-uri-import_input_withduplicateurl_a75e84b4.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 2, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/input/withduplicateurl.css"],"sourcesContent":["/* This should not be duplicated */\n@import 'https://example.com/stylesheet1.css';\n\n.bar {\n background-color: green;\n}\n"],"names":[],"mappings":"AAGA"}}]
}
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/5c1d0_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_53d36408.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_1fa64d9f._.css","output/780ce_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_d8843af2.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/5c1d0_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_cab04d6d.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_86191b3e.css","output/aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_c_ef6cffd3.css","output/aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_b_0dd56a4c.css","output/aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_a_531b8d37.css","output/780ce_turbopack-tests_tests_snapshot_css_chained-attributes_input_style_8666effe.css","output/780ce_turbopack-tests_tests_snapshot_css_chained-attributes_input_index_d8843af2.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/style.css [test] (css) */
.style {
color: #ff0;
}
/*# sourceMappingURL=780ce_turbopack-tests_tests_snapshot_css_chained-attributes_input_style_8666effe.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 1, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/style.css"],"sourcesContent":["@import url('./a.css') layer(layer) supports(not(display: inline-grid)) print;\n\n.style {\n color: yellow;\n}\n"],"names":[],"mappings":"AAEA"}}]
}
\ No newline at end of file
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/c.css [test] (css, layer(layer) layer(foo) print and (orientation: landscape) supports(not(display: inline-grid)) supports(font-format(woff2))) */
@layer layer.foo {
@media print and (orientation: landscape) {
@supports not(display: inline-grid) and font-format(woff2) {
.imported {
color: red;
}
}
}
}
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/c.css [test] (css, layer(layer) layer(bar) print and (orientation: portrait) supports(not(display: inline-grid)) supports(font-format(woff2))) */
@layer layer.bar {
@media print and (orientation: portrait) {
@supports not(display: inline-grid) and font-format(woff2) {
.imported {
color: red;
}
}
}
}
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/b.css [test] (css, layer(layer) print supports(not(display: inline-grid)) supports(font-format(woff2))) */
@layer layer {
@media print {
@supports not(display: inline-grid) and font-format(woff2) {
.imported {
color: orange;
}
}
}
}
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/a.css [test] (css, layer(layer) print supports(not(display: inline-grid))) */
@layer layer {
@media print {
@supports not(display: inline-grid) {
.imported {
color: #0ff;
}
}
}
}
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/style.css [test] (css) */
.style {
color: #ff0;
}
/*# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_1fa64d9f._.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/c.css"],"sourcesContent":[".imported {\n color: red;\n}\n"],"names":[],"mappings":"AAAA"}},
{"offset": {"line": 16, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/c.css"],"sourcesContent":[".imported {\n color: red;\n}\n"],"names":[],"mappings":"AAAA"}},
{"offset": {"line": 28, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/b.css"],"sourcesContent":["@import url('./c.css') layer(foo) (orientation: landscape);\n@import url('./c.css') layer(bar) (orientation: portrait);\n\n.imported {\n color: orange;\n}\n"],"names":[],"mappings":"AAGA"}},
{"offset": {"line": 40, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/a.css"],"sourcesContent":["@import url('./b.css') supports(font-format(woff2));\n\n.imported {\n color: cyan;\n}\n"],"names":[],"mappings":"AAEA"}},
{"offset": {"line": 49, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/style.css"],"sourcesContent":["@import url('./a.css') layer(layer) supports(not(display: inline-grid)) print;\n\n.style {\n color: yellow;\n}\n"],"names":[],"mappings":"AAEA"}}]
}
\ No newline at end of file
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/a.css [test] (css, layer(layer) print supports(not(display: inline-grid))) */
@layer layer {
@media print {
@supports not(display: inline-grid) {
.imported {
color: #0ff;
}
}
}
}
/*# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_a_531b8d37.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/a.css"],"sourcesContent":["@import url('./b.css') supports(font-format(woff2));\n\n.imported {\n color: cyan;\n}\n"],"names":[],"mappings":"AAEA"}}]
}
\ No newline at end of file
/* [project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/b.css [test] (css, layer(layer) print supports(not(display: inline-grid)) supports(font-format(woff2))) */
@layer layer {
@media print {
@supports not(display: inline-grid) and font-format(woff2) {
.imported {
color: orange;
}
}
}
}
/*# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_css_chained-attributes_input_b_0dd56a4c.css.map*/
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/css/chained-attributes/input/b.css"],"sourcesContent":["@import url('./c.css') layer(foo) (orientation: landscape);\n@import url('./c.css') layer(bar) (orientation: portrait);\n\n.imported {\n color: orange;\n}\n"],"names":[],"mappings":"AAGA"}}]
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment