Skip to content

Commit

Permalink
feat: avoid hardcoded HOME for spawn-wrap working dir
Browse files Browse the repository at this point in the history
By default, spawn-wrap writes temporary files to HOME.
It used to be /tmp, but it changed that to HOME to support
environments that have 'noexec' flags set on their tmpfs mount.
Ref istanbuljs/spawn-wrap#3.

The problem with this is that nyc now no longer works in environments
without a (writable) home directory (e.g. the 'nobody' user on
Linux).

While it is fine to fallback to HOME, it should write elsewhere
if that is unavailable, and ideally in a way that doesn't require
every sysadmin or end-user to hardcode some environment variable
in their package.json specifically for nyc or spawn-wrap.

A common way to communicate this intent is with the XDG_CACHE_HOME
environment variable.

Fixes istanbuljs#951.
  • Loading branch information
Krinkle committed Jan 3, 2019
1 parent 409a2f5 commit 2df1f35
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bin/nyc.js
Expand Up @@ -45,7 +45,10 @@ if ([
NYC_CONFIG: JSON.stringify(argv),
NYC_CWD: process.cwd(),
NYC_ROOT_ID: nyc.rootId,
NYC_INSTRUMENTER: argv.instrumenter
NYC_INSTRUMENTER: argv.instrumenter,
// Support running nyc as a user without HOME (e.g. linux 'nobody'),
// https://github.com/istanbuljs/nyc/issues/951
SPAWN_WRAP_SHIM_ROOT: process.env.XDG_CACHE_HOME || require('os').homedir()
}

if (argv['babel-cache'] === false) {
Expand Down

0 comments on commit 2df1f35

Please sign in to comment.