Skip to content

Commit

Permalink
refactor(turbopack-dev-server): Use ResolvedVc/NonLocalValue in Rewri…
Browse files Browse the repository at this point in the history
…teType, remove all "local" opt-outs from structs
  • Loading branch information
bgw committed Jan 11, 2025
1 parent 403c50b commit d0863f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
26 changes: 12 additions & 14 deletions turbopack/crates/turbopack-dev-server/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,33 +475,31 @@ impl ContentSource for NoContentSource {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)]
pub enum RewriteType {
Location {
/// The new path and query used to lookup content. This _does not_ need
/// to be the original path or query.
/// The new path and query used to lookup content. This _does not_ need to be the original
/// path or query.
path_and_query: RcStr,
},
ContentSource {
/// [Vc<Box<dyn ContentSource>>]s from which to restart the lookup
/// process. This _does not_ need to be the original content
/// source.
source: Vc<Box<dyn ContentSource>>,
/// [`ContentSource`]s from which to restart the lookup process. This _does not_ need to be
/// the original content source.
source: ResolvedVc<Box<dyn ContentSource>>,
/// The new path and query used to lookup content. This _does not_ need
/// to be the original path or query.
path_and_query: RcStr,
},
Sources {
/// [GetContentSourceContent]s from which to restart the lookup
/// process. This _does not_ need to be the original content
/// source.
sources: Vc<GetContentSourceContents>,
/// [`GetContentSourceContent`]s from which to restart the lookup process. This _does not_
/// need to be the original content source.
sources: ResolvedVc<GetContentSourceContents>,
},
}

/// A rewrite returned from a [ContentSource]. This tells the dev server to
/// update its parsed url, path, and queries with this new information.
#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Debug)]
pub struct Rewrite {
pub ty: RewriteType,
Expand Down Expand Up @@ -531,7 +529,7 @@ impl RewriteBuilder {
}

pub fn new_source_with_path_and_query(
source: Vc<Box<dyn ContentSource>>,
source: ResolvedVc<Box<dyn ContentSource>>,
path_and_query: RcStr,
) -> Self {
Self {
Expand All @@ -546,7 +544,7 @@ impl RewriteBuilder {
}
}

pub fn new_sources(sources: Vc<GetContentSourceContents>) -> Self {
pub fn new_sources(sources: ResolvedVc<GetContentSourceContents>) -> Self {
Self {
rewrite: Rewrite {
ty: RewriteType::Sources { sources },
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-dev-server/src/source/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
/// The result of [`resolve_source_request`]. Similar to a
/// `ContentSourceContent`, but without the `Rewrite` variant as this is taken
/// care in the function.
#[turbo_tasks::value(serialization = "none", local)]
#[turbo_tasks::value(serialization = "none")]
pub enum ResolveSourceRequestResult {
NotFound,
Static(ResolvedVc<StaticContent>, ResolvedVc<HeaderList>),
Expand Down Expand Up @@ -102,7 +102,7 @@ pub async fn resolve_source_request(
RewriteType::Sources {
sources: new_sources,
} => {
sources = *new_sources;
sources = **new_sources;
continue 'sources;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl GetContentSourceContent for WrappedGetContentSourceContent {
"Rewrites for WrappedGetContentSourceContent are not implemented yet"
),
RewriteType::Sources { sources } => RewriteType::Sources {
sources: Vc::cell(
sources: ResolvedVc::cell(
sources
.await?
.iter()
Expand Down

0 comments on commit d0863f9

Please sign in to comment.