From 1df94a2587c1dc4226a3237c13bdfa8d4fd2241c Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Thu, 24 Jun 2021 11:48:05 +0400 Subject: [PATCH] refactor(composer): Use util function for cache dir creation (#10581) --- lib/manager/composer/artifacts.spec.ts | 3 +++ lib/manager/composer/artifacts.ts | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/manager/composer/artifacts.spec.ts b/lib/manager/composer/artifacts.spec.ts index 07f21e9dfa..68ecdd611b 100644 --- a/lib/manager/composer/artifacts.spec.ts +++ b/lib/manager/composer/artifacts.spec.ts @@ -51,6 +51,9 @@ describe('.updateArtifacts()', () => { docker.resetPrefetchedImages(); hostRules.clear(); setAdminConfig(adminConfig); + fs.ensureCacheDir.mockResolvedValue( + join(adminConfig.cacheDir, './others/composer') + ); }); afterEach(() => { setAdminConfig(); diff --git a/lib/manager/composer/artifacts.ts b/lib/manager/composer/artifacts.ts index f67f3e2b63..1467e30e4c 100644 --- a/lib/manager/composer/artifacts.ts +++ b/lib/manager/composer/artifacts.ts @@ -1,6 +1,5 @@ import is from '@sindresorhus/is'; import { quote } from 'shlex'; -import upath from 'upath'; import { getAdminConfig } from '../../config/admin'; import { SYSTEM_INSUFFICIENT_DISK_SPACE, @@ -15,7 +14,7 @@ import { logger } from '../../logger'; import { ExecOptions, exec } from '../../util/exec'; import { deleteLocalFile, - ensureDir, + ensureCacheDir, ensureLocalDir, getSiblingFileName, localPathExists, @@ -77,11 +76,10 @@ export async function updateArtifacts({ }: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> { logger.debug(`composer.updateArtifacts(${packageFileName})`); - const { allowScripts, cacheDir: adminCacheDir } = getAdminConfig(); - const cacheDir = - process.env.COMPOSER_CACHE_DIR || - upath.join(adminCacheDir, './others/composer'); - await ensureDir(cacheDir); + const cacheDir = await ensureCacheDir( + './others/composer', + 'COMPOSER_CACHE_DIR' + ); logger.debug(`Using composer cache ${cacheDir}`); const lockFileName = packageFileName.replace(/\.json$/, '.lock'); @@ -125,7 +123,7 @@ export async function updateArtifacts({ args += ' --ignore-platform-reqs'; } args += ' --no-ansi --no-interaction'; - if (!allowScripts || config.ignoreScripts) { + if (!getAdminConfig().allowScripts || config.ignoreScripts) { args += ' --no-scripts --no-autoloader'; } logger.debug({ cmd, args }, 'composer command'); -- GitLab