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(misc): avoid terminal popups when checking package manager version #27329

Merged
merged 2 commits into from
Aug 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/create-nx-workspace/src/utils/git/default-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/create-nx-workspace/src/utils/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion packages/create-nx-workspace/src/utils/nx/ab-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions packages/nx/src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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();
}

Expand All @@ -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 };
Expand Down