Skip to content

Commit

Permalink
fix(misc): avoid terminal popups when checking package manager version (
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Aug 7, 2024
1 parent 7e22661 commit 333ab77
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
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
1 change: 1 addition & 0 deletions packages/create-nx-workspace/src/utils/package-manager.ts
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

0 comments on commit 333ab77

Please sign in to comment.