Unverified Commit 75df0bb4 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: rename ServerPaths to AssetPaths (#90234)

We are soon going to use these for client-side static assets as well
parent 8f231d63
...@@ -80,7 +80,7 @@ use crate::{ ...@@ -80,7 +80,7 @@ use crate::{
module_graph::{ClientReferencesGraphs, NextDynamicGraphs, ServerActionsGraphs}, module_graph::{ClientReferencesGraphs, NextDynamicGraphs, ServerActionsGraphs},
nft_json::NftJsonAsset, nft_json::NftJsonAsset,
paths::{ paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root, all_asset_paths, all_paths_in_root, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings, get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
}, },
project::{BaseAndFullModuleGraph, Project}, project::{BaseAndFullModuleGraph, Project},
...@@ -2019,7 +2019,7 @@ impl Endpoint for AppEndpoint { ...@@ -2019,7 +2019,7 @@ impl Endpoint for AppEndpoint {
.is_development() .is_development()
{ {
let node_root = this.app_project.project().node_root().owned().await?; let node_root = this.app_project.project().node_root().owned().await?;
let server_paths = all_server_paths(output_assets, node_root).owned().await?; let server_paths = all_asset_paths(output_assets, node_root).owned().await?;
let client_relative_root = this let client_relative_root = this
.app_project .app_project
......
...@@ -28,7 +28,7 @@ use turbopack_core::{ ...@@ -28,7 +28,7 @@ use turbopack_core::{
use crate::{ use crate::{
nft_json::NftJsonAsset, nft_json::NftJsonAsset,
paths::{ paths::{
all_server_paths, get_js_paths_from_root, get_wasm_paths_from_root, wasm_paths_to_bindings, all_asset_paths, get_js_paths_from_root, get_wasm_paths_from_root, wasm_paths_to_bindings,
}, },
project::Project, project::Project,
route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs}, route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs},
...@@ -210,7 +210,7 @@ impl Endpoint for InstrumentationEndpoint { ...@@ -210,7 +210,7 @@ impl Endpoint for InstrumentationEndpoint {
let server_paths = if this.project.next_mode().await?.is_development() { let server_paths = if this.project.next_mode().await?.is_development() {
let node_root = this.project.node_root().owned().await?; let node_root = this.project.node_root().owned().await?;
all_server_paths(output_assets, node_root).owned().await? all_asset_paths(output_assets, node_root).owned().await?
} else { } else {
vec![] vec![]
}; };
......
...@@ -30,7 +30,7 @@ use turbopack_core::{ ...@@ -30,7 +30,7 @@ use turbopack_core::{
use crate::{ use crate::{
nft_json::NftJsonAsset, nft_json::NftJsonAsset,
paths::{ paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root, all_asset_paths, all_paths_in_root, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings, get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
}, },
project::Project, project::Project,
...@@ -337,7 +337,7 @@ impl Endpoint for MiddlewareEndpoint { ...@@ -337,7 +337,7 @@ impl Endpoint for MiddlewareEndpoint {
let (server_paths, client_paths) = if this.project.next_mode().await?.is_development() { let (server_paths, client_paths) = if this.project.next_mode().await?.is_development() {
let node_root = this.project.node_root().owned().await?; let node_root = this.project.node_root().owned().await?;
let server_paths = all_server_paths(output_assets, node_root).owned().await?; let server_paths = all_asset_paths(output_assets, node_root).owned().await?;
// Middleware could in theory have a client path (e.g. `new URL`). // Middleware could in theory have a client path (e.g. `new URL`).
let client_relative_root = this.project.client_relative_path().owned().await?; let client_relative_root = this.project.client_relative_path().owned().await?;
......
...@@ -75,7 +75,7 @@ use crate::{ ...@@ -75,7 +75,7 @@ use crate::{
module_graph::{NextDynamicGraphs, validate_pages_css_imports}, module_graph::{NextDynamicGraphs, validate_pages_css_imports},
nft_json::NftJsonAsset, nft_json::NftJsonAsset,
paths::{ paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root, all_asset_paths, all_paths_in_root, get_asset_paths_from_root, get_js_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings, get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
}, },
project::Project, project::Project,
...@@ -1613,7 +1613,7 @@ impl Endpoint for PageEndpoint { ...@@ -1613,7 +1613,7 @@ impl Endpoint for PageEndpoint {
.await? .await?
.is_development() .is_development()
{ {
let server_paths = all_server_paths(output_assets, node_root.clone()) let server_paths = all_asset_paths(output_assets, node_root.clone())
.owned() .owned()
.await?; .await?;
......
...@@ -11,31 +11,31 @@ use turbopack_core::{ ...@@ -11,31 +11,31 @@ use turbopack_core::{
}; };
use turbopack_wasm::wasm_edge_var_name; use turbopack_wasm::wasm_edge_var_name;
/// A reference to a server file with content hash for change detection /// A reference to an output asset with content hash for change detection
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ServerPath { pub struct AssetPath {
/// Relative to the root_path /// Relative to the root_path
pub path: RcStr, pub path: RcStr,
pub content_hash: u64, pub content_hash: u64,
} }
/// A list of server paths /// A list of asset paths
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct ServerPaths(Vec<ServerPath>); pub struct AssetPaths(Vec<AssetPath>);
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct OptionServerPath(Option<ServerPath>); pub struct OptionAssetPath(Option<AssetPath>);
#[turbo_tasks::function] #[turbo_tasks::function]
async fn server_path( async fn asset_path(
asset: Vc<Box<dyn OutputAsset>>, asset: Vc<Box<dyn OutputAsset>>,
node_root: FileSystemPath, node_root: FileSystemPath,
) -> Result<Vc<OptionServerPath>> { ) -> Result<Vc<OptionAssetPath>> {
Ok(Vc::cell( Ok(Vc::cell(
if let Some(path) = node_root.get_path_to(&*asset.path().await?) { if let Some(path) = node_root.get_path_to(&*asset.path().await?) {
let content_hash = *asset.content().hash().await?; let content_hash = *asset.content().hash().await?;
Some(ServerPath { Some(AssetPath {
path: RcStr::from(path), path: RcStr::from(path),
content_hash, content_hash,
}) })
...@@ -45,30 +45,29 @@ async fn server_path( ...@@ -45,30 +45,29 @@ async fn server_path(
)) ))
} }
/// Return a list of all server paths with filename and hash for all output /// Return a list of all asset paths with filename and hash for all output
/// assets references from the `assets` list. Server paths are identified by /// assets references from the `assets` list. Only paths inside `node_root` are included.
/// being inside `node_root`.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn all_server_paths( pub async fn all_asset_paths(
assets: Vc<OutputAssets>, assets: Vc<OutputAssets>,
node_root: FileSystemPath, node_root: FileSystemPath,
) -> Result<Vc<ServerPaths>> { ) -> Result<Vc<AssetPaths>> {
let span = tracing::info_span!( let span = tracing::info_span!(
"collect all server paths", "collect all asset paths",
assets_count = tracing::field::Empty, assets_count = tracing::field::Empty,
server_assets_count = tracing::field::Empty asset_paths_count = tracing::field::Empty
); );
let span_clone = span.clone(); let span_clone = span.clone();
async move { async move {
let all_assets = all_assets_from_entries(assets).await?; let all_assets = all_assets_from_entries(assets).await?;
span.record("assets_count", all_assets.len()); span.record("assets_count", all_assets.len());
let server_paths = all_assets let asset_paths = all_assets
.iter() .iter()
.map(|&asset| server_path(*asset, node_root.clone()).owned()) .map(|&asset| asset_path(*asset, node_root.clone()).owned())
.try_flat_join() .try_flat_join()
.await?; .await?;
span.record("server_assets_count", server_paths.len()); span.record("asset_paths_count", asset_paths.len());
Ok(Vc::cell(server_paths)) Ok(Vc::cell(asset_paths))
} }
.instrument(span_clone) .instrument(span_clone)
.await .await
......
...@@ -12,7 +12,7 @@ use turbopack_core::{ ...@@ -12,7 +12,7 @@ use turbopack_core::{
output::OutputAssets, output::OutputAssets,
}; };
use crate::{operation::OptionEndpoint, paths::ServerPath, project::Project}; use crate::{operation::OptionEndpoint, paths::AssetPath, project::Project};
#[derive( #[derive(
TraceRawVcs, PartialEq, Eq, ValueDebugFormat, Clone, Debug, NonLocalValue, Encode, Decode, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, Clone, Debug, NonLocalValue, Encode, Decode,
...@@ -267,11 +267,11 @@ pub enum EndpointOutputPaths { ...@@ -267,11 +267,11 @@ pub enum EndpointOutputPaths {
NodeJs { NodeJs {
/// Relative to the root_path /// Relative to the root_path
server_entry_path: RcStr, server_entry_path: RcStr,
server_paths: Vec<ServerPath>, server_paths: Vec<AssetPath>,
client_paths: Vec<RcStr>, client_paths: Vec<RcStr>,
}, },
Edge { Edge {
server_paths: Vec<ServerPath>, server_paths: Vec<AssetPath>,
client_paths: Vec<RcStr>, client_paths: Vec<RcStr>,
}, },
NotFound, NotFound,
......
...@@ -6,7 +6,7 @@ use napi::{JsFunction, bindgen_prelude::External}; ...@@ -6,7 +6,7 @@ use napi::{JsFunction, bindgen_prelude::External};
use napi_derive::napi; use napi_derive::napi;
use next_api::{ use next_api::{
operation::OptionEndpoint, operation::OptionEndpoint,
paths::ServerPath, paths::AssetPath,
route::{ route::{
Endpoint, EndpointOutputPaths, endpoint_client_changed_operation, Endpoint, EndpointOutputPaths, endpoint_client_changed_operation,
endpoint_server_changed_operation, endpoint_write_to_disk_operation, endpoint_server_changed_operation, endpoint_write_to_disk_operation,
...@@ -30,16 +30,16 @@ pub struct NapiEndpointConfig {} ...@@ -30,16 +30,16 @@ pub struct NapiEndpointConfig {}
#[napi(object)] #[napi(object)]
#[derive(Default)] #[derive(Default)]
pub struct NapiServerPath { pub struct NapiAssetPath {
pub path: String, pub path: String,
pub content_hash: String, pub content_hash: String,
} }
impl From<ServerPath> for NapiServerPath { impl From<AssetPath> for NapiAssetPath {
fn from(server_path: ServerPath) -> Self { fn from(asset_path: AssetPath) -> Self {
Self { Self {
path: server_path.path.into_owned(), path: asset_path.path.into_owned(),
content_hash: format!("{:x}", server_path.content_hash), content_hash: format!("{:x}", asset_path.content_hash),
} }
} }
} }
...@@ -50,7 +50,7 @@ pub struct NapiWrittenEndpoint { ...@@ -50,7 +50,7 @@ pub struct NapiWrittenEndpoint {
pub r#type: String, pub r#type: String,
pub entry_path: Option<String>, pub entry_path: Option<String>,
pub client_paths: Vec<String>, pub client_paths: Vec<String>,
pub server_paths: Vec<NapiServerPath>, pub server_paths: Vec<NapiAssetPath>,
pub config: NapiEndpointConfig, pub config: NapiEndpointConfig,
} }
......
...@@ -67,7 +67,7 @@ export declare function minify( ...@@ -67,7 +67,7 @@ export declare function minify(
): Promise<TransformOutput> ): Promise<TransformOutput>
export declare function minifySync(input: Buffer, opts: Buffer): TransformOutput export declare function minifySync(input: Buffer, opts: Buffer): TransformOutput
export interface NapiEndpointConfig {} export interface NapiEndpointConfig {}
export interface NapiServerPath { export interface NapiAssetPath {
path: string path: string
contentHash: string contentHash: string
} }
...@@ -75,7 +75,7 @@ export interface NapiWrittenEndpoint { ...@@ -75,7 +75,7 @@ export interface NapiWrittenEndpoint {
type: string type: string
entryPath?: string entryPath?: string
clientPaths: Array<string> clientPaths: Array<string>
serverPaths: Array<NapiServerPath> serverPaths: Array<NapiAssetPath>
config: NapiEndpointConfig config: NapiEndpointConfig
} }
export declare function endpointWriteToDisk(endpoint: { export declare function endpointWriteToDisk(endpoint: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment