From 24e41327a373e684440782ca892e93833ac7032c Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 13 Dec 2019 17:45:10 +0200 Subject: [PATCH] Provide fake $HOME env to Yarn commands --- src/command-line/install.js | 7 +------ src/command-line/upgrade.js | 2 +- src/command-line/utils.js | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/command-line/install.js b/src/command-line/install.js index b65df299..96b4f45b 100644 --- a/src/command-line/install.js +++ b/src/command-line/install.js @@ -66,12 +66,7 @@ program ); } - return Utils.executeYarnCommand( - "add", - "--production", - "--exact", - `${json.name}@${json.version}` - ) + return Utils.executeYarnCommand("add", "--exact", `${json.name}@${json.version}`) .then(() => { log.info( `${colors.green( diff --git a/src/command-line/upgrade.js b/src/command-line/upgrade.js index 6d5c6121..da9c724f 100644 --- a/src/command-line/upgrade.js +++ b/src/command-line/upgrade.js @@ -18,7 +18,7 @@ program const packagesPath = Helper.getPackagesPath(); const packagesConfig = path.join(packagesPath, "package.json"); const packagesList = JSON.parse(fs.readFileSync(packagesConfig)).dependencies; - const argsList = ["upgrade", "--production", "--latest"]; + const argsList = ["upgrade", "--latest"]; let count = 0; diff --git a/src/command-line/utils.js b/src/command-line/utils.js index 23d8ef9e..ada81bc6 100644 --- a/src/command-line/utils.js +++ b/src/command-line/utils.js @@ -106,14 +106,26 @@ class Utils { "--non-interactive", ]; + const env = { + // We only ever operate in production mode + NODE_ENV: "production", + + // If The Lounge runs from a user that does not have a home directory, + // yarn may fail when it tries to read certain folders, + // we give it an existing folder so the reads do not throw a permission error. + // Yarn uses os.homedir() to figure out the path, which internally reads + // from the $HOME env on unix. On Windows it uses $USERPROFILE, but + // the user folder should always exist on Windows, so we don't set it. + HOME: cachePath, + }; + return new Promise((resolve, reject) => { let success = false; - const add = require("child_process").spawn(process.execPath, [ - yarn, - command, - ...staticParameters, - ...parameters, - ]); + const add = require("child_process").spawn( + process.execPath, + [yarn, command, ...staticParameters, ...parameters], + {env: env} + ); add.stdout.on("data", (data) => { data.toString()