Unverified Commit 9fdfe2a8 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

refactor(turbopack): Use `ResolvedVc<T>` instead of `Vc<T>` for `turbopack-node` (#72320)

### What?

Use `ResolvedVc<T>` instead of `Vc<T>` for **struct fields**.

### Why?

It's required for future works.

### How?



Closes PACK-3381

---------
Co-authored-by: 's avatarBenjamin Woodruff <benjamin.woodruff@vercel.com>
parent 93b3af5e
...@@ -289,7 +289,11 @@ pub async fn get_client_module_options_context( ...@@ -289,7 +289,11 @@ pub async fn get_client_module_options_context(
next_client_rules.extend(additional_rules); next_client_rules.extend(additional_rules);
let postcss_transform_options = PostCssTransformOptions { let postcss_transform_options = PostCssTransformOptions {
postcss_package: Some(get_postcss_package_mapping(project_path)), postcss_package: Some(
get_postcss_package_mapping(project_path)
.to_resolved()
.await?,
),
config_location: PostCssConfigLocation::ProjectPathOrLocalPath, config_location: PostCssConfigLocation::ProjectPathOrLocalPath,
..Default::default() ..Default::default()
}; };
......
...@@ -690,10 +690,10 @@ async fn get_mock_stylesheet( ...@@ -690,10 +690,10 @@ async fn get_mock_stylesheet(
let val = evaluate( let val = evaluate(
mocked_response_asset, mocked_response_asset,
root, root,
env, *env,
AssetIdent::from_path(loader_path), AssetIdent::from_path(loader_path),
asset_context, asset_context,
chunking_context, *chunking_context,
None, None,
vec![], vec![],
Completion::immutable(), Completion::immutable(),
......
...@@ -419,7 +419,11 @@ pub async fn get_server_module_options_context( ...@@ -419,7 +419,11 @@ pub async fn get_server_module_options_context(
let foreign_code_context_condition = let foreign_code_context_condition =
foreign_code_context_condition(next_config, project_path).await?; foreign_code_context_condition(next_config, project_path).await?;
let postcss_transform_options = PostCssTransformOptions { let postcss_transform_options = PostCssTransformOptions {
postcss_package: Some(get_postcss_package_mapping(project_path)), postcss_package: Some(
get_postcss_package_mapping(project_path)
.to_resolved()
.await?,
),
config_location: PostCssConfigLocation::ProjectPathOrLocalPath, config_location: PostCssConfigLocation::ProjectPathOrLocalPath,
..Default::default() ..Default::default()
}; };
......
...@@ -159,12 +159,14 @@ pub async fn get_evaluate_pool( ...@@ -159,12 +159,14 @@ pub async fn get_evaluate_pool(
runtime_entries, runtime_entries,
); );
let output_root: Vc<FileSystemPath> = chunking_context.output_root(); let output_root = chunking_context.output_root().to_resolved().await?;
let _ = emit_package_json(output_root); let _ = emit_package_json(*output_root);
// Invalidate pool when code content changes // Invalidate pool when code content changes
content_changed(Vc::upcast(bootstrap)).await?; content_changed(Vc::upcast(bootstrap)).await?;
let _ = emit(bootstrap, output_root); let _ = emit(bootstrap, *output_root);
let assets_for_source_mapping = internal_assets_for_source_mapping(bootstrap, output_root); let assets_for_source_mapping = internal_assets_for_source_mapping(bootstrap, *output_root)
.to_resolved()
.await?;
let pool = NodeJsPool::new( let pool = NodeJsPool::new(
cwd, cwd,
entrypoint, entrypoint,
...@@ -175,7 +177,7 @@ pub async fn get_evaluate_pool( ...@@ -175,7 +177,7 @@ pub async fn get_evaluate_pool(
.collect(), .collect(),
assets_for_source_mapping, assets_for_source_mapping,
output_root, output_root,
chunking_context.context_path().root(), chunking_context.context_path().root().to_resolved().await?,
available_parallelism().map_or(1, |v| v.get()), available_parallelism().map_or(1, |v| v.get()),
debug, debug,
); );
...@@ -284,15 +286,15 @@ pub fn custom_evaluate(evaluate_context: impl EvaluateContext) -> Vc<JavaScriptE ...@@ -284,15 +286,15 @@ pub fn custom_evaluate(evaluate_context: impl EvaluateContext) -> Vc<JavaScriptE
/// evaluated result automatically. /// evaluated result automatically.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn evaluate( pub fn evaluate(
module_asset: Vc<Box<dyn Module>>, module_asset: ResolvedVc<Box<dyn Module>>,
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
context_ident_for_issue: Vc<AssetIdent>, context_ident_for_issue: ResolvedVc<AssetIdent>,
asset_context: Vc<Box<dyn AssetContext>>, asset_context: ResolvedVc<Box<dyn AssetContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
runtime_entries: Option<Vc<EvaluatableAssets>>, runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
args: Vec<Vc<JsonValue>>, args: Vec<Vc<JsonValue>>,
additional_invalidation: Vc<Completion>, additional_invalidation: ResolvedVc<Completion>,
debug: bool, debug: bool,
) -> Vc<JavaScriptEvaluation> { ) -> Vc<JavaScriptEvaluation> {
custom_evaluate(BasicEvaluateContext { custom_evaluate(BasicEvaluateContext {
...@@ -465,15 +467,15 @@ async fn basic_compute( ...@@ -465,15 +467,15 @@ async fn basic_compute(
#[derive(Clone, PartialEq, Eq, Hash, TaskInput, Debug, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Hash, TaskInput, Debug, Serialize, Deserialize)]
struct BasicEvaluateContext { struct BasicEvaluateContext {
module_asset: Vc<Box<dyn Module>>, module_asset: ResolvedVc<Box<dyn Module>>,
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
context_ident_for_issue: Vc<AssetIdent>, context_ident_for_issue: ResolvedVc<AssetIdent>,
asset_context: Vc<Box<dyn AssetContext>>, asset_context: ResolvedVc<Box<dyn AssetContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
runtime_entries: Option<Vc<EvaluatableAssets>>, runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
args: Vec<Vc<JsonValue>>, args: Vec<Vc<JsonValue>>,
additional_invalidation: Vc<Completion>, additional_invalidation: ResolvedVc<Completion>,
debug: bool, debug: bool,
} }
...@@ -490,13 +492,13 @@ impl EvaluateContext for BasicEvaluateContext { ...@@ -490,13 +492,13 @@ impl EvaluateContext for BasicEvaluateContext {
fn pool(&self) -> Vc<crate::pool::NodeJsPool> { fn pool(&self) -> Vc<crate::pool::NodeJsPool> {
get_evaluate_pool( get_evaluate_pool(
self.module_asset, *self.module_asset,
self.cwd, *self.cwd,
self.env, *self.env,
self.asset_context, *self.asset_context,
self.chunking_context, *self.chunking_context,
self.runtime_entries, self.runtime_entries.map(|r| *r),
self.additional_invalidation, *self.additional_invalidation,
self.debug, self.debug,
) )
} }
...@@ -506,7 +508,7 @@ impl EvaluateContext for BasicEvaluateContext { ...@@ -506,7 +508,7 @@ impl EvaluateContext for BasicEvaluateContext {
} }
fn cwd(&self) -> Vc<turbo_tasks_fs::FileSystemPath> { fn cwd(&self) -> Vc<turbo_tasks_fs::FileSystemPath> {
self.cwd *self.cwd
} }
fn keep_alive(&self) -> bool { fn keep_alive(&self) -> bool {
...@@ -519,7 +521,12 @@ impl EvaluateContext for BasicEvaluateContext { ...@@ -519,7 +521,12 @@ impl EvaluateContext for BasicEvaluateContext {
context_ident: self.context_ident_for_issue, context_ident: self.context_ident_for_issue,
assets_for_source_mapping: pool.assets_for_source_mapping, assets_for_source_mapping: pool.assets_for_source_mapping,
assets_root: pool.assets_root, assets_root: pool.assets_root,
project_dir: self.chunking_context.context_path().root(), project_dir: self
.chunking_context
.context_path()
.root()
.to_resolved()
.await?,
} }
.cell() .cell()
.emit(); .emit();
...@@ -556,8 +563,8 @@ async fn print_error( ...@@ -556,8 +563,8 @@ async fn print_error(
) -> Result<String> { ) -> Result<String> {
error error
.print( .print(
pool.assets_for_source_mapping, *pool.assets_for_source_mapping,
pool.assets_root, *pool.assets_root,
evaluate_context.cwd(), evaluate_context.cwd(),
FormattingMode::Plain, FormattingMode::Plain,
) )
...@@ -566,11 +573,11 @@ async fn print_error( ...@@ -566,11 +573,11 @@ async fn print_error(
/// An issue that occurred while evaluating node code. /// An issue that occurred while evaluating node code.
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct EvaluationIssue { pub struct EvaluationIssue {
pub context_ident: Vc<AssetIdent>, pub context_ident: ResolvedVc<AssetIdent>,
pub error: StructuredError, pub error: StructuredError,
pub assets_for_source_mapping: Vc<AssetsForSourceMapping>, pub assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
pub assets_root: Vc<FileSystemPath>, pub assets_root: ResolvedVc<FileSystemPath>,
pub project_dir: Vc<FileSystemPath>, pub project_dir: ResolvedVc<FileSystemPath>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -596,9 +603,9 @@ impl Issue for EvaluationIssue { ...@@ -596,9 +603,9 @@ impl Issue for EvaluationIssue {
StyledString::Text( StyledString::Text(
self.error self.error
.print( .print(
self.assets_for_source_mapping, *self.assets_for_source_mapping,
self.assets_root, *self.assets_root,
self.project_dir, *self.project_dir,
FormattingMode::Plain, FormattingMode::Plain,
) )
.await? .await?
......
use turbo_tasks::Vc; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::chunk::ChunkingContext; use turbopack_core::chunk::ChunkingContext;
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct ExecutionContext { pub struct ExecutionContext {
pub project_path: Vc<FileSystemPath>, pub project_path: ResolvedVc<FileSystemPath>,
pub chunking_context: Vc<Box<dyn ChunkingContext>>, pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub env: Vc<Box<dyn ProcessEnv>>, pub env: ResolvedVc<Box<dyn ProcessEnv>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ExecutionContext { impl ExecutionContext {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new( pub fn new(
project_path: Vc<FileSystemPath>, project_path: ResolvedVc<FileSystemPath>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
) -> Vc<Self> { ) -> Vc<Self> {
ExecutionContext { ExecutionContext {
project_path, project_path,
...@@ -28,16 +28,16 @@ impl ExecutionContext { ...@@ -28,16 +28,16 @@ impl ExecutionContext {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn project_path(&self) -> Vc<FileSystemPath> { pub fn project_path(&self) -> Vc<FileSystemPath> {
self.project_path *self.project_path
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> { pub fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.chunking_context *self.chunking_context
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn env(&self) -> Vc<Box<dyn ProcessEnv>> { pub fn env(&self) -> Vc<Box<dyn ProcessEnv>> {
self.env *self.env
} }
} }
...@@ -57,8 +57,8 @@ async fn emit( ...@@ -57,8 +57,8 @@ async fn emit(
#[derive(Debug)] #[derive(Debug)]
#[turbo_tasks::value] #[turbo_tasks::value]
struct SeparatedAssets { struct SeparatedAssets {
internal_assets: Vc<OutputAssetsSet>, internal_assets: ResolvedVc<OutputAssetsSet>,
external_asset_entrypoints: Vc<OutputAssetsSet>, external_asset_entrypoints: ResolvedVc<OutputAssetsSet>,
} }
/// Extracts the subgraph of "internal" assets (assets within the passes /// Extracts the subgraph of "internal" assets (assets within the passes
...@@ -70,7 +70,7 @@ async fn internal_assets( ...@@ -70,7 +70,7 @@ async fn internal_assets(
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: Vc<FileSystemPath>,
) -> Result<Vc<OutputAssetsSet>> { ) -> Result<Vc<OutputAssetsSet>> {
Ok( Ok(
separate_assets(intermediate_asset, intermediate_output_path) *separate_assets(intermediate_asset, intermediate_output_path)
.strongly_consistent() .strongly_consistent()
.await? .await?
.internal_assets, .internal_assets,
...@@ -112,7 +112,7 @@ pub async fn external_asset_entrypoints( ...@@ -112,7 +112,7 @@ pub async fn external_asset_entrypoints(
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: Vc<Box<dyn ChunkingContext>>,
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: Vc<FileSystemPath>,
) -> Result<Vc<OutputAssetsSet>> { ) -> Result<Vc<OutputAssetsSet>> {
Ok(separate_assets( Ok(*separate_assets(
get_intermediate_asset(chunking_context, module, runtime_entries) get_intermediate_asset(chunking_context, module, runtime_entries)
.resolve() .resolve()
.await?, .await?,
...@@ -186,8 +186,8 @@ async fn separate_assets( ...@@ -186,8 +186,8 @@ async fn separate_assets(
} }
Ok(SeparatedAssets { Ok(SeparatedAssets {
internal_assets: Vc::cell(internal_assets), internal_assets: ResolvedVc::cell(internal_assets),
external_asset_entrypoints: Vc::cell(external_asset_entrypoints), external_asset_entrypoints: ResolvedVc::cell(external_asset_entrypoints),
} }
.cell()) .cell())
} }
...@@ -212,15 +212,15 @@ pub async fn get_renderer_pool( ...@@ -212,15 +212,15 @@ pub async fn get_renderer_pool(
env: Vc<Box<dyn ProcessEnv>>, env: Vc<Box<dyn ProcessEnv>>,
intermediate_asset: Vc<Box<dyn OutputAsset>>, intermediate_asset: Vc<Box<dyn OutputAsset>>,
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: Vc<FileSystemPath>,
output_root: Vc<FileSystemPath>, output_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
debug: bool, debug: bool,
) -> Result<Vc<NodeJsPool>> { ) -> Result<Vc<NodeJsPool>> {
emit_package_json(intermediate_output_path).await?; emit_package_json(intermediate_output_path).await?;
let emit = emit(intermediate_asset, output_root); let emit = emit(intermediate_asset, *output_root);
let assets_for_source_mapping = let assets_for_source_mapping =
internal_assets_for_source_mapping(intermediate_asset, output_root); internal_assets_for_source_mapping(intermediate_asset, *output_root);
let entrypoint = intermediate_asset.ident().path(); let entrypoint = intermediate_asset.ident().path();
...@@ -246,7 +246,7 @@ pub async fn get_renderer_pool( ...@@ -246,7 +246,7 @@ pub async fn get_renderer_pool(
.iter() .iter()
.map(|(k, v)| (k.clone(), v.clone())) .map(|(k, v)| (k.clone(), v.clone()))
.collect(), .collect(),
assets_for_source_mapping, assets_for_source_mapping.to_resolved().await?,
output_root, output_root,
project_dir, project_dir,
available_parallelism().map_or(1, |v| v.get()), available_parallelism().map_or(1, |v| v.get()),
......
use turbo_tasks::{Value, Vc}; use turbo_tasks::{ResolvedVc, Value, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkingContext, EvaluatableAssets}, chunk::{ChunkingContext, EvaluatableAssets},
...@@ -8,12 +8,12 @@ use turbopack_dev_server::source::ContentSourceData; ...@@ -8,12 +8,12 @@ use turbopack_dev_server::source::ContentSourceData;
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct NodeRenderingEntry { pub struct NodeRenderingEntry {
pub runtime_entries: Vc<EvaluatableAssets>, pub runtime_entries: ResolvedVc<EvaluatableAssets>,
pub module: Vc<Box<dyn Module>>, pub module: ResolvedVc<Box<dyn Module>>,
pub chunking_context: Vc<Box<dyn ChunkingContext>>, pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub intermediate_output_path: Vc<FileSystemPath>, pub intermediate_output_path: ResolvedVc<FileSystemPath>,
pub output_root: Vc<FileSystemPath>, pub output_root: ResolvedVc<FileSystemPath>,
pub project_dir: Vc<FileSystemPath>, pub project_dir: ResolvedVc<FileSystemPath>,
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
......
...@@ -27,7 +27,7 @@ use tokio::{ ...@@ -27,7 +27,7 @@ use tokio::{
sync::{OwnedSemaphorePermit, Semaphore}, sync::{OwnedSemaphorePermit, Semaphore},
time::{sleep, timeout}, time::{sleep, timeout},
}; };
use turbo_tasks::{duration_span, FxIndexSet, RcStr, Vc}; use turbo_tasks::{duration_span, FxIndexSet, RcStr, ResolvedVc, Vc};
use turbo_tasks_fs::{json::parse_json_with_source_context, FileSystemPath}; use turbo_tasks_fs::{json::parse_json_with_source_context, FileSystemPath};
use turbopack_ecmascript::magic_identifier::unmangle_identifiers; use turbopack_ecmascript::magic_identifier::unmangle_identifiers;
...@@ -69,9 +69,9 @@ impl FormattingMode { ...@@ -69,9 +69,9 @@ impl FormattingMode {
struct NodeJsPoolProcess { struct NodeJsPoolProcess {
child: Option<Child>, child: Option<Child>,
connection: TcpStream, connection: TcpStream,
assets_for_source_mapping: Vc<AssetsForSourceMapping>, assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
assets_root: Vc<FileSystemPath>, assets_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
stdout_handler: OutputStreamHandler<ChildStdout, Stdout>, stdout_handler: OutputStreamHandler<ChildStdout, Stdout>,
stderr_handler: OutputStreamHandler<ChildStderr, Stderr>, stderr_handler: OutputStreamHandler<ChildStderr, Stderr>,
debug: bool, debug: bool,
...@@ -88,9 +88,9 @@ impl NodeJsPoolProcess { ...@@ -88,9 +88,9 @@ impl NodeJsPoolProcess {
Cow::Borrowed(text) => { Cow::Borrowed(text) => {
apply_source_mapping( apply_source_mapping(
text, text,
self.assets_for_source_mapping, *self.assets_for_source_mapping,
self.assets_root, *self.assets_root,
self.project_dir, *self.project_dir,
formatting_mode, formatting_mode,
) )
.await .await
...@@ -98,9 +98,9 @@ impl NodeJsPoolProcess { ...@@ -98,9 +98,9 @@ impl NodeJsPoolProcess {
Cow::Owned(ref text) => { Cow::Owned(ref text) => {
let cow = apply_source_mapping( let cow = apply_source_mapping(
text, text,
self.assets_for_source_mapping, *self.assets_for_source_mapping,
self.assets_root, *self.assets_root,
self.project_dir, *self.project_dir,
formatting_mode, formatting_mode,
) )
.await?; .await?;
...@@ -127,9 +127,9 @@ static MARKER_STR: &str = "TURBOPACK_OUTPUT_"; ...@@ -127,9 +127,9 @@ static MARKER_STR: &str = "TURBOPACK_OUTPUT_";
struct OutputStreamHandler<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> { struct OutputStreamHandler<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> {
stream: BufReader<R>, stream: BufReader<R>,
shared: SharedOutputSet, shared: SharedOutputSet,
assets_for_source_mapping: Vc<AssetsForSourceMapping>, assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
root: Vc<FileSystemPath>, root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
final_stream: W, final_stream: W,
} }
...@@ -266,9 +266,9 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> { ...@@ -266,9 +266,9 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> {
} }
write_source_mapped_final( write_source_mapped_final(
&entry.data, &entry.data,
*assets_for_source_mapping, **assets_for_source_mapping,
*root, **root,
*project_dir, **project_dir,
final_stream, final_stream,
) )
.await?; .await?;
...@@ -293,9 +293,9 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> { ...@@ -293,9 +293,9 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> {
write_source_mapped_final( write_source_mapped_final(
&buffer, &buffer,
*assets_for_source_mapping, **assets_for_source_mapping,
*root, **root,
*project_dir, **project_dir,
final_stream, final_stream,
) )
.await?; .await?;
...@@ -310,9 +310,9 @@ impl NodeJsPoolProcess { ...@@ -310,9 +310,9 @@ impl NodeJsPoolProcess {
cwd: &Path, cwd: &Path,
env: &HashMap<RcStr, RcStr>, env: &HashMap<RcStr, RcStr>,
entrypoint: &Path, entrypoint: &Path,
assets_for_source_mapping: Vc<AssetsForSourceMapping>, assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
assets_root: Vc<FileSystemPath>, assets_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
shared_stdout: SharedOutputSet, shared_stdout: SharedOutputSet,
shared_stderr: SharedOutputSet, shared_stderr: SharedOutputSet,
debug: bool, debug: bool,
...@@ -688,9 +688,9 @@ pub struct NodeJsPool { ...@@ -688,9 +688,9 @@ pub struct NodeJsPool {
cwd: PathBuf, cwd: PathBuf,
entrypoint: PathBuf, entrypoint: PathBuf,
env: HashMap<RcStr, RcStr>, env: HashMap<RcStr, RcStr>,
pub assets_for_source_mapping: Vc<AssetsForSourceMapping>, pub assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
pub assets_root: Vc<FileSystemPath>, pub assets_root: ResolvedVc<FileSystemPath>,
pub project_dir: Vc<FileSystemPath>, pub project_dir: ResolvedVc<FileSystemPath>,
#[turbo_tasks(trace_ignore, debug_ignore)] #[turbo_tasks(trace_ignore, debug_ignore)]
processes: Arc<Mutex<Vec<NodeJsPoolProcess>>>, processes: Arc<Mutex<Vec<NodeJsPoolProcess>>>,
/// Semaphore to limit the number of concurrent operations in general /// Semaphore to limit the number of concurrent operations in general
...@@ -719,9 +719,9 @@ impl NodeJsPool { ...@@ -719,9 +719,9 @@ impl NodeJsPool {
cwd: PathBuf, cwd: PathBuf,
entrypoint: PathBuf, entrypoint: PathBuf,
env: HashMap<RcStr, RcStr>, env: HashMap<RcStr, RcStr>,
assets_for_source_mapping: Vc<AssetsForSourceMapping>, assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
assets_root: Vc<FileSystemPath>, assets_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
concurrency: usize, concurrency: usize,
debug: bool, debug: bool,
) -> Self { ) -> Self {
......
use turbo_tasks::Vc; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::issue::{Issue, IssueStage, OptionStyledString, StyledString}; use turbopack_core::issue::{Issue, IssueStage, OptionStyledString, StyledString};
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct RenderingIssue { pub struct RenderingIssue {
pub file_path: Vc<FileSystemPath>, pub file_path: ResolvedVc<FileSystemPath>,
pub message: Vc<StyledString>, pub message: ResolvedVc<StyledString>,
pub status: Option<i32>, pub status: Option<i32>,
} }
...@@ -24,12 +24,12 @@ impl Issue for RenderingIssue { ...@@ -24,12 +24,12 @@ impl Issue for RenderingIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> { fn file_path(&self) -> Vc<FileSystemPath> {
self.file_path *self.file_path
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn description(&self) -> Vc<OptionStyledString> { fn description(&self) -> Vc<OptionStyledString> {
Vc::cell(Some(self.message)) Vc::cell(Some(*self.message))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use turbo_tasks::{FxIndexSet, RcStr, Value, Vc}; use turbo_tasks::{FxIndexSet, RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::introspect::{ use turbopack_core::introspect::{
...@@ -19,15 +19,15 @@ use crate::{get_intermediate_asset, node_entry::NodeEntry, route_matcher::RouteM ...@@ -19,15 +19,15 @@ use crate::{get_intermediate_asset, node_entry::NodeEntry, route_matcher::RouteM
/// Creates a [NodeApiContentSource]. /// Creates a [NodeApiContentSource].
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn create_node_api_source( pub fn create_node_api_source(
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
base_segments: Vec<BaseSegment>, base_segments: Vec<BaseSegment>,
route_type: RouteType, route_type: RouteType,
server_root: Vc<FileSystemPath>, server_root: ResolvedVc<FileSystemPath>,
route_match: Vc<Box<dyn RouteMatcher>>, route_match: ResolvedVc<Box<dyn RouteMatcher>>,
pathname: Vc<RcStr>, pathname: ResolvedVc<RcStr>,
entry: Vc<Box<dyn NodeEntry>>, entry: ResolvedVc<Box<dyn NodeEntry>>,
render_data: Vc<JsonValue>, render_data: ResolvedVc<JsonValue>,
debug: bool, debug: bool,
) -> Vc<Box<dyn ContentSource>> { ) -> Vc<Box<dyn ContentSource>> {
Vc::upcast( Vc::upcast(
...@@ -55,15 +55,15 @@ pub fn create_node_api_source( ...@@ -55,15 +55,15 @@ pub fn create_node_api_source(
/// to this directory. /// to this directory.
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct NodeApiContentSource { pub struct NodeApiContentSource {
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
base_segments: Vec<BaseSegment>, base_segments: Vec<BaseSegment>,
route_type: RouteType, route_type: RouteType,
server_root: Vc<FileSystemPath>, server_root: ResolvedVc<FileSystemPath>,
pathname: Vc<RcStr>, pathname: ResolvedVc<RcStr>,
route_match: Vc<Box<dyn RouteMatcher>>, route_match: ResolvedVc<Box<dyn RouteMatcher>>,
entry: Vc<Box<dyn NodeEntry>>, entry: ResolvedVc<Box<dyn NodeEntry>>,
render_data: Vc<JsonValue>, render_data: ResolvedVc<JsonValue>,
debug: bool, debug: bool,
} }
...@@ -71,7 +71,7 @@ pub struct NodeApiContentSource { ...@@ -71,7 +71,7 @@ pub struct NodeApiContentSource {
impl NodeApiContentSource { impl NodeApiContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn get_pathname(&self) -> Vc<RcStr> { pub fn get_pathname(&self) -> Vc<RcStr> {
self.pathname *self.pathname
} }
} }
...@@ -126,18 +126,18 @@ impl GetContentSourceContent for NodeApiContentSource { ...@@ -126,18 +126,18 @@ impl GetContentSourceContent for NodeApiContentSource {
else { else {
return Err(anyhow!("Missing request data")); return Err(anyhow!("Missing request data"));
}; };
let entry = self.entry.entry(data.clone()).await?; let entry = (*self.entry).entry(data.clone()).await?;
Ok(ContentSourceContent::HttpProxy( Ok(ContentSourceContent::HttpProxy(
render_proxy( render_proxy(
self.cwd, *self.cwd,
self.env, *self.env,
self.server_root.join(path.clone()), self.server_root.join(path.clone()),
entry.module, *entry.module,
entry.runtime_entries, *entry.runtime_entries,
entry.chunking_context, *entry.chunking_context,
entry.intermediate_output_path, *entry.intermediate_output_path,
entry.output_root, *entry.output_root,
entry.project_dir, *entry.project_dir,
RenderData { RenderData {
params: params.clone(), params: params.clone(),
method: method.clone(), method: method.clone(),
...@@ -173,7 +173,7 @@ impl Introspectable for NodeApiContentSource { ...@@ -173,7 +173,7 @@ impl Introspectable for NodeApiContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
fn title(&self) -> Vc<RcStr> { fn title(&self) -> Vc<RcStr> {
self.pathname *self.pathname
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -194,14 +194,14 @@ impl Introspectable for NodeApiContentSource { ...@@ -194,14 +194,14 @@ impl Introspectable for NodeApiContentSource {
let entry = entry.await?; let entry = entry.await?;
set.insert(( set.insert((
Vc::cell("module".into()), Vc::cell("module".into()),
IntrospectableModule::new(Vc::upcast(entry.module)), IntrospectableModule::new(Vc::upcast(*entry.module)),
)); ));
set.insert(( set.insert((
Vc::cell("intermediate asset".into()), Vc::cell("intermediate asset".into()),
IntrospectableOutputAsset::new(get_intermediate_asset( IntrospectableOutputAsset::new(get_intermediate_asset(
entry.chunking_context, *entry.chunking_context,
Vc::upcast(entry.module), Vc::upcast(*entry.module),
entry.runtime_entries, *entry.runtime_entries,
)), )),
)); ));
} }
......
...@@ -7,8 +7,8 @@ use futures::{ ...@@ -7,8 +7,8 @@ use futures::{
use parking_lot::Mutex; use parking_lot::Mutex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{ use turbo_tasks::{
duration_span, mark_finished, prevent_gc, util::SharedError, RawVc, RcStr, TaskInput, duration_span, mark_finished, prevent_gc, util::SharedError, RawVc, RcStr, ResolvedVc,
ValueToString, Vc, TaskInput, ValueToString, Vc,
}; };
use turbo_tasks_bytes::{Bytes, Stream}; use turbo_tasks_bytes::{Bytes, Stream};
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
...@@ -33,17 +33,17 @@ use crate::{ ...@@ -33,17 +33,17 @@ use crate::{
/// Renders a module as static HTML in a node.js process. /// Renders a module as static HTML in a node.js process.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn render_proxy( pub async fn render_proxy(
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
runtime_entries: Vc<EvaluatableAssets>, runtime_entries: ResolvedVc<EvaluatableAssets>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: ResolvedVc<FileSystemPath>,
output_root: Vc<FileSystemPath>, output_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
data: Vc<RenderData>, data: ResolvedVc<RenderData>,
body: Vc<Body>, body: ResolvedVc<Body>,
debug: bool, debug: bool,
) -> Result<Vc<ProxyResult>> { ) -> Result<Vc<ProxyResult>> {
let render = render_stream(RenderStreamOptions { let render = render_stream(RenderStreamOptions {
...@@ -94,7 +94,7 @@ pub async fn render_proxy( ...@@ -94,7 +94,7 @@ pub async fn render_proxy(
} }
async fn proxy_error( async fn proxy_error(
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
error: anyhow::Error, error: anyhow::Error,
operation: Option<NodeJsOperation>, operation: Option<NodeJsOperation>,
) -> Result<(u16, RcStr)> { ) -> Result<(u16, RcStr)> {
...@@ -121,7 +121,7 @@ async fn proxy_error( ...@@ -121,7 +121,7 @@ async fn proxy_error(
RenderingIssue { RenderingIssue {
file_path: path, file_path: path,
message: StyledString::Text(message.into()).cell(), message: StyledString::Text(message.into()).resolved_cell(),
status: status.and_then(|status| status.code()), status: status.and_then(|status| status.code()),
} }
.cell() .cell()
...@@ -150,17 +150,17 @@ struct RenderStream(#[turbo_tasks(trace_ignore)] Stream<RenderItemResult>); ...@@ -150,17 +150,17 @@ struct RenderStream(#[turbo_tasks(trace_ignore)] Stream<RenderItemResult>);
#[derive(Clone, Debug, TaskInput, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, TaskInput, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct RenderStreamOptions { struct RenderStreamOptions {
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
runtime_entries: Vc<EvaluatableAssets>, runtime_entries: ResolvedVc<EvaluatableAssets>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: ResolvedVc<FileSystemPath>,
output_root: Vc<FileSystemPath>, output_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
data: Vc<RenderData>, data: ResolvedVc<RenderData>,
body: Vc<Body>, body: ResolvedVc<Body>,
debug: bool, debug: bool,
} }
...@@ -234,17 +234,17 @@ async fn render_stream_internal( ...@@ -234,17 +234,17 @@ async fn render_stream_internal(
let stream = generator! { let stream = generator! {
let intermediate_asset = get_intermediate_asset( let intermediate_asset = get_intermediate_asset(
chunking_context, *chunking_context,
module, *module,
runtime_entries, *runtime_entries,
); );
let pool = get_renderer_pool( let pool = get_renderer_pool(
cwd, *cwd,
env, *env,
intermediate_asset, intermediate_asset,
intermediate_output_path, *intermediate_output_path,
output_root, *output_root,
project_dir, *project_dir,
debug, debug,
); );
...@@ -279,8 +279,8 @@ async fn render_stream_internal( ...@@ -279,8 +279,8 @@ async fn render_stream_internal(
let trace = trace_stack( let trace = trace_stack(
error, error,
intermediate_asset, intermediate_asset,
intermediate_output_path, *intermediate_output_path,
project_dir *project_dir
) )
.await?; .await?;
let (status, body) = proxy_error(path, anyhow!("error rendering: {}", trace), Some(operation)).await?; let (status, body) = proxy_error(path, anyhow!("error rendering: {}", trace), Some(operation)).await?;
...@@ -313,7 +313,7 @@ async fn render_stream_internal( ...@@ -313,7 +313,7 @@ async fn render_stream_internal(
// headers/body to a proxy error. // headers/body to a proxy error.
operation.disallow_reuse(); operation.disallow_reuse();
let trace = let trace =
trace_stack(error, intermediate_asset, intermediate_output_path, project_dir).await?; trace_stack(error, intermediate_asset, *intermediate_output_path, *project_dir).await?;
Err(anyhow!("error during streaming render: {}", trace))?; Err(anyhow!("error during streaming render: {}", trace))?;
return; return;
} }
......
...@@ -37,13 +37,13 @@ use crate::{ ...@@ -37,13 +37,13 @@ use crate::{
#[turbo_tasks::value] #[turbo_tasks::value]
pub enum StaticResult { pub enum StaticResult {
Content { Content {
content: Vc<AssetContent>, content: ResolvedVc<AssetContent>,
status_code: u16, status_code: u16,
headers: Vc<HeaderList>, headers: ResolvedVc<HeaderList>,
}, },
StreamedContent { StreamedContent {
status: u16, status: u16,
headers: Vc<HeaderList>, headers: ResolvedVc<HeaderList>,
body: Body, body: Body,
}, },
Rewrite(ResolvedVc<Rewrite>), Rewrite(ResolvedVc<Rewrite>),
...@@ -53,9 +53,9 @@ pub enum StaticResult { ...@@ -53,9 +53,9 @@ pub enum StaticResult {
impl StaticResult { impl StaticResult {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn content( pub fn content(
content: Vc<AssetContent>, content: ResolvedVc<AssetContent>,
status_code: u16, status_code: u16,
headers: Vc<HeaderList>, headers: ResolvedVc<HeaderList>,
) -> Vc<Self> { ) -> Vc<Self> {
StaticResult::Content { StaticResult::Content {
content, content,
...@@ -74,17 +74,17 @@ impl StaticResult { ...@@ -74,17 +74,17 @@ impl StaticResult {
/// Renders a module as static HTML in a node.js process. /// Renders a module as static HTML in a node.js process.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn render_static( pub async fn render_static(
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
runtime_entries: Vc<EvaluatableAssets>, runtime_entries: ResolvedVc<EvaluatableAssets>,
fallback_page: Vc<DevHtmlAsset>, fallback_page: ResolvedVc<DevHtmlAsset>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: ResolvedVc<FileSystemPath>,
output_root: Vc<FileSystemPath>, output_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
data: Vc<RenderData>, data: ResolvedVc<RenderData>,
debug: bool, debug: bool,
) -> Result<Vc<StaticResult>> { ) -> Result<Vc<StaticResult>> {
let render = render_stream(RenderStreamOptions { let render = render_stream(RenderStreamOptions {
...@@ -126,7 +126,7 @@ pub async fn render_static( ...@@ -126,7 +126,7 @@ pub async fn render_static(
}); });
StaticResult::StreamedContent { StaticResult::StreamedContent {
status: data.status, status: data.status,
headers: Vc::cell(data.headers), headers: ResolvedVc::cell(data.headers),
body: Body::from_stream(body), body: Body::from_stream(body),
} }
.cell() .cell()
...@@ -136,7 +136,7 @@ pub async fn render_static( ...@@ -136,7 +136,7 @@ pub async fn render_static(
} }
async fn static_error( async fn static_error(
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
error: anyhow::Error, error: anyhow::Error,
operation: Option<NodeJsOperation>, operation: Option<NodeJsOperation>,
fallback_page: Vc<DevHtmlAsset>, fallback_page: Vc<DevHtmlAsset>,
...@@ -169,7 +169,7 @@ async fn static_error( ...@@ -169,7 +169,7 @@ async fn static_error(
let issue = RenderingIssue { let issue = RenderingIssue {
file_path: path, file_path: path,
message: StyledString::Text(error.into()).cell(), message: StyledString::Text(error.into()).resolved_cell(),
status: status.and_then(|status| status.code()), status: status.and_then(|status| status.code()),
}; };
...@@ -201,17 +201,17 @@ struct RenderStream(#[turbo_tasks(trace_ignore)] Stream<RenderItemResult>); ...@@ -201,17 +201,17 @@ struct RenderStream(#[turbo_tasks(trace_ignore)] Stream<RenderItemResult>);
#[derive(Clone, Debug, TaskInput, PartialEq, Eq, Hash, Deserialize, Serialize)] #[derive(Clone, Debug, TaskInput, PartialEq, Eq, Hash, Deserialize, Serialize)]
struct RenderStreamOptions { struct RenderStreamOptions {
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
runtime_entries: Vc<EvaluatableAssets>, runtime_entries: ResolvedVc<EvaluatableAssets>,
fallback_page: Vc<DevHtmlAsset>, fallback_page: ResolvedVc<DevHtmlAsset>,
chunking_context: Vc<Box<dyn ChunkingContext>>, chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
intermediate_output_path: Vc<FileSystemPath>, intermediate_output_path: ResolvedVc<FileSystemPath>,
output_root: Vc<FileSystemPath>, output_root: ResolvedVc<FileSystemPath>,
project_dir: Vc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
data: Vc<RenderData>, data: ResolvedVc<RenderData>,
debug: bool, debug: bool,
} }
...@@ -285,17 +285,17 @@ async fn render_stream_internal( ...@@ -285,17 +285,17 @@ async fn render_stream_internal(
let stream = generator! { let stream = generator! {
let intermediate_asset = get_intermediate_asset( let intermediate_asset = get_intermediate_asset(
chunking_context, *chunking_context,
module, *module,
runtime_entries, *runtime_entries,
); );
let renderer_pool = get_renderer_pool( let renderer_pool = get_renderer_pool(
cwd, *cwd,
env, *env,
intermediate_asset, intermediate_asset,
intermediate_output_path, *intermediate_output_path,
output_root, *output_root,
project_dir, *project_dir,
debug, debug,
); );
...@@ -344,13 +344,13 @@ async fn render_stream_internal( ...@@ -344,13 +344,13 @@ async fn render_stream_internal(
let trace = trace_stack( let trace = trace_stack(
error, error,
intermediate_asset, intermediate_asset,
intermediate_output_path, *intermediate_output_path,
project_dir, *project_dir,
) )
.await?; .await?;
yield RenderItem::Response( yield RenderItem::Response(
StaticResult::content( StaticResult::content(
static_error(path, anyhow!(trace), Some(operation), fallback_page).await?, static_error(path, anyhow!(trace), Some(operation), *fallback_page).await?,
500, 500,
HeaderList::empty(), HeaderList::empty(),
).to_resolved().await? ).to_resolved().await?
...@@ -377,7 +377,7 @@ async fn render_stream_internal( ...@@ -377,7 +377,7 @@ async fn render_stream_internal(
// headers/body to a proxy error. // headers/body to a proxy error.
operation.disallow_reuse(); operation.disallow_reuse();
let trace = let trace =
trace_stack(error, intermediate_asset, intermediate_output_path, project_dir).await?; trace_stack(error, intermediate_asset, *intermediate_output_path, *project_dir).await?;
drop(guard); drop(guard);
Err(anyhow!("error during streaming render: {}", trace))?; Err(anyhow!("error during streaming render: {}", trace))?;
return; return;
......
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use turbo_tasks::{FxIndexSet, RcStr, Value, Vc}; use turbo_tasks::{FxIndexSet, RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
...@@ -42,16 +42,16 @@ use crate::{ ...@@ -42,16 +42,16 @@ use crate::{
/// to this directory. /// to this directory.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn create_node_rendered_source( pub fn create_node_rendered_source(
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
base_segments: Vec<BaseSegment>, base_segments: Vec<BaseSegment>,
route_type: RouteType, route_type: RouteType,
server_root: Vc<FileSystemPath>, server_root: ResolvedVc<FileSystemPath>,
route_match: Vc<Box<dyn RouteMatcher>>, route_match: ResolvedVc<Box<dyn RouteMatcher>>,
pathname: Vc<RcStr>, pathname: ResolvedVc<RcStr>,
entry: Vc<Box<dyn NodeEntry>>, entry: ResolvedVc<Box<dyn NodeEntry>>,
fallback_page: Vc<DevHtmlAsset>, fallback_page: ResolvedVc<DevHtmlAsset>,
render_data: Vc<JsonValue>, render_data: ResolvedVc<JsonValue>,
debug: bool, debug: bool,
) -> Vc<Box<dyn ContentSource>> { ) -> Vc<Box<dyn ContentSource>> {
let source = NodeRenderContentSource { let source = NodeRenderContentSource {
...@@ -82,16 +82,16 @@ pub fn create_node_rendered_source( ...@@ -82,16 +82,16 @@ pub fn create_node_rendered_source(
/// see [create_node_rendered_source] /// see [create_node_rendered_source]
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct NodeRenderContentSource { pub struct NodeRenderContentSource {
cwd: Vc<FileSystemPath>, cwd: ResolvedVc<FileSystemPath>,
env: Vc<Box<dyn ProcessEnv>>, env: ResolvedVc<Box<dyn ProcessEnv>>,
base_segments: Vec<BaseSegment>, base_segments: Vec<BaseSegment>,
route_type: RouteType, route_type: RouteType,
server_root: Vc<FileSystemPath>, server_root: ResolvedVc<FileSystemPath>,
route_match: Vc<Box<dyn RouteMatcher>>, route_match: ResolvedVc<Box<dyn RouteMatcher>>,
pathname: Vc<RcStr>, pathname: ResolvedVc<RcStr>,
entry: Vc<Box<dyn NodeEntry>>, entry: ResolvedVc<Box<dyn NodeEntry>>,
fallback_page: Vc<DevHtmlAsset>, fallback_page: ResolvedVc<DevHtmlAsset>,
render_data: Vc<JsonValue>, render_data: ResolvedVc<JsonValue>,
debug: bool, debug: bool,
} }
...@@ -99,7 +99,7 @@ pub struct NodeRenderContentSource { ...@@ -99,7 +99,7 @@ pub struct NodeRenderContentSource {
impl NodeRenderContentSource { impl NodeRenderContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn get_pathname(&self) -> Vc<RcStr> { pub fn get_pathname(&self) -> Vc<RcStr> {
self.pathname *self.pathname
} }
} }
...@@ -118,10 +118,10 @@ impl GetContentSource for NodeRenderContentSource { ...@@ -118,10 +118,10 @@ impl GetContentSource for NodeRenderContentSource {
let entry = entry.await?; let entry = entry.await?;
set.extend( set.extend(
external_asset_entrypoints( external_asset_entrypoints(
entry.module, *entry.module,
entry.runtime_entries, *entry.runtime_entries,
entry.chunking_context, *entry.chunking_context,
entry.intermediate_output_path, *entry.intermediate_output_path,
) )
.await? .await?
.iter() .iter()
...@@ -129,7 +129,7 @@ impl GetContentSource for NodeRenderContentSource { ...@@ -129,7 +129,7 @@ impl GetContentSource for NodeRenderContentSource {
) )
} }
Ok(Vc::upcast(AssetGraphContentSource::new_lazy_multiple( Ok(Vc::upcast(AssetGraphContentSource::new_lazy_multiple(
self.server_root, *self.server_root,
Vc::cell(set), Vc::cell(set),
))) )))
} }
...@@ -188,18 +188,18 @@ impl GetContentSourceContent for NodeRenderContentSource { ...@@ -188,18 +188,18 @@ impl GetContentSourceContent for NodeRenderContentSource {
else { else {
return Err(anyhow!("Missing request data")); return Err(anyhow!("Missing request data"));
}; };
let entry = self.entry.entry(data.clone()).await?; let entry = (*self.entry).entry(data.clone()).await?;
let result = render_static( let result = render_static(
self.cwd, *self.cwd,
self.env, *self.env,
self.server_root.join(path.clone()), self.server_root.join(path.clone()),
entry.module, *entry.module,
entry.runtime_entries, *entry.runtime_entries,
self.fallback_page, *self.fallback_page,
entry.chunking_context, *entry.chunking_context,
entry.intermediate_output_path, *entry.intermediate_output_path,
entry.output_root, *entry.output_root,
entry.project_dir, *entry.project_dir,
RenderData { RenderData {
params: params.clone(), params: params.clone(),
method: method.clone(), method: method.clone(),
...@@ -223,9 +223,11 @@ impl GetContentSourceContent for NodeRenderContentSource { ...@@ -223,9 +223,11 @@ impl GetContentSourceContent for NodeRenderContentSource {
content, content,
status_code, status_code,
headers, headers,
} => { } => ContentSourceContent::static_with_headers(
ContentSourceContent::static_with_headers(content.versioned(), status_code, headers) content.versioned(),
} status_code,
*headers,
),
StaticResult::StreamedContent { StaticResult::StreamedContent {
status, status,
headers, headers,
...@@ -260,7 +262,7 @@ impl Introspectable for NodeRenderContentSource { ...@@ -260,7 +262,7 @@ impl Introspectable for NodeRenderContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
fn title(&self) -> Vc<RcStr> { fn title(&self) -> Vc<RcStr> {
self.pathname *self.pathname
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -281,14 +283,14 @@ impl Introspectable for NodeRenderContentSource { ...@@ -281,14 +283,14 @@ impl Introspectable for NodeRenderContentSource {
let entry = entry.await?; let entry = entry.await?;
set.insert(( set.insert((
Vc::cell("module".into()), Vc::cell("module".into()),
IntrospectableModule::new(Vc::upcast(entry.module)), IntrospectableModule::new(Vc::upcast(*entry.module)),
)); ));
set.insert(( set.insert((
Vc::cell("intermediate asset".into()), Vc::cell("intermediate asset".into()),
IntrospectableOutputAsset::new(get_intermediate_asset( IntrospectableOutputAsset::new(get_intermediate_asset(
entry.chunking_context, *entry.chunking_context,
entry.module, *entry.module,
entry.runtime_entries, *entry.runtime_entries,
)), )),
)); ));
} }
......
...@@ -4,7 +4,7 @@ use anyhow::Result; ...@@ -4,7 +4,7 @@ use anyhow::Result;
use mime::APPLICATION_JSON; use mime::APPLICATION_JSON;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
use turbo_tasks::{RcStr, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Vc};
use turbo_tasks_fs::File; use turbo_tasks_fs::File;
use turbopack_core::{ use turbopack_core::{
asset::AssetContent, asset::AssetContent,
...@@ -85,7 +85,7 @@ impl Display for StackFrame<'_> { ...@@ -85,7 +85,7 @@ impl Display for StackFrame<'_> {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Debug)] #[derive(Debug)]
pub struct SourceMapTrace { pub struct SourceMapTrace {
map: Vc<SourceMap>, map: ResolvedVc<SourceMap>,
line: usize, line: usize,
column: usize, column: usize,
name: Option<RcStr>, name: Option<RcStr>,
...@@ -102,7 +102,12 @@ pub enum TraceResult { ...@@ -102,7 +102,12 @@ pub enum TraceResult {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl SourceMapTrace { impl SourceMapTrace {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(map: Vc<SourceMap>, line: usize, column: usize, name: Option<RcStr>) -> Vc<Self> { pub fn new(
map: ResolvedVc<SourceMap>,
line: usize,
column: usize,
name: Option<RcStr>,
) -> Vc<Self> {
SourceMapTrace { SourceMapTrace {
map, map,
line, line,
......
...@@ -57,7 +57,7 @@ pub enum PostCssConfigLocation { ...@@ -57,7 +57,7 @@ pub enum PostCssConfigLocation {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct PostCssTransformOptions { pub struct PostCssTransformOptions {
pub postcss_package: Option<Vc<ImportMapping>>, pub postcss_package: Option<ResolvedVc<ImportMapping>>,
pub config_location: PostCssConfigLocation, pub config_location: PostCssConfigLocation,
pub placeholder_for_future_extensions: u8, pub placeholder_for_future_extensions: u8,
} }
...@@ -93,8 +93,8 @@ fn postcss_configs() -> Vc<Vec<RcStr>> { ...@@ -93,8 +93,8 @@ fn postcss_configs() -> Vc<Vec<RcStr>> {
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct PostCssTransform { pub struct PostCssTransform {
evaluate_context: Vc<Box<dyn AssetContext>>, evaluate_context: ResolvedVc<Box<dyn AssetContext>>,
execution_context: Vc<ExecutionContext>, execution_context: ResolvedVc<ExecutionContext>,
config_location: PostCssConfigLocation, config_location: PostCssConfigLocation,
} }
...@@ -102,8 +102,8 @@ pub struct PostCssTransform { ...@@ -102,8 +102,8 @@ pub struct PostCssTransform {
impl PostCssTransform { impl PostCssTransform {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new( pub fn new(
evaluate_context: Vc<Box<dyn AssetContext>>, evaluate_context: ResolvedVc<Box<dyn AssetContext>>,
execution_context: Vc<ExecutionContext>, execution_context: ResolvedVc<ExecutionContext>,
config_location: PostCssConfigLocation, config_location: PostCssConfigLocation,
) -> Vc<Self> { ) -> Vc<Self> {
PostCssTransform { PostCssTransform {
...@@ -118,7 +118,7 @@ impl PostCssTransform { ...@@ -118,7 +118,7 @@ impl PostCssTransform {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl SourceTransform for PostCssTransform { impl SourceTransform for PostCssTransform {
#[turbo_tasks::function] #[turbo_tasks::function]
fn transform(&self, source: Vc<Box<dyn Source>>) -> Vc<Box<dyn Source>> { fn transform(&self, source: ResolvedVc<Box<dyn Source>>) -> Vc<Box<dyn Source>> {
Vc::upcast( Vc::upcast(
PostCssTransformedAsset { PostCssTransformedAsset {
evaluate_context: self.evaluate_context, evaluate_context: self.evaluate_context,
...@@ -133,10 +133,10 @@ impl SourceTransform for PostCssTransform { ...@@ -133,10 +133,10 @@ impl SourceTransform for PostCssTransform {
#[turbo_tasks::value] #[turbo_tasks::value]
struct PostCssTransformedAsset { struct PostCssTransformedAsset {
evaluate_context: Vc<Box<dyn AssetContext>>, evaluate_context: ResolvedVc<Box<dyn AssetContext>>,
execution_context: Vc<ExecutionContext>, execution_context: ResolvedVc<ExecutionContext>,
config_location: PostCssConfigLocation, config_location: PostCssConfigLocation,
source: Vc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -152,7 +152,7 @@ impl Asset for PostCssTransformedAsset { ...@@ -152,7 +152,7 @@ impl Asset for PostCssTransformedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> { async fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> {
let this = self.await?; let this = self.await?;
Ok(self Ok(*self
.process() .process()
.issue_file_path(this.source.ident().path(), "PostCSS processing") .issue_file_path(this.source.ident().path(), "PostCSS processing")
.await? .await?
...@@ -163,7 +163,7 @@ impl Asset for PostCssTransformedAsset { ...@@ -163,7 +163,7 @@ impl Asset for PostCssTransformedAsset {
#[turbo_tasks::value] #[turbo_tasks::value]
struct ProcessPostCssResult { struct ProcessPostCssResult {
content: Vc<AssetContent>, content: ResolvedVc<AssetContent>,
assets: Vec<ResolvedVc<VirtualSource>>, assets: Vec<ResolvedVc<VirtualSource>>,
} }
...@@ -228,20 +228,25 @@ async fn extra_configs_changed( ...@@ -228,20 +228,25 @@ async fn extra_configs_changed(
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct JsonSource { pub struct JsonSource {
pub path: Vc<FileSystemPath>, pub path: ResolvedVc<FileSystemPath>,
pub key: Vc<Option<RcStr>>, pub key: ResolvedVc<Option<RcStr>>,
pub allow_json5: bool, pub allow_json5: bool,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl JsonSource { impl JsonSource {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(path: Vc<FileSystemPath>, key: Vc<Option<RcStr>>, allow_json5: bool) -> Vc<Self> { pub fn new(
Self::cell(JsonSource { path: ResolvedVc<FileSystemPath>,
key: ResolvedVc<Option<RcStr>>,
allow_json5: bool,
) -> Vc<Self> {
JsonSource {
path, path,
key, key,
allow_json5, allow_json5,
}) }
.cell()
} }
} }
...@@ -420,7 +425,7 @@ async fn find_config_in_location( ...@@ -420,7 +425,7 @@ async fn find_config_in_location(
impl GenerateSourceMap for PostCssTransformedAsset { impl GenerateSourceMap for PostCssTransformedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn generate_source_map(&self) -> Result<Vc<OptionSourceMap>> { async fn generate_source_map(&self) -> Result<Vc<OptionSourceMap>> {
let source = Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(self.source).await?; let source = Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(*self.source).await?;
match source { match source {
Some(source) => Ok(source.generate_source_map()), Some(source) => Ok(source.generate_source_map()),
None => Ok(Vc::cell(None)), None => Ok(Vc::cell(None)),
...@@ -436,7 +441,7 @@ impl PostCssTransformedAsset { ...@@ -436,7 +441,7 @@ impl PostCssTransformedAsset {
project_path, project_path,
chunking_context, chunking_context,
env, env,
} = *self.execution_context.await?; } = &*self.execution_context.await?;
// For this postcss transform, there is no gaurantee that looking up for the // For this postcss transform, there is no gaurantee that looking up for the
// source path will arrives specific project config for the postcss. // source path will arrives specific project config for the postcss.
...@@ -450,10 +455,10 @@ impl PostCssTransformedAsset { ...@@ -450,10 +455,10 @@ impl PostCssTransformedAsset {
// //
// We look for the config in the project path first, then the source path // We look for the config in the project path first, then the source path
let Some(config_path) = let Some(config_path) =
find_config_in_location(project_path, self.config_location, self.source).await? find_config_in_location(**project_path, self.config_location, *self.source).await?
else { else {
return Ok(ProcessPostCssResult { return Ok(ProcessPostCssResult {
content: self.source.content(), content: self.source.content().to_resolved().await?,
assets: Vec::new(), assets: Vec::new(),
} }
.cell()); .cell());
...@@ -465,7 +470,7 @@ impl PostCssTransformedAsset { ...@@ -465,7 +470,7 @@ impl PostCssTransformedAsset {
}; };
let FileContent::Content(content) = &*file.await? else { let FileContent::Content(content) = &*file.await? else {
return Ok(ProcessPostCssResult { return Ok(ProcessPostCssResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).cell(), content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(),
assets: Vec::new(), assets: Vec::new(),
} }
.cell()); .cell());
...@@ -474,10 +479,14 @@ impl PostCssTransformedAsset { ...@@ -474,10 +479,14 @@ impl PostCssTransformedAsset {
let evaluate_context = self.evaluate_context; let evaluate_context = self.evaluate_context;
// This invalidates the transform when the config changes. // This invalidates the transform when the config changes.
let config_changed = config_changed(evaluate_context, config_path); let config_changed = config_changed(*evaluate_context, config_path)
.to_resolved()
let postcss_executor = .await?;
postcss_executor(evaluate_context, project_path, config_path).module();
let postcss_executor = postcss_executor(*evaluate_context, **project_path, config_path)
.module()
.to_resolved()
.await?;
let css_fs_path = self.source.ident().path(); let css_fs_path = self.source.ident().path();
// We need to get a path relative to the project because the postcss loader // We need to get a path relative to the project because the postcss loader
...@@ -494,11 +503,11 @@ impl PostCssTransformedAsset { ...@@ -494,11 +503,11 @@ impl PostCssTransformedAsset {
let config_value = evaluate_webpack_loader(WebpackLoaderContext { let config_value = evaluate_webpack_loader(WebpackLoaderContext {
module_asset: postcss_executor, module_asset: postcss_executor,
cwd: project_path, cwd: *project_path,
env, env: *env,
context_ident_for_issue: self.source.ident(), context_ident_for_issue: self.source.ident().to_resolved().await?,
asset_context: evaluate_context, asset_context: evaluate_context,
chunking_context, chunking_context: *chunking_context,
resolve_options_context: None, resolve_options_context: None,
args: vec![Vc::cell(content.into()), Vc::cell(css_path.into())], args: vec![Vc::cell(content.into()), Vc::cell(css_path.into())],
additional_invalidation: config_changed, additional_invalidation: config_changed,
...@@ -508,7 +517,7 @@ impl PostCssTransformedAsset { ...@@ -508,7 +517,7 @@ impl PostCssTransformedAsset {
let SingleValue::Single(val) = config_value.try_into_single().await? else { let SingleValue::Single(val) = config_value.try_into_single().await? else {
// An error happened, which has already been converted into an issue. // An error happened, which has already been converted into an issue.
return Ok(ProcessPostCssResult { return Ok(ProcessPostCssResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).cell(), content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(),
assets: Vec::new(), assets: Vec::new(),
} }
.cell()); .cell());
...@@ -519,16 +528,17 @@ impl PostCssTransformedAsset { ...@@ -519,16 +528,17 @@ impl PostCssTransformedAsset {
// TODO handle SourceMap // TODO handle SourceMap
let file = File::from(processed_css.css); let file = File::from(processed_css.css);
let assets = emitted_assets_to_virtual_sources(processed_css.assets).await?; let assets = emitted_assets_to_virtual_sources(processed_css.assets).await?;
let content = AssetContent::File(FileContent::Content(file).resolved_cell()).cell(); let content =
AssetContent::File(FileContent::Content(file).resolved_cell()).resolved_cell();
Ok(ProcessPostCssResult { content, assets }.cell()) Ok(ProcessPostCssResult { content, assets }.cell())
} }
} }
#[turbo_tasks::value] #[turbo_tasks::value]
struct PostCssTransformIssue { struct PostCssTransformIssue {
source: Vc<FileSystemPath>, source: ResolvedVc<FileSystemPath>,
description: RcStr, description: RcStr,
severity: Vc<IssueSeverity>, severity: ResolvedVc<IssueSeverity>,
title: RcStr, title: RcStr,
} }
...@@ -536,7 +546,7 @@ struct PostCssTransformIssue { ...@@ -536,7 +546,7 @@ struct PostCssTransformIssue {
impl Issue for PostCssTransformIssue { impl Issue for PostCssTransformIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> { fn file_path(&self) -> Vc<FileSystemPath> {
self.source *self.source
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -551,7 +561,7 @@ impl Issue for PostCssTransformIssue { ...@@ -551,7 +561,7 @@ impl Issue for PostCssTransformIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn severity(&self) -> Vc<IssueSeverity> { fn severity(&self) -> Vc<IssueSeverity> {
self.severity *self.severity
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -410,7 +410,7 @@ impl ModuleOptions { ...@@ -410,7 +410,7 @@ impl ModuleOptions {
.context("execution_context is required for the postcss_transform")?; .context("execution_context is required for the postcss_transform")?;
let import_map = if let Some(postcss_package) = options.postcss_package { let import_map = if let Some(postcss_package) = options.postcss_package {
package_import_map_from_import_mapping("postcss".into(), postcss_package) package_import_map_from_import_mapping("postcss".into(), *postcss_package)
} else { } else {
package_import_map_from_context("postcss".into(), path) package_import_map_from_context("postcss".into(), path)
}; };
......
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