From eaa0287238df9a35a4d6abada7abd7ccb6039c1c Mon Sep 17 00:00:00 2001 From: Shihab Uddin Date: Wed, 18 Aug 2021 23:56:13 +0200 Subject: [PATCH] fix(core): always use environment variable for cache directory (#6746) In 6c16ee0feead3f01c575af2b998fe614c207ac96 the environment variable was used while reading from `nx.json`. But in `packages/workspace/src/tasks-runner/cache.ts` the `cacheDirectory` is used without using `readCacheDirectoryProperty`. Now we check the environment variable in `cacheDirectory`, so that the environment variable is always used. ISSUES CLOSED: #6629 --- packages/workspace/src/utilities/cache-directory.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/workspace/src/utilities/cache-directory.ts b/packages/workspace/src/utilities/cache-directory.ts index b576a7139b..fb7438aec9 100644 --- a/packages/workspace/src/utilities/cache-directory.ts +++ b/packages/workspace/src/utilities/cache-directory.ts @@ -2,10 +2,6 @@ import { join } from 'path'; import { readJsonFile } from './fileutils'; export function readCacheDirectoryProperty(root: string) { - const cacheDir = process.env.NX_CACHE_DIRECTORY; - if (cacheDir) { - return cacheDir; - } try { const nxJson = readJsonFile(join(root, 'nx.json')); return nxJson.tasksRunnerOptions.default.options.cacheDirectory; @@ -15,6 +11,10 @@ export function readCacheDirectoryProperty(root: string) { } export function cacheDirectory(root: string, cacheDirectory: string) { + const cacheDirFromEnv = process.env.NX_CACHE_DIRECTORY; + if (cacheDirFromEnv) { + cacheDirectory = cacheDirFromEnv; + } if (cacheDirectory) { if (cacheDirectory.startsWith('./')) { return join(root, cacheDirectory);