Skip to content

Commit

Permalink
fix: hot fix for gatsby develop when HOME is not set (#21914)
Browse files Browse the repository at this point in the history
* fix: hot fix for `gatsby develop` when HOME is not set

* use actual (temporary) directory
  • Loading branch information
pieh committed Mar 2, 2020
1 parent 0039221 commit b6de2b9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/gatsby/src/utils/get-ssl-cert.js
@@ -1,7 +1,7 @@
const certificateFor = require(`devcert`).certificateFor
const report = require(`gatsby-cli/lib/reporter`)
const fs = require(`fs`)
const path = require(`path`)
const os = require(`os`)

const absoluteOrDirectory = (directory, filePath) => {
// Support absolute paths
Expand Down Expand Up @@ -35,6 +35,18 @@ module.exports = async ({ name, certFile, keyFile, directory }) => {

report.info(`setting up automatic SSL certificate (may require sudo)\n`)
try {
if ([`linux`, `darwin`].includes(os.platform()) && !process.env.HOME) {
// this is a total hack to ensure process.env.HOME is set on linux and mac
// devcert creates config path at import time (hence we import devcert after setting dummy value):
// - https://github.com/davewasmer/devcert/blob/2b1b8d40eda251616bf74fd69f00ae8222ca1171/src/constants.ts#L15
// - https://github.com/LinusU/node-application-config-path/blob/ae49ff6748b68b29ec76c00ce4a28ba8e9161d9b/index.js#L13
// if HOME is not set, we will get:
// "The "path" argument must be of type s tring. Received type undefined"
// fatal error. This still likely will result in fatal error, but at least it's not on import time
const mkdtemp = fs.mkdtempSync(path.join(os.tmpdir(), `home-`))
process.env.HOME = mkdtemp
}
const certificateFor = require(`devcert`).certificateFor
return await certificateFor(name, {
installCertutil: true,
})
Expand Down

0 comments on commit b6de2b9

Please sign in to comment.