fix(misc): avoid terminal popups when checking package manager version (#27329)

This commit is contained in:
Craigory Coppola 2024-08-07 17:43:58 -04:00 committed by GitHub
parent 7e2266177d
commit 333ab7708f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 24 additions and 7 deletions

View File

@ -8,8 +8,9 @@ export function deduceDefaultBase(): string {
const nxDefaultBase = 'main';
try {
return (
execSync('git config --get init.defaultBranch').toString().trim() ||
nxDefaultBase
execSync('git config --get init.defaultBranch', { windowsHide: true })
.toString()
.trim() || nxDefaultBase
);
} catch {
return nxDefaultBase;

View File

@ -4,7 +4,9 @@ import { output } from '../output';
export function checkGitVersion(): string | null | undefined {
try {
let gitVersionOutput = execSync('git --version').toString().trim();
let gitVersionOutput = execSync('git --version', { windowsHide: true })
.toString()
.trim();
return gitVersionOutput.match(/[0-9]+\.[0-9]+\.+[0-9]+/)?.[0];
} catch {
return null;

View File

@ -137,7 +137,10 @@ function shouldRecordStats(): boolean {
return true;
}
try {
const stdout = execSync(pmc.getRegistryUrl, { encoding: 'utf-8' });
const stdout = execSync(pmc.getRegistryUrl, {
encoding: 'utf-8',
windowsHide: true,
});
const url = new URL(stdout.trim());
// don't record stats when testing locally

View File

@ -9,6 +9,7 @@ export function showNxWarning(workspaceName: string) {
execSync('nx --version', {
cwd: pathToRunNxCommand,
stdio: ['ignore', 'ignore', 'ignore'],
windowsHide: true,
});
} catch (e) {
// no nx found

View File

@ -123,6 +123,7 @@ export function getPackageManagerVersion(
const version = execSync(`${packageManager} --version`, {
cwd,
encoding: 'utf-8',
windowsHide: true,
}).trim();
pmVersionCache.set(packageManager, version);
return version;

View File

@ -203,6 +203,7 @@ export function getPackageManagerVersion(
version = execSync(`${packageManager} --version`, {
cwd,
encoding: 'utf-8',
windowsHide: true,
}).trim();
} catch {
if (existsSync(join(cwd, 'package.json'))) {
@ -411,7 +412,10 @@ export async function resolvePackageVersionUsingInstallation(
try {
const pmc = getPackageManagerCommand();
await execAsync(`${pmc.add} ${packageName}@${version}`, { cwd: dir });
await execAsync(`${pmc.add} ${packageName}@${version}`, {
cwd: dir,
windowsHide: true,
});
const { packageJson } = readModulePackageJson(packageName, [dir]);
@ -441,7 +445,9 @@ export async function packageRegistryView(
pm = 'npm';
}
const { stdout } = await execAsync(`${pm} view ${pkg}@${version} ${args}`);
const { stdout } = await execAsync(`${pm} view ${pkg}@${version} ${args}`, {
windowsHide: true,
});
return stdout.toString().trim();
}
@ -464,7 +470,10 @@ export async function packageRegistryPack(
pm = 'npm';
}
const { stdout } = await execAsync(`${pm} pack ${pkg}@${version}`, { cwd });
const { stdout } = await execAsync(`${pm} pack ${pkg}@${version}`, {
cwd,
windowsHide: true,
});
const tarballPath = stdout.trim();
return { tarballPath };