Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): ensure plugin testing uses correct pm for install #20061

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/plugin/src/utils/testing-utils/async-commands.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions packages/plugin/src/utils/testing-utils/commands.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions packages/plugin/src/utils/testing-utils/nx-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { workspaceRoot } from '@nx/devkit';
import { detectPackageManager, workspaceRoot } from '@nx/devkit';
import {
getPackageManagerCommand,
readJsonFile,
Expand Down Expand Up @@ -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() : '';
Expand Down