From 10cc62bb977a7ad2977a85e76c44e0cd9e939852 Mon Sep 17 00:00:00 2001 From: ylemkimon <y@ylem.kim> Date: Wed, 11 Aug 2021 13:16:15 +0900 Subject: [PATCH] fix(npm): set Yarn cache/global folder (#11146) --- .../npm/post-update/__snapshots__/yarn.spec.ts.snap | 8 ++++++++ lib/manager/npm/post-update/index.ts | 1 + lib/manager/npm/post-update/yarn.spec.ts | 9 ++++++++- lib/manager/npm/post-update/yarn.ts | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/manager/npm/post-update/__snapshots__/yarn.spec.ts.snap b/lib/manager/npm/post-update/__snapshots__/yarn.spec.ts.snap index fb5c50ae7e..c7397cf62a 100644 --- a/lib/manager/npm/post-update/__snapshots__/yarn.spec.ts.snap +++ b/lib/manager/npm/post-update/__snapshots__/yarn.spec.ts.snap @@ -54,6 +54,7 @@ Array [ "LC_ALL": "en_US", "NO_PROXY": "localhost", "PATH": "/tmp/path", + "YARN_CACHE_FOLDER": "/tmp/renovate/cache/yarn", }, "maxBuffer": 10485760, "timeout": 900000, @@ -73,6 +74,7 @@ Array [ "LC_ALL": "en_US", "NO_PROXY": "localhost", "PATH": "/tmp/path", + "YARN_CACHE_FOLDER": "/tmp/renovate/cache/yarn", }, "maxBuffer": 10485760, "timeout": 900000, @@ -92,6 +94,7 @@ Array [ "LC_ALL": "en_US", "NO_PROXY": "localhost", "PATH": "/tmp/path", + "YARN_CACHE_FOLDER": "/tmp/renovate/cache/yarn", }, "maxBuffer": 10485760, "timeout": 900000, @@ -111,6 +114,7 @@ Array [ "LC_ALL": "en_US", "NO_PROXY": "localhost", "PATH": "/tmp/path", + "YARN_CACHE_FOLDER": "/tmp/renovate/cache/yarn", }, "maxBuffer": 10485760, "timeout": 900000, @@ -130,6 +134,7 @@ Array [ "LC_ALL": "en_US", "NO_PROXY": "localhost", "PATH": "/tmp/path", + "YARN_CACHE_FOLDER": "/tmp/renovate/cache/yarn", }, "maxBuffer": 10485760, "timeout": 900000, @@ -156,6 +161,7 @@ Array [ "PATH": "/tmp/path", "YARN_ENABLE_IMMUTABLE_INSTALLS": "false", "YARN_ENABLE_SCRIPTS": "0", + "YARN_GLOBAL_FOLDER": "/tmp/renovate/cache/berry", "YARN_HTTP_TIMEOUT": "100000", }, "maxBuffer": 10485760, @@ -183,6 +189,7 @@ Array [ "PATH": "/tmp/path", "YARN_ENABLE_IMMUTABLE_INSTALLS": "false", "YARN_ENABLE_SCRIPTS": "0", + "YARN_GLOBAL_FOLDER": "/tmp/renovate/cache/berry", "YARN_HTTP_TIMEOUT": "100000", }, "maxBuffer": 10485760, @@ -205,6 +212,7 @@ Array [ "PATH": "/tmp/path", "YARN_ENABLE_IMMUTABLE_INSTALLS": "false", "YARN_ENABLE_SCRIPTS": "0", + "YARN_GLOBAL_FOLDER": "/tmp/renovate/cache/berry", "YARN_HTTP_TIMEOUT": "100000", }, "maxBuffer": 10485760, diff --git a/lib/manager/npm/post-update/index.ts b/lib/manager/npm/post-update/index.ts index 644740dc90..af13df358a 100644 --- a/lib/manager/npm/post-update/index.ts +++ b/lib/manager/npm/post-update/index.ts @@ -441,6 +441,7 @@ export async function getAdditionalFiles( './others/yarn', 'YARN_CACHE_FOLDER' ), + YARN_GLOBAL_FOLDER: await ensureCacheDir('./others/berry'), npm_config_store: await ensureCacheDir('./others/pnpm', 'npm_config_store'), NODE_ENV: 'dev', }; diff --git a/lib/manager/npm/post-update/yarn.spec.ts b/lib/manager/npm/post-update/yarn.spec.ts index 62d0050384..87cfb3cfed 100644 --- a/lib/manager/npm/post-update/yarn.spec.ts +++ b/lib/manager/npm/post-update/yarn.spec.ts @@ -59,7 +59,14 @@ describe(getName(), () => { }, postUpdateOptions: ['yarnDedupeFewer', 'yarnDedupeHighest'], }; - const res = await yarnHelper.generateLockFile('some-dir', {}, config); + const res = await yarnHelper.generateLockFile( + 'some-dir', + { + YARN_CACHE_FOLDER: '/tmp/renovate/cache/yarn', + YARN_GLOBAL_FOLDER: '/tmp/renovate/cache/berry', + }, + config + ); expect(fs.readFile).toHaveBeenCalledTimes(expectedFsCalls); expect(fs.remove).toHaveBeenCalledTimes(0); expect(res.lockFile).toEqual('package-lock-contents'); diff --git a/lib/manager/npm/post-update/yarn.ts b/lib/manager/npm/post-update/yarn.ts index 5cd6b80694..d4fa0b9150 100644 --- a/lib/manager/npm/post-update/yarn.ts +++ b/lib/manager/npm/post-update/yarn.ts @@ -93,9 +93,11 @@ export async function generateLockFile( if (isYarn1) { cmdOptions += '--ignore-engines --ignore-platform --network-timeout 100000'; + extraEnv.YARN_CACHE_FOLDER = env.YARN_CACHE_FOLDER; } else { extraEnv.YARN_ENABLE_IMMUTABLE_INSTALLS = 'false'; extraEnv.YARN_HTTP_TIMEOUT = '100000'; + extraEnv.YARN_GLOBAL_FOLDER = env.YARN_GLOBAL_FOLDER; } if (!getAdminConfig().allowScripts || config.ignoreScripts) { if (isYarn1) { -- GitLab