1
1
use std:: path:: MAIN_SEPARATOR ;
2
2
3
3
use anyhow:: Result ;
4
- use indexmap:: { map:: Entry , IndexMap } ;
4
+ use indexmap:: { indexmap , map:: Entry , IndexMap } ;
5
5
use next_core:: {
6
6
all_assets_from_entries,
7
7
app_structure:: find_app_dir,
@@ -68,6 +68,14 @@ use crate::{
68
68
versioned_content_map:: { OutputAssetsOperation , VersionedContentMap } ,
69
69
} ;
70
70
71
+ #[ derive( Debug , Serialize , Deserialize , Clone , TaskInput , PartialEq , Eq , TraceRawVcs ) ]
72
+ #[ serde( rename_all = "camelCase" ) ]
73
+ pub struct DraftModeOptions {
74
+ pub preview_mode_id : String ,
75
+ pub preview_mode_encryption_key : String ,
76
+ pub preview_mode_signing_key : String ,
77
+ }
78
+
71
79
#[ derive( Debug , Serialize , Deserialize , Clone , TaskInput , PartialEq , Eq , TraceRawVcs ) ]
72
80
#[ serde( rename_all = "camelCase" ) ]
73
81
pub struct ProjectOptions {
@@ -96,6 +104,15 @@ pub struct ProjectOptions {
96
104
97
105
/// The mode in which Next.js is running.
98
106
pub dev : bool ,
107
+
108
+ /// The server actions encryption key.
109
+ pub encryption_key : String ,
110
+
111
+ /// The build id.
112
+ pub build_id : String ,
113
+
114
+ /// Options for draft mode.
115
+ pub preview_props : DraftModeOptions ,
99
116
}
100
117
101
118
#[ derive( Debug , Serialize , Deserialize , Clone , TaskInput , PartialEq , Eq , TraceRawVcs ) ]
@@ -126,6 +143,15 @@ pub struct PartialProjectOptions {
126
143
127
144
/// The mode in which Next.js is running.
128
145
pub dev : Option < bool > ,
146
+
147
+ /// The server actions encryption key.
148
+ pub encryption_key : Option < String > ,
149
+
150
+ /// The build id.
151
+ pub build_id : Option < String > ,
152
+
153
+ /// Options for draft mode.
154
+ pub preview_props : Option < DraftModeOptions > ,
129
155
}
130
156
131
157
#[ derive( Debug , Serialize , Deserialize , Clone , TaskInput , PartialEq , Eq , TraceRawVcs ) ]
@@ -166,29 +192,55 @@ impl ProjectContainer {
166
192
167
193
#[ turbo_tasks:: function]
168
194
pub fn update ( & self , options : PartialProjectOptions ) -> Vc < ( ) > {
195
+ let PartialProjectOptions {
196
+ root_path,
197
+ project_path,
198
+ next_config,
199
+ js_config,
200
+ env,
201
+ define_env,
202
+ watch,
203
+ dev,
204
+ encryption_key,
205
+ build_id,
206
+ preview_props,
207
+ } = options;
208
+
169
209
let mut new_options = self . options_state . get ( ) . clone ( ) ;
170
210
171
- if let Some ( root_path) = options . root_path {
211
+ if let Some ( root_path) = root_path {
172
212
new_options. root_path = root_path;
173
213
}
174
- if let Some ( project_path) = options . project_path {
214
+ if let Some ( project_path) = project_path {
175
215
new_options. project_path = project_path;
176
216
}
177
- if let Some ( next_config) = options . next_config {
217
+ if let Some ( next_config) = next_config {
178
218
new_options. next_config = next_config;
179
219
}
180
- if let Some ( js_config) = options . js_config {
220
+ if let Some ( js_config) = js_config {
181
221
new_options. js_config = js_config;
182
222
}
183
- if let Some ( env) = options . env {
223
+ if let Some ( env) = env {
184
224
new_options. env = env;
185
225
}
186
- if let Some ( define_env) = options . define_env {
226
+ if let Some ( define_env) = define_env {
187
227
new_options. define_env = define_env;
188
228
}
189
- if let Some ( watch) = options . watch {
229
+ if let Some ( watch) = watch {
190
230
new_options. watch = watch;
191
231
}
232
+ if let Some ( dev) = dev {
233
+ new_options. dev = dev;
234
+ }
235
+ if let Some ( encryption_key) = encryption_key {
236
+ new_options. encryption_key = encryption_key;
237
+ }
238
+ if let Some ( build_id) = build_id {
239
+ new_options. build_id = build_id;
240
+ }
241
+ if let Some ( preview_props) = preview_props {
242
+ new_options. preview_props = preview_props;
243
+ }
192
244
193
245
// TODO: Handle mode switch, should prevent mode being switched.
194
246
@@ -201,32 +253,36 @@ impl ProjectContainer {
201
253
pub async fn project ( self : Vc < Self > ) -> Result < Vc < Project > > {
202
254
let this = self . await ?;
203
255
204
- let ( env, define_env, next_config, js_config, root_path, project_path, watch, dev) = {
256
+ let env_map: Vc < EnvMap > ;
257
+ let next_config;
258
+ let define_env;
259
+ let js_config;
260
+ let root_path;
261
+ let project_path;
262
+ let watch;
263
+ let dev;
264
+ let encryption_key;
265
+ let build_id;
266
+ let preview_props;
267
+ {
205
268
let options = this. options_state . get ( ) ;
206
- let env : Vc < EnvMap > = Vc :: cell ( options. env . iter ( ) . cloned ( ) . collect ( ) ) ;
207
- let define_env: Vc < ProjectDefineEnv > = ProjectDefineEnv {
269
+ env_map = Vc :: cell ( options. env . iter ( ) . cloned ( ) . collect ( ) ) ;
270
+ define_env = ProjectDefineEnv {
208
271
client : Vc :: cell ( options. define_env . client . iter ( ) . cloned ( ) . collect ( ) ) ,
209
272
edge : Vc :: cell ( options. define_env . edge . iter ( ) . cloned ( ) . collect ( ) ) ,
210
273
nodejs : Vc :: cell ( options. define_env . nodejs . iter ( ) . cloned ( ) . collect ( ) ) ,
211
274
}
212
275
. cell ( ) ;
213
- let next_config = NextConfig :: from_string ( Vc :: cell ( options. next_config . clone ( ) ) ) ;
214
- let js_config = JsConfig :: from_string ( Vc :: cell ( options. js_config . clone ( ) ) ) ;
215
- let root_path = options. root_path . clone ( ) ;
216
- let project_path = options. project_path . clone ( ) ;
217
- let watch = options. watch ;
218
- let dev = options. dev ;
219
- (
220
- env,
221
- define_env,
222
- next_config,
223
- js_config,
224
- root_path,
225
- project_path,
226
- watch,
227
- dev,
228
- )
229
- } ;
276
+ next_config = NextConfig :: from_string ( Vc :: cell ( options. next_config . clone ( ) ) ) ;
277
+ js_config = JsConfig :: from_string ( Vc :: cell ( options. js_config . clone ( ) ) ) ;
278
+ root_path = options. root_path . clone ( ) ;
279
+ project_path = options. project_path . clone ( ) ;
280
+ watch = options. watch ;
281
+ dev = options. dev ;
282
+ encryption_key = options. encryption_key . clone ( ) ;
283
+ build_id = options. build_id . clone ( ) ;
284
+ preview_props = options. preview_props . clone ( ) ;
285
+ }
230
286
231
287
let dist_dir = next_config
232
288
. await ?
@@ -241,7 +297,7 @@ impl ProjectContainer {
241
297
next_config,
242
298
js_config,
243
299
dist_dir,
244
- env : Vc :: upcast ( env ) ,
300
+ env : Vc :: upcast ( env_map ) ,
245
301
define_env,
246
302
browserslist_query : "last 1 Chrome versions, last 1 Firefox versions, last 1 Safari \
247
303
versions, last 1 Edge versions"
@@ -252,6 +308,9 @@ impl ProjectContainer {
252
308
NextMode :: Build . cell ( )
253
309
} ,
254
310
versioned_content_map : this. versioned_content_map ,
311
+ build_id,
312
+ encryption_key,
313
+ preview_props,
255
314
}
256
315
. cell ( ) )
257
316
}
@@ -323,6 +382,12 @@ pub struct Project {
323
382
mode : Vc < NextMode > ,
324
383
325
384
versioned_content_map : Vc < VersionedContentMap > ,
385
+
386
+ build_id : String ,
387
+
388
+ encryption_key : String ,
389
+
390
+ preview_props : DraftModeOptions ,
326
391
}
327
392
328
393
#[ turbo_tasks:: value]
@@ -545,6 +610,18 @@ impl Project {
545
610
) )
546
611
}
547
612
613
+ #[ turbo_tasks:: function]
614
+ pub ( super ) fn edge_env ( & self ) -> Vc < EnvMap > {
615
+ let edge_env = indexmap ! {
616
+ "__NEXT_BUILD_ID" . to_string( ) => self . build_id. clone( ) ,
617
+ "NEXT_SERVER_ACTIONS_ENCRYPTION_KEY" . to_string( ) => self . encryption_key. clone( ) ,
618
+ "__NEXT_PREVIEW_MODE_ID" . to_string( ) => self . preview_props. preview_mode_id. clone( ) ,
619
+ "__NEXT_PREVIEW_MODE_ENCRYPTION_KEY" . to_string( ) => self . preview_props. preview_mode_encryption_key. clone( ) ,
620
+ "__NEXT_PREVIEW_MODE_SIGNING_KEY" . to_string( ) => self . preview_props. preview_mode_signing_key. clone( ) ,
621
+ } ;
622
+ Vc :: cell ( edge_env)
623
+ }
624
+
548
625
#[ turbo_tasks:: function]
549
626
pub ( super ) async fn client_chunking_context (
550
627
self : Vc < Self > ,
0 commit comments