diff --git a/docs/shared/reference/environment-variables.md b/docs/shared/reference/environment-variables.md index d1dc04c61f65e..6c17f2a10b486 100644 --- a/docs/shared/reference/environment-variables.md +++ b/docs/shared/reference/environment-variables.md @@ -30,6 +30,7 @@ The following environment variables are ones that you can set to change the beha | NX_SKIP_LOG_GROUPING | boolean | If set to `true`, Nx will not group command's logs on CI. | | NX_MIGRATE_CLI_VERSION | string | The version of Nx to use for running the `nx migrate` command. If not set, it defaults to `latest`. | | NX_LOAD_DOT_ENV_FILES | boolean | If set to 'false', Nx will not load any environment files (e.g. `.local.env`, `.env.local`) | +| NX_NATIVE_FILE_CACHE_DIRECTORY | string | The cache for native `.node` files is stored under a global temp directory by default. Set this variable to use a different directory. This is interpreted as an absolute path. | Nx will set the following environment variables so they can be accessible within the process even outside of executors and generators. diff --git a/packages/nx/src/native/native-file-cache-location.ts b/packages/nx/src/native/native-file-cache-location.ts index 13f1e532e0bac..d65c1bcd9d7cf 100644 --- a/packages/nx/src/native/native-file-cache-location.ts +++ b/packages/nx/src/native/native-file-cache-location.ts @@ -1,10 +1,20 @@ -import { tmpdir } from 'os'; +import { tmpdir, userInfo } from 'os'; import { join } from 'path'; import { createHash } from 'crypto'; import { workspaceRoot } from '../utils/workspace-root'; export const nativeFileCacheLocation = join( - tmpdir(), - 'nx-native-file-cache', - createHash('sha256').update(workspaceRoot).digest('hex') + getNativeFileCacheBaseFolder(), + createHash('sha256') + .update(workspaceRoot) + .update(userInfo().username) + .digest('hex') ); + +function getNativeFileCacheBaseFolder() { + if (process.env.NX_NATIVE_FILE_CACHE_DIRECTORY) { + return process.env.NX_NATIVE_FILE_CACHE_DIRECTORY; + } else { + return join(tmpdir(), 'nx-native-file-cache'); + } +}