diff --git a/docs/configuration.md b/docs/configuration.md index 18296444959c39d5486b2c8f97ccdbd28d864740..66e442b78dff4e95a8c5c2b72d303b8847c90463 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -89,6 +89,7 @@ $ node renovate --help --rebase-stale-prs [boolean] Rebase stale PRs (GitHub only) --pr-creation <string> When to create the PR for a branch. Values: immediate, not-pending, status-success. --automerge <string> What types of upgrades to merge to base branch automatically. Values: none, minor or any + --yarn-cache-folder <string> Location of yarn cache folder to use. Set to empty string to disable --maintain-yarn-lock [boolean] Keep yarn.lock files updated in base branch --group-name <string> Human understandable name for the dependency group --group-slug <string> Slug to use for group (e.g. in branch name). Will be calculated from groupName if null @@ -154,6 +155,7 @@ Obviously, you can't set repository or package file location with this method. | `commitMessage` | Commit message template | string | `"Update dependency {{depName}} to version {{newVersion}}"` | `RENOVATE_COMMIT_MESSAGE` | | | `prTitle` | Pull Request title template | string | `"{{#if isPin}}Pin{{else}}Update{{/if}} dependency {{depName}} to version {{#if isRange}}{{newVersion}}{{else}}{{#if isMajor}}{{newVersionMajor}}.x{{else}}{{newVersion}}{{/if}}{{/if}}"` | `RENOVATE_PR_TITLE` | | | `prBody` | Pull Request body template | string | `"This Pull Request updates dependency {{depName}} from version `{{currentVersion}}` to `{{newVersion}}`\n\n{{changelog}}"` | `RENOVATE_PR_BODY` | | +| `yarnCacheFolder` | Location of yarn cache folder to use. Set to empty string to disable | string | `"/tmp/yarn-cache"` | `RENOVATE_YARN_CACHE_FOLDER` | `--yarn-cache-folder` | | `maintainYarnLock` | Keep yarn.lock files updated in base branch | boolean | `false` | `RENOVATE_MAINTAIN_YARN_LOCK` | `--maintain-yarn-lock` | | `yarnMaintenanceBranchName` | Branch name template when maintaining yarn.lock | string | `"renovate/yarn-lock"` | `RENOVATE_YARN_MAINTENANCE_BRANCH_NAME` | | | `yarnMaintenanceCommitMessage` | Commit message template when maintaining yarn.lock | string | `"Renovate yarn.lock file"` | `RENOVATE_YARN_MAINTENANCE_COMMIT_MESSAGE` | | diff --git a/lib/config/definitions.js b/lib/config/definitions.js index efabdcb5ef2beb1daacf9eb2a722d8b54f25a899..727e065dc4506b6a3cf5a8bd916ecf9e6ba1673c 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -151,6 +151,13 @@ const options = [ cli: false, }, // Yarn Lock Maintenance + { + name: 'yarnCacheFolder', + description: + 'Location of yarn cache folder to use. Set to empty string to disable', + type: 'string', + default: '/tmp/yarn-cache', + }, { name: 'maintainYarnLock', description: 'Keep yarn.lock files updated in base branch', diff --git a/lib/helpers/yarn.js b/lib/helpers/yarn.js index 4ce02b9d575e1d6f552cc339ac025534f2f8ec9b..016a6a2e1dfcef6bf0cbc53666d0b59b0ff31212 100644 --- a/lib/helpers/yarn.js +++ b/lib/helpers/yarn.js @@ -10,7 +10,12 @@ module.exports = { maintainLockFile, }; -async function generateLockFile(newPackageJson, npmrcContent, yarnrcContent) { +async function generateLockFile( + newPackageJson, + npmrcContent, + yarnrcContent, + cacheFolder +) { logger.debug('Generating new yarn.lock file'); const tmpDir = tmp.dirSync({ unsafeCleanup: true }); let yarnLock; @@ -23,7 +28,12 @@ async function generateLockFile(newPackageJson, npmrcContent, yarnrcContent) { fs.writeFileSync(path.join(tmpDir.name, '.yarnrc'), yarnrcContent); } logger.debug('Spawning yarn install'); - const result = cp.spawnSync('yarn', ['install'], { + const yarnOptions = ['install']; + if (cacheFolder && cacheFolder.length) { + logger.debug(`Setting yarn cache folder to ${cacheFolder}`); + yarnOptions.push(`--cache-folder ${cacheFolder}`); + } + const result = cp.spawnSync('yarn', yarnOptions, { cwd: tmpDir.name, shell: true, }); @@ -37,7 +47,7 @@ async function generateLockFile(newPackageJson, npmrcContent, yarnrcContent) { return yarnLock; } -async function getLockFile(packageFile, packageContent, api) { +async function getLockFile(packageFile, packageContent, api, cacheFolder) { // Detect if a yarn.lock file is in use const yarnLockFileName = path.join(path.dirname(packageFile), 'yarn.lock'); if (!await api.getFileContent(yarnLockFileName)) { @@ -50,7 +60,8 @@ async function getLockFile(packageFile, packageContent, api) { const newYarnLockContent = await module.exports.generateLockFile( packageContent, npmrcContent, - yarnrcContent + yarnrcContent, + cacheFolder ); // Return file object return { @@ -80,7 +91,8 @@ async function maintainLockFile(inputConfig) { const newYarnLock = await module.exports.getLockFile( inputConfig.packageFile, packageContent, - inputConfig.api + inputConfig.api, + inputConfig.yarnCacheFolder ); logger.silly(`newYarnLock:\n${newYarnLock.contents}`); if (existingYarnLock.toString() === newYarnLock.contents.toString()) { diff --git a/lib/workers/branch.js b/lib/workers/branch.js index 902be0c4d2e1b2a888817c86152bb77f805356c4..cedfd646b7d8b1161db54f8749d671e55a10471b 100644 --- a/lib/workers/branch.js +++ b/lib/workers/branch.js @@ -65,6 +65,7 @@ async function ensureBranch(upgrades) { upgrades[0] ); const api = upgrades[0].api; + const cacheFolder = upgrades[0].yarnCacheFolder; const packageFiles = {}; const commitFiles = []; for (const upgrade of upgrades) { @@ -116,7 +117,8 @@ async function ensureBranch(upgrades) { const yarnLockFile = await yarnHelper.getLockFile( packageFile, packageFiles[packageFile], - api + api, + cacheFolder ); if (yarnLockFile) { // Add new yarn.lock file too diff --git a/readme.md b/readme.md index edba1b009b2e37820af99420585514e0915ee33b..da00e03b528a4cd06013f75fab35614de7515549 100644 --- a/readme.md +++ b/readme.md @@ -62,6 +62,7 @@ $ node renovate --help --rebase-stale-prs [boolean] Rebase stale PRs (GitHub only) --pr-creation <string> When to create the PR for a branch. Values: immediate, not-pending, status-success. --automerge <string> What types of upgrades to merge to base branch automatically. Values: none, minor or any + --yarn-cache-folder <string> Location of yarn cache folder to use. Set to empty string to disable --maintain-yarn-lock [boolean] Keep yarn.lock files updated in base branch --group-name <string> Human understandable name for the dependency group --group-slug <string> Slug to use for group (e.g. in branch name). Will be calculated from groupName if null diff --git a/test/helpers/yarn.spec.js b/test/helpers/yarn.spec.js index 06cc201a200fe9ffe467e382c97a6e0a2a0fc72f..7856efacf00f6ae4966392eb555ee021fd7c7d26 100644 --- a/test/helpers/yarn.spec.js +++ b/test/helpers/yarn.spec.js @@ -21,7 +21,8 @@ describe('generateLockFile(newPackageJson, npmrcContent, yarnrcContent)', () => const yarnLock = await yarnHelper.generateLockFile( 'package-json-contents', 'npmrc-contents', - 'yarnrc-contents' + 'yarnrc-contents', + '/tmp/yarn-cache' ); expect(tmp.dirSync.mock.calls.length).toEqual(1); expect(fs.writeFileSync.mock.calls.length).toEqual(3);