Skip to content

Commit

Permalink
Merge 70d2446 into f0dfb7a
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored Mar 3, 2023
2 parents f0dfb7a + 70d2446 commit fb6e3ce
Show file tree
Hide file tree
Showing 29 changed files with 474 additions and 135 deletions.
41 changes: 26 additions & 15 deletions crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::{BTreeMap, HashMap},
io::Write,
iter::once,
};

use anyhow::{anyhow, Result};
Expand All @@ -25,7 +26,8 @@ use turbopack_core::{
use turbopack_dev_server::{
html::DevHtmlAssetVc,
source::{
combined::CombinedContentSource, ContentSourceData, ContentSourceVc, NoContentSourceVc,
combined::CombinedContentSource, issue_context::IssueContextSourceVc, ContentSourceData,
ContentSourceVc, NoContentSourceVc,
},
};
use turbopack_ecmascript::{
Expand Down Expand Up @@ -478,21 +480,30 @@ async fn create_app_source_for_directory(
return Ok(NoContentSourceVc::new().into());
}
}
for child in children.iter() {
sources.push(create_app_source_for_directory(
*child,
context_ssr,
context,
project_path,
env,
server_root,
runtime_entries,
fallback_page,
intermediate_output_path_root,
));
}

Ok(CombinedContentSource { sources }.cell().into())
let source = CombinedContentSource { sources }.cell().into();
let source =
IssueContextSourceVc::new_context(directory, "Next.js app directory", source).into();

Ok(CombinedContentSource {
sources: once(source)
.chain(children.iter().map(|child| {
create_app_source_for_directory(
*child,
context_ssr,
context,
project_path,
env,
server_root,
runtime_entries,
fallback_page,
intermediate_output_path_root,
)
}))
.collect(),
}
.cell()
.into())
}

