From 7b49fa08e1a63a0d6f5916e34c2b5d852e4c3e5e Mon Sep 17 00:00:00 2001 From: Yazalde Filimone Date: Mon, 14 Nov 2022 13:59:51 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20prevented=20.env=20values=20=E2=80=8B?= =?UTF-8?q?=E2=80=8Bfrom=20overwriting=20existing=20env=20values=20?= =?UTF-8?q?=E2=80=8B=E2=80=8Bwhen=20using=20--watch=20#558=20(#564)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- lib/watch/index.js | 3 +-- test/start.test.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/watch/index.js b/lib/watch/index.js index 81de0b2f..12adee00 100644 --- a/lib/watch/index.js +++ b/lib/watch/index.js @@ -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(), diff --git a/test/start.test.js b/test/start.test.js index 59299776..0994c167 100644 --- a/test/start.test.js +++ b/test/start.test.js @@ -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() })