Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion turbopack/crates/turbopack-node/src/transforms/postcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fn postcss_configs() -> Vc<Vec<RcStr>> {
#[turbo_tasks::value]
pub struct PostCssTransform {
evaluate_context: ResolvedVc<Box<dyn AssetContext>>,
config_tracing_context: ResolvedVc<Box<dyn AssetContext>>,
execution_context: ResolvedVc<ExecutionContext>,
config_location: PostCssConfigLocation,
source_maps: bool,
Expand All @@ -113,12 +114,14 @@ impl PostCssTransform {
#[turbo_tasks::function]
pub fn new(
evaluate_context: ResolvedVc<Box<dyn AssetContext>>,
config_tracing_context: ResolvedVc<Box<dyn AssetContext>>,
execution_context: ResolvedVc<ExecutionContext>,
config_location: PostCssConfigLocation,
source_maps: bool,
) -> Vc<Self> {
PostCssTransform {
evaluate_context,
config_tracing_context,
execution_context,
config_location,
source_maps,
Expand All @@ -134,6 +137,7 @@ impl SourceTransform for PostCssTransform {
Vc::upcast(
PostCssTransformedAsset {
evaluate_context: self.evaluate_context,
config_tracing_context: self.config_tracing_context,
execution_context: self.execution_context,
config_location: self.config_location,
source,
Expand All @@ -147,6 +151,7 @@ impl SourceTransform for PostCssTransform {
#[turbo_tasks::value]
struct PostCssTransformedAsset {
evaluate_context: ResolvedVc<Box<dyn AssetContext>>,
config_tracing_context: ResolvedVc<Box<dyn AssetContext>>,
execution_context: ResolvedVc<ExecutionContext>,
config_location: PostCssConfigLocation,
source: ResolvedVc<Box<dyn Source>>,
Expand Down Expand Up @@ -483,7 +488,7 @@ impl PostCssTransformedAsset {
let source_map = self.source_map;

// This invalidates the transform when the config changes.
let config_changed = config_changed(*evaluate_context, config_path.clone())
let config_changed = config_changed(*self.config_tracing_context, config_path.clone())
.to_resolved()
.await?;

Expand Down
28 changes: 27 additions & 1 deletion turbopack/crates/turbopack/src/evaluate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use turbopack_node::execution_context::ExecutionContext;
use turbopack_resolve::resolve_options_context::ResolveOptionsContext;

use crate::{
ModuleAssetContext,
ModuleAssetContext, externals_tracing_module_context,
module_options::{EcmascriptOptionsContext, ModuleOptionsContext, TypescriptTransformOptions},
transition::TransitionOptions,
};
Expand Down Expand Up @@ -115,3 +115,29 @@ pub async fn node_evaluate_asset_context(
layer,
)))
}

#[turbo_tasks::function]
pub async fn config_tracing_module_context(
execution_context: Vc<ExecutionContext>,
) -> Result<Vc<Box<dyn AssetContext>>> {
let node_env: RcStr =
if let Some(node_env) = &*execution_context.env().read(rcstr!("NODE_ENV")).await? {
node_env.clone()
} else {
rcstr!("development")
};
Comment on lines +123 to +128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good candidate for a helper function, because node_evaluate_asset_context​ does exactly the same thing.


Ok(Vc::upcast(externals_tracing_module_context(
CompileTimeInfo::builder(node_build_environment().to_resolved().await?)
.defines(
compile_time_defines!(
process.turbopack = true,
process.env.NODE_ENV = node_env.into_owned(),
process.env.TURBOPACK = true
Comment on lines +134 to +136
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
.resolved_cell(),
)
.cell()
.await?,
)))
}
4 changes: 3 additions & 1 deletion turbopack/crates/turbopack/src/module_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use turbopack_node::{
use turbopack_wasm::source::WebAssemblySourceType;

use crate::{
evaluate_context::node_evaluate_asset_context, resolve_options_context::ResolveOptionsContext,
evaluate_context::{config_tracing_module_context, node_evaluate_asset_context},
resolve_options_context::ResolveOptionsContext,
};

#[turbo_tasks::function]
Expand Down Expand Up @@ -695,6 +696,7 @@ impl ModuleOptions {
Layer::new(rcstr!("postcss")),
true,
),
config_tracing_module_context(*execution_context),
*execution_context,
options.config_location,
matches!(css_source_maps, SourceMapsType::Full),
Expand Down
Loading