From 0853fd4a74a7aefad9d7288d6421269de7a711e9 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Wed, 20 May 2020 11:08:05 +0200 Subject: [PATCH] refactor: revert yarnv2 logic --- lib/manager/npm/post-update/yarn.ts | 74 ++--- .../__snapshots__/yarn.spec.ts.snap | 279 ------------------ lib/workers/branch/lock-files/yarn.spec.ts | 66 ++--- 3 files changed, 58 insertions(+), 361 deletions(-) diff --git a/lib/manager/npm/post-update/yarn.ts b/lib/manager/npm/post-update/yarn.ts index e1860a2b45..5c8ea45f56 100644 --- a/lib/manager/npm/post-update/yarn.ts +++ b/lib/manager/npm/post-update/yarn.ts @@ -5,7 +5,6 @@ import { DatasourceError } from '../../../datasource'; import { logger } from '../../../logger'; import { exec } from '../../../util/exec'; import { BinarySource } from '../../../util/exec/common'; -import { api as semver } from '../../../versioning/semver'; import { PostUpdateConfig, Upgrade } from '../../common'; export interface GenerateLockFileResult { @@ -51,19 +50,9 @@ export async function generateLockFile( cmd += `renovate/yarn yarn`; } - const { stdout: yarnVersion } = await exec(`${cmd} --version`); - - logger.debug(`Using yarn: ${cmd} ${yarnVersion}`); - - const yarnMajorVersion = semver.getMajor(yarnVersion); - let cmdExtras = ''; const cmdEnv = { ...env }; - if (yarnMajorVersion < 2) { - cmdExtras += ' --ignore-scripts'; - } else { - cmdEnv.YARN_ENABLE_SCRIPTS = '0'; - } + cmdExtras += ' --ignore-scripts'; cmdExtras += ' --ignore-engines'; cmdExtras += ' --ignore-platform'; const installCmd = cmd + ' install' + cmdExtras; @@ -91,42 +80,35 @@ export async function generateLockFile( stderr += updateRes.stderr || ''; } - if (yarnMajorVersion < 2) { - if ( - config.postUpdateOptions && - config.postUpdateOptions.includes('yarnDedupeFewer') - ) { - logger.debug('Performing yarn dedupe fewer'); - const dedupeCommand = - 'npx yarn-deduplicate@1.1.1 --strategy fewer && yarn'; - const dedupeRes = await exec(dedupeCommand, { - cwd, - env, - }); - // istanbul ignore next - stdout += dedupeRes.stdout || ''; - stderr += dedupeRes.stderr || ''; - } - if ( - config.postUpdateOptions && - config.postUpdateOptions.includes('yarnDedupeHighest') - ) { - logger.debug('Performing yarn dedupe highest'); - const dedupeCommand = - 'npx yarn-deduplicate@1.1.1 --strategy highest && yarn'; - const dedupeRes = await exec(dedupeCommand, { - cwd, - env, - }); - // istanbul ignore next - stdout += dedupeRes.stdout || ''; - stderr += dedupeRes.stderr || ''; - } - } else if ( + if ( config.postUpdateOptions && - config.postUpdateOptions.some((option) => option.startsWith('yarnDedupe')) + config.postUpdateOptions.includes('yarnDedupeFewer') ) { - logger.warn('yarn-deduplicate is not supported since yarn 2'); + logger.debug('Performing yarn dedupe fewer'); + const dedupeCommand = + 'npx yarn-deduplicate@1.1.1 --strategy fewer && yarn'; + const dedupeRes = await exec(dedupeCommand, { + cwd, + env, + }); + // istanbul ignore next + stdout += dedupeRes.stdout || ''; + stderr += dedupeRes.stderr || ''; + } + if ( + config.postUpdateOptions && + config.postUpdateOptions.includes('yarnDedupeHighest') + ) { + logger.debug('Performing yarn dedupe highest'); + const dedupeCommand = + 'npx yarn-deduplicate@1.1.1 --strategy highest && yarn'; + const dedupeRes = await exec(dedupeCommand, { + cwd, + env, + }); + // istanbul ignore next + stdout += dedupeRes.stdout || ''; + stderr += dedupeRes.stderr || ''; } lockFile = await readFile(join(cwd, 'yarn.lock'), 'utf8'); } catch (err) /* istanbul ignore next */ { diff --git a/lib/workers/branch/lock-files/__snapshots__/yarn.spec.ts.snap b/lib/workers/branch/lock-files/__snapshots__/yarn.spec.ts.snap index d66e0fc99b..792b4fd180 100644 --- a/lib/workers/branch/lock-files/__snapshots__/yarn.spec.ts.snap +++ b/lib/workers/branch/lock-files/__snapshots__/yarn.spec.ts.snap @@ -2,23 +2,6 @@ exports[`workers/branch/lock-files/yarn catches errors 1`] = ` Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, Object { "cmd": "yarn install --ignore-scripts --ignore-engines --ignore-platform", "options": Object { @@ -41,23 +24,6 @@ Array [ exports[`workers/branch/lock-files/yarn docker using yarn v1.0.0 1`] = ` Array [ - Object { - "cmd": "docker run --rm -v \\"some-dir\\":\\"some-dir\\" -v \\"dummy/dir\\":\\"dummy/dir\\" -e NPM_CONFIG_CACHE -e npm_config_store -w \\"some-dir\\" renovate/yarn yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, Object { "cmd": "docker run --rm -v \\"some-dir\\":\\"some-dir\\" -v \\"dummy/dir\\":\\"dummy/dir\\" -e NPM_CONFIG_CACHE -e npm_config_store -w \\"some-dir\\" renovate/yarn yarn install --ignore-scripts --ignore-engines --ignore-platform", "options": Object { @@ -95,82 +61,8 @@ Array [ ] `; -exports[`workers/branch/lock-files/yarn docker using yarn v2.0.0 1`] = ` -Array [ - Object { - "cmd": "docker run --rm -v \\"some-dir\\":\\"some-dir\\" -v \\"dummy/dir\\":\\"dummy/dir\\" -e NPM_CONFIG_CACHE -e npm_config_store -w \\"some-dir\\" renovate/yarn yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, - Object { - "cmd": "docker run --rm -v \\"some-dir\\":\\"some-dir\\" -v \\"dummy/dir\\":\\"dummy/dir\\" -e NPM_CONFIG_CACHE -e npm_config_store -w \\"some-dir\\" renovate/yarn yarn install --ignore-engines --ignore-platform", - "options": Object { - "cwd": "some-dir", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - "YARN_ENABLE_SCRIPTS": "0", - }, - "timeout": 900000, - }, - }, - Object { - "cmd": "docker run --rm -v \\"some-dir\\":\\"some-dir\\" -v \\"dummy/dir\\":\\"dummy/dir\\" -e NPM_CONFIG_CACHE -e npm_config_store -w \\"some-dir\\" renovate/yarn yarn upgrade some-dep --ignore-engines --ignore-platform", - "options": Object { - "cwd": "some-dir", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, -] -`; - exports[`workers/branch/lock-files/yarn finds yarn v1.0.0 globally 1`] = ` Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, Object { "cmd": "yarn install --ignore-scripts --ignore-engines --ignore-platform", "options": Object { @@ -191,65 +83,8 @@ Array [ ] `; -exports[`workers/branch/lock-files/yarn finds yarn v2.0.0 globally 1`] = ` -Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, - Object { - "cmd": "yarn install --ignore-engines --ignore-platform", - "options": Object { - "cwd": "some-dir", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - "YARN_ENABLE_SCRIPTS": "0", - }, - "timeout": 900000, - }, - }, -] -`; - exports[`workers/branch/lock-files/yarn generates lock files using yarn v1.0.0 1`] = ` Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, Object { "cmd": "yarn install --ignore-scripts --ignore-engines --ignore-platform", "options": Object { @@ -304,65 +139,8 @@ Array [ ] `; -exports[`workers/branch/lock-files/yarn generates lock files using yarn v2.0.0 1`] = ` -Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, - Object { - "cmd": "yarn install --ignore-engines --ignore-platform", - "options": Object { - "cwd": "some-dir", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - "YARN_ENABLE_SCRIPTS": "0", - }, - "timeout": 900000, - }, - }, -] -`; - exports[`workers/branch/lock-files/yarn performs lock file updates using yarn v1.0.0 1`] = ` Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, Object { "cmd": "yarn install --ignore-scripts --ignore-engines --ignore-platform", "options": Object { @@ -399,60 +177,3 @@ Array [ }, ] `; - -exports[`workers/branch/lock-files/yarn performs lock file updates using yarn v2.0.0 1`] = ` -Array [ - Object { - "cmd": "yarn --version", - "options": Object { - "cwd": null, - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, - Object { - "cmd": "yarn install --ignore-engines --ignore-platform", - "options": Object { - "cwd": "some-dir", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - "YARN_ENABLE_SCRIPTS": "0", - }, - "timeout": 900000, - }, - }, - Object { - "cmd": "yarn upgrade some-dep --ignore-engines --ignore-platform", - "options": Object { - "cwd": "some-dir", - "encoding": "utf-8", - "env": Object { - "HOME": "/home/user", - "HTTPS_PROXY": "https://example.com", - "HTTP_PROXY": "http://example.com", - "LANG": "en_US.UTF-8", - "LC_ALL": "en_US", - "NO_PROXY": "localhost", - "PATH": "/tmp/path", - }, - "timeout": 900000, - }, - }, -] -`; diff --git a/lib/workers/branch/lock-files/yarn.spec.ts b/lib/workers/branch/lock-files/yarn.spec.ts index 069cd1097c..23055eb40d 100644 --- a/lib/workers/branch/lock-files/yarn.spec.ts +++ b/lib/workers/branch/lock-files/yarn.spec.ts @@ -27,7 +27,7 @@ describe(getName(__filename), () => { jest.resetAllMocks(); env.getChildProcessEnv.mockReturnValue(envMock.basic); }); - it.each([['1.0.0'], ['2.0.0']])( + it.each([['1.0.0']])( 'generates lock files using yarn v%s', async (yarnVersion) => { const execSnapshots = mockExecAll(exec, { @@ -44,7 +44,7 @@ describe(getName(__filename), () => { expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); } ); - it.each([['1.0.0'], ['2.0.0']])( + it.each([['1.0.0']])( 'performs lock file updates using yarn v%s', async (yarnVersion) => { const execSnapshots = mockExecAll(exec, { @@ -60,27 +60,24 @@ describe(getName(__filename), () => { expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); } ); - it.each([['1.0.0'], ['2.0.0']])( - 'docker using yarn v%s', - async (yarnVersion) => { - const execSnapshots = mockExecAll(exec, { - stdout: yarnVersion, - stderr: '', - }); + it.each([['1.0.0']])('docker using yarn v%s', async (yarnVersion) => { + const execSnapshots = mockExecAll(exec, { + stdout: yarnVersion, + stderr: '', + }); - fs.readFile = jest.fn(() => 'package-lock-contents') as never; - const config = { - upgrades: [{}], - binarySource: BinarySource.Docker, - cacheDir: 'dummy/dir', - }; - const res = await yarnHelper.generateLockFile('some-dir', {}, config, [ - { depName: 'some-dep', isLockfileUpdate: true }, - ]); - expect(res.lockFile).toEqual('package-lock-contents'); - expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); - } - ); + fs.readFile = jest.fn(() => 'package-lock-contents') as never; + const config = { + upgrades: [{}], + binarySource: BinarySource.Docker, + cacheDir: 'dummy/dir', + }; + const res = await yarnHelper.generateLockFile('some-dir', {}, config, [ + { depName: 'some-dep', isLockfileUpdate: true }, + ]); + expect(res.lockFile).toEqual('package-lock-contents'); + expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); + }); it('catches errors', async () => { const execSnapshots = mockExecAll(exec, { stdout: '1.9.4', @@ -96,19 +93,16 @@ describe(getName(__filename), () => { expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); }); - it.each([['1.0.0'], ['2.0.0']])( - 'finds yarn v%s globally', - async (yarnVersion) => { - const execSnapshots = mockExecAll(exec, { - stdout: yarnVersion, - stderr: '', - }); + it.each([['1.0.0']])('finds yarn v%s globally', async (yarnVersion) => { + const execSnapshots = mockExecAll(exec, { + stdout: yarnVersion, + stderr: '', + }); - fs.readFile = jest.fn(() => 'package-lock-contents') as never; - const res = await yarnHelper.generateLockFile('some-dir'); - expect(fs.readFile).toHaveBeenCalledTimes(1); - expect(res.lockFile).toEqual('package-lock-contents'); - expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); - } - ); + fs.readFile = jest.fn(() => 'package-lock-contents') as never; + const res = await yarnHelper.generateLockFile('some-dir'); + expect(fs.readFile).toHaveBeenCalledTimes(1); + expect(res.lockFile).toEqual('package-lock-contents'); + expect(fixSnapshots(execSnapshots)).toMatchSnapshot(); + }); }); -- GitLab