Skip to content

Commit

Permalink
improve and enable issue path handling (vercel/turborepo#4017)
Browse files Browse the repository at this point in the history
### Description

adds the issue trace again, adds some basic descriptions e. g. to pages

### Testing Instructions

snapshot issues

[X] Auto label
  • Loading branch information
sokra authored Mar 7, 2023
1 parent ec77623 commit 0d75273
Show file tree
Hide file tree
Showing 39 changed files with 632 additions and 175 deletions.
43 changes: 28 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 Down Expand Up @@ -394,7 +395,9 @@ async fn create_app_source_for_directory(
intermediate_output_path_root: FileSystemPathVc,
) -> Result<ContentSourceVc> {
let AppStructure {
item, ref children, ..
item,
ref children,
directory,
} = *app_structure.await?;
let mut sources = Vec::new();

Expand Down Expand Up @@ -473,21 +476,31 @@ 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()
.as_content_source()
.issue_context(directory, "Next.js App Router");

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
23 changes: 18 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::IssueContextExt,
reference_type::{EntryReferenceSubType, ReferenceType},
resolve::{
find_context_file,
Expand Down Expand Up @@ -539,6 +540,22 @@ 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,
};
load_next_config_internal(execution_context, config_file)
.issue_context(config_file, "Loading Next.js config")
.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 +569,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
93 changes: 48 additions & 45 deletions crates/next-core/src/page_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,21 @@ 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,
force_not_found_source.issue_context(pages_dir, "Next.js pages directory not found"),
page_source,
fallback_source.into(),
fallback_not_found_source,
fallback_source
.as_content_source()
.issue_context(pages_dir, "Next.js pages directory fallback"),
fallback_not_found_source
.issue_context(pages_dir, "Next.js pages directory not found fallback"),
],
}
.cell()
.into())
.into();
Ok(source)
}

/// Handles a single page file in the pages directory
Expand Down Expand Up @@ -555,54 +559,53 @@ 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(
project_path,
env,
server_context,
server_data_context,
client_context,
pages_dir,
specificity,
SourceAssetVc::new(page).into(),
runtime_entries,
fallback_page,
server_root,
url,
false,
output_root,
output_root,
));
}
} => create_page_source_for_file(
project_path,
env,
server_context,
server_data_context,
client_context,
pages_dir,
specificity,
SourceAssetVc::new(page).into(),
runtime_entries,
fallback_page,
server_root,
url,
false,
output_root,
output_root,
)
.issue_context(page, "Next.js pages directory"),
PagesStructureItem::Api {
api,
specificity,
url,
} => {
sources.push(create_page_source_for_file(
project_path,
env,
server_context,
server_data_context,
client_context,
pages_dir,
specificity,
SourceAssetVc::new(api).into(),
runtime_entries,
fallback_page,
server_root,
url,
true,
output_root,
output_root,
));
}
}
} => create_page_source_for_file(
project_path,
env,
server_context,
server_data_context,
client_context,
pages_dir,
specificity,
SourceAssetVc::new(api).into(),
runtime_entries,
fallback_page,
server_root,
url,
true,
output_root,
output_root,
)
.issue_context(api, "Next.js pages api directory"),
};
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 @@ -316,6 +317,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 @@ -8,4 +8,14 @@ PlainIssue {
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/pages/index.js",
),
description: "Next.js pages directory",
},
],
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ PlainIssue {
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/pages/index.js",
),
description: "Next.js pages directory",
},
],
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ PlainIssue {
documentation_link: "",
source: None,
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/webpack-loaders/emitted-errors/input/pages/index.js",
),
description: "Next.js pages directory",
},
],
),
}
Loading

0 comments on commit 0d75273

Please sign in to comment.