Skip to content

Commit

Permalink
Revert "build(edge): extract buildId into environment (#64521)"
Browse files Browse the repository at this point in the history
This reverts commit ce99c61.
  • Loading branch information
ijjk authored May 6, 2024
1 parent ce99c61 commit d5b18eb
Show file tree
Hide file tree
Showing 36 changed files with 83 additions and 424 deletions.
45 changes: 2 additions & 43 deletions packages/next-swc/crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use napi::{
use next_api::{
entrypoints::Entrypoints,
project::{
DefineEnv, DraftModeOptions, Instrumentation, Middleware, PartialProjectOptions, Project,
ProjectContainer, ProjectOptions,
DefineEnv, Instrumentation, Middleware, PartialProjectOptions, Project, ProjectContainer,
ProjectOptions,
},
route::{Endpoint, Route},
};
Expand Down Expand Up @@ -63,23 +63,6 @@ pub struct NapiEnvVar {
pub value: String,
}

#[napi(object)]
pub struct NapiDraftModeOptions {
pub preview_mode_id: String,
pub preview_mode_encryption_key: String,
pub preview_mode_signing_key: String,
}

impl From<NapiDraftModeOptions> for DraftModeOptions {
fn from(val: NapiDraftModeOptions) -> Self {
DraftModeOptions {
preview_mode_id: val.preview_mode_id,
preview_mode_encryption_key: val.preview_mode_encryption_key,
preview_mode_signing_key: val.preview_mode_signing_key,
}
}
}

#[napi(object)]
pub struct NapiProjectOptions {
/// A root path from which all files must be nested under. Trying to access
Expand Down Expand Up @@ -111,15 +94,6 @@ pub struct NapiProjectOptions {

/// The mode in which Next.js is running.
pub dev: bool,

/// The server actions encryption key.
pub encryption_key: String,

/// The build id.
pub build_id: String,

/// Options for draft mode.
pub preview_props: NapiDraftModeOptions,
}

/// [NapiProjectOptions] with all fields optional.
Expand Down Expand Up @@ -154,15 +128,6 @@ pub struct NapiPartialProjectOptions {

/// The mode in which Next.js is running.
pub dev: Option<bool>,

/// The server actions encryption key.
pub encryption_key: Option<String>,

/// The build id.
pub build_id: Option<String>,

/// Options for draft mode.
pub preview_props: Option<NapiDraftModeOptions>,
}

#[napi(object)]
Expand Down Expand Up @@ -194,9 +159,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
.collect(),
define_env: val.define_env.into(),
dev: val.dev,
encryption_key: val.encryption_key,
build_id: val.build_id,
preview_props: val.preview_props.into(),
}
}
}
Expand All @@ -214,9 +176,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
.map(|env| env.into_iter().map(|var| (var.name, var.value)).collect()),
define_env: val.define_env.map(|env| env.into()),
dev: val.dev,
encryption_key: val.encryption_key,
build_id: val.build_id,
preview_props: val.preview_props.map(|props| props.into()),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,6 @@ impl AppEndpoint {
.clone()
.map(Regions::Multiple),
matchers: vec![matchers],
env: this.app_project.project().edge_env().await?.clone_value(),
..Default::default()
};
let middleware_manifest_v2 = MiddlewaresManifestV2 {
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ impl MiddlewareEndpoint {
page: "/".to_string(),
regions: None,
matchers,
env: this.project.edge_env().await?.clone_value(),
..Default::default()
};
let middleware_manifest_v2 = MiddlewaresManifestV2 {
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,6 @@ impl PageEndpoint {
page: original_name.to_string(),
regions: None,
matchers: vec![matchers],
env: this.pages_project.project().edge_env().await?.clone_value(),
..Default::default()
};
let middleware_manifest_v2 = MiddlewaresManifestV2 {
Expand Down
135 changes: 29 additions & 106 deletions packages/next-swc/crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::MAIN_SEPARATOR;

use anyhow::Result;
use indexmap::{indexmap, map::Entry, IndexMap};
use indexmap::{map::Entry, IndexMap};
use next_core::{
all_assets_from_entries,
app_structure::find_app_dir,
Expand Down Expand Up @@ -68,14 +68,6 @@ use crate::{
versioned_content_map::{OutputAssetsOperation, VersionedContentMap},
};

#[derive(Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct DraftModeOptions {
pub preview_mode_id: String,
pub preview_mode_encryption_key: String,
pub preview_mode_signing_key: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct ProjectOptions {
Expand Down Expand Up @@ -104,15 +96,6 @@ pub struct ProjectOptions {

/// The mode in which Next.js is running.
pub dev: bool,

/// The server actions encryption key.
pub encryption_key: String,

/// The build id.
pub build_id: String,

/// Options for draft mode.
pub preview_props: DraftModeOptions,
}

#[derive(Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, TraceRawVcs)]
Expand Down Expand Up @@ -143,15 +126,6 @@ pub struct PartialProjectOptions {

/// The mode in which Next.js is running.
pub dev: Option<bool>,

/// The server actions encryption key.
pub encryption_key: Option<String>,

/// The build id.
pub build_id: Option<String>,

/// Options for draft mode.
pub preview_props: Option<DraftModeOptions>,
}

#[derive(Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, TraceRawVcs)]
Expand Down Expand Up @@ -192,55 +166,29 @@ impl ProjectContainer {

#[turbo_tasks::function]
pub fn update(&self, options: PartialProjectOptions) -> Vc<()> {
let PartialProjectOptions {
root_path,
project_path,
next_config,
js_config,
env,
define_env,
watch,
dev,
encryption_key,
build_id,
preview_props,
} = options;

let mut new_options = self.options_state.get().clone();

if let Some(root_path) = root_path {
if let Some(root_path) = options.root_path {
new_options.root_path = root_path;
}
if let Some(project_path) = project_path {
if let Some(project_path) = options.project_path {
new_options.project_path = project_path;
}
if let Some(next_config) = next_config {
if let Some(next_config) = options.next_config {
new_options.next_config = next_config;
}
if let Some(js_config) = js_config {
if let Some(js_config) = options.js_config {
new_options.js_config = js_config;
}
if let Some(env) = env {
if let Some(env) = options.env {
new_options.env = env;
}
if let Some(define_env) = define_env {
if let Some(define_env) = options.define_env {
new_options.define_env = define_env;
}
if let Some(watch) = watch {
if let Some(watch) = options.watch {
new_options.watch = watch;
}
if let Some(dev) = dev {
new_options.dev = dev;
}
if let Some(encryption_key) = encryption_key {
new_options.encryption_key = encryption_key;
}
if let Some(build_id) = build_id {
new_options.build_id = build_id;
}
if let Some(preview_props) = preview_props {
new_options.preview_props = preview_props;
}

// TODO: Handle mode switch, should prevent mode being switched.

Expand All @@ -253,36 +201,32 @@ impl ProjectContainer {
pub async fn project(self: Vc<Self>) -> Result<Vc<Project>> {
let this = self.await?;

let env_map: Vc<EnvMap>;
let next_config;
let define_env;
let js_config;
let root_path;
let project_path;
let watch;
let dev;
let encryption_key;
let build_id;
let preview_props;
{
let (env, define_env, next_config, js_config, root_path, project_path, watch, dev) = {
let options = this.options_state.get();
env_map = Vc::cell(options.env.iter().cloned().collect());
define_env = ProjectDefineEnv {
let env: Vc<EnvMap> = Vc::cell(options.env.iter().cloned().collect());
let define_env: Vc<ProjectDefineEnv> = ProjectDefineEnv {
client: Vc::cell(options.define_env.client.iter().cloned().collect()),
edge: Vc::cell(options.define_env.edge.iter().cloned().collect()),
nodejs: Vc::cell(options.define_env.nodejs.iter().cloned().collect()),
}
.cell();
next_config = NextConfig::from_string(Vc::cell(options.next_config.clone()));
js_config = JsConfig::from_string(Vc::cell(options.js_config.clone()));
root_path = options.root_path.clone();
project_path = options.project_path.clone();
watch = options.watch;
dev = options.dev;
encryption_key = options.encryption_key.clone();
build_id = options.build_id.clone();
preview_props = options.preview_props.clone();
}
let next_config = NextConfig::from_string(Vc::cell(options.next_config.clone()));
let js_config = JsConfig::from_string(Vc::cell(options.js_config.clone()));
let root_path = options.root_path.clone();
let project_path = options.project_path.clone();
let watch = options.watch;
let dev = options.dev;
(
env,
define_env,
next_config,
js_config,
root_path,
project_path,
watch,
dev,
)
};

let dist_dir = next_config
.await?
Expand All @@ -297,7 +241,7 @@ impl ProjectContainer {
next_config,
js_config,
dist_dir,
env: Vc::upcast(env_map),
env: Vc::upcast(env),
define_env,
browserslist_query: "last 1 Chrome versions, last 1 Firefox versions, last 1 Safari \
versions, last 1 Edge versions"
Expand All @@ -308,9 +252,6 @@ impl ProjectContainer {
NextMode::Build.cell()
},
versioned_content_map: this.versioned_content_map,
build_id,
encryption_key,
preview_props,
}
.cell())
}
Expand Down Expand Up @@ -382,12 +323,6 @@ pub struct Project {
mode: Vc<NextMode>,

versioned_content_map: Vc<VersionedContentMap>,

build_id: String,

encryption_key: String,

preview_props: DraftModeOptions,
}

#[turbo_tasks::value]
Expand Down Expand Up @@ -610,18 +545,6 @@ impl Project {
))
}

#[turbo_tasks::function]
pub(super) fn edge_env(&self) -> Vc<EnvMap> {
let edge_env = indexmap! {
"__NEXT_BUILD_ID".to_string() => self.build_id.clone(),
"NEXT_SERVER_ACTIONS_ENCRYPTION_KEY".to_string() => self.encryption_key.clone(),
"__NEXT_PREVIEW_MODE_ID".to_string() => self.preview_props.preview_mode_id.clone(),
"__NEXT_PREVIEW_MODE_ENCRYPTION_KEY".to_string() => self.preview_props.preview_mode_encryption_key.clone(),
"__NEXT_PREVIEW_MODE_SIGNING_KEY".to_string() => self.preview_props.preview_mode_signing_key.clone(),
};
Vc::cell(edge_env)
}

#[turbo_tasks::function]
pub(super) async fn client_chunking_context(
self: Vc<Self>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ async fn wrap_edge_page(
let next_config = &*next_config.await?;

// TODO(WEB-1824): add build support
let build_id = "development";
let dev = true;

// TODO(timneutkens): remove this
Expand All @@ -173,6 +174,7 @@ async fn wrap_edge_page(
indexmap! {
"VAR_USERLAND" => INNER.to_string(),
"VAR_PAGE" => page.to_string(),
"VAR_BUILD_ID" => build_id.to_string(),
},
indexmap! {
"sriEnabled" => serde_json::Value::Bool(sri_enabled).to_string(),
Expand Down
3 changes: 1 addition & 2 deletions packages/next-swc/crates/next-core/src/next_manifests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) mod client_reference_manifest;

use std::collections::HashMap;

use indexmap::{IndexMap, IndexSet};
use indexmap::IndexSet;
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, TaskInput};

Expand Down Expand Up @@ -88,7 +88,6 @@ pub struct EdgeFunctionDefinition {
pub assets: Vec<AssetBinding>,
#[serde(skip_serializing_if = "Option::is_none")]
pub regions: Option<Regions>,
pub env: IndexMap<String, String>,
}

#[derive(Serialize, Default, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ async fn wrap_edge_page(
let next_config = &*next_config.await?;

// TODO(WEB-1824): add build support
let build_id = "development";
let dev = true;

let sri_enabled = !dev
Expand All @@ -228,6 +229,7 @@ async fn wrap_edge_page(
indexmap! {
"VAR_USERLAND" => INNER.to_string(),
"VAR_PAGE" => pathname.clone(),
"VAR_BUILD_ID" => build_id.to_string(),
"VAR_MODULE_DOCUMENT" => INNER_DOCUMENT.to_string(),
"VAR_MODULE_APP" => INNER_APP.to_string(),
"VAR_MODULE_GLOBAL_ERROR" => INNER_ERROR.to_string(),
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export function getEdgeServerEntry(opts: {
absoluteDocumentPath: opts.pages['/_document'],
absoluteErrorPath: opts.pages['/_error'],
absolutePagePath: opts.absolutePagePath,
buildId: opts.buildId,
dev: opts.isDev,
isServerComponent: opts.isServerComponent,
page: opts.page,
Expand Down
Loading

0 comments on commit d5b18eb

Please sign in to comment.