From 7464280d6efad5d0583f89ecd93c3ea3df0aa009 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Fri, 31 Mar 2023 12:23:50 +0200 Subject: [PATCH] fix(core): replace empty preset with apps --- e2e/utils/command-utils.ts | 8 +++++--- e2e/utils/create-project-utils.ts | 19 +++++++------------ .../src/create-nx-workspace.test.ts | 18 +++++++++--------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/e2e/utils/command-utils.ts b/e2e/utils/command-utils.ts index e38bde3e836808..2c59edda9fe0b8 100644 --- a/e2e/utils/command-utils.ts +++ b/e2e/utils/command-utils.ts @@ -13,8 +13,9 @@ import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process'; import { join } from 'path'; import * as isCI from 'is-ci'; import { Workspaces } from '../../packages/nx/src/config/workspaces'; -import { updateFile } from './file-utils'; +import { exists, updateFile } from './file-utils'; import { logError, stripConsoleColors } from './log-utils'; +import { existsSync } from 'fs-extra'; export interface RunCmdOpts { silenceError?: boolean; @@ -118,6 +119,7 @@ export function getPackageManagerCommand({ } { const npmMajorVersion = getNpmMajorVersion(); const publishedVersion = getPublishedVersion(); + const isPnpmWorkspace = existsSync(join(path, 'pnpm-workspace.yaml')); return { npm: { @@ -158,8 +160,8 @@ export function getPackageManagerCommand({ runUninstalledPackage: 'pnpm dlx', install: 'pnpm i', ciInstall: 'pnpm install --frozen-lockfile', - addProd: `pnpm add`, - addDev: `pnpm add -D`, + addProd: isPnpmWorkspace ? 'pnpm add -w' : 'pnpm add', + addDev: isPnpmWorkspace ? 'pnpm add -Dw' : 'pnpm add -D', list: 'npm ls --depth 10', runLerna: `pnpm exec lerna`, }, diff --git a/e2e/utils/create-project-utils.ts b/e2e/utils/create-project-utils.ts index add78ac4917a20..019473492dd77f 100644 --- a/e2e/utils/create-project-utils.ts +++ b/e2e/utils/create-project-utils.ts @@ -47,7 +47,7 @@ export function newProject({ if (!directoryExists(tmpBackupProjPath())) { runCreateWorkspace(projScope, { - preset: 'empty', + preset: 'apps', packageManager, }); @@ -287,17 +287,12 @@ export function packageInstall( } ${pkgsWithVersions}${isVerbose() ? ' --verbose' : ''}`; try { - const install = execSync( - `${mode === 'dev' ? pm.addDev : pm.addProd} ${pkgsWithVersions}${ - isVerbose() ? ' --verbose' : '' - }`, - { - cwd, - stdio: 'pipe', - env: process.env, - encoding: 'utf-8', - } - ); + const install = execSync(command, { + cwd, + stdio: 'pipe', + env: process.env, + encoding: 'utf-8', + }); if (isVerbose()) { output.log({ diff --git a/e2e/workspace-create/src/create-nx-workspace.test.ts b/e2e/workspace-create/src/create-nx-workspace.test.ts index 682792de87e8b2..96681b7b09e15b 100644 --- a/e2e/workspace-create/src/create-nx-workspace.test.ts +++ b/e2e/workspace-create/src/create-nx-workspace.test.ts @@ -96,7 +96,7 @@ describe('create-nx-workspace', () => { it('should be able to create an empty workspace built for apps', () => { const wsName = uniq('apps'); runCreateWorkspace(wsName, { - preset: 'empty', + preset: 'apps', packageManager, }); @@ -273,7 +273,7 @@ describe('create-nx-workspace', () => { it('should be able to create a workspace with a custom base branch and HEAD', () => { const wsName = uniq('branch'); runCreateWorkspace(wsName, { - preset: 'empty', + preset: 'apps', base: 'main', packageManager, }); @@ -282,7 +282,7 @@ describe('create-nx-workspace', () => { it('should be able to create a workspace with custom commit information', () => { const wsName = uniq('branch'); runCreateWorkspace(wsName, { - preset: 'empty', + preset: 'apps', extraArgs: '--commit.name="John Doe" --commit.email="myemail@test.com" --commit.message="Custom commit message!"', packageManager, @@ -307,8 +307,8 @@ describe('create-nx-workspace', () => { process.env.SELECTED_PM = 'npm'; runCreateWorkspace(wsName, { - preset: 'empty', - packageManager, + preset: 'apps', + packageManager: 'npm', }); checkFilesDoNotExist('yarn.lock'); @@ -320,7 +320,7 @@ describe('create-nx-workspace', () => { it('should return error when ci workflow is selected but no cloud is set up', () => { const wsName = uniq('github'); runCreateWorkspace(wsName, { - preset: 'empty', + preset: 'apps', packageManager, ci: 'circleci', }); @@ -332,7 +332,7 @@ describe('create-nx-workspace', () => { function setupProject(envPm: 'npm' | 'yarn' | 'pnpm') { process.env.SELECTED_PM = envPm; runCreateWorkspace(uniq('pm'), { - preset: 'empty', + preset: 'apps', packageManager: envPm, useDetectedPm: true, }); @@ -379,7 +379,7 @@ describe('create-nx-workspace', () => { describe('create-nx-workspace custom parent folder', () => { const tmpDir = `${e2eCwd}/${uniq('with space')}`; - const wsName = uniq('empty'); + const wsName = uniq('parent'); const packageManager = getSelectedPackageManager() || 'pnpm'; afterEach(() => cleanupProject({ cwd: `${tmpDir}/${wsName}` })); @@ -388,7 +388,7 @@ describe('create-nx-workspace custom parent folder', () => { mkdirSync(tmpDir, { recursive: true }); runCreateWorkspace(wsName, { - preset: 'empty', + preset: 'apps', packageManager, cwd: tmpDir, });