Skip to content

Commit

Permalink
Revert "[Turbopack] Production Chunking (#75010)"
Browse files Browse the repository at this point in the history
This reverts commit 169829a.
  • Loading branch information
sokra authored Jan 20, 2025
1 parent 169829a commit 1dd04ba
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 472 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use turbopack::{
};
use turbopack_browser::{react_refresh::assert_can_resolve_react_refresh, BrowserChunkingContext};
use turbopack_core::{
chunk::{module_id_strategies::ModuleIdStrategy, ChunkingConfig, ChunkingContext, MinifyType},
chunk::{module_id_strategies::ModuleIdStrategy, ChunkingContext, MinifyType},
compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, DefineableNameSegment,
FreeVarReference, FreeVarReferences,
Expand Down Expand Up @@ -425,8 +425,6 @@ pub async fn get_client_chunking_context(

if next_mode.is_development() {
builder = builder.hot_module_replacement().use_file_source_map_uris();
} else {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}

Ok(Vc::upcast(builder.build()))
Expand Down
102 changes: 48 additions & 54 deletions crates/next-core/src/next_edge/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use turbo_tasks_fs::FileSystemPath;
use turbopack::resolve_options_context::ResolveOptionsContext;
use turbopack_browser::BrowserChunkingContext;
use turbopack_core::{
chunk::{module_id_strategies::ModuleIdStrategy, ChunkingConfig, ChunkingContext, MinifyType},
chunk::{module_id_strategies::ModuleIdStrategy, ChunkingContext, MinifyType},
compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, DefineableNameSegment,
FreeVarReference, FreeVarReferences,
Expand Down Expand Up @@ -211,32 +211,29 @@ pub async fn get_edge_chunking_context_with_client_assets(
) -> Result<Vc<Box<dyn ChunkingContext>>> {
let output_root = node_root.join("server/edge".into()).to_resolved().await?;
let next_mode = mode.await?;
let mut builder = BrowserChunkingContext::builder(
root_path,
output_root,
output_root_to_root_path,
client_root,
output_root.join("chunks/ssr".into()).to_resolved().await?,
client_root
.join("static/media".into())
.to_resolved()
.await?,
environment,
next_mode.runtime_type(),
)
.asset_base_path(asset_prefix)
.minify_type(if *turbo_minify.await? {
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.module_id_strategy(module_id_strategy);

if !next_mode.is_development() {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}

Ok(Vc::upcast(builder.build()))
Ok(Vc::upcast(
BrowserChunkingContext::builder(
root_path,
output_root,
output_root_to_root_path,
client_root,
output_root.join("chunks/ssr".into()).to_resolved().await?,
client_root
.join("static/media".into())
.to_resolved()
.await?,
environment,
next_mode.runtime_type(),
)
.asset_base_path(asset_prefix)
.minify_type(if *turbo_minify.await? {
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.module_id_strategy(module_id_strategy)
.build(),
))
}

#[turbo_tasks::function]
Expand All @@ -251,31 +248,28 @@ pub async fn get_edge_chunking_context(
) -> Result<Vc<Box<dyn ChunkingContext>>> {
let output_root = node_root.join("server/edge".into()).to_resolved().await?;
let next_mode = mode.await?;
let mut builder = BrowserChunkingContext::builder(
root_path,
output_root,
node_root_to_root_path,
output_root,
output_root.join("chunks".into()).to_resolved().await?,
output_root.join("assets".into()).to_resolved().await?,
environment,
next_mode.runtime_type(),
)
// Since one can't read files in edge directly, any asset need to be fetched
// instead. This special blob url is handled by the custom fetch
// implementation in the edge sandbox. It will respond with the
// asset from the output directory.
.asset_base_path(ResolvedVc::cell(Some("blob:server/edge/".into())))
.minify_type(if *turbo_minify.await? {
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.module_id_strategy(module_id_strategy);

if !next_mode.is_development() {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}

Ok(Vc::upcast(builder.build()))
Ok(Vc::upcast(
BrowserChunkingContext::builder(
root_path,
output_root,
node_root_to_root_path,
output_root,
output_root.join("chunks".into()).to_resolved().await?,
output_root.join("assets".into()).to_resolved().await?,
environment,
next_mode.runtime_type(),
)
// Since one can't read files in edge directly, any asset need to be fetched
// instead. This special blob url is handled by the custom fetch
// implementation in the edge sandbox. It will respond with the
// asset from the output directory.
.asset_base_path(ResolvedVc::cell(Some("blob:server/edge/".into())))
.minify_type(if *turbo_minify.await? {
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.module_id_strategy(module_id_strategy)
.build(),
))
}
7 changes: 1 addition & 6 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use turbopack::{
transition::Transition,
};
use turbopack_core::{
chunk::{module_id_strategies::ModuleIdStrategy, ChunkingConfig, MinifyType},
chunk::{module_id_strategies::ModuleIdStrategy, MinifyType},
compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, DefineableNameSegment,
FreeVarReferences,
Expand Down Expand Up @@ -1010,10 +1010,7 @@ pub async fn get_server_chunking_context_with_client_assets(

if next_mode.is_development() {
builder = builder.use_file_source_map_uris();
} else {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}

Ok(builder.build())
}

Expand Down Expand Up @@ -1051,8 +1048,6 @@ pub async fn get_server_chunking_context(

if next_mode.is_development() {
builder = builder.use_file_source_map_uris()
} else {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}

Ok(builder.build())
Expand Down
1 change: 0 additions & 1 deletion turbopack/crates/turbopack-browser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ workspace = true
anyhow = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_qs = { workspace = true }
Expand Down
31 changes: 3 additions & 28 deletions turbopack/crates/turbopack-browser/src/chunking_context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::{bail, Context, Result};
use rustc_hash::FxHashMap;
use tracing::Instrument;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc};
Expand All @@ -9,9 +8,8 @@ use turbopack_core::{
availability_info::AvailabilityInfo,
chunk_group::{make_chunk_group, MakeChunkGroupResult},
module_id_strategies::{DevModuleIdStrategy, ModuleIdStrategy},
Chunk, ChunkGroupResult, ChunkItem, ChunkableModule, ChunkableModules, ChunkingConfig,
ChunkingConfigs, ChunkingContext, EntryChunkGroupResult, EvaluatableAssets, MinifyType,
ModuleId,
Chunk, ChunkGroupResult, ChunkItem, ChunkableModule, ChunkableModules, ChunkingContext,
EntryChunkGroupResult, EvaluatableAssets, MinifyType, ModuleId,
},
environment::Environment,
ident::AssetIdent,
Expand All @@ -21,7 +19,7 @@ use turbopack_core::{
};
use turbopack_ecmascript::{
async_chunk::module::AsyncLoaderModule,
chunk::{EcmascriptChunk, EcmascriptChunkType},
chunk::EcmascriptChunk,
manifest::{chunk_asset::ManifestAsyncModule, loader_item::ManifestLoaderChunkItem},
};
use turbopack_ecmascript_runtime::RuntimeType;
Expand Down Expand Up @@ -100,14 +98,6 @@ impl BrowserChunkingContextBuilder {
self
}

pub fn ecmascript_chunking_config(
mut self,
ecmascript_chunking_config: ChunkingConfig,
) -> Self {
self.chunking_context.ecmascript_chunking_config = Some(ecmascript_chunking_config);
self
}

pub fn build(self) -> Vc<BrowserChunkingContext> {
BrowserChunkingContext::new(Value::new(self.chunking_context))
}
Expand Down Expand Up @@ -161,8 +151,6 @@ pub struct BrowserChunkingContext {
manifest_chunks: bool,
/// The module id strategy to use
module_id_strategy: ResolvedVc<Box<dyn ModuleIdStrategy>>,
/// The chunking config for ecmascript
ecmascript_chunking_config: Option<ChunkingConfig>,
}

impl BrowserChunkingContext {
Expand Down Expand Up @@ -197,7 +185,6 @@ impl BrowserChunkingContext {
minify_type: MinifyType::NoMinify,
manifest_chunks: false,
module_id_strategy: ResolvedVc::upcast(DevModuleIdStrategy::new_resolved()),
ecmascript_chunking_config: None,
},
}
}
Expand Down Expand Up @@ -395,18 +382,6 @@ impl ChunkingContext for BrowserChunkingContext {
Vc::cell(self.enable_hot_module_replacement)
}

#[turbo_tasks::function]
async fn chunking_configs(&self) -> Result<Vc<ChunkingConfigs>> {
let mut map = FxHashMap::default();
if let Some(ecmascript) = &self.ecmascript_chunking_config {
map.insert(
ResolvedVc::upcast(Vc::<EcmascriptChunkType>::default().to_resolved().await?),
ecmascript.clone(),
);
}
Ok(Vc::cell(map))
}

#[turbo_tasks::function]
fn should_use_file_source_map_uris(&self) -> Vc<bool> {
Vc::cell(self.should_use_file_source_map_uris)
Expand Down
40 changes: 12 additions & 28 deletions turbopack/crates/turbopack-cli/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use turbopack_cli_utils::issue::{ConsoleUi, LogOptions};
use turbopack_core::{
asset::Asset,
chunk::{
availability_info::AvailabilityInfo, ChunkingConfig, ChunkingContext, EvaluatableAsset,
EvaluatableAssets, MinifyType,
availability_info::AvailabilityInfo, ChunkingContext, EvaluatableAsset, EvaluatableAssets,
MinifyType,
},
environment::{BrowserEnvironment, Environment, ExecutionEnvironment, NodeJsEnvironment},
ident::AssetIdent,
Expand Down Expand Up @@ -208,8 +208,8 @@ async fn build_internal(
};

let chunking_context: Vc<Box<dyn ChunkingContext>> = match target {
Target::Browser => {
let mut builder = BrowserChunkingContext::builder(
Target::Browser => Vc::upcast(
BrowserChunkingContext::builder(
project_path,
build_output_root,
ResolvedVc::cell(build_output_root_to_root_path),
Expand All @@ -229,19 +229,11 @@ async fn build_internal(
.await?,
runtime_type,
)
.minify_type(minify_type);

match *node_env.await? {
NodeEnv::Development => {}
NodeEnv::Production => {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}
}

Vc::upcast(builder.build())
}
Target::Node => {
let mut builder = NodeJsChunkingContext::builder(
.minify_type(minify_type)
.build(),
),
Target::Node => Vc::upcast(
NodeJsChunkingContext::builder(
project_path,
build_output_root,
ResolvedVc::cell(build_output_root_to_root_path),
Expand All @@ -255,17 +247,9 @@ async fn build_internal(
.await?,
runtime_type,
)
.minify_type(minify_type);

match *node_env.await? {
NodeEnv::Development => {}
NodeEnv::Production => {
builder = builder.ecmascript_chunking_config(ChunkingConfig {})
}
}

Vc::upcast(builder.build())
}
.minify_type(minify_type)
.build(),
),
};

let compile_time_info = get_client_compile_time_info(browserslist_query, node_env);
Expand Down
2 changes: 0 additions & 2 deletions turbopack/crates/turbopack-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ patricia_tree = "0.5.5"
petgraph = { workspace = true, features = ["serde-1"] }
roaring = { version = "0.10.10", features = ["serde"] }
ref-cast = "1.0.20"
rustc-hash ={ workspace = true }
regex = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_bytes = { workspace = true }
serde_json = { workspace = true, features = ["preserve_order"] }
sourcemap = { workspace = true }
swc_core = { workspace = true, features = ["ecma_preset_env", "common"] }
tracing = { workspace = true }
turbo-prehash = { workspace = true }
turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-env = { workspace = true }
Expand Down
Loading

0 comments on commit 1dd04ba

Please sign in to comment.