Skip to content

Commit d7aeaec

Browse files
committed
fix: serve command to respect the ENV_PATH environment variable
We are now using the same files loader as the application within serve and test commands
1 parent e01642f commit d7aeaec

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/EnvParser/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,24 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import { join } from 'path'
11-
import { readFile } from 'fs-extra'
12-
import { EnvParser as Parser } from '@adonisjs/env'
10+
import { EnvParser as Parser, envLoader } from '@adonisjs/env'
1311

1412
/**
1513
* Parses the env file inside the project root.
1614
*/
1715
export class EnvParser {
1816
private envContents: any = {}
1917

20-
private parser = new Parser(false)
21-
22-
constructor(private envFileName: string = '.env') {}
18+
constructor() {}
2319

2420
/**
2521
* Parse .env file contents
2622
*/
2723
public async parse(rootDir: string) {
28-
try {
29-
this.envContents = this.parser.parse(await readFile(join(rootDir, this.envFileName), 'utf-8'))
30-
} catch {}
24+
const { envContents, testEnvContent } = envLoader(rootDir)
25+
const envVars = new Parser(true).parse(envContents)
26+
const testEnvVars = new Parser(true).parse(testEnvContent)
27+
this.envContents = { ...envVars, ...testEnvVars }
3128
}
3229

3330
/**

src/Test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class TestsServer {
129129
* for the HTTP server
130130
*/
131131
private async getEnvironmentVariables() {
132-
const envParser = new EnvParser('.env.test')
132+
const envParser = new EnvParser()
133133
await envParser.parse(this.appRoot)
134134

135135
const envOptions = envParser.asEnvObject(['PORT', 'TZ', 'HOST'])

0 commit comments

Comments
 (0)