From 16c938d5dc5b77dbf173fb6289ad6b0c4ba284bb Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Thu, 27 Jul 2023 15:30:03 +0200 Subject: [PATCH 1/2] fix(repo): fix silent yarn run on e2e for berry --- e2e/utils/command-utils.ts | 6 ++++-- e2e/utils/get-env-info.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/e2e/utils/command-utils.ts b/e2e/utils/command-utils.ts index 3e609435b2513..f87350f610353 100644 --- a/e2e/utils/command-utils.ts +++ b/e2e/utils/command-utils.ts @@ -6,6 +6,7 @@ import { getNpmMajorVersion, getPublishedVersion, getStrippedEnvironmentVariables, + getYarnMajorVersion, isVerboseE2ERun, } from './get-env-info'; import { TargetConfiguration } from '@nx/devkit'; @@ -119,6 +120,7 @@ export function getPackageManagerCommand({ runLerna: string; } { const npmMajorVersion = getNpmMajorVersion(); + const yarnMajorVersion = getYarnMajorVersion(path); const publishedVersion = getPublishedVersion(); const isYarnWorkspace = fileExists(join(path, 'package.json')) ? readJson('package.json').workspaces @@ -147,14 +149,14 @@ export function getPackageManagerCommand({ } create-nx-workspace@${publishedVersion}`, run: (script: string, args: string) => `yarn ${script} ${args}`, runNx: `yarn nx`, - runNxSilent: `yarn --silent nx`, + runNxSilent: +yarnMajorVersion >= 2 ? 'yarn nx' : `yarn --silent nx`, runUninstalledPackage: 'npx --yes', install: 'yarn', ciInstall: 'yarn --frozen-lockfile', addProd: isYarnWorkspace ? 'yarn add -W' : 'yarn add', addDev: isYarnWorkspace ? 'yarn add -DW' : 'yarn add -D', list: 'yarn list --pattern', - runLerna: `yarn --silent lerna`, + runLerna: +yarnMajorVersion >= 2 ? 'yarn lerna' : `yarn --silent lerna`, }, // Pnpm 3.5+ adds nx to pnpm: { diff --git a/e2e/utils/get-env-info.ts b/e2e/utils/get-env-info.ts index a46ece3043f34..c1472e8a31dac 100644 --- a/e2e/utils/get-env-info.ts +++ b/e2e/utils/get-env-info.ts @@ -73,6 +73,22 @@ export function getNpmMajorVersion(): string { return npmMajorVersion; } +export function getYarnMajorVersion(path: string): string { + try { + // this fails if path is not yet created + const [npmMajorVersion] = execSync(`yarn -v`, { + cwd: path, + encoding: 'utf-8', + }).split('.'); + return npmMajorVersion; + } catch { + const [npmMajorVersion] = execSync(`yarn -v`, { encoding: 'utf-8' }).split( + '.' + ); + return npmMajorVersion; + } +} + export function getLatestLernaVersion(): string { const lernaVersion = execSync(`npm view lerna version`, { encoding: 'utf-8', From ed5754a11a617288ab149d2c2ee5f7debe84c0f5 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Thu, 27 Jul 2023 16:41:44 +0200 Subject: [PATCH 2/2] fix(repo): fix naming; --- e2e/utils/get-env-info.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/utils/get-env-info.ts b/e2e/utils/get-env-info.ts index c1472e8a31dac..da3fc57361cbe 100644 --- a/e2e/utils/get-env-info.ts +++ b/e2e/utils/get-env-info.ts @@ -76,16 +76,16 @@ export function getNpmMajorVersion(): string { export function getYarnMajorVersion(path: string): string { try { // this fails if path is not yet created - const [npmMajorVersion] = execSync(`yarn -v`, { + const [yarnMajorVersion] = execSync(`yarn -v`, { cwd: path, encoding: 'utf-8', }).split('.'); - return npmMajorVersion; + return yarnMajorVersion; } catch { - const [npmMajorVersion] = execSync(`yarn -v`, { encoding: 'utf-8' }).split( + const [yarnMajorVersion] = execSync(`yarn -v`, { encoding: 'utf-8' }).split( '.' ); - return npmMajorVersion; + return yarnMajorVersion; } }