Skip to content
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
44 changes: 15 additions & 29 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ console-subscriber = "0.4.1"
const_format = "0.2.30"
crc32fast = "1.5.0"
criterion = { package = "codspeed-criterion-compat", version = "4.3.0" }
ctor = "0.10"
ctor = "1.0.6"
crossbeam-channel = "0.5.8"
crossbeam-utils = "0.8"
dashmap = "6.1.0"
Expand Down
36 changes: 34 additions & 2 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use crate::{
font::FontManifest,
loadable_manifest::create_react_loadable_manifest,
module_graph::{ClientReferencesGraphs, NextDynamicGraphs, ServerActionsGraphs},
nft::{EndpointTraceResult, trace_endpoint},
nft_json::NftJsonAsset,
paths::{
all_asset_paths, all_paths_in_root, get_asset_paths_from_root, get_js_paths_from_root,
Expand Down Expand Up @@ -1789,8 +1790,7 @@ impl AppEndpoint {
.chain(loadable_manifest_output.iter().flat_map(|m| &**m).copied())
.map(|m| *m)
.collect(),
*module_graphs.full,
vec![*rsc_entry],
self.trace_result(),
)
.to_resolved()
.await?,
Expand Down Expand Up @@ -1978,6 +1978,33 @@ impl AppEndpoint {
}
})
}

#[turbo_tasks::function]
async fn trace_result(self: Vc<Self>) -> Result<Vc<EndpointTraceResult>> {
let this = self.await?;
let app_entry = self.app_endpoint_entry().await?;

let rsc_entry = app_entry.rsc_entry;

let is_app_page = matches!(this.ty, AppEndpointType::Page { .. });

let module_graphs = this
.app_project
.app_module_graphs(
self,
*rsc_entry,
// We only need the client runtime entries for pages not for Route Handlers
is_app_page.then(|| this.app_project.client_runtime_entries()),
)
.await?;

Ok(trace_endpoint(
this.app_project.project(),
Some(app_function_name(&app_entry.original_name).into()),
*module_graphs.full,
vec![*rsc_entry],
))
}
}

async fn create_app_paths_manifest(
Expand Down Expand Up @@ -2200,6 +2227,11 @@ impl Endpoint for AppEndpoint {
async fn project(self: Vc<Self>) -> Result<Vc<Project>> {
Ok(self.await?.app_project.project())
}

#[turbo_tasks::function]
fn traced_files(self: Vc<Self>) -> Vc<FileSystemPathVec> {
self.trace_result().all_files()
}
}

#[turbo_tasks::value]
Expand Down
6 changes: 6 additions & 0 deletions crates/next-api/src/empty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{Result, bail};
use next_core::app_structure::FileSystemPathVec;
use turbo_tasks::{Completion, ResolvedVc, Vc};
use turbopack_core::module_graph::GraphEntries;

Expand Down Expand Up @@ -51,4 +52,9 @@ impl Endpoint for EmptyEndpoint {
fn project(&self) -> Vc<Project> {
*self.project
}

#[turbo_tasks::function]
fn traced_files(self: Vc<Self>) -> Vc<FileSystemPathVec> {
Vc::cell(vec![])
}
}
33 changes: 22 additions & 11 deletions crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use next_core::{
app_structure::FileSystemPathVec,
next_edge::entry::wrap_edge_entry,
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
};
Expand All @@ -26,6 +27,7 @@ use turbopack_core::{
};

use crate::{
nft::{EndpointTraceResult, trace_endpoint},
nft_json::NftJsonAsset,
paths::{
all_asset_paths, get_js_paths_from_root, get_wasm_paths_from_root, wasm_paths_to_bindings,
Expand Down Expand Up @@ -185,23 +187,27 @@ impl InstrumentationEndpoint {
let chunk = self.node_chunk().to_resolved().await?;
let mut output_assets = vec![chunk];
if this.project.next_mode().await?.is_production() {
let userland_module = self.entry_module();
output_assets.push(ResolvedVc::upcast(
NftJsonAsset::new(
*this.project,
None,
*chunk,
vec![],
this.project.module_graph(userland_module),
vec![userland_module],
)
.to_resolved()
.await?,
NftJsonAsset::new(*this.project, None, *chunk, vec![], self.trace_result())
.to_resolved()
.await?,
));
}
Ok(Vc::cell(output_assets))
}
}

#[turbo_tasks::function]
async fn trace_result(self: Vc<Self>) -> Result<Vc<EndpointTraceResult>> {
let this = self.await?;
let userland_module = self.entry_module();
Ok(trace_endpoint(
*this.project,
None,
this.project.module_graph(userland_module),
vec![userland_module],
))
}
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -265,4 +271,9 @@ impl Endpoint for InstrumentationEndpoint {
fn project(&self) -> Vc<Project> {
*self.project
}

#[turbo_tasks::function]
fn traced_files(self: Vc<Self>) -> Vc<FileSystemPathVec> {
self.trace_result().all_files()
}
}
1 change: 1 addition & 0 deletions crates/next-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod loadable_manifest;
mod middleware;
mod module_graph;
pub mod next_server_nft;
mod nft;
mod nft_json;
pub mod operation;
mod pages;
Expand Down
33 changes: 22 additions & 11 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::future::IntoFuture;

use anyhow::{Context, Result};
use next_core::{
app_structure::FileSystemPathVec,
middleware::get_middleware_module,
next_edge::entry::wrap_edge_entry,
next_manifests::{EdgeFunctionDefinition, MiddlewaresManifestV2, ProxyMatcher, Regions},
Expand All @@ -28,6 +29,7 @@ use turbopack_core::{
};

use crate::{
nft::{EndpointTraceResult, trace_endpoint},
nft_json::NftJsonAsset,
paths::{
all_asset_paths, all_paths_in_root, get_asset_paths_from_root, get_js_paths_from_root,
Expand Down Expand Up @@ -227,18 +229,10 @@ impl MiddlewareEndpoint {
let chunk = self.node_chunk().to_resolved().await?;
let mut output_assets = vec![chunk];
if this.project.next_mode().await?.is_production() {
let userland_module = self.entry_module();
output_assets.push(ResolvedVc::upcast(
NftJsonAsset::new(
*this.project,
None,
*chunk,
vec![],
this.project.module_graph(userland_module),
vec![userland_module],
)
.to_resolved()
.await?,
NftJsonAsset::new(*this.project, None, *chunk, vec![], self.trace_result())
.to_resolved()
.await?,
));
}
let middleware_manifest_v2 = MiddlewaresManifestV2 {
Expand Down Expand Up @@ -344,6 +338,18 @@ impl MiddlewareEndpoint {
)
.module()
}

#[turbo_tasks::function]
async fn trace_result(self: Vc<Self>) -> Result<Vc<EndpointTraceResult>> {
let this = self.await?;
let userland_module = self.entry_module();
Ok(trace_endpoint(
*this.project,
None,
this.project.module_graph(userland_module),
vec![userland_module],
))
}
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -420,4 +426,9 @@ impl Endpoint for MiddlewareEndpoint {
fn project(&self) -> Vc<Project> {
*self.project
}

#[turbo_tasks::function]
fn traced_files(self: Vc<Self>) -> Vc<FileSystemPathVec> {
self.trace_result().all_files()
}
}
41 changes: 13 additions & 28 deletions crates/next-api/src/next_server_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use anyhow::{Context, Result, bail};
use bincode::{Decode, Encode};
use either::Either;
use next_core::{get_next_package, next_server::get_tracing_compile_time_info};
use serde_json::{Value, json};
use turbo_rcstr::RcStr;
use serde_json::json;
use turbo_tasks::{
NonLocalValue, ResolvedVc, TaskInput, TryFlatJoinIterExt, TryJoinIterExt, Vc,
trace::TraceRawVcs,
Expand All @@ -27,10 +26,7 @@ use turbopack_core::{
};
use turbopack_resolve::ecmascript::cjs_resolve;

use crate::{
nft_json::{relativize_glob, traced_modules_for_entries},
project::Project,
};
use crate::{nft::traced_modules_for_entries, project::Project};

#[derive(
PartialEq, Eq, TraceRawVcs, NonLocalValue, Debug, Clone, Hash, TaskInput, Encode, Decode,
Expand Down Expand Up @@ -304,30 +300,19 @@ impl ServerNftJsonAsset {
let output_file_tracing_excludes = self
.project
.next_config()
.output_file_tracing_excludes()
.output_file_tracing_excludes(project_path)
.await?;
let mut additional_ignores = BTreeSet::new();
if let Some(output_file_tracing_excludes) = output_file_tracing_excludes
.as_ref()
.and_then(Value::as_object)
{
for (glob_pattern, exclude_patterns) in output_file_tracing_excludes {
// Check if the route matches the glob pattern
let glob = Glob::new(RcStr::from(glob_pattern.clone()), Default::default()).await?;
if glob.matches("next-server")
&& let Some(patterns) = exclude_patterns.as_array()
{
for pattern in patterns {
if let Some(pattern_str) = pattern.as_str() {
let (glob, root) = relativize_glob(pattern_str, project_path.clone())?;
let glob = if root.path.is_empty() {
glob.to_string()
} else {
format!("{root}/{glob}")
};
additional_ignores.insert(glob);
}
}

for (route_glob, exclude_patterns) in output_file_tracing_excludes.iter() {
// Check if the route matches the glob pattern
if route_glob.await?.matches("next-server") {
for (glob, root) in exclude_patterns {
additional_ignores.insert(if root.path.is_empty() {
glob.to_string()
} else {
format!("{root}/{glob}")
});
}
}
}
Expand Down
Loading
Loading