Skip to content

Commit

Permalink
Merge 8b34f2f into 131c370
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 19, 2022
2 parents 131c370 + 8b34f2f commit 4f9d7e0
Show file tree
Hide file tree
Showing 56 changed files with 1,352 additions and 678 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/next-core/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"css.escape": "^1.5.1",
"next": "^13.0.6",
"platform": "1.3.6",
"postcss": "^8.4.20",
"react-dom": "^18.2.0",
"react": "^18.2.0",
"source-map": "0.8.0-beta.0",
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/js/src/entry/config/next.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const loadConfig = require("next/dist/server/config").default;
const { PHASE_DEVELOPMENT_SERVER } = require("next/dist/shared/lib/constants");

module.exports = (async () => {
module.exports = async () => {
const nextConfig = await loadConfig(PHASE_DEVELOPMENT_SERVER, process.cwd());
nextConfig.rewrites = await nextConfig.rewrites?.();
nextConfig.redirects = await nextConfig.redirects?.();
return nextConfig;
})();
};
86 changes: 58 additions & 28 deletions crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ use turbopack_ecmascript::{
};
use turbopack_env::ProcessEnvAssetVc;
use turbopack_node::{
create_node_rendered_source,
execution_context::ExecutionContextVc,
node_entry::{NodeRenderingEntry, NodeRenderingEntryVc},
render::rendered_source::create_node_rendered_source,
NodeEntry, NodeEntryVc,
};

Expand Down Expand Up @@ -69,21 +70,22 @@ use crate::{

#[turbo_tasks::function]
fn next_client_chunks_transition(
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
app_dir: FileSystemPathVc,
server_root: FileSystemPathVc,
browserslist_query: &str,
) -> TransitionVc {
let ty = Value::new(ContextType::App { app_dir });
let client_chunking_context = get_client_chunking_context(project_root, server_root, ty);
let client_chunking_context = get_client_chunking_context(project_path, server_root, ty);
let client_environment = get_client_environment(browserslist_query);

let client_module_options_context =
get_client_module_options_context(project_root, client_environment, ty);
get_client_module_options_context(project_path, execution_context, client_environment, ty);
NextClientChunksTransition {
client_chunking_context,
client_module_options_context,
client_resolve_options_context: get_client_resolve_options_context(project_root, ty),
client_resolve_options_context: get_client_resolve_options_context(project_path, ty),
client_environment,
server_root,
}
Expand All @@ -93,20 +95,21 @@ fn next_client_chunks_transition(

#[turbo_tasks::function]
async fn next_client_transition(
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
server_root: FileSystemPathVc,
app_dir: FileSystemPathVc,
env: ProcessEnvVc,
browserslist_query: &str,
next_config: NextConfigVc,
) -> Result<TransitionVc> {
let ty = Value::new(ContextType::App { app_dir });
let client_chunking_context = get_client_chunking_context(project_root, server_root, ty);
let client_chunking_context = get_client_chunking_context(project_path, server_root, ty);
let client_environment = get_client_environment(browserslist_query);
let client_module_options_context =
get_client_module_options_context(project_root, client_environment, ty);
let client_runtime_entries = get_client_runtime_entries(project_root, env, ty, next_config);
let client_resolve_options_context = get_client_resolve_options_context(project_root, ty);
get_client_module_options_context(project_path, execution_context, client_environment, ty);
let client_runtime_entries = get_client_runtime_entries(project_path, env, ty, next_config);
let client_resolve_options_context = get_client_resolve_options_context(project_path, ty);

Ok(NextClientTransition {
is_app: true,
Expand All @@ -123,16 +126,17 @@ async fn next_client_transition(

#[turbo_tasks::function]
fn next_ssr_client_module_transition(
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
app_dir: FileSystemPathVc,
process_env: ProcessEnvVc,
next_config: NextConfigVc,
) -> TransitionVc {
let ty = Value::new(ServerContextType::AppSSR { app_dir });
NextSSRClientModuleTransition {
ssr_module_options_context: get_server_module_options_context(ty),
ssr_module_options_context: get_server_module_options_context(execution_context, ty),
ssr_resolve_options_context: get_server_resolve_options_context(
project_root,
project_path,
ty,
next_config,
),
Expand All @@ -144,7 +148,8 @@ fn next_ssr_client_module_transition(

#[turbo_tasks::function]
fn next_layout_entry_transition(
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
app_dir: FileSystemPathVc,
server_root: FileSystemPathVc,
process_env: ProcessEnvVc,
Expand All @@ -153,8 +158,8 @@ fn next_layout_entry_transition(
let ty = Value::new(ServerContextType::AppRSC { app_dir });
let rsc_environment = get_server_environment(ty, process_env);
let rsc_resolve_options_context =
get_server_resolve_options_context(project_root, ty, next_config);
let rsc_module_options_context = get_server_module_options_context(ty);
get_server_resolve_options_context(project_path, ty, next_config);
let rsc_module_options_context = get_server_module_options_context(execution_context, ty);

NextLayoutEntryTransition {
rsc_environment,
Expand All @@ -168,7 +173,8 @@ fn next_layout_entry_transition(

#[turbo_tasks::function]
fn app_context(
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
server_root: FileSystemPathVc,
app_dir: FileSystemPathVc,
env: ProcessEnvVc,
Expand All @@ -181,7 +187,14 @@ fn app_context(
let mut transitions = HashMap::new();
transitions.insert(
"next-layout-entry".to_string(),
next_layout_entry_transition(project_root, app_dir, server_root, env, next_config),
next_layout_entry_transition(
project_path,
execution_context,
app_dir,
server_root,
env,
next_config,
),
);
transitions.insert(
"server-to-client".to_string(),
Expand All @@ -190,7 +203,8 @@ fn app_context(
transitions.insert(
"next-client".to_string(),
next_client_transition(
project_root,
project_path,
execution_context,
server_root,
app_dir,
env,
Expand All @@ -200,19 +214,31 @@ fn app_context(
);
transitions.insert(
"next-client-chunks".to_string(),
next_client_chunks_transition(project_root, app_dir, server_root, browserslist_query),
next_client_chunks_transition(
project_path,
execution_context,
app_dir,
server_root,
browserslist_query,
),
);
transitions.insert(
"next-ssr-client-module".to_string(),
next_ssr_client_module_transition(project_root, app_dir, env, next_config),
next_ssr_client_module_transition(
project_path,
execution_context,
app_dir,
env,
next_config,
),
);

let ssr_ty = Value::new(ServerContextType::AppSSR { app_dir });
ModuleAssetContextVc::new(
TransitionsByNameVc::cell(transitions),
get_server_environment(ssr_ty, env),
get_server_module_options_context(ssr_ty),
get_server_resolve_options_context(project_root, ssr_ty, next_config),
get_server_module_options_context(execution_context, ssr_ty),
get_server_resolve_options_context(project_path, ssr_ty, next_config),
)
.into()
}
Expand All @@ -222,6 +248,7 @@ fn app_context(
#[turbo_tasks::function]
pub async fn create_app_source(
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
output_path: FileSystemPathVc,
server_root: FileSystemPathVc,
env: ProcessEnvVc,
Expand All @@ -246,6 +273,7 @@ pub async fn create_app_source(

let context_ssr = app_context(
project_path,
execution_context,
server_root,
app_dir,
env,
Expand All @@ -255,6 +283,7 @@ pub async fn create_app_source(
);
let context = app_context(
project_path,
execution_context,
server_root,
app_dir,
env,
Expand All @@ -271,6 +300,7 @@ pub async fn create_app_source(

let fallback_page = get_fallback_page(
project_path,
execution_context,
server_root,
env,
browserslist_query,
Expand Down Expand Up @@ -298,7 +328,7 @@ pub async fn create_app_source(
async fn create_app_source_for_directory(
context_ssr: AssetContextVc,
context: AssetContextVc,
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
specificity: SpecificityVc,
position: u32,
input_dir: FileSystemPathVc,
Expand Down Expand Up @@ -392,7 +422,7 @@ async fn create_app_source_for_directory(
layout_path: layouts,
page_path,
target,
project_root,
project_path,
intermediate_output_path,
}
.cell()
Expand Down Expand Up @@ -422,7 +452,7 @@ async fn create_app_source_for_directory(
create_app_source_for_directory(
context_ssr,
context,
project_root,
project_path,
specificity,
position,
*dir,
Expand All @@ -449,7 +479,7 @@ struct AppRenderer {
layout_path: LayoutSegmentsVc,
page_path: FileSystemPathVc,
target: FileSystemPathVc,
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
intermediate_output_path: FileSystemPathVc,
}

Expand Down Expand Up @@ -580,7 +610,7 @@ import BOOTSTRAP from {};
};

let chunking_context = DevChunkingContextVc::builder(
self.project_root,
self.project_path,
intermediate_output_path,
intermediate_output_path.join("chunks"),
self.server_root.join("_next/static/assets"),
Expand Down
17 changes: 10 additions & 7 deletions crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use turbopack_core::{
resolve::{options::ImportMap, origin::PlainResolveOriginVc},
};
use turbopack_dev_server::html::DevHtmlAssetVc;
use turbopack_node::execution_context::ExecutionContextVc;

use crate::{
next_client::context::{
Expand All @@ -26,21 +27,23 @@ use crate::{

#[turbo_tasks::function]
pub async fn get_fallback_page(
project_root: FileSystemPathVc,
project_path: FileSystemPathVc,
execution_context: ExecutionContextVc,
dev_server_root: FileSystemPathVc,
env: ProcessEnvVc,
browserslist_query: &str,
next_config: NextConfigVc,
) -> Result<DevHtmlAssetVc> {
let ty = Value::new(ContextType::Fallback);
let environment = get_client_environment(browserslist_query);
let resolve_options_context = get_client_resolve_options_context(project_root, ty);
let module_options_context = get_client_module_options_context(project_root, environment, ty);
let chunking_context = get_client_chunking_context(project_root, dev_server_root, ty);
let entries = get_client_runtime_entries(project_root, env, ty, next_config);
let resolve_options_context = get_client_resolve_options_context(project_path, ty);
let module_options_context =
get_client_module_options_context(project_path, execution_context, environment, ty);
let chunking_context = get_client_chunking_context(project_path, dev_server_root, ty);
let entries = get_client_runtime_entries(project_path, env, ty, next_config);

let mut import_map = ImportMap::empty();
insert_next_shared_aliases(&mut import_map, project_root);
insert_next_shared_aliases(&mut import_map, project_path);

let context: AssetContextVc = ModuleAssetContextVc::new(
TransitionsByNameVc::cell(HashMap::new()),
Expand All @@ -53,7 +56,7 @@ pub async fn get_fallback_page(
let runtime_entries = entries.resolve_entries(context);

let fallback_chunk = resolve_runtime_request(
PlainResolveOriginVc::new(context, project_root).into(),
PlainResolveOriginVc::new(context, project_path).into(),
"entry/fallback",
);

Expand Down
5 changes: 3 additions & 2 deletions crates/next-core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use turbopack_core::asset::AssetContentVc;
use turbopack_dev_server::source::{
ContentSource, ContentSourceContent, ContentSourceData, ContentSourceResultVc, ContentSourceVc,
};
use turbopack_node::{
node_api_source::NodeApiContentSourceVc, node_rendered_source::NodeRenderContentSourceVc,
use turbopack_node::render::{
node_api_source::NodeApiContentSourceVc, rendered_source::NodeRenderContentSourceVc,
};

/// A content source which creates the next.js `_devPagesManifest.json` and
Expand All @@ -29,6 +29,7 @@ impl DevManifestContentSourceVc {
while let Some(content_source) = queue.pop() {
queue.extend(content_source.get_children().await?.iter());

// TODO This shouldn't use casts but an public api instead
if let Some(api_source) = NodeApiContentSourceVc::resolve_from(content_source).await? {
routes.insert(format!("/{}", api_source.get_pathname().await?));

Expand Down

0 comments on commit 4f9d7e0

Please sign in to comment.