Skip to content

Commit

Permalink
add CompileTimeInfo struct for passing compile time info
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 10, 2023
1 parent a00b6a3 commit e05ffba
Show file tree
Hide file tree
Showing 38 changed files with 1,607 additions and 362 deletions.
11 changes: 7 additions & 4 deletions crates/next-core/src/app_render/next_layout_entry_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use turbopack::{
};
use turbopack_core::{
asset::{Asset, AssetVc},
environment::EnvironmentVc,
compile_time_info::CompileTimeInfoVc,
virtual_asset::VirtualAssetVc,
};
use turbopack_ecmascript::chunk::EcmascriptChunkPlaceableVc;
Expand All @@ -20,7 +20,7 @@ use crate::{

#[turbo_tasks::value(shared)]
pub struct NextLayoutEntryTransition {
pub rsc_environment: EnvironmentVc,
pub rsc_compile_time_info: CompileTimeInfoVc,
pub rsc_module_options_context: ModuleOptionsContextVc,
pub rsc_resolve_options_context: ResolveOptionsContextVc,
pub server_root: FileSystemPathVc,
Expand All @@ -38,8 +38,11 @@ impl Transition for NextLayoutEntryTransition {
}

#[turbo_tasks::function]
fn process_environment(&self, _environment: EnvironmentVc) -> EnvironmentVc {
self.rsc_environment
fn process_compile_time_info(
&self,
_compile_time_info: CompileTimeInfoVc,
) -> CompileTimeInfoVc {
self.rsc_compile_time_info
}

#[turbo_tasks::function]
Expand Down
33 changes: 19 additions & 14 deletions crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ use crate::{
fallback::get_fallback_page,
next_client::{
context::{
get_client_chunking_context, get_client_environment, get_client_module_options_context,
get_client_resolve_options_context, get_client_runtime_entries, ClientContextType,
get_client_chunking_context, get_client_compile_time_info,
get_client_module_options_context, get_client_resolve_options_context,
get_client_runtime_entries, ClientContextType,
},
transition::NextClientTransition,
},
Expand All @@ -65,7 +66,7 @@ use crate::{
next_config::NextConfigVc,
next_route_matcher::NextParamsMatcherVc,
next_server::context::{
get_server_environment, get_server_module_options_context,
get_server_compile_time_info, get_server_module_options_context,
get_server_resolve_options_context, ServerContextType,
},
util::pathname_for_path,
Expand All @@ -82,13 +83,17 @@ async fn next_client_transition(
next_config: NextConfigVc,
) -> Result<TransitionVc> {
let ty = Value::new(ClientContextType::App { app_dir });
let client_environment = get_client_environment(browserslist_query);
let client_chunking_context =
get_client_chunking_context(project_path, server_root, client_environment, ty);
let client_compile_time_info = get_client_compile_time_info(browserslist_query);
let client_chunking_context = get_client_chunking_context(
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);
let client_module_options_context = get_client_module_options_context(
project_path,
execution_context,
client_environment,
client_compile_time_info.environment(),
ty,
next_config,
);
Expand All @@ -102,7 +107,7 @@ async fn next_client_transition(
client_chunking_context,
client_module_options_context,
client_resolve_options_context,
client_environment,
client_compile_time_info,
runtime_entries: client_runtime_entries,
}
.cell()
Expand Down Expand Up @@ -131,7 +136,7 @@ fn next_ssr_client_module_transition(
ty,
next_config,
),
ssr_environment: get_server_environment(ty, process_env, server_addr),
ssr_environment: get_server_compile_time_info(ty, process_env, server_addr),
}
.cell()
.into()
Expand All @@ -148,14 +153,14 @@ fn next_layout_entry_transition(
server_addr: ServerAddrVc,
) -> TransitionVc {
let ty = Value::new(ServerContextType::AppRSC { app_dir });
let rsc_environment = get_server_environment(ty, process_env, server_addr);
let rsc_compile_time_info = get_server_compile_time_info(ty, process_env, server_addr);
let rsc_resolve_options_context =
get_server_resolve_options_context(project_path, ty, next_config);
let rsc_module_options_context =
get_server_module_options_context(project_path, execution_context, ty, next_config);

NextLayoutEntryTransition {
rsc_environment,
rsc_compile_time_info,
rsc_module_options_context,
rsc_resolve_options_context,
server_root,
Expand Down Expand Up @@ -236,7 +241,7 @@ fn app_context(
let ssr_ty = Value::new(ServerContextType::AppSSR { app_dir });
ModuleAssetContextVc::new(
TransitionsByNameVc::cell(transitions),
get_server_environment(ssr_ty, env, server_addr),
get_server_compile_time_info(ssr_ty, env, server_addr),
get_server_module_options_context(project_path, execution_context, ssr_ty, next_config),
get_server_resolve_options_context(project_path, ssr_ty, next_config),
)
Expand Down Expand Up @@ -637,7 +642,7 @@ import BOOTSTRAP from {};
intermediate_output_path,
intermediate_output_path.join("chunks"),
this.server_root.join("_next/static/assets"),
context.environment(),
context.compile_time_info().environment(),
)
.layer("ssr")
.css_chunk_root_path(this.server_root.join("_next/static/chunks"))
Expand All @@ -652,7 +657,7 @@ import BOOTSTRAP from {};
EcmascriptInputTransform::React { refresh: false },
EcmascriptInputTransform::TypeScript,
]),
context.environment(),
context.compile_time_info(),
),
chunking_context,
intermediate_output_path,
Expand Down
19 changes: 12 additions & 7 deletions crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use turbopack_node::execution_context::ExecutionContextVc;

use crate::{
next_client::context::{
get_client_chunking_context, get_client_environment, get_client_module_options_context,
get_client_resolve_options_context, get_client_runtime_entries, ClientContextType,
get_client_chunking_context, get_client_compile_time_info,
get_client_module_options_context, get_client_resolve_options_context,
get_client_runtime_entries, ClientContextType,
},
next_config::NextConfigVc,
next_import_map::{insert_alias_option, insert_next_shared_aliases},
Expand All @@ -35,17 +36,21 @@ pub async fn get_fallback_page(
next_config: NextConfigVc,
) -> Result<DevHtmlAssetVc> {
let ty = Value::new(ClientContextType::Fallback);
let environment = get_client_environment(browserslist_query);
let client_compile_time_info = get_client_compile_time_info(browserslist_query);
let resolve_options_context = get_client_resolve_options_context(project_path, ty, next_config);
let module_options_context = get_client_module_options_context(
project_path,
execution_context,
environment,
client_compile_time_info.environment(),
ty,
next_config,
);
let chunking_context =
get_client_chunking_context(project_path, dev_server_root, environment, ty);
let chunking_context = get_client_chunking_context(
project_path,
dev_server_root,
client_compile_time_info.environment(),
ty,
);
let entries = get_client_runtime_entries(project_path, env, ty, next_config);

let mut import_map = ImportMap::empty();
Expand All @@ -60,7 +65,7 @@ pub async fn get_fallback_page(

let context: AssetContextVc = ModuleAssetContextVc::new(
TransitionsByNameVc::cell(HashMap::new()),
environment,
client_compile_time_info,
module_options_context,
resolve_options_context.with_extended_import_map(import_map.cell()),
)
Expand Down
36 changes: 20 additions & 16 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use turbopack::{
};
use turbopack_core::{
chunk::{dev::DevChunkingContextVc, ChunkingContextVc},
compile_time_info::{CompileTimeInfo, CompileTimeInfoVc},
context::AssetContextVc,
environment::{BrowserEnvironment, EnvironmentIntention, EnvironmentVc, ExecutionEnvironment},
resolve::{parse::RequestVc, pattern::Pattern},
Expand All @@ -39,19 +40,22 @@ use crate::{
};

#[turbo_tasks::function]
pub fn get_client_environment(browserslist_query: &str) -> EnvironmentVc {
EnvironmentVc::new(
Value::new(ExecutionEnvironment::Browser(
BrowserEnvironment {
dom: true,
web_worker: false,
service_worker: false,
browserslist_query: browserslist_query.to_owned(),
}
.into(),
)),
Value::new(EnvironmentIntention::Client),
)
pub fn get_client_compile_time_info(browserslist_query: &str) -> CompileTimeInfoVc {
CompileTimeInfo {
environment: EnvironmentVc::new(
Value::new(ExecutionEnvironment::Browser(
BrowserEnvironment {
dom: true,
web_worker: false,
service_worker: false,
browserslist_query: browserslist_query.to_owned(),
}
.into(),
)),
Value::new(EnvironmentIntention::Client),
),
}
.cell()
}

#[turbo_tasks::value(serialization = "auto_for_input")]
Expand Down Expand Up @@ -145,22 +149,22 @@ pub async fn get_client_module_options_context(
pub fn get_client_asset_context(
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
environment: EnvironmentVc,
compile_time_info: CompileTimeInfoVc,
ty: Value<ClientContextType>,
next_config: NextConfigVc,
) -> AssetContextVc {
let resolve_options_context = get_client_resolve_options_context(project_path, ty, next_config);
let module_options_context = get_client_module_options_context(
project_path,
execution_context,
environment,
compile_time_info.environment(),
ty,
next_config,
);

let context: AssetContextVc = ModuleAssetContextVc::new(
TransitionsByNameVc::cell(HashMap::new()),
environment,
compile_time_info,
module_options_context,
resolve_options_context,
)
Expand Down
11 changes: 7 additions & 4 deletions crates/next-core/src/next_client/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use turbopack::{
use turbopack_core::{
asset::{Asset, AssetVc},
chunk::{ChunkableAssetVc, ChunkingContextVc},
environment::EnvironmentVc,
compile_time_info::CompileTimeInfoVc,
virtual_asset::VirtualAssetVc,
};

Expand All @@ -26,7 +26,7 @@ use crate::embed_js::next_js_file;
#[turbo_tasks::value(shared)]
pub struct NextClientTransition {
pub is_app: bool,
pub client_environment: EnvironmentVc,
pub client_compile_time_info: CompileTimeInfoVc,
pub client_module_options_context: ModuleOptionsContextVc,
pub client_resolve_options_context: ResolveOptionsContextVc,
pub client_chunking_context: ChunkingContextVc,
Expand Down Expand Up @@ -54,8 +54,11 @@ impl Transition for NextClientTransition {
}

#[turbo_tasks::function]
fn process_environment(&self, _environment: EnvironmentVc) -> EnvironmentVc {
self.client_environment
fn process_compile_time_info(
&self,
_compile_time_info: CompileTimeInfoVc,
) -> CompileTimeInfoVc {
self.client_compile_time_info
}

#[turbo_tasks::function]
Expand Down
31 changes: 20 additions & 11 deletions crates/next-core/src/next_client_chunks/client_chunks_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ use turbopack::{
transition::{Transition, TransitionVc},
ModuleAssetContextVc,
};
use turbopack_core::{asset::AssetVc, chunk::ChunkingContextVc, environment::EnvironmentVc};
use turbopack_core::{
asset::AssetVc, chunk::ChunkingContextVc, compile_time_info::CompileTimeInfoVc,
};
use turbopack_node::execution_context::ExecutionContextVc;

use super::with_chunks::WithChunksAsset;
use crate::{
next_client::context::{
get_client_chunking_context, get_client_environment, get_client_module_options_context,
get_client_resolve_options_context, ClientContextType,
get_client_chunking_context, get_client_compile_time_info,
get_client_module_options_context, get_client_resolve_options_context, ClientContextType,
},
next_config::NextConfigVc,
};

#[turbo_tasks::value(shared)]
pub struct NextClientChunksTransition {
pub client_environment: EnvironmentVc,
pub client_compile_time_info: CompileTimeInfoVc,
pub client_module_options_context: ModuleOptionsContextVc,
pub client_resolve_options_context: ResolveOptionsContextVc,
pub client_chunking_context: ChunkingContextVc,
Expand All @@ -40,14 +42,18 @@ impl NextClientChunksTransitionVc {
browserslist_query: &str,
next_config: NextConfigVc,
) -> NextClientChunksTransitionVc {
let client_environment = get_client_environment(browserslist_query);
let client_chunking_context =
get_client_chunking_context(project_path, server_root, client_environment, ty);
let client_compile_time_info = get_client_compile_time_info(browserslist_query);
let client_chunking_context = get_client_chunking_context(
project_path,
server_root,
client_compile_time_info.environment(),
ty,
);

let client_module_options_context = get_client_module_options_context(
project_path,
execution_context,
client_environment,
client_compile_time_info.environment(),
ty,
next_config,
);
Expand All @@ -59,7 +65,7 @@ impl NextClientChunksTransitionVc {
ty,
next_config,
),
client_environment,
client_compile_time_info,
server_root,
}
.cell()
Expand All @@ -69,8 +75,11 @@ impl NextClientChunksTransitionVc {
#[turbo_tasks::value_impl]
impl Transition for NextClientChunksTransition {
#[turbo_tasks::function]
fn process_environment(&self, _environment: EnvironmentVc) -> EnvironmentVc {
self.client_environment
fn process_compile_time_info(
&self,
_compile_time_info: CompileTimeInfoVc,
) -> CompileTimeInfoVc {
self.client_compile_time_info
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ use turbopack::{
transition::{Transition, TransitionVc},
ModuleAssetContextVc,
};
use turbopack_core::{asset::AssetVc, environment::EnvironmentVc};
use turbopack_core::{asset::AssetVc, compile_time_info::CompileTimeInfoVc};

use super::with_chunking_context_scope_asset::WithChunkingContextScopeAsset;

#[turbo_tasks::value(shared)]
pub struct NextSSRClientModuleTransition {
pub ssr_environment: EnvironmentVc,
pub ssr_environment: CompileTimeInfoVc,
pub ssr_module_options_context: ModuleOptionsContextVc,
pub ssr_resolve_options_context: ResolveOptionsContextVc,
}

#[turbo_tasks::value_impl]
impl Transition for NextSSRClientModuleTransition {
#[turbo_tasks::function]
fn process_environment(&self, _environment: EnvironmentVc) -> EnvironmentVc {
fn process_compile_time_info(
&self,
_compile_time_info: CompileTimeInfoVc,
) -> CompileTimeInfoVc {
self.ssr_environment
}

Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub async fn load_next_config(execution_context: ExecutionContextVc) -> Result<N
context,
Value::new(EcmascriptModuleAssetType::Ecmascript),
EcmascriptInputTransformsVc::cell(vec![]),
context.environment(),
context.compile_time_info(),
)
.as_ecmascript_chunk_placeable();
EcmascriptChunkPlaceablesVc::cell(vec![config_chunk])
Expand Down
Loading

0 comments on commit e05ffba

Please sign in to comment.