@@ -7,7 +7,7 @@ use napi::{
7
7
JsFunction , Status ,
8
8
} ;
9
9
use next_api:: {
10
- project:: { Middleware , ProjectContainer , ProjectOptions } ,
10
+ project:: { DefineEnv , Middleware , PartialProjectOptions , ProjectContainer , ProjectOptions } ,
11
11
route:: { Endpoint , Route } ,
12
12
} ;
13
13
use next_core:: tracing_presets:: {
@@ -44,6 +44,7 @@ use super::{
44
44
use crate :: register;
45
45
46
46
#[ napi( object) ]
47
+ #[ derive( Clone , Debug ) ]
47
48
pub struct NapiEnvVar {
48
49
pub name : String ,
49
50
pub value : String ,
@@ -74,10 +75,56 @@ pub struct NapiProjectOptions {
74
75
/// A map of environment variables to use when compiling code.
75
76
pub env : Vec < NapiEnvVar > ,
76
77
78
+ /// A map of environment variables which should get injected at compile
79
+ /// time.
80
+ pub define_env : NapiDefineEnv ,
81
+
77
82
/// The address of the dev server.
78
83
pub server_addr : String ,
79
84
}
80
85
86
+ /// [NapiProjectOptions] with all fields optional.
87
+ #[ napi( object) ]
88
+ pub struct NapiPartialProjectOptions {
89
+ /// A root path from which all files must be nested under. Trying to access
90
+ /// a file outside this root will fail. Think of this as a chroot.
91
+ pub root_path : Option < String > ,
92
+
93
+ /// A path inside the root_path which contains the app/pages directories.
94
+ pub project_path : Option < String > ,
95
+
96
+ /// next.config's distDir. Project initialization occurs eariler than
97
+ /// deserializing next.config, so passing it as separate option.
98
+ pub dist_dir : Option < Option < String > > ,
99
+
100
+ /// Whether to watch he filesystem for file changes.
101
+ pub watch : Option < bool > ,
102
+
103
+ /// The contents of next.config.js, serialized to JSON.
104
+ pub next_config : Option < String > ,
105
+
106
+ /// The contents of ts/config read by load-jsconfig, serialized to JSON.
107
+ pub js_config : Option < String > ,
108
+
109
+ /// A map of environment variables to use when compiling code.
110
+ pub env : Option < Vec < NapiEnvVar > > ,
111
+
112
+ /// A map of environment variables which should get injected at compile
113
+ /// time.
114
+ pub define_env : Option < NapiDefineEnv > ,
115
+
116
+ /// The address of the dev server.
117
+ pub server_addr : Option < String > ,
118
+ }
119
+
120
+ #[ napi( object) ]
121
+ #[ derive( Clone , Debug ) ]
122
+ pub struct NapiDefineEnv {
123
+ pub client : Vec < NapiEnvVar > ,
124
+ pub edge : Vec < NapiEnvVar > ,
125
+ pub nodejs : Vec < NapiEnvVar > ,
126
+ }
127
+
81
128
#[ napi( object) ]
82
129
pub struct NapiTurboEngineOptions {
83
130
/// An upper bound of memory that turbopack will attempt to stay under.
@@ -95,13 +142,53 @@ impl From<NapiProjectOptions> for ProjectOptions {
95
142
env : val
96
143
. env
97
144
. into_iter ( )
98
- . map ( |NapiEnvVar { name , value } | ( name, value) )
145
+ . map ( |var | ( var . name , var . value ) )
99
146
. collect ( ) ,
147
+ define_env : val. define_env . into ( ) ,
148
+ server_addr : val. server_addr ,
149
+ }
150
+ }
151
+ }
152
+
153
+ impl From < NapiPartialProjectOptions > for PartialProjectOptions {
154
+ fn from ( val : NapiPartialProjectOptions ) -> Self {
155
+ PartialProjectOptions {
156
+ root_path : val. root_path ,
157
+ project_path : val. project_path ,
158
+ watch : val. watch ,
159
+ next_config : val. next_config ,
160
+ js_config : val. js_config ,
161
+ env : val
162
+ . env
163
+ . map ( |env| env. into_iter ( ) . map ( |var| ( var. name , var. value ) ) . collect ( ) ) ,
164
+ define_env : val. define_env . map ( |env| env. into ( ) ) ,
100
165
server_addr : val. server_addr ,
101
166
}
102
167
}
103
168
}
104
169
170
+ impl From < NapiDefineEnv > for DefineEnv {
171
+ fn from ( val : NapiDefineEnv ) -> Self {
172
+ DefineEnv {
173
+ client : val
174
+ . client
175
+ . into_iter ( )
176
+ . map ( |var| ( var. name , var. value ) )
177
+ . collect ( ) ,
178
+ edge : val
179
+ . edge
180
+ . into_iter ( )
181
+ . map ( |var| ( var. name , var. value ) )
182
+ . collect ( ) ,
183
+ nodejs : val
184
+ . nodejs
185
+ . into_iter ( )
186
+ . map ( |var| ( var. name , var. value ) )
187
+ . collect ( ) ,
188
+ }
189
+ }
190
+ }
191
+
105
192
pub struct ProjectInstance {
106
193
turbo_tasks : Arc < TurboTasks < MemoryBackend > > ,
107
194
container : Vc < ProjectContainer > ,
@@ -190,7 +277,7 @@ pub async fn project_new(
190
277
#[ napi( ts_return_type = "{ __napiType: \" Project\" }" ) ]
191
278
pub async fn project_update (
192
279
#[ napi( ts_arg_type = "{ __napiType: \" Project\" }" ) ] project : External < ProjectInstance > ,
193
- options : NapiProjectOptions ,
280
+ options : NapiPartialProjectOptions ,
194
281
) -> napi:: Result < ( ) > {
195
282
let turbo_tasks = project. turbo_tasks . clone ( ) ;
196
283
let options = options. into ( ) ;
0 commit comments