File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export interface LoadOptions {
35
35
*
36
36
* @default {"./.env"}
37
37
*/
38
- envPath ?: string | null ;
38
+ envPath ?: string | URL | null ;
39
39
40
40
/**
41
41
* Set to `true` to export all `.env` variables to the current processes
@@ -227,7 +227,7 @@ export async function load(
227
227
}
228
228
229
229
function parseFileSync (
230
- filepath : string ,
230
+ filepath : string | URL ,
231
231
) : Record < string , string > {
232
232
try {
233
233
return parse ( Deno . readTextFileSync ( filepath ) ) ;
@@ -238,7 +238,7 @@ function parseFileSync(
238
238
}
239
239
240
240
async function parseFile (
241
- filepath : string ,
241
+ filepath : string | URL ,
242
242
) : Promise < Record < string , string > > {
243
243
try {
244
244
return parse ( await Deno . readTextFile ( filepath ) ) ;
Original file line number Diff line number Diff line change @@ -29,6 +29,24 @@ Deno.test("load() handles non-existent .env files", async () => {
29
29
assertEquals ( { } , loadSync ( loadOptions ) ) ;
30
30
} ) ;
31
31
32
+ Deno . test ( "load() handles URL as path for .env files" , async ( ) => {
33
+ const conf = loadSync ( {
34
+ envPath : new URL (
35
+ path . toFileUrl ( path . join ( testdataDir , ".env" ) ) ,
36
+ import . meta. url ,
37
+ ) ,
38
+ } ) ;
39
+ assertEquals ( conf . GREETING , "hello world" , "loaded from .env" ) ;
40
+
41
+ const asyncConf = await load ( {
42
+ envPath : new URL (
43
+ path . toFileUrl ( path . join ( testdataDir , ".env" ) ) ,
44
+ import . meta. url ,
45
+ ) ,
46
+ } ) ;
47
+ assertEquals ( asyncConf . GREETING , "hello world" , "loaded from .env" ) ;
48
+ } ) ;
49
+
32
50
Deno . test ( "load() handles comprised .env and .env.defaults" , async ( ) => {
33
51
const conf = loadSync ( testOptions ) ;
34
52
assertEquals ( conf . GREETING , "hello world" , "loaded from .env" ) ;
You can’t perform that action at this time.
0 commit comments