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'; const nxDefaultBase = 'main';
try { try {
return ( return (
execSync('git config --get init.defaultBranch').toString().trim() || execSync('git config --get init.defaultBranch', { windowsHide: true })
nxDefaultBase .toString()
.trim() || nxDefaultBase
); );
} catch { } catch {
return nxDefaultBase; return nxDefaultBase;

View File

@ -4,7 +4,9 @@ import { output } from '../output';
export function checkGitVersion(): string | null | undefined { export function checkGitVersion(): string | null | undefined {
try { 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]; return gitVersionOutput.match(/[0-9]+\.[0-9]+\.+[0-9]+/)?.[0];
} catch { } catch {
return null; return null;

View File

@ -137,7 +137,10 @@ function shouldRecordStats(): boolean {
return true; return true;
} }
try { 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()); const url = new URL(stdout.trim());
// don't record stats when testing locally // don't record stats when testing locally

View File

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

View File

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

View File

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