Skip to content

Commit

Permalink
Merge 7fd145a into f869443
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony authored Jan 17, 2023
2 parents f869443 + 7fd145a commit cfe5756
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 6 additions & 4 deletions crates/next-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ pub async fn env_for_js(
} else {
env
};
let env = EmbeddableProcessEnvVc::new(env).into();
let image_config = next_config.image_config().await?;

let next_config = next_config.await?;
let env =
EmbeddableProcessEnvVc::new(CustomProcessEnvVc::new(env, next_config.env()).into()).into();

let image_config = next_config.image_config().await?;
let mut map = indexmap! {
// We need to overload the __NEXT_IMAGE_OPTS to override the default remotePatterns field.
// This allows us to support loading from remote hostnames until we properly support reading
// the next.config.js file.
"__NEXT_IMAGE_OPTS".to_string() => serde_json::to_string(&image_config).unwrap(),
"__NEXT_IMAGE_OPTS".to_string() => serde_json::to_string(&image_config)?,
};

let next_config = next_config.await?;

if next_config.react_strict_mode.unwrap_or(false) {
map.insert("__NEXT_STRICT_MODE".to_string(), "true".to_string());
}
Expand Down
10 changes: 7 additions & 3 deletions crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::Result;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
Expand All @@ -8,6 +6,7 @@ use turbo_tasks::{
trace::TraceRawVcs,
Value,
};
use turbo_tasks_env::EnvMapVc;
use turbopack::{
evaluate_context::node_evaluate_asset_context,
module_options::{
Expand Down Expand Up @@ -44,7 +43,7 @@ pub struct NextConfig {
pub typescript: Option<TypeScriptConfig>,
pub react_strict_mode: Option<bool>,
pub experimental: Option<ExperimentalConfig>,
pub env: Option<HashMap<String, String>>,
pub env: IndexMap<String, String>,
pub compiler: Option<CompilerConfig>,
pub images: ImageConfig,
pub transpile_packages: Option<Vec<String>>,
Expand Down Expand Up @@ -206,6 +205,11 @@ impl NextConfigVc {
))
}

#[turbo_tasks::function]
pub async fn env(self) -> Result<EnvMapVc> {
Ok(EnvMapVc::cell(self.await?.env.clone()))
}

#[turbo_tasks::function]
pub async fn image_config(self) -> Result<ImageConfigVc> {
Ok(self.await?.images.clone().cell())
Expand Down

0 comments on commit cfe5756

Please sign in to comment.