@@ -16,7 +16,7 @@ use notify::event::ModifyKind;
16
16
use notify:: { Config , EventKind , RecommendedWatcher , RecursiveMode , Watcher } ;
17
17
use std:: collections:: HashMap ;
18
18
use std:: convert:: Infallible ;
19
- use std:: path:: { Path , PathBuf } ;
19
+ use std:: path:: PathBuf ;
20
20
use std:: sync:: Arc ;
21
21
use std:: time:: Duration ;
22
22
use tokio:: runtime:: Handle ;
@@ -25,20 +25,21 @@ use tokio::sync::Mutex;
25
25
const LOCAL_REGION : & str = "local" ;
26
26
27
27
fn parse_environment_variables (
28
- root : & Path ,
28
+ path : Option < PathBuf > ,
29
29
env : Option < PathBuf > ,
30
30
) -> Result < HashMap < String , String > > {
31
+ let path = path. unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
31
32
let mut environment_variables = HashMap :: new ( ) ;
32
33
33
- if let Some ( path ) = env {
34
- let envfile = EnvFile :: new ( root . join ( path ) ) ?;
34
+ if let Some ( env ) = env {
35
+ let envfile = EnvFile :: new ( env ) ?;
35
36
36
37
for ( key, value) in envfile. store {
37
38
environment_variables. insert ( key, value) ;
38
39
}
39
40
40
41
println ! ( "{}" , style( "Loaded .env file..." ) . black( ) . bright( ) ) ;
41
- } else if let Ok ( envfile) = EnvFile :: new ( root . join ( ".env" ) ) {
42
+ } else if let Ok ( envfile) = EnvFile :: new ( path . join ( ".env" ) ) {
42
43
for ( key, value) in envfile. store {
43
44
environment_variables. insert ( key, value) ;
44
45
}
@@ -163,7 +164,7 @@ pub async fn dev(
163
164
allow_code_generation : bool ,
164
165
prod : bool ,
165
166
) -> Result < ( ) > {
166
- let ( root, function_config) = resolve_path ( path, client, public_dir) ?;
167
+ let ( root, function_config) = resolve_path ( path. clone ( ) , client, public_dir) ?;
167
168
let ( index, assets) = bundle_function ( & function_config, & root, prod) ?;
168
169
169
170
let index = Arc :: new ( Mutex :: new ( index) ) ;
@@ -183,7 +184,7 @@ pub async fn dev(
183
184
. as_ref ( )
184
185
. map ( |assets| root. join ( assets) ) ;
185
186
186
- let environment_variables = match parse_environment_variables ( & root , env) {
187
+ let environment_variables = match parse_environment_variables ( path , env) {
187
188
Ok ( env) => env,
188
189
Err ( err) => return Err ( anyhow ! ( "Could not load environment variables: {:?}" , err) ) ,
189
190
} ;
0 commit comments