Skip to content

Commit b6de2b9

Browse files
authoredMar 2, 2020
fix: hot fix for gatsby develop when HOME is not set (#21914)
* fix: hot fix for `gatsby develop` when HOME is not set * use actual (temporary) directory
1 parent 0039221 commit b6de2b9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

‎packages/gatsby/src/utils/get-ssl-cert.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const certificateFor = require(`devcert`).certificateFor
21
const report = require(`gatsby-cli/lib/reporter`)
32
const fs = require(`fs`)
43
const path = require(`path`)
4+
const os = require(`os`)
55

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.