Skip to content

Commit

Permalink
fix(core): ensure plugin testing uses correct pm for install
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Nov 6, 2023
1 parent 1d62dce commit 8d95b33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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

0 comments on commit 8d95b33

Please sign in to comment.