Unverified Commit 99303d31 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: accept ChunkGroup in entry_chunk_group (#90821)

Now all of the chunking context functions accept `ChunkGroup`

The names are bad, but `entry_chunk_group` and `ChunkGroup::Entry` have nothing to do with each other:
- `entry_chunk_group` means: it's a standalone file where `node path/to/chunk.js` will execute it
- `ChunkGroup::Entry` = it's the top-level chunk group

For example a `evaluated_chunk_group(ChunkGroup::Entry)` is also fine
parent b7b58b22
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result};
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use next_core::{ use next_core::{
app_structure::{ app_structure::{
...@@ -1820,12 +1820,6 @@ impl AppEndpoint { ...@@ -1820,12 +1820,6 @@ impl AppEndpoint {
.concatenate(chunk_group2_assets) .concatenate(chunk_group2_assets)
} }
NextRuntime::NodeJs => { NextRuntime::NodeJs => {
let Some(rsc_entry) = ResolvedVc::try_downcast(app_entry.rsc_entry) else {
bail!("rsc_entry must be evaluatable");
};
let evaluatable_assets = Vc::cell(vec![rsc_entry]);
async { async {
let mut current_chunk_group = ChunkGroupResult::empty_resolved(); let mut current_chunk_group = ChunkGroupResult::empty_resolved();
...@@ -1925,7 +1919,7 @@ impl AppEndpoint { ...@@ -1925,7 +1919,7 @@ impl AppEndpoint {
"app{original_name}.js", "app{original_name}.js",
original_name = app_entry.original_name original_name = app_entry.original_name
))?, ))?,
evaluatable_assets, ChunkGroup::Entry(vec![app_entry.rsc_entry]),
module_graph, module_graph,
*current_chunks, *current_chunks,
current_referenced_assets, current_referenced_assets,
......
use anyhow::{Result, bail}; use anyhow::Result;
use next_core::{ use next_core::{
next_edge::entry::wrap_edge_entry, next_edge::entry::wrap_edge_entry,
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2}, next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
...@@ -120,17 +120,13 @@ impl InstrumentationEndpoint { ...@@ -120,17 +120,13 @@ impl InstrumentationEndpoint {
let userland_module = self.entry_module().to_resolved().await?; let userland_module = self.entry_module().to_resolved().await?;
let module_graph = this.project.module_graph(*userland_module); let module_graph = this.project.module_graph(*userland_module);
let Some(module) = ResolvedVc::try_downcast(userland_module) else {
bail!("Entry module must be evaluatable");
};
let EntryChunkGroupResult { asset: chunk, .. } = *chunking_context let EntryChunkGroupResult { asset: chunk, .. } = *chunking_context
.entry_chunk_group( .entry_chunk_group(
this.project this.project
.node_root() .node_root()
.await? .await?
.join("server/instrumentation.js")?, .join("server/instrumentation.js")?,
Vc::cell(vec![module]), ChunkGroup::Entry(vec![userland_module]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
use std::future::IntoFuture; use std::future::IntoFuture;
use anyhow::{Result, bail}; use anyhow::Result;
use next_core::{ use next_core::{
middleware::get_middleware_module, middleware::get_middleware_module,
next_edge::entry::wrap_edge_entry, next_edge::entry::wrap_edge_entry,
...@@ -130,17 +130,13 @@ impl MiddlewareEndpoint { ...@@ -130,17 +130,13 @@ impl MiddlewareEndpoint {
let userland_module = self.entry_module().to_resolved().await?; let userland_module = self.entry_module().to_resolved().await?;
let module_graph = this.project.module_graph(*userland_module); let module_graph = this.project.module_graph(*userland_module);
let Some(module) = ResolvedVc::try_downcast(userland_module) else {
bail!("Entry module must be evaluatable");
};
let EntryChunkGroupResult { asset: chunk, .. } = *chunking_context let EntryChunkGroupResult { asset: chunk, .. } = *chunking_context
.root_entry_chunk_group( .root_entry_chunk_group(
this.project this.project
.node_root() .node_root()
.await? .await?
.join("server/middleware.js")?, .join("server/middleware.js")?,
Vc::cell(vec![module]), ChunkGroup::Entry(vec![userland_module]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -1018,13 +1018,11 @@ impl PageEndpoint { ...@@ -1018,13 +1018,11 @@ impl PageEndpoint {
.await?; .await?;
} }
let ssr_module_evaluatable = ResolvedVc::try_sidecast(ssr_module)
.context("could not process page loader entry module")?;
let is_edge = matches!(runtime, NextRuntime::Edge); let is_edge = matches!(runtime, NextRuntime::Edge);
if is_edge { if is_edge {
let chunk_assets = edge_chunking_context.evaluated_chunk_group_assets( let chunk_assets = edge_chunking_context.evaluated_chunk_group_assets(
ssr_module.ident(), ssr_module.ident(),
ChunkGroup::Entry(vec![ResolvedVc::upcast(ssr_module_evaluatable)]), ChunkGroup::Entry(vec![ssr_module]),
ssr_module_graph, ssr_module_graph,
current_chunk_group.await?.availability_info, current_chunk_group.await?.availability_info,
); );
...@@ -1052,7 +1050,7 @@ impl PageEndpoint { ...@@ -1052,7 +1050,7 @@ impl PageEndpoint {
let ssr_entry_chunk = node_chunking_context let ssr_entry_chunk = node_chunking_context
.entry_chunk_group_asset( .entry_chunk_group_asset(
ssr_entry_chunk_path, ssr_entry_chunk_path,
EvaluatableAssets::empty().with_entry(*ssr_module_evaluatable), ChunkGroup::Entry(vec![ssr_module]),
ssr_module_graph, ssr_module_graph,
current_chunk_group.primary_assets(), current_chunk_group.primary_assets(),
current_chunk_group.referenced_assets(), current_chunk_group.referenced_assets(),
......
...@@ -880,7 +880,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -880,7 +880,7 @@ impl ChunkingContext for BrowserChunkingContext {
fn entry_chunk_group( fn entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
_path: FileSystemPath, _path: FileSystemPath,
_evaluatable_assets: Vc<EvaluatableAssets>, _chunk_group: ChunkGroup,
_module_graph: Vc<ModuleGraph>, _module_graph: Vc<ModuleGraph>,
_extra_chunks: Vc<OutputAssets>, _extra_chunks: Vc<OutputAssets>,
_extra_referenced_assets: Vc<OutputAssets>, _extra_referenced_assets: Vc<OutputAssets>,
......
...@@ -21,8 +21,8 @@ use turbopack_cli_utils::issue::{ConsoleUi, LogOptions}; ...@@ -21,8 +21,8 @@ use turbopack_cli_utils::issue::{ConsoleUi, LogOptions};
use turbopack_core::{ use turbopack_core::{
asset::Asset, asset::Asset,
chunk::{ chunk::{
ChunkingConfig, ChunkingContext, ChunkingContextExt, EvaluatableAsset, EvaluatableAssets, ChunkingConfig, ChunkingContext, ChunkingContextExt, EvaluatableAsset, MangleType,
MangleType, MinifyType, SourceMapsType, availability_info::AvailabilityInfo, MinifyType, SourceMapsType, availability_info::AvailabilityInfo,
}, },
environment::{BrowserEnvironment, Environment, ExecutionEnvironment, NodeJsEnvironment}, environment::{BrowserEnvironment, Environment, ExecutionEnvironment, NodeJsEnvironment},
ident::AssetIdent, ident::AssetIdent,
...@@ -470,7 +470,7 @@ async fn build_internal( ...@@ -470,7 +470,7 @@ async fn build_internal(
.unwrap(), .unwrap(),
)? )?
.with_extension("entry.js"), .with_extension("entry.js"),
EvaluatableAssets::one(*ecmascript), ChunkGroup::Entry(vec![ResolvedVc::upcast(ecmascript)]),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -12,8 +12,8 @@ use turbo_tasks_hash::DeterministicHash; ...@@ -12,8 +12,8 @@ use turbo_tasks_hash::DeterministicHash;
use crate::{ use crate::{
asset::Asset, asset::Asset,
chunk::{ chunk::{
ChunkItem, ChunkType, ChunkableModule, EvaluatableAssets, ChunkItem, ChunkType, ChunkableModule, availability_info::AvailabilityInfo,
availability_info::AvailabilityInfo, chunk_id_strategy::ModuleIdStrategy, chunk_id_strategy::ModuleIdStrategy,
}, },
environment::Environment, environment::Environment,
ident::AssetIdent, ident::AssetIdent,
...@@ -456,7 +456,7 @@ pub trait ChunkingContext { ...@@ -456,7 +456,7 @@ pub trait ChunkingContext {
fn entry_chunk_group( fn entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -525,7 +525,7 @@ pub trait ChunkingContextExt { ...@@ -525,7 +525,7 @@ pub trait ChunkingContextExt {
fn entry_chunk_group_asset( fn entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -537,7 +537,7 @@ pub trait ChunkingContextExt { ...@@ -537,7 +537,7 @@ pub trait ChunkingContextExt {
fn root_entry_chunk_group( fn root_entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -548,7 +548,7 @@ pub trait ChunkingContextExt { ...@@ -548,7 +548,7 @@ pub trait ChunkingContextExt {
fn root_entry_chunk_group_asset( fn root_entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -617,7 +617,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -617,7 +617,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn entry_chunk_group_asset( fn entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -626,7 +626,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -626,7 +626,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
entry_chunk_group_asset( entry_chunk_group_asset(
Vc::upcast_non_strict(self), Vc::upcast_non_strict(self),
path, path,
evaluatable_assets, chunk_group,
module_graph, module_graph,
extra_chunks, extra_chunks,
extra_referenced_assets, extra_referenced_assets,
...@@ -637,14 +637,14 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -637,14 +637,14 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_entry_chunk_group( fn root_entry_chunk_group(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
) -> Vc<EntryChunkGroupResult> { ) -> Vc<EntryChunkGroupResult> {
self.entry_chunk_group( self.entry_chunk_group(
path, path,
evaluatable_assets, chunk_group,
module_graph, module_graph,
extra_chunks, extra_chunks,
extra_referenced_assets, extra_referenced_assets,
...@@ -655,7 +655,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -655,7 +655,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
fn root_entry_chunk_group_asset( fn root_entry_chunk_group_asset(
self: Vc<Self>, self: Vc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -663,7 +663,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte ...@@ -663,7 +663,7 @@ impl<T: ChunkingContext + Send + Upcast<Box<dyn ChunkingContext>>> ChunkingConte
entry_chunk_group_asset( entry_chunk_group_asset(
Vc::upcast_non_strict(self), Vc::upcast_non_strict(self),
path, path,
evaluatable_assets, chunk_group,
module_graph, module_graph,
extra_chunks, extra_chunks,
extra_referenced_assets, extra_referenced_assets,
...@@ -762,7 +762,7 @@ fn evaluated_chunk_group_assets( ...@@ -762,7 +762,7 @@ fn evaluated_chunk_group_assets(
async fn entry_chunk_group_asset( async fn entry_chunk_group_asset(
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -771,7 +771,7 @@ async fn entry_chunk_group_asset( ...@@ -771,7 +771,7 @@ async fn entry_chunk_group_asset(
Ok(*chunking_context Ok(*chunking_context
.entry_chunk_group( .entry_chunk_group(
path, path,
evaluatable_assets, chunk_group,
module_graph, module_graph,
extra_chunks, extra_chunks,
extra_referenced_assets, extra_referenced_assets,
......
...@@ -6,7 +6,7 @@ use turbopack_core::{ ...@@ -6,7 +6,7 @@ use turbopack_core::{
chunk::{ chunk::{
AsyncModuleInfo, ChunkData, ChunkGroupType, ChunkableModule, ChunkingContext, AsyncModuleInfo, ChunkData, ChunkGroupType, ChunkableModule, ChunkingContext,
ChunkingContextExt, ChunkingType, ChunkingTypeOption, ChunksData, EvaluatableAsset, ChunkingContextExt, ChunkingType, ChunkingTypeOption, ChunksData, EvaluatableAsset,
EvaluatableAssets, availability_info::AvailabilityInfo, availability_info::AvailabilityInfo,
}, },
context::AssetContext, context::AssetContext,
ident::AssetIdent, ident::AssetIdent,
...@@ -91,7 +91,7 @@ impl WorkerLoaderModule { ...@@ -91,7 +91,7 @@ impl WorkerLoaderModule {
let entry_result = chunking_context let entry_result = chunking_context
.root_entry_chunk_group( .root_entry_chunk_group(
worker_path, worker_path,
EvaluatableAssets::one(*evaluatable), ChunkGroup::Isolated(ResolvedVc::upcast(evaluatable)),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -28,7 +28,10 @@ use turbopack_core::{ ...@@ -28,7 +28,10 @@ use turbopack_core::{
StyledString, StyledString,
}, },
module::Module, module::Module,
module_graph::{GraphEntries, ModuleGraph, chunk_group_info::ChunkGroupEntry}, module_graph::{
GraphEntries, ModuleGraph,
chunk_group_info::{ChunkGroup, ChunkGroupEntry},
},
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
reference_type::{InnerAssets, ReferenceType}, reference_type::{InnerAssets, ReferenceType},
source::Source, source::Source,
...@@ -158,7 +161,7 @@ async fn emit_evaluate_pool_assets_operation( ...@@ -158,7 +161,7 @@ async fn emit_evaluate_pool_assets_operation(
let bootstrap = chunking_context.root_entry_chunk_group_asset( let bootstrap = chunking_context.root_entry_chunk_group_asset(
entrypoint.clone(), entrypoint.clone(),
Vc::cell(entries.clone()), ChunkGroup::Entry(entries.iter().cloned().map(ResolvedVc::upcast).collect()),
*module_graph, *module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
......
...@@ -7,7 +7,7 @@ use turbopack_core::{ ...@@ -7,7 +7,7 @@ use turbopack_core::{
asset::Asset, asset::Asset,
chunk::{ chunk::{
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule, AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule,
ChunkingConfig, ChunkingConfigs, ChunkingContext, EntryChunkGroupResult, EvaluatableAssets, ChunkingConfig, ChunkingConfigs, ChunkingContext, EntryChunkGroupResult, EvaluatableAsset,
MinifyType, SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior, MinifyType, SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
availability_info::AvailabilityInfo, availability_info::AvailabilityInfo,
chunk_group::{MakeChunkGroupResult, make_chunk_group}, chunk_group::{MakeChunkGroupResult, make_chunk_group},
...@@ -542,7 +542,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -542,7 +542,7 @@ impl ChunkingContext for NodeJsChunkingContext {
pub async fn entry_chunk_group( pub async fn entry_chunk_group(
self: ResolvedVc<Self>, self: ResolvedVc<Self>,
path: FileSystemPath, path: FileSystemPath,
evaluatable_assets: Vc<EvaluatableAssets>, chunk_group: ChunkGroup,
module_graph: Vc<ModuleGraph>, module_graph: Vc<ModuleGraph>,
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
extra_referenced_assets: Vc<OutputAssets>, extra_referenced_assets: Vc<OutputAssets>,
...@@ -554,11 +554,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -554,11 +554,7 @@ impl ChunkingContext for NodeJsChunkingContext {
chunking_type = "entry", chunking_type = "entry",
); );
async move { async move {
let evaluatable_assets_ref = evaluatable_assets.await?; let entries = chunk_group.entries();
let entries = evaluatable_assets_ref
.iter()
.map(|&asset| ResolvedVc::upcast::<Box<dyn Module>>(asset));
let MakeChunkGroupResult { let MakeChunkGroupResult {
chunks, chunks,
mut referenced_output_assets, mut referenced_output_assets,
...@@ -584,16 +580,24 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -584,16 +580,24 @@ impl ChunkingContext for NodeJsChunkingContext {
referenced_output_assets.extend(extra_referenced_assets.await?.iter().copied()); referenced_output_assets.extend(extra_referenced_assets.await?.iter().copied());
let Some(module) = ResolvedVc::try_sidecast(*evaluatable_assets_ref.last().unwrap()) let Some(module) = ResolvedVc::try_sidecast(chunk_group.entries().last().unwrap())
else { else {
bail!("module must be placeable in an ecmascript chunk"); bail!("module must be placeable in an ecmascript chunk");
}; };
let evaluatable_assets = chunk_group
.entries()
.map(|entry| {
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(entry)
.context("entry_chunk_group entries must be evaluatable")
})
.collect::<Result<Vec<_>>>()?;
let asset = ResolvedVc::upcast( let asset = ResolvedVc::upcast(
EcmascriptBuildNodeEntryChunk::new( EcmascriptBuildNodeEntryChunk::new(
path, path,
Vc::cell(other_chunks), Vc::cell(other_chunks),
evaluatable_assets, Vc::cell(evaluatable_assets),
*module, *module,
Vc::cell(referenced_output_assets), Vc::cell(referenced_output_assets),
Vc::cell(references), Vc::cell(references),
......
...@@ -5,7 +5,7 @@ mod util; ...@@ -5,7 +5,7 @@ mod util;
use std::{collections::VecDeque, fs, io, path::PathBuf}; use std::{collections::VecDeque, fs, io, path::PathBuf};
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result};
use dunce::canonicalize; use dunce::canonicalize;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use serde::Deserialize; use serde::Deserialize;
...@@ -30,7 +30,7 @@ use turbopack_core::{ ...@@ -30,7 +30,7 @@ use turbopack_core::{
asset::Asset, asset::Asset,
chunk::{ chunk::{
ChunkingConfig, ChunkingContext, ChunkingContextExt, EvaluatableAsset, EvaluatableAssetExt, ChunkingConfig, ChunkingContext, ChunkingContextExt, EvaluatableAsset, EvaluatableAssetExt,
EvaluatableAssets, MinifyType, SourceMapSourceType, availability_info::AvailabilityInfo, MinifyType, SourceMapSourceType, availability_info::AvailabilityInfo,
}, },
compile_time_defines, compile_time_defines,
compile_time_info::{ compile_time_info::{
...@@ -51,7 +51,6 @@ use turbopack_core::{ ...@@ -51,7 +51,6 @@ use turbopack_core::{
}, },
output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced},
reference_type::{EntryReferenceSubType, ReferenceType, UrlReferenceSubType}, reference_type::{EntryReferenceSubType, ReferenceType, UrlReferenceSubType},
source::Source,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
AnalyzeMode, EcmascriptInputTransform, TreeShakingMode, chunk::EcmascriptChunkType, AnalyzeMode, EcmascriptInputTransform, TreeShakingMode, chunk::EcmascriptChunkType,
...@@ -430,36 +429,22 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -430,36 +429,22 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
Layer::new(rcstr!("test")), Layer::new(rcstr!("test")),
)); ));
let runtime_entries = maybe_load_env(asset_context, project_path.clone())
.await?
.map(|asset| EvaluatableAssets::one(asset.to_evaluatable(asset_context)));
let entry_module = asset_context let entry_module = asset_context
.process( .process(
Vc::upcast(FileSource::new(entry_asset)), Vc::upcast(FileSource::new(entry_asset)),
ReferenceType::Entry(EntryReferenceSubType::Undefined), ReferenceType::Entry(EntryReferenceSubType::Undefined),
) )
.module(); .module()
.to_resolved()
.await?;
let (evaluatable_assets, entry_modules) = if let Some(ecmascript) = let entry_modules: Vec<ResolvedVc<Box<dyn Module>>> =
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(entry_module.to_resolved().await?) maybe_load_env(asset_context, project_path.clone())
{ .await?
let evaluatable_assets = runtime_entries .into_iter()
.unwrap_or_else(EvaluatableAssets::empty) .map(ResolvedVc::upcast)
.with_entry(*ecmascript); .chain(std::iter::once(entry_module))
( .collect();
evaluatable_assets,
evaluatable_assets
.await?
.iter()
.copied()
.map(ResolvedVc::upcast)
.collect::<Vec<_>>(),
)
} else {
// TODO convert into a serve-able asset
bail!("Entry module is not chunkable, so it can't be used to bootstrap the application")
};
let single_graph = SingleModuleGraph::new_with_entries( let single_graph = SingleModuleGraph::new_with_entries(
ResolvedVc::cell(vec![ChunkGroupEntry::Entry(entry_modules.clone())]), ResolvedVc::cell(vec![ChunkGroupEntry::Entry(entry_modules.clone())]),
...@@ -607,7 +592,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -607,7 +592,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
chunk_root_path chunk_root_path
.join(entry_module.ident().path().await?.file_stem().unwrap())? .join(entry_module.ident().path().await?.file_stem().unwrap())?
.with_extension("entry.js"), .with_extension("entry.js"),
evaluatable_assets, ChunkGroup::Entry(entry_modules),
module_graph, module_graph,
OutputAssets::empty(), OutputAssets::empty(),
OutputAssets::empty(), OutputAssets::empty(),
...@@ -666,9 +651,9 @@ async fn walk_asset( ...@@ -666,9 +651,9 @@ async fn walk_asset(
} }
async fn maybe_load_env( async fn maybe_load_env(
_context: Vc<Box<dyn AssetContext>>, asset_context: Vc<Box<dyn AssetContext>>,
path: FileSystemPath, path: FileSystemPath,
) -> Result<Option<Vc<Box<dyn Source>>>> { ) -> Result<Option<ResolvedVc<Box<dyn EvaluatableAsset>>>> {
let dotenv_path = path.join("input/.env")?; let dotenv_path = path.join("input/.env")?;
if !dotenv_path.read().await?.is_content() { if !dotenv_path.read().await?.is_content() {
...@@ -676,6 +661,10 @@ async fn maybe_load_env( ...@@ -676,6 +661,10 @@ async fn maybe_load_env(
} }
let env = DotenvProcessEnv::new(None, dotenv_path.clone()); let env = DotenvProcessEnv::new(None, dotenv_path.clone());
let asset = ProcessEnvAsset::new(dotenv_path, Vc::upcast(env)); let asset = ProcessEnvAsset::new(dotenv_path, Vc::upcast(env))
Ok(Some(Vc::upcast(asset))) .to_evaluatable(asset_context)
.to_resolved()
.await?;
Ok(Some(asset))
} }
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