Unverified Commit b0d33e9a authored by Sam Poder's avatar Sam Poder Committed by GitHub

[turbopack] Add support for single-entry chunks (#94727)

This PR adds support for generating single-entry chunks, based on this
plan: https://gist.github.com/bgw/356344ea6fb0e897647c478d01c096d3 up
until Step 6.

Also adds a basic snapshot test to capture this behaviour.

---------
Co-authored-by: 's avatarBenjamin Woodruff <benjamin.woodruff@vercel.com>
parent b132f1dc
...@@ -77,7 +77,7 @@ impl OutputChunk for EcmascriptBrowserChunk { ...@@ -77,7 +77,7 @@ impl OutputChunk for EcmascriptBrowserChunk {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl EcmascriptBrowserChunk { impl EcmascriptBrowserChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn own_content(self: Vc<Self>) -> Result<Vc<EcmascriptBrowserChunkContent>> { pub(crate) async fn own_content(self: Vc<Self>) -> Result<Vc<EcmascriptBrowserChunkContent>> {
let this = self.await?; let this = self.await?;
Ok(EcmascriptBrowserChunkContent::new( Ok(EcmascriptBrowserChunkContent::new(
*this.chunking_context, *this.chunking_context,
......
...@@ -72,7 +72,7 @@ impl EcmascriptBrowserChunkContent { ...@@ -72,7 +72,7 @@ impl EcmascriptBrowserChunkContent {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn code(self: Vc<Self>) -> Result<Vc<Code>> { pub(crate) async fn code(self: Vc<Self>) -> Result<Vc<Code>> {
let this = self.await?; let this = self.await?;
let source_maps = *this let source_maps = *this
.chunking_context .chunking_context
......
...@@ -78,7 +78,7 @@ impl EcmascriptBrowserEvaluateChunk { ...@@ -78,7 +78,7 @@ impl EcmascriptBrowserEvaluateChunk {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn code(self: Vc<Self>) -> Result<Vc<Code>> { pub(crate) async fn code(self: Vc<Self>) -> Result<Vc<Code>> {
let this = self.await?; let this = self.await?;
let environment = this.chunking_context.environment(); let environment = this.chunking_context.environment();
...@@ -194,6 +194,7 @@ impl EcmascriptBrowserEvaluateChunk { ...@@ -194,6 +194,7 @@ impl EcmascriptBrowserEvaluateChunk {
this.chunking_context.cross_origin(), this.chunking_context.cross_origin(),
this.chunking_context.chunk_load_retry(), this.chunking_context.chunk_load_retry(),
has_async_modules, has_async_modules,
this.chunking_context.chunk_loading(),
); );
code.push_code(&*runtime_code.await?); code.push_code(&*runtime_code.await?);
} }
......
pub(crate) mod chunk; pub(crate) mod chunk;
pub(crate) mod single_entry_chunk;
use anyhow::Result;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{Chunk, ChunkingContext, EvaluatableAssets},
code_builder::{Code, CodeBuilder},
module_graph::ModuleGraph,
output::{
OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsReferences,
OutputAssetsWithReferenced,
},
source_map::{GenerateSourceMap, SourceMapAsset},
};
use turbopack_ecmascript::chunk::EcmascriptChunk;
use crate::{
BrowserChunkingContext,
ecmascript::{chunk::EcmascriptBrowserChunk, evaluate::chunk::EcmascriptBrowserEvaluateChunk},
};
/// A self-contained chunk that inlines the entire module together with
/// the Turbopack browser runtime and the evaluation of the entry modules.
///
/// Unlike the regular evaluate chunk, this emits everything into one file at a
/// fixed path and never loads additional chunks at runtime.
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Browser Single Entry Chunk")]
pub(crate) struct EcmascriptBrowserSingleEntryChunk {
chunking_context: ResolvedVc<BrowserChunkingContext>,
path: FileSystemPath,
chunk: ResolvedVc<EcmascriptChunk>,
evaluatable_assets: ResolvedVc<EvaluatableAssets>,
referenced_output_assets: ResolvedVc<OutputAssets>,
references: ResolvedVc<OutputAssetsReferences>,
module_graph: ResolvedVc<ModuleGraph>,
}
#[turbo_tasks::value_impl]
impl EcmascriptBrowserSingleEntryChunk {
#[turbo_tasks::function]
pub fn new(
chunking_context: ResolvedVc<BrowserChunkingContext>,
path: FileSystemPath,
chunk: ResolvedVc<EcmascriptChunk>,
evaluatable_assets: ResolvedVc<EvaluatableAssets>,
referenced_output_assets: ResolvedVc<OutputAssets>,
references: ResolvedVc<OutputAssetsReferences>,
module_graph: ResolvedVc<ModuleGraph>,
) -> Vc<Self> {
EcmascriptBrowserSingleEntryChunk {
chunking_context,
path,
chunk,
evaluatable_assets,
referenced_output_assets,
references,
module_graph,
}
.cell()
}
#[turbo_tasks::function]
async fn code(self: Vc<Self>) -> Result<Vc<Code>> {
let this = self.await?;
let source_maps = *this
.chunking_context
.reference_chunk_source_maps(Vc::upcast(self))
.await?;
let mut code = CodeBuilder::new(
source_maps,
*this.chunking_context.debug_ids_enabled().await?,
);
let module_chunk = EcmascriptBrowserChunk::new(*this.chunking_context, *this.chunk);
code.push_code(&*module_chunk.own_content().code().await?);
let evaluate_chunk = EcmascriptBrowserEvaluateChunk::new(
*this.chunking_context,
this.chunk.ident(),
OutputAssets::empty(),
*this.evaluatable_assets,
*this.module_graph,
);
code.push_code(&*evaluate_chunk.code().await?);
Ok(Code::cell(code.build()))
}
#[turbo_tasks::function]
async fn source_map(self: Vc<Self>) -> Result<Vc<SourceMapAsset>> {
let this = self.await?;
Ok(SourceMapAsset::new_fixed(
this.path.clone(),
Vc::upcast(self),
))
}
}
#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptBrowserSingleEntryChunk {
#[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<OutputAssetsWithReferenced>> {
let this = self.await?;
let mut assets = Vec::new();
if *this
.chunking_context
.reference_chunk_source_maps(Vc::upcast(self))
.await?
{
assets.push(ResolvedVc::upcast(self.source_map().to_resolved().await?));
}
Ok(OutputAssetsWithReferenced {
assets: ResolvedVc::cell(assets),
referenced_assets: this.referenced_output_assets,
references: this.references,
}
.cell())
}
}
#[turbo_tasks::value_impl]
impl OutputAsset for EcmascriptBrowserSingleEntryChunk {
#[turbo_tasks::function]
fn path(&self) -> Vc<FileSystemPath> {
self.path.clone().cell()
}
}
#[turbo_tasks::value_impl]
impl Asset for EcmascriptBrowserSingleEntryChunk {
#[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> {
Ok(AssetContent::file(
FileContent::Content(File::from(
self.code()
.to_rope_with_magic_comments(|| self.source_map())
.await?,
))
.cell(),
))
}
}
#[turbo_tasks::value_impl]
impl GenerateSourceMap for EcmascriptBrowserSingleEntryChunk {
#[turbo_tasks::function]
fn generate_source_map(self: Vc<Self>) -> Vc<FileContent> {
self.code().generate_source_map()
}
}
...@@ -19,7 +19,6 @@ use crate::{ ...@@ -19,7 +19,6 @@ use crate::{
available_modules::{AvailableModuleItem, AvailableModulesSet}, available_modules::{AvailableModuleItem, AvailableModulesSet},
chunk_item_batch::{ChunkItemBatchGroup, ChunkItemOrBatchWithAsyncModuleInfo}, chunk_item_batch::{ChunkItemBatchGroup, ChunkItemOrBatchWithAsyncModuleInfo},
}, },
environment::ChunkLoading,
module_graph::{ module_graph::{
GraphTraversalAction, ModuleGraph, GraphTraversalAction, ModuleGraph,
chunk_group_info::ChunkGroup, chunk_group_info::ChunkGroup,
...@@ -46,10 +45,7 @@ pub async fn make_chunk_group( ...@@ -46,10 +45,7 @@ pub async fn make_chunk_group(
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
availability_info: AvailabilityInfo, availability_info: AvailabilityInfo,
) -> Result<MakeChunkGroupResult> { ) -> Result<MakeChunkGroupResult> {
let can_split_async = !matches!( let can_split_async = chunking_context.chunk_loading().await?.can_split_async();
*chunking_context.environment().chunk_loading().await?,
ChunkLoading::Edge
);
let is_nested_async_availability_enabled = *chunking_context let is_nested_async_availability_enabled = *chunking_context
.is_nested_async_availability_enabled() .is_nested_async_availability_enabled()
.await?; .await?;
......
...@@ -13,7 +13,7 @@ use crate::{ ...@@ -13,7 +13,7 @@ use crate::{
ChunkItem, ChunkType, ChunkableModule, availability_info::AvailabilityInfo, ChunkItem, ChunkType, ChunkableModule, availability_info::AvailabilityInfo,
chunk_id_strategy::ModuleIdStrategy, chunk_id_strategy::ModuleIdStrategy,
}, },
environment::Environment, environment::{ChunkLoading, Environment},
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
module_graph::{ module_graph::{
...@@ -320,6 +320,11 @@ pub trait ChunkingContext { ...@@ -320,6 +320,11 @@ pub trait ChunkingContext {
#[turbo_tasks::function] #[turbo_tasks::function]
fn chunk_root_path(self: Vc<Self>) -> Vc<FileSystemPath>; fn chunk_root_path(self: Vc<Self>) -> Vc<FileSystemPath>;
#[turbo_tasks::function]
fn chunk_loading(self: Vc<Self>) -> Vc<ChunkLoading> {
self.environment().chunk_loading()
}
// TODO(alexkirsz) Remove this from the chunking context. This should be at the // TODO(alexkirsz) Remove this from the chunking context. This should be at the
// discretion of chunking context implementors. However, we currently use this // discretion of chunking context implementors. However, we currently use this
// in a couple of places in `turbopack-css`, so we need to remove that // in a couple of places in `turbopack-css`, so we need to remove that
......
...@@ -30,13 +30,21 @@ impl Rendering { ...@@ -30,13 +30,21 @@ impl Rendering {
} }
} }
#[turbo_tasks::value] #[turbo_tasks::value(shared)]
pub enum ChunkLoading { pub enum ChunkLoading {
Edge, Edge,
/// CommonJS in Node.js /// CommonJS in Node.js
NodeJs, NodeJs,
/// `<script>` and `<link>` tags in the browser /// `<script>` and `<link>` tags in the browser
Dom, Dom,
/// Everything inlined into one entry chunk
SingleChunk,
}
impl ChunkLoading {
pub fn can_split_async(&self) -> bool {
matches!(self, ChunkLoading::NodeJs | ChunkLoading::Dom)
}
} }
#[turbo_tasks::value] #[turbo_tasks::value]
......
...@@ -27,6 +27,7 @@ pub async fn get_browser_runtime_code( ...@@ -27,6 +27,7 @@ pub async fn get_browser_runtime_code(
cross_origin: Vc<CrossOrigin>, cross_origin: Vc<CrossOrigin>,
chunk_load_retry: Vc<ChunkLoadRetry>, chunk_load_retry: Vc<ChunkLoadRetry>,
has_async_modules: bool, has_async_modules: bool,
chunk_loading: Vc<ChunkLoading>,
) -> Result<Vc<Code>> { ) -> Result<Vc<Code>> {
let asset_context = *asset_context; let asset_context = *asset_context;
let environment = asset_context.compile_time_info().environment(); let environment = asset_context.compile_time_info().environment();
...@@ -50,21 +51,19 @@ pub async fn get_browser_runtime_code( ...@@ -50,21 +51,19 @@ pub async fn get_browser_runtime_code(
} }
} }
let chunk_loading = &*asset_context let chunk_loading = &*chunk_loading.await?;
.compile_time_info()
.environment()
.chunk_loading()
.await?;
let mut runtime_backend_code = vec![]; let mut runtime_backend_code = vec![];
match (chunk_loading, runtime_type) { match (chunk_loading, runtime_type) {
(ChunkLoading::Edge, RuntimeType::Development) => { // The self-contained backend performs no runtime chunk loading and registers chunks only
// via `globalThis`/`self` (no DOM).
(ChunkLoading::Edge | ChunkLoading::SingleChunk, RuntimeType::Development) => {
runtime_backend_code runtime_backend_code
.push("browser/runtime/self-contained/runtime-backend-self-contained.ts"); .push("browser/runtime/self-contained/runtime-backend-self-contained.ts");
runtime_backend_code runtime_backend_code
.push("browser/runtime/self-contained/dev-backend-self-contained.ts"); .push("browser/runtime/self-contained/dev-backend-self-contained.ts");
} }
(ChunkLoading::Edge, RuntimeType::Production) => { (ChunkLoading::Edge | ChunkLoading::SingleChunk, RuntimeType::Production) => {
runtime_backend_code runtime_backend_code
.push("browser/runtime/self-contained/runtime-backend-self-contained.ts"); .push("browser/runtime/self-contained/runtime-backend-self-contained.ts");
} }
...@@ -141,8 +140,11 @@ pub async fn get_browser_runtime_code( ...@@ -141,8 +140,11 @@ pub async fn get_browser_runtime_code(
)?; )?;
} }
AssetSuffix::Inferred => { AssetSuffix::Inferred => {
if chunk_loading == &ChunkLoading::Edge { if matches!(
panic!("AssetSuffix::Inferred is not supported in Edge runtimes"); chunk_loading,
ChunkLoading::Edge | ChunkLoading::SingleChunk
) {
panic!("AssetSuffix::Inferred is not supported in Edge or single-chunk runtimes");
} }
writedoc!( writedoc!(
code, code,
......
...@@ -10,7 +10,6 @@ use turbo_tasks::{ ...@@ -10,7 +10,6 @@ use turbo_tasks::{
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkingContext, ChunkingType}, chunk::{ChunkingContext, ChunkingType},
environment::ChunkLoading,
issue::IssueSource, issue::IssueSource,
module::Module, module::Module,
reference::ModuleReference, reference::ModuleReference,
...@@ -154,13 +153,10 @@ impl EsmAsyncAssetReferenceCodeGen { ...@@ -154,13 +153,10 @@ impl EsmAsyncAssetReferenceCodeGen {
*reference.origin, *reference.origin,
chunking_context, chunking_context,
self.reference.resolve_reference(), self.reference.resolve_reference(),
if matches!( if chunking_context.chunk_loading().await?.can_split_async() {
*chunking_context.environment().chunk_loading().await?,
ChunkLoading::Edge
) {
ResolveType::ChunkItem
} else {
ResolveType::AsyncChunkLoader ResolveType::AsyncChunkLoader
} else {
ResolveType::ChunkItem
}, },
) )
.await?; .await?;
......
...@@ -97,6 +97,8 @@ struct SnapshotOptions { ...@@ -97,6 +97,8 @@ struct SnapshotOptions {
#[serde(default)] #[serde(default)]
production_chunking: bool, production_chunking: bool,
#[serde(default)] #[serde(default)]
single_chunk: bool,
#[serde(default)]
enable_debug_ids: bool, enable_debug_ids: bool,
#[serde(default)] #[serde(default)]
source_map_source_type: SourceMapSourceType, source_map_source_type: SourceMapSourceType,
...@@ -134,6 +136,7 @@ impl Default for SnapshotOptions { ...@@ -134,6 +136,7 @@ impl Default for SnapshotOptions {
remove_unused_exports: false, remove_unused_exports: false,
scope_hoisting: false, scope_hoisting: false,
production_chunking: false, production_chunking: false,
single_chunk: false,
enable_debug_ids: false, enable_debug_ids: false,
source_map_source_type: SourceMapSourceType::default(), source_map_source_type: SourceMapSourceType::default(),
chunk_loading_global: default_chunk_loading_global(), chunk_loading_global: default_chunk_loading_global(),
...@@ -518,6 +521,10 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -518,6 +521,10 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
.source_map_source_type(options.source_map_source_type) .source_map_source_type(options.source_map_source_type)
.chunk_loading_global(options.chunk_loading_global.into()); .chunk_loading_global(options.chunk_loading_global.into());
if options.single_chunk {
builder = builder.single_chunk().await?;
}
if options.remove_unused_imports { if options.remove_unused_imports {
builder = builder.unused_references( builder = builder.unused_references(
binding_usage binding_usage
...@@ -595,6 +602,27 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -595,6 +602,27 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
// TODO: Load runtime entries from snapshots // TODO: Load runtime entries from snapshots
let chunks = match options.runtime { let chunks = match options.runtime {
Runtime::Browser if options.single_chunk => OutputAssetsWithReferenced {
assets: ResolvedVc::cell(vec![
chunking_context
.entry_chunk_group(
// `expected` expects a completely flat output directory.
chunk_root_path
.join(entry_module.ident().await?.path.file_stem().unwrap())?
.with_extension("entry.js"),
ChunkGroup::Entry(entry_modules),
module_graph,
OutputAssets::empty(),
OutputAssets::empty(),
AvailabilityInfo::root(),
)
.await?
.asset,
]),
referenced_assets: ResolvedVc::cell(vec![]),
references: ResolvedVc::cell(vec![]),
}
.cell(),
Runtime::Browser => chunking_context.evaluated_chunk_group_assets( Runtime::Browser => chunking_context.evaluated_chunk_group_assets(
entry_module.ident(), entry_module.ident(),
ChunkGroup::Entry(entry_modules.into_iter().collect()), ChunkGroup::Entry(entry_modules.into_iter().collect()),
......
// `dep1` is reached via `import('./dep1')` and itself dynamically imports
// `dep2` — exercising a nested dynamic-import boundary that must also inline.
export function dep1() {
console.log('dep1')
import('./dep2').then(({ dep2 }) => {
dep2()
})
}
// Leaf module reached via the nested `import('./dep2')`.
export function dep2() {
console.log('dep2')
}
// Service-worker-style entry: the whole transitive closure (including the
// dynamic `import()` targets) must be inlined into a single output file.
console.log('service worker entry')
import('./dep1').then(({ dep1 }) => {
dep1()
})
{
"minifyType": "NoMinify",
"runtime": "Browser",
"singleChunk": true
}
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1do3_crates_turbopack-tests_tests_snapshot_basic_single-chunk-entry_input_0085tus._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/dep1.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
// `dep1` is reached via `import('./dep1')` and itself dynamically imports
// `dep2` — exercising a nested dynamic-import boundary that must also inline.
__turbopack_context__.s([
"dep1",
()=>dep1
]);
function dep1() {
console.log('dep1');
Promise.resolve().then(()=>__turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/dep2.js [test] (ecmascript)")).then(({ dep2 })=>{
dep2();
});
}
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/dep2.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
// Leaf module reached via the nested `import('./dep2')`.
__turbopack_context__.s([
"dep2",
()=>dep2
]);
function dep2() {
console.log('dep2');
}
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/index.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
// Service-worker-style entry: the whole transitive closure (including the
// dynamic `import()` targets) must be inlined into a single output file.
console.log('service worker entry');
Promise.resolve().then(()=>__turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/dep1.js [test] (ecmascript)")).then(({ dep1 })=>{
dep1();
});
}),
]);(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1i9t_crates_turbopack-tests_tests_snapshot_basic_single-chunk-entry_input_1gjyv-z._.js",
{"otherChunks":[],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
//# sourceMappingURL=index.entry.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/single-chunk-entry/input/dep1.js"],"sourcesContent":["// `dep1` is reached via `import('./dep1')` and itself dynamically imports\n// `dep2` — exercising a nested dynamic-import boundary that must also inline.\nexport function dep1() {\n console.log('dep1')\n import('./dep2').then(({ dep2 }) => {\n dep2()\n })\n}\n"],"names":["dep1","console","log","then","dep2"],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;;;;;AACvE,SAASA;IACdC,QAAQC,GAAG,CAAC;IACZ,4KAAiBC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE;QAC7BA;IACF;AACF"}},
{"offset": {"line": 20, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/dep2.js"],"sourcesContent":["// Leaf module reached via the nested `import('./dep2')`.\nexport function dep2() {\n console.log('dep2')\n}\n"],"names":["dep2","console","log"],"mappings":"AAAA,yDAAyD;;;;;AAClD,SAASA;IACdC,QAAQC,GAAG,CAAC;AACd"}},
{"offset": {"line": 31, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic/single-chunk-entry/input/index.js"],"sourcesContent":["// Service-worker-style entry: the whole transitive closure (including the\n// dynamic `import()` targets) must be inlined into a single output file.\nconsole.log('service worker entry')\n\nimport('./dep1').then(({ dep1 }) => {\n dep1()\n})\n"],"names":["console","log","then","dep1"],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AACzEA,QAAQC,GAAG,CAAC;AAEZ,4KAAiBC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE;IAC7BA;AACF"}}]
}
\ No newline at end of file
...@@ -72,6 +72,7 @@ impl WebAssemblyModuleAsset { ...@@ -72,6 +72,7 @@ impl WebAssemblyModuleAsset {
.environment() .environment()
.chunk_loading() .chunk_loading()
.await?; .await?;
let is_edge = matches!(*chunk_loading, ChunkLoading::Edge); let is_edge = matches!(*chunk_loading, ChunkLoading::Edge);
let loader_source = if query == "?module" { let loader_source = if query == "?module" {
...@@ -84,6 +85,10 @@ impl WebAssemblyModuleAsset { ...@@ -84,6 +85,10 @@ impl WebAssemblyModuleAsset {
ChunkLoading::Edge => rcstr!("edge/loadWasm.ts"), ChunkLoading::Edge => rcstr!("edge/loadWasm.ts"),
ChunkLoading::NodeJs => rcstr!("node/loadWasm.ts"), ChunkLoading::NodeJs => rcstr!("node/loadWasm.ts"),
ChunkLoading::Dom => rcstr!("browser/loadWasm.ts"), ChunkLoading::Dom => rcstr!("browser/loadWasm.ts"),
ChunkLoading::SingleChunk => unreachable!(
"Environment::chunk_loading never returns SingleChunk; single-chunk WASM is \
rejected in chunk_item_content"
),
}; };
let helper = self let helper = self
...@@ -223,6 +228,16 @@ impl EcmascriptChunkPlaceable for WebAssemblyModuleAsset { ...@@ -223,6 +228,16 @@ impl EcmascriptChunkPlaceable for WebAssemblyModuleAsset {
async_module_info: Option<Vc<AsyncModuleInfo>>, async_module_info: Option<Vc<AsyncModuleInfo>>,
estimated: bool, estimated: bool,
) -> Result<Vc<EcmascriptChunkItemContent>> { ) -> Result<Vc<EcmascriptChunkItemContent>> {
if matches!(
*chunking_context.chunk_loading().await?,
ChunkLoading::SingleChunk
) {
bail!(
"WebAssembly imports are not supported in single-chunk (service-worker) \
entrypoints"
);
}
// Delegate to the loader's chunk item content // Delegate to the loader's chunk item content
Ok(self.loader().chunk_item_content( Ok(self.loader().chunk_item_content(
chunking_context, chunking_context,
......
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