Buckets:
| //! Type definitions for the Next.js manifest formats. | |
| pub mod client_reference_manifest; | |
| mod encode_uri_component; | |
| use anyhow::{Context, Result}; | |
| use bincode::{Decode, Encode}; | |
| use serde::{Deserialize, Serialize}; | |
| use turbo_rcstr::RcStr; | |
| use turbo_tasks::{ | |
| FxIndexMap, NonLocalValue, ReadRef, ResolvedVc, TaskInput, TryFlatJoinIterExt, TryJoinIterExt, | |
| Vc, trace::TraceRawVcs, | |
| }; | |
| use turbo_tasks_fs::{File, FileContent, FileSystemPath}; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| output::{OutputAsset, OutputAssets, OutputAssetsReference, OutputAssetsWithReferenced}, | |
| }; | |
| use crate::next_config::RouteHas; | |
| pub struct PagesManifest { | |
| pub pages: FxIndexMap<RcStr, RcStr>, | |
| } | |
| pub struct BuildManifest { | |
| pub output_path: FileSystemPath, | |
| pub client_relative_path: FileSystemPath, | |
| pub polyfill_files: Vec<ResolvedVc<Box<dyn OutputAsset>>>, | |
| pub root_main_files: Vec<ResolvedVc<Box<dyn OutputAsset>>>, | |
| pub pages: FxIndexMap<RcStr, ResolvedVc<OutputAssets>>, | |
| } | |
| impl OutputAssetsReference for BuildManifest { | |
| async fn references(&self) -> Result<Vc<OutputAssetsWithReferenced>> { | |
| let chunks: Vec<ReadRef<OutputAssets>> = self.pages.values().try_join().await?; | |
| let root_main_files = self | |
| .root_main_files | |
| .iter() | |
| .map(async |c| Ok(c.path().await?.has_extension(".js").then_some(*c))) | |
| .try_flat_join() | |
| .await?; | |
| let references = chunks | |
| .into_iter() | |
| .flatten() | |
| .copied() | |
| .chain(root_main_files) | |
| .chain(self.polyfill_files.iter().copied()) | |
| .collect(); | |
| Ok(OutputAssetsWithReferenced::from_assets(Vc::cell( | |
| references, | |
| ))) | |
| } | |
| } | |
| impl OutputAsset for BuildManifest { | |
| async fn path(&self) -> Vc<FileSystemPath> { | |
| self.output_path.clone().cell() | |
| } | |
| } | |
| impl Asset for BuildManifest { | |
| async fn content(&self) -> Result<Vc<AssetContent>> { | |
| let client_relative_path = &self.client_relative_path; | |
| pub struct SerializedBuildManifest { | |
| pub dev_files: Vec<RcStr>, | |
| pub amp_dev_files: Vec<RcStr>, | |
| pub polyfill_files: Vec<RcStr>, | |
| pub low_priority_files: Vec<RcStr>, | |
| pub root_main_files: Vec<RcStr>, | |
| pub pages: FxIndexMap<RcStr, Vec<RcStr>>, | |
| pub amp_first_pages: Vec<RcStr>, | |
| } | |
| let pages: Vec<(RcStr, Vec<RcStr>)> = self | |
| .pages | |
| .iter() | |
| .map(async |(k, chunks)| { | |
| Ok(( | |
| k.clone(), | |
| chunks | |
| .await? | |
| .iter() | |
| .copied() | |
| .map(async |chunk| { | |
| let chunk_path = chunk.path().await?; | |
| Ok(client_relative_path | |
| .get_path_to(&chunk_path) | |
| .context("client chunk entry path must be inside the client root")? | |
| .into()) | |
| }) | |
| .try_join() | |
| .await?, | |
| )) | |
| }) | |
| .try_join() | |
| .await?; | |
| let polyfill_files: Vec<RcStr> = self | |
| .polyfill_files | |
| .iter() | |
| .copied() | |
| .map(async |chunk| { | |
| let chunk_path = chunk.path().await?; | |
| Ok(client_relative_path | |
| .get_path_to(&chunk_path) | |
| .context("failed to resolve client-relative path to polyfill")? | |
| .into()) | |
| }) | |
| .try_join() | |
| .await?; | |
| let root_main_files: Vec<RcStr> = self | |
| .root_main_files | |
| .iter() | |
| .map(async |chunk| { | |
| let chunk_path = chunk.path().await?; | |
| if !chunk_path.has_extension(".js") { | |
| Ok(None) | |
| } else { | |
| Ok(Some( | |
| client_relative_path | |
| .get_path_to(&chunk_path) | |
| .context("failed to resolve client-relative path to root_main_file")? | |
| .into(), | |
| )) | |
| } | |
| }) | |
| .try_flat_join() | |
| .await?; | |
| let manifest = SerializedBuildManifest { | |
| pages: FxIndexMap::from_iter(pages), | |
| polyfill_files, | |
| root_main_files, | |
| ..Default::default() | |
| }; | |
| Ok(AssetContent::file( | |
| FileContent::Content(File::from(serde_json::to_string_pretty(&manifest)?)).cell(), | |
| )) | |
| } | |
| } | |
| pub struct ClientBuildManifest { | |
| pub output_path: FileSystemPath, | |
| pub client_relative_path: FileSystemPath, | |
| pub pages: FxIndexMap<RcStr, ResolvedVc<Box<dyn OutputAsset>>>, | |
| } | |
| impl OutputAssetsReference for ClientBuildManifest { | |
| async fn references(&self) -> Result<Vc<OutputAssetsWithReferenced>> { | |
| let chunks: Vec<ResolvedVc<Box<dyn OutputAsset>>> = self.pages.values().copied().collect(); | |
| Ok(OutputAssetsWithReferenced::from_assets(Vc::cell(chunks))) | |
| } | |
| } | |
| impl OutputAsset for ClientBuildManifest { | |
| async fn path(&self) -> Vc<FileSystemPath> { | |
| self.output_path.clone().cell() | |
| } | |
| } | |
| impl Asset for ClientBuildManifest { | |
| async fn content(&self) -> Result<Vc<AssetContent>> { | |
| let client_relative_path = &self.client_relative_path; | |
| let manifest: FxIndexMap<RcStr, Vec<RcStr>> = self | |
| .pages | |
| .iter() | |
| .map(async |(k, chunk)| { | |
| Ok(( | |
| k.clone(), | |
| vec![ | |
| client_relative_path | |
| .get_path_to(&*chunk.path().await?) | |
| .context("client chunk entry path must be inside the client root")? | |
| .into(), | |
| ], | |
| )) | |
| }) | |
| .try_join() | |
| .await? | |
| .into_iter() | |
| .collect(); | |
| Ok(AssetContent::file( | |
| FileContent::Content(File::from(serde_json::to_string_pretty(&manifest)?)).cell(), | |
| )) | |
| } | |
| } | |
| pub enum MiddlewaresManifest { | |
| MiddlewaresManifestV2(MiddlewaresManifestV2), | |
| Unsupported, | |
| } | |
| impl Default for MiddlewaresManifest { | |
| fn default() -> Self { | |
| Self::MiddlewaresManifestV2(Default::default()) | |
| } | |
| } | |
| pub struct ProxyMatcher { | |
| // When skipped, next.js will fill the field during merging. | |
| pub regexp: Option<RcStr>, | |
| pub locale: bool, | |
| pub has: Option<Vec<RouteHas>>, | |
| pub missing: Option<Vec<RouteHas>>, | |
| pub original_source: RcStr, | |
| } | |
| impl Default for ProxyMatcher { | |
| fn default() -> Self { | |
| Self { | |
| regexp: None, | |
| locale: true, | |
| has: None, | |
| missing: None, | |
| original_source: Default::default(), | |
| } | |
| } | |
| } | |
| fn bool_is_true(b: &bool) -> bool { | |
| *b | |
| } | |
| pub struct EdgeFunctionDefinition { | |
| pub files: Vec<RcStr>, | |
| pub name: RcStr, | |
| pub page: RcStr, | |
| pub entrypoint: RcStr, | |
| pub matchers: Vec<ProxyMatcher>, | |
| pub wasm: Vec<AssetBinding>, | |
| pub assets: Vec<AssetBinding>, | |
| pub regions: Option<Regions>, | |
| pub env: FxIndexMap<RcStr, RcStr>, | |
| } | |
| pub struct InstrumentationDefinition { | |
| pub files: Vec<RcStr>, | |
| pub name: RcStr, | |
| pub wasm: Vec<AssetBinding>, | |
| pub assets: Vec<AssetBinding>, | |
| } | |
| pub struct AssetBinding { | |
| pub name: RcStr, | |
| pub file_path: RcStr, | |
| } | |
| pub enum Regions { | |
| Multiple(Vec<RcStr>), | |
| Single(RcStr), | |
| } | |
| pub struct MiddlewaresManifestV2 { | |
| pub sorted_middleware: Vec<RcStr>, | |
| pub middleware: FxIndexMap<RcStr, EdgeFunctionDefinition>, | |
| pub instrumentation: Option<InstrumentationDefinition>, | |
| pub functions: FxIndexMap<RcStr, EdgeFunctionDefinition>, | |
| } | |
| pub struct ReactLoadableManifest { | |
| pub manifest: FxIndexMap<RcStr, ReactLoadableManifestEntry>, | |
| } | |
| pub struct ReactLoadableManifestEntry { | |
| pub id: u32, | |
| pub files: Vec<RcStr>, | |
| } | |
| pub struct NextFontManifest { | |
| pub pages: FxIndexMap<RcStr, Vec<RcStr>>, | |
| pub app: FxIndexMap<RcStr, Vec<RcStr>>, | |
| pub app_using_size_adjust: bool, | |
| pub pages_using_size_adjust: bool, | |
| } | |
| pub struct AppPathsManifest { | |
| pub edge_server_app_paths: PagesManifest, | |
| pub node_server_app_paths: PagesManifest, | |
| } | |
| // A struct represent a single entry in react-loadable-manifest.json. | |
| // The manifest is in a format of: | |
| // { [`${origin} -> ${imported}`]: { id: `${origin} -> ${imported}`, files: | |
| // string[] } } | |
| pub struct LoadableManifest { | |
| pub id: ModuleId, | |
| pub files: Vec<RcStr>, | |
| } | |
| pub struct ServerReferenceManifest<'a> { | |
| /// A map from hashed action name to the runtime module we that exports it. | |
| pub node: FxIndexMap<&'a str, ActionManifestEntry<'a>>, | |
| /// A map from hashed action name to the runtime module we that exports it. | |
| pub edge: FxIndexMap<&'a str, ActionManifestEntry<'a>>, | |
| } | |
| pub struct ActionManifestEntry<'a> { | |
| /// A mapping from the page that uses the server action to the runtime | |
| /// module that exports it. | |
| pub workers: FxIndexMap<&'a str, ActionManifestWorkerEntry<'a>>, | |
| pub exported_name: &'a str, | |
| pub filename: &'a str, | |
| /// Source location line number (1-indexed), if available | |
| pub line: Option<u32>, | |
| /// Source location column number (1-indexed), if available | |
| pub col: Option<u32>, | |
| } | |
| pub struct ActionManifestWorkerEntry<'a> { | |
| pub module_id: ActionManifestModuleId<'a>, | |
| pub is_async: bool, | |
| pub exported_name: &'a str, | |
| pub filename: &'a str, | |
| } | |
| pub enum ActionManifestModuleId<'a> { | |
| String(&'a str), | |
| Number(u64), | |
| } | |
| pub enum ActionLayer { | |
| Rsc, | |
| ActionBrowser, | |
| } | |
| pub enum ModuleId { | |
| String(RcStr), | |
| Number(u64), | |
| } | |
| pub struct FontManifest(pub Vec<FontManifestEntry>); | |
| pub struct FontManifestEntry { | |
| pub url: RcStr, | |
| pub content: RcStr, | |
| } | |
| mod tests { | |
| use turbo_rcstr::rcstr; | |
| use super::*; | |
| fn test_middleware_matcher_serialization() { | |
| let matchers = vec![ | |
| ProxyMatcher { | |
| regexp: None, | |
| locale: false, | |
| has: None, | |
| missing: None, | |
| original_source: rcstr!(""), | |
| }, | |
| ProxyMatcher { | |
| regexp: Some(rcstr!(".*")), | |
| locale: true, | |
| has: Some(vec![RouteHas::Query { | |
| key: rcstr!("foo"), | |
| value: None, | |
| }]), | |
| missing: Some(vec![RouteHas::Query { | |
| key: rcstr!("bar"), | |
| value: Some(rcstr!("value")), | |
| }]), | |
| original_source: rcstr!("source"), | |
| }, | |
| ]; | |
| let serialized = serde_json::to_string(&matchers).unwrap(); | |
| let deserialized: Vec<ProxyMatcher> = serde_json::from_str(&serialized).unwrap(); | |
| assert_eq!(matchers, deserialized); | |
| } | |
| } | |
Xet Storage Details
- Size:
- 14.2 kB
- Xet hash:
- 612b195345cbfa725509f7d026645c932f913e6304af9abb085340d58696e5cf
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.