diff --git a/lib/manager/gomod/artifacts.ts b/lib/manager/gomod/artifacts.ts index 899627b176f07f..2d61d59b6fa07d 100644 --- a/lib/manager/gomod/artifacts.ts +++ b/lib/manager/gomod/artifacts.ts @@ -1,11 +1,10 @@ -import { ensureDir } from 'fs-extra'; import { quote } from 'shlex'; import { dirname, join } from 'upath'; import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; import { logger } from '../../logger'; import { ExecOptions, exec } from '../../util/exec'; import { BinarySource } from '../../util/exec/common'; -import { readLocalFile, writeLocalFile } from '../../util/fs'; +import { ensureCacheDir, readLocalFile, writeLocalFile } from '../../util/fs'; import { getRepoStatus } from '../../util/git'; import { find } from '../../util/host-rules'; import { UpdateArtifact, UpdateArtifactsResult } from '../common'; @@ -36,8 +35,7 @@ export async function updateArtifacts({ }: UpdateArtifact): Promise { logger.debug(`gomod.updateArtifacts(${goModFileName})`); - const goPath = process.env.GOPATH || join(config.cacheDir, './others/go'); - await ensureDir(goPath); + const goPath = await ensureCacheDir('./others/go', 'GOPATH'); logger.debug(`Using GOPATH: ${goPath}`); const sumFileName = goModFileName.replace(/\.mod$/, '.sum'); diff --git a/lib/manager/pipenv/artifacts.ts b/lib/manager/pipenv/artifacts.ts index 89e098f0f311e2..70c5997f5c5be6 100644 --- a/lib/manager/pipenv/artifacts.ts +++ b/lib/manager/pipenv/artifacts.ts @@ -1,8 +1,11 @@ -import { ensureDir } from 'fs-extra'; -import { join } from 'upath'; import { logger } from '../../logger'; import { ExecOptions, exec } from '../../util/exec'; -import { deleteLocalFile, readLocalFile, writeLocalFile } from '../../util/fs'; +import { + deleteLocalFile, + ensureCacheDir, + readLocalFile, + writeLocalFile, +} from '../../util/fs'; import { getRepoStatus } from '../../util/git'; import { UpdateArtifact, @@ -42,9 +45,7 @@ export async function updateArtifacts({ }: UpdateArtifact): Promise { logger.debug(`pipenv.updateArtifacts(${pipfileName})`); - const cacheDir = - process.env.PIPENV_CACHE_DIR || join(config.cacheDir, './others/pipenv'); - await ensureDir(cacheDir); + const cacheDir = await ensureCacheDir('./others/pipenv', 'PIPENV_CACHE_DIR'); logger.debug('Using pipenv cache ' + cacheDir); const lockFileName = pipfileName + '.lock'; diff --git a/lib/util/fs/index.ts b/lib/util/fs/index.ts index 602b810a1e5e75..7f08141177e57a 100644 --- a/lib/util/fs/index.ts +++ b/lib/util/fs/index.ts @@ -4,9 +4,11 @@ import { RenovateConfig } from '../../config/common'; import { logger } from '../../logger'; let localDir = ''; +let cacheDir = ''; export function setFsConfig(config: Partial): void { localDir = config.localDir; + cacheDir = config.cacheDir; } export function getSubDirectory(fileName: string): string { @@ -63,3 +65,13 @@ export async function ensureLocalDir(dirName): Promise { const localDirName = join(localDir, dirName); await fs.ensureDir(localDirName); } + +export async function ensureCacheDir( + dirName, + envPathVar?: string +): Promise { + const envCacheDirName = envPathVar ? process.env[envPathVar] : null; + const cacheDirName = envCacheDirName || join(cacheDir, dirName); + await fs.ensureDir(cacheDirName); + return cacheDirName; +}