-
Notifications
You must be signed in to change notification settings - Fork 26k
/
server_paths.rs
57 lines (54 loc) · 1.89 KB
/
server_paths.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use anyhow::Result;
use next_core::all_assets_from_entries;
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, TryFlatJoinIterExt, Vc};
use turbopack_binding::{
turbo::tasks_fs::FileSystemPath,
turbopack::core::{
asset::{Asset, AssetContent},
output::{OutputAsset, OutputAssets},
},
};
/// A reference to a server file with content hash for change detection
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, TraceRawVcs)]
pub struct ServerPath {
/// Relative to the root_path
pub path: String,
pub content_hash: u64,
}
/// A list of server paths
#[turbo_tasks::value(transparent)]
pub struct ServerPaths(Vec<ServerPath>);
/// Return a list of all server paths with filename and hash for all output
/// assets references from the `assets` list. Server paths are identified by
/// being inside of `node_root`.
#[turbo_tasks::function]
pub async fn all_server_paths(
assets: Vc<OutputAssets>,
node_root: Vc<FileSystemPath>,
) -> Result<Vc<ServerPaths>> {
let all_assets = all_assets_from_entries(assets).await?;
let node_root = &node_root.await?;
Ok(Vc::cell(
all_assets
.iter()
.map(|&asset| async move {
Ok(
if let Some(path) = node_root.get_path_to(&*asset.ident().path().await?) {
let content_hash = match *asset.content().await? {
AssetContent::File(file) => *file.hash().await?,
AssetContent::Redirect { .. } => 0,
};
Some(ServerPath {
path: path.to_string(),
content_hash,
})
} else {
None
},
)
})
.try_flat_join()
.await?,
))
}