Skip to content

Commit

Permalink
port turbopack-node to ResolvedVc (#73082)
Browse files Browse the repository at this point in the history
Does what it says on the tin.

One struct seems to be trivially used in a trait which requires it to be a Vc so I left it with a comment. @bgw perhaps we can set up some lint + disabling comment for all the cases in this doc?

Would be handy to ensure we are continuing to follow the heuristic in the future also.
  • Loading branch information
arlyon authored and wyattjoh committed Nov 28, 2024
1 parent 8a41d90 commit 2322dc6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
8 changes: 4 additions & 4 deletions turbopack/crates/turbopack-node/src/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub trait EvaluateContext {
fn keep_alive(&self) -> bool {
false
}
fn args(&self) -> &[Vc<JsonValue>];
fn args(&self) -> &[ResolvedVc<JsonValue>];
fn cwd(&self) -> Vc<FileSystemPath>;
async fn emit_error(&self, error: StructuredError, pool: &NodeJsPool) -> Result<()>;
async fn info(
Expand Down Expand Up @@ -370,7 +370,7 @@ pub fn evaluate(
asset_context: ResolvedVc<Box<dyn AssetContext>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
args: Vec<Vc<JsonValue>>,
args: Vec<ResolvedVc<JsonValue>>,
additional_invalidation: ResolvedVc<Completion>,
debug: bool,
) -> Vc<JavaScriptEvaluation> {
Expand Down Expand Up @@ -551,7 +551,7 @@ struct BasicEvaluateContext {
asset_context: ResolvedVc<Box<dyn AssetContext>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
args: Vec<Vc<JsonValue>>,
args: Vec<ResolvedVc<JsonValue>>,
additional_invalidation: ResolvedVc<Completion>,
debug: bool,
}
Expand Down Expand Up @@ -580,7 +580,7 @@ impl EvaluateContext for BasicEvaluateContext {
)
}

fn args(&self) -> &[Vc<serde_json::Value>] {
fn args(&self) -> &[ResolvedVc<serde_json::Value>] {
&self.args
}

Expand Down
2 changes: 2 additions & 0 deletions turbopack/crates/turbopack-node/src/node_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct NodeRenderingEntry {
pub project_dir: ResolvedVc<FileSystemPath>,
}

// TODO(ResolvedVc): this struct seems to be trivially used in this trait which returns a Vc
// so perhaps it should remain a Vc?
#[turbo_tasks::value(transparent)]
pub struct NodeRenderingEntries(Vec<Vc<NodeRenderingEntry>>);

Expand Down
5 changes: 4 additions & 1 deletion turbopack/crates/turbopack-node/src/transforms/postcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ impl PostCssTransformedAsset {
asset_context: evaluate_context,
chunking_context: *chunking_context,
resolve_options_context: None,
args: vec![Vc::cell(content.into()), Vc::cell(css_path.into())],
args: vec![
ResolvedVc::cell(content.into()),
ResolvedVc::cell(css_path.into()),
],
additional_invalidation: config_changed,
})
.await?;
Expand Down
28 changes: 16 additions & 12 deletions turbopack/crates/turbopack-node/src/transforms/webpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::mem::take;
use anyhow::{bail, Context, Result};
use async_trait::async_trait;
use either::Either;
use futures::future::try_join_all;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value as JsonValue};
use serde_with::serde_as;
Expand Down Expand Up @@ -172,7 +173,7 @@ impl GenerateSourceMap for WebpackLoadersProcessedAsset {
struct ProcessWebpackLoadersResult {
content: ResolvedVc<AssetContent>,
source_map: Option<ResolvedVc<SourceMap>>,
assets: Vec<Vc<VirtualSource>>,
assets: Vec<ResolvedVc<VirtualSource>>,
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -242,11 +243,11 @@ impl WebpackLoadersProcessedAsset {
chunking_context,
resolve_options_context: Some(transform.resolve_options_context),
args: vec![
Vc::cell(content.into()),
ResolvedVc::cell(content.into()),
// We need to pass the query string to the loader
Vc::cell(resource_path.to_string().into()),
Vc::cell(this.source.ident().query().await?.to_string().into()),
Vc::cell(json!(*loaders)),
ResolvedVc::cell(resource_path.to_string().into()),
ResolvedVc::cell(this.source.ident().query().await?.to_string().into()),
ResolvedVc::cell(json!(*loaders)),
],
additional_invalidation: Completion::immutable().to_resolved().await?,
})
Expand Down Expand Up @@ -278,11 +279,14 @@ impl WebpackLoadersProcessedAsset {
Either::Left(str) => File::from(str),
Either::Right(bytes) => File::from(bytes.binary),
};
let assets = emitted_assets_to_virtual_sources(processed.assets)
.await?
.into_iter()
.map(|asset| *asset)
.collect();
let assets = try_join_all(
emitted_assets_to_virtual_sources(processed.assets)
.await?
.into_iter()
.map(|v| v.to_resolved()),
)
.await?;

let content =
AssetContent::File(FileContent::Content(file).resolved_cell()).resolved_cell();
Ok(ProcessWebpackLoadersResult {
Expand Down Expand Up @@ -397,7 +401,7 @@ pub struct WebpackLoaderContext {
pub asset_context: ResolvedVc<Box<dyn AssetContext>>,
pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub resolve_options_context: Option<ResolvedVc<ResolveOptionsContext>>,
pub args: Vec<Vc<JsonValue>>,
pub args: Vec<ResolvedVc<JsonValue>>,
pub additional_invalidation: ResolvedVc<Completion>,
}

Expand Down Expand Up @@ -425,7 +429,7 @@ impl EvaluateContext for WebpackLoaderContext {
)
}

fn args(&self) -> &[Vc<serde_json::Value>] {
fn args(&self) -> &[ResolvedVc<serde_json::Value>] {
&self.args
}

Expand Down

0 comments on commit 2322dc6

Please sign in to comment.