/// The renderer for pages in app directory
Expand Down
26 changes: 21 additions & 5 deletions crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use turbopack_core::{
changed::any_content_changed,
context::AssetContext,
ident::AssetIdentVc,
issue::IssueVc,
reference_type::{EntryReferenceSubType, ReferenceType},
resolve::{
find_context_file,
Expand Down Expand Up @@ -539,6 +540,25 @@ fn next_configs() -> StringsVc {

#[turbo_tasks::function]
pub async fn load_next_config(execution_context: ExecutionContextVc) -> Result<NextConfigVc> {
let ExecutionContext { project_path, .. } = *execution_context.await?;
let find_config_result = find_context_file(project_path, next_configs());
let config_file = match &*find_config_result.await? {
FindContextFileResult::Found(config_path, _) => Some(*config_path),
FindContextFileResult::NotFound(_) => None,
};
IssueVc::attach_context_or_description(
config_file,
"Loading Next.js config",
load_next_config_internal(execution_context, config_file),
)
.await
}

#[turbo_tasks::function]
pub async fn load_next_config_internal(
execution_context: ExecutionContextVc,
config_file: Option<FileSystemPathVc>,
) -> Result<NextConfigVc> {
let ExecutionContext {
project_path,
intermediate_output_path,
Expand All @@ -552,11 +572,7 @@ pub async fn load_next_config(execution_context: ExecutionContextVc) -> Result<N
import_map.insert_wildcard_alias("styled-jsx/", ImportMapping::External(None).into());

let context = node_evaluate_asset_context(project_path, Some(import_map.cell()), None);
let find_config_result = find_context_file(project_path, next_configs());
let config_asset = match &*find_config_result.await? {
FindContextFileResult::Found(config_path, _) => Some(SourceAssetVc::new(*config_path)),
FindContextFileResult::NotFound(_) => None,
};
let config_asset = config_file.map(SourceAssetVc::new);

let config_changed = config_asset.map_or_else(CompletionVc::immutable, |config_asset| {
// This invalidates the execution when anything referenced by the config file
Expand Down
54 changes: 39 additions & 15 deletions crates/next-core/src/page_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use turbopack_dev_server::{
source::{
asset_graph::AssetGraphContentSourceVc,
combined::{CombinedContentSource, CombinedContentSourceVc},
issue_context::IssueContextSourceVc,
specificity::SpecificityVc,
ContentSourceData, ContentSourceVc, NoContentSourceVc,
},
Expand Down Expand Up @@ -276,17 +277,33 @@ pub async fn create_page_source(
let fallback_source =
AssetGraphContentSourceVc::new_eager(server_root, fallback_page.as_asset());

Ok(CombinedContentSource {
let source = CombinedContentSource {
sources: vec![
// Match _next/404 first to ensure rewrites work properly.
force_not_found_source,
IssueContextSourceVc::new_context(
pages_dir,
"Next.js pages directory not found",
force_not_found_source,
)
.into(),
page_source,
fallback_source.into(),
fallback_not_found_source,
IssueContextSourceVc::new_context(
pages_dir,
"Next.js pages directory fallback",
fallback_source.into(),
)
.into(),
IssueContextSourceVc::new_context(
pages_dir,
"Next.js pages directory not found fallback",
fallback_not_found_source,
)
.into(),
],
}
.cell()
.into())
.into();
Ok(source)
}

/// Handles a single page file in the pages directory
Expand Down Expand Up @@ -554,13 +571,15 @@ async fn create_page_source_for_directory(
let mut sources = vec![];

for item in items.iter() {
match *item.await? {
let source = match *item.await? {
PagesStructureItem::Page {
page,
specificity,
url,
} => {
sources.push(create_page_source_for_file(
} => IssueContextSourceVc::new_context(
page,
"Next.js pages directory",
create_page_source_for_file(
project_path,
env,
server_context,
Expand All @@ -576,14 +595,17 @@ async fn create_page_source_for_directory(
false,
rebase(page, project_path, output_root),
output_root,
));
}
),
)
.into(),
PagesStructureItem::Api {
api,
specificity,
url,
} => {
sources.push(create_page_source_for_file(
} => IssueContextSourceVc::new_context(
api,
"Next.js pages api directory",
create_page_source_for_file(
project_path,
env,
server_context,
Expand All @@ -599,9 +621,11 @@ async fn create_page_source_for_directory(
true,
rebase(api, project_path, output_root),
output_root,
));
}
}
),
)
.into(),
};
sources.push(source);
}

for child in children.iter() {
Expand Down
27 changes: 27 additions & 0 deletions crates/next-core/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use turbopack_core::{
context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention::Middleware, ServerAddrVc},
ident::AssetIdentVc,
issue::IssueVc,
reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType},
resolve::{find_context_file, FindContextFileResult},
source_asset::SourceAssetVc,
Expand Down Expand Up @@ -306,6 +307,32 @@ pub async fn route(
next_config: NextConfigVc,
server_addr: ServerAddrVc,
routes_changed: CompletionVc,
) -> Result<RouterResultVc> {
let RouterRequest {
ref method,
ref pathname,
..
} = *request.await?;
IssueVc::attach_description(
format!("Next.js Routing for {} {}", method, pathname),
route_internal(
execution_context,
request,
next_config,
server_addr,
routes_changed,
),
)
.await
}

#[turbo_tasks::function]
async fn route_internal(
execution_context: ExecutionContextVc,
request: RouterRequestVc,
next_config: NextConfigVc,
server_addr: ServerAddrVc,
routes_changed: CompletionVc,
) -> Result<RouterResultVc> {
let ExecutionContext {
project_path,
Expand Down
4 changes: 2 additions & 2 deletions crates/next-dev-tests/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ impl IssueReporter for TestIssueReporter {
_source: TransientValue<RawVc>,
) -> Result<BoolVc> {
let issue_tx = self.issue_tx.get_untracked().clone();
for issue in captured_issues.iter() {
let plain = issue.into_plain();
for (issue, path) in captured_issues.iter_with_shortest_path() {
let plain = issue.into_plain(path);
issue_tx.send((plain.await?, plain.dbg().await?)).await?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ PlainIssue {
},
),
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
),
description: "Next.js pages directory",
},
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
),
description: "PostCSS processing",
},
],
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ PlainIssue {
},
),
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
),
description: "Next.js pages directory",
},
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
),
description: "PostCSS processing",
},
],
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ PlainIssue {
},
),
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
),
description: "Next.js pages directory",
},
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
),
description: "PostCSS processing",
},
],
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function f() {
if (process.env.NODE_ENV !== "development") {
throw new Error("NODE_ENV is not development");
}
console.log(process.env);
}

f();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ PlainIssue {
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: None,
description: "Next.js Routing for GET /_chunks/index_e7cdb3.js",
},
],
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ PlainIssue {
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[],
),
}
3 changes: 2 additions & 1 deletion crates/next-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
future::{join, Future},
io::{stdout, Write},
net::{IpAddr, SocketAddr},
path::MAIN_SEPARATOR,
path::{PathBuf, MAIN_SEPARATOR},
sync::Arc,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -206,6 +206,7 @@ impl NextDevServerBuilder {
let browserslist_query = self.browserslist_query;
let log_options = Arc::new(LogOptions {
current_dir: current_dir().unwrap(),
project_dir: PathBuf::from(project_dir.clone()),
show_all,
log_detail,
log_level: self.log_level,
Expand Down
Loading

0 comments on commit fb6e3ce

Please sign in to comment.