Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CompileTimeInfo struct for passing compile time info #3685

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 28 additions & 22 deletions crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use turbopack::{
};
use turbopack_core::{
chunk::dev::DevChunkingContextVc,
compile_time_info::CompileTimeInfoVc,
context::{AssetContext, AssetContextVc},
environment::{EnvironmentVc, ServerAddrVc},
environment::ServerAddrVc,
issue::{Issue, IssueSeverity, IssueSeverityVc, IssueVc},
virtual_asset::VirtualAssetVc,
};
Expand Down Expand Up @@ -52,8 +53,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 +67,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 @@ -78,16 +80,20 @@ async fn next_client_transition(
server_root: FileSystemPathVc,
app_dir: FileSystemPathVc,
env: ProcessEnvVc,
client_environment: EnvironmentVc,
client_compile_time_info: CompileTimeInfoVc,
next_config: NextConfigVc,
) -> Result<TransitionVc> {
let ty = Value::new(ClientContextType::App { app_dir });
let client_chunking_context =
get_client_chunking_context(project_path, server_root, client_environment, ty);
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 @@ -101,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 @@ -130,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 @@ -147,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 All @@ -171,7 +177,7 @@ fn app_context(
server_root: FileSystemPathVc,
app_dir: FileSystemPathVc,
env: ProcessEnvVc,
client_environment: EnvironmentVc,
client_compile_time_info: CompileTimeInfoVc,
ssr: bool,
next_config: NextConfigVc,
server_addr: ServerAddrVc,
Expand Down Expand Up @@ -203,7 +209,7 @@ fn app_context(
server_root,
app_dir,
env,
client_environment,
client_compile_time_info,
next_config,
),
);
Expand All @@ -215,7 +221,7 @@ fn app_context(
execution_context,
client_ty,
server_root,
client_environment,
client_compile_time_info,
next_config,
)
.into(),
Expand All @@ -235,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 @@ -272,15 +278,15 @@ pub async fn create_app_source(
}
.resolve()
.await?;
let client_environment = get_client_environment(browserslist_query);
let client_compile_time_info = get_client_compile_time_info(browserslist_query);

let context_ssr = app_context(
project_path,
execution_context,
server_root,
app_dir,
env,
client_environment,
client_compile_time_info,
true,
next_config,
server_addr,
Expand All @@ -291,7 +297,7 @@ pub async fn create_app_source(
server_root,
app_dir,
env,
client_environment,
client_compile_time_info,
false,
next_config,
server_addr,
Expand All @@ -308,7 +314,7 @@ pub async fn create_app_source(
execution_context,
server_root,
env,
client_environment,
client_compile_time_info,
next_config,
);

Expand Down Expand Up @@ -643,7 +649,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 @@ -658,7 +664,7 @@ import BOOTSTRAP from {};
EcmascriptInputTransform::React { refresh: false },
EcmascriptInputTransform::TypeScript,
]),
context.environment(),
context.compile_time_info(),
),
chunking_context,
intermediate_output_path,
Expand Down
16 changes: 10 additions & 6 deletions crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use turbopack::{
};
use turbopack_core::{
chunk::ChunkGroupVc,
compile_time_info::CompileTimeInfoVc,
context::AssetContextVc,
environment::EnvironmentVc,
resolve::{options::ImportMap, origin::PlainResolveOriginVc},
};
use turbopack_dev_server::html::DevHtmlAssetVc;
Expand All @@ -32,20 +32,24 @@ pub async fn get_fallback_page(
execution_context: ExecutionContextVc,
dev_server_root: FileSystemPathVc,
env: ProcessEnvVc,
client_environment: EnvironmentVc,
client_compile_time_info: CompileTimeInfoVc,
next_config: NextConfigVc,
) -> Result<DevHtmlAssetVc> {
let ty = Value::new(ClientContextType::Fallback);
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,
client_environment,
client_compile_time_info.environment(),
ty,
next_config,
);
let chunking_context =
get_client_chunking_context(project_path, dev_server_root, client_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 +64,7 @@ pub async fn get_fallback_page(

let context: AssetContextVc = ModuleAssetContextVc::new(
TransitionsByNameVc::cell(HashMap::new()),
client_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
Loading