diff --git a/packages/plugin/src/utils/testing-utils/async-commands.ts b/packages/plugin/src/utils/testing-utils/async-commands.ts index 718b061df5..ae69d347e1 100644 --- a/packages/plugin/src/utils/testing-utils/async-commands.ts +++ b/packages/plugin/src/utils/testing-utils/async-commands.ts @@ -1,6 +1,6 @@ import { exec } from 'child_process'; import { tmpProjPath } from './paths'; -import { getPackageManagerCommand } from '@nx/devkit'; +import { detectPackageManager, getPackageManagerCommand } from '@nx/devkit'; import { fileExists } from './utils'; /** @@ -43,8 +43,9 @@ export function runNxCommandAsync( silenceError: false, } ): Promise<{ stdout: string; stderr: string }> { + const cwd = opts.cwd ?? tmpProjPath(); if (fileExists(tmpProjPath('package.json'))) { - const pmc = getPackageManagerCommand(); + const pmc = getPackageManagerCommand(detectPackageManager(cwd)); return runCommandAsync(`${pmc.exec} nx ${command}`, opts); } else if (process.platform === 'win32') { return runCommandAsync(`./nx.bat %${command}`, opts); diff --git a/packages/plugin/src/utils/testing-utils/commands.ts b/packages/plugin/src/utils/testing-utils/commands.ts index 946b516f70..d5b0cd58d6 100644 --- a/packages/plugin/src/utils/testing-utils/commands.ts +++ b/packages/plugin/src/utils/testing-utils/commands.ts @@ -1,6 +1,6 @@ import { ExecOptions, execSync } from 'child_process'; import { tmpProjPath } from './paths'; -import { getPackageManagerCommand } from '@nx/devkit'; +import { detectPackageManager, getPackageManagerCommand } from '@nx/devkit'; import { fileExists } from './utils'; /** @@ -17,12 +17,13 @@ export function runNxCommand( } ): string { function _runNxCommand(c) { + const cwd = opts.cwd ?? tmpProjPath(); const execSyncOptions: ExecOptions = { - cwd: opts.cwd ?? tmpProjPath(), + cwd, env: { ...process.env, ...opts.env }, }; if (fileExists(tmpProjPath('package.json'))) { - const pmc = getPackageManagerCommand(); + const pmc = getPackageManagerCommand(detectPackageManager(cwd)); return execSync(`${pmc.exec} nx ${command}`, execSyncOptions); } else if (process.platform === 'win32') { return execSync(`./nx.bat %${command}`, execSyncOptions); diff --git a/packages/plugin/src/utils/testing-utils/nx-project.ts b/packages/plugin/src/utils/testing-utils/nx-project.ts index 1acce758a8..af70eaa65e 100644 --- a/packages/plugin/src/utils/testing-utils/nx-project.ts +++ b/packages/plugin/src/utils/testing-utils/nx-project.ts @@ -1,4 +1,4 @@ -import { workspaceRoot } from '@nx/devkit'; +import { detectPackageManager, workspaceRoot } from '@nx/devkit'; import { getPackageManagerCommand, readJsonFile, @@ -50,9 +50,10 @@ export function uniq(prefix: string) { * @param silent silent output from the install */ export function runPackageManagerInstall(silent: boolean = true) { - const pmc = getPackageManagerCommand(); + const cwd = tmpProjPath(); + const pmc = getPackageManagerCommand(detectPackageManager(cwd)); const install = execSync(pmc.install, { - cwd: tmpProjPath(), + cwd, ...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}), }); return install ? install.toString() : '';