Skip to content
Open
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion lib/watch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path')
const cp = require('child_process')
const chalk = require('chalk')
const { readFileSync, existsSync } = require('fs')
const { arrayToRegExp, logWatchVerbose } = require('./utils')
const { GRACEFUL_SHUT } = require('./constants.js')

Expand Down Expand Up @@ -39,7 +40,15 @@ const watch = function (args, ignoreWatch, verboseWatch) {

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

// in order to not override existing env vars, we have to load and parse
// dotenv without modifying process.env
let dotenvParsed = {}
const dotenvPath = path.resolve(process.cwd(), '.env')
if (existsSync(dotenvPath)) {
dotenvParsed = require('dotenv').parse(readFileSync(dotenvPath, { encoding: 'utf-8' }))
}
const env = Object.assign({}, process.env, childEvent, dotenvParsed)

const _child = cp.fork(forkPath, args, {
env,
Expand Down