Merge pull request #3578 from thelounge/xpaw/yarn-home

Provide fake $HOME env to Yarn commands
This commit is contained in:
Pavel Djundik 2019-12-14 20:47:09 +02:00 committed by GitHub
commit 059cedcf7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 13 deletions

View File

@ -66,12 +66,7 @@ program
); );
} }
return Utils.executeYarnCommand( return Utils.executeYarnCommand("add", "--exact", `${json.name}@${json.version}`)
"add",
"--production",
"--exact",
`${json.name}@${json.version}`
)
.then(() => { .then(() => {
log.info( log.info(
`${colors.green( `${colors.green(

View File

@ -18,7 +18,7 @@ program
const packagesPath = Helper.getPackagesPath(); const packagesPath = Helper.getPackagesPath();
const packagesConfig = path.join(packagesPath, "package.json"); const packagesConfig = path.join(packagesPath, "package.json");
const packagesList = JSON.parse(fs.readFileSync(packagesConfig)).dependencies; const packagesList = JSON.parse(fs.readFileSync(packagesConfig)).dependencies;
const argsList = ["upgrade", "--production", "--latest"]; const argsList = ["upgrade", "--latest"];
let count = 0; let count = 0;

View File

@ -106,14 +106,26 @@ class Utils {
"--non-interactive", "--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) => { return new Promise((resolve, reject) => {
let success = false; let success = false;
const add = require("child_process").spawn(process.execPath, [ const add = require("child_process").spawn(
yarn, process.execPath,
command, [yarn, command, ...staticParameters, ...parameters],
...staticParameters, {env: env}
...parameters, );
]);
add.stdout.on("data", (data) => { add.stdout.on("data", (data) => {
data.toString() data.toString()