Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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