Skip to content

Commit

Permalink
Make get_client_chunking_context independent of context
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkirsz committed Jul 6, 2023
1 parent 37c40b7 commit f9d0020
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 57 deletions.
14 changes: 4 additions & 10 deletions packages/next-swc/crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ async fn next_client_transition(
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);
let client_module_options_context = get_client_module_options_context(
project_path,
Expand Down Expand Up @@ -277,7 +276,7 @@ fn next_edge_route_transition(
project_path,
output_path.join("edge"),
output_path.join("edge/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("app_source"))
Expand Down Expand Up @@ -317,7 +316,7 @@ fn next_edge_page_transition(
project_path,
output_path.join("edge-pages"),
output_path.join("edge-pages/chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
edge_compile_time_info.environment(),
)
.layer("ssr")
Expand Down Expand Up @@ -1110,7 +1109,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
project_path,
intermediate_output_path,
intermediate_output_path.join("chunks"),
get_client_assets_path(server_root, Value::new(ClientContextType::App { app_dir })),
get_client_assets_path(server_root),
context.compile_time_info().environment(),
)
.layer("ssr")
Expand Down Expand Up @@ -1205,12 +1204,7 @@ impl AppRouteVc {
this.project_path,
this.intermediate_output_path,
this.intermediate_output_path.join("chunks"),
get_client_assets_path(
this.server_root,
Value::new(ClientContextType::App {
app_dir: this.app_dir,
}),
),
get_client_assets_path(this.server_root),
this.context.compile_time_info().environment(),
)
.layer("ssr")
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub async fn get_fallback_page(
project_path,
dev_server_root,
client_compile_time_info.environment(),
ty,
);
let entries =
get_client_runtime_entries(project_path, env, ty, mode, next_config, execution_context);
Expand Down
26 changes: 6 additions & 20 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,37 +312,23 @@ pub fn get_client_asset_context(
#[turbo_tasks::function]
pub fn get_client_chunking_context(
project_path: FileSystemPathVc,
server_root: FileSystemPathVc,
client_root: FileSystemPathVc,
environment: EnvironmentVc,
ty: Value<ClientContextType>,
) -> ChunkingContextVc {
DevChunkingContextVc::builder(
project_path,
server_root,
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => server_root.join("/_next/static/chunks"),
ClientContextType::Other => server_root.join("/_chunks"),
},
get_client_assets_path(server_root, ty),
client_root,
client_root.join("/_next/static/chunks"),
get_client_assets_path(client_root),
environment,
)
.hot_module_replacement()
.build()
}

#[turbo_tasks::function]
pub fn get_client_assets_path(
client_root: FileSystemPathVc,
ty: Value<ClientContextType>,
) -> FileSystemPathVc {
match ty.into_value() {
ClientContextType::Pages { .. }
| ClientContextType::App { .. }
| ClientContextType::Fallback => client_root.join("/_next/static/media"),
ClientContextType::Other => client_root.join("/_assets"),
}
pub fn get_client_assets_path(client_root: FileSystemPathVc) -> FileSystemPathVc {
client_root.join("/_next/static/media")
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl NextClientChunksTransitionVc {
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);

let client_module_options_context = get_client_module_options_context(
Expand Down
23 changes: 4 additions & 19 deletions packages/next-swc/crates/next-core/src/page_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub async fn create_page_source(
project_root,
client_root,
client_compile_time_info.environment(),
client_ty,
);

let client_runtime_entries = get_client_runtime_entries(
Expand Down Expand Up @@ -158,10 +157,7 @@ pub async fn create_page_source(
project_root,
node_root.join("edge"),
node_root.join("edge/chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
edge_compile_time_info.environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand Down Expand Up @@ -365,10 +361,7 @@ async fn create_page_source_for_file(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -380,10 +373,7 @@ async fn create_page_source_for_file(
project_path,
data_node_path,
data_node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -393,7 +383,6 @@ async fn create_page_source_for_file(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);

let pathname = pathname_for_path(client_root, client_path, PathType::Page);
Expand Down Expand Up @@ -535,10 +524,7 @@ async fn create_not_found_page_source(
project_path,
node_path,
node_path.join("chunks"),
get_client_assets_path(
client_root,
Value::new(ClientContextType::Pages { pages_dir }),
),
get_client_assets_path(client_root),
server_context.compile_time_info().environment(),
)
.reference_chunk_source_maps(should_debug("page_source"))
Expand All @@ -548,7 +534,6 @@ async fn create_not_found_page_source(
project_path,
client_root,
client_context.compile_time_info().environment(),
Value::new(ClientContextType::Pages { pages_dir }),
);

let (page_asset, pathname) =
Expand Down
8 changes: 2 additions & 6 deletions packages/next-swc/crates/next-core/src/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ pub async fn create_web_entry_source(
mode,
next_config,
);
let chunking_context = get_client_chunking_context(
project_root,
client_root,
compile_time_info.environment(),
ty,
);
let chunking_context =
get_client_chunking_context(project_root, client_root, compile_time_info.environment());
let entries = get_web_runtime_entries(project_root, ty, mode, next_config, execution_context);

let runtime_entries = entries.resolve_entries(context);
Expand Down

0 comments on commit f9d0020

Please sign in to comment.