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::{
module_graph::{ClientReferencesGraphs, NextDynamicGraphs, ServerActionsGraphs},
nft_json::NftJsonAsset,
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,
},
project::{BaseAndFullModuleGraph, Project},
......@@ -2019,7 +2019,7 @@ impl Endpoint for AppEndpoint {
.is_development()
{
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
.app_project
......
......@@ -28,7 +28,7 @@ use turbopack_core::{
use crate::{
nft_json::NftJsonAsset,
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,
route::{Endpoint, EndpointOutput, EndpointOutputPaths, ModuleGraphs},
......@@ -210,7 +210,7 @@ impl Endpoint for InstrumentationEndpoint {
let server_paths = if this.project.next_mode().await?.is_development() {
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 {
vec![]
};
......
......@@ -30,7 +30,7 @@ use turbopack_core::{
use crate::{
nft_json::NftJsonAsset,
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,
},
project::Project,
......@@ -337,7 +337,7 @@ impl Endpoint for MiddlewareEndpoint {
let (server_paths, client_paths) = if this.project.next_mode().await?.is_development() {
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`).
let client_relative_root = this.project.client_relative_path().owned().await?;
......
......@@ -75,7 +75,7 @@ use crate::{
module_graph::{NextDynamicGraphs, validate_pages_css_imports},
nft_json::NftJsonAsset,
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,
},
project::Project,
......@@ -1613,7 +1613,7 @@ impl Endpoint for PageEndpoint {
.await?
.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()
.await?;
......
......@@ -11,31 +11,31 @@ use turbopack_core::{
};
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]
#[derive(Debug, Clone)]
pub struct ServerPath {
pub struct AssetPath {
/// Relative to the root_path
pub path: RcStr,
pub content_hash: u64,
}
/// A list of server paths
/// A list of asset paths
#[turbo_tasks::value(transparent)]
pub struct ServerPaths(Vec<ServerPath>);
pub struct AssetPaths(Vec<AssetPath>);
#[turbo_tasks::value(transparent)]
pub struct OptionServerPath(Option<ServerPath>);
pub struct OptionAssetPath(Option<AssetPath>);
#[turbo_tasks::function]
async fn server_path(
async fn asset_path(
asset: Vc<Box<dyn OutputAsset>>,
node_root: FileSystemPath,
) -> Result<Vc<OptionServerPath>> {
) -> Result<Vc<OptionAssetPath>> {
Ok(Vc::cell(
if let Some(path) = node_root.get_path_to(&*asset.path().await?) {
let content_hash = *asset.content().hash().await?;
Some(ServerPath {
Some(AssetPath {
path: RcStr::from(path),
content_hash,
})
......@@ -45,30 +45,29 @@ async fn server_path(
))
}
/// 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 `node_root`.
/// Return a list of all asset paths with filename and hash for all output
/// assets references from the `assets` list. Only paths inside `node_root` are included.
#[turbo_tasks::function]
pub async fn all_server_paths(
pub async fn all_asset_paths(
assets: Vc<OutputAssets>,
node_root: FileSystemPath,
) -> Result<Vc<ServerPaths>> {
) -> Result<Vc<AssetPaths>> {
let span = tracing::info_span!(
"collect all server paths",
"collect all asset paths",
assets_count = tracing::field::Empty,
server_assets_count = tracing::field::Empty
asset_paths_count = tracing::field::Empty
);
let span_clone = span.clone();
async move {
let all_assets = all_assets_from_entries(assets).await?;
span.record("assets_count", all_assets.len());
let server_paths = all_assets
let asset_paths = all_assets
.iter()
.map(|&asset| server_path(*asset, node_root.clone()).owned())
.map(|&asset| asset_path(*asset, node_root.clone()).owned())
.try_flat_join()
.await?;
span.record("server_assets_count", server_paths.len());
Ok(Vc::cell(server_paths))
span.record("asset_paths_count", asset_paths.len());
Ok(Vc::cell(asset_paths))
}
.instrument(span_clone)
.await
......
......@@ -12,7 +12,7 @@ use turbopack_core::{
output::OutputAssets,
};
use crate::{operation::OptionEndpoint, paths::ServerPath, project::Project};
use crate::{operation::OptionEndpoint, paths::AssetPath, project::Project};
#[derive(
TraceRawVcs, PartialEq, Eq, ValueDebugFormat, Clone, Debug, NonLocalValue, Encode, Decode,
......@@ -267,11 +267,11 @@ pub enum EndpointOutputPaths {
NodeJs {
/// Relative to the root_path
server_entry_path: RcStr,
server_paths: Vec<ServerPath>,
server_paths: Vec<AssetPath>,
client_paths: Vec<RcStr>,
},
Edge {
server_paths: Vec<ServerPath>,
server_paths: Vec<AssetPath>,
client_paths: Vec<RcStr>,
},
NotFound,
......
......@@ -6,7 +6,7 @@ use napi::{JsFunction, bindgen_prelude::External};
use napi_derive::napi;
use next_api::{
operation::OptionEndpoint,
paths::ServerPath,
paths::AssetPath,
route::{
Endpoint, EndpointOutputPaths, endpoint_client_changed_operation,
endpoint_server_changed_operation, endpoint_write_to_disk_operation,
......@@ -30,16 +30,16 @@ pub struct NapiEndpointConfig {}
#[napi(object)]
#[derive(Default)]
pub struct NapiServerPath {
pub struct NapiAssetPath {
pub path: String,
pub content_hash: String,
}
impl From<ServerPath> for NapiServerPath {
fn from(server_path: ServerPath) -> Self {
impl From<AssetPath> for NapiAssetPath {
fn from(asset_path: AssetPath) -> Self {
Self {
path: server_path.path.into_owned(),
content_hash: format!("{:x}", server_path.content_hash),
path: asset_path.path.into_owned(),
content_hash: format!("{:x}", asset_path.content_hash),
}
}
}
......@@ -50,7 +50,7 @@ pub struct NapiWrittenEndpoint {
pub r#type: String,
pub entry_path: Option<String>,
pub client_paths: Vec<String>,
pub server_paths: Vec<NapiServerPath>,
pub server_paths: Vec<NapiAssetPath>,
pub config: NapiEndpointConfig,
}
......
......@@ -67,7 +67,7 @@ export declare function minify(
): Promise<TransformOutput>
export declare function minifySync(input: Buffer, opts: Buffer): TransformOutput
export interface NapiEndpointConfig {}
export interface NapiServerPath {
export interface NapiAssetPath {
path: string
contentHash: string
}
......@@ -75,7 +75,7 @@ export interface NapiWrittenEndpoint {
type: string
entryPath?: string
clientPaths: Array<string>
serverPaths: Array<NapiServerPath>
serverPaths: Array<NapiAssetPath>
config: NapiEndpointConfig
}
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