Skip to content

Commit

Permalink
Added protection against non-writable process.env environments e.g. i…
Browse files Browse the repository at this point in the history
…nside Webpack bundles
  • Loading branch information
swernerx committed Apr 5, 2019
1 parent 5d54e31 commit ac015f6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ dotenvFiles.forEach((dotenvFile) => {
})

if (process.env.APP_ROOT == null) {
process.env.APP_ROOT = appRoot.get()
const detectedRoot = appRoot.get()
try {
process.env.APP_ROOT = detectedRoot
} catch (error) {
throw new Error(
"Universal-DotEnv requires a writable process.env! Please make sure that this code is not transpiled with Webpack."
)
}
}

if (process.env.APP_SOURCE == null) {
const sourceFolder = path.join(process.env.APP_ROOT, "src")
process.env.APP_SOURCE = fs.existsSync(sourceFolder) ? sourceFolder : process.env.APP_ROOT
process.env.APP_SOURCE = fs.existsSync(sourceFolder) ?
sourceFolder :
process.env.APP_ROOT
}

// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
Expand Down

0 comments on commit ac015f6

Please sign in to comment.