Skip to content

Commit d1d8b65

Browse files
authored
refactor(turbopack/next-core): Migrate app_page_loader_tree structs to ResolvedVc (vercel#74114)
A pretty easy/straightforward migration.
1 parent 5ff2100 commit d1d8b65

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

crates/next-core/src/app_page_loader_tree.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,14 @@ impl AppPageLoaderTreeBuilder {
169169
) -> Result<()> {
170170
match item {
171171
MetadataWithAltItem::Static { path, alt_path } => {
172-
self.write_static_metadata_item(app_page, name, item, *path, *alt_path)
173-
.await?;
172+
self.write_static_metadata_item(
173+
app_page,
174+
name,
175+
item,
176+
**path,
177+
alt_path.as_deref().copied(),
178+
)
179+
.await?;
174180
}
175181
MetadataWithAltItem::Dynamic { path, .. } => {
176182
let i = self.base.unique_number();
@@ -183,7 +189,7 @@ impl AppPageLoaderTreeBuilder {
183189

184190
let source = dynamic_image_metadata_source(
185191
Vc::upcast(self.base.module_asset_context),
186-
*path,
192+
**path,
187193
name.into(),
188194
app_page.clone(),
189195
);

crates/next-core/src/app_structure.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize};
77
use tracing::Instrument;
88
use turbo_rcstr::RcStr;
99
use turbo_tasks::{
10-
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs, FxIndexMap, ResolvedVc, TaskInput,
11-
TryJoinIterExt, ValueDefault, ValueToString, Vc,
10+
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs, FxIndexMap, NonLocalValue, ResolvedVc,
11+
TaskInput, TryJoinIterExt, ValueDefault, ValueToString, Vc,
1212
};
1313
use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath};
1414
use turbopack_core::issue::{
@@ -27,7 +27,7 @@ use crate::{
2727
};
2828

2929
/// A final route in the app directory.
30-
#[turbo_tasks::value(local)]
30+
#[turbo_tasks::value]
3131
#[derive(Default, Debug, Clone)]
3232
pub struct AppDirModules {
3333
#[serde(skip_serializing_if = "Option::is_none")]
@@ -76,24 +76,34 @@ impl AppDirModules {
7676
}
7777

7878
/// A single metadata file plus an optional "alt" text file.
79-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, TraceRawVcs)]
79+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, TraceRawVcs, NonLocalValue)]
8080
pub enum MetadataWithAltItem {
8181
Static {
82-
path: Vc<FileSystemPath>,
83-
alt_path: Option<Vc<FileSystemPath>>,
82+
path: ResolvedVc<FileSystemPath>,
83+
alt_path: Option<ResolvedVc<FileSystemPath>>,
8484
},
8585
Dynamic {
86-
path: Vc<FileSystemPath>,
86+
path: ResolvedVc<FileSystemPath>,
8787
},
8888
}
8989

9090
/// A single metadata file.
9191
#[derive(
92-
Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, TaskInput, TraceRawVcs,
92+
Copy,
93+
Clone,
94+
Debug,
95+
Hash,
96+
Serialize,
97+
Deserialize,
98+
PartialEq,
99+
Eq,
100+
TaskInput,
101+
TraceRawVcs,
102+
NonLocalValue,
93103
)]
94104
pub enum MetadataItem {
95-
Static { path: Vc<FileSystemPath> },
96-
Dynamic { path: Vc<FileSystemPath> },
105+
Static { path: ResolvedVc<FileSystemPath> },
106+
Dynamic { path: ResolvedVc<FileSystemPath> },
97107
}
98108

99109
#[turbo_tasks::function]
@@ -120,7 +130,7 @@ pub async fn get_metadata_route_name(meta: MetadataItem) -> Result<Vc<RcStr>> {
120130
}
121131

122132
impl MetadataItem {
123-
pub fn into_path(self) -> Vc<FileSystemPath> {
133+
pub fn into_path(self) -> ResolvedVc<FileSystemPath> {
124134
match self {
125135
MetadataItem::Static { path } => path,
126136
MetadataItem::Dynamic { path } => path,
@@ -138,7 +148,9 @@ impl From<MetadataWithAltItem> for MetadataItem {
138148
}
139149

140150
/// Metadata file that can be placed in any segment of the app directory.
141-
#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, TraceRawVcs)]
151+
#[derive(
152+
Default, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, TraceRawVcs, NonLocalValue,
153+
)]
142154
pub struct Metadata {
143155
#[serde(skip_serializing_if = "Vec::is_empty", default)]
144156
pub icon: Vec<MetadataWithAltItem>,
@@ -338,17 +350,17 @@ async fn get_directory_tree_internal(
338350
"opengraph-image" => &mut metadata_open_graph,
339351
"sitemap" => {
340352
if dynamic {
341-
modules.metadata.sitemap = Some(MetadataItem::Dynamic { path: *file });
353+
modules.metadata.sitemap = Some(MetadataItem::Dynamic { path: file });
342354
} else {
343-
modules.metadata.sitemap = Some(MetadataItem::Static { path: *file });
355+
modules.metadata.sitemap = Some(MetadataItem::Static { path: file });
344356
}
345357
continue;
346358
}
347359
_ => continue,
348360
};
349361

350362
if dynamic {
351-
entry.push((number, MetadataWithAltItem::Dynamic { path: *file }));
363+
entry.push((number, MetadataWithAltItem::Dynamic { path: file }));
352364
continue;
353365
}
354366

@@ -357,14 +369,18 @@ async fn get_directory_tree_internal(
357369
let basename = file_name
358370
.rsplit_once('.')
359371
.map_or(file_name, |(basename, _)| basename);
360-
let alt_path = file.parent().join(format!("{}.alt.txt", basename).into());
372+
let alt_path = file
373+
.parent()
374+
.join(format!("{}.alt.txt", basename).into())
375+
.to_resolved()
376+
.await?;
361377
let alt_path = matches!(&*alt_path.get_type().await?, FileSystemEntryType::File)
362378
.then_some(alt_path);
363379

364380
entry.push((
365381
number,
366382
MetadataWithAltItem::Static {
367-
path: *file,
383+
path: file,
368384
alt_path,
369385
},
370386
));
@@ -1401,9 +1417,9 @@ pub async fn get_global_metadata(
14011417
};
14021418

14031419
if dynamic {
1404-
*entry = Some(MetadataItem::Dynamic { path: *file });
1420+
*entry = Some(MetadataItem::Dynamic { path: file });
14051421
} else {
1406-
*entry = Some(MetadataItem::Static { path: *file });
1422+
*entry = Some(MetadataItem::Static { path: file });
14071423
}
14081424
// TODO(WEB-952) handle symlinks in app dir
14091425
}

crates/next-core/src/next_app/metadata/route.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ pub async fn get_app_metadata_route_source(
3232
is_multi_dynamic: bool,
3333
) -> Result<Vc<Box<dyn Source>>> {
3434
Ok(match metadata {
35-
MetadataItem::Static { path } => static_route_source(mode, path),
35+
MetadataItem::Static { path } => static_route_source(mode, *path),
3636
MetadataItem::Dynamic { path } => {
3737
let stem = path.file_stem().await?;
3838
let stem = stem.as_deref().unwrap_or_default();
3939

4040
if stem == "robots" || stem == "manifest" {
41-
dynamic_text_route_source(path)
41+
dynamic_text_route_source(*path)
4242
} else if stem == "sitemap" {
43-
dynamic_site_map_route_source(mode, path, is_multi_dynamic)
43+
dynamic_site_map_route_source(mode, *path, is_multi_dynamic)
4444
} else {
45-
dynamic_image_route_source(path)
45+
dynamic_image_route_source(*path)
4646
}
4747
}
4848
})
@@ -60,11 +60,9 @@ pub async fn get_app_metadata_route_entry(
6060
) -> Vc<AppEntry> {
6161
// Read original source's segment config before replacing source into
6262
// dynamic|static metadata route handler.
63-
let original_path = match metadata {
64-
MetadataItem::Static { path } | MetadataItem::Dynamic { path } => path,
65-
};
63+
let original_path = metadata.into_path();
6664

67-
let source = Vc::upcast(FileSource::new(original_path));
65+
let source = Vc::upcast(FileSource::new(*original_path));
6866
let segment_config = parse_segment_config_from_source(source);
6967
let is_dynamic_metadata = matches!(metadata, MetadataItem::Dynamic { .. });
7068
let is_multi_dynamic: bool = if Some(segment_config).is_some() {

0 commit comments

Comments
 (0)