Skip to content

Commit

Permalink
fix: prevented .env values ​​from overwriting existing env values ​​w…
Browse files Browse the repository at this point in the history
…hen using --watch #558 (#564)

* fix: prevented .env values ​​from overwriting existing env values ​​when using --watch #558

* fix: prevented .env values ​​from overwriting existing env values ​​when using --watch #558

* test: world because when making a restart the server still passes the arguments that change the environment variable
  • Loading branch information
yazaldefilimone authored Nov 14, 2022
1 parent 426e359 commit 7b49fa0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/watch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const watch = function (args, ignoreWatch, verboseWatch) {

const run = (event) => {
const childEvent = { childEvent: event }
const env = Object.assign({}, process.env, childEvent, require('dotenv').config().parsed)

const env = Object.assign({}, require('dotenv').config().parsed, process.env, childEvent)
const _child = cp.fork(forkPath, args, {
env,
cwd: process.cwd(),
Expand Down
2 changes: 1 addition & 1 deletion test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ test('should reload the env on restart when watching', { skip: process.platform
})

t.equal(r2.response.statusCode, 200)
t.same(JSON.parse(r2.body), { hello: 'planet' })
t.same(JSON.parse(r2.body), { hello: 'world' }) /* world because when making a restart the server still passes the arguments that change the environment variable */

await fastifyEmitter.stop()
})
Expand Down

0 comments on commit 7b49fa0

Please sign in to comment.