fix(nx-plugin): ensure plugin testing uses correct pm for install (#20061)
This commit is contained in:
parent
40f8c40df2
commit
5cd938a1a0
@ -1,6 +1,6 @@
|
|||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { tmpProjPath } from './paths';
|
import { tmpProjPath } from './paths';
|
||||||
import { getPackageManagerCommand } from '@nx/devkit';
|
import { detectPackageManager, getPackageManagerCommand } from '@nx/devkit';
|
||||||
import { fileExists } from './utils';
|
import { fileExists } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,8 +43,9 @@ export function runNxCommandAsync(
|
|||||||
silenceError: false,
|
silenceError: false,
|
||||||
}
|
}
|
||||||
): Promise<{ stdout: string; stderr: string }> {
|
): Promise<{ stdout: string; stderr: string }> {
|
||||||
|
const cwd = opts.cwd ?? tmpProjPath();
|
||||||
if (fileExists(tmpProjPath('package.json'))) {
|
if (fileExists(tmpProjPath('package.json'))) {
|
||||||
const pmc = getPackageManagerCommand();
|
const pmc = getPackageManagerCommand(detectPackageManager(cwd));
|
||||||
return runCommandAsync(`${pmc.exec} nx ${command}`, opts);
|
return runCommandAsync(`${pmc.exec} nx ${command}`, opts);
|
||||||
} else if (process.platform === 'win32') {
|
} else if (process.platform === 'win32') {
|
||||||
return runCommandAsync(`./nx.bat %${command}`, opts);
|
return runCommandAsync(`./nx.bat %${command}`, opts);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { ExecOptions, execSync } from 'child_process';
|
import { ExecOptions, execSync } from 'child_process';
|
||||||
import { tmpProjPath } from './paths';
|
import { tmpProjPath } from './paths';
|
||||||
import { getPackageManagerCommand } from '@nx/devkit';
|
import { detectPackageManager, getPackageManagerCommand } from '@nx/devkit';
|
||||||
import { fileExists } from './utils';
|
import { fileExists } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,12 +17,13 @@ export function runNxCommand(
|
|||||||
}
|
}
|
||||||
): string {
|
): string {
|
||||||
function _runNxCommand(c) {
|
function _runNxCommand(c) {
|
||||||
|
const cwd = opts.cwd ?? tmpProjPath();
|
||||||
const execSyncOptions: ExecOptions = {
|
const execSyncOptions: ExecOptions = {
|
||||||
cwd: opts.cwd ?? tmpProjPath(),
|
cwd,
|
||||||
env: { ...process.env, ...opts.env },
|
env: { ...process.env, ...opts.env },
|
||||||
};
|
};
|
||||||
if (fileExists(tmpProjPath('package.json'))) {
|
if (fileExists(tmpProjPath('package.json'))) {
|
||||||
const pmc = getPackageManagerCommand();
|
const pmc = getPackageManagerCommand(detectPackageManager(cwd));
|
||||||
return execSync(`${pmc.exec} nx ${command}`, execSyncOptions);
|
return execSync(`${pmc.exec} nx ${command}`, execSyncOptions);
|
||||||
} else if (process.platform === 'win32') {
|
} else if (process.platform === 'win32') {
|
||||||
return execSync(`./nx.bat %${command}`, execSyncOptions);
|
return execSync(`./nx.bat %${command}`, execSyncOptions);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { workspaceRoot } from '@nx/devkit';
|
import { detectPackageManager, workspaceRoot } from '@nx/devkit';
|
||||||
import {
|
import {
|
||||||
getPackageManagerCommand,
|
getPackageManagerCommand,
|
||||||
readJsonFile,
|
readJsonFile,
|
||||||
@ -50,9 +50,10 @@ export function uniq(prefix: string) {
|
|||||||
* @param silent silent output from the install
|
* @param silent silent output from the install
|
||||||
*/
|
*/
|
||||||
export function runPackageManagerInstall(silent: boolean = true) {
|
export function runPackageManagerInstall(silent: boolean = true) {
|
||||||
const pmc = getPackageManagerCommand();
|
const cwd = tmpProjPath();
|
||||||
|
const pmc = getPackageManagerCommand(detectPackageManager(cwd));
|
||||||
const install = execSync(pmc.install, {
|
const install = execSync(pmc.install, {
|
||||||
cwd: tmpProjPath(),
|
cwd,
|
||||||
...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}),
|
...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}),
|
||||||
});
|
});
|
||||||
return install ? install.toString() : '';
|
return install ? install.toString() : '';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